repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/bakery/_codec.py | encode_caveat | def encode_caveat(condition, root_key, third_party_info, key, ns):
'''Encrypt a third-party caveat.
The third_party_info key holds information about the
third party we're encrypting the caveat for; the key is the
public/private key pair of the party that's adding the caveat.
The caveat will be enc... | python | def encode_caveat(condition, root_key, third_party_info, key, ns):
'''Encrypt a third-party caveat.
The third_party_info key holds information about the
third party we're encrypting the caveat for; the key is the
public/private key pair of the party that's adding the caveat.
The caveat will be enc... | [
"def",
"encode_caveat",
"(",
"condition",
",",
"root_key",
",",
"third_party_info",
",",
"key",
",",
"ns",
")",
":",
"if",
"third_party_info",
".",
"version",
"==",
"VERSION_1",
":",
"return",
"_encode_caveat_v1",
"(",
"condition",
",",
"root_key",
",",
"third... | Encrypt a third-party caveat.
The third_party_info key holds information about the
third party we're encrypting the caveat for; the key is the
public/private key pair of the party that's adding the caveat.
The caveat will be encoded according to the version information
found in third_party_info.
... | [
"Encrypt",
"a",
"third",
"-",
"party",
"caveat",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/bakery/_codec.py#L21-L46 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/bakery/_codec.py | _encode_caveat_v1 | def _encode_caveat_v1(condition, root_key, third_party_pub_key, key):
'''Create a JSON-encoded third-party caveat.
The third_party_pub_key key represents the PublicKey of the third party
we're encrypting the caveat for; the key is the public/private key pair of
the party that's adding the caveat.
... | python | def _encode_caveat_v1(condition, root_key, third_party_pub_key, key):
'''Create a JSON-encoded third-party caveat.
The third_party_pub_key key represents the PublicKey of the third party
we're encrypting the caveat for; the key is the public/private key pair of
the party that's adding the caveat.
... | [
"def",
"_encode_caveat_v1",
"(",
"condition",
",",
"root_key",
",",
"third_party_pub_key",
",",
"key",
")",
":",
"plain_data",
"=",
"json",
".",
"dumps",
"(",
"{",
"'RootKey'",
":",
"base64",
".",
"b64encode",
"(",
"root_key",
")",
".",
"decode",
"(",
"'as... | Create a JSON-encoded third-party caveat.
The third_party_pub_key key represents the PublicKey of the third party
we're encrypting the caveat for; the key is the public/private key pair of
the party that's adding the caveat.
@param condition string
@param root_key bytes
@param third_party_pub_... | [
"Create",
"a",
"JSON",
"-",
"encoded",
"third",
"-",
"party",
"caveat",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/bakery/_codec.py#L49-L76 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/bakery/_codec.py | _encode_caveat_v2_v3 | def _encode_caveat_v2_v3(version, condition, root_key, third_party_pub_key,
key, ns):
'''Create a version 2 or version 3 third-party caveat.
The format has the following packed binary fields (note
that all fields up to and including the nonce are the same
as the v2 format):
... | python | def _encode_caveat_v2_v3(version, condition, root_key, third_party_pub_key,
key, ns):
'''Create a version 2 or version 3 third-party caveat.
The format has the following packed binary fields (note
that all fields up to and including the nonce are the same
as the v2 format):
... | [
"def",
"_encode_caveat_v2_v3",
"(",
"version",
",",
"condition",
",",
"root_key",
",",
"third_party_pub_key",
",",
"key",
",",
"ns",
")",
":",
"ns_data",
"=",
"bytearray",
"(",
")",
"if",
"version",
">=",
"VERSION_3",
":",
"ns_data",
"=",
"ns",
".",
"seria... | Create a version 2 or version 3 third-party caveat.
The format has the following packed binary fields (note
that all fields up to and including the nonce are the same
as the v2 format):
version 2 or 3 [1 byte]
first 4 bytes of third-party Curve25519 public key [4 bytes]
first-party... | [
"Create",
"a",
"version",
"2",
"or",
"version",
"3",
"third",
"-",
"party",
"caveat",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/bakery/_codec.py#L79-L117 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/bakery/_codec.py | _encode_secret_part_v2_v3 | def _encode_secret_part_v2_v3(version, condition, root_key, ns):
'''Creates a version 2 or version 3 secret part of the third party
caveat. The returned data is not encrypted.
The format has the following packed binary fields:
version 2 or 3 [1 byte]
root key length [n: uvarint]
root key [n byt... | python | def _encode_secret_part_v2_v3(version, condition, root_key, ns):
'''Creates a version 2 or version 3 secret part of the third party
caveat. The returned data is not encrypted.
The format has the following packed binary fields:
version 2 or 3 [1 byte]
root key length [n: uvarint]
root key [n byt... | [
"def",
"_encode_secret_part_v2_v3",
"(",
"version",
",",
"condition",
",",
"root_key",
",",
"ns",
")",
":",
"data",
"=",
"bytearray",
"(",
")",
"data",
".",
"append",
"(",
"version",
")",
"encode_uvarint",
"(",
"len",
"(",
"root_key",
")",
",",
"data",
"... | Creates a version 2 or version 3 secret part of the third party
caveat. The returned data is not encrypted.
The format has the following packed binary fields:
version 2 or 3 [1 byte]
root key length [n: uvarint]
root key [n bytes]
namespace length [n: uvarint] (v3 only)
namespace [n bytes] ... | [
"Creates",
"a",
"version",
"2",
"or",
"version",
"3",
"secret",
"part",
"of",
"the",
"third",
"party",
"caveat",
".",
"The",
"returned",
"data",
"is",
"not",
"encrypted",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/bakery/_codec.py#L120-L140 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/bakery/_codec.py | decode_caveat | def decode_caveat(key, caveat):
'''Decode caveat by decrypting the encrypted part using key.
@param key the nacl private key to decode.
@param caveat bytes.
@return ThirdPartyCaveatInfo
'''
if len(caveat) == 0:
raise VerificationError('empty third party caveat')
first = caveat[:1]
... | python | def decode_caveat(key, caveat):
'''Decode caveat by decrypting the encrypted part using key.
@param key the nacl private key to decode.
@param caveat bytes.
@return ThirdPartyCaveatInfo
'''
if len(caveat) == 0:
raise VerificationError('empty third party caveat')
first = caveat[:1]
... | [
"def",
"decode_caveat",
"(",
"key",
",",
"caveat",
")",
":",
"if",
"len",
"(",
"caveat",
")",
"==",
"0",
":",
"raise",
"VerificationError",
"(",
"'empty third party caveat'",
")",
"first",
"=",
"caveat",
"[",
":",
"1",
"]",
"if",
"first",
"==",
"b'e'",
... | Decode caveat by decrypting the encrypted part using key.
@param key the nacl private key to decode.
@param caveat bytes.
@return ThirdPartyCaveatInfo | [
"Decode",
"caveat",
"by",
"decrypting",
"the",
"encrypted",
"part",
"using",
"key",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/bakery/_codec.py#L143-L169 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/bakery/_codec.py | _decode_caveat_v1 | def _decode_caveat_v1(key, caveat):
'''Decode a base64 encoded JSON id.
@param key the nacl private key to decode.
@param caveat a base64 encoded JSON string.
'''
data = base64.b64decode(caveat).decode('utf-8')
wrapper = json.loads(data)
tp_public_key = nacl.public.PublicKey(
base6... | python | def _decode_caveat_v1(key, caveat):
'''Decode a base64 encoded JSON id.
@param key the nacl private key to decode.
@param caveat a base64 encoded JSON string.
'''
data = base64.b64decode(caveat).decode('utf-8')
wrapper = json.loads(data)
tp_public_key = nacl.public.PublicKey(
base6... | [
"def",
"_decode_caveat_v1",
"(",
"key",
",",
"caveat",
")",
":",
"data",
"=",
"base64",
".",
"b64decode",
"(",
"caveat",
")",
".",
"decode",
"(",
"'utf-8'",
")",
"wrapper",
"=",
"json",
".",
"loads",
"(",
"data",
")",
"tp_public_key",
"=",
"nacl",
".",... | Decode a base64 encoded JSON id.
@param key the nacl private key to decode.
@param caveat a base64 encoded JSON string. | [
"Decode",
"a",
"base64",
"encoded",
"JSON",
"id",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/bakery/_codec.py#L172-L210 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/bakery/_codec.py | _decode_caveat_v2_v3 | def _decode_caveat_v2_v3(version, key, caveat):
'''Decodes a version 2 or version 3 caveat.
'''
if (len(caveat) < 1 + _PUBLIC_KEY_PREFIX_LEN +
_KEY_LEN + nacl.public.Box.NONCE_SIZE + 16):
raise VerificationError('caveat id too short')
original_caveat = caveat
caveat = caveat[1:] ... | python | def _decode_caveat_v2_v3(version, key, caveat):
'''Decodes a version 2 or version 3 caveat.
'''
if (len(caveat) < 1 + _PUBLIC_KEY_PREFIX_LEN +
_KEY_LEN + nacl.public.Box.NONCE_SIZE + 16):
raise VerificationError('caveat id too short')
original_caveat = caveat
caveat = caveat[1:] ... | [
"def",
"_decode_caveat_v2_v3",
"(",
"version",
",",
"key",
",",
"caveat",
")",
":",
"if",
"(",
"len",
"(",
"caveat",
")",
"<",
"1",
"+",
"_PUBLIC_KEY_PREFIX_LEN",
"+",
"_KEY_LEN",
"+",
"nacl",
".",
"public",
".",
"Box",
".",
"NONCE_SIZE",
"+",
"16",
")... | Decodes a version 2 or version 3 caveat. | [
"Decodes",
"a",
"version",
"2",
"or",
"version",
"3",
"caveat",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/bakery/_codec.py#L213-L244 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/bakery/_codec.py | encode_uvarint | def encode_uvarint(n, data):
'''encodes integer into variable-length format into data.'''
if n < 0:
raise ValueError('only support positive integer')
while True:
this_byte = n & 127
n >>= 7
if n == 0:
data.append(this_byte)
break
data.append(th... | python | def encode_uvarint(n, data):
'''encodes integer into variable-length format into data.'''
if n < 0:
raise ValueError('only support positive integer')
while True:
this_byte = n & 127
n >>= 7
if n == 0:
data.append(this_byte)
break
data.append(th... | [
"def",
"encode_uvarint",
"(",
"n",
",",
"data",
")",
":",
"if",
"n",
"<",
"0",
":",
"raise",
"ValueError",
"(",
"'only support positive integer'",
")",
"while",
"True",
":",
"this_byte",
"=",
"n",
"&",
"127",
"n",
">>=",
"7",
"if",
"n",
"==",
"0",
":... | encodes integer into variable-length format into data. | [
"encodes",
"integer",
"into",
"variable",
"-",
"length",
"format",
"into",
"data",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/bakery/_codec.py#L271-L281 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/bakery/_codec.py | decode_uvarint | def decode_uvarint(data):
'''Decode a variable-length integer.
Reads a sequence of unsigned integer byte and decodes them into an integer
in variable-length format and returns it and the length read.
'''
n = 0
shift = 0
length = 0
for b in data:
if not isinstance(b, int):
... | python | def decode_uvarint(data):
'''Decode a variable-length integer.
Reads a sequence of unsigned integer byte and decodes them into an integer
in variable-length format and returns it and the length read.
'''
n = 0
shift = 0
length = 0
for b in data:
if not isinstance(b, int):
... | [
"def",
"decode_uvarint",
"(",
"data",
")",
":",
"n",
"=",
"0",
"shift",
"=",
"0",
"length",
"=",
"0",
"for",
"b",
"in",
"data",
":",
"if",
"not",
"isinstance",
"(",
"b",
",",
"int",
")",
":",
"b",
"=",
"six",
".",
"byte2int",
"(",
"b",
")",
"... | Decode a variable-length integer.
Reads a sequence of unsigned integer byte and decodes them into an integer
in variable-length format and returns it and the length read. | [
"Decode",
"a",
"variable",
"-",
"length",
"integer",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/bakery/_codec.py#L284-L301 | train |
jenisys/parse_type | parse_type/builder.py | TypeBuilder.make_enum | def make_enum(enum_mappings):
"""
Creates a type converter for an enumeration or text-to-value mapping.
:param enum_mappings: Defines enumeration names and values.
:return: Type converter function object for the enum/mapping.
"""
if (inspect.isclass(enum_mappings) and
... | python | def make_enum(enum_mappings):
"""
Creates a type converter for an enumeration or text-to-value mapping.
:param enum_mappings: Defines enumeration names and values.
:return: Type converter function object for the enum/mapping.
"""
if (inspect.isclass(enum_mappings) and
... | [
"def",
"make_enum",
"(",
"enum_mappings",
")",
":",
"if",
"(",
"inspect",
".",
"isclass",
"(",
"enum_mappings",
")",
"and",
"issubclass",
"(",
"enum_mappings",
",",
"enum",
".",
"Enum",
")",
")",
":",
"enum_class",
"=",
"enum_mappings",
"enum_mappings",
"=",... | Creates a type converter for an enumeration or text-to-value mapping.
:param enum_mappings: Defines enumeration names and values.
:return: Type converter function object for the enum/mapping. | [
"Creates",
"a",
"type",
"converter",
"for",
"an",
"enumeration",
"or",
"text",
"-",
"to",
"-",
"value",
"mapping",
"."
] | 7cad3a67a5ca725cb786da31f656fd473084289f | https://github.com/jenisys/parse_type/blob/7cad3a67a5ca725cb786da31f656fd473084289f/parse_type/builder.py#L98-L116 | train |
jenisys/parse_type | parse_type/builder.py | TypeBuilder.make_variant | def make_variant(cls, converters, re_opts=None, compiled=False, strict=True):
"""
Creates a type converter for a number of type converter alternatives.
The first matching type converter is used.
REQUIRES: type_converter.pattern attribute
:param converters: List of type converte... | python | def make_variant(cls, converters, re_opts=None, compiled=False, strict=True):
"""
Creates a type converter for a number of type converter alternatives.
The first matching type converter is used.
REQUIRES: type_converter.pattern attribute
:param converters: List of type converte... | [
"def",
"make_variant",
"(",
"cls",
",",
"converters",
",",
"re_opts",
"=",
"None",
",",
"compiled",
"=",
"False",
",",
"strict",
"=",
"True",
")",
":",
"assert",
"converters",
",",
"\"REQUIRE: Non-empty list.\"",
"if",
"len",
"(",
"converters",
")",
"==",
... | Creates a type converter for a number of type converter alternatives.
The first matching type converter is used.
REQUIRES: type_converter.pattern attribute
:param converters: List of type converters as alternatives.
:param re_opts: Regular expression options zu use (=default_re_opts).... | [
"Creates",
"a",
"type",
"converter",
"for",
"a",
"number",
"of",
"type",
"converter",
"alternatives",
".",
"The",
"first",
"matching",
"type",
"converter",
"is",
"used",
"."
] | 7cad3a67a5ca725cb786da31f656fd473084289f | https://github.com/jenisys/parse_type/blob/7cad3a67a5ca725cb786da31f656fd473084289f/parse_type/builder.py#L183-L227 | train |
crm416/semantic | semantic/units.py | ConversionService.isValidUnit | def isValidUnit(self, w):
"""Checks if a string represents a valid quantities unit.
Args:
w (str): A string to be tested against the set of valid
quantities units.
Returns:
True if the string can be used as a unit in the quantities
module.
... | python | def isValidUnit(self, w):
"""Checks if a string represents a valid quantities unit.
Args:
w (str): A string to be tested against the set of valid
quantities units.
Returns:
True if the string can be used as a unit in the quantities
module.
... | [
"def",
"isValidUnit",
"(",
"self",
",",
"w",
")",
":",
"bad",
"=",
"set",
"(",
"[",
"'point'",
",",
"'a'",
"]",
")",
"if",
"w",
"in",
"bad",
":",
"return",
"False",
"try",
":",
"pq",
".",
"Quantity",
"(",
"0.0",
",",
"w",
")",
"return",
"True",... | Checks if a string represents a valid quantities unit.
Args:
w (str): A string to be tested against the set of valid
quantities units.
Returns:
True if the string can be used as a unit in the quantities
module. | [
"Checks",
"if",
"a",
"string",
"represents",
"a",
"valid",
"quantities",
"unit",
"."
] | 46deb8fefb3ea58aad2fedc8d0d62f3ee254b8fe | https://github.com/crm416/semantic/blob/46deb8fefb3ea58aad2fedc8d0d62f3ee254b8fe/semantic/units.py#L73-L92 | train |
crm416/semantic | semantic/units.py | ConversionService.extractUnits | def extractUnits(self, inp):
"""Collects all the valid units from an inp string. Works by
appending consecutive words from the string and cross-referncing
them with a set of valid units.
Args:
inp (str): Some text which hopefully contains descriptions
of diff... | python | def extractUnits(self, inp):
"""Collects all the valid units from an inp string. Works by
appending consecutive words from the string and cross-referncing
them with a set of valid units.
Args:
inp (str): Some text which hopefully contains descriptions
of diff... | [
"def",
"extractUnits",
"(",
"self",
",",
"inp",
")",
":",
"inp",
"=",
"self",
".",
"_preprocess",
"(",
"inp",
")",
"units",
"=",
"[",
"]",
"description",
"=",
"\"\"",
"for",
"w",
"in",
"inp",
".",
"split",
"(",
"' '",
")",
":",
"if",
"self",
".",... | Collects all the valid units from an inp string. Works by
appending consecutive words from the string and cross-referncing
them with a set of valid units.
Args:
inp (str): Some text which hopefully contains descriptions
of different units.
Returns:
... | [
"Collects",
"all",
"the",
"valid",
"units",
"from",
"an",
"inp",
"string",
".",
"Works",
"by",
"appending",
"consecutive",
"words",
"from",
"the",
"string",
"and",
"cross",
"-",
"referncing",
"them",
"with",
"a",
"set",
"of",
"valid",
"units",
"."
] | 46deb8fefb3ea58aad2fedc8d0d62f3ee254b8fe | https://github.com/crm416/semantic/blob/46deb8fefb3ea58aad2fedc8d0d62f3ee254b8fe/semantic/units.py#L94-L123 | train |
crm416/semantic | semantic/units.py | ConversionService.convert | def convert(self, inp):
"""Converts a string representation of some quantity of units into a
quantities object.
Args:
inp (str): A textual representation of some quantity of units,
e.g., "fifty kilograms".
Returns:
A quantities object representin... | python | def convert(self, inp):
"""Converts a string representation of some quantity of units into a
quantities object.
Args:
inp (str): A textual representation of some quantity of units,
e.g., "fifty kilograms".
Returns:
A quantities object representin... | [
"def",
"convert",
"(",
"self",
",",
"inp",
")",
":",
"inp",
"=",
"self",
".",
"_preprocess",
"(",
"inp",
")",
"n",
"=",
"NumberService",
"(",
")",
".",
"longestNumber",
"(",
"inp",
")",
"units",
"=",
"self",
".",
"extractUnits",
"(",
"inp",
")",
"q... | Converts a string representation of some quantity of units into a
quantities object.
Args:
inp (str): A textual representation of some quantity of units,
e.g., "fifty kilograms".
Returns:
A quantities object representing the described quantity and its
... | [
"Converts",
"a",
"string",
"representation",
"of",
"some",
"quantity",
"of",
"units",
"into",
"a",
"quantities",
"object",
"."
] | 46deb8fefb3ea58aad2fedc8d0d62f3ee254b8fe | https://github.com/crm416/semantic/blob/46deb8fefb3ea58aad2fedc8d0d62f3ee254b8fe/semantic/units.py#L125-L146 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/bakery/_identity.py | SimpleIdentity.allow | def allow(self, ctx, acls):
'''Allow access to any ACL members that was equal to the user name.
That is, some user u is considered a member of group u and no other.
'''
for acl in acls:
if self._identity == acl:
return True
return False | python | def allow(self, ctx, acls):
'''Allow access to any ACL members that was equal to the user name.
That is, some user u is considered a member of group u and no other.
'''
for acl in acls:
if self._identity == acl:
return True
return False | [
"def",
"allow",
"(",
"self",
",",
"ctx",
",",
"acls",
")",
":",
"for",
"acl",
"in",
"acls",
":",
"if",
"self",
".",
"_identity",
"==",
"acl",
":",
"return",
"True",
"return",
"False"
] | Allow access to any ACL members that was equal to the user name.
That is, some user u is considered a member of group u and no other. | [
"Allow",
"access",
"to",
"any",
"ACL",
"members",
"that",
"was",
"equal",
"to",
"the",
"user",
"name",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/bakery/_identity.py#L68-L76 | train |
eonpatapon/contrail-api-cli | contrail_api_cli/command.py | expand_paths | def expand_paths(paths=None, predicate=None, filters=None, parent_uuid=None):
"""Return an unique list of resources or collections from a list of paths.
Supports fq_name and wilcards resolution.
>>> expand_paths(['virtual-network',
'floating-ip/2a0a54b4-a420-485e-8372-42f70a627ec9'])
... | python | def expand_paths(paths=None, predicate=None, filters=None, parent_uuid=None):
"""Return an unique list of resources or collections from a list of paths.
Supports fq_name and wilcards resolution.
>>> expand_paths(['virtual-network',
'floating-ip/2a0a54b4-a420-485e-8372-42f70a627ec9'])
... | [
"def",
"expand_paths",
"(",
"paths",
"=",
"None",
",",
"predicate",
"=",
"None",
",",
"filters",
"=",
"None",
",",
"parent_uuid",
"=",
"None",
")",
":",
"if",
"not",
"paths",
":",
"paths",
"=",
"[",
"Context",
"(",
")",
".",
"shell",
".",
"current_pa... | Return an unique list of resources or collections from a list of paths.
Supports fq_name and wilcards resolution.
>>> expand_paths(['virtual-network',
'floating-ip/2a0a54b4-a420-485e-8372-42f70a627ec9'])
[Collection('virtual-network'),
Resource('floating-ip', uuid='2a0a54b4-a420-... | [
"Return",
"an",
"unique",
"list",
"of",
"resources",
"or",
"collections",
"from",
"a",
"list",
"of",
"paths",
".",
"Supports",
"fq_name",
"and",
"wilcards",
"resolution",
"."
] | 1571bf523fa054f3d6bf83dba43a224fea173a73 | https://github.com/eonpatapon/contrail-api-cli/blob/1571bf523fa054f3d6bf83dba43a224fea173a73/contrail_api_cli/command.py#L136-L174 | train |
dbarsam/python-vsgen | vsgen/writer.py | VSGJinjaRenderer.render | def render(self, template, filename, context={}, filters={}):
"""
Renders a Jinja2 template to text.
"""
filename = os.path.normpath(filename)
path, file = os.path.split(filename)
try:
os.makedirs(path)
except OSError as exception:
if excep... | python | def render(self, template, filename, context={}, filters={}):
"""
Renders a Jinja2 template to text.
"""
filename = os.path.normpath(filename)
path, file = os.path.split(filename)
try:
os.makedirs(path)
except OSError as exception:
if excep... | [
"def",
"render",
"(",
"self",
",",
"template",
",",
"filename",
",",
"context",
"=",
"{",
"}",
",",
"filters",
"=",
"{",
"}",
")",
":",
"filename",
"=",
"os",
".",
"path",
".",
"normpath",
"(",
"filename",
")",
"path",
",",
"file",
"=",
"os",
"."... | Renders a Jinja2 template to text. | [
"Renders",
"a",
"Jinja2",
"template",
"to",
"text",
"."
] | 640191bb018a1ff7d7b7a4982e0d3c1a423ba878 | https://github.com/dbarsam/python-vsgen/blob/640191bb018a1ff7d7b7a4982e0d3c1a423ba878/vsgen/writer.py#L19-L38 | train |
dbarsam/python-vsgen | vsgen/writer.py | VSGWriter.write | def write(pylist, parallel=True):
"""
Utility method to spawn a VSGWriter for each element in a collection.
:param list pylist: A list of VSG objects (PrProjects, VSGSolutions, etc)
:param bool parallel: Flag to enable asynchronous writing.
"""
threads = [VSGWriter(o) ... | python | def write(pylist, parallel=True):
"""
Utility method to spawn a VSGWriter for each element in a collection.
:param list pylist: A list of VSG objects (PrProjects, VSGSolutions, etc)
:param bool parallel: Flag to enable asynchronous writing.
"""
threads = [VSGWriter(o) ... | [
"def",
"write",
"(",
"pylist",
",",
"parallel",
"=",
"True",
")",
":",
"threads",
"=",
"[",
"VSGWriter",
"(",
"o",
")",
"for",
"o",
"in",
"pylist",
"]",
"if",
"parallel",
":",
"for",
"t",
"in",
"threads",
":",
"t",
".",
"start",
"(",
")",
"for",
... | Utility method to spawn a VSGWriter for each element in a collection.
:param list pylist: A list of VSG objects (PrProjects, VSGSolutions, etc)
:param bool parallel: Flag to enable asynchronous writing. | [
"Utility",
"method",
"to",
"spawn",
"a",
"VSGWriter",
"for",
"each",
"element",
"in",
"a",
"collection",
"."
] | 640191bb018a1ff7d7b7a4982e0d3c1a423ba878 | https://github.com/dbarsam/python-vsgen/blob/640191bb018a1ff7d7b7a4982e0d3c1a423ba878/vsgen/writer.py#L156-L171 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/httpbakery/_browser.py | WebBrowserInteractor.interact | def interact(self, ctx, location, ir_err):
'''Implement Interactor.interact by opening the browser window
and waiting for the discharge token'''
p = ir_err.interaction_method(self.kind(), WebBrowserInteractionInfo)
if not location.endswith('/'):
location += '/'
visit_... | python | def interact(self, ctx, location, ir_err):
'''Implement Interactor.interact by opening the browser window
and waiting for the discharge token'''
p = ir_err.interaction_method(self.kind(), WebBrowserInteractionInfo)
if not location.endswith('/'):
location += '/'
visit_... | [
"def",
"interact",
"(",
"self",
",",
"ctx",
",",
"location",
",",
"ir_err",
")",
":",
"p",
"=",
"ir_err",
".",
"interaction_method",
"(",
"self",
".",
"kind",
"(",
")",
",",
"WebBrowserInteractionInfo",
")",
"if",
"not",
"location",
".",
"endswith",
"(",... | Implement Interactor.interact by opening the browser window
and waiting for the discharge token | [
"Implement",
"Interactor",
".",
"interact",
"by",
"opening",
"the",
"browser",
"window",
"and",
"waiting",
"for",
"the",
"discharge",
"token"
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/httpbakery/_browser.py#L38-L47 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/httpbakery/_browser.py | WebBrowserInteractor._wait_for_token | def _wait_for_token(self, ctx, wait_token_url):
''' Returns a token from a the wait token URL
@param wait_token_url URL to wait for (string)
:return DischargeToken
'''
resp = requests.get(wait_token_url)
if resp.status_code != 200:
raise InteractionError('cann... | python | def _wait_for_token(self, ctx, wait_token_url):
''' Returns a token from a the wait token URL
@param wait_token_url URL to wait for (string)
:return DischargeToken
'''
resp = requests.get(wait_token_url)
if resp.status_code != 200:
raise InteractionError('cann... | [
"def",
"_wait_for_token",
"(",
"self",
",",
"ctx",
",",
"wait_token_url",
")",
":",
"resp",
"=",
"requests",
".",
"get",
"(",
"wait_token_url",
")",
"if",
"resp",
".",
"status_code",
"!=",
"200",
":",
"raise",
"InteractionError",
"(",
"'cannot get {}'",
".",... | Returns a token from a the wait token URL
@param wait_token_url URL to wait for (string)
:return DischargeToken | [
"Returns",
"a",
"token",
"from",
"a",
"the",
"wait",
"token",
"URL"
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/httpbakery/_browser.py#L49-L69 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/httpbakery/_browser.py | WebBrowserInteractionInfo.from_dict | def from_dict(cls, info_dict):
'''Create a new instance of WebBrowserInteractionInfo, as expected
by the Error.interaction_method method.
@param info_dict The deserialized JSON object
@return a new WebBrowserInteractionInfo object.
'''
return WebBrowserInteractionInfo(
... | python | def from_dict(cls, info_dict):
'''Create a new instance of WebBrowserInteractionInfo, as expected
by the Error.interaction_method method.
@param info_dict The deserialized JSON object
@return a new WebBrowserInteractionInfo object.
'''
return WebBrowserInteractionInfo(
... | [
"def",
"from_dict",
"(",
"cls",
",",
"info_dict",
")",
":",
"return",
"WebBrowserInteractionInfo",
"(",
"visit_url",
"=",
"info_dict",
".",
"get",
"(",
"'VisitURL'",
")",
",",
"wait_token_url",
"=",
"info_dict",
".",
"get",
"(",
"'WaitTokenURL'",
")",
")"
] | Create a new instance of WebBrowserInteractionInfo, as expected
by the Error.interaction_method method.
@param info_dict The deserialized JSON object
@return a new WebBrowserInteractionInfo object. | [
"Create",
"a",
"new",
"instance",
"of",
"WebBrowserInteractionInfo",
"as",
"expected",
"by",
"the",
"Error",
".",
"interaction_method",
"method",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/httpbakery/_browser.py#L82-L90 | train |
useblocks/groundwork | groundwork/configuration/config.py | Config.set | def set(self, name, value, overwrite=False):
"""
Sets a new value for a given configuration parameter.
If it already exists, an Exception is thrown.
To overwrite an existing value, set overwrite to True.
:param name: Unique name of the parameter
:param value: Value of t... | python | def set(self, name, value, overwrite=False):
"""
Sets a new value for a given configuration parameter.
If it already exists, an Exception is thrown.
To overwrite an existing value, set overwrite to True.
:param name: Unique name of the parameter
:param value: Value of t... | [
"def",
"set",
"(",
"self",
",",
"name",
",",
"value",
",",
"overwrite",
"=",
"False",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"name",
")",
":",
"if",
"overwrite",
":",
"setattr",
"(",
"self",
",",
"name",
",",
"value",
")",
"else",
":",
"sel... | Sets a new value for a given configuration parameter.
If it already exists, an Exception is thrown.
To overwrite an existing value, set overwrite to True.
:param name: Unique name of the parameter
:param value: Value of the configuration parameter
:param overwrite: If true, an ... | [
"Sets",
"a",
"new",
"value",
"for",
"a",
"given",
"configuration",
"parameter",
"."
] | d34fce43f54246ca4db0f7b89e450dcdc847c68c | https://github.com/useblocks/groundwork/blob/d34fce43f54246ca4db0f7b89e450dcdc847c68c/groundwork/configuration/config.py#L30-L50 | train |
jenisys/parse_type | parse_type/cfparse.py | Parser.create_missing_types | def create_missing_types(cls, schema, type_dict, type_builder=None):
"""Creates missing types for fields with a CardinalityField part.
It is assumed that the primary type converter for cardinality=1
is registered in the type dictionary.
:param schema: Parse schema (or format) for parse... | python | def create_missing_types(cls, schema, type_dict, type_builder=None):
"""Creates missing types for fields with a CardinalityField part.
It is assumed that the primary type converter for cardinality=1
is registered in the type dictionary.
:param schema: Parse schema (or format) for parse... | [
"def",
"create_missing_types",
"(",
"cls",
",",
"schema",
",",
"type_dict",
",",
"type_builder",
"=",
"None",
")",
":",
"if",
"not",
"type_builder",
":",
"type_builder",
"=",
"cls",
".",
"type_builder",
"missing",
"=",
"cls",
".",
"extract_missing_special_type_n... | Creates missing types for fields with a CardinalityField part.
It is assumed that the primary type converter for cardinality=1
is registered in the type dictionary.
:param schema: Parse schema (or format) for parser (as string).
:param type_dict: Type dictionary with type converters.
... | [
"Creates",
"missing",
"types",
"for",
"fields",
"with",
"a",
"CardinalityField",
"part",
".",
"It",
"is",
"assumed",
"that",
"the",
"primary",
"type",
"converter",
"for",
"cardinality",
"=",
"1",
"is",
"registered",
"in",
"the",
"type",
"dictionary",
"."
] | 7cad3a67a5ca725cb786da31f656fd473084289f | https://github.com/jenisys/parse_type/blob/7cad3a67a5ca725cb786da31f656fd473084289f/parse_type/cfparse.py#L56-L72 | train |
jenisys/parse_type | parse_type/cfparse.py | Parser.extract_missing_special_type_names | def extract_missing_special_type_names(schema, type_dict):
"""Extract the type names for fields with CardinalityField part.
Selects only the missing type names that are not in the type dictionary.
:param schema: Parse schema to use (as string).
:param type_dict: Type dictionary wit... | python | def extract_missing_special_type_names(schema, type_dict):
"""Extract the type names for fields with CardinalityField part.
Selects only the missing type names that are not in the type dictionary.
:param schema: Parse schema to use (as string).
:param type_dict: Type dictionary wit... | [
"def",
"extract_missing_special_type_names",
"(",
"schema",
",",
"type_dict",
")",
":",
"for",
"name",
"in",
"FieldParser",
".",
"extract_types",
"(",
"schema",
")",
":",
"if",
"CardinalityField",
".",
"matches_type",
"(",
"name",
")",
"and",
"(",
"name",
"not... | Extract the type names for fields with CardinalityField part.
Selects only the missing type names that are not in the type dictionary.
:param schema: Parse schema to use (as string).
:param type_dict: Type dictionary with type converters.
:return: Generator with missing type names ... | [
"Extract",
"the",
"type",
"names",
"for",
"fields",
"with",
"CardinalityField",
"part",
".",
"Selects",
"only",
"the",
"missing",
"type",
"names",
"that",
"are",
"not",
"in",
"the",
"type",
"dictionary",
"."
] | 7cad3a67a5ca725cb786da31f656fd473084289f | https://github.com/jenisys/parse_type/blob/7cad3a67a5ca725cb786da31f656fd473084289f/parse_type/cfparse.py#L75-L85 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/checkers/_checkers.py | _check_operations | def _check_operations(ctx, need_ops, arg):
''' Checks an allow or a deny caveat. The need_ops parameter specifies
whether we require all the operations in the caveat to be declared in
the context.
'''
ctx_ops = ctx.get(OP_KEY, [])
if len(ctx_ops) == 0:
if need_ops:
f = arg.sp... | python | def _check_operations(ctx, need_ops, arg):
''' Checks an allow or a deny caveat. The need_ops parameter specifies
whether we require all the operations in the caveat to be declared in
the context.
'''
ctx_ops = ctx.get(OP_KEY, [])
if len(ctx_ops) == 0:
if need_ops:
f = arg.sp... | [
"def",
"_check_operations",
"(",
"ctx",
",",
"need_ops",
",",
"arg",
")",
":",
"ctx_ops",
"=",
"ctx",
".",
"get",
"(",
"OP_KEY",
",",
"[",
"]",
")",
"if",
"len",
"(",
"ctx_ops",
")",
"==",
"0",
":",
"if",
"need_ops",
":",
"f",
"=",
"arg",
".",
... | Checks an allow or a deny caveat. The need_ops parameter specifies
whether we require all the operations in the caveat to be declared in
the context. | [
"Checks",
"an",
"allow",
"or",
"a",
"deny",
"caveat",
".",
"The",
"need_ops",
"parameter",
"specifies",
"whether",
"we",
"require",
"all",
"the",
"operations",
"in",
"the",
"caveat",
"to",
"be",
"declared",
"in",
"the",
"context",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/checkers/_checkers.py#L210-L229 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/checkers/_checkers.py | Checker.info | def info(self):
''' Returns information on all the registered checkers.
Sorted by namespace and then name
:returns a list of CheckerInfo
'''
return sorted(self._checkers.values(), key=lambda x: (x.ns, x.name)) | python | def info(self):
''' Returns information on all the registered checkers.
Sorted by namespace and then name
:returns a list of CheckerInfo
'''
return sorted(self._checkers.values(), key=lambda x: (x.ns, x.name)) | [
"def",
"info",
"(",
"self",
")",
":",
"return",
"sorted",
"(",
"self",
".",
"_checkers",
".",
"values",
"(",
")",
",",
"key",
"=",
"lambda",
"x",
":",
"(",
"x",
".",
"ns",
",",
"x",
".",
"name",
")",
")"
] | Returns information on all the registered checkers.
Sorted by namespace and then name
:returns a list of CheckerInfo | [
"Returns",
"information",
"on",
"all",
"the",
"registered",
"checkers",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/checkers/_checkers.py#L90-L96 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/checkers/_checkers.py | Checker.register_std | def register_std(self):
''' Registers all the standard checkers in the given checker.
If not present already, the standard checkers schema (STD_NAMESPACE) is
added to the checker's namespace with an empty prefix.
'''
self._namespace.register(STD_NAMESPACE, '')
for cond i... | python | def register_std(self):
''' Registers all the standard checkers in the given checker.
If not present already, the standard checkers schema (STD_NAMESPACE) is
added to the checker's namespace with an empty prefix.
'''
self._namespace.register(STD_NAMESPACE, '')
for cond i... | [
"def",
"register_std",
"(",
"self",
")",
":",
"self",
".",
"_namespace",
".",
"register",
"(",
"STD_NAMESPACE",
",",
"''",
")",
"for",
"cond",
"in",
"_ALL_CHECKERS",
":",
"self",
".",
"register",
"(",
"cond",
",",
"STD_NAMESPACE",
",",
"_ALL_CHECKERS",
"["... | Registers all the standard checkers in the given checker.
If not present already, the standard checkers schema (STD_NAMESPACE) is
added to the checker's namespace with an empty prefix. | [
"Registers",
"all",
"the",
"standard",
"checkers",
"in",
"the",
"given",
"checker",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/checkers/_checkers.py#L137-L145 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/bakery/_authorizer.py | AuthorizerFunc.authorize | def authorize(self, ctx, identity, ops):
'''Implements Authorizer.authorize by calling f with the given identity
for each operation.
'''
allowed = []
caveats = []
for op in ops:
ok, fcaveats = self._f(ctx, identity, op)
allowed.append(ok)
... | python | def authorize(self, ctx, identity, ops):
'''Implements Authorizer.authorize by calling f with the given identity
for each operation.
'''
allowed = []
caveats = []
for op in ops:
ok, fcaveats = self._f(ctx, identity, op)
allowed.append(ok)
... | [
"def",
"authorize",
"(",
"self",
",",
"ctx",
",",
"identity",
",",
"ops",
")",
":",
"allowed",
"=",
"[",
"]",
"caveats",
"=",
"[",
"]",
"for",
"op",
"in",
"ops",
":",
"ok",
",",
"fcaveats",
"=",
"self",
".",
"_f",
"(",
"ctx",
",",
"identity",
"... | Implements Authorizer.authorize by calling f with the given identity
for each operation. | [
"Implements",
"Authorizer",
".",
"authorize",
"by",
"calling",
"f",
"with",
"the",
"given",
"identity",
"for",
"each",
"operation",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/bakery/_authorizer.py#L50-L61 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/bakery/_authorizer.py | ACLAuthorizer.authorize | def authorize(self, ctx, identity, ops):
'''Implements Authorizer.authorize by calling identity.allow to
determine whether the identity is a member of the ACLs associated with
the given operations.
'''
if len(ops) == 0:
# Anyone is allowed to do nothing.
r... | python | def authorize(self, ctx, identity, ops):
'''Implements Authorizer.authorize by calling identity.allow to
determine whether the identity is a member of the ACLs associated with
the given operations.
'''
if len(ops) == 0:
# Anyone is allowed to do nothing.
r... | [
"def",
"authorize",
"(",
"self",
",",
"ctx",
",",
"identity",
",",
"ops",
")",
":",
"if",
"len",
"(",
"ops",
")",
"==",
"0",
":",
"return",
"[",
"]",
",",
"[",
"]",
"allowed",
"=",
"[",
"False",
"]",
"*",
"len",
"(",
"ops",
")",
"has_allow",
... | Implements Authorizer.authorize by calling identity.allow to
determine whether the identity is a member of the ACLs associated with
the given operations. | [
"Implements",
"Authorizer",
".",
"authorize",
"by",
"calling",
"identity",
".",
"allow",
"to",
"determine",
"whether",
"the",
"identity",
"is",
"a",
"member",
"of",
"the",
"ACLs",
"associated",
"with",
"the",
"given",
"operations",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/bakery/_authorizer.py#L83-L99 | train |
cocoakekeyu/cancan | cancan/rule.py | Rule.is_relevant | def is_relevant(self, action, subject):
"""
Matches both the subject and action, not necessarily the conditions.
"""
return self.matches_action(action) and self.matches_subject(subject) | python | def is_relevant(self, action, subject):
"""
Matches both the subject and action, not necessarily the conditions.
"""
return self.matches_action(action) and self.matches_subject(subject) | [
"def",
"is_relevant",
"(",
"self",
",",
"action",
",",
"subject",
")",
":",
"return",
"self",
".",
"matches_action",
"(",
"action",
")",
"and",
"self",
".",
"matches_subject",
"(",
"subject",
")"
] | Matches both the subject and action, not necessarily the conditions. | [
"Matches",
"both",
"the",
"subject",
"and",
"action",
"not",
"necessarily",
"the",
"conditions",
"."
] | f198d560e6e008e6c5580ba55581a939a5d544ed | https://github.com/cocoakekeyu/cancan/blob/f198d560e6e008e6c5580ba55581a939a5d544ed/cancan/rule.py#L42-L46 | train |
Phyks/libbmc | libbmc/repositories/hal.py | is_valid | def is_valid(hal_id):
"""
Check that a given HAL id is a valid one.
:param hal_id: The HAL id to be checked.
:returns: Boolean indicating whether the HAL id is valid or not.
>>> is_valid("hal-01258754, version 1")
True
>>> is_valid("hal-01258754")
True
>>> is_valid("hal-01258754v... | python | def is_valid(hal_id):
"""
Check that a given HAL id is a valid one.
:param hal_id: The HAL id to be checked.
:returns: Boolean indicating whether the HAL id is valid or not.
>>> is_valid("hal-01258754, version 1")
True
>>> is_valid("hal-01258754")
True
>>> is_valid("hal-01258754v... | [
"def",
"is_valid",
"(",
"hal_id",
")",
":",
"match",
"=",
"REGEX",
".",
"match",
"(",
"hal_id",
")",
"return",
"(",
"match",
"is",
"not",
"None",
")",
"and",
"(",
"match",
".",
"group",
"(",
"0",
")",
"==",
"hal_id",
")"
] | Check that a given HAL id is a valid one.
:param hal_id: The HAL id to be checked.
:returns: Boolean indicating whether the HAL id is valid or not.
>>> is_valid("hal-01258754, version 1")
True
>>> is_valid("hal-01258754")
True
>>> is_valid("hal-01258754v2")
True
>>> is_valid("fo... | [
"Check",
"that",
"a",
"given",
"HAL",
"id",
"is",
"a",
"valid",
"one",
"."
] | 9ef1a29d2514157d1edd6c13ecbd61b07ae9315e | https://github.com/Phyks/libbmc/blob/9ef1a29d2514157d1edd6c13ecbd61b07ae9315e/libbmc/repositories/hal.py#L16-L36 | train |
Phyks/libbmc | libbmc/repositories/hal.py | extract_from_text | def extract_from_text(text):
"""
Extract HAL ids from a text.
:param text: The text to extract HAL ids from.
:returns: A list of matching HAL ids.
>>> sorted(extract_from_text("hal-01258754 hal-01258754v2 foobar"))
['hal-01258754', 'hal-01258754v2']
"""
return tools.remove_duplicates([... | python | def extract_from_text(text):
"""
Extract HAL ids from a text.
:param text: The text to extract HAL ids from.
:returns: A list of matching HAL ids.
>>> sorted(extract_from_text("hal-01258754 hal-01258754v2 foobar"))
['hal-01258754', 'hal-01258754v2']
"""
return tools.remove_duplicates([... | [
"def",
"extract_from_text",
"(",
"text",
")",
":",
"return",
"tools",
".",
"remove_duplicates",
"(",
"[",
"i",
"[",
"0",
"]",
"for",
"i",
"in",
"REGEX",
".",
"findall",
"(",
"text",
")",
"if",
"i",
"!=",
"''",
"]",
")"
] | Extract HAL ids from a text.
:param text: The text to extract HAL ids from.
:returns: A list of matching HAL ids.
>>> sorted(extract_from_text("hal-01258754 hal-01258754v2 foobar"))
['hal-01258754', 'hal-01258754v2'] | [
"Extract",
"HAL",
"ids",
"from",
"a",
"text",
"."
] | 9ef1a29d2514157d1edd6c13ecbd61b07ae9315e | https://github.com/Phyks/libbmc/blob/9ef1a29d2514157d1edd6c13ecbd61b07ae9315e/libbmc/repositories/hal.py#L39-L50 | train |
dbarsam/python-vsgen | vsgen/suite.py | VSGSuite._getsolution | def _getsolution(self, config, section, **kwargs):
"""
Creates a VSG solution from a configparser instance.
:param object config: The instance of the configparser class
:param str section: The section name to read.
:param kwargs: List of additional keyworded arguments to be pas... | python | def _getsolution(self, config, section, **kwargs):
"""
Creates a VSG solution from a configparser instance.
:param object config: The instance of the configparser class
:param str section: The section name to read.
:param kwargs: List of additional keyworded arguments to be pas... | [
"def",
"_getsolution",
"(",
"self",
",",
"config",
",",
"section",
",",
"**",
"kwargs",
")",
":",
"if",
"section",
"not",
"in",
"config",
":",
"raise",
"ValueError",
"(",
"'Section [{}] not found in [{}]'",
".",
"format",
"(",
"section",
",",
"', '",
".",
... | Creates a VSG solution from a configparser instance.
:param object config: The instance of the configparser class
:param str section: The section name to read.
:param kwargs: List of additional keyworded arguments to be passed into the VSGSolution.
:return: A valid VSGSolution instance... | [
"Creates",
"a",
"VSG",
"solution",
"from",
"a",
"configparser",
"instance",
"."
] | 640191bb018a1ff7d7b7a4982e0d3c1a423ba878 | https://github.com/dbarsam/python-vsgen/blob/640191bb018a1ff7d7b7a4982e0d3c1a423ba878/vsgen/suite.py#L43-L68 | train |
dbarsam/python-vsgen | vsgen/suite.py | VSGSuite._getproject | def _getproject(self, config, section, **kwargs):
"""
Creates a VSG project from a configparser instance.
:param object config: The instance of the configparser class
:param str section: The section name to read.
:param kwargs: List of additional keyworded arguments to be passe... | python | def _getproject(self, config, section, **kwargs):
"""
Creates a VSG project from a configparser instance.
:param object config: The instance of the configparser class
:param str section: The section name to read.
:param kwargs: List of additional keyworded arguments to be passe... | [
"def",
"_getproject",
"(",
"self",
",",
"config",
",",
"section",
",",
"**",
"kwargs",
")",
":",
"if",
"section",
"not",
"in",
"config",
":",
"raise",
"ValueError",
"(",
"'Section [{}] not found in [{}]'",
".",
"format",
"(",
"section",
",",
"', '",
".",
"... | Creates a VSG project from a configparser instance.
:param object config: The instance of the configparser class
:param str section: The section name to read.
:param kwargs: List of additional keyworded arguments to be passed into the VSGProject.
:return: A valid VSGProject instance if... | [
"Creates",
"a",
"VSG",
"project",
"from",
"a",
"configparser",
"instance",
"."
] | 640191bb018a1ff7d7b7a4982e0d3c1a423ba878 | https://github.com/dbarsam/python-vsgen/blob/640191bb018a1ff7d7b7a4982e0d3c1a423ba878/vsgen/suite.py#L70-L87 | train |
dbarsam/python-vsgen | vsgen/suite.py | VSGSuite.from_args | def from_args(cls, **kwargs):
"""
Generates one or more VSGSuite instances from command line arguments.
:param kwargs: List of additional keyworded arguments to be passed into the VSGSuite defined in the :meth:`~VSGSuite.make_parser` method.
"""
# Create a VSGSuite for each fil... | python | def from_args(cls, **kwargs):
"""
Generates one or more VSGSuite instances from command line arguments.
:param kwargs: List of additional keyworded arguments to be passed into the VSGSuite defined in the :meth:`~VSGSuite.make_parser` method.
"""
# Create a VSGSuite for each fil... | [
"def",
"from_args",
"(",
"cls",
",",
"**",
"kwargs",
")",
":",
"if",
"kwargs",
".",
"get",
"(",
"'suite_commands'",
",",
"None",
")",
"==",
"'generate'",
":",
"filenames",
"=",
"kwargs",
".",
"pop",
"(",
"'configuration_filenames'",
",",
"[",
"]",
")",
... | Generates one or more VSGSuite instances from command line arguments.
:param kwargs: List of additional keyworded arguments to be passed into the VSGSuite defined in the :meth:`~VSGSuite.make_parser` method. | [
"Generates",
"one",
"or",
"more",
"VSGSuite",
"instances",
"from",
"command",
"line",
"arguments",
"."
] | 640191bb018a1ff7d7b7a4982e0d3c1a423ba878 | https://github.com/dbarsam/python-vsgen/blob/640191bb018a1ff7d7b7a4982e0d3c1a423ba878/vsgen/suite.py#L137-L154 | train |
dbarsam/python-vsgen | vsgen/suite.py | VSGSuite.write | def write(self, parallel=True):
"""
Writes the configuration to disk.
"""
# Write the Solution files
solutions = sorted(self._solutions, key=lambda x: x.Name)
with VSGWriteCommand('Writing VSG Solution', solutions, parallel) as command:
command.execute()
... | python | def write(self, parallel=True):
"""
Writes the configuration to disk.
"""
# Write the Solution files
solutions = sorted(self._solutions, key=lambda x: x.Name)
with VSGWriteCommand('Writing VSG Solution', solutions, parallel) as command:
command.execute()
... | [
"def",
"write",
"(",
"self",
",",
"parallel",
"=",
"True",
")",
":",
"solutions",
"=",
"sorted",
"(",
"self",
".",
"_solutions",
",",
"key",
"=",
"lambda",
"x",
":",
"x",
".",
"Name",
")",
"with",
"VSGWriteCommand",
"(",
"'Writing VSG Solution'",
",",
... | Writes the configuration to disk. | [
"Writes",
"the",
"configuration",
"to",
"disk",
"."
] | 640191bb018a1ff7d7b7a4982e0d3c1a423ba878 | https://github.com/dbarsam/python-vsgen/blob/640191bb018a1ff7d7b7a4982e0d3c1a423ba878/vsgen/suite.py#L176-L193 | train |
Phyks/libbmc | libbmc/citations/bbl.py | bibitem_as_plaintext | def bibitem_as_plaintext(bibitem):
"""
Return a plaintext representation of a bibitem from the ``.bbl`` file.
.. note::
This plaintext representation can be super ugly, contain URLs and so \
on.
.. note::
You need to have ``delatex`` installed system-wide, or to build it in \... | python | def bibitem_as_plaintext(bibitem):
"""
Return a plaintext representation of a bibitem from the ``.bbl`` file.
.. note::
This plaintext representation can be super ugly, contain URLs and so \
on.
.. note::
You need to have ``delatex`` installed system-wide, or to build it in \... | [
"def",
"bibitem_as_plaintext",
"(",
"bibitem",
")",
":",
"try",
":",
"output",
"=",
"subprocess",
".",
"check_output",
"(",
"[",
"\"delatex\"",
",",
"\"-s\"",
"]",
",",
"input",
"=",
"bibitem",
".",
"encode",
"(",
"\"utf-8\"",
")",
")",
"except",
"FileNotF... | Return a plaintext representation of a bibitem from the ``.bbl`` file.
.. note::
This plaintext representation can be super ugly, contain URLs and so \
on.
.. note::
You need to have ``delatex`` installed system-wide, or to build it in \
this repo, according to the ``... | [
"Return",
"a",
"plaintext",
"representation",
"of",
"a",
"bibitem",
"from",
"the",
".",
"bbl",
"file",
"."
] | 9ef1a29d2514157d1edd6c13ecbd61b07ae9315e | https://github.com/Phyks/libbmc/blob/9ef1a29d2514157d1edd6c13ecbd61b07ae9315e/libbmc/citations/bbl.py#L19-L49 | train |
jenisys/parse_type | parse_type/cardinality_field.py | CardinalityField.split_type | def split_type(cls, type_name):
"""Split type of a type name with CardinalityField suffix into its parts.
:param type_name: Type name (as string).
:return: Tuple (type_basename, cardinality)
"""
if cls.matches_type(type_name):
basename = type_name[:-1]
c... | python | def split_type(cls, type_name):
"""Split type of a type name with CardinalityField suffix into its parts.
:param type_name: Type name (as string).
:return: Tuple (type_basename, cardinality)
"""
if cls.matches_type(type_name):
basename = type_name[:-1]
c... | [
"def",
"split_type",
"(",
"cls",
",",
"type_name",
")",
":",
"if",
"cls",
".",
"matches_type",
"(",
"type_name",
")",
":",
"basename",
"=",
"type_name",
"[",
":",
"-",
"1",
"]",
"cardinality",
"=",
"cls",
".",
"from_char_map",
"[",
"type_name",
"[",
"-... | Split type of a type name with CardinalityField suffix into its parts.
:param type_name: Type name (as string).
:return: Tuple (type_basename, cardinality) | [
"Split",
"type",
"of",
"a",
"type",
"name",
"with",
"CardinalityField",
"suffix",
"into",
"its",
"parts",
"."
] | 7cad3a67a5ca725cb786da31f656fd473084289f | https://github.com/jenisys/parse_type/blob/7cad3a67a5ca725cb786da31f656fd473084289f/parse_type/cardinality_field.py#L48-L61 | train |
jenisys/parse_type | parse_type/cardinality_field.py | CardinalityField.make_type | def make_type(cls, basename, cardinality):
"""Build new type name according to CardinalityField naming scheme.
:param basename: Type basename of primary type (as string).
:param cardinality: Cardinality of the new type (as Cardinality item).
:return: Type name with CardinalityField suf... | python | def make_type(cls, basename, cardinality):
"""Build new type name according to CardinalityField naming scheme.
:param basename: Type basename of primary type (as string).
:param cardinality: Cardinality of the new type (as Cardinality item).
:return: Type name with CardinalityField suf... | [
"def",
"make_type",
"(",
"cls",
",",
"basename",
",",
"cardinality",
")",
":",
"if",
"cardinality",
"is",
"Cardinality",
".",
"one",
":",
"return",
"basename",
"type_name",
"=",
"\"%s%s\"",
"%",
"(",
"basename",
",",
"cls",
".",
"to_char_map",
"[",
"cardin... | Build new type name according to CardinalityField naming scheme.
:param basename: Type basename of primary type (as string).
:param cardinality: Cardinality of the new type (as Cardinality item).
:return: Type name with CardinalityField suffix (if needed) | [
"Build",
"new",
"type",
"name",
"according",
"to",
"CardinalityField",
"naming",
"scheme",
"."
] | 7cad3a67a5ca725cb786da31f656fd473084289f | https://github.com/jenisys/parse_type/blob/7cad3a67a5ca725cb786da31f656fd473084289f/parse_type/cardinality_field.py#L64-L77 | train |
jenisys/parse_type | parse_type/cardinality_field.py | CardinalityFieldTypeBuilder.create_missing_type_variants | def create_missing_type_variants(cls, type_names, type_dict):
"""
Create missing type variants for types with a cardinality field.
:param type_names: List of type names with cardinality field suffix.
:param type_dict: Type dictionary with named type converters.
:return: Type di... | python | def create_missing_type_variants(cls, type_names, type_dict):
"""
Create missing type variants for types with a cardinality field.
:param type_names: List of type names with cardinality field suffix.
:param type_dict: Type dictionary with named type converters.
:return: Type di... | [
"def",
"create_missing_type_variants",
"(",
"cls",
",",
"type_names",
",",
"type_dict",
")",
":",
"missing_type_names",
"=",
"[",
"name",
"for",
"name",
"in",
"type_names",
"if",
"name",
"not",
"in",
"type_dict",
"]",
"return",
"cls",
".",
"create_type_variants"... | Create missing type variants for types with a cardinality field.
:param type_names: List of type names with cardinality field suffix.
:param type_dict: Type dictionary with named type converters.
:return: Type dictionary with missing type converter variants. | [
"Create",
"missing",
"type",
"variants",
"for",
"types",
"with",
"a",
"cardinality",
"field",
"."
] | 7cad3a67a5ca725cb786da31f656fd473084289f | https://github.com/jenisys/parse_type/blob/7cad3a67a5ca725cb786da31f656fd473084289f/parse_type/cardinality_field.py#L162-L172 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/bakery/_store.py | MemoryOpsStore.put_ops | def put_ops(self, key, time, ops):
''' Put an ops only if not already there, otherwise it's a no op.
'''
if self._store.get(key) is None:
self._store[key] = ops | python | def put_ops(self, key, time, ops):
''' Put an ops only if not already there, otherwise it's a no op.
'''
if self._store.get(key) is None:
self._store[key] = ops | [
"def",
"put_ops",
"(",
"self",
",",
"key",
",",
"time",
",",
"ops",
")",
":",
"if",
"self",
".",
"_store",
".",
"get",
"(",
"key",
")",
"is",
"None",
":",
"self",
".",
"_store",
"[",
"key",
"]",
"=",
"ops"
] | Put an ops only if not already there, otherwise it's a no op. | [
"Put",
"an",
"ops",
"only",
"if",
"not",
"already",
"there",
"otherwise",
"it",
"s",
"a",
"no",
"op",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/bakery/_store.py#L13-L17 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/bakery/_store.py | MemoryOpsStore.get_ops | def get_ops(self, key):
''' Returns ops from the key if found otherwise raises a KeyError.
'''
ops = self._store.get(key)
if ops is None:
raise KeyError(
'cannot get operations for {}'.format(key))
return ops | python | def get_ops(self, key):
''' Returns ops from the key if found otherwise raises a KeyError.
'''
ops = self._store.get(key)
if ops is None:
raise KeyError(
'cannot get operations for {}'.format(key))
return ops | [
"def",
"get_ops",
"(",
"self",
",",
"key",
")",
":",
"ops",
"=",
"self",
".",
"_store",
".",
"get",
"(",
"key",
")",
"if",
"ops",
"is",
"None",
":",
"raise",
"KeyError",
"(",
"'cannot get operations for {}'",
".",
"format",
"(",
"key",
")",
")",
"ret... | Returns ops from the key if found otherwise raises a KeyError. | [
"Returns",
"ops",
"from",
"the",
"key",
"if",
"found",
"otherwise",
"raises",
"a",
"KeyError",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/bakery/_store.py#L19-L26 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/bakery/_macaroon.py | _parse_local_location | def _parse_local_location(loc):
'''Parse a local caveat location as generated by LocalThirdPartyCaveat.
This is of the form:
local <version> <pubkey>
where <version> is the bakery version of the client that we're
adding the local caveat for.
It returns None if the location does not repre... | python | def _parse_local_location(loc):
'''Parse a local caveat location as generated by LocalThirdPartyCaveat.
This is of the form:
local <version> <pubkey>
where <version> is the bakery version of the client that we're
adding the local caveat for.
It returns None if the location does not repre... | [
"def",
"_parse_local_location",
"(",
"loc",
")",
":",
"if",
"not",
"(",
"loc",
".",
"startswith",
"(",
"'local '",
")",
")",
":",
"return",
"None",
"v",
"=",
"VERSION_1",
"fields",
"=",
"loc",
".",
"split",
"(",
")",
"fields",
"=",
"fields",
"[",
"1"... | Parse a local caveat location as generated by LocalThirdPartyCaveat.
This is of the form:
local <version> <pubkey>
where <version> is the bakery version of the client that we're
adding the local caveat for.
It returns None if the location does not represent a local
caveat location.
@... | [
"Parse",
"a",
"local",
"caveat",
"location",
"as",
"generated",
"by",
"LocalThirdPartyCaveat",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/bakery/_macaroon.py#L372-L400 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/bakery/_macaroon.py | Macaroon.add_caveat | def add_caveat(self, cav, key=None, loc=None):
'''Add a caveat to the macaroon.
It encrypts it using the given key pair
and by looking up the location using the given locator.
As a special case, if the caveat's Location field has the prefix
"local " the caveat is added as a clie... | python | def add_caveat(self, cav, key=None, loc=None):
'''Add a caveat to the macaroon.
It encrypts it using the given key pair
and by looking up the location using the given locator.
As a special case, if the caveat's Location field has the prefix
"local " the caveat is added as a clie... | [
"def",
"add_caveat",
"(",
"self",
",",
"cav",
",",
"key",
"=",
"None",
",",
"loc",
"=",
"None",
")",
":",
"if",
"cav",
".",
"location",
"is",
"None",
":",
"self",
".",
"_macaroon",
".",
"add_first_party_caveat",
"(",
"self",
".",
"namespace",
".",
"r... | Add a caveat to the macaroon.
It encrypts it using the given key pair
and by looking up the location using the given locator.
As a special case, if the caveat's Location field has the prefix
"local " the caveat is added as a client self-discharge caveat using
the public key base... | [
"Add",
"a",
"caveat",
"to",
"the",
"macaroon",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/bakery/_macaroon.py#L90-L150 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/bakery/_macaroon.py | Macaroon.add_caveats | def add_caveats(self, cavs, key, loc):
'''Add an array of caveats to the macaroon.
This method does not mutate the current object.
@param cavs arrary of caveats.
@param key the PublicKey to encrypt third party caveat.
@param loc locator to find the location object that has a met... | python | def add_caveats(self, cavs, key, loc):
'''Add an array of caveats to the macaroon.
This method does not mutate the current object.
@param cavs arrary of caveats.
@param key the PublicKey to encrypt third party caveat.
@param loc locator to find the location object that has a met... | [
"def",
"add_caveats",
"(",
"self",
",",
"cavs",
",",
"key",
",",
"loc",
")",
":",
"if",
"cavs",
"is",
"None",
":",
"return",
"for",
"cav",
"in",
"cavs",
":",
"self",
".",
"add_caveat",
"(",
"cav",
",",
"key",
",",
"loc",
")"
] | Add an array of caveats to the macaroon.
This method does not mutate the current object.
@param cavs arrary of caveats.
@param key the PublicKey to encrypt third party caveat.
@param loc locator to find the location object that has a method
third_party_info. | [
"Add",
"an",
"array",
"of",
"caveats",
"to",
"the",
"macaroon",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/bakery/_macaroon.py#L152-L164 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/bakery/_macaroon.py | Macaroon.to_dict | def to_dict(self):
'''Return a dict representation of the macaroon data in JSON format.
@return a dict
'''
if self.version < VERSION_3:
if len(self._caveat_data) > 0:
raise ValueError('cannot serialize pre-version3 macaroon with '
... | python | def to_dict(self):
'''Return a dict representation of the macaroon data in JSON format.
@return a dict
'''
if self.version < VERSION_3:
if len(self._caveat_data) > 0:
raise ValueError('cannot serialize pre-version3 macaroon with '
... | [
"def",
"to_dict",
"(",
"self",
")",
":",
"if",
"self",
".",
"version",
"<",
"VERSION_3",
":",
"if",
"len",
"(",
"self",
".",
"_caveat_data",
")",
">",
"0",
":",
"raise",
"ValueError",
"(",
"'cannot serialize pre-version3 macaroon with '",
"'external caveat data'... | Return a dict representation of the macaroon data in JSON format.
@return a dict | [
"Return",
"a",
"dict",
"representation",
"of",
"the",
"macaroon",
"data",
"in",
"JSON",
"format",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/bakery/_macaroon.py#L172-L196 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/bakery/_macaroon.py | Macaroon.from_dict | def from_dict(cls, json_dict):
'''Return a macaroon obtained from the given dictionary as
deserialized from JSON.
@param json_dict The deserialized JSON object.
'''
json_macaroon = json_dict.get('m')
if json_macaroon is None:
# Try the v1 format if we don't ha... | python | def from_dict(cls, json_dict):
'''Return a macaroon obtained from the given dictionary as
deserialized from JSON.
@param json_dict The deserialized JSON object.
'''
json_macaroon = json_dict.get('m')
if json_macaroon is None:
# Try the v1 format if we don't ha... | [
"def",
"from_dict",
"(",
"cls",
",",
"json_dict",
")",
":",
"json_macaroon",
"=",
"json_dict",
".",
"get",
"(",
"'m'",
")",
"if",
"json_macaroon",
"is",
"None",
":",
"m",
"=",
"pymacaroons",
".",
"Macaroon",
".",
"deserialize",
"(",
"json",
".",
"dumps",... | Return a macaroon obtained from the given dictionary as
deserialized from JSON.
@param json_dict The deserialized JSON object. | [
"Return",
"a",
"macaroon",
"obtained",
"from",
"the",
"given",
"dictionary",
"as",
"deserialized",
"from",
"JSON",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/bakery/_macaroon.py#L199-L239 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/bakery/_macaroon.py | Macaroon.deserialize_json | def deserialize_json(cls, serialized_json):
'''Return a macaroon deserialized from a string
@param serialized_json The string to decode {str}
@return {Macaroon}
'''
serialized = json.loads(serialized_json)
return Macaroon.from_dict(serialized) | python | def deserialize_json(cls, serialized_json):
'''Return a macaroon deserialized from a string
@param serialized_json The string to decode {str}
@return {Macaroon}
'''
serialized = json.loads(serialized_json)
return Macaroon.from_dict(serialized) | [
"def",
"deserialize_json",
"(",
"cls",
",",
"serialized_json",
")",
":",
"serialized",
"=",
"json",
".",
"loads",
"(",
"serialized_json",
")",
"return",
"Macaroon",
".",
"from_dict",
"(",
"serialized",
")"
] | Return a macaroon deserialized from a string
@param serialized_json The string to decode {str}
@return {Macaroon} | [
"Return",
"a",
"macaroon",
"deserialized",
"from",
"a",
"string"
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/bakery/_macaroon.py#L242-L248 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/bakery/_macaroon.py | Macaroon._new_caveat_id | def _new_caveat_id(self, base):
'''Return a third party caveat id
This does not duplicate any third party caveat ids already inside
macaroon. If base is non-empty, it is used as the id prefix.
@param base bytes
@return bytes
'''
id = bytearray()
if len(b... | python | def _new_caveat_id(self, base):
'''Return a third party caveat id
This does not duplicate any third party caveat ids already inside
macaroon. If base is non-empty, it is used as the id prefix.
@param base bytes
@return bytes
'''
id = bytearray()
if len(b... | [
"def",
"_new_caveat_id",
"(",
"self",
",",
"base",
")",
":",
"id",
"=",
"bytearray",
"(",
")",
"if",
"len",
"(",
"base",
")",
">",
"0",
":",
"id",
".",
"extend",
"(",
"base",
")",
"else",
":",
"id",
".",
"append",
"(",
"VERSION_3",
")",
"i",
"=... | Return a third party caveat id
This does not duplicate any third party caveat ids already inside
macaroon. If base is non-empty, it is used as the id prefix.
@param base bytes
@return bytes | [
"Return",
"a",
"third",
"party",
"caveat",
"id"
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/bakery/_macaroon.py#L250-L293 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/httpbakery/_client.py | extract_macaroons | def extract_macaroons(headers_or_request):
''' Returns an array of any macaroons found in the given slice of cookies.
If the argument implements a get_header method, that will be used
instead of the get method to retrieve headers.
@param headers_or_request: dict of headers or a
urllib.request.Reques... | python | def extract_macaroons(headers_or_request):
''' Returns an array of any macaroons found in the given slice of cookies.
If the argument implements a get_header method, that will be used
instead of the get method to retrieve headers.
@param headers_or_request: dict of headers or a
urllib.request.Reques... | [
"def",
"extract_macaroons",
"(",
"headers_or_request",
")",
":",
"def",
"get_header",
"(",
"key",
",",
"default",
"=",
"None",
")",
":",
"try",
":",
"return",
"headers_or_request",
".",
"get_header",
"(",
"key",
",",
"default",
")",
"except",
"AttributeError",... | Returns an array of any macaroons found in the given slice of cookies.
If the argument implements a get_header method, that will be used
instead of the get method to retrieve headers.
@param headers_or_request: dict of headers or a
urllib.request.Request-like object.
@return: A list of list of mpy m... | [
"Returns",
"an",
"array",
"of",
"any",
"macaroons",
"found",
"in",
"the",
"given",
"slice",
"of",
"cookies",
".",
"If",
"the",
"argument",
"implements",
"a",
"get_header",
"method",
"that",
"will",
"be",
"used",
"instead",
"of",
"the",
"get",
"method",
"to... | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/httpbakery/_client.py#L302-L344 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/httpbakery/_client.py | _wait_for_macaroon | def _wait_for_macaroon(wait_url):
''' Returns a macaroon from a legacy wait endpoint.
'''
headers = {
BAKERY_PROTOCOL_HEADER: str(bakery.LATEST_VERSION)
}
resp = requests.get(url=wait_url, headers=headers)
if resp.status_code != 200:
raise InteractionError('cannot get {}'.format(... | python | def _wait_for_macaroon(wait_url):
''' Returns a macaroon from a legacy wait endpoint.
'''
headers = {
BAKERY_PROTOCOL_HEADER: str(bakery.LATEST_VERSION)
}
resp = requests.get(url=wait_url, headers=headers)
if resp.status_code != 200:
raise InteractionError('cannot get {}'.format(... | [
"def",
"_wait_for_macaroon",
"(",
"wait_url",
")",
":",
"headers",
"=",
"{",
"BAKERY_PROTOCOL_HEADER",
":",
"str",
"(",
"bakery",
".",
"LATEST_VERSION",
")",
"}",
"resp",
"=",
"requests",
".",
"get",
"(",
"url",
"=",
"wait_url",
",",
"headers",
"=",
"heade... | Returns a macaroon from a legacy wait endpoint. | [
"Returns",
"a",
"macaroon",
"from",
"a",
"legacy",
"wait",
"endpoint",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/httpbakery/_client.py#L361-L371 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/httpbakery/_client.py | Client.handle_error | def handle_error(self, error, url):
'''Try to resolve the given error, which should be a response
to the given URL, by discharging any macaroon contained in
it. That is, if error.code is ERR_DISCHARGE_REQUIRED
then it will try to discharge err.info.macaroon. If the discharge
succ... | python | def handle_error(self, error, url):
'''Try to resolve the given error, which should be a response
to the given URL, by discharging any macaroon contained in
it. That is, if error.code is ERR_DISCHARGE_REQUIRED
then it will try to discharge err.info.macaroon. If the discharge
succ... | [
"def",
"handle_error",
"(",
"self",
",",
"error",
",",
"url",
")",
":",
"if",
"error",
".",
"info",
"is",
"None",
"or",
"error",
".",
"info",
".",
"macaroon",
"is",
"None",
":",
"raise",
"BakeryException",
"(",
"'unable to read info in discharge error '",
"'... | Try to resolve the given error, which should be a response
to the given URL, by discharging any macaroon contained in
it. That is, if error.code is ERR_DISCHARGE_REQUIRED
then it will try to discharge err.info.macaroon. If the discharge
succeeds, the discharged macaroon will be saved to ... | [
"Try",
"to",
"resolve",
"the",
"given",
"error",
"which",
"should",
"be",
"a",
"response",
"to",
"the",
"given",
"URL",
"by",
"discharging",
"any",
"macaroon",
"contained",
"in",
"it",
".",
"That",
"is",
"if",
"error",
".",
"code",
"is",
"ERR_DISCHARGE_REQ... | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/httpbakery/_client.py#L89-L121 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/httpbakery/_client.py | Client.acquire_discharge | def acquire_discharge(self, cav, payload):
''' Request a discharge macaroon from the caveat location
as an HTTP URL.
@param cav Third party {pymacaroons.Caveat} to be discharged.
@param payload External caveat data {bytes}.
@return The acquired macaroon {macaroonbakery.Macaroon}
... | python | def acquire_discharge(self, cav, payload):
''' Request a discharge macaroon from the caveat location
as an HTTP URL.
@param cav Third party {pymacaroons.Caveat} to be discharged.
@param payload External caveat data {bytes}.
@return The acquired macaroon {macaroonbakery.Macaroon}
... | [
"def",
"acquire_discharge",
"(",
"self",
",",
"cav",
",",
"payload",
")",
":",
"resp",
"=",
"self",
".",
"_acquire_discharge_with_token",
"(",
"cav",
",",
"payload",
",",
"None",
")",
"if",
"resp",
".",
"status_code",
"==",
"200",
":",
"return",
"bakery",
... | Request a discharge macaroon from the caveat location
as an HTTP URL.
@param cav Third party {pymacaroons.Caveat} to be discharged.
@param payload External caveat data {bytes}.
@return The acquired macaroon {macaroonbakery.Macaroon} | [
"Request",
"a",
"discharge",
"macaroon",
"from",
"the",
"caveat",
"location",
"as",
"an",
"HTTP",
"URL",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/httpbakery/_client.py#L123-L156 | train |
go-macaroon-bakery/py-macaroon-bakery | macaroonbakery/httpbakery/_client.py | Client._interact | def _interact(self, location, error_info, payload):
'''Gathers a macaroon by directing the user to interact with a
web page. The error_info argument holds the interaction-required
error response.
@return DischargeToken, bakery.Macaroon
'''
if (self._interaction_methods is... | python | def _interact(self, location, error_info, payload):
'''Gathers a macaroon by directing the user to interact with a
web page. The error_info argument holds the interaction-required
error response.
@return DischargeToken, bakery.Macaroon
'''
if (self._interaction_methods is... | [
"def",
"_interact",
"(",
"self",
",",
"location",
",",
"error_info",
",",
"payload",
")",
":",
"if",
"(",
"self",
".",
"_interaction_methods",
"is",
"None",
"or",
"len",
"(",
"self",
".",
"_interaction_methods",
")",
"==",
"0",
")",
":",
"raise",
"Intera... | Gathers a macaroon by directing the user to interact with a
web page. The error_info argument holds the interaction-required
error response.
@return DischargeToken, bakery.Macaroon | [
"Gathers",
"a",
"macaroon",
"by",
"directing",
"the",
"user",
"to",
"interact",
"with",
"a",
"web",
"page",
".",
"The",
"error_info",
"argument",
"holds",
"the",
"interaction",
"-",
"required",
"error",
"response",
"."
] | 63ce1ef1dabe816eb8aaec48fbb46761c34ddf77 | https://github.com/go-macaroon-bakery/py-macaroon-bakery/blob/63ce1ef1dabe816eb8aaec48fbb46761c34ddf77/macaroonbakery/httpbakery/_client.py#L173-L200 | train |
Phyks/libbmc | libbmc/bibtex.py | dict2bibtex | def dict2bibtex(data):
"""
Convert a single BibTeX entry dict to a BibTeX string.
:param data: A dict representing BibTeX entry, as the ones from \
``bibtexparser.BibDatabase.entries`` output.
:return: A formatted BibTeX string.
"""
bibtex = '@' + data['ENTRYTYPE'] + '{' + data['ID'... | python | def dict2bibtex(data):
"""
Convert a single BibTeX entry dict to a BibTeX string.
:param data: A dict representing BibTeX entry, as the ones from \
``bibtexparser.BibDatabase.entries`` output.
:return: A formatted BibTeX string.
"""
bibtex = '@' + data['ENTRYTYPE'] + '{' + data['ID'... | [
"def",
"dict2bibtex",
"(",
"data",
")",
":",
"bibtex",
"=",
"'@'",
"+",
"data",
"[",
"'ENTRYTYPE'",
"]",
"+",
"'{'",
"+",
"data",
"[",
"'ID'",
"]",
"+",
"\",\\n\"",
"for",
"field",
"in",
"[",
"i",
"for",
"i",
"in",
"sorted",
"(",
"data",
")",
"if... | Convert a single BibTeX entry dict to a BibTeX string.
:param data: A dict representing BibTeX entry, as the ones from \
``bibtexparser.BibDatabase.entries`` output.
:return: A formatted BibTeX string. | [
"Convert",
"a",
"single",
"BibTeX",
"entry",
"dict",
"to",
"a",
"BibTeX",
"string",
"."
] | 9ef1a29d2514157d1edd6c13ecbd61b07ae9315e | https://github.com/Phyks/libbmc/blob/9ef1a29d2514157d1edd6c13ecbd61b07ae9315e/libbmc/bibtex.py#L17-L30 | train |
Phyks/libbmc | libbmc/bibtex.py | write | def write(filename, data):
"""
Create a new BibTeX file.
:param filename: The name of the BibTeX file to write.
:param data: A ``bibtexparser.BibDatabase`` object.
"""
with open(filename, 'w') as fh:
fh.write(bibdatabase2bibtex(data)) | python | def write(filename, data):
"""
Create a new BibTeX file.
:param filename: The name of the BibTeX file to write.
:param data: A ``bibtexparser.BibDatabase`` object.
"""
with open(filename, 'w') as fh:
fh.write(bibdatabase2bibtex(data)) | [
"def",
"write",
"(",
"filename",
",",
"data",
")",
":",
"with",
"open",
"(",
"filename",
",",
"'w'",
")",
"as",
"fh",
":",
"fh",
".",
"write",
"(",
"bibdatabase2bibtex",
"(",
"data",
")",
")"
] | Create a new BibTeX file.
:param filename: The name of the BibTeX file to write.
:param data: A ``bibtexparser.BibDatabase`` object. | [
"Create",
"a",
"new",
"BibTeX",
"file",
"."
] | 9ef1a29d2514157d1edd6c13ecbd61b07ae9315e | https://github.com/Phyks/libbmc/blob/9ef1a29d2514157d1edd6c13ecbd61b07ae9315e/libbmc/bibtex.py#L43-L51 | train |
Phyks/libbmc | libbmc/bibtex.py | edit | def edit(filename, identifier, data):
"""
Update an entry in a BibTeX file.
:param filename: The name of the BibTeX file to edit.
:param identifier: The id of the entry to update, in the BibTeX file.
:param data: A dict associating fields and updated values. Fields present \
in the BibT... | python | def edit(filename, identifier, data):
"""
Update an entry in a BibTeX file.
:param filename: The name of the BibTeX file to edit.
:param identifier: The id of the entry to update, in the BibTeX file.
:param data: A dict associating fields and updated values. Fields present \
in the BibT... | [
"def",
"edit",
"(",
"filename",
",",
"identifier",
",",
"data",
")",
":",
"with",
"open",
"(",
"filename",
",",
"'r'",
")",
"as",
"fh",
":",
"bibtex",
"=",
"bibtexparser",
".",
"load",
"(",
"fh",
")",
"bibtex",
".",
"entries_dict",
"[",
"identifier",
... | Update an entry in a BibTeX file.
:param filename: The name of the BibTeX file to edit.
:param identifier: The id of the entry to update, in the BibTeX file.
:param data: A dict associating fields and updated values. Fields present \
in the BibTeX file but not in this dict will be kept as is. | [
"Update",
"an",
"entry",
"in",
"a",
"BibTeX",
"file",
"."
] | 9ef1a29d2514157d1edd6c13ecbd61b07ae9315e | https://github.com/Phyks/libbmc/blob/9ef1a29d2514157d1edd6c13ecbd61b07ae9315e/libbmc/bibtex.py#L65-L83 | train |
Phyks/libbmc | libbmc/bibtex.py | delete | def delete(filename, identifier):
"""
Delete an entry in a BibTeX file.
:param filename: The name of the BibTeX file to edit.
:param identifier: The id of the entry to delete, in the BibTeX file.
"""
# Get current bibtex
with open(filename, 'r') as fh:
bibtex = bibtexparser.load(fh)... | python | def delete(filename, identifier):
"""
Delete an entry in a BibTeX file.
:param filename: The name of the BibTeX file to edit.
:param identifier: The id of the entry to delete, in the BibTeX file.
"""
# Get current bibtex
with open(filename, 'r') as fh:
bibtex = bibtexparser.load(fh)... | [
"def",
"delete",
"(",
"filename",
",",
"identifier",
")",
":",
"with",
"open",
"(",
"filename",
",",
"'r'",
")",
"as",
"fh",
":",
"bibtex",
"=",
"bibtexparser",
".",
"load",
"(",
"fh",
")",
"try",
":",
"del",
"bibtex",
".",
"entries_dict",
"[",
"iden... | Delete an entry in a BibTeX file.
:param filename: The name of the BibTeX file to edit.
:param identifier: The id of the entry to delete, in the BibTeX file. | [
"Delete",
"an",
"entry",
"in",
"a",
"BibTeX",
"file",
"."
] | 9ef1a29d2514157d1edd6c13ecbd61b07ae9315e | https://github.com/Phyks/libbmc/blob/9ef1a29d2514157d1edd6c13ecbd61b07ae9315e/libbmc/bibtex.py#L107-L126 | train |
Phyks/libbmc | libbmc/bibtex.py | get | def get(filename, ignore_fields=None):
"""
Get all entries from a BibTeX file.
:param filename: The name of the BibTeX file.
:param ignore_fields: An optional list of fields to strip from the BibTeX \
file.
:returns: A ``bibtexparser.BibDatabase`` object representing the fetched \
... | python | def get(filename, ignore_fields=None):
"""
Get all entries from a BibTeX file.
:param filename: The name of the BibTeX file.
:param ignore_fields: An optional list of fields to strip from the BibTeX \
file.
:returns: A ``bibtexparser.BibDatabase`` object representing the fetched \
... | [
"def",
"get",
"(",
"filename",
",",
"ignore_fields",
"=",
"None",
")",
":",
"if",
"ignore_fields",
"is",
"None",
":",
"ignore_fields",
"=",
"[",
"]",
"with",
"open",
"(",
"filename",
",",
"'r'",
")",
"as",
"fh",
":",
"bibtex",
"=",
"bibtexparser",
".",... | Get all entries from a BibTeX file.
:param filename: The name of the BibTeX file.
:param ignore_fields: An optional list of fields to strip from the BibTeX \
file.
:returns: A ``bibtexparser.BibDatabase`` object representing the fetched \
entries. | [
"Get",
"all",
"entries",
"from",
"a",
"BibTeX",
"file",
"."
] | 9ef1a29d2514157d1edd6c13ecbd61b07ae9315e | https://github.com/Phyks/libbmc/blob/9ef1a29d2514157d1edd6c13ecbd61b07ae9315e/libbmc/bibtex.py#L129-L153 | train |
Phyks/libbmc | libbmc/bibtex.py | to_filename | def to_filename(data,
mask=DEFAULT_PAPERS_FILENAME_MASK,
extra_formatters=None):
"""
Convert a bibtex entry to a formatted filename according to a given mask.
.. note ::
Available formatters out of the box are:
- ``journal``
- ``title``
... | python | def to_filename(data,
mask=DEFAULT_PAPERS_FILENAME_MASK,
extra_formatters=None):
"""
Convert a bibtex entry to a formatted filename according to a given mask.
.. note ::
Available formatters out of the box are:
- ``journal``
- ``title``
... | [
"def",
"to_filename",
"(",
"data",
",",
"mask",
"=",
"DEFAULT_PAPERS_FILENAME_MASK",
",",
"extra_formatters",
"=",
"None",
")",
":",
"if",
"extra_formatters",
"is",
"None",
":",
"extra_formatters",
"=",
"{",
"}",
"entry",
"=",
"data",
".",
"entries",
"[",
"0... | Convert a bibtex entry to a formatted filename according to a given mask.
.. note ::
Available formatters out of the box are:
- ``journal``
- ``title``
- ``year``
- ``first`` for the first author
- ``last`` for the last author
- ``aut... | [
"Convert",
"a",
"bibtex",
"entry",
"to",
"a",
"formatted",
"filename",
"according",
"to",
"a",
"given",
"mask",
"."
] | 9ef1a29d2514157d1edd6c13ecbd61b07ae9315e | https://github.com/Phyks/libbmc/blob/9ef1a29d2514157d1edd6c13ecbd61b07ae9315e/libbmc/bibtex.py#L224-L285 | train |
ets-labs/python-domain-models | domain_models/fields.py | Field.bind_name | def bind_name(self, name):
"""Bind field to its name in model class."""
if self.name:
raise errors.Error('Already bound "{0}" with name "{1}" could not '
'be rebound'.format(self, self.name))
self.name = name
self.storage_name = ''.join(('_', se... | python | def bind_name(self, name):
"""Bind field to its name in model class."""
if self.name:
raise errors.Error('Already bound "{0}" with name "{1}" could not '
'be rebound'.format(self, self.name))
self.name = name
self.storage_name = ''.join(('_', se... | [
"def",
"bind_name",
"(",
"self",
",",
"name",
")",
":",
"if",
"self",
".",
"name",
":",
"raise",
"errors",
".",
"Error",
"(",
"'Already bound \"{0}\" with name \"{1}\" could not '",
"'be rebound'",
".",
"format",
"(",
"self",
",",
"self",
".",
"name",
")",
"... | Bind field to its name in model class. | [
"Bind",
"field",
"to",
"its",
"name",
"in",
"model",
"class",
"."
] | 7de1816ba0338f20fdb3e0f57fad0ffd5bea13f9 | https://github.com/ets-labs/python-domain-models/blob/7de1816ba0338f20fdb3e0f57fad0ffd5bea13f9/domain_models/fields.py#L24-L31 | train |
ets-labs/python-domain-models | domain_models/fields.py | Field.bind_model_cls | def bind_model_cls(self, model_cls):
"""Bind field to model class."""
if self.model_cls:
raise errors.Error('"{0}" has been already bound to "{1}" and '
'could not be rebound to "{2}"'.format(
self, self.model_cls, model_cls))... | python | def bind_model_cls(self, model_cls):
"""Bind field to model class."""
if self.model_cls:
raise errors.Error('"{0}" has been already bound to "{1}" and '
'could not be rebound to "{2}"'.format(
self, self.model_cls, model_cls))... | [
"def",
"bind_model_cls",
"(",
"self",
",",
"model_cls",
")",
":",
"if",
"self",
".",
"model_cls",
":",
"raise",
"errors",
".",
"Error",
"(",
"'\"{0}\" has been already bound to \"{1}\" and '",
"'could not be rebound to \"{2}\"'",
".",
"format",
"(",
"self",
",",
"se... | Bind field to model class. | [
"Bind",
"field",
"to",
"model",
"class",
"."
] | 7de1816ba0338f20fdb3e0f57fad0ffd5bea13f9 | https://github.com/ets-labs/python-domain-models/blob/7de1816ba0338f20fdb3e0f57fad0ffd5bea13f9/domain_models/fields.py#L33-L40 | train |
ets-labs/python-domain-models | domain_models/fields.py | Field.init_model | def init_model(self, model, value):
"""Init model with field.
:param DomainModel model:
:param object value:
"""
if value is None and self.default is not None:
value = self.default() if callable(self.default) else self.default
self.set_value(model, value) | python | def init_model(self, model, value):
"""Init model with field.
:param DomainModel model:
:param object value:
"""
if value is None and self.default is not None:
value = self.default() if callable(self.default) else self.default
self.set_value(model, value) | [
"def",
"init_model",
"(",
"self",
",",
"model",
",",
"value",
")",
":",
"if",
"value",
"is",
"None",
"and",
"self",
".",
"default",
"is",
"not",
"None",
":",
"value",
"=",
"self",
".",
"default",
"(",
")",
"if",
"callable",
"(",
"self",
".",
"defau... | Init model with field.
:param DomainModel model:
:param object value: | [
"Init",
"model",
"with",
"field",
"."
] | 7de1816ba0338f20fdb3e0f57fad0ffd5bea13f9 | https://github.com/ets-labs/python-domain-models/blob/7de1816ba0338f20fdb3e0f57fad0ffd5bea13f9/domain_models/fields.py#L42-L51 | train |
ets-labs/python-domain-models | domain_models/fields.py | Field.get_value | def get_value(self, model, default=None):
"""Return field's value.
:param DomainModel model:
:param object default:
:rtype object:
"""
if default is not None:
default = self._converter(default)
value = getattr(model, self.storage_name)
return... | python | def get_value(self, model, default=None):
"""Return field's value.
:param DomainModel model:
:param object default:
:rtype object:
"""
if default is not None:
default = self._converter(default)
value = getattr(model, self.storage_name)
return... | [
"def",
"get_value",
"(",
"self",
",",
"model",
",",
"default",
"=",
"None",
")",
":",
"if",
"default",
"is",
"not",
"None",
":",
"default",
"=",
"self",
".",
"_converter",
"(",
"default",
")",
"value",
"=",
"getattr",
"(",
"model",
",",
"self",
".",
... | Return field's value.
:param DomainModel model:
:param object default:
:rtype object: | [
"Return",
"field",
"s",
"value",
"."
] | 7de1816ba0338f20fdb3e0f57fad0ffd5bea13f9 | https://github.com/ets-labs/python-domain-models/blob/7de1816ba0338f20fdb3e0f57fad0ffd5bea13f9/domain_models/fields.py#L53-L64 | train |
ets-labs/python-domain-models | domain_models/fields.py | Field.set_value | def set_value(self, model, value):
"""Set field's value.
:param DomainModel model:
:param object value:
"""
if value is None and self.required:
raise AttributeError("This field is required.")
if value is not None:
value = self._converter(value)
... | python | def set_value(self, model, value):
"""Set field's value.
:param DomainModel model:
:param object value:
"""
if value is None and self.required:
raise AttributeError("This field is required.")
if value is not None:
value = self._converter(value)
... | [
"def",
"set_value",
"(",
"self",
",",
"model",
",",
"value",
")",
":",
"if",
"value",
"is",
"None",
"and",
"self",
".",
"required",
":",
"raise",
"AttributeError",
"(",
"\"This field is required.\"",
")",
"if",
"value",
"is",
"not",
"None",
":",
"value",
... | Set field's value.
:param DomainModel model:
:param object value: | [
"Set",
"field",
"s",
"value",
"."
] | 7de1816ba0338f20fdb3e0f57fad0ffd5bea13f9 | https://github.com/ets-labs/python-domain-models/blob/7de1816ba0338f20fdb3e0f57fad0ffd5bea13f9/domain_models/fields.py#L66-L78 | train |
ets-labs/python-domain-models | domain_models/fields.py | Field._get_model_instance | def _get_model_instance(model_cls, data):
"""Convert dict into object of class of passed model.
:param class model_cls:
:param object data:
:rtype DomainModel:
"""
if not isinstance(data, (model_cls, dict)):
raise TypeError('{0} is not valid type, instance of... | python | def _get_model_instance(model_cls, data):
"""Convert dict into object of class of passed model.
:param class model_cls:
:param object data:
:rtype DomainModel:
"""
if not isinstance(data, (model_cls, dict)):
raise TypeError('{0} is not valid type, instance of... | [
"def",
"_get_model_instance",
"(",
"model_cls",
",",
"data",
")",
":",
"if",
"not",
"isinstance",
"(",
"data",
",",
"(",
"model_cls",
",",
"dict",
")",
")",
":",
"raise",
"TypeError",
"(",
"'{0} is not valid type, instance of '",
"'{1} or dict required'",
".",
"... | Convert dict into object of class of passed model.
:param class model_cls:
:param object data:
:rtype DomainModel: | [
"Convert",
"dict",
"into",
"object",
"of",
"class",
"of",
"passed",
"model",
"."
] | 7de1816ba0338f20fdb3e0f57fad0ffd5bea13f9 | https://github.com/ets-labs/python-domain-models/blob/7de1816ba0338f20fdb3e0f57fad0ffd5bea13f9/domain_models/fields.py#L97-L107 | train |
ets-labs/python-domain-models | domain_models/fields.py | Collection.get_builtin_type | def get_builtin_type(self, model):
"""Return built-in type representation of Collection.
:param DomainModel model:
:rtype list:
"""
return [item.get_data() if isinstance(item, self.related_model_cls)
else item for item in self.get_value(model)] | python | def get_builtin_type(self, model):
"""Return built-in type representation of Collection.
:param DomainModel model:
:rtype list:
"""
return [item.get_data() if isinstance(item, self.related_model_cls)
else item for item in self.get_value(model)] | [
"def",
"get_builtin_type",
"(",
"self",
",",
"model",
")",
":",
"return",
"[",
"item",
".",
"get_data",
"(",
")",
"if",
"isinstance",
"(",
"item",
",",
"self",
".",
"related_model_cls",
")",
"else",
"item",
"for",
"item",
"in",
"self",
".",
"get_value",
... | Return built-in type representation of Collection.
:param DomainModel model:
:rtype list: | [
"Return",
"built",
"-",
"in",
"type",
"representation",
"of",
"Collection",
"."
] | 7de1816ba0338f20fdb3e0f57fad0ffd5bea13f9 | https://github.com/ets-labs/python-domain-models/blob/7de1816ba0338f20fdb3e0f57fad0ffd5bea13f9/domain_models/fields.py#L215-L222 | train |
useblocks/groundwork | groundwork/util.py | gw_get | def gw_get(object_dict, name=None, plugin=None):
"""
Getter function to retrieve objects from a given object dictionary.
Used mainly to provide get() inside patterns.
:param object_dict: objects, which must have 'name' and 'plugin' as attribute
:type object_dict: dictionary
:param name: name o... | python | def gw_get(object_dict, name=None, plugin=None):
"""
Getter function to retrieve objects from a given object dictionary.
Used mainly to provide get() inside patterns.
:param object_dict: objects, which must have 'name' and 'plugin' as attribute
:type object_dict: dictionary
:param name: name o... | [
"def",
"gw_get",
"(",
"object_dict",
",",
"name",
"=",
"None",
",",
"plugin",
"=",
"None",
")",
":",
"if",
"plugin",
"is",
"not",
"None",
":",
"if",
"name",
"is",
"None",
":",
"object_list",
"=",
"{",
"}",
"for",
"key",
"in",
"object_dict",
".",
"k... | Getter function to retrieve objects from a given object dictionary.
Used mainly to provide get() inside patterns.
:param object_dict: objects, which must have 'name' and 'plugin' as attribute
:type object_dict: dictionary
:param name: name of the object
:type name: str
:param plugin: plugin na... | [
"Getter",
"function",
"to",
"retrieve",
"objects",
"from",
"a",
"given",
"object",
"dictionary",
"."
] | d34fce43f54246ca4db0f7b89e450dcdc847c68c | https://github.com/useblocks/groundwork/blob/d34fce43f54246ca4db0f7b89e450dcdc847c68c/groundwork/util.py#L1-L36 | train |
eonpatapon/contrail-api-cli | contrail_api_cli/resource.py | http_error_handler | def http_error_handler(f):
"""Handle 404 errors returned by the API server
"""
def hrefs_to_resources(hrefs):
for href in hrefs.replace(',', '').split():
type, uuid = href.split('/')[-2:]
yield Resource(type, uuid=uuid)
def hrefs_list_to_resources(hrefs_list):
f... | python | def http_error_handler(f):
"""Handle 404 errors returned by the API server
"""
def hrefs_to_resources(hrefs):
for href in hrefs.replace(',', '').split():
type, uuid = href.split('/')[-2:]
yield Resource(type, uuid=uuid)
def hrefs_list_to_resources(hrefs_list):
f... | [
"def",
"http_error_handler",
"(",
"f",
")",
":",
"def",
"hrefs_to_resources",
"(",
"hrefs",
")",
":",
"for",
"href",
"in",
"hrefs",
".",
"replace",
"(",
"','",
",",
"''",
")",
".",
"split",
"(",
")",
":",
"type",
",",
"uuid",
"=",
"href",
".",
"spl... | Handle 404 errors returned by the API server | [
"Handle",
"404",
"errors",
"returned",
"by",
"the",
"API",
"server"
] | 1571bf523fa054f3d6bf83dba43a224fea173a73 | https://github.com/eonpatapon/contrail-api-cli/blob/1571bf523fa054f3d6bf83dba43a224fea173a73/contrail_api_cli/resource.py#L30-L77 | train |
eonpatapon/contrail-api-cli | contrail_api_cli/resource.py | ResourceBase.href | def href(self):
"""Return URL of the resource
:rtype: str
"""
url = self.session.base_url + str(self.path)
if self.path.is_collection and not self.path.is_root:
return url + 's'
return url | python | def href(self):
"""Return URL of the resource
:rtype: str
"""
url = self.session.base_url + str(self.path)
if self.path.is_collection and not self.path.is_root:
return url + 's'
return url | [
"def",
"href",
"(",
"self",
")",
":",
"url",
"=",
"self",
".",
"session",
".",
"base_url",
"+",
"str",
"(",
"self",
".",
"path",
")",
"if",
"self",
".",
"path",
".",
"is_collection",
"and",
"not",
"self",
".",
"path",
".",
"is_root",
":",
"return",... | Return URL of the resource
:rtype: str | [
"Return",
"URL",
"of",
"the",
"resource"
] | 1571bf523fa054f3d6bf83dba43a224fea173a73 | https://github.com/eonpatapon/contrail-api-cli/blob/1571bf523fa054f3d6bf83dba43a224fea173a73/contrail_api_cli/resource.py#L205-L213 | train |
eonpatapon/contrail-api-cli | contrail_api_cli/resource.py | Collection.filter | def filter(self, field_name, field_value):
"""Add permanent filter on the collection
:param field_name: name of the field to filter on
:type field_name: str
:param field_value: value to filter on
:rtype: Collection
"""
self.filters.append((field_name, field_valu... | python | def filter(self, field_name, field_value):
"""Add permanent filter on the collection
:param field_name: name of the field to filter on
:type field_name: str
:param field_value: value to filter on
:rtype: Collection
"""
self.filters.append((field_name, field_valu... | [
"def",
"filter",
"(",
"self",
",",
"field_name",
",",
"field_value",
")",
":",
"self",
".",
"filters",
".",
"append",
"(",
"(",
"field_name",
",",
"field_value",
")",
")",
"return",
"self"
] | Add permanent filter on the collection
:param field_name: name of the field to filter on
:type field_name: str
:param field_value: value to filter on
:rtype: Collection | [
"Add",
"permanent",
"filter",
"on",
"the",
"collection"
] | 1571bf523fa054f3d6bf83dba43a224fea173a73 | https://github.com/eonpatapon/contrail-api-cli/blob/1571bf523fa054f3d6bf83dba43a224fea173a73/contrail_api_cli/resource.py#L299-L309 | train |
eonpatapon/contrail-api-cli | contrail_api_cli/resource.py | Collection.fetch | def fetch(self, recursive=1, fields=None, detail=None,
filters=None, parent_uuid=None, back_refs_uuid=None):
"""
Fetch collection from API server
:param recursive: level of recursion
:type recursive: int
:param fields: fetch only listed fields.
... | python | def fetch(self, recursive=1, fields=None, detail=None,
filters=None, parent_uuid=None, back_refs_uuid=None):
"""
Fetch collection from API server
:param recursive: level of recursion
:type recursive: int
:param fields: fetch only listed fields.
... | [
"def",
"fetch",
"(",
"self",
",",
"recursive",
"=",
"1",
",",
"fields",
"=",
"None",
",",
"detail",
"=",
"None",
",",
"filters",
"=",
"None",
",",
"parent_uuid",
"=",
"None",
",",
"back_refs_uuid",
"=",
"None",
")",
":",
"params",
"=",
"self",
".",
... | Fetch collection from API server
:param recursive: level of recursion
:type recursive: int
:param fields: fetch only listed fields.
contrail 3.0 required
:type fields: [str]
:param detail: fetch all fields
:type detail: bool
:param filters:... | [
"Fetch",
"collection",
"from",
"API",
"server"
] | 1571bf523fa054f3d6bf83dba43a224fea173a73 | https://github.com/eonpatapon/contrail-api-cli/blob/1571bf523fa054f3d6bf83dba43a224fea173a73/contrail_api_cli/resource.py#L346-L393 | train |
eonpatapon/contrail-api-cli | contrail_api_cli/resource.py | Resource.check | def check(self):
"""Check that the resource exists.
:raises ResourceNotFound: if the resource doesn't exists
"""
if self.fq_name:
self['uuid'] = self._check_fq_name(self.fq_name)
elif self.uuid:
self['fq_name'] = self._check_uuid(self.uuid)
return... | python | def check(self):
"""Check that the resource exists.
:raises ResourceNotFound: if the resource doesn't exists
"""
if self.fq_name:
self['uuid'] = self._check_fq_name(self.fq_name)
elif self.uuid:
self['fq_name'] = self._check_uuid(self.uuid)
return... | [
"def",
"check",
"(",
"self",
")",
":",
"if",
"self",
".",
"fq_name",
":",
"self",
"[",
"'uuid'",
"]",
"=",
"self",
".",
"_check_fq_name",
"(",
"self",
".",
"fq_name",
")",
"elif",
"self",
".",
"uuid",
":",
"self",
"[",
"'fq_name'",
"]",
"=",
"self"... | Check that the resource exists.
:raises ResourceNotFound: if the resource doesn't exists | [
"Check",
"that",
"the",
"resource",
"exists",
"."
] | 1571bf523fa054f3d6bf83dba43a224fea173a73 | https://github.com/eonpatapon/contrail-api-cli/blob/1571bf523fa054f3d6bf83dba43a224fea173a73/contrail_api_cli/resource.py#L488-L497 | train |
eonpatapon/contrail-api-cli | contrail_api_cli/resource.py | Resource.fq_name | def fq_name(self):
"""Return FQDN of the resource
:rtype: FQName
"""
return self.get('fq_name', self.get('to', super(Resource, self).fq_name)) | python | def fq_name(self):
"""Return FQDN of the resource
:rtype: FQName
"""
return self.get('fq_name', self.get('to', super(Resource, self).fq_name)) | [
"def",
"fq_name",
"(",
"self",
")",
":",
"return",
"self",
".",
"get",
"(",
"'fq_name'",
",",
"self",
".",
"get",
"(",
"'to'",
",",
"super",
"(",
"Resource",
",",
"self",
")",
".",
"fq_name",
")",
")"
] | Return FQDN of the resource
:rtype: FQName | [
"Return",
"FQDN",
"of",
"the",
"resource"
] | 1571bf523fa054f3d6bf83dba43a224fea173a73 | https://github.com/eonpatapon/contrail-api-cli/blob/1571bf523fa054f3d6bf83dba43a224fea173a73/contrail_api_cli/resource.py#L529-L534 | train |
eonpatapon/contrail-api-cli | contrail_api_cli/resource.py | Resource.parent | def parent(self):
"""Return parent resource
:rtype: Resource
:raises ResourceNotFound: parent resource doesn't exists
:raises ResourceMissing: parent resource is not defined
"""
try:
return Resource(self['parent_type'], uuid=self['parent_uuid'], check=True)
... | python | def parent(self):
"""Return parent resource
:rtype: Resource
:raises ResourceNotFound: parent resource doesn't exists
:raises ResourceMissing: parent resource is not defined
"""
try:
return Resource(self['parent_type'], uuid=self['parent_uuid'], check=True)
... | [
"def",
"parent",
"(",
"self",
")",
":",
"try",
":",
"return",
"Resource",
"(",
"self",
"[",
"'parent_type'",
"]",
",",
"uuid",
"=",
"self",
"[",
"'parent_uuid'",
"]",
",",
"check",
"=",
"True",
")",
"except",
"KeyError",
":",
"raise",
"ResourceMissing",
... | Return parent resource
:rtype: Resource
:raises ResourceNotFound: parent resource doesn't exists
:raises ResourceMissing: parent resource is not defined | [
"Return",
"parent",
"resource"
] | 1571bf523fa054f3d6bf83dba43a224fea173a73 | https://github.com/eonpatapon/contrail-api-cli/blob/1571bf523fa054f3d6bf83dba43a224fea173a73/contrail_api_cli/resource.py#L537-L547 | train |
eonpatapon/contrail-api-cli | contrail_api_cli/resource.py | Resource.parent | def parent(self, resource):
"""Set parent resource
:param resource: parent resource
:type resource: Resource
:raises ResourceNotFound: resource not found on the API
"""
resource.check()
self['parent_type'] = resource.type
self['parent_uuid'] = resource.u... | python | def parent(self, resource):
"""Set parent resource
:param resource: parent resource
:type resource: Resource
:raises ResourceNotFound: resource not found on the API
"""
resource.check()
self['parent_type'] = resource.type
self['parent_uuid'] = resource.u... | [
"def",
"parent",
"(",
"self",
",",
"resource",
")",
":",
"resource",
".",
"check",
"(",
")",
"self",
"[",
"'parent_type'",
"]",
"=",
"resource",
".",
"type",
"self",
"[",
"'parent_uuid'",
"]",
"=",
"resource",
".",
"uuid"
] | Set parent resource
:param resource: parent resource
:type resource: Resource
:raises ResourceNotFound: resource not found on the API | [
"Set",
"parent",
"resource"
] | 1571bf523fa054f3d6bf83dba43a224fea173a73 | https://github.com/eonpatapon/contrail-api-cli/blob/1571bf523fa054f3d6bf83dba43a224fea173a73/contrail_api_cli/resource.py#L550-L560 | train |
eonpatapon/contrail-api-cli | contrail_api_cli/resource.py | Resource.created | def created(self):
"""Return creation date
:rtype: datetime
:raises ResourceNotFound: resource not found on the API
"""
if 'id_perms' not in self:
self.fetch()
created = self['id_perms']['created']
return datetime.strptime(created, '%Y-%m-%dT%H:%M:%S.... | python | def created(self):
"""Return creation date
:rtype: datetime
:raises ResourceNotFound: resource not found on the API
"""
if 'id_perms' not in self:
self.fetch()
created = self['id_perms']['created']
return datetime.strptime(created, '%Y-%m-%dT%H:%M:%S.... | [
"def",
"created",
"(",
"self",
")",
":",
"if",
"'id_perms'",
"not",
"in",
"self",
":",
"self",
".",
"fetch",
"(",
")",
"created",
"=",
"self",
"[",
"'id_perms'",
"]",
"[",
"'created'",
"]",
"return",
"datetime",
".",
"strptime",
"(",
"created",
",",
... | Return creation date
:rtype: datetime
:raises ResourceNotFound: resource not found on the API | [
"Return",
"creation",
"date"
] | 1571bf523fa054f3d6bf83dba43a224fea173a73 | https://github.com/eonpatapon/contrail-api-cli/blob/1571bf523fa054f3d6bf83dba43a224fea173a73/contrail_api_cli/resource.py#L563-L572 | train |
eonpatapon/contrail-api-cli | contrail_api_cli/resource.py | Resource.save | def save(self):
"""Save the resource to the API server
If the resource doesn't have a uuid the resource will be created.
If uuid is present the resource is updated.
:rtype: Resource
"""
if self.path.is_collection:
self.session.post_json(self.href,
... | python | def save(self):
"""Save the resource to the API server
If the resource doesn't have a uuid the resource will be created.
If uuid is present the resource is updated.
:rtype: Resource
"""
if self.path.is_collection:
self.session.post_json(self.href,
... | [
"def",
"save",
"(",
"self",
")",
":",
"if",
"self",
".",
"path",
".",
"is_collection",
":",
"self",
".",
"session",
".",
"post_json",
"(",
"self",
".",
"href",
",",
"{",
"self",
".",
"type",
":",
"dict",
"(",
"self",
".",
"data",
")",
"}",
",",
... | Save the resource to the API server
If the resource doesn't have a uuid the resource will be created.
If uuid is present the resource is updated.
:rtype: Resource | [
"Save",
"the",
"resource",
"to",
"the",
"API",
"server"
] | 1571bf523fa054f3d6bf83dba43a224fea173a73 | https://github.com/eonpatapon/contrail-api-cli/blob/1571bf523fa054f3d6bf83dba43a224fea173a73/contrail_api_cli/resource.py#L575-L591 | train |
eonpatapon/contrail-api-cli | contrail_api_cli/resource.py | Resource.delete | def delete(self):
"""Delete resource from the API server
"""
res = self.session.delete(self.href)
self.emit('deleted', self)
return res | python | def delete(self):
"""Delete resource from the API server
"""
res = self.session.delete(self.href)
self.emit('deleted', self)
return res | [
"def",
"delete",
"(",
"self",
")",
":",
"res",
"=",
"self",
".",
"session",
".",
"delete",
"(",
"self",
".",
"href",
")",
"self",
".",
"emit",
"(",
"'deleted'",
",",
"self",
")",
"return",
"res"
] | Delete resource from the API server | [
"Delete",
"resource",
"from",
"the",
"API",
"server"
] | 1571bf523fa054f3d6bf83dba43a224fea173a73 | https://github.com/eonpatapon/contrail-api-cli/blob/1571bf523fa054f3d6bf83dba43a224fea173a73/contrail_api_cli/resource.py#L594-L599 | train |
eonpatapon/contrail-api-cli | contrail_api_cli/resource.py | Resource.fetch | def fetch(self, recursive=1, exclude_children=False, exclude_back_refs=False):
"""Fetch resource from the API server
:param recursive: level of recursion for fetching resources
:type recursive: int
:param exclude_children: don't get children references
:type exclude_children: bo... | python | def fetch(self, recursive=1, exclude_children=False, exclude_back_refs=False):
"""Fetch resource from the API server
:param recursive: level of recursion for fetching resources
:type recursive: int
:param exclude_children: don't get children references
:type exclude_children: bo... | [
"def",
"fetch",
"(",
"self",
",",
"recursive",
"=",
"1",
",",
"exclude_children",
"=",
"False",
",",
"exclude_back_refs",
"=",
"False",
")",
":",
"if",
"not",
"self",
".",
"path",
".",
"is_resource",
"and",
"not",
"self",
".",
"path",
".",
"is_uuid",
"... | Fetch resource from the API server
:param recursive: level of recursion for fetching resources
:type recursive: int
:param exclude_children: don't get children references
:type exclude_children: bool
:param exclude_back_refs: don't get back_refs references
:type exclude_... | [
"Fetch",
"resource",
"from",
"the",
"API",
"server"
] | 1571bf523fa054f3d6bf83dba43a224fea173a73 | https://github.com/eonpatapon/contrail-api-cli/blob/1571bf523fa054f3d6bf83dba43a224fea173a73/contrail_api_cli/resource.py#L602-L624 | train |
eonpatapon/contrail-api-cli | contrail_api_cli/resource.py | Resource.from_dict | def from_dict(self, data, recursive=1):
"""Populate the resource from a python dict
:param recursive: level of recursion for fetching resources
:type recursive: int
"""
# Find other linked resources
data = self._encode_resource(data, recursive=recursive)
self.dat... | python | def from_dict(self, data, recursive=1):
"""Populate the resource from a python dict
:param recursive: level of recursion for fetching resources
:type recursive: int
"""
# Find other linked resources
data = self._encode_resource(data, recursive=recursive)
self.dat... | [
"def",
"from_dict",
"(",
"self",
",",
"data",
",",
"recursive",
"=",
"1",
")",
":",
"data",
"=",
"self",
".",
"_encode_resource",
"(",
"data",
",",
"recursive",
"=",
"recursive",
")",
"self",
".",
"data",
"=",
"data"
] | Populate the resource from a python dict
:param recursive: level of recursion for fetching resources
:type recursive: int | [
"Populate",
"the",
"resource",
"from",
"a",
"python",
"dict"
] | 1571bf523fa054f3d6bf83dba43a224fea173a73 | https://github.com/eonpatapon/contrail-api-cli/blob/1571bf523fa054f3d6bf83dba43a224fea173a73/contrail_api_cli/resource.py#L626-L634 | train |
eonpatapon/contrail-api-cli | contrail_api_cli/resource.py | Resource.remove_ref | def remove_ref(self, ref):
"""Remove reference from self to ref
>>> iip = Resource('instance-ip',
uuid='30213cf9-4b03-4afc-b8f9-c9971a216978',
fetch=True)
>>> for vmi in iip['virtual_machine_interface_refs']:
iip.remove_ref(v... | python | def remove_ref(self, ref):
"""Remove reference from self to ref
>>> iip = Resource('instance-ip',
uuid='30213cf9-4b03-4afc-b8f9-c9971a216978',
fetch=True)
>>> for vmi in iip['virtual_machine_interface_refs']:
iip.remove_ref(v... | [
"def",
"remove_ref",
"(",
"self",
",",
"ref",
")",
":",
"self",
".",
"session",
".",
"remove_ref",
"(",
"self",
",",
"ref",
")",
"return",
"self",
".",
"fetch",
"(",
")"
] | Remove reference from self to ref
>>> iip = Resource('instance-ip',
uuid='30213cf9-4b03-4afc-b8f9-c9971a216978',
fetch=True)
>>> for vmi in iip['virtual_machine_interface_refs']:
iip.remove_ref(vmi)
>>> iip['virtual_machine_i... | [
"Remove",
"reference",
"from",
"self",
"to",
"ref"
] | 1571bf523fa054f3d6bf83dba43a224fea173a73 | https://github.com/eonpatapon/contrail-api-cli/blob/1571bf523fa054f3d6bf83dba43a224fea173a73/contrail_api_cli/resource.py#L669-L686 | train |
eonpatapon/contrail-api-cli | contrail_api_cli/resource.py | Resource.set_ref | def set_ref(self, ref, attr=None):
"""Set reference to resource
Can be used to set references on a resource
that is not already created.
:param ref: reference to add
:type ref: Resource
:rtype: Resource
"""
ref_attr = '%s_refs' % ref.type.replace('-', '... | python | def set_ref(self, ref, attr=None):
"""Set reference to resource
Can be used to set references on a resource
that is not already created.
:param ref: reference to add
:type ref: Resource
:rtype: Resource
"""
ref_attr = '%s_refs' % ref.type.replace('-', '... | [
"def",
"set_ref",
"(",
"self",
",",
"ref",
",",
"attr",
"=",
"None",
")",
":",
"ref_attr",
"=",
"'%s_refs'",
"%",
"ref",
".",
"type",
".",
"replace",
"(",
"'-'",
",",
"'_'",
")",
"ref",
"=",
"{",
"'to'",
":",
"ref",
".",
"fq_name",
",",
"'uuid'",... | Set reference to resource
Can be used to set references on a resource
that is not already created.
:param ref: reference to add
:type ref: Resource
:rtype: Resource | [
"Set",
"reference",
"to",
"resource"
] | 1571bf523fa054f3d6bf83dba43a224fea173a73 | https://github.com/eonpatapon/contrail-api-cli/blob/1571bf523fa054f3d6bf83dba43a224fea173a73/contrail_api_cli/resource.py#L699-L719 | train |
eonpatapon/contrail-api-cli | contrail_api_cli/resource.py | Resource.add_ref | def add_ref(self, ref, attr=None):
"""Add reference to resource
:param ref: reference to add
:type ref: Resource
:rtype: Resource
"""
self.session.add_ref(self, ref, attr)
return self.fetch() | python | def add_ref(self, ref, attr=None):
"""Add reference to resource
:param ref: reference to add
:type ref: Resource
:rtype: Resource
"""
self.session.add_ref(self, ref, attr)
return self.fetch() | [
"def",
"add_ref",
"(",
"self",
",",
"ref",
",",
"attr",
"=",
"None",
")",
":",
"self",
".",
"session",
".",
"add_ref",
"(",
"self",
",",
"ref",
",",
"attr",
")",
"return",
"self",
".",
"fetch",
"(",
")"
] | Add reference to resource
:param ref: reference to add
:type ref: Resource
:rtype: Resource | [
"Add",
"reference",
"to",
"resource"
] | 1571bf523fa054f3d6bf83dba43a224fea173a73 | https://github.com/eonpatapon/contrail-api-cli/blob/1571bf523fa054f3d6bf83dba43a224fea173a73/contrail_api_cli/resource.py#L721-L730 | train |
eonpatapon/contrail-api-cli | contrail_api_cli/resource.py | Resource.add_back_ref | def add_back_ref(self, back_ref, attr=None):
"""Add reference from back_ref to self
:param back_ref: back_ref to add
:type back_ref: Resource
:rtype: Resource
"""
back_ref.add_ref(self, attr)
return self.fetch() | python | def add_back_ref(self, back_ref, attr=None):
"""Add reference from back_ref to self
:param back_ref: back_ref to add
:type back_ref: Resource
:rtype: Resource
"""
back_ref.add_ref(self, attr)
return self.fetch() | [
"def",
"add_back_ref",
"(",
"self",
",",
"back_ref",
",",
"attr",
"=",
"None",
")",
":",
"back_ref",
".",
"add_ref",
"(",
"self",
",",
"attr",
")",
"return",
"self",
".",
"fetch",
"(",
")"
] | Add reference from back_ref to self
:param back_ref: back_ref to add
:type back_ref: Resource
:rtype: Resource | [
"Add",
"reference",
"from",
"back_ref",
"to",
"self"
] | 1571bf523fa054f3d6bf83dba43a224fea173a73 | https://github.com/eonpatapon/contrail-api-cli/blob/1571bf523fa054f3d6bf83dba43a224fea173a73/contrail_api_cli/resource.py#L732-L741 | train |
eonpatapon/contrail-api-cli | contrail_api_cli/resource.py | ResourceCache._search | def _search(self, trie, strings, limit=None):
"""Search in cache
:param strings: list of strings to get from the cache
:type strings: str list
:param limit: limit search results
:type limit: int
:rtype: [Resource | Collection]
"""
results = [trie.has_key... | python | def _search(self, trie, strings, limit=None):
"""Search in cache
:param strings: list of strings to get from the cache
:type strings: str list
:param limit: limit search results
:type limit: int
:rtype: [Resource | Collection]
"""
results = [trie.has_key... | [
"def",
"_search",
"(",
"self",
",",
"trie",
",",
"strings",
",",
"limit",
"=",
"None",
")",
":",
"results",
"=",
"[",
"trie",
".",
"has_keys_with_prefix",
"(",
"s",
")",
"for",
"s",
"in",
"strings",
"]",
"if",
"not",
"any",
"(",
"results",
")",
":"... | Search in cache
:param strings: list of strings to get from the cache
:type strings: str list
:param limit: limit search results
:type limit: int
:rtype: [Resource | Collection] | [
"Search",
"in",
"cache"
] | 1571bf523fa054f3d6bf83dba43a224fea173a73 | https://github.com/eonpatapon/contrail-api-cli/blob/1571bf523fa054f3d6bf83dba43a224fea173a73/contrail_api_cli/resource.py#L777-L792 | train |
useblocks/groundwork | groundwork/signals.py | SignalsApplication.register | def register(self, signal, plugin, description=""):
"""
Registers a new signal.
:param signal: Unique name of the signal
:param plugin: Plugin, which registers the new signal
:param description: Description of the reason or use case, why this signal is needed.
... | python | def register(self, signal, plugin, description=""):
"""
Registers a new signal.
:param signal: Unique name of the signal
:param plugin: Plugin, which registers the new signal
:param description: Description of the reason or use case, why this signal is needed.
... | [
"def",
"register",
"(",
"self",
",",
"signal",
",",
"plugin",
",",
"description",
"=",
"\"\"",
")",
":",
"if",
"signal",
"in",
"self",
".",
"signals",
".",
"keys",
"(",
")",
":",
"raise",
"Exception",
"(",
"\"Signal %s was already registered by %s\"",
"%",
... | Registers a new signal.
:param signal: Unique name of the signal
:param plugin: Plugin, which registers the new signal
:param description: Description of the reason or use case, why this signal is needed.
Used for documentation. | [
"Registers",
"a",
"new",
"signal",
"."
] | d34fce43f54246ca4db0f7b89e450dcdc847c68c | https://github.com/useblocks/groundwork/blob/d34fce43f54246ca4db0f7b89e450dcdc847c68c/groundwork/signals.py#L48-L62 | train |
useblocks/groundwork | groundwork/signals.py | SignalsApplication.unregister | def unregister(self, signal):
"""
Unregisters an existing signal
:param signal: Name of the signal
"""
if signal in self.signals.keys():
del(self.signals[signal])
self.__log.debug("Signal %s unregisterd" % signal)
else:
self.__log.debu... | python | def unregister(self, signal):
"""
Unregisters an existing signal
:param signal: Name of the signal
"""
if signal in self.signals.keys():
del(self.signals[signal])
self.__log.debug("Signal %s unregisterd" % signal)
else:
self.__log.debu... | [
"def",
"unregister",
"(",
"self",
",",
"signal",
")",
":",
"if",
"signal",
"in",
"self",
".",
"signals",
".",
"keys",
"(",
")",
":",
"del",
"(",
"self",
".",
"signals",
"[",
"signal",
"]",
")",
"self",
".",
"__log",
".",
"debug",
"(",
"\"Signal %s ... | Unregisters an existing signal
:param signal: Name of the signal | [
"Unregisters",
"an",
"existing",
"signal"
] | d34fce43f54246ca4db0f7b89e450dcdc847c68c | https://github.com/useblocks/groundwork/blob/d34fce43f54246ca4db0f7b89e450dcdc847c68c/groundwork/signals.py#L64-L74 | train |
useblocks/groundwork | groundwork/signals.py | SignalsApplication.disconnect | def disconnect(self, receiver):
"""
Disconnect a receiver from a signal.
Signal and receiver must exist, otherwise an exception is thrown.
:param receiver: Name of the receiver
"""
if receiver not in self.receivers.keys():
raise Exception("No receiver %s was ... | python | def disconnect(self, receiver):
"""
Disconnect a receiver from a signal.
Signal and receiver must exist, otherwise an exception is thrown.
:param receiver: Name of the receiver
"""
if receiver not in self.receivers.keys():
raise Exception("No receiver %s was ... | [
"def",
"disconnect",
"(",
"self",
",",
"receiver",
")",
":",
"if",
"receiver",
"not",
"in",
"self",
".",
"receivers",
".",
"keys",
"(",
")",
":",
"raise",
"Exception",
"(",
"\"No receiver %s was registered\"",
"%",
"receiver",
")",
"self",
".",
"receivers",
... | Disconnect a receiver from a signal.
Signal and receiver must exist, otherwise an exception is thrown.
:param receiver: Name of the receiver | [
"Disconnect",
"a",
"receiver",
"from",
"a",
"signal",
".",
"Signal",
"and",
"receiver",
"must",
"exist",
"otherwise",
"an",
"exception",
"is",
"thrown",
"."
] | d34fce43f54246ca4db0f7b89e450dcdc847c68c | https://github.com/useblocks/groundwork/blob/d34fce43f54246ca4db0f7b89e450dcdc847c68c/groundwork/signals.py#L98-L109 | train |
useblocks/groundwork | groundwork/signals.py | SignalsApplication.get | def get(self, signal=None, plugin=None):
"""
Get one or more signals.
:param signal: Name of the signal
:type signal: str
:param plugin: Plugin object, under which the signals where registered
:type plugin: GwBasePattern
"""
if plugin is not None:
... | python | def get(self, signal=None, plugin=None):
"""
Get one or more signals.
:param signal: Name of the signal
:type signal: str
:param plugin: Plugin object, under which the signals where registered
:type plugin: GwBasePattern
"""
if plugin is not None:
... | [
"def",
"get",
"(",
"self",
",",
"signal",
"=",
"None",
",",
"plugin",
"=",
"None",
")",
":",
"if",
"plugin",
"is",
"not",
"None",
":",
"if",
"signal",
"is",
"None",
":",
"signals_list",
"=",
"{",
"}",
"for",
"key",
"in",
"self",
".",
"signals",
"... | Get one or more signals.
:param signal: Name of the signal
:type signal: str
:param plugin: Plugin object, under which the signals where registered
:type plugin: GwBasePattern | [
"Get",
"one",
"or",
"more",
"signals",
"."
] | d34fce43f54246ca4db0f7b89e450dcdc847c68c | https://github.com/useblocks/groundwork/blob/d34fce43f54246ca4db0f7b89e450dcdc847c68c/groundwork/signals.py#L126-L157 | train |
useblocks/groundwork | groundwork/signals.py | SignalsApplication.get_receiver | def get_receiver(self, receiver=None, plugin=None):
"""
Get one or more receivers.
:param receiver: Name of the signal
:type receiver: str
:param plugin: Plugin object, under which the signals where registered
:type plugin: GwBasePattern
"""
if plugin is ... | python | def get_receiver(self, receiver=None, plugin=None):
"""
Get one or more receivers.
:param receiver: Name of the signal
:type receiver: str
:param plugin: Plugin object, under which the signals where registered
:type plugin: GwBasePattern
"""
if plugin is ... | [
"def",
"get_receiver",
"(",
"self",
",",
"receiver",
"=",
"None",
",",
"plugin",
"=",
"None",
")",
":",
"if",
"plugin",
"is",
"not",
"None",
":",
"if",
"receiver",
"is",
"None",
":",
"receiver_list",
"=",
"{",
"}",
"for",
"key",
"in",
"self",
".",
... | Get one or more receivers.
:param receiver: Name of the signal
:type receiver: str
:param plugin: Plugin object, under which the signals where registered
:type plugin: GwBasePattern | [
"Get",
"one",
"or",
"more",
"receivers",
"."
] | d34fce43f54246ca4db0f7b89e450dcdc847c68c | https://github.com/useblocks/groundwork/blob/d34fce43f54246ca4db0f7b89e450dcdc847c68c/groundwork/signals.py#L159-L190 | train |
suurjaak/InputScope | inputscope/listener.py | start | def start(inqueue, outqueue=None):
"""Starts the listener with incoming and outgoing queues."""
conf.init(), db.init(conf.DbPath)
Listener(inqueue, outqueue).run() | python | def start(inqueue, outqueue=None):
"""Starts the listener with incoming and outgoing queues."""
conf.init(), db.init(conf.DbPath)
Listener(inqueue, outqueue).run() | [
"def",
"start",
"(",
"inqueue",
",",
"outqueue",
"=",
"None",
")",
":",
"conf",
".",
"init",
"(",
")",
",",
"db",
".",
"init",
"(",
"conf",
".",
"DbPath",
")",
"Listener",
"(",
"inqueue",
",",
"outqueue",
")",
".",
"run",
"(",
")"
] | Starts the listener with incoming and outgoing queues. | [
"Starts",
"the",
"listener",
"with",
"incoming",
"and",
"outgoing",
"queues",
"."
] | 245ff045163a1995e8cd5ac558d0a93024eb86eb | https://github.com/suurjaak/InputScope/blob/245ff045163a1995e8cd5ac558d0a93024eb86eb/inputscope/listener.py#L263-L266 | train |
suurjaak/InputScope | inputscope/listener.py | main | def main():
"""Entry point for stand-alone execution."""
conf.init(), db.init(conf.DbPath)
inqueue = LineQueue(sys.stdin).queue
outqueue = type("", (), {"put": lambda self, x: print("\r%s" % x, end=" ")})()
if "--quiet" in sys.argv: outqueue = None
if conf.MouseEnabled: inqueue.put("mou... | python | def main():
"""Entry point for stand-alone execution."""
conf.init(), db.init(conf.DbPath)
inqueue = LineQueue(sys.stdin).queue
outqueue = type("", (), {"put": lambda self, x: print("\r%s" % x, end=" ")})()
if "--quiet" in sys.argv: outqueue = None
if conf.MouseEnabled: inqueue.put("mou... | [
"def",
"main",
"(",
")",
":",
"conf",
".",
"init",
"(",
")",
",",
"db",
".",
"init",
"(",
"conf",
".",
"DbPath",
")",
"inqueue",
"=",
"LineQueue",
"(",
"sys",
".",
"stdin",
")",
".",
"queue",
"outqueue",
"=",
"type",
"(",
"\"\"",
",",
"(",
")",... | Entry point for stand-alone execution. | [
"Entry",
"point",
"for",
"stand",
"-",
"alone",
"execution",
"."
] | 245ff045163a1995e8cd5ac558d0a93024eb86eb | https://github.com/suurjaak/InputScope/blob/245ff045163a1995e8cd5ac558d0a93024eb86eb/inputscope/listener.py#L269-L277 | train |
suurjaak/InputScope | inputscope/listener.py | KeyHandler._handle_windows | def _handle_windows(self, event):
"""Windows key event handler."""
vkey = self._keyname(event.GetKey())
if event.Message in self.KEYS_UP + self.KEYS_DOWN:
if vkey in self.MODIFIERNAMES:
self._realmodifiers[vkey] = event.Message in self.KEYS_DOWN
... | python | def _handle_windows(self, event):
"""Windows key event handler."""
vkey = self._keyname(event.GetKey())
if event.Message in self.KEYS_UP + self.KEYS_DOWN:
if vkey in self.MODIFIERNAMES:
self._realmodifiers[vkey] = event.Message in self.KEYS_DOWN
... | [
"def",
"_handle_windows",
"(",
"self",
",",
"event",
")",
":",
"vkey",
"=",
"self",
".",
"_keyname",
"(",
"event",
".",
"GetKey",
"(",
")",
")",
"if",
"event",
".",
"Message",
"in",
"self",
".",
"KEYS_UP",
"+",
"self",
".",
"KEYS_DOWN",
":",
"if",
... | Windows key event handler. | [
"Windows",
"key",
"event",
"handler",
"."
] | 245ff045163a1995e8cd5ac558d0a93024eb86eb | https://github.com/suurjaak/InputScope/blob/245ff045163a1995e8cd5ac558d0a93024eb86eb/inputscope/listener.py#L170-L216 | train |
suurjaak/InputScope | inputscope/listener.py | KeyHandler._handle_mac | def _handle_mac(self, keycode):
"""Mac key event handler"""
key = self._keyname(unichr(keycode))
self._output(type="keys", key=key, realkey=key) | python | def _handle_mac(self, keycode):
"""Mac key event handler"""
key = self._keyname(unichr(keycode))
self._output(type="keys", key=key, realkey=key) | [
"def",
"_handle_mac",
"(",
"self",
",",
"keycode",
")",
":",
"key",
"=",
"self",
".",
"_keyname",
"(",
"unichr",
"(",
"keycode",
")",
")",
"self",
".",
"_output",
"(",
"type",
"=",
"\"keys\"",
",",
"key",
"=",
"key",
",",
"realkey",
"=",
"key",
")"... | Mac key event handler | [
"Mac",
"key",
"event",
"handler"
] | 245ff045163a1995e8cd5ac558d0a93024eb86eb | https://github.com/suurjaak/InputScope/blob/245ff045163a1995e8cd5ac558d0a93024eb86eb/inputscope/listener.py#L219-L222 | train |
suurjaak/InputScope | inputscope/listener.py | KeyHandler._handle_linux | def _handle_linux(self, keycode, character, press):
"""Linux key event handler."""
if character is None: return
key = self._keyname(character, keycode)
if key in self.MODIFIERNAMES:
self._modifiers[self.MODIFIERNAMES[key]] = press
self._realmodifiers[key] = ... | python | def _handle_linux(self, keycode, character, press):
"""Linux key event handler."""
if character is None: return
key = self._keyname(character, keycode)
if key in self.MODIFIERNAMES:
self._modifiers[self.MODIFIERNAMES[key]] = press
self._realmodifiers[key] = ... | [
"def",
"_handle_linux",
"(",
"self",
",",
"keycode",
",",
"character",
",",
"press",
")",
":",
"if",
"character",
"is",
"None",
":",
"return",
"key",
"=",
"self",
".",
"_keyname",
"(",
"character",
",",
"keycode",
")",
"if",
"key",
"in",
"self",
".",
... | Linux key event handler. | [
"Linux",
"key",
"event",
"handler",
"."
] | 245ff045163a1995e8cd5ac558d0a93024eb86eb | https://github.com/suurjaak/InputScope/blob/245ff045163a1995e8cd5ac558d0a93024eb86eb/inputscope/listener.py#L224-L241 | train |
useblocks/groundwork | groundwork/plugins/gw_documents_info.py | GwDocumentsInfo._store_documentation | def _store_documentation(self, path, html, overwrite, quiet):
"""
Stores all documents on the file system.
Target location is **path**. File name is the lowercase name of the document + .rst.
"""
echo("Storing groundwork application documents\n")
echo("Application: %s" ... | python | def _store_documentation(self, path, html, overwrite, quiet):
"""
Stores all documents on the file system.
Target location is **path**. File name is the lowercase name of the document + .rst.
"""
echo("Storing groundwork application documents\n")
echo("Application: %s" ... | [
"def",
"_store_documentation",
"(",
"self",
",",
"path",
",",
"html",
",",
"overwrite",
",",
"quiet",
")",
":",
"echo",
"(",
"\"Storing groundwork application documents\\n\"",
")",
"echo",
"(",
"\"Application: %s\"",
"%",
"self",
".",
"app",
".",
"name",
")",
... | Stores all documents on the file system.
Target location is **path**. File name is the lowercase name of the document + .rst. | [
"Stores",
"all",
"documents",
"on",
"the",
"file",
"system",
"."
] | d34fce43f54246ca4db0f7b89e450dcdc847c68c | https://github.com/useblocks/groundwork/blob/d34fce43f54246ca4db0f7b89e450dcdc847c68c/groundwork/plugins/gw_documents_info.py#L86-L150 | train |
useblocks/groundwork | groundwork/plugins/gw_documents_info.py | GwDocumentsInfo._show_documentation | def _show_documentation(self):
"""
Shows all documents of the current groundwork app in the console.
Documents are sorted bei its names, except "main", which gets set to the beginning.
"""
documents = []
for key, document in self.app.documents.get().items():
... | python | def _show_documentation(self):
"""
Shows all documents of the current groundwork app in the console.
Documents are sorted bei its names, except "main", which gets set to the beginning.
"""
documents = []
for key, document in self.app.documents.get().items():
... | [
"def",
"_show_documentation",
"(",
"self",
")",
":",
"documents",
"=",
"[",
"]",
"for",
"key",
",",
"document",
"in",
"self",
".",
"app",
".",
"documents",
".",
"get",
"(",
")",
".",
"items",
"(",
")",
":",
"if",
"key",
"!=",
"\"main\"",
":",
"docu... | Shows all documents of the current groundwork app in the console.
Documents are sorted bei its names, except "main", which gets set to the beginning. | [
"Shows",
"all",
"documents",
"of",
"the",
"current",
"groundwork",
"app",
"in",
"the",
"console",
"."
] | d34fce43f54246ca4db0f7b89e450dcdc847c68c | https://github.com/useblocks/groundwork/blob/d34fce43f54246ca4db0f7b89e450dcdc847c68c/groundwork/plugins/gw_documents_info.py#L152-L202 | train |
jenisys/parse_type | tasks/_tasklet_cleanup.py | execute_cleanup_tasks | def execute_cleanup_tasks(ctx, cleanup_tasks, dry_run=False):
"""Execute several cleanup tasks as part of the cleanup.
REQUIRES: ``clean(ctx, dry_run=False)`` signature in cleanup tasks.
:param ctx: Context object for the tasks.
:param cleanup_tasks: Collection of cleanup tasks (as Colle... | python | def execute_cleanup_tasks(ctx, cleanup_tasks, dry_run=False):
"""Execute several cleanup tasks as part of the cleanup.
REQUIRES: ``clean(ctx, dry_run=False)`` signature in cleanup tasks.
:param ctx: Context object for the tasks.
:param cleanup_tasks: Collection of cleanup tasks (as Colle... | [
"def",
"execute_cleanup_tasks",
"(",
"ctx",
",",
"cleanup_tasks",
",",
"dry_run",
"=",
"False",
")",
":",
"executor",
"=",
"Executor",
"(",
"cleanup_tasks",
",",
"ctx",
".",
"config",
")",
"for",
"cleanup_task",
"in",
"cleanup_tasks",
".",
"tasks",
":",
"pri... | Execute several cleanup tasks as part of the cleanup.
REQUIRES: ``clean(ctx, dry_run=False)`` signature in cleanup tasks.
:param ctx: Context object for the tasks.
:param cleanup_tasks: Collection of cleanup tasks (as Collection).
:param dry_run: Indicates dry-run mode (bool) | [
"Execute",
"several",
"cleanup",
"tasks",
"as",
"part",
"of",
"the",
"cleanup",
"."
] | 7cad3a67a5ca725cb786da31f656fd473084289f | https://github.com/jenisys/parse_type/blob/7cad3a67a5ca725cb786da31f656fd473084289f/tasks/_tasklet_cleanup.py#L70-L83 | train |
dbarsam/python-vsgen | vsgen/util/entrypoints.py | entrypoints | def entrypoints(section):
"""
Returns the Entry Point for a given Entry Point section.
:param str section: The section name in the entry point collection
:returns: A dictionary of (Name, Class) pairs stored in the entry point collection.
"""
return {ep.name: ep.load() for ep in pkg_resources.i... | python | def entrypoints(section):
"""
Returns the Entry Point for a given Entry Point section.
:param str section: The section name in the entry point collection
:returns: A dictionary of (Name, Class) pairs stored in the entry point collection.
"""
return {ep.name: ep.load() for ep in pkg_resources.i... | [
"def",
"entrypoints",
"(",
"section",
")",
":",
"return",
"{",
"ep",
".",
"name",
":",
"ep",
".",
"load",
"(",
")",
"for",
"ep",
"in",
"pkg_resources",
".",
"iter_entry_points",
"(",
"section",
")",
"}"
] | Returns the Entry Point for a given Entry Point section.
:param str section: The section name in the entry point collection
:returns: A dictionary of (Name, Class) pairs stored in the entry point collection. | [
"Returns",
"the",
"Entry",
"Point",
"for",
"a",
"given",
"Entry",
"Point",
"section",
"."
] | 640191bb018a1ff7d7b7a4982e0d3c1a423ba878 | https://github.com/dbarsam/python-vsgen/blob/640191bb018a1ff7d7b7a4982e0d3c1a423ba878/vsgen/util/entrypoints.py#L12-L19 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.