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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
ethereum/web3.py | web3/iban.py | mod9710 | def mod9710(iban):
"""
Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064.
@method mod9710
@param {String} iban
@returns {Number}
"""
remainder = iban
block = None
while len(remainder) > 2:
block = remainder[:9]
remainder = str(int(block) % 97) + re... | python | def mod9710(iban):
"""
Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064.
@method mod9710
@param {String} iban
@returns {Number}
"""
remainder = iban
block = None
while len(remainder) > 2:
block = remainder[:9]
remainder = str(int(block) % 97) + re... | [
"def",
"mod9710",
"(",
"iban",
")",
":",
"remainder",
"=",
"iban",
"block",
"=",
"None",
"while",
"len",
"(",
"remainder",
")",
">",
"2",
":",
"block",
"=",
"remainder",
"[",
":",
"9",
"]",
"remainder",
"=",
"str",
"(",
"int",
"(",
"block",
")",
... | Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064.
@method mod9710
@param {String} iban
@returns {Number} | [
"Calculates",
"the",
"MOD",
"97",
"10",
"of",
"the",
"passed",
"IBAN",
"as",
"specified",
"in",
"ISO7064",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/iban.py#L44-L59 | train |
ethereum/web3.py | web3/iban.py | baseN | def baseN(num, b, numerals="0123456789abcdefghijklmnopqrstuvwxyz"):
"""
This prototype should be used to create
an iban object from iban correct string
@param {String} iban
"""
return ((num == 0) and numerals[0]) or \
(baseN(num // b, b, numerals).lstrip(numerals[0]) + numerals[num % b]... | python | def baseN(num, b, numerals="0123456789abcdefghijklmnopqrstuvwxyz"):
"""
This prototype should be used to create
an iban object from iban correct string
@param {String} iban
"""
return ((num == 0) and numerals[0]) or \
(baseN(num // b, b, numerals).lstrip(numerals[0]) + numerals[num % b]... | [
"def",
"baseN",
"(",
"num",
",",
"b",
",",
"numerals",
"=",
"\"0123456789abcdefghijklmnopqrstuvwxyz\"",
")",
":",
"return",
"(",
"(",
"num",
"==",
"0",
")",
"and",
"numerals",
"[",
"0",
"]",
")",
"or",
"(",
"baseN",
"(",
"num",
"//",
"b",
",",
"b",
... | This prototype should be used to create
an iban object from iban correct string
@param {String} iban | [
"This",
"prototype",
"should",
"be",
"used",
"to",
"create",
"an",
"iban",
"object",
"from",
"iban",
"correct",
"string"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/iban.py#L62-L70 | train |
ethereum/web3.py | web3/iban.py | Iban.fromAddress | def fromAddress(address):
"""
This method should be used to create
an iban object from ethereum address
@method fromAddress
@param {String} address
@return {Iban} the IBAN object
"""
validate_address(address)
address_as_integer = int(address, 16)
... | python | def fromAddress(address):
"""
This method should be used to create
an iban object from ethereum address
@method fromAddress
@param {String} address
@return {Iban} the IBAN object
"""
validate_address(address)
address_as_integer = int(address, 16)
... | [
"def",
"fromAddress",
"(",
"address",
")",
":",
"validate_address",
"(",
"address",
")",
"address_as_integer",
"=",
"int",
"(",
"address",
",",
"16",
")",
"address_as_base36",
"=",
"baseN",
"(",
"address_as_integer",
",",
"36",
")",
"padded",
"=",
"pad_left_he... | This method should be used to create
an iban object from ethereum address
@method fromAddress
@param {String} address
@return {Iban} the IBAN object | [
"This",
"method",
"should",
"be",
"used",
"to",
"create",
"an",
"iban",
"object",
"from",
"ethereum",
"address"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/iban.py#L105-L118 | train |
ethereum/web3.py | web3/iban.py | Iban.address | def address(self):
"""
Should be called to get client direct address
@method address
@returns {String} client direct address
"""
if self.isDirect():
base36 = self._iban[4:]
asInt = int(base36, 36)
return to_checksum_address(pad_left_he... | python | def address(self):
"""
Should be called to get client direct address
@method address
@returns {String} client direct address
"""
if self.isDirect():
base36 = self._iban[4:]
asInt = int(base36, 36)
return to_checksum_address(pad_left_he... | [
"def",
"address",
"(",
"self",
")",
":",
"if",
"self",
".",
"isDirect",
"(",
")",
":",
"base36",
"=",
"self",
".",
"_iban",
"[",
"4",
":",
"]",
"asInt",
"=",
"int",
"(",
"base36",
",",
"36",
")",
"return",
"to_checksum_address",
"(",
"pad_left_hex",
... | Should be called to get client direct address
@method address
@returns {String} client direct address | [
"Should",
"be",
"called",
"to",
"get",
"client",
"direct",
"address"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/iban.py#L207-L219 | train |
ethereum/web3.py | web3/middleware/filter.py | block_ranges | def block_ranges(start_block, last_block, step=5):
"""Returns 2-tuple ranges describing ranges of block from start_block to last_block
Ranges do not overlap to facilitate use as ``toBlock``, ``fromBlock``
json-rpc arguments, which are both inclusive.
"""
if last_block is not None and start_b... | python | def block_ranges(start_block, last_block, step=5):
"""Returns 2-tuple ranges describing ranges of block from start_block to last_block
Ranges do not overlap to facilitate use as ``toBlock``, ``fromBlock``
json-rpc arguments, which are both inclusive.
"""
if last_block is not None and start_b... | [
"def",
"block_ranges",
"(",
"start_block",
",",
"last_block",
",",
"step",
"=",
"5",
")",
":",
"if",
"last_block",
"is",
"not",
"None",
"and",
"start_block",
">",
"last_block",
":",
"raise",
"TypeError",
"(",
"\"Incompatible start and stop arguments.\"",
",",
"\... | Returns 2-tuple ranges describing ranges of block from start_block to last_block
Ranges do not overlap to facilitate use as ``toBlock``, ``fromBlock``
json-rpc arguments, which are both inclusive. | [
"Returns",
"2",
"-",
"tuple",
"ranges",
"describing",
"ranges",
"of",
"block",
"from",
"start_block",
"to",
"last_block"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/middleware/filter.py#L68-L84 | train |
ethereum/web3.py | web3/middleware/filter.py | get_logs_multipart | def get_logs_multipart(
w3,
startBlock,
stopBlock,
address,
topics,
max_blocks):
"""Used to break up requests to ``eth_getLogs``
The getLog request is partitioned into multiple calls of the max number of blocks
``max_blocks``.
"""
_block_ranges = bloc... | python | def get_logs_multipart(
w3,
startBlock,
stopBlock,
address,
topics,
max_blocks):
"""Used to break up requests to ``eth_getLogs``
The getLog request is partitioned into multiple calls of the max number of blocks
``max_blocks``.
"""
_block_ranges = bloc... | [
"def",
"get_logs_multipart",
"(",
"w3",
",",
"startBlock",
",",
"stopBlock",
",",
"address",
",",
"topics",
",",
"max_blocks",
")",
":",
"_block_ranges",
"=",
"block_ranges",
"(",
"startBlock",
",",
"stopBlock",
",",
"max_blocks",
")",
"for",
"from_block",
","... | Used to break up requests to ``eth_getLogs``
The getLog request is partitioned into multiple calls of the max number of blocks
``max_blocks``. | [
"Used",
"to",
"break",
"up",
"requests",
"to",
"eth_getLogs"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/middleware/filter.py#L158-L179 | train |
ethereum/web3.py | web3/method.py | Method.method_selector_fn | def method_selector_fn(self):
"""Gets the method selector from the config.
"""
if callable(self.json_rpc_method):
return self.json_rpc_method
elif isinstance(self.json_rpc_method, (str,)):
return lambda *_: self.json_rpc_method
raise ValueError("``json_rpc... | python | def method_selector_fn(self):
"""Gets the method selector from the config.
"""
if callable(self.json_rpc_method):
return self.json_rpc_method
elif isinstance(self.json_rpc_method, (str,)):
return lambda *_: self.json_rpc_method
raise ValueError("``json_rpc... | [
"def",
"method_selector_fn",
"(",
"self",
")",
":",
"if",
"callable",
"(",
"self",
".",
"json_rpc_method",
")",
":",
"return",
"self",
".",
"json_rpc_method",
"elif",
"isinstance",
"(",
"self",
".",
"json_rpc_method",
",",
"(",
"str",
",",
")",
")",
":",
... | Gets the method selector from the config. | [
"Gets",
"the",
"method",
"selector",
"from",
"the",
"config",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/method.py#L97-L104 | train |
ethereum/web3.py | web3/_utils/encoding.py | hex_encode_abi_type | def hex_encode_abi_type(abi_type, value, force_size=None):
"""
Encodes value into a hex string in format of abi_type
"""
validate_abi_type(abi_type)
validate_abi_value(abi_type, value)
data_size = force_size or size_of_type(abi_type)
if is_array_type(abi_type):
sub_type = sub_type_o... | python | def hex_encode_abi_type(abi_type, value, force_size=None):
"""
Encodes value into a hex string in format of abi_type
"""
validate_abi_type(abi_type)
validate_abi_value(abi_type, value)
data_size = force_size or size_of_type(abi_type)
if is_array_type(abi_type):
sub_type = sub_type_o... | [
"def",
"hex_encode_abi_type",
"(",
"abi_type",
",",
"value",
",",
"force_size",
"=",
"None",
")",
":",
"validate_abi_type",
"(",
"abi_type",
")",
"validate_abi_value",
"(",
"abi_type",
",",
"value",
")",
"data_size",
"=",
"force_size",
"or",
"size_of_type",
"(",... | Encodes value into a hex string in format of abi_type | [
"Encodes",
"value",
"into",
"a",
"hex",
"string",
"in",
"format",
"of",
"abi_type"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/_utils/encoding.py#L50-L79 | train |
ethereum/web3.py | web3/_utils/encoding.py | to_hex_twos_compliment | def to_hex_twos_compliment(value, bit_size):
"""
Converts integer value to twos compliment hex representation with given bit_size
"""
if value >= 0:
return to_hex_with_size(value, bit_size)
value = (1 << bit_size) + value
hex_value = hex(value)
hex_value = hex_value.rstrip("L")
... | python | def to_hex_twos_compliment(value, bit_size):
"""
Converts integer value to twos compliment hex representation with given bit_size
"""
if value >= 0:
return to_hex_with_size(value, bit_size)
value = (1 << bit_size) + value
hex_value = hex(value)
hex_value = hex_value.rstrip("L")
... | [
"def",
"to_hex_twos_compliment",
"(",
"value",
",",
"bit_size",
")",
":",
"if",
"value",
">=",
"0",
":",
"return",
"to_hex_with_size",
"(",
"value",
",",
"bit_size",
")",
"value",
"=",
"(",
"1",
"<<",
"bit_size",
")",
"+",
"value",
"hex_value",
"=",
"hex... | Converts integer value to twos compliment hex representation with given bit_size | [
"Converts",
"integer",
"value",
"to",
"twos",
"compliment",
"hex",
"representation",
"with",
"given",
"bit_size"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/_utils/encoding.py#L82-L92 | train |
ethereum/web3.py | web3/_utils/encoding.py | pad_hex | def pad_hex(value, bit_size):
"""
Pads a hex string up to the given bit_size
"""
value = remove_0x_prefix(value)
return add_0x_prefix(value.zfill(int(bit_size / 4))) | python | def pad_hex(value, bit_size):
"""
Pads a hex string up to the given bit_size
"""
value = remove_0x_prefix(value)
return add_0x_prefix(value.zfill(int(bit_size / 4))) | [
"def",
"pad_hex",
"(",
"value",
",",
"bit_size",
")",
":",
"value",
"=",
"remove_0x_prefix",
"(",
"value",
")",
"return",
"add_0x_prefix",
"(",
"value",
".",
"zfill",
"(",
"int",
"(",
"bit_size",
"/",
"4",
")",
")",
")"
] | Pads a hex string up to the given bit_size | [
"Pads",
"a",
"hex",
"string",
"up",
"to",
"the",
"given",
"bit_size"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/_utils/encoding.py#L102-L107 | train |
ethereum/web3.py | web3/_utils/encoding.py | to_int | def to_int(value=None, hexstr=None, text=None):
"""
Converts value to it's integer representation.
Values are converted this way:
* value:
* bytes: big-endian integer
* bool: True => 1, False => 0
* hexstr: interpret hex as integer
* text: interpret as string of digits, like '... | python | def to_int(value=None, hexstr=None, text=None):
"""
Converts value to it's integer representation.
Values are converted this way:
* value:
* bytes: big-endian integer
* bool: True => 1, False => 0
* hexstr: interpret hex as integer
* text: interpret as string of digits, like '... | [
"def",
"to_int",
"(",
"value",
"=",
"None",
",",
"hexstr",
"=",
"None",
",",
"text",
"=",
"None",
")",
":",
"assert_one_val",
"(",
"value",
",",
"hexstr",
"=",
"hexstr",
",",
"text",
"=",
"text",
")",
"if",
"hexstr",
"is",
"not",
"None",
":",
"retu... | Converts value to it's integer representation.
Values are converted this way:
* value:
* bytes: big-endian integer
* bool: True => 1, False => 0
* hexstr: interpret hex as integer
* text: interpret as string of digits, like '12' => 12 | [
"Converts",
"value",
"to",
"it",
"s",
"integer",
"representation",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/_utils/encoding.py#L118-L141 | train |
ethereum/web3.py | web3/pm.py | VyperReferenceRegistry.deploy_new_instance | def deploy_new_instance(cls, w3: Web3) -> "VyperReferenceRegistry":
"""
Returns a new instance of ```VyperReferenceRegistry`` representing a freshly deployed
instance on the given ``web3`` instance of the Vyper Reference Registry implementation.
"""
manifest = get_vyper_registry_... | python | def deploy_new_instance(cls, w3: Web3) -> "VyperReferenceRegistry":
"""
Returns a new instance of ```VyperReferenceRegistry`` representing a freshly deployed
instance on the given ``web3`` instance of the Vyper Reference Registry implementation.
"""
manifest = get_vyper_registry_... | [
"def",
"deploy_new_instance",
"(",
"cls",
",",
"w3",
":",
"Web3",
")",
"->",
"\"VyperReferenceRegistry\"",
":",
"manifest",
"=",
"get_vyper_registry_manifest",
"(",
")",
"registry_package",
"=",
"Package",
"(",
"manifest",
",",
"w3",
")",
"registry_factory",
"=",
... | Returns a new instance of ```VyperReferenceRegistry`` representing a freshly deployed
instance on the given ``web3`` instance of the Vyper Reference Registry implementation. | [
"Returns",
"a",
"new",
"instance",
"of",
"VyperReferenceRegistry",
"representing",
"a",
"freshly",
"deployed",
"instance",
"on",
"the",
"given",
"web3",
"instance",
"of",
"the",
"Vyper",
"Reference",
"Registry",
"implementation",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/pm.py#L230-L241 | train |
ethereum/web3.py | web3/pm.py | VyperReferenceRegistry.transfer_owner | def transfer_owner(self, new_owner: Address) -> TxReceipt:
"""
Transfers ownership of this registry instance to the given ``new_owner``. Only the
``owner`` is allowed to transfer ownership.
* Parameters:
* ``new_owner``: The address of the new owner.
"""
tx_h... | python | def transfer_owner(self, new_owner: Address) -> TxReceipt:
"""
Transfers ownership of this registry instance to the given ``new_owner``. Only the
``owner`` is allowed to transfer ownership.
* Parameters:
* ``new_owner``: The address of the new owner.
"""
tx_h... | [
"def",
"transfer_owner",
"(",
"self",
",",
"new_owner",
":",
"Address",
")",
"->",
"TxReceipt",
":",
"tx_hash",
"=",
"self",
".",
"registry",
".",
"functions",
".",
"transferOwner",
"(",
"new_owner",
")",
".",
"transact",
"(",
")",
"return",
"self",
".",
... | Transfers ownership of this registry instance to the given ``new_owner``. Only the
``owner`` is allowed to transfer ownership.
* Parameters:
* ``new_owner``: The address of the new owner. | [
"Transfers",
"ownership",
"of",
"this",
"registry",
"instance",
"to",
"the",
"given",
"new_owner",
".",
"Only",
"the",
"owner",
"is",
"allowed",
"to",
"transfer",
"ownership",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/pm.py#L311-L320 | train |
ethereum/web3.py | web3/pm.py | PM.release_package | def release_package(
self, package_name: str, version: str, manifest_uri: str
) -> bytes:
"""
Returns the release id generated by releasing a package on the current registry.
Requires ``web3.PM`` to have a registry set. Requires ``web3.eth.defaultAccount``
to be the registry ... | python | def release_package(
self, package_name: str, version: str, manifest_uri: str
) -> bytes:
"""
Returns the release id generated by releasing a package on the current registry.
Requires ``web3.PM`` to have a registry set. Requires ``web3.eth.defaultAccount``
to be the registry ... | [
"def",
"release_package",
"(",
"self",
",",
"package_name",
":",
"str",
",",
"version",
":",
"str",
",",
"manifest_uri",
":",
"str",
")",
"->",
"bytes",
":",
"validate_is_supported_manifest_uri",
"(",
"manifest_uri",
")",
"raw_manifest",
"=",
"to_text",
"(",
"... | Returns the release id generated by releasing a package on the current registry.
Requires ``web3.PM`` to have a registry set. Requires ``web3.eth.defaultAccount``
to be the registry owner.
* Parameters:
* ``package_name``: Must be a valid package name, matching the given manifest.
... | [
"Returns",
"the",
"release",
"id",
"generated",
"by",
"releasing",
"a",
"package",
"on",
"the",
"current",
"registry",
".",
"Requires",
"web3",
".",
"PM",
"to",
"have",
"a",
"registry",
"set",
".",
"Requires",
"web3",
".",
"eth",
".",
"defaultAccount",
"to... | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/pm.py#L471-L504 | train |
ethereum/web3.py | web3/pm.py | PM.get_all_package_names | def get_all_package_names(self) -> Iterable[str]:
"""
Returns a tuple containing all the package names available on the current registry.
"""
self._validate_set_registry()
package_ids = self.registry._get_all_package_ids()
for package_id in package_ids:
yield ... | python | def get_all_package_names(self) -> Iterable[str]:
"""
Returns a tuple containing all the package names available on the current registry.
"""
self._validate_set_registry()
package_ids = self.registry._get_all_package_ids()
for package_id in package_ids:
yield ... | [
"def",
"get_all_package_names",
"(",
"self",
")",
"->",
"Iterable",
"[",
"str",
"]",
":",
"self",
".",
"_validate_set_registry",
"(",
")",
"package_ids",
"=",
"self",
".",
"registry",
".",
"_get_all_package_ids",
"(",
")",
"for",
"package_id",
"in",
"package_i... | Returns a tuple containing all the package names available on the current registry. | [
"Returns",
"a",
"tuple",
"containing",
"all",
"the",
"package",
"names",
"available",
"on",
"the",
"current",
"registry",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/pm.py#L507-L514 | train |
ethereum/web3.py | web3/pm.py | PM.get_release_count | def get_release_count(self, package_name: str) -> int:
"""
Returns the number of releases of the given package name available on the current registry.
"""
validate_package_name(package_name)
self._validate_set_registry()
return self.registry._num_release_ids(package_name) | python | def get_release_count(self, package_name: str) -> int:
"""
Returns the number of releases of the given package name available on the current registry.
"""
validate_package_name(package_name)
self._validate_set_registry()
return self.registry._num_release_ids(package_name) | [
"def",
"get_release_count",
"(",
"self",
",",
"package_name",
":",
"str",
")",
"->",
"int",
":",
"validate_package_name",
"(",
"package_name",
")",
"self",
".",
"_validate_set_registry",
"(",
")",
"return",
"self",
".",
"registry",
".",
"_num_release_ids",
"(",
... | Returns the number of releases of the given package name available on the current registry. | [
"Returns",
"the",
"number",
"of",
"releases",
"of",
"the",
"given",
"package",
"name",
"available",
"on",
"the",
"current",
"registry",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/pm.py#L523-L529 | train |
ethereum/web3.py | web3/pm.py | PM.get_release_id | def get_release_id(self, package_name: str, version: str) -> bytes:
"""
Returns the 32 byte identifier of a release for the given package name and version,
if they are available on the current registry.
"""
validate_package_name(package_name)
validate_package_version(vers... | python | def get_release_id(self, package_name: str, version: str) -> bytes:
"""
Returns the 32 byte identifier of a release for the given package name and version,
if they are available on the current registry.
"""
validate_package_name(package_name)
validate_package_version(vers... | [
"def",
"get_release_id",
"(",
"self",
",",
"package_name",
":",
"str",
",",
"version",
":",
"str",
")",
"->",
"bytes",
":",
"validate_package_name",
"(",
"package_name",
")",
"validate_package_version",
"(",
"version",
")",
"self",
".",
"_validate_set_registry",
... | Returns the 32 byte identifier of a release for the given package name and version,
if they are available on the current registry. | [
"Returns",
"the",
"32",
"byte",
"identifier",
"of",
"a",
"release",
"for",
"the",
"given",
"package",
"name",
"and",
"version",
"if",
"they",
"are",
"available",
"on",
"the",
"current",
"registry",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/pm.py#L531-L539 | train |
ethereum/web3.py | web3/pm.py | PM.get_package | def get_package(self, package_name: str, version: str) -> Package:
"""
Returns a ``Package`` instance, generated by the ``manifest_uri`` associated with the
given package name and version, if they are published to the currently set registry.
* Parameters:
* ``name``: Must be... | python | def get_package(self, package_name: str, version: str) -> Package:
"""
Returns a ``Package`` instance, generated by the ``manifest_uri`` associated with the
given package name and version, if they are published to the currently set registry.
* Parameters:
* ``name``: Must be... | [
"def",
"get_package",
"(",
"self",
",",
"package_name",
":",
"str",
",",
"version",
":",
"str",
")",
"->",
"Package",
":",
"validate_package_name",
"(",
"package_name",
")",
"validate_package_version",
"(",
"version",
")",
"self",
".",
"_validate_set_registry",
... | Returns a ``Package`` instance, generated by the ``manifest_uri`` associated with the
given package name and version, if they are published to the currently set registry.
* Parameters:
* ``name``: Must be a valid package name.
* ``version``: Must be a valid package version. | [
"Returns",
"a",
"Package",
"instance",
"generated",
"by",
"the",
"manifest_uri",
"associated",
"with",
"the",
"given",
"package",
"name",
"and",
"version",
"if",
"they",
"are",
"published",
"to",
"the",
"currently",
"set",
"registry",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/pm.py#L580-L593 | train |
ethereum/web3.py | web3/_utils/filters.py | normalize_data_values | def normalize_data_values(type_string, data_value):
"""Decodes utf-8 bytes to strings for abi string values.
eth-abi v1 returns utf-8 bytes for string values.
This can be removed once eth-abi v2 is required.
"""
_type = parse_type_string(type_string)
if _type.base == "string":
if _type.... | python | def normalize_data_values(type_string, data_value):
"""Decodes utf-8 bytes to strings for abi string values.
eth-abi v1 returns utf-8 bytes for string values.
This can be removed once eth-abi v2 is required.
"""
_type = parse_type_string(type_string)
if _type.base == "string":
if _type.... | [
"def",
"normalize_data_values",
"(",
"type_string",
",",
"data_value",
")",
":",
"_type",
"=",
"parse_type_string",
"(",
"type_string",
")",
"if",
"_type",
".",
"base",
"==",
"\"string\"",
":",
"if",
"_type",
".",
"arrlist",
"is",
"not",
"None",
":",
"return... | Decodes utf-8 bytes to strings for abi string values.
eth-abi v1 returns utf-8 bytes for string values.
This can be removed once eth-abi v2 is required. | [
"Decodes",
"utf",
"-",
"8",
"bytes",
"to",
"strings",
"for",
"abi",
"string",
"values",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/_utils/filters.py#L192-L204 | train |
ethereum/web3.py | web3/_utils/filters.py | match_fn | def match_fn(match_values_and_abi, data):
"""Match function used for filtering non-indexed event arguments.
Values provided through the match_values_and_abi parameter are
compared to the abi decoded log data.
"""
abi_types, all_match_values = zip(*match_values_and_abi)
decoded_values = decode_a... | python | def match_fn(match_values_and_abi, data):
"""Match function used for filtering non-indexed event arguments.
Values provided through the match_values_and_abi parameter are
compared to the abi decoded log data.
"""
abi_types, all_match_values = zip(*match_values_and_abi)
decoded_values = decode_a... | [
"def",
"match_fn",
"(",
"match_values_and_abi",
",",
"data",
")",
":",
"abi_types",
",",
"all_match_values",
"=",
"zip",
"(",
"*",
"match_values_and_abi",
")",
"decoded_values",
"=",
"decode_abi",
"(",
"abi_types",
",",
"HexBytes",
"(",
"data",
")",
")",
"for"... | Match function used for filtering non-indexed event arguments.
Values provided through the match_values_and_abi parameter are
compared to the abi decoded log data. | [
"Match",
"function",
"used",
"for",
"filtering",
"non",
"-",
"indexed",
"event",
"arguments",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/_utils/filters.py#L208-L230 | train |
ethereum/web3.py | web3/middleware/attrdict.py | attrdict_middleware | def attrdict_middleware(make_request, web3):
"""
Converts any result which is a dictionary into an a
"""
def middleware(method, params):
response = make_request(method, params)
if 'result' in response:
result = response['result']
if is_dict(result) and not isinst... | python | def attrdict_middleware(make_request, web3):
"""
Converts any result which is a dictionary into an a
"""
def middleware(method, params):
response = make_request(method, params)
if 'result' in response:
result = response['result']
if is_dict(result) and not isinst... | [
"def",
"attrdict_middleware",
"(",
"make_request",
",",
"web3",
")",
":",
"def",
"middleware",
"(",
"method",
",",
"params",
")",
":",
"response",
"=",
"make_request",
"(",
"method",
",",
"params",
")",
"if",
"'result'",
"in",
"response",
":",
"result",
"=... | Converts any result which is a dictionary into an a | [
"Converts",
"any",
"result",
"which",
"is",
"a",
"dictionary",
"into",
"an",
"a"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/middleware/attrdict.py#L13-L28 | train |
ethereum/web3.py | ens/main.py | ENS.fromWeb3 | def fromWeb3(cls, web3, addr=None):
"""
Generate an ENS instance with web3
:param `web3.Web3` web3: to infer connection information
:param hex-string addr: the address of the ENS registry on-chain. If not provided,
ENS.py will default to the mainnet ENS registry address.
... | python | def fromWeb3(cls, web3, addr=None):
"""
Generate an ENS instance with web3
:param `web3.Web3` web3: to infer connection information
:param hex-string addr: the address of the ENS registry on-chain. If not provided,
ENS.py will default to the mainnet ENS registry address.
... | [
"def",
"fromWeb3",
"(",
"cls",
",",
"web3",
",",
"addr",
"=",
"None",
")",
":",
"return",
"cls",
"(",
"web3",
".",
"manager",
".",
"provider",
",",
"addr",
"=",
"addr",
")"
] | Generate an ENS instance with web3
:param `web3.Web3` web3: to infer connection information
:param hex-string addr: the address of the ENS registry on-chain. If not provided,
ENS.py will default to the mainnet ENS registry address. | [
"Generate",
"an",
"ENS",
"instance",
"with",
"web3"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/ens/main.py#L65-L73 | train |
ethereum/web3.py | ens/main.py | ENS.name | def name(self, address):
"""
Look up the name that the address points to, using a
reverse lookup. Reverse lookup is opt-in for name owners.
:param address:
:type address: hex-string
"""
reversed_domain = address_to_reverse_domain(address)
return self.reso... | python | def name(self, address):
"""
Look up the name that the address points to, using a
reverse lookup. Reverse lookup is opt-in for name owners.
:param address:
:type address: hex-string
"""
reversed_domain = address_to_reverse_domain(address)
return self.reso... | [
"def",
"name",
"(",
"self",
",",
"address",
")",
":",
"reversed_domain",
"=",
"address_to_reverse_domain",
"(",
"address",
")",
"return",
"self",
".",
"resolve",
"(",
"reversed_domain",
",",
"get",
"=",
"'name'",
")"
] | Look up the name that the address points to, using a
reverse lookup. Reverse lookup is opt-in for name owners.
:param address:
:type address: hex-string | [
"Look",
"up",
"the",
"name",
"that",
"the",
"address",
"points",
"to",
"using",
"a",
"reverse",
"lookup",
".",
"Reverse",
"lookup",
"is",
"opt",
"-",
"in",
"for",
"name",
"owners",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/ens/main.py#L84-L93 | train |
ethereum/web3.py | ens/main.py | ENS.setup_address | def setup_address(self, name, address=default, transact={}):
"""
Set up the name to point to the supplied address.
The sender of the transaction must own the name, or
its parent name.
Example: If the caller owns ``parentname.eth`` with no subdomains
and calls this method... | python | def setup_address(self, name, address=default, transact={}):
"""
Set up the name to point to the supplied address.
The sender of the transaction must own the name, or
its parent name.
Example: If the caller owns ``parentname.eth`` with no subdomains
and calls this method... | [
"def",
"setup_address",
"(",
"self",
",",
"name",
",",
"address",
"=",
"default",
",",
"transact",
"=",
"{",
"}",
")",
":",
"owner",
"=",
"self",
".",
"setup_owner",
"(",
"name",
",",
"transact",
"=",
"transact",
")",
"self",
".",
"_assert_control",
"(... | Set up the name to point to the supplied address.
The sender of the transaction must own the name, or
its parent name.
Example: If the caller owns ``parentname.eth`` with no subdomains
and calls this method with ``sub.parentname.eth``,
then ``sub`` will be created as part of thi... | [
"Set",
"up",
"the",
"name",
"to",
"point",
"to",
"the",
"supplied",
"address",
".",
"The",
"sender",
"of",
"the",
"transaction",
"must",
"own",
"the",
"name",
"or",
"its",
"parent",
"name",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/ens/main.py#L96-L130 | train |
ethereum/web3.py | ens/main.py | ENS.setup_owner | def setup_owner(self, name, new_owner=default, transact={}):
"""
Set the owner of the supplied name to `new_owner`.
For typical scenarios, you'll never need to call this method directly,
simply call :meth:`setup_name` or :meth:`setup_address`. This method does *not*
set up the n... | python | def setup_owner(self, name, new_owner=default, transact={}):
"""
Set the owner of the supplied name to `new_owner`.
For typical scenarios, you'll never need to call this method directly,
simply call :meth:`setup_name` or :meth:`setup_address`. This method does *not*
set up the n... | [
"def",
"setup_owner",
"(",
"self",
",",
"name",
",",
"new_owner",
"=",
"default",
",",
"transact",
"=",
"{",
"}",
")",
":",
"(",
"super_owner",
",",
"unowned",
",",
"owned",
")",
"=",
"self",
".",
"_first_owner",
"(",
"name",
")",
"if",
"new_owner",
... | Set the owner of the supplied name to `new_owner`.
For typical scenarios, you'll never need to call this method directly,
simply call :meth:`setup_name` or :meth:`setup_address`. This method does *not*
set up the name to point to an address.
If `new_owner` is not supplied, then this wi... | [
"Set",
"the",
"owner",
"of",
"the",
"supplied",
"name",
"to",
"new_owner",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/ens/main.py#L213-L252 | train |
ethereum/web3.py | ens/main.py | ENS._first_owner | def _first_owner(self, name):
"""
Takes a name, and returns the owner of the deepest subdomain that has an owner
:returns: (owner or None, list(unowned_subdomain_labels), first_owned_domain)
"""
owner = None
unowned = []
pieces = normalize_name(name).split('.')
... | python | def _first_owner(self, name):
"""
Takes a name, and returns the owner of the deepest subdomain that has an owner
:returns: (owner or None, list(unowned_subdomain_labels), first_owned_domain)
"""
owner = None
unowned = []
pieces = normalize_name(name).split('.')
... | [
"def",
"_first_owner",
"(",
"self",
",",
"name",
")",
":",
"owner",
"=",
"None",
"unowned",
"=",
"[",
"]",
"pieces",
"=",
"normalize_name",
"(",
"name",
")",
".",
"split",
"(",
"'.'",
")",
"while",
"pieces",
"and",
"is_none_or_zero_address",
"(",
"owner"... | Takes a name, and returns the owner of the deepest subdomain that has an owner
:returns: (owner or None, list(unowned_subdomain_labels), first_owned_domain) | [
"Takes",
"a",
"name",
"and",
"returns",
"the",
"owner",
"of",
"the",
"deepest",
"subdomain",
"that",
"has",
"an",
"owner"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/ens/main.py#L262-L276 | train |
ethereum/web3.py | web3/contract.py | call_contract_function | def call_contract_function(
web3,
address,
normalizers,
function_identifier,
transaction,
block_id=None,
contract_abi=None,
fn_abi=None,
*args,
**kwargs):
"""
Helper function for interacting with a contract function using the
`e... | python | def call_contract_function(
web3,
address,
normalizers,
function_identifier,
transaction,
block_id=None,
contract_abi=None,
fn_abi=None,
*args,
**kwargs):
"""
Helper function for interacting with a contract function using the
`e... | [
"def",
"call_contract_function",
"(",
"web3",
",",
"address",
",",
"normalizers",
",",
"function_identifier",
",",
"transaction",
",",
"block_id",
"=",
"None",
",",
"contract_abi",
"=",
"None",
",",
"fn_abi",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"... | Helper function for interacting with a contract function using the
`eth_call` API. | [
"Helper",
"function",
"for",
"interacting",
"with",
"a",
"contract",
"function",
"using",
"the",
"eth_call",
"API",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/contract.py#L1275-L1345 | train |
ethereum/web3.py | web3/contract.py | transact_with_contract_function | def transact_with_contract_function(
address,
web3,
function_name=None,
transaction=None,
contract_abi=None,
fn_abi=None,
*args,
**kwargs):
"""
Helper function for interacting with a contract function by sending a
transaction.
"""
trans... | python | def transact_with_contract_function(
address,
web3,
function_name=None,
transaction=None,
contract_abi=None,
fn_abi=None,
*args,
**kwargs):
"""
Helper function for interacting with a contract function by sending a
transaction.
"""
trans... | [
"def",
"transact_with_contract_function",
"(",
"address",
",",
"web3",
",",
"function_name",
"=",
"None",
",",
"transaction",
"=",
"None",
",",
"contract_abi",
"=",
"None",
",",
"fn_abi",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
... | Helper function for interacting with a contract function by sending a
transaction. | [
"Helper",
"function",
"for",
"interacting",
"with",
"a",
"contract",
"function",
"by",
"sending",
"a",
"transaction",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/contract.py#L1370-L1395 | train |
ethereum/web3.py | web3/contract.py | estimate_gas_for_function | def estimate_gas_for_function(
address,
web3,
fn_identifier=None,
transaction=None,
contract_abi=None,
fn_abi=None,
*args,
**kwargs):
"""Estimates gas cost a function call would take.
Don't call this directly, instead use :meth:`Contract.estimateG... | python | def estimate_gas_for_function(
address,
web3,
fn_identifier=None,
transaction=None,
contract_abi=None,
fn_abi=None,
*args,
**kwargs):
"""Estimates gas cost a function call would take.
Don't call this directly, instead use :meth:`Contract.estimateG... | [
"def",
"estimate_gas_for_function",
"(",
"address",
",",
"web3",
",",
"fn_identifier",
"=",
"None",
",",
"transaction",
"=",
"None",
",",
"contract_abi",
"=",
"None",
",",
"fn_abi",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"estim... | Estimates gas cost a function call would take.
Don't call this directly, instead use :meth:`Contract.estimateGas`
on your contract instance. | [
"Estimates",
"gas",
"cost",
"a",
"function",
"call",
"would",
"take",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/contract.py#L1398-L1424 | train |
ethereum/web3.py | web3/contract.py | build_transaction_for_function | def build_transaction_for_function(
address,
web3,
function_name=None,
transaction=None,
contract_abi=None,
fn_abi=None,
*args,
**kwargs):
"""Builds a dictionary with the fields required to make the given transaction
Don't call this directly, inst... | python | def build_transaction_for_function(
address,
web3,
function_name=None,
transaction=None,
contract_abi=None,
fn_abi=None,
*args,
**kwargs):
"""Builds a dictionary with the fields required to make the given transaction
Don't call this directly, inst... | [
"def",
"build_transaction_for_function",
"(",
"address",
",",
"web3",
",",
"function_name",
"=",
"None",
",",
"transaction",
"=",
"None",
",",
"contract_abi",
"=",
"None",
",",
"fn_abi",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"... | Builds a dictionary with the fields required to make the given transaction
Don't call this directly, instead use :meth:`Contract.buildTransaction`
on your contract instance. | [
"Builds",
"a",
"dictionary",
"with",
"the",
"fields",
"required",
"to",
"make",
"the",
"given",
"transaction"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/contract.py#L1427-L1454 | train |
ethereum/web3.py | web3/contract.py | Contract.encodeABI | def encodeABI(cls, fn_name, args=None, kwargs=None, data=None):
"""
Encodes the arguments using the Ethereum ABI for the contract function
that matches the given name and arguments..
:param data: defaults to function selector
"""
fn_abi, fn_selector, fn_arguments = get_f... | python | def encodeABI(cls, fn_name, args=None, kwargs=None, data=None):
"""
Encodes the arguments using the Ethereum ABI for the contract function
that matches the given name and arguments..
:param data: defaults to function selector
"""
fn_abi, fn_selector, fn_arguments = get_f... | [
"def",
"encodeABI",
"(",
"cls",
",",
"fn_name",
",",
"args",
"=",
"None",
",",
"kwargs",
"=",
"None",
",",
"data",
"=",
"None",
")",
":",
"fn_abi",
",",
"fn_selector",
",",
"fn_arguments",
"=",
"get_function_info",
"(",
"fn_name",
",",
"contract_abi",
"=... | Encodes the arguments using the Ethereum ABI for the contract function
that matches the given name and arguments..
:param data: defaults to function selector | [
"Encodes",
"the",
"arguments",
"using",
"the",
"Ethereum",
"ABI",
"for",
"the",
"contract",
"function",
"that",
"matches",
"the",
"given",
"name",
"and",
"arguments",
".."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/contract.py#L330-L344 | train |
ethereum/web3.py | web3/contract.py | ContractFunction.call | def call(self, transaction=None, block_identifier='latest'):
"""
Execute a contract function call using the `eth_call` interface.
This method prepares a ``Caller`` object that exposes the contract
functions and public variables as callable Python functions.
Reading a public ``o... | python | def call(self, transaction=None, block_identifier='latest'):
"""
Execute a contract function call using the `eth_call` interface.
This method prepares a ``Caller`` object that exposes the contract
functions and public variables as callable Python functions.
Reading a public ``o... | [
"def",
"call",
"(",
"self",
",",
"transaction",
"=",
"None",
",",
"block_identifier",
"=",
"'latest'",
")",
":",
"if",
"transaction",
"is",
"None",
":",
"call_transaction",
"=",
"{",
"}",
"else",
":",
"call_transaction",
"=",
"dict",
"(",
"*",
"*",
"tran... | Execute a contract function call using the `eth_call` interface.
This method prepares a ``Caller`` object that exposes the contract
functions and public variables as callable Python functions.
Reading a public ``owner`` address variable example:
.. code-block:: python
Con... | [
"Execute",
"a",
"contract",
"function",
"call",
"using",
"the",
"eth_call",
"interface",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/contract.py#L761-L824 | train |
ethereum/web3.py | web3/contract.py | ContractEvent.getLogs | def getLogs(self,
argument_filters=None,
fromBlock=None,
toBlock=None,
blockHash=None):
"""Get events for this contract instance using eth_getLogs API.
This is a stateless method, as opposed to createFilter.
It can be safely called... | python | def getLogs(self,
argument_filters=None,
fromBlock=None,
toBlock=None,
blockHash=None):
"""Get events for this contract instance using eth_getLogs API.
This is a stateless method, as opposed to createFilter.
It can be safely called... | [
"def",
"getLogs",
"(",
"self",
",",
"argument_filters",
"=",
"None",
",",
"fromBlock",
"=",
"None",
",",
"toBlock",
"=",
"None",
",",
"blockHash",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"address",
":",
"raise",
"TypeError",
"(",
"\"This method ... | Get events for this contract instance using eth_getLogs API.
This is a stateless method, as opposed to createFilter.
It can be safely called against nodes which do not provide
eth_newFilter API, like Infura nodes.
If there are many events,
like ``Transfer`` events for a popular... | [
"Get",
"events",
"for",
"this",
"contract",
"instance",
"using",
"eth_getLogs",
"API",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/contract.py#L1065-L1161 | train |
ethereum/web3.py | ens/utils.py | dict_copy | def dict_copy(func):
"copy dict keyword args, to avoid modifying caller's copy"
@functools.wraps(func)
def wrapper(*args, **kwargs):
copied_kwargs = copy.deepcopy(kwargs)
return func(*args, **copied_kwargs)
return wrapper | python | def dict_copy(func):
"copy dict keyword args, to avoid modifying caller's copy"
@functools.wraps(func)
def wrapper(*args, **kwargs):
copied_kwargs = copy.deepcopy(kwargs)
return func(*args, **copied_kwargs)
return wrapper | [
"def",
"dict_copy",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"copied_kwargs",
"=",
"copy",
".",
"deepcopy",
"(",
"kwargs",
")",
"return",
"func",
... | copy dict keyword args, to avoid modifying caller's copy | [
"copy",
"dict",
"keyword",
"args",
"to",
"avoid",
"modifying",
"caller",
"s",
"copy"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/ens/utils.py#L33-L39 | train |
ethereum/web3.py | ens/utils.py | dot_eth_label | def dot_eth_label(name):
"""
Convert from a name, like 'ethfinex.eth', to a label, like 'ethfinex'
If name is already a label, this should be a noop, except for converting to a string
and validating the name syntax.
"""
label = name_to_label(name, registrar='eth')
if len(label) < MIN_ETH_LAB... | python | def dot_eth_label(name):
"""
Convert from a name, like 'ethfinex.eth', to a label, like 'ethfinex'
If name is already a label, this should be a noop, except for converting to a string
and validating the name syntax.
"""
label = name_to_label(name, registrar='eth')
if len(label) < MIN_ETH_LAB... | [
"def",
"dot_eth_label",
"(",
"name",
")",
":",
"label",
"=",
"name_to_label",
"(",
"name",
",",
"registrar",
"=",
"'eth'",
")",
"if",
"len",
"(",
"label",
")",
"<",
"MIN_ETH_LABEL_LENGTH",
":",
"raise",
"InvalidLabel",
"(",
"'name %r is too short'",
"%",
"la... | Convert from a name, like 'ethfinex.eth', to a label, like 'ethfinex'
If name is already a label, this should be a noop, except for converting to a string
and validating the name syntax. | [
"Convert",
"from",
"a",
"name",
"like",
"ethfinex",
".",
"eth",
"to",
"a",
"label",
"like",
"ethfinex",
"If",
"name",
"is",
"already",
"a",
"label",
"this",
"should",
"be",
"a",
"noop",
"except",
"for",
"converting",
"to",
"a",
"string",
"and",
"validati... | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/ens/utils.py#L125-L135 | train |
ethereum/web3.py | web3/_utils/formatters.py | map_collection | def map_collection(func, collection):
"""
Apply func to each element of a collection, or value of a dictionary.
If the value is not a collection, return it unmodified
"""
datatype = type(collection)
if isinstance(collection, Mapping):
return datatype((key, func(val)) for key, val in coll... | python | def map_collection(func, collection):
"""
Apply func to each element of a collection, or value of a dictionary.
If the value is not a collection, return it unmodified
"""
datatype = type(collection)
if isinstance(collection, Mapping):
return datatype((key, func(val)) for key, val in coll... | [
"def",
"map_collection",
"(",
"func",
",",
"collection",
")",
":",
"datatype",
"=",
"type",
"(",
"collection",
")",
"if",
"isinstance",
"(",
"collection",
",",
"Mapping",
")",
":",
"return",
"datatype",
"(",
"(",
"key",
",",
"func",
"(",
"val",
")",
")... | Apply func to each element of a collection, or value of a dictionary.
If the value is not a collection, return it unmodified | [
"Apply",
"func",
"to",
"each",
"element",
"of",
"a",
"collection",
"or",
"value",
"of",
"a",
"dictionary",
".",
"If",
"the",
"value",
"is",
"not",
"a",
"collection",
"return",
"it",
"unmodified"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/_utils/formatters.py#L91-L104 | train |
ethereum/web3.py | web3/_utils/math.py | percentile | def percentile(values=None, percentile=None):
"""Calculates a simplified weighted average percentile
"""
if values in [None, tuple(), []] or len(values) < 1:
raise InsufficientData(
"Expected a sequence of at least 1 integers, got {0!r}".format(values))
if percentile is None:
... | python | def percentile(values=None, percentile=None):
"""Calculates a simplified weighted average percentile
"""
if values in [None, tuple(), []] or len(values) < 1:
raise InsufficientData(
"Expected a sequence of at least 1 integers, got {0!r}".format(values))
if percentile is None:
... | [
"def",
"percentile",
"(",
"values",
"=",
"None",
",",
"percentile",
"=",
"None",
")",
":",
"if",
"values",
"in",
"[",
"None",
",",
"tuple",
"(",
")",
",",
"[",
"]",
"]",
"or",
"len",
"(",
"values",
")",
"<",
"1",
":",
"raise",
"InsufficientData",
... | Calculates a simplified weighted average percentile | [
"Calculates",
"a",
"simplified",
"weighted",
"average",
"percentile"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/_utils/math.py#L6-L32 | train |
ethereum/web3.py | web3/datastructures.py | ReadableAttributeDict._repr_pretty_ | def _repr_pretty_(self, builder, cycle):
"""
Custom pretty output for the IPython console
"""
builder.text(self.__class__.__name__ + "(")
if cycle:
builder.text("<cycle>")
else:
builder.pretty(self.__dict__)
builder.text(")") | python | def _repr_pretty_(self, builder, cycle):
"""
Custom pretty output for the IPython console
"""
builder.text(self.__class__.__name__ + "(")
if cycle:
builder.text("<cycle>")
else:
builder.pretty(self.__dict__)
builder.text(")") | [
"def",
"_repr_pretty_",
"(",
"self",
",",
"builder",
",",
"cycle",
")",
":",
"builder",
".",
"text",
"(",
"self",
".",
"__class__",
".",
"__name__",
"+",
"\"(\"",
")",
"if",
"cycle",
":",
"builder",
".",
"text",
"(",
"\"<cycle>\"",
")",
"else",
":",
... | Custom pretty output for the IPython console | [
"Custom",
"pretty",
"output",
"for",
"the",
"IPython",
"console"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/datastructures.py#L45-L54 | train |
ethereum/web3.py | web3/datastructures.py | NamedElementOnion.inject | def inject(self, element, name=None, layer=None):
"""
Inject a named element to an arbitrary layer in the onion.
The current implementation only supports insertion at the innermost layer,
or at the outermost layer. Note that inserting to the outermost is equivalent
to calling :m... | python | def inject(self, element, name=None, layer=None):
"""
Inject a named element to an arbitrary layer in the onion.
The current implementation only supports insertion at the innermost layer,
or at the outermost layer. Note that inserting to the outermost is equivalent
to calling :m... | [
"def",
"inject",
"(",
"self",
",",
"element",
",",
"name",
"=",
"None",
",",
"layer",
"=",
"None",
")",
":",
"if",
"not",
"is_integer",
"(",
"layer",
")",
":",
"raise",
"TypeError",
"(",
"\"The layer for insertion must be an int.\"",
")",
"elif",
"layer",
... | Inject a named element to an arbitrary layer in the onion.
The current implementation only supports insertion at the innermost layer,
or at the outermost layer. Note that inserting to the outermost is equivalent
to calling :meth:`add` . | [
"Inject",
"a",
"named",
"element",
"to",
"an",
"arbitrary",
"layer",
"in",
"the",
"onion",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/datastructures.py#L127-L156 | train |
ethereum/web3.py | web3/middleware/signing.py | construct_sign_and_send_raw_middleware | def construct_sign_and_send_raw_middleware(private_key_or_account):
"""Capture transactions sign and send as raw transactions
Keyword arguments:
private_key_or_account -- A single private key or a tuple,
list or set of private keys. Keys can be any of the following formats:
- An eth_account.Loca... | python | def construct_sign_and_send_raw_middleware(private_key_or_account):
"""Capture transactions sign and send as raw transactions
Keyword arguments:
private_key_or_account -- A single private key or a tuple,
list or set of private keys. Keys can be any of the following formats:
- An eth_account.Loca... | [
"def",
"construct_sign_and_send_raw_middleware",
"(",
"private_key_or_account",
")",
":",
"accounts",
"=",
"gen_normalized_accounts",
"(",
"private_key_or_account",
")",
"def",
"sign_and_send_raw_middleware",
"(",
"make_request",
",",
"w3",
")",
":",
"format_and_fill_tx",
"... | Capture transactions sign and send as raw transactions
Keyword arguments:
private_key_or_account -- A single private key or a tuple,
list or set of private keys. Keys can be any of the following formats:
- An eth_account.LocalAccount object
- An eth_keys.PrivateKey object
- A raw private... | [
"Capture",
"transactions",
"sign",
"and",
"send",
"as",
"raw",
"transactions"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/middleware/signing.py#L95-L136 | train |
ethereum/web3.py | web3/_utils/validation.py | validate_abi | def validate_abi(abi):
"""
Helper function for validating an ABI
"""
if not is_list_like(abi):
raise ValueError("'abi' is not a list")
if not all(is_dict(e) for e in abi):
raise ValueError("'abi' is not a list of dictionaries")
functions = filter_by_type('function', abi)
se... | python | def validate_abi(abi):
"""
Helper function for validating an ABI
"""
if not is_list_like(abi):
raise ValueError("'abi' is not a list")
if not all(is_dict(e) for e in abi):
raise ValueError("'abi' is not a list of dictionaries")
functions = filter_by_type('function', abi)
se... | [
"def",
"validate_abi",
"(",
"abi",
")",
":",
"if",
"not",
"is_list_like",
"(",
"abi",
")",
":",
"raise",
"ValueError",
"(",
"\"'abi' is not a list\"",
")",
"if",
"not",
"all",
"(",
"is_dict",
"(",
"e",
")",
"for",
"e",
"in",
"abi",
")",
":",
"raise",
... | Helper function for validating an ABI | [
"Helper",
"function",
"for",
"validating",
"an",
"ABI"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/_utils/validation.py#L55-L75 | train |
ethereum/web3.py | web3/_utils/validation.py | validate_address | def validate_address(value):
"""
Helper function for validating an address
"""
if is_bytes(value):
if not is_binary_address(value):
raise InvalidAddress("Address must be 20 bytes when input type is bytes", value)
return
if not isinstance(value, str):
raise TypeEr... | python | def validate_address(value):
"""
Helper function for validating an address
"""
if is_bytes(value):
if not is_binary_address(value):
raise InvalidAddress("Address must be 20 bytes when input type is bytes", value)
return
if not isinstance(value, str):
raise TypeEr... | [
"def",
"validate_address",
"(",
"value",
")",
":",
"if",
"is_bytes",
"(",
"value",
")",
":",
"if",
"not",
"is_binary_address",
"(",
"value",
")",
":",
"raise",
"InvalidAddress",
"(",
"\"Address must be 20 bytes when input type is bytes\"",
",",
"value",
")",
"retu... | Helper function for validating an address | [
"Helper",
"function",
"for",
"validating",
"an",
"address"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/_utils/validation.py#L142-L170 | train |
ethereum/web3.py | web3/middleware/cache.py | construct_simple_cache_middleware | def construct_simple_cache_middleware(
cache_class,
rpc_whitelist=SIMPLE_CACHE_RPC_WHITELIST,
should_cache_fn=_should_cache):
"""
Constructs a middleware which caches responses based on the request
``method`` and ``params``
:param cache: Any dictionary-like object
:param rpc... | python | def construct_simple_cache_middleware(
cache_class,
rpc_whitelist=SIMPLE_CACHE_RPC_WHITELIST,
should_cache_fn=_should_cache):
"""
Constructs a middleware which caches responses based on the request
``method`` and ``params``
:param cache: Any dictionary-like object
:param rpc... | [
"def",
"construct_simple_cache_middleware",
"(",
"cache_class",
",",
"rpc_whitelist",
"=",
"SIMPLE_CACHE_RPC_WHITELIST",
",",
"should_cache_fn",
"=",
"_should_cache",
")",
":",
"def",
"simple_cache_middleware",
"(",
"make_request",
",",
"web3",
")",
":",
"cache",
"=",
... | Constructs a middleware which caches responses based on the request
``method`` and ``params``
:param cache: Any dictionary-like object
:param rpc_whitelist: A set of RPC methods which may have their responses cached.
:param should_cache_fn: A callable which accepts ``method`` ``params`` and
``r... | [
"Constructs",
"a",
"middleware",
"which",
"caches",
"responses",
"based",
"on",
"the",
"request",
"method",
"and",
"params"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/middleware/cache.py#L74-L110 | train |
ethereum/web3.py | web3/middleware/cache.py | construct_time_based_cache_middleware | def construct_time_based_cache_middleware(
cache_class,
cache_expire_seconds=15,
rpc_whitelist=TIME_BASED_CACHE_RPC_WHITELIST,
should_cache_fn=_should_cache):
"""
Constructs a middleware which caches responses based on the request
``method`` and ``params`` for a maximum amoun... | python | def construct_time_based_cache_middleware(
cache_class,
cache_expire_seconds=15,
rpc_whitelist=TIME_BASED_CACHE_RPC_WHITELIST,
should_cache_fn=_should_cache):
"""
Constructs a middleware which caches responses based on the request
``method`` and ``params`` for a maximum amoun... | [
"def",
"construct_time_based_cache_middleware",
"(",
"cache_class",
",",
"cache_expire_seconds",
"=",
"15",
",",
"rpc_whitelist",
"=",
"TIME_BASED_CACHE_RPC_WHITELIST",
",",
"should_cache_fn",
"=",
"_should_cache",
")",
":",
"def",
"time_based_cache_middleware",
"(",
"make_... | Constructs a middleware which caches responses based on the request
``method`` and ``params`` for a maximum amount of time as specified
:param cache: Any dictionary-like object
:param cache_expire_seconds: The number of seconds an item may be cached
before it should expire.
:param rpc_whitelist... | [
"Constructs",
"a",
"middleware",
"which",
"caches",
"responses",
"based",
"on",
"the",
"request",
"method",
"and",
"params",
"for",
"a",
"maximum",
"amount",
"of",
"time",
"as",
"specified"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/middleware/cache.py#L170-L220 | train |
ethereum/web3.py | web3/_utils/decorators.py | reject_recursive_repeats | def reject_recursive_repeats(to_wrap):
"""
Prevent simple cycles by returning None when called recursively with same instance
"""
to_wrap.__already_called = {}
@functools.wraps(to_wrap)
def wrapped(*args):
arg_instances = tuple(map(id, args))
thread_id = threading.get_ident()
... | python | def reject_recursive_repeats(to_wrap):
"""
Prevent simple cycles by returning None when called recursively with same instance
"""
to_wrap.__already_called = {}
@functools.wraps(to_wrap)
def wrapped(*args):
arg_instances = tuple(map(id, args))
thread_id = threading.get_ident()
... | [
"def",
"reject_recursive_repeats",
"(",
"to_wrap",
")",
":",
"to_wrap",
".",
"__already_called",
"=",
"{",
"}",
"@",
"functools",
".",
"wraps",
"(",
"to_wrap",
")",
"def",
"wrapped",
"(",
"*",
"args",
")",
":",
"arg_instances",
"=",
"tuple",
"(",
"map",
... | Prevent simple cycles by returning None when called recursively with same instance | [
"Prevent",
"simple",
"cycles",
"by",
"returning",
"None",
"when",
"called",
"recursively",
"with",
"same",
"instance"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/_utils/decorators.py#L20-L39 | train |
ethereum/web3.py | web3/_utils/abi.py | get_tuple_type_str_parts | def get_tuple_type_str_parts(s: str) -> Optional[Tuple[str, Optional[str]]]:
"""
Takes a JSON ABI type string. For tuple type strings, returns the separated
prefix and array dimension parts. For all other strings, returns ``None``.
"""
match = TUPLE_TYPE_STR_RE.match(s)
if match is not None:
... | python | def get_tuple_type_str_parts(s: str) -> Optional[Tuple[str, Optional[str]]]:
"""
Takes a JSON ABI type string. For tuple type strings, returns the separated
prefix and array dimension parts. For all other strings, returns ``None``.
"""
match = TUPLE_TYPE_STR_RE.match(s)
if match is not None:
... | [
"def",
"get_tuple_type_str_parts",
"(",
"s",
":",
"str",
")",
"->",
"Optional",
"[",
"Tuple",
"[",
"str",
",",
"Optional",
"[",
"str",
"]",
"]",
"]",
":",
"match",
"=",
"TUPLE_TYPE_STR_RE",
".",
"match",
"(",
"s",
")",
"if",
"match",
"is",
"not",
"No... | Takes a JSON ABI type string. For tuple type strings, returns the separated
prefix and array dimension parts. For all other strings, returns ``None``. | [
"Takes",
"a",
"JSON",
"ABI",
"type",
"string",
".",
"For",
"tuple",
"type",
"strings",
"returns",
"the",
"separated",
"prefix",
"and",
"array",
"dimension",
"parts",
".",
"For",
"all",
"other",
"strings",
"returns",
"None",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/_utils/abi.py#L319-L332 | train |
ethereum/web3.py | web3/_utils/abi.py | _align_abi_input | def _align_abi_input(arg_abi, arg):
"""
Aligns the values of any mapping at any level of nesting in ``arg``
according to the layout of the corresponding abi spec.
"""
tuple_parts = get_tuple_type_str_parts(arg_abi['type'])
if tuple_parts is None:
# Arg is non-tuple. Just return value.
... | python | def _align_abi_input(arg_abi, arg):
"""
Aligns the values of any mapping at any level of nesting in ``arg``
according to the layout of the corresponding abi spec.
"""
tuple_parts = get_tuple_type_str_parts(arg_abi['type'])
if tuple_parts is None:
# Arg is non-tuple. Just return value.
... | [
"def",
"_align_abi_input",
"(",
"arg_abi",
",",
"arg",
")",
":",
"tuple_parts",
"=",
"get_tuple_type_str_parts",
"(",
"arg_abi",
"[",
"'type'",
"]",
")",
"if",
"tuple_parts",
"is",
"None",
":",
"# Arg is non-tuple. Just return value.",
"return",
"arg",
"tuple_prefi... | Aligns the values of any mapping at any level of nesting in ``arg``
according to the layout of the corresponding abi spec. | [
"Aligns",
"the",
"values",
"of",
"any",
"mapping",
"at",
"any",
"level",
"of",
"nesting",
"in",
"arg",
"according",
"to",
"the",
"layout",
"of",
"the",
"corresponding",
"abi",
"spec",
"."
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/_utils/abi.py#L335-L376 | train |
ethereum/web3.py | web3/_utils/abi.py | size_of_type | def size_of_type(abi_type):
"""
Returns size in bits of abi_type
"""
if 'string' in abi_type:
return None
if 'byte' in abi_type:
return None
if '[' in abi_type:
return None
if abi_type == 'bool':
return 8
if abi_type == 'address':
return 160
re... | python | def size_of_type(abi_type):
"""
Returns size in bits of abi_type
"""
if 'string' in abi_type:
return None
if 'byte' in abi_type:
return None
if '[' in abi_type:
return None
if abi_type == 'bool':
return 8
if abi_type == 'address':
return 160
re... | [
"def",
"size_of_type",
"(",
"abi_type",
")",
":",
"if",
"'string'",
"in",
"abi_type",
":",
"return",
"None",
"if",
"'byte'",
"in",
"abi_type",
":",
"return",
"None",
"if",
"'['",
"in",
"abi_type",
":",
"return",
"None",
"if",
"abi_type",
"==",
"'bool'",
... | Returns size in bits of abi_type | [
"Returns",
"size",
"in",
"bits",
"of",
"abi_type"
] | 71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab | https://github.com/ethereum/web3.py/blob/71b8bf03dc6d332dd97d8902a38ffab6f8b5a5ab/web3/_utils/abi.py#L485-L499 | train |
danielfrg/word2vec | word2vec/wordclusters.py | WordClusters.ix | def ix(self, word):
"""
Returns the index on self.vocab and self.clusters for 'word'
"""
temp = np.where(self.vocab == word)[0]
if temp.size == 0:
raise KeyError("Word not in vocabulary")
else:
return temp[0] | python | def ix(self, word):
"""
Returns the index on self.vocab and self.clusters for 'word'
"""
temp = np.where(self.vocab == word)[0]
if temp.size == 0:
raise KeyError("Word not in vocabulary")
else:
return temp[0] | [
"def",
"ix",
"(",
"self",
",",
"word",
")",
":",
"temp",
"=",
"np",
".",
"where",
"(",
"self",
".",
"vocab",
"==",
"word",
")",
"[",
"0",
"]",
"if",
"temp",
".",
"size",
"==",
"0",
":",
"raise",
"KeyError",
"(",
"\"Word not in vocabulary\"",
")",
... | Returns the index on self.vocab and self.clusters for 'word' | [
"Returns",
"the",
"index",
"on",
"self",
".",
"vocab",
"and",
"self",
".",
"clusters",
"for",
"word"
] | 762200acec2941a030abed69e946838af35eb2ae | https://github.com/danielfrg/word2vec/blob/762200acec2941a030abed69e946838af35eb2ae/word2vec/wordclusters.py#L10-L18 | train |
danielfrg/word2vec | word2vec/wordclusters.py | WordClusters.get_cluster | def get_cluster(self, word):
"""
Returns the cluster number for a word in the vocabulary
"""
idx = self.ix(word)
return self.clusters[idx] | python | def get_cluster(self, word):
"""
Returns the cluster number for a word in the vocabulary
"""
idx = self.ix(word)
return self.clusters[idx] | [
"def",
"get_cluster",
"(",
"self",
",",
"word",
")",
":",
"idx",
"=",
"self",
".",
"ix",
"(",
"word",
")",
"return",
"self",
".",
"clusters",
"[",
"idx",
"]"
] | Returns the cluster number for a word in the vocabulary | [
"Returns",
"the",
"cluster",
"number",
"for",
"a",
"word",
"in",
"the",
"vocabulary"
] | 762200acec2941a030abed69e946838af35eb2ae | https://github.com/danielfrg/word2vec/blob/762200acec2941a030abed69e946838af35eb2ae/word2vec/wordclusters.py#L23-L28 | train |
danielfrg/word2vec | word2vec/wordvectors.py | WordVectors.closest | def closest(self, vector, n=10, metric="cosine"):
"""Returns the closest n words to a vector
Parameters
-------
vector : numpy.array
n : int (default 10)
Returns
-------
Tuple of 2 numpy.array:
1. position in self.vocab
2. cosine ... | python | def closest(self, vector, n=10, metric="cosine"):
"""Returns the closest n words to a vector
Parameters
-------
vector : numpy.array
n : int (default 10)
Returns
-------
Tuple of 2 numpy.array:
1. position in self.vocab
2. cosine ... | [
"def",
"closest",
"(",
"self",
",",
"vector",
",",
"n",
"=",
"10",
",",
"metric",
"=",
"\"cosine\"",
")",
":",
"distances",
"=",
"distance",
"(",
"self",
".",
"vectors",
",",
"vector",
",",
"metric",
"=",
"metric",
")",
"best",
"=",
"np",
".",
"arg... | Returns the closest n words to a vector
Parameters
-------
vector : numpy.array
n : int (default 10)
Returns
-------
Tuple of 2 numpy.array:
1. position in self.vocab
2. cosine similarity | [
"Returns",
"the",
"closest",
"n",
"words",
"to",
"a",
"vector"
] | 762200acec2941a030abed69e946838af35eb2ae | https://github.com/danielfrg/word2vec/blob/762200acec2941a030abed69e946838af35eb2ae/word2vec/wordvectors.py#L90-L107 | train |
danielfrg/word2vec | word2vec/wordvectors.py | WordVectors.similar | def similar(self, word, n=10, metric="cosine"):
"""
Return similar words based on a metric
Parameters
----------
word : string
n : int (default 10)
Returns
-------
Tuple of 2 numpy.array:
1. position in self.vocab
2. cosin... | python | def similar(self, word, n=10, metric="cosine"):
"""
Return similar words based on a metric
Parameters
----------
word : string
n : int (default 10)
Returns
-------
Tuple of 2 numpy.array:
1. position in self.vocab
2. cosin... | [
"def",
"similar",
"(",
"self",
",",
"word",
",",
"n",
"=",
"10",
",",
"metric",
"=",
"\"cosine\"",
")",
":",
"return",
"self",
".",
"closest",
"(",
"self",
"[",
"word",
"]",
",",
"n",
"=",
"n",
",",
"metric",
"=",
"metric",
")"
] | Return similar words based on a metric
Parameters
----------
word : string
n : int (default 10)
Returns
-------
Tuple of 2 numpy.array:
1. position in self.vocab
2. cosine similarity | [
"Return",
"similar",
"words",
"based",
"on",
"a",
"metric"
] | 762200acec2941a030abed69e946838af35eb2ae | https://github.com/danielfrg/word2vec/blob/762200acec2941a030abed69e946838af35eb2ae/word2vec/wordvectors.py#L109-L124 | train |
danielfrg/word2vec | word2vec/wordvectors.py | WordVectors.analogy | def analogy(self, pos, neg, n=10, metric="cosine"):
"""
Analogy similarity.
Parameters
----------
pos : list
neg : list
Returns
-------
Tuple of 2 numpy.array:
1. position in self.vocab
2. cosine similarity
Exampl... | python | def analogy(self, pos, neg, n=10, metric="cosine"):
"""
Analogy similarity.
Parameters
----------
pos : list
neg : list
Returns
-------
Tuple of 2 numpy.array:
1. position in self.vocab
2. cosine similarity
Exampl... | [
"def",
"analogy",
"(",
"self",
",",
"pos",
",",
"neg",
",",
"n",
"=",
"10",
",",
"metric",
"=",
"\"cosine\"",
")",
":",
"exclude",
"=",
"pos",
"+",
"neg",
"pos",
"=",
"[",
"(",
"word",
",",
"1.0",
")",
"for",
"word",
"in",
"pos",
"]",
"neg",
... | Analogy similarity.
Parameters
----------
pos : list
neg : list
Returns
-------
Tuple of 2 numpy.array:
1. position in self.vocab
2. cosine similarity
Example
-------
`king - man + woman = queen` will be: `pos... | [
"Analogy",
"similarity",
"."
] | 762200acec2941a030abed69e946838af35eb2ae | https://github.com/danielfrg/word2vec/blob/762200acec2941a030abed69e946838af35eb2ae/word2vec/wordvectors.py#L126-L160 | train |
danielfrg/word2vec | word2vec/wordvectors.py | WordVectors.from_binary | def from_binary(
cls,
fname,
vocab_unicode_size=78,
desired_vocab=None,
encoding="utf-8",
new_lines=True,
):
"""
Create a WordVectors class based on a word2vec binary file
Parameters
----------
fname : p... | python | def from_binary(
cls,
fname,
vocab_unicode_size=78,
desired_vocab=None,
encoding="utf-8",
new_lines=True,
):
"""
Create a WordVectors class based on a word2vec binary file
Parameters
----------
fname : p... | [
"def",
"from_binary",
"(",
"cls",
",",
"fname",
",",
"vocab_unicode_size",
"=",
"78",
",",
"desired_vocab",
"=",
"None",
",",
"encoding",
"=",
"\"utf-8\"",
",",
"new_lines",
"=",
"True",
",",
")",
":",
"with",
"open",
"(",
"fname",
",",
"\"rb\"",
")",
... | Create a WordVectors class based on a word2vec binary file
Parameters
----------
fname : path to file
vocabUnicodeSize: the maximum string length (78, by default)
desired_vocab: if set any words that don't fall into this vocab will be droped
Returns
-------
... | [
"Create",
"a",
"WordVectors",
"class",
"based",
"on",
"a",
"word2vec",
"binary",
"file"
] | 762200acec2941a030abed69e946838af35eb2ae | https://github.com/danielfrg/word2vec/blob/762200acec2941a030abed69e946838af35eb2ae/word2vec/wordvectors.py#L179-L230 | train |
danielfrg/word2vec | word2vec/wordvectors.py | WordVectors.from_text | def from_text(cls, fname, vocabUnicodeSize=78, desired_vocab=None, encoding="utf-8"):
"""
Create a WordVectors class based on a word2vec text file
Parameters
----------
fname : path to file
vocabUnicodeSize: the maximum string length (78, by default)
desired_voca... | python | def from_text(cls, fname, vocabUnicodeSize=78, desired_vocab=None, encoding="utf-8"):
"""
Create a WordVectors class based on a word2vec text file
Parameters
----------
fname : path to file
vocabUnicodeSize: the maximum string length (78, by default)
desired_voca... | [
"def",
"from_text",
"(",
"cls",
",",
"fname",
",",
"vocabUnicodeSize",
"=",
"78",
",",
"desired_vocab",
"=",
"None",
",",
"encoding",
"=",
"\"utf-8\"",
")",
":",
"with",
"open",
"(",
"fname",
",",
"\"rb\"",
")",
"as",
"fin",
":",
"header",
"=",
"fin",
... | Create a WordVectors class based on a word2vec text file
Parameters
----------
fname : path to file
vocabUnicodeSize: the maximum string length (78, by default)
desired_vocab: if set, this will ignore any word and vector that
doesn't fall inside desired_vo... | [
"Create",
"a",
"WordVectors",
"class",
"based",
"on",
"a",
"word2vec",
"text",
"file"
] | 762200acec2941a030abed69e946838af35eb2ae | https://github.com/danielfrg/word2vec/blob/762200acec2941a030abed69e946838af35eb2ae/word2vec/wordvectors.py#L233-L267 | train |
danielfrg/word2vec | word2vec/wordvectors.py | WordVectors.from_mmap | def from_mmap(cls, fname):
"""
Create a WordVectors class from a memory map
Parameters
----------
fname : path to file
Returns
-------
WordVectors instance
"""
memmaped = joblib.load(fname, mmap_mode="r+")
return cls(vocab=memmape... | python | def from_mmap(cls, fname):
"""
Create a WordVectors class from a memory map
Parameters
----------
fname : path to file
Returns
-------
WordVectors instance
"""
memmaped = joblib.load(fname, mmap_mode="r+")
return cls(vocab=memmape... | [
"def",
"from_mmap",
"(",
"cls",
",",
"fname",
")",
":",
"memmaped",
"=",
"joblib",
".",
"load",
"(",
"fname",
",",
"mmap_mode",
"=",
"\"r+\"",
")",
"return",
"cls",
"(",
"vocab",
"=",
"memmaped",
".",
"vocab",
",",
"vectors",
"=",
"memmaped",
".",
"v... | Create a WordVectors class from a memory map
Parameters
----------
fname : path to file
Returns
-------
WordVectors instance | [
"Create",
"a",
"WordVectors",
"class",
"from",
"a",
"memory",
"map"
] | 762200acec2941a030abed69e946838af35eb2ae | https://github.com/danielfrg/word2vec/blob/762200acec2941a030abed69e946838af35eb2ae/word2vec/wordvectors.py#L270-L283 | train |
danielfrg/word2vec | word2vec/utils.py | distance | def distance(a, b, metric="cosine"):
"""
Calculate distance between two vectors based on a Metric
Metrics:
1. cosine distance. Note that in word2vec all the norms are 1 so the dot product is the same as cosine distance
"""
if metric == "cosine":
return np.dot(a, b.T)
raise Exception... | python | def distance(a, b, metric="cosine"):
"""
Calculate distance between two vectors based on a Metric
Metrics:
1. cosine distance. Note that in word2vec all the norms are 1 so the dot product is the same as cosine distance
"""
if metric == "cosine":
return np.dot(a, b.T)
raise Exception... | [
"def",
"distance",
"(",
"a",
",",
"b",
",",
"metric",
"=",
"\"cosine\"",
")",
":",
"if",
"metric",
"==",
"\"cosine\"",
":",
"return",
"np",
".",
"dot",
"(",
"a",
",",
"b",
".",
"T",
")",
"raise",
"Exception",
"(",
"\"Unknown metric '{metric}'\"",
".",
... | Calculate distance between two vectors based on a Metric
Metrics:
1. cosine distance. Note that in word2vec all the norms are 1 so the dot product is the same as cosine distance | [
"Calculate",
"distance",
"between",
"two",
"vectors",
"based",
"on",
"a",
"Metric"
] | 762200acec2941a030abed69e946838af35eb2ae | https://github.com/danielfrg/word2vec/blob/762200acec2941a030abed69e946838af35eb2ae/word2vec/utils.py#L8-L17 | train |
danielfrg/word2vec | word2vec/io.py | load | def load(fname, kind="auto", *args, **kwargs):
"""
Loads a word vectors file
"""
if kind == "auto":
if fname.endswith(".bin"):
kind = "bin"
elif fname.endswith(".txt"):
kind = "txt"
else:
raise Exception("Could not identify kind")
if kind =... | python | def load(fname, kind="auto", *args, **kwargs):
"""
Loads a word vectors file
"""
if kind == "auto":
if fname.endswith(".bin"):
kind = "bin"
elif fname.endswith(".txt"):
kind = "txt"
else:
raise Exception("Could not identify kind")
if kind =... | [
"def",
"load",
"(",
"fname",
",",
"kind",
"=",
"\"auto\"",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"kind",
"==",
"\"auto\"",
":",
"if",
"fname",
".",
"endswith",
"(",
"\".bin\"",
")",
":",
"kind",
"=",
"\"bin\"",
"elif",
"fname",... | Loads a word vectors file | [
"Loads",
"a",
"word",
"vectors",
"file"
] | 762200acec2941a030abed69e946838af35eb2ae | https://github.com/danielfrg/word2vec/blob/762200acec2941a030abed69e946838af35eb2ae/word2vec/io.py#L4-L22 | train |
django-crispy-forms/django-crispy-forms | crispy_forms/templatetags/crispy_forms_tags.py | ForLoopSimulator.iterate | def iterate(self):
"""
Updates values as if we had iterated over the for
"""
self.counter += 1
self.counter0 += 1
self.revcounter -= 1
self.revcounter0 -= 1
self.first = False
self.last = (self.revcounter0 == self.len_values - 1) | python | def iterate(self):
"""
Updates values as if we had iterated over the for
"""
self.counter += 1
self.counter0 += 1
self.revcounter -= 1
self.revcounter0 -= 1
self.first = False
self.last = (self.revcounter0 == self.len_values - 1) | [
"def",
"iterate",
"(",
"self",
")",
":",
"self",
".",
"counter",
"+=",
"1",
"self",
".",
"counter0",
"+=",
"1",
"self",
".",
"revcounter",
"-=",
"1",
"self",
".",
"revcounter0",
"-=",
"1",
"self",
".",
"first",
"=",
"False",
"self",
".",
"last",
"=... | Updates values as if we had iterated over the for | [
"Updates",
"values",
"as",
"if",
"we",
"had",
"iterated",
"over",
"the",
"for"
] | cd476927a756133c667c199bb12120f877bf6b7e | https://github.com/django-crispy-forms/django-crispy-forms/blob/cd476927a756133c667c199bb12120f877bf6b7e/crispy_forms/templatetags/crispy_forms_tags.py#L43-L52 | train |
django-crispy-forms/django-crispy-forms | crispy_forms/templatetags/crispy_forms_tags.py | BasicNode.get_render | def get_render(self, context):
"""
Returns a `Context` object with all the necessary stuff for rendering the form
:param context: `django.template.Context` variable holding the context for the node
`self.form` and `self.helper` are resolved into real Python objects resolving them
... | python | def get_render(self, context):
"""
Returns a `Context` object with all the necessary stuff for rendering the form
:param context: `django.template.Context` variable holding the context for the node
`self.form` and `self.helper` are resolved into real Python objects resolving them
... | [
"def",
"get_render",
"(",
"self",
",",
"context",
")",
":",
"# Nodes are not thread safe in multithreaded environments",
"# https://docs.djangoproject.com/en/dev/howto/custom-template-tags/#thread-safety-considerations",
"if",
"self",
"not",
"in",
"context",
".",
"render_context",
... | Returns a `Context` object with all the necessary stuff for rendering the form
:param context: `django.template.Context` variable holding the context for the node
`self.form` and `self.helper` are resolved into real Python objects resolving them
from the `context`. The `actual_form` can be a f... | [
"Returns",
"a",
"Context",
"object",
"with",
"all",
"the",
"necessary",
"stuff",
"for",
"rendering",
"the",
"form"
] | cd476927a756133c667c199bb12120f877bf6b7e | https://github.com/django-crispy-forms/django-crispy-forms/blob/cd476927a756133c667c199bb12120f877bf6b7e/crispy_forms/templatetags/crispy_forms_tags.py#L71-L133 | train |
django-crispy-forms/django-crispy-forms | crispy_forms/templatetags/crispy_forms_utils.py | specialspaceless | def specialspaceless(parser, token):
"""
Removes whitespace between HTML tags, and introduces a whitespace
after buttons an inputs, necessary for Bootstrap to place them
correctly in the layout.
"""
nodelist = parser.parse(('endspecialspaceless',))
parser.delete_first_token()
return Spe... | python | def specialspaceless(parser, token):
"""
Removes whitespace between HTML tags, and introduces a whitespace
after buttons an inputs, necessary for Bootstrap to place them
correctly in the layout.
"""
nodelist = parser.parse(('endspecialspaceless',))
parser.delete_first_token()
return Spe... | [
"def",
"specialspaceless",
"(",
"parser",
",",
"token",
")",
":",
"nodelist",
"=",
"parser",
".",
"parse",
"(",
"(",
"'endspecialspaceless'",
",",
")",
")",
"parser",
".",
"delete_first_token",
"(",
")",
"return",
"SpecialSpacelessNode",
"(",
"nodelist",
")"
] | Removes whitespace between HTML tags, and introduces a whitespace
after buttons an inputs, necessary for Bootstrap to place them
correctly in the layout. | [
"Removes",
"whitespace",
"between",
"HTML",
"tags",
"and",
"introduces",
"a",
"whitespace",
"after",
"buttons",
"an",
"inputs",
"necessary",
"for",
"Bootstrap",
"to",
"place",
"them",
"correctly",
"in",
"the",
"layout",
"."
] | cd476927a756133c667c199bb12120f877bf6b7e | https://github.com/django-crispy-forms/django-crispy-forms/blob/cd476927a756133c667c199bb12120f877bf6b7e/crispy_forms/templatetags/crispy_forms_utils.py#L38-L47 | train |
django-crispy-forms/django-crispy-forms | crispy_forms/bootstrap.py | ContainerHolder.first_container_with_errors | def first_container_with_errors(self, errors):
"""
Returns the first container with errors, otherwise returns None.
"""
for tab in self.fields:
errors_here = any(error in tab for error in errors)
if errors_here:
return tab
return None | python | def first_container_with_errors(self, errors):
"""
Returns the first container with errors, otherwise returns None.
"""
for tab in self.fields:
errors_here = any(error in tab for error in errors)
if errors_here:
return tab
return None | [
"def",
"first_container_with_errors",
"(",
"self",
",",
"errors",
")",
":",
"for",
"tab",
"in",
"self",
".",
"fields",
":",
"errors_here",
"=",
"any",
"(",
"error",
"in",
"tab",
"for",
"error",
"in",
"errors",
")",
"if",
"errors_here",
":",
"return",
"ta... | Returns the first container with errors, otherwise returns None. | [
"Returns",
"the",
"first",
"container",
"with",
"errors",
"otherwise",
"returns",
"None",
"."
] | cd476927a756133c667c199bb12120f877bf6b7e | https://github.com/django-crispy-forms/django-crispy-forms/blob/cd476927a756133c667c199bb12120f877bf6b7e/crispy_forms/bootstrap.py#L230-L238 | train |
django-crispy-forms/django-crispy-forms | crispy_forms/bootstrap.py | ContainerHolder.open_target_group_for_form | def open_target_group_for_form(self, form):
"""
Makes sure that the first group that should be open is open.
This is either the first group with errors or the first group
in the container, unless that first group was originally set to
active=False.
"""
target = se... | python | def open_target_group_for_form(self, form):
"""
Makes sure that the first group that should be open is open.
This is either the first group with errors or the first group
in the container, unless that first group was originally set to
active=False.
"""
target = se... | [
"def",
"open_target_group_for_form",
"(",
"self",
",",
"form",
")",
":",
"target",
"=",
"self",
".",
"first_container_with_errors",
"(",
"form",
".",
"errors",
".",
"keys",
"(",
")",
")",
"if",
"target",
"is",
"None",
":",
"target",
"=",
"self",
".",
"fi... | Makes sure that the first group that should be open is open.
This is either the first group with errors or the first group
in the container, unless that first group was originally set to
active=False. | [
"Makes",
"sure",
"that",
"the",
"first",
"group",
"that",
"should",
"be",
"open",
"is",
"open",
".",
"This",
"is",
"either",
"the",
"first",
"group",
"with",
"errors",
"or",
"the",
"first",
"group",
"in",
"the",
"container",
"unless",
"that",
"first",
"g... | cd476927a756133c667c199bb12120f877bf6b7e | https://github.com/django-crispy-forms/django-crispy-forms/blob/cd476927a756133c667c199bb12120f877bf6b7e/crispy_forms/bootstrap.py#L240-L255 | train |
django-crispy-forms/django-crispy-forms | crispy_forms/bootstrap.py | Tab.render_link | def render_link(self, template_pack=TEMPLATE_PACK, **kwargs):
"""
Render the link for the tab-pane. It must be called after render so css_class is updated
with active if needed.
"""
link_template = self.link_template % template_pack
return render_to_string(link_template, ... | python | def render_link(self, template_pack=TEMPLATE_PACK, **kwargs):
"""
Render the link for the tab-pane. It must be called after render so css_class is updated
with active if needed.
"""
link_template = self.link_template % template_pack
return render_to_string(link_template, ... | [
"def",
"render_link",
"(",
"self",
",",
"template_pack",
"=",
"TEMPLATE_PACK",
",",
"*",
"*",
"kwargs",
")",
":",
"link_template",
"=",
"self",
".",
"link_template",
"%",
"template_pack",
"return",
"render_to_string",
"(",
"link_template",
",",
"{",
"'link'",
... | Render the link for the tab-pane. It must be called after render so css_class is updated
with active if needed. | [
"Render",
"the",
"link",
"for",
"the",
"tab",
"-",
"pane",
".",
"It",
"must",
"be",
"called",
"after",
"render",
"so",
"css_class",
"is",
"updated",
"with",
"active",
"if",
"needed",
"."
] | cd476927a756133c667c199bb12120f877bf6b7e | https://github.com/django-crispy-forms/django-crispy-forms/blob/cd476927a756133c667c199bb12120f877bf6b7e/crispy_forms/bootstrap.py#L268-L274 | train |
django-crispy-forms/django-crispy-forms | crispy_forms/layout_slice.py | LayoutSlice.wrapped_object | def wrapped_object(self, LayoutClass, fields, *args, **kwargs):
"""
Returns a layout object of type `LayoutClass` with `args` and `kwargs` that
wraps `fields` inside.
"""
if args:
if isinstance(fields, list):
fields = tuple(fields)
else:
... | python | def wrapped_object(self, LayoutClass, fields, *args, **kwargs):
"""
Returns a layout object of type `LayoutClass` with `args` and `kwargs` that
wraps `fields` inside.
"""
if args:
if isinstance(fields, list):
fields = tuple(fields)
else:
... | [
"def",
"wrapped_object",
"(",
"self",
",",
"LayoutClass",
",",
"fields",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"args",
":",
"if",
"isinstance",
"(",
"fields",
",",
"list",
")",
":",
"fields",
"=",
"tuple",
"(",
"fields",
")",
"... | Returns a layout object of type `LayoutClass` with `args` and `kwargs` that
wraps `fields` inside. | [
"Returns",
"a",
"layout",
"object",
"of",
"type",
"LayoutClass",
"with",
"args",
"and",
"kwargs",
"that",
"wraps",
"fields",
"inside",
"."
] | cd476927a756133c667c199bb12120f877bf6b7e | https://github.com/django-crispy-forms/django-crispy-forms/blob/cd476927a756133c667c199bb12120f877bf6b7e/crispy_forms/layout_slice.py#L19-L40 | train |
django-crispy-forms/django-crispy-forms | crispy_forms/layout_slice.py | LayoutSlice.pre_map | def pre_map(self, function):
"""
Iterates over layout objects pointed in `self.slice` executing `function` on them.
It passes `function` penultimate layout object and the position where to find last one
"""
if isinstance(self.slice, slice):
for i in range(*self.slice.... | python | def pre_map(self, function):
"""
Iterates over layout objects pointed in `self.slice` executing `function` on them.
It passes `function` penultimate layout object and the position where to find last one
"""
if isinstance(self.slice, slice):
for i in range(*self.slice.... | [
"def",
"pre_map",
"(",
"self",
",",
"function",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"slice",
",",
"slice",
")",
":",
"for",
"i",
"in",
"range",
"(",
"*",
"self",
".",
"slice",
".",
"indices",
"(",
"len",
"(",
"self",
".",
"layout",
".... | Iterates over layout objects pointed in `self.slice` executing `function` on them.
It passes `function` penultimate layout object and the position where to find last one | [
"Iterates",
"over",
"layout",
"objects",
"pointed",
"in",
"self",
".",
"slice",
"executing",
"function",
"on",
"them",
".",
"It",
"passes",
"function",
"penultimate",
"layout",
"object",
"and",
"the",
"position",
"where",
"to",
"find",
"last",
"one"
] | cd476927a756133c667c199bb12120f877bf6b7e | https://github.com/django-crispy-forms/django-crispy-forms/blob/cd476927a756133c667c199bb12120f877bf6b7e/crispy_forms/layout_slice.py#L42-L70 | train |
django-crispy-forms/django-crispy-forms | crispy_forms/layout_slice.py | LayoutSlice.wrap | def wrap(self, LayoutClass, *args, **kwargs):
"""
Wraps every layout object pointed in `self.slice` under a `LayoutClass` instance with
`args` and `kwargs` passed.
"""
def wrap_object(layout_object, j):
layout_object.fields[j] = self.wrapped_object(
La... | python | def wrap(self, LayoutClass, *args, **kwargs):
"""
Wraps every layout object pointed in `self.slice` under a `LayoutClass` instance with
`args` and `kwargs` passed.
"""
def wrap_object(layout_object, j):
layout_object.fields[j] = self.wrapped_object(
La... | [
"def",
"wrap",
"(",
"self",
",",
"LayoutClass",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"wrap_object",
"(",
"layout_object",
",",
"j",
")",
":",
"layout_object",
".",
"fields",
"[",
"j",
"]",
"=",
"self",
".",
"wrapped_object",
"(... | Wraps every layout object pointed in `self.slice` under a `LayoutClass` instance with
`args` and `kwargs` passed. | [
"Wraps",
"every",
"layout",
"object",
"pointed",
"in",
"self",
".",
"slice",
"under",
"a",
"LayoutClass",
"instance",
"with",
"args",
"and",
"kwargs",
"passed",
"."
] | cd476927a756133c667c199bb12120f877bf6b7e | https://github.com/django-crispy-forms/django-crispy-forms/blob/cd476927a756133c667c199bb12120f877bf6b7e/crispy_forms/layout_slice.py#L72-L82 | train |
django-crispy-forms/django-crispy-forms | crispy_forms/layout_slice.py | LayoutSlice.wrap_once | def wrap_once(self, LayoutClass, *args, **kwargs):
"""
Wraps every layout object pointed in `self.slice` under a `LayoutClass` instance with
`args` and `kwargs` passed, unless layout object's parent is already a subclass of
`LayoutClass`.
"""
def wrap_object_once(layout_o... | python | def wrap_once(self, LayoutClass, *args, **kwargs):
"""
Wraps every layout object pointed in `self.slice` under a `LayoutClass` instance with
`args` and `kwargs` passed, unless layout object's parent is already a subclass of
`LayoutClass`.
"""
def wrap_object_once(layout_o... | [
"def",
"wrap_once",
"(",
"self",
",",
"LayoutClass",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"wrap_object_once",
"(",
"layout_object",
",",
"j",
")",
":",
"if",
"not",
"isinstance",
"(",
"layout_object",
",",
"LayoutClass",
")",
":",
... | Wraps every layout object pointed in `self.slice` under a `LayoutClass` instance with
`args` and `kwargs` passed, unless layout object's parent is already a subclass of
`LayoutClass`. | [
"Wraps",
"every",
"layout",
"object",
"pointed",
"in",
"self",
".",
"slice",
"under",
"a",
"LayoutClass",
"instance",
"with",
"args",
"and",
"kwargs",
"passed",
"unless",
"layout",
"object",
"s",
"parent",
"is",
"already",
"a",
"subclass",
"of",
"LayoutClass",... | cd476927a756133c667c199bb12120f877bf6b7e | https://github.com/django-crispy-forms/django-crispy-forms/blob/cd476927a756133c667c199bb12120f877bf6b7e/crispy_forms/layout_slice.py#L84-L96 | train |
django-crispy-forms/django-crispy-forms | crispy_forms/layout_slice.py | LayoutSlice.wrap_together | def wrap_together(self, LayoutClass, *args, **kwargs):
"""
Wraps all layout objects pointed in `self.slice` together under a `LayoutClass`
instance with `args` and `kwargs` passed.
"""
if isinstance(self.slice, slice):
# The start of the slice is replaced
... | python | def wrap_together(self, LayoutClass, *args, **kwargs):
"""
Wraps all layout objects pointed in `self.slice` together under a `LayoutClass`
instance with `args` and `kwargs` passed.
"""
if isinstance(self.slice, slice):
# The start of the slice is replaced
... | [
"def",
"wrap_together",
"(",
"self",
",",
"LayoutClass",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"slice",
",",
"slice",
")",
":",
"# The start of the slice is replaced",
"start",
"=",
"self",
".",
"slice",... | Wraps all layout objects pointed in `self.slice` together under a `LayoutClass`
instance with `args` and `kwargs` passed. | [
"Wraps",
"all",
"layout",
"objects",
"pointed",
"in",
"self",
".",
"slice",
"together",
"under",
"a",
"LayoutClass",
"instance",
"with",
"args",
"and",
"kwargs",
"passed",
"."
] | cd476927a756133c667c199bb12120f877bf6b7e | https://github.com/django-crispy-forms/django-crispy-forms/blob/cd476927a756133c667c199bb12120f877bf6b7e/crispy_forms/layout_slice.py#L98-L116 | train |
django-crispy-forms/django-crispy-forms | crispy_forms/layout_slice.py | LayoutSlice.map | def map(self, function):
"""
Iterates over layout objects pointed in `self.slice` executing `function` on them
It passes `function` last layout object
"""
if isinstance(self.slice, slice):
for i in range(*self.slice.indices(len(self.layout.fields))):
f... | python | def map(self, function):
"""
Iterates over layout objects pointed in `self.slice` executing `function` on them
It passes `function` last layout object
"""
if isinstance(self.slice, slice):
for i in range(*self.slice.indices(len(self.layout.fields))):
f... | [
"def",
"map",
"(",
"self",
",",
"function",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"slice",
",",
"slice",
")",
":",
"for",
"i",
"in",
"range",
"(",
"*",
"self",
".",
"slice",
".",
"indices",
"(",
"len",
"(",
"self",
".",
"layout",
".",
... | Iterates over layout objects pointed in `self.slice` executing `function` on them
It passes `function` last layout object | [
"Iterates",
"over",
"layout",
"objects",
"pointed",
"in",
"self",
".",
"slice",
"executing",
"function",
"on",
"them",
"It",
"passes",
"function",
"last",
"layout",
"object"
] | cd476927a756133c667c199bb12120f877bf6b7e | https://github.com/django-crispy-forms/django-crispy-forms/blob/cd476927a756133c667c199bb12120f877bf6b7e/crispy_forms/layout_slice.py#L118-L144 | train |
django-crispy-forms/django-crispy-forms | crispy_forms/layout_slice.py | LayoutSlice.update_attributes | def update_attributes(self, **original_kwargs):
"""
Updates attributes of every layout object pointed in `self.slice` using kwargs
"""
def update_attrs(layout_object):
kwargs = original_kwargs.copy()
if hasattr(layout_object, 'attrs'):
if 'css_clas... | python | def update_attributes(self, **original_kwargs):
"""
Updates attributes of every layout object pointed in `self.slice` using kwargs
"""
def update_attrs(layout_object):
kwargs = original_kwargs.copy()
if hasattr(layout_object, 'attrs'):
if 'css_clas... | [
"def",
"update_attributes",
"(",
"self",
",",
"*",
"*",
"original_kwargs",
")",
":",
"def",
"update_attrs",
"(",
"layout_object",
")",
":",
"kwargs",
"=",
"original_kwargs",
".",
"copy",
"(",
")",
"if",
"hasattr",
"(",
"layout_object",
",",
"'attrs'",
")",
... | Updates attributes of every layout object pointed in `self.slice` using kwargs | [
"Updates",
"attributes",
"of",
"every",
"layout",
"object",
"pointed",
"in",
"self",
".",
"slice",
"using",
"kwargs"
] | cd476927a756133c667c199bb12120f877bf6b7e | https://github.com/django-crispy-forms/django-crispy-forms/blob/cd476927a756133c667c199bb12120f877bf6b7e/crispy_forms/layout_slice.py#L146-L160 | train |
django-crispy-forms/django-crispy-forms | crispy_forms/helper.py | DynamicLayoutHandler.all | def all(self):
"""
Returns all layout objects of first level of depth
"""
self._check_layout()
return LayoutSlice(self.layout, slice(0, len(self.layout.fields), 1)) | python | def all(self):
"""
Returns all layout objects of first level of depth
"""
self._check_layout()
return LayoutSlice(self.layout, slice(0, len(self.layout.fields), 1)) | [
"def",
"all",
"(",
"self",
")",
":",
"self",
".",
"_check_layout",
"(",
")",
"return",
"LayoutSlice",
"(",
"self",
".",
"layout",
",",
"slice",
"(",
"0",
",",
"len",
"(",
"self",
".",
"layout",
".",
"fields",
")",
",",
"1",
")",
")"
] | Returns all layout objects of first level of depth | [
"Returns",
"all",
"layout",
"objects",
"of",
"first",
"level",
"of",
"depth"
] | cd476927a756133c667c199bb12120f877bf6b7e | https://github.com/django-crispy-forms/django-crispy-forms/blob/cd476927a756133c667c199bb12120f877bf6b7e/crispy_forms/helper.py#L31-L36 | train |
django-crispy-forms/django-crispy-forms | crispy_forms/helper.py | DynamicLayoutHandler.filter | def filter(self, *LayoutClasses, **kwargs):
"""
Returns a LayoutSlice pointing to layout objects of type `LayoutClass`
"""
self._check_layout()
max_level = kwargs.pop('max_level', 0)
greedy = kwargs.pop('greedy', False)
filtered_layout_objects = self.layout.get_la... | python | def filter(self, *LayoutClasses, **kwargs):
"""
Returns a LayoutSlice pointing to layout objects of type `LayoutClass`
"""
self._check_layout()
max_level = kwargs.pop('max_level', 0)
greedy = kwargs.pop('greedy', False)
filtered_layout_objects = self.layout.get_la... | [
"def",
"filter",
"(",
"self",
",",
"*",
"LayoutClasses",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_check_layout",
"(",
")",
"max_level",
"=",
"kwargs",
".",
"pop",
"(",
"'max_level'",
",",
"0",
")",
"greedy",
"=",
"kwargs",
".",
"pop",
"(",
... | Returns a LayoutSlice pointing to layout objects of type `LayoutClass` | [
"Returns",
"a",
"LayoutSlice",
"pointing",
"to",
"layout",
"objects",
"of",
"type",
"LayoutClass"
] | cd476927a756133c667c199bb12120f877bf6b7e | https://github.com/django-crispy-forms/django-crispy-forms/blob/cd476927a756133c667c199bb12120f877bf6b7e/crispy_forms/helper.py#L38-L47 | train |
django-crispy-forms/django-crispy-forms | crispy_forms/helper.py | DynamicLayoutHandler.filter_by_widget | def filter_by_widget(self, widget_type):
"""
Returns a LayoutSlice pointing to fields with widgets of `widget_type`
"""
self._check_layout_and_form()
layout_field_names = self.layout.get_field_names()
# Let's filter all fields with widgets like widget_type
filter... | python | def filter_by_widget(self, widget_type):
"""
Returns a LayoutSlice pointing to fields with widgets of `widget_type`
"""
self._check_layout_and_form()
layout_field_names = self.layout.get_field_names()
# Let's filter all fields with widgets like widget_type
filter... | [
"def",
"filter_by_widget",
"(",
"self",
",",
"widget_type",
")",
":",
"self",
".",
"_check_layout_and_form",
"(",
")",
"layout_field_names",
"=",
"self",
".",
"layout",
".",
"get_field_names",
"(",
")",
"# Let's filter all fields with widgets like widget_type",
"filtere... | Returns a LayoutSlice pointing to fields with widgets of `widget_type` | [
"Returns",
"a",
"LayoutSlice",
"pointing",
"to",
"fields",
"with",
"widgets",
"of",
"widget_type"
] | cd476927a756133c667c199bb12120f877bf6b7e | https://github.com/django-crispy-forms/django-crispy-forms/blob/cd476927a756133c667c199bb12120f877bf6b7e/crispy_forms/helper.py#L49-L62 | train |
django-crispy-forms/django-crispy-forms | crispy_forms/helper.py | FormHelper.get_attributes | def get_attributes(self, template_pack=TEMPLATE_PACK):
"""
Used by crispy_forms_tags to get helper attributes
"""
items = {
'form_method': self.form_method.strip(),
'form_tag': self.form_tag,
'form_style': self.form_style.strip(),
'form_sho... | python | def get_attributes(self, template_pack=TEMPLATE_PACK):
"""
Used by crispy_forms_tags to get helper attributes
"""
items = {
'form_method': self.form_method.strip(),
'form_tag': self.form_tag,
'form_style': self.form_style.strip(),
'form_sho... | [
"def",
"get_attributes",
"(",
"self",
",",
"template_pack",
"=",
"TEMPLATE_PACK",
")",
":",
"items",
"=",
"{",
"'form_method'",
":",
"self",
".",
"form_method",
".",
"strip",
"(",
")",
",",
"'form_tag'",
":",
"self",
".",
"form_tag",
",",
"'form_style'",
"... | Used by crispy_forms_tags to get helper attributes | [
"Used",
"by",
"crispy_forms_tags",
"to",
"get",
"helper",
"attributes"
] | cd476927a756133c667c199bb12120f877bf6b7e | https://github.com/django-crispy-forms/django-crispy-forms/blob/cd476927a756133c667c199bb12120f877bf6b7e/crispy_forms/helper.py#L353-L421 | train |
django-crispy-forms/django-crispy-forms | crispy_forms/utils.py | flatatt | def flatatt(attrs):
"""
Convert a dictionary of attributes to a single string.
Passed attributes are redirected to `django.forms.utils.flatatt()`
with replaced "_" (underscores) by "-" (dashes) in their names.
"""
return _flatatt({k.replace('_', '-'): v for k, v in attrs.items()}) | python | def flatatt(attrs):
"""
Convert a dictionary of attributes to a single string.
Passed attributes are redirected to `django.forms.utils.flatatt()`
with replaced "_" (underscores) by "-" (dashes) in their names.
"""
return _flatatt({k.replace('_', '-'): v for k, v in attrs.items()}) | [
"def",
"flatatt",
"(",
"attrs",
")",
":",
"return",
"_flatatt",
"(",
"{",
"k",
".",
"replace",
"(",
"'_'",
",",
"'-'",
")",
":",
"v",
"for",
"k",
",",
"v",
"in",
"attrs",
".",
"items",
"(",
")",
"}",
")"
] | Convert a dictionary of attributes to a single string.
Passed attributes are redirected to `django.forms.utils.flatatt()`
with replaced "_" (underscores) by "-" (dashes) in their names. | [
"Convert",
"a",
"dictionary",
"of",
"attributes",
"to",
"a",
"single",
"string",
"."
] | cd476927a756133c667c199bb12120f877bf6b7e | https://github.com/django-crispy-forms/django-crispy-forms/blob/cd476927a756133c667c199bb12120f877bf6b7e/crispy_forms/utils.py#L153-L160 | train |
django-crispy-forms/django-crispy-forms | crispy_forms/utils.py | render_crispy_form | def render_crispy_form(form, helper=None, context=None):
"""
Renders a form and returns its HTML output.
This function wraps the template logic in a function easy to use in a Django view.
"""
from crispy_forms.templatetags.crispy_forms_tags import CrispyFormNode
if helper is not None:
... | python | def render_crispy_form(form, helper=None, context=None):
"""
Renders a form and returns its HTML output.
This function wraps the template logic in a function easy to use in a Django view.
"""
from crispy_forms.templatetags.crispy_forms_tags import CrispyFormNode
if helper is not None:
... | [
"def",
"render_crispy_form",
"(",
"form",
",",
"helper",
"=",
"None",
",",
"context",
"=",
"None",
")",
":",
"from",
"crispy_forms",
".",
"templatetags",
".",
"crispy_forms_tags",
"import",
"CrispyFormNode",
"if",
"helper",
"is",
"not",
"None",
":",
"node",
... | Renders a form and returns its HTML output.
This function wraps the template logic in a function easy to use in a Django view. | [
"Renders",
"a",
"form",
"and",
"returns",
"its",
"HTML",
"output",
"."
] | cd476927a756133c667c199bb12120f877bf6b7e | https://github.com/django-crispy-forms/django-crispy-forms/blob/cd476927a756133c667c199bb12120f877bf6b7e/crispy_forms/utils.py#L163-L182 | train |
moderngl/moderngl | moderngl/vertex_array.py | VertexArray.bind | def bind(self, attribute, cls, buffer, fmt, *, offset=0, stride=0, divisor=0, normalize=False) -> None:
'''
Bind individual attributes to buffers.
Args:
location (int): The attribute location.
cls (str): The attribute class. Valid values are ``f``, ``i`` ... | python | def bind(self, attribute, cls, buffer, fmt, *, offset=0, stride=0, divisor=0, normalize=False) -> None:
'''
Bind individual attributes to buffers.
Args:
location (int): The attribute location.
cls (str): The attribute class. Valid values are ``f``, ``i`` ... | [
"def",
"bind",
"(",
"self",
",",
"attribute",
",",
"cls",
",",
"buffer",
",",
"fmt",
",",
"*",
",",
"offset",
"=",
"0",
",",
"stride",
"=",
"0",
",",
"divisor",
"=",
"0",
",",
"normalize",
"=",
"False",
")",
"->",
"None",
":",
"self",
".",
"mgl... | Bind individual attributes to buffers.
Args:
location (int): The attribute location.
cls (str): The attribute class. Valid values are ``f``, ``i`` or ``d``.
buffer (Buffer): The buffer.
format (str): The buffer format.
Keyword Arg... | [
"Bind",
"individual",
"attributes",
"to",
"buffers",
"."
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/moderngl/vertex_array.py#L173-L190 | train |
moderngl/moderngl | examples/08_compute_shader.py | source | def source(uri, consts):
''' read gl code '''
with open(uri, 'r') as fp:
content = fp.read()
# feed constant values
for key, value in consts.items():
content = content.replace(f"%%{key}%%", str(value))
return content | python | def source(uri, consts):
''' read gl code '''
with open(uri, 'r') as fp:
content = fp.read()
# feed constant values
for key, value in consts.items():
content = content.replace(f"%%{key}%%", str(value))
return content | [
"def",
"source",
"(",
"uri",
",",
"consts",
")",
":",
"with",
"open",
"(",
"uri",
",",
"'r'",
")",
"as",
"fp",
":",
"content",
"=",
"fp",
".",
"read",
"(",
")",
"# feed constant values",
"for",
"key",
",",
"value",
"in",
"consts",
".",
"items",
"("... | read gl code | [
"read",
"gl",
"code"
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/examples/08_compute_shader.py#L17-L25 | train |
moderngl/moderngl | moderngl/context.py | create_standalone_context | def create_standalone_context(require=None, **settings) -> 'Context':
'''
Create a standalone ModernGL context.
Example::
# Create a context with highest possible supported version
ctx = moderngl.create_context()
# Require at least OpenGL 4.3
ctx = ... | python | def create_standalone_context(require=None, **settings) -> 'Context':
'''
Create a standalone ModernGL context.
Example::
# Create a context with highest possible supported version
ctx = moderngl.create_context()
# Require at least OpenGL 4.3
ctx = ... | [
"def",
"create_standalone_context",
"(",
"require",
"=",
"None",
",",
"*",
"*",
"settings",
")",
"->",
"'Context'",
":",
"backend",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'MODERNGL_BACKEND'",
")",
"if",
"backend",
"is",
"not",
"None",
":",
"settings"... | Create a standalone ModernGL context.
Example::
# Create a context with highest possible supported version
ctx = moderngl.create_context()
# Require at least OpenGL 4.3
ctx = moderngl.create_context(require=430)
Keyword Arguments:
require (... | [
"Create",
"a",
"standalone",
"ModernGL",
"context",
"."
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/moderngl/context.py#L1135-L1169 | train |
moderngl/moderngl | moderngl/context.py | Context.copy_buffer | def copy_buffer(self, dst, src, size=-1, *, read_offset=0, write_offset=0) -> None:
'''
Copy buffer content.
Args:
dst (Buffer): The destination buffer.
src (Buffer): The source buffer.
size (int): The number of bytes to copy.
... | python | def copy_buffer(self, dst, src, size=-1, *, read_offset=0, write_offset=0) -> None:
'''
Copy buffer content.
Args:
dst (Buffer): The destination buffer.
src (Buffer): The source buffer.
size (int): The number of bytes to copy.
... | [
"def",
"copy_buffer",
"(",
"self",
",",
"dst",
",",
"src",
",",
"size",
"=",
"-",
"1",
",",
"*",
",",
"read_offset",
"=",
"0",
",",
"write_offset",
"=",
"0",
")",
"->",
"None",
":",
"self",
".",
"mglo",
".",
"copy_buffer",
"(",
"dst",
".",
"mglo"... | Copy buffer content.
Args:
dst (Buffer): The destination buffer.
src (Buffer): The source buffer.
size (int): The number of bytes to copy.
Keyword Args:
read_offset (int): The read offset.
write_offset (int): The w... | [
"Copy",
"buffer",
"content",
"."
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/moderngl/context.py#L505-L519 | train |
moderngl/moderngl | moderngl/context.py | Context.copy_framebuffer | def copy_framebuffer(self, dst, src) -> None:
'''
Copy framebuffer content.
Use this method to:
- blit framebuffers.
- copy framebuffer content into a texture.
- downsample framebuffers. (it will allow to read the framebuffer's content)
... | python | def copy_framebuffer(self, dst, src) -> None:
'''
Copy framebuffer content.
Use this method to:
- blit framebuffers.
- copy framebuffer content into a texture.
- downsample framebuffers. (it will allow to read the framebuffer's content)
... | [
"def",
"copy_framebuffer",
"(",
"self",
",",
"dst",
",",
"src",
")",
"->",
"None",
":",
"self",
".",
"mglo",
".",
"copy_framebuffer",
"(",
"dst",
".",
"mglo",
",",
"src",
".",
"mglo",
")"
] | Copy framebuffer content.
Use this method to:
- blit framebuffers.
- copy framebuffer content into a texture.
- downsample framebuffers. (it will allow to read the framebuffer's content)
- downsample a framebuffer directly to a texture.
... | [
"Copy",
"framebuffer",
"content",
"."
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/moderngl/context.py#L521-L537 | train |
moderngl/moderngl | moderngl/context.py | Context.detect_framebuffer | def detect_framebuffer(self, glo=None) -> 'Framebuffer':
'''
Detect framebuffer.
Args:
glo (int): Framebuffer object.
Returns:
:py:class:`Framebuffer` object
'''
res = Framebuffer.__new__(Framebuffer)
res.mglo, res._s... | python | def detect_framebuffer(self, glo=None) -> 'Framebuffer':
'''
Detect framebuffer.
Args:
glo (int): Framebuffer object.
Returns:
:py:class:`Framebuffer` object
'''
res = Framebuffer.__new__(Framebuffer)
res.mglo, res._s... | [
"def",
"detect_framebuffer",
"(",
"self",
",",
"glo",
"=",
"None",
")",
"->",
"'Framebuffer'",
":",
"res",
"=",
"Framebuffer",
".",
"__new__",
"(",
"Framebuffer",
")",
"res",
".",
"mglo",
",",
"res",
".",
"_size",
",",
"res",
".",
"_samples",
",",
"res... | Detect framebuffer.
Args:
glo (int): Framebuffer object.
Returns:
:py:class:`Framebuffer` object | [
"Detect",
"framebuffer",
"."
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/moderngl/context.py#L539-L556 | train |
moderngl/moderngl | moderngl/context.py | Context.core_profile_check | def core_profile_check(self) -> None:
'''
Core profile check.
FOR DEBUG PURPOSES ONLY
'''
profile_mask = self.info['GL_CONTEXT_PROFILE_MASK']
if profile_mask != 1:
warnings.warn('The window should request a CORE OpenGL profile')
version_code... | python | def core_profile_check(self) -> None:
'''
Core profile check.
FOR DEBUG PURPOSES ONLY
'''
profile_mask = self.info['GL_CONTEXT_PROFILE_MASK']
if profile_mask != 1:
warnings.warn('The window should request a CORE OpenGL profile')
version_code... | [
"def",
"core_profile_check",
"(",
"self",
")",
"->",
"None",
":",
"profile_mask",
"=",
"self",
".",
"info",
"[",
"'GL_CONTEXT_PROFILE_MASK'",
"]",
"if",
"profile_mask",
"!=",
"1",
":",
"warnings",
".",
"warn",
"(",
"'The window should request a CORE OpenGL profile'"... | Core profile check.
FOR DEBUG PURPOSES ONLY | [
"Core",
"profile",
"check",
"."
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/moderngl/context.py#L1072-L1089 | train |
moderngl/moderngl | examples/window/glfw/window.py | Window.mouse_button_callback | def mouse_button_callback(self, window, button, action, mods):
"""
Handle mouse button events and forward them to the example
"""
# Offset button index by 1 to make it match the other libraries
button += 1
# Support left and right mouse button for now
if bu... | python | def mouse_button_callback(self, window, button, action, mods):
"""
Handle mouse button events and forward them to the example
"""
# Offset button index by 1 to make it match the other libraries
button += 1
# Support left and right mouse button for now
if bu... | [
"def",
"mouse_button_callback",
"(",
"self",
",",
"window",
",",
"button",
",",
"action",
",",
"mods",
")",
":",
"# Offset button index by 1 to make it match the other libraries\r",
"button",
"+=",
"1",
"# Support left and right mouse button for now\r",
"if",
"button",
"not... | Handle mouse button events and forward them to the example | [
"Handle",
"mouse",
"button",
"events",
"and",
"forward",
"them",
"to",
"the",
"example"
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/examples/window/glfw/window.py#L121-L136 | train |
moderngl/moderngl | moderngl/buffer.py | Buffer.write_chunks | def write_chunks(self, data, start, step, count) -> None:
'''
Split data to count equal parts.
Write the chunks using offsets calculated from start, step and stop.
Args:
data (bytes): The data.
start (int): First offset.
step ... | python | def write_chunks(self, data, start, step, count) -> None:
'''
Split data to count equal parts.
Write the chunks using offsets calculated from start, step and stop.
Args:
data (bytes): The data.
start (int): First offset.
step ... | [
"def",
"write_chunks",
"(",
"self",
",",
"data",
",",
"start",
",",
"step",
",",
"count",
")",
"->",
"None",
":",
"self",
".",
"mglo",
".",
"write_chunks",
"(",
"data",
",",
"start",
",",
"step",
",",
"count",
")"
] | Split data to count equal parts.
Write the chunks using offsets calculated from start, step and stop.
Args:
data (bytes): The data.
start (int): First offset.
step (int): Offset increment.
count (int): The number of offsets. | [
"Split",
"data",
"to",
"count",
"equal",
"parts",
"."
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/moderngl/buffer.py#L72-L85 | train |
moderngl/moderngl | moderngl/buffer.py | Buffer.read_into | def read_into(self, buffer, size=-1, *, offset=0, write_offset=0) -> None:
'''
Read the content into a buffer.
Args:
buffer (bytarray): The buffer that will receive the content.
size (int): The size. Value ``-1`` means all.
Keyword Args:
... | python | def read_into(self, buffer, size=-1, *, offset=0, write_offset=0) -> None:
'''
Read the content into a buffer.
Args:
buffer (bytarray): The buffer that will receive the content.
size (int): The size. Value ``-1`` means all.
Keyword Args:
... | [
"def",
"read_into",
"(",
"self",
",",
"buffer",
",",
"size",
"=",
"-",
"1",
",",
"*",
",",
"offset",
"=",
"0",
",",
"write_offset",
"=",
"0",
")",
"->",
"None",
":",
"return",
"self",
".",
"mglo",
".",
"read_into",
"(",
"buffer",
",",
"size",
","... | Read the content into a buffer.
Args:
buffer (bytarray): The buffer that will receive the content.
size (int): The size. Value ``-1`` means all.
Keyword Args:
offset (int): The read offset.
write_offset (int): The write offset. | [
"Read",
"the",
"content",
"into",
"a",
"buffer",
"."
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/moderngl/buffer.py#L103-L116 | train |
moderngl/moderngl | moderngl/buffer.py | Buffer.clear | def clear(self, size=-1, *, offset=0, chunk=None) -> None:
'''
Clear the content.
Args:
size (int): The size. Value ``-1`` means all.
Keyword Args:
offset (int): The offset.
chunk (bytes): The chunk to use repeatedly.
... | python | def clear(self, size=-1, *, offset=0, chunk=None) -> None:
'''
Clear the content.
Args:
size (int): The size. Value ``-1`` means all.
Keyword Args:
offset (int): The offset.
chunk (bytes): The chunk to use repeatedly.
... | [
"def",
"clear",
"(",
"self",
",",
"size",
"=",
"-",
"1",
",",
"*",
",",
"offset",
"=",
"0",
",",
"chunk",
"=",
"None",
")",
"->",
"None",
":",
"self",
".",
"mglo",
".",
"clear",
"(",
"size",
",",
"offset",
",",
"chunk",
")"
] | Clear the content.
Args:
size (int): The size. Value ``-1`` means all.
Keyword Args:
offset (int): The offset.
chunk (bytes): The chunk to use repeatedly. | [
"Clear",
"the",
"content",
"."
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/moderngl/buffer.py#L157-L169 | train |
moderngl/moderngl | moderngl/buffer.py | Buffer.bind_to_uniform_block | def bind_to_uniform_block(self, binding=0, *, offset=0, size=-1) -> None:
'''
Bind the buffer to a uniform block.
Args:
binding (int): The uniform block binding.
Keyword Args:
offset (int): The offset.
size (int): The size. Va... | python | def bind_to_uniform_block(self, binding=0, *, offset=0, size=-1) -> None:
'''
Bind the buffer to a uniform block.
Args:
binding (int): The uniform block binding.
Keyword Args:
offset (int): The offset.
size (int): The size. Va... | [
"def",
"bind_to_uniform_block",
"(",
"self",
",",
"binding",
"=",
"0",
",",
"*",
",",
"offset",
"=",
"0",
",",
"size",
"=",
"-",
"1",
")",
"->",
"None",
":",
"self",
".",
"mglo",
".",
"bind_to_uniform_block",
"(",
"binding",
",",
"offset",
",",
"size... | Bind the buffer to a uniform block.
Args:
binding (int): The uniform block binding.
Keyword Args:
offset (int): The offset.
size (int): The size. Value ``-1`` means all. | [
"Bind",
"the",
"buffer",
"to",
"a",
"uniform",
"block",
"."
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/moderngl/buffer.py#L171-L183 | train |
moderngl/moderngl | moderngl/buffer.py | Buffer.bind_to_storage_buffer | def bind_to_storage_buffer(self, binding=0, *, offset=0, size=-1) -> None:
'''
Bind the buffer to a shader storage buffer.
Args:
binding (int): The shader storage binding.
Keyword Args:
offset (int): The offset.
size (int): Th... | python | def bind_to_storage_buffer(self, binding=0, *, offset=0, size=-1) -> None:
'''
Bind the buffer to a shader storage buffer.
Args:
binding (int): The shader storage binding.
Keyword Args:
offset (int): The offset.
size (int): Th... | [
"def",
"bind_to_storage_buffer",
"(",
"self",
",",
"binding",
"=",
"0",
",",
"*",
",",
"offset",
"=",
"0",
",",
"size",
"=",
"-",
"1",
")",
"->",
"None",
":",
"self",
".",
"mglo",
".",
"bind_to_storage_buffer",
"(",
"binding",
",",
"offset",
",",
"si... | Bind the buffer to a shader storage buffer.
Args:
binding (int): The shader storage binding.
Keyword Args:
offset (int): The offset.
size (int): The size. Value ``-1`` means all. | [
"Bind",
"the",
"buffer",
"to",
"a",
"shader",
"storage",
"buffer",
"."
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/moderngl/buffer.py#L185-L197 | train |
moderngl/moderngl | examples/window/pyqt5/window.py | Window.swap_buffers | def swap_buffers(self):
"""
Swap buffers, set viewport, trigger events and increment frame counter
"""
self.widget.swapBuffers()
self.set_default_viewport()
self.app.processEvents()
self.frames += 1 | python | def swap_buffers(self):
"""
Swap buffers, set viewport, trigger events and increment frame counter
"""
self.widget.swapBuffers()
self.set_default_viewport()
self.app.processEvents()
self.frames += 1 | [
"def",
"swap_buffers",
"(",
"self",
")",
":",
"self",
".",
"widget",
".",
"swapBuffers",
"(",
")",
"self",
".",
"set_default_viewport",
"(",
")",
"self",
".",
"app",
".",
"processEvents",
"(",
")",
"self",
".",
"frames",
"+=",
"1"
] | Swap buffers, set viewport, trigger events and increment frame counter | [
"Swap",
"buffers",
"set",
"viewport",
"trigger",
"events",
"and",
"increment",
"frame",
"counter"
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/examples/window/pyqt5/window.py#L100-L107 | train |
moderngl/moderngl | examples/window/pyqt5/window.py | Window.resize | def resize(self, width: int, height: int):
"""
Replacement for Qt's resizeGL method.
"""
self.width = width // self.widget.devicePixelRatio()
self.height = height // self.widget.devicePixelRatio()
self.buffer_width = width
self.buffer_height = height
... | python | def resize(self, width: int, height: int):
"""
Replacement for Qt's resizeGL method.
"""
self.width = width // self.widget.devicePixelRatio()
self.height = height // self.widget.devicePixelRatio()
self.buffer_width = width
self.buffer_height = height
... | [
"def",
"resize",
"(",
"self",
",",
"width",
":",
"int",
",",
"height",
":",
"int",
")",
":",
"self",
".",
"width",
"=",
"width",
"//",
"self",
".",
"widget",
".",
"devicePixelRatio",
"(",
")",
"self",
".",
"height",
"=",
"height",
"//",
"self",
"."... | Replacement for Qt's resizeGL method. | [
"Replacement",
"for",
"Qt",
"s",
"resizeGL",
"method",
"."
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/examples/window/pyqt5/window.py#L109-L122 | train |
moderngl/moderngl | examples/window/pyqt5/window.py | Window.key_pressed_event | def key_pressed_event(self, event):
"""
Process Qt key press events forwarding them to the example
"""
if event.key() == self.keys.ESCAPE:
self.close()
self.example.key_event(event.key(), self.keys.ACTION_PRESS) | python | def key_pressed_event(self, event):
"""
Process Qt key press events forwarding them to the example
"""
if event.key() == self.keys.ESCAPE:
self.close()
self.example.key_event(event.key(), self.keys.ACTION_PRESS) | [
"def",
"key_pressed_event",
"(",
"self",
",",
"event",
")",
":",
"if",
"event",
".",
"key",
"(",
")",
"==",
"self",
".",
"keys",
".",
"ESCAPE",
":",
"self",
".",
"close",
"(",
")",
"self",
".",
"example",
".",
"key_event",
"(",
"event",
".",
"key",... | Process Qt key press events forwarding them to the example | [
"Process",
"Qt",
"key",
"press",
"events",
"forwarding",
"them",
"to",
"the",
"example"
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/examples/window/pyqt5/window.py#L124-L131 | train |
moderngl/moderngl | examples/window/pyqt5/window.py | Window.key_release_event | def key_release_event(self, event):
"""
Process Qt key release events forwarding them to the example
"""
self.example.key_event(event.key(), self.keys.ACTION_RELEASE) | python | def key_release_event(self, event):
"""
Process Qt key release events forwarding them to the example
"""
self.example.key_event(event.key(), self.keys.ACTION_RELEASE) | [
"def",
"key_release_event",
"(",
"self",
",",
"event",
")",
":",
"self",
".",
"example",
".",
"key_event",
"(",
"event",
".",
"key",
"(",
")",
",",
"self",
".",
"keys",
".",
"ACTION_RELEASE",
")"
] | Process Qt key release events forwarding them to the example | [
"Process",
"Qt",
"key",
"release",
"events",
"forwarding",
"them",
"to",
"the",
"example"
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/examples/window/pyqt5/window.py#L133-L137 | train |
moderngl/moderngl | examples/window/pyqt5/window.py | Window.mouse_move_event | def mouse_move_event(self, event):
"""
Forward mouse cursor position events to the example
"""
self.example.mouse_position_event(event.x(), event.y()) | python | def mouse_move_event(self, event):
"""
Forward mouse cursor position events to the example
"""
self.example.mouse_position_event(event.x(), event.y()) | [
"def",
"mouse_move_event",
"(",
"self",
",",
"event",
")",
":",
"self",
".",
"example",
".",
"mouse_position_event",
"(",
"event",
".",
"x",
"(",
")",
",",
"event",
".",
"y",
"(",
")",
")"
] | Forward mouse cursor position events to the example | [
"Forward",
"mouse",
"cursor",
"position",
"events",
"to",
"the",
"example"
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/examples/window/pyqt5/window.py#L139-L143 | train |
moderngl/moderngl | examples/window/pyqt5/window.py | Window.mouse_press_event | def mouse_press_event(self, event):
"""
Forward mouse press events to the example
"""
# Support left and right mouse button for now
if event.button() not in [1, 2]:
return
self.example.mouse_press_event(event.x(), event.y(), event.button()) | python | def mouse_press_event(self, event):
"""
Forward mouse press events to the example
"""
# Support left and right mouse button for now
if event.button() not in [1, 2]:
return
self.example.mouse_press_event(event.x(), event.y(), event.button()) | [
"def",
"mouse_press_event",
"(",
"self",
",",
"event",
")",
":",
"# Support left and right mouse button for now\r",
"if",
"event",
".",
"button",
"(",
")",
"not",
"in",
"[",
"1",
",",
"2",
"]",
":",
"return",
"self",
".",
"example",
".",
"mouse_press_event",
... | Forward mouse press events to the example | [
"Forward",
"mouse",
"press",
"events",
"to",
"the",
"example"
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/examples/window/pyqt5/window.py#L145-L153 | train |
moderngl/moderngl | examples/window/pyqt5/window.py | Window.mouse_release_event | def mouse_release_event(self, event):
"""
Forward mouse release events to the example
"""
# Support left and right mouse button for now
if event.button() not in [1, 2]:
return
self.example.mouse_release_event(event.x(), event.y(), event.button()) | python | def mouse_release_event(self, event):
"""
Forward mouse release events to the example
"""
# Support left and right mouse button for now
if event.button() not in [1, 2]:
return
self.example.mouse_release_event(event.x(), event.y(), event.button()) | [
"def",
"mouse_release_event",
"(",
"self",
",",
"event",
")",
":",
"# Support left and right mouse button for now\r",
"if",
"event",
".",
"button",
"(",
")",
"not",
"in",
"[",
"1",
",",
"2",
"]",
":",
"return",
"self",
".",
"example",
".",
"mouse_release_event... | Forward mouse release events to the example | [
"Forward",
"mouse",
"release",
"events",
"to",
"the",
"example"
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/examples/window/pyqt5/window.py#L155-L163 | train |
moderngl/moderngl | moderngl/framebuffer.py | Framebuffer.read | def read(self, viewport=None, components=3, *, attachment=0, alignment=1, dtype='f1') -> bytes:
'''
Read the content of the framebuffer.
Args:
viewport (tuple): The viewport.
components (int): The number of components to read.
Keyword Args:
... | python | def read(self, viewport=None, components=3, *, attachment=0, alignment=1, dtype='f1') -> bytes:
'''
Read the content of the framebuffer.
Args:
viewport (tuple): The viewport.
components (int): The number of components to read.
Keyword Args:
... | [
"def",
"read",
"(",
"self",
",",
"viewport",
"=",
"None",
",",
"components",
"=",
"3",
",",
"*",
",",
"attachment",
"=",
"0",
",",
"alignment",
"=",
"1",
",",
"dtype",
"=",
"'f1'",
")",
"->",
"bytes",
":",
"return",
"self",
".",
"mglo",
".",
"rea... | Read the content of the framebuffer.
Args:
viewport (tuple): The viewport.
components (int): The number of components to read.
Keyword Args:
attachment (int): The color attachment.
alignment (int): The byte alignment of the pixels... | [
"Read",
"the",
"content",
"of",
"the",
"framebuffer",
"."
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/moderngl/framebuffer.py#L174-L191 | train |
moderngl/moderngl | moderngl/framebuffer.py | Framebuffer.read_into | def read_into(self, buffer, viewport=None, components=3, *,
attachment=0, alignment=1, dtype='f1', write_offset=0) -> None:
'''
Read the content of the framebuffer into a buffer.
Args:
buffer (bytearray): The buffer that will receive the pixels.
... | python | def read_into(self, buffer, viewport=None, components=3, *,
attachment=0, alignment=1, dtype='f1', write_offset=0) -> None:
'''
Read the content of the framebuffer into a buffer.
Args:
buffer (bytearray): The buffer that will receive the pixels.
... | [
"def",
"read_into",
"(",
"self",
",",
"buffer",
",",
"viewport",
"=",
"None",
",",
"components",
"=",
"3",
",",
"*",
",",
"attachment",
"=",
"0",
",",
"alignment",
"=",
"1",
",",
"dtype",
"=",
"'f1'",
",",
"write_offset",
"=",
"0",
")",
"->",
"None... | Read the content of the framebuffer into a buffer.
Args:
buffer (bytearray): The buffer that will receive the pixels.
viewport (tuple): The viewport.
components (int): The number of components to read.
Keyword Args:
attachment (in... | [
"Read",
"the",
"content",
"of",
"the",
"framebuffer",
"into",
"a",
"buffer",
"."
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/moderngl/framebuffer.py#L193-L213 | train |
moderngl/moderngl | examples/window/base.py | BaseWindow.resize | def resize(self, width, height):
"""
Should be called every time window is resized
so the example can adapt to the new size if needed
"""
if self.example:
self.example.resize(width, height) | python | def resize(self, width, height):
"""
Should be called every time window is resized
so the example can adapt to the new size if needed
"""
if self.example:
self.example.resize(width, height) | [
"def",
"resize",
"(",
"self",
",",
"width",
",",
"height",
")",
":",
"if",
"self",
".",
"example",
":",
"self",
".",
"example",
".",
"resize",
"(",
"width",
",",
"height",
")"
] | Should be called every time window is resized
so the example can adapt to the new size if needed | [
"Should",
"be",
"called",
"every",
"time",
"window",
"is",
"resized",
"so",
"the",
"example",
"can",
"adapt",
"to",
"the",
"new",
"size",
"if",
"needed"
] | a8f5dce8dc72ae84a2f9523887fb5f6b620049b9 | https://github.com/moderngl/moderngl/blob/a8f5dce8dc72ae84a2f9523887fb5f6b620049b9/examples/window/base.py#L136-L142 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.