repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
CZ-NIC/python-rt | rt.py | Rt.get_attachments_ids | def get_attachments_ids(self, ticket_id):
""" Get IDs of attachments for given ticket.
:param ticket_id: ID of ticket
:returns: List of IDs (type int) of attachments belonging to given
ticket. Returns None if ticket does not exist.
"""
attachments = self.get_at... | python | def get_attachments_ids(self, ticket_id):
""" Get IDs of attachments for given ticket.
:param ticket_id: ID of ticket
:returns: List of IDs (type int) of attachments belonging to given
ticket. Returns None if ticket does not exist.
"""
attachments = self.get_at... | [
"def",
"get_attachments_ids",
"(",
"self",
",",
"ticket_id",
")",
":",
"attachments",
"=",
"self",
".",
"get_attachments",
"(",
"ticket_id",
")",
"return",
"[",
"int",
"(",
"at",
"[",
"0",
"]",
")",
"for",
"at",
"in",
"attachments",
"]",
"if",
"attachmen... | Get IDs of attachments for given ticket.
:param ticket_id: ID of ticket
:returns: List of IDs (type int) of attachments belonging to given
ticket. Returns None if ticket does not exist. | [
"Get",
"IDs",
"of",
"attachments",
"for",
"given",
"ticket",
"."
] | train | https://github.com/CZ-NIC/python-rt/blob/e7a9f555e136708aec3317f857045145a2271e16/rt.py#L953-L961 |
CZ-NIC/python-rt | rt.py | Rt.get_attachment | def get_attachment(self, ticket_id, attachment_id):
""" Get attachment.
:param ticket_id: ID of ticket
:param attachment_id: ID of attachment for obtain
:returns: Attachment as dictionary with these keys:
* Transaction
* ContentType
... | python | def get_attachment(self, ticket_id, attachment_id):
""" Get attachment.
:param ticket_id: ID of ticket
:param attachment_id: ID of attachment for obtain
:returns: Attachment as dictionary with these keys:
* Transaction
* ContentType
... | [
"def",
"get_attachment",
"(",
"self",
",",
"ticket_id",
",",
"attachment_id",
")",
":",
"msg",
"=",
"self",
".",
"__request",
"(",
"'ticket/{}/attachments/{}'",
".",
"format",
"(",
"str",
"(",
"ticket_id",
")",
",",
"str",
"(",
"attachment_id",
")",
")",
"... | Get attachment.
:param ticket_id: ID of ticket
:param attachment_id: ID of attachment for obtain
:returns: Attachment as dictionary with these keys:
* Transaction
* ContentType
* Parent
* Creator
... | [
"Get",
"attachment",
"."
] | train | https://github.com/CZ-NIC/python-rt/blob/e7a9f555e136708aec3317f857045145a2271e16/rt.py#L963-L1051 |
CZ-NIC/python-rt | rt.py | Rt.get_attachment_content | def get_attachment_content(self, ticket_id, attachment_id):
""" Get content of attachment without headers.
This function is necessary to use for binary attachment,
as it can contain ``\\n`` chars, which would disrupt parsing
of message if :py:meth:`~Rt.get_attachment` is used.
... | python | def get_attachment_content(self, ticket_id, attachment_id):
""" Get content of attachment without headers.
This function is necessary to use for binary attachment,
as it can contain ``\\n`` chars, which would disrupt parsing
of message if :py:meth:`~Rt.get_attachment` is used.
... | [
"def",
"get_attachment_content",
"(",
"self",
",",
"ticket_id",
",",
"attachment_id",
")",
":",
"msg",
"=",
"self",
".",
"__request",
"(",
"'ticket/{}/attachments/{}/content'",
".",
"format",
"(",
"str",
"(",
"ticket_id",
")",
",",
"str",
"(",
"attachment_id",
... | Get content of attachment without headers.
This function is necessary to use for binary attachment,
as it can contain ``\\n`` chars, which would disrupt parsing
of message if :py:meth:`~Rt.get_attachment` is used.
Format of message::
RT/3.8.7 200 Ok\n\nStart of the content... | [
"Get",
"content",
"of",
"attachment",
"without",
"headers",
"."
] | train | https://github.com/CZ-NIC/python-rt/blob/e7a9f555e136708aec3317f857045145a2271e16/rt.py#L1053-L1077 |
CZ-NIC/python-rt | rt.py | Rt.get_user | def get_user(self, user_id):
""" Get user details.
:param user_id: Identification of user by username (str) or user ID
(int)
:returns: User details as strings in dictionary with these keys for RT
users:
* Lang
... | python | def get_user(self, user_id):
""" Get user details.
:param user_id: Identification of user by username (str) or user ID
(int)
:returns: User details as strings in dictionary with these keys for RT
users:
* Lang
... | [
"def",
"get_user",
"(",
"self",
",",
"user_id",
")",
":",
"msg",
"=",
"self",
".",
"__request",
"(",
"'user/{}'",
".",
"format",
"(",
"str",
"(",
"user_id",
")",
",",
")",
")",
"status_code",
"=",
"self",
".",
"__get_status_code",
"(",
"msg",
")",
"i... | Get user details.
:param user_id: Identification of user by username (str) or user ID
(int)
:returns: User details as strings in dictionary with these keys for RT
users:
* Lang
* RealName
* Priv... | [
"Get",
"user",
"details",
"."
] | train | https://github.com/CZ-NIC/python-rt/blob/e7a9f555e136708aec3317f857045145a2271e16/rt.py#L1079-L1123 |
CZ-NIC/python-rt | rt.py | Rt.create_user | def create_user(self, Name, EmailAddress, **kwargs):
""" Create user (undocumented API feature).
:param Name: User name (login for privileged, required)
:param EmailAddress: Email address (required)
:param kwargs: Optional fields to set (see edit_user)
:returns: ID of new user o... | python | def create_user(self, Name, EmailAddress, **kwargs):
""" Create user (undocumented API feature).
:param Name: User name (login for privileged, required)
:param EmailAddress: Email address (required)
:param kwargs: Optional fields to set (see edit_user)
:returns: ID of new user o... | [
"def",
"create_user",
"(",
"self",
",",
"Name",
",",
"EmailAddress",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"edit_user",
"(",
"'new'",
",",
"Name",
"=",
"Name",
",",
"EmailAddress",
"=",
"EmailAddress",
",",
"*",
"*",
"kwargs",
")"
] | Create user (undocumented API feature).
:param Name: User name (login for privileged, required)
:param EmailAddress: Email address (required)
:param kwargs: Optional fields to set (see edit_user)
:returns: ID of new user or False when create fails
:raises BadRequest: When user a... | [
"Create",
"user",
"(",
"undocumented",
"API",
"feature",
")",
"."
] | train | https://github.com/CZ-NIC/python-rt/blob/e7a9f555e136708aec3317f857045145a2271e16/rt.py#L1125-L1136 |
CZ-NIC/python-rt | rt.py | Rt.edit_queue | def edit_queue(self, queue_id, **kwargs):
""" Edit queue (undocumented API feature).
:param queue_id: Identification of queue by name (str) or ID (int)
:param kwargs: Other fields to edit from the following list:
* Name
* Description
... | python | def edit_queue(self, queue_id, **kwargs):
""" Edit queue (undocumented API feature).
:param queue_id: Identification of queue by name (str) or ID (int)
:param kwargs: Other fields to edit from the following list:
* Name
* Description
... | [
"def",
"edit_queue",
"(",
"self",
",",
"queue_id",
",",
"*",
"*",
"kwargs",
")",
":",
"valid_fields",
"=",
"set",
"(",
"(",
"'name'",
",",
"'description'",
",",
"'correspondaddress'",
",",
"'commentaddress'",
",",
"'initialpriority'",
",",
"'finalpriority'",
"... | Edit queue (undocumented API feature).
:param queue_id: Identification of queue by name (str) or ID (int)
:param kwargs: Other fields to edit from the following list:
* Name
* Description
* CorrespondAddress
... | [
"Edit",
"queue",
"(",
"undocumented",
"API",
"feature",
")",
"."
] | train | https://github.com/CZ-NIC/python-rt/blob/e7a9f555e136708aec3317f857045145a2271e16/rt.py#L1237-L1272 |
CZ-NIC/python-rt | rt.py | Rt.create_queue | def create_queue(self, Name, **kwargs):
""" Create queue (undocumented API feature).
:param Name: Queue name (required)
:param kwargs: Optional fields to set (see edit_queue)
:returns: ID of new queue or False when create fails
:raises BadRequest: When queue already exists
... | python | def create_queue(self, Name, **kwargs):
""" Create queue (undocumented API feature).
:param Name: Queue name (required)
:param kwargs: Optional fields to set (see edit_queue)
:returns: ID of new queue or False when create fails
:raises BadRequest: When queue already exists
... | [
"def",
"create_queue",
"(",
"self",
",",
"Name",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"int",
"(",
"self",
".",
"edit_queue",
"(",
"'new'",
",",
"Name",
"=",
"Name",
",",
"*",
"*",
"kwargs",
")",
")"
] | Create queue (undocumented API feature).
:param Name: Queue name (required)
:param kwargs: Optional fields to set (see edit_queue)
:returns: ID of new queue or False when create fails
:raises BadRequest: When queue already exists
:raises InvalidUse: When invalid fields are set | [
"Create",
"queue",
"(",
"undocumented",
"API",
"feature",
")",
"."
] | train | https://github.com/CZ-NIC/python-rt/blob/e7a9f555e136708aec3317f857045145a2271e16/rt.py#L1274-L1284 |
CZ-NIC/python-rt | rt.py | Rt.get_links | def get_links(self, ticket_id):
""" Gets the ticket links for a single ticket.
:param ticket_id: ticket ID
:returns: Links as lists of strings in dictionary with these keys
(just those which are defined):
* id
* Members
... | python | def get_links(self, ticket_id):
""" Gets the ticket links for a single ticket.
:param ticket_id: ticket ID
:returns: Links as lists of strings in dictionary with these keys
(just those which are defined):
* id
* Members
... | [
"def",
"get_links",
"(",
"self",
",",
"ticket_id",
")",
":",
"msg",
"=",
"self",
".",
"__request",
"(",
"'ticket/{}/links/show'",
".",
"format",
"(",
"str",
"(",
"ticket_id",
")",
",",
")",
")",
"status_code",
"=",
"self",
".",
"__get_status_code",
"(",
... | Gets the ticket links for a single ticket.
:param ticket_id: ticket ID
:returns: Links as lists of strings in dictionary with these keys
(just those which are defined):
* id
* Members
* MemberOf
*... | [
"Gets",
"the",
"ticket",
"links",
"for",
"a",
"single",
"ticket",
"."
] | train | https://github.com/CZ-NIC/python-rt/blob/e7a9f555e136708aec3317f857045145a2271e16/rt.py#L1286-L1329 |
CZ-NIC/python-rt | rt.py | Rt.edit_ticket_links | def edit_ticket_links(self, ticket_id, **kwargs):
""" Edit ticket links.
.. warning:: This method is deprecated in favour of edit_link method, because
there exists bug in RT 3.8 REST API causing mapping created links to
ticket/1. The only drawback is that edit_link cannot process ... | python | def edit_ticket_links(self, ticket_id, **kwargs):
""" Edit ticket links.
.. warning:: This method is deprecated in favour of edit_link method, because
there exists bug in RT 3.8 REST API causing mapping created links to
ticket/1. The only drawback is that edit_link cannot process ... | [
"def",
"edit_ticket_links",
"(",
"self",
",",
"ticket_id",
",",
"*",
"*",
"kwargs",
")",
":",
"post_data",
"=",
"''",
"for",
"key",
"in",
"kwargs",
":",
"post_data",
"+=",
"\"{}: {}\\n\"",
".",
"format",
"(",
"key",
",",
"str",
"(",
"kwargs",
"[",
"key... | Edit ticket links.
.. warning:: This method is deprecated in favour of edit_link method, because
there exists bug in RT 3.8 REST API causing mapping created links to
ticket/1. The only drawback is that edit_link cannot process multiple
links all at once.
:param ticket_... | [
"Edit",
"ticket",
"links",
"."
] | train | https://github.com/CZ-NIC/python-rt/blob/e7a9f555e136708aec3317f857045145a2271e16/rt.py#L1331-L1357 |
CZ-NIC/python-rt | rt.py | Rt.edit_link | def edit_link(self, ticket_id, link_name, link_value, delete=False):
""" Creates or deletes a link between the specified tickets (undocumented API feature).
:param ticket_id: ID of ticket to edit
:param link_name: Name of link to edit (DependsOn, DependedOnBy,
RefersTo... | python | def edit_link(self, ticket_id, link_name, link_value, delete=False):
""" Creates or deletes a link between the specified tickets (undocumented API feature).
:param ticket_id: ID of ticket to edit
:param link_name: Name of link to edit (DependsOn, DependedOnBy,
RefersTo... | [
"def",
"edit_link",
"(",
"self",
",",
"ticket_id",
",",
"link_name",
",",
"link_value",
",",
"delete",
"=",
"False",
")",
":",
"valid_link_names",
"=",
"set",
"(",
"(",
"'dependson'",
",",
"'dependedonby'",
",",
"'refersto'",
",",
"'referredtoby'",
",",
"'ha... | Creates or deletes a link between the specified tickets (undocumented API feature).
:param ticket_id: ID of ticket to edit
:param link_name: Name of link to edit (DependsOn, DependedOnBy,
RefersTo, ReferredToBy, HasMember or MemberOf)
:param link_value: Either ticker I... | [
"Creates",
"or",
"deletes",
"a",
"link",
"between",
"the",
"specified",
"tickets",
"(",
"undocumented",
"API",
"feature",
")",
"."
] | train | https://github.com/CZ-NIC/python-rt/blob/e7a9f555e136708aec3317f857045145a2271e16/rt.py#L1359-L1389 |
CZ-NIC/python-rt | rt.py | Rt.merge_ticket | def merge_ticket(self, ticket_id, into_id):
""" Merge ticket into another (undocumented API feature).
:param ticket_id: ID of ticket to be merged
:param into: ID of destination ticket
:returns: ``True``
Operation was successful
``False``
... | python | def merge_ticket(self, ticket_id, into_id):
""" Merge ticket into another (undocumented API feature).
:param ticket_id: ID of ticket to be merged
:param into: ID of destination ticket
:returns: ``True``
Operation was successful
``False``
... | [
"def",
"merge_ticket",
"(",
"self",
",",
"ticket_id",
",",
"into_id",
")",
":",
"msg",
"=",
"self",
".",
"__request",
"(",
"'ticket/{}/merge/{}'",
".",
"format",
"(",
"str",
"(",
"ticket_id",
")",
",",
"str",
"(",
"into_id",
")",
")",
")",
"state",
"="... | Merge ticket into another (undocumented API feature).
:param ticket_id: ID of ticket to be merged
:param into: ID of destination ticket
:returns: ``True``
Operation was successful
``False``
Either origin or destination ticket does no... | [
"Merge",
"ticket",
"into",
"another",
"(",
"undocumented",
"API",
"feature",
")",
"."
] | train | https://github.com/CZ-NIC/python-rt/blob/e7a9f555e136708aec3317f857045145a2271e16/rt.py#L1391-L1405 |
CZ-NIC/python-rt | rt.py | Rt.untake | def untake(self, ticket_id):
""" Untake ticket
:param ticket_id: ID of ticket to be merged
:returns: ``True``
Operation was successful
``False``
Either the ticket does not exist or user does not
own the ticket.
... | python | def untake(self, ticket_id):
""" Untake ticket
:param ticket_id: ID of ticket to be merged
:returns: ``True``
Operation was successful
``False``
Either the ticket does not exist or user does not
own the ticket.
... | [
"def",
"untake",
"(",
"self",
",",
"ticket_id",
")",
":",
"post_data",
"=",
"{",
"'content'",
":",
"\"Ticket: {}\\nAction: untake\"",
".",
"format",
"(",
"str",
"(",
"ticket_id",
")",
")",
"}",
"msg",
"=",
"self",
".",
"__request",
"(",
"'ticket/{}/take'",
... | Untake ticket
:param ticket_id: ID of ticket to be merged
:returns: ``True``
Operation was successful
``False``
Either the ticket does not exist or user does not
own the ticket. | [
"Untake",
"ticket"
] | train | https://github.com/CZ-NIC/python-rt/blob/e7a9f555e136708aec3317f857045145a2271e16/rt.py#L1435-L1447 |
CZ-NIC/python-rt | rt.py | Rt.split_header | def split_header(line):
""" Split a header line into field name and field value.
Note that custom fields may contain colons inside the curly braces,
so we need a special test for them.
:param line: A message line to be split.
:returns: (Field name, field value) tuple.
... | python | def split_header(line):
""" Split a header line into field name and field value.
Note that custom fields may contain colons inside the curly braces,
so we need a special test for them.
:param line: A message line to be split.
:returns: (Field name, field value) tuple.
... | [
"def",
"split_header",
"(",
"line",
")",
":",
"match",
"=",
"re",
".",
"match",
"(",
"r'^(CF\\.\\{.*?}): (.*)$'",
",",
"line",
")",
"if",
"match",
":",
"return",
"(",
"match",
".",
"group",
"(",
"1",
")",
",",
"match",
".",
"group",
"(",
"2",
")",
... | Split a header line into field name and field value.
Note that custom fields may contain colons inside the curly braces,
so we need a special test for them.
:param line: A message line to be split.
:returns: (Field name, field value) tuple. | [
"Split",
"a",
"header",
"line",
"into",
"field",
"name",
"and",
"field",
"value",
"."
] | train | https://github.com/CZ-NIC/python-rt/blob/e7a9f555e136708aec3317f857045145a2271e16/rt.py#L1450-L1463 |
CityOfZion/neo-python-core | neocore/KeyPair.py | KeyPair.PrivateKeyFromWIF | def PrivateKeyFromWIF(wif):
"""
Get the private key from a WIF key
Args:
wif (str): The wif key
Returns:
bytes: The private key
"""
if wif is None or len(wif) is not 52:
raise ValueError('Please provide a wif with a length of 52 bytes... | python | def PrivateKeyFromWIF(wif):
"""
Get the private key from a WIF key
Args:
wif (str): The wif key
Returns:
bytes: The private key
"""
if wif is None or len(wif) is not 52:
raise ValueError('Please provide a wif with a length of 52 bytes... | [
"def",
"PrivateKeyFromWIF",
"(",
"wif",
")",
":",
"if",
"wif",
"is",
"None",
"or",
"len",
"(",
"wif",
")",
"is",
"not",
"52",
":",
"raise",
"ValueError",
"(",
"'Please provide a wif with a length of 52 bytes (LEN: {0:d})'",
".",
"format",
"(",
"len",
"(",
"wif... | Get the private key from a WIF key
Args:
wif (str): The wif key
Returns:
bytes: The private key | [
"Get",
"the",
"private",
"key",
"from",
"a",
"WIF",
"key"
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/KeyPair.py#L81-L106 |
CityOfZion/neo-python-core | neocore/KeyPair.py | KeyPair.PrivateKeyFromNEP2 | def PrivateKeyFromNEP2(nep2_key, passphrase):
"""
Gets the private key from a NEP-2 encrypted private key
Args:
nep2_key (str): The nep-2 encrypted private key
passphrase (str): The password to encrypt the private key with, as unicode string
Returns:
... | python | def PrivateKeyFromNEP2(nep2_key, passphrase):
"""
Gets the private key from a NEP-2 encrypted private key
Args:
nep2_key (str): The nep-2 encrypted private key
passphrase (str): The password to encrypt the private key with, as unicode string
Returns:
... | [
"def",
"PrivateKeyFromNEP2",
"(",
"nep2_key",
",",
"passphrase",
")",
":",
"if",
"not",
"nep2_key",
"or",
"len",
"(",
"nep2_key",
")",
"!=",
"58",
":",
"raise",
"ValueError",
"(",
"'Please provide a nep2_key with a length of 58 bytes (LEN: {0:d})'",
".",
"format",
"... | Gets the private key from a NEP-2 encrypted private key
Args:
nep2_key (str): The nep-2 encrypted private key
passphrase (str): The password to encrypt the private key with, as unicode string
Returns:
bytes: The private key | [
"Gets",
"the",
"private",
"key",
"from",
"a",
"NEP",
"-",
"2",
"encrypted",
"private",
"key"
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/KeyPair.py#L109-L157 |
CityOfZion/neo-python-core | neocore/KeyPair.py | KeyPair.GetAddress | def GetAddress(self):
"""
Returns the public NEO address for this KeyPair
Returns:
str: The private key
"""
script = b'21' + self.PublicKey.encode_point(True) + b'ac'
script_hash = Crypto.ToScriptHash(script)
address = Crypto.ToAddress(script_hash)
... | python | def GetAddress(self):
"""
Returns the public NEO address for this KeyPair
Returns:
str: The private key
"""
script = b'21' + self.PublicKey.encode_point(True) + b'ac'
script_hash = Crypto.ToScriptHash(script)
address = Crypto.ToAddress(script_hash)
... | [
"def",
"GetAddress",
"(",
"self",
")",
":",
"script",
"=",
"b'21'",
"+",
"self",
".",
"PublicKey",
".",
"encode_point",
"(",
"True",
")",
"+",
"b'ac'",
"script_hash",
"=",
"Crypto",
".",
"ToScriptHash",
"(",
"script",
")",
"address",
"=",
"Crypto",
".",
... | Returns the public NEO address for this KeyPair
Returns:
str: The private key | [
"Returns",
"the",
"public",
"NEO",
"address",
"for",
"this",
"KeyPair"
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/KeyPair.py#L159-L169 |
CityOfZion/neo-python-core | neocore/KeyPair.py | KeyPair.Export | def Export(self):
"""
Export this KeyPair's private key in WIF format.
Returns:
str: The key in wif format
"""
data = bytearray(38)
data[0] = 0x80
data[1:33] = self.PrivateKey[0:32]
data[33] = 0x01
checksum = Crypto.Default().Hash256(... | python | def Export(self):
"""
Export this KeyPair's private key in WIF format.
Returns:
str: The key in wif format
"""
data = bytearray(38)
data[0] = 0x80
data[1:33] = self.PrivateKey[0:32]
data[33] = 0x01
checksum = Crypto.Default().Hash256(... | [
"def",
"Export",
"(",
"self",
")",
":",
"data",
"=",
"bytearray",
"(",
"38",
")",
"data",
"[",
"0",
"]",
"=",
"0x80",
"data",
"[",
"1",
":",
"33",
"]",
"=",
"self",
".",
"PrivateKey",
"[",
"0",
":",
"32",
"]",
"data",
"[",
"33",
"]",
"=",
"... | Export this KeyPair's private key in WIF format.
Returns:
str: The key in wif format | [
"Export",
"this",
"KeyPair",
"s",
"private",
"key",
"in",
"WIF",
"format",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/KeyPair.py#L171-L187 |
CityOfZion/neo-python-core | neocore/KeyPair.py | KeyPair.ExportNEP2 | def ExportNEP2(self, passphrase):
"""
Export the encrypted private key in NEP-2 format.
Args:
passphrase (str): The password to encrypt the private key with, as unicode string
Returns:
str: The NEP-2 encrypted private key
"""
if len(passphrase) <... | python | def ExportNEP2(self, passphrase):
"""
Export the encrypted private key in NEP-2 format.
Args:
passphrase (str): The password to encrypt the private key with, as unicode string
Returns:
str: The NEP-2 encrypted private key
"""
if len(passphrase) <... | [
"def",
"ExportNEP2",
"(",
"self",
",",
"passphrase",
")",
":",
"if",
"len",
"(",
"passphrase",
")",
"<",
"2",
":",
"raise",
"ValueError",
"(",
"\"Passphrase must have a minimum of 2 characters\"",
")",
"# Hash address twice, then only use the first 4 bytes",
"address_hash... | Export the encrypted private key in NEP-2 format.
Args:
passphrase (str): The password to encrypt the private key with, as unicode string
Returns:
str: The NEP-2 encrypted private key | [
"Export",
"the",
"encrypted",
"private",
"key",
"in",
"NEP",
"-",
"2",
"format",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/KeyPair.py#L189-L233 |
CityOfZion/neo-python-core | neocore/IO/BinaryReader.py | BinaryReader.unpack | def unpack(self, fmt, length=1):
"""
Unpack the stream contents according to the specified format in `fmt`.
For more information about the `fmt` format see: https://docs.python.org/3/library/struct.html
Args:
fmt (str): format string.
length (int): amount of byte... | python | def unpack(self, fmt, length=1):
"""
Unpack the stream contents according to the specified format in `fmt`.
For more information about the `fmt` format see: https://docs.python.org/3/library/struct.html
Args:
fmt (str): format string.
length (int): amount of byte... | [
"def",
"unpack",
"(",
"self",
",",
"fmt",
",",
"length",
"=",
"1",
")",
":",
"return",
"struct",
".",
"unpack",
"(",
"fmt",
",",
"self",
".",
"stream",
".",
"read",
"(",
"length",
")",
")",
"[",
"0",
"]"
] | Unpack the stream contents according to the specified format in `fmt`.
For more information about the `fmt` format see: https://docs.python.org/3/library/struct.html
Args:
fmt (str): format string.
length (int): amount of bytes to read.
Returns:
variable: th... | [
"Unpack",
"the",
"stream",
"contents",
"according",
"to",
"the",
"specified",
"format",
"in",
"fmt",
".",
"For",
"more",
"information",
"about",
"the",
"fmt",
"format",
"see",
":",
"https",
":",
"//",
"docs",
".",
"python",
".",
"org",
"/",
"3",
"/",
"... | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/IO/BinaryReader.py#L32-L44 |
CityOfZion/neo-python-core | neocore/IO/BinaryReader.py | BinaryReader.ReadByte | def ReadByte(self, do_ord=True):
"""
Read a single byte.
Args:
do_ord (bool): (default True) convert the byte to an ordinal first.
Returns:
bytes: a single byte if successful. 0 (int) if an exception occurred.
"""
try:
if do_ord:
... | python | def ReadByte(self, do_ord=True):
"""
Read a single byte.
Args:
do_ord (bool): (default True) convert the byte to an ordinal first.
Returns:
bytes: a single byte if successful. 0 (int) if an exception occurred.
"""
try:
if do_ord:
... | [
"def",
"ReadByte",
"(",
"self",
",",
"do_ord",
"=",
"True",
")",
":",
"try",
":",
"if",
"do_ord",
":",
"return",
"ord",
"(",
"self",
".",
"stream",
".",
"read",
"(",
"1",
")",
")",
"return",
"self",
".",
"stream",
".",
"read",
"(",
"1",
")",
"e... | Read a single byte.
Args:
do_ord (bool): (default True) convert the byte to an ordinal first.
Returns:
bytes: a single byte if successful. 0 (int) if an exception occurred. | [
"Read",
"a",
"single",
"byte",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/IO/BinaryReader.py#L46-L62 |
CityOfZion/neo-python-core | neocore/IO/BinaryReader.py | BinaryReader.SafeReadBytes | def SafeReadBytes(self, length):
"""
Read exactly `length` number of bytes from the stream.
Raises:
ValueError is not enough data
Returns:
bytes: `length` number of bytes
"""
data = self.ReadBytes(length)
if len(data) < length:
... | python | def SafeReadBytes(self, length):
"""
Read exactly `length` number of bytes from the stream.
Raises:
ValueError is not enough data
Returns:
bytes: `length` number of bytes
"""
data = self.ReadBytes(length)
if len(data) < length:
... | [
"def",
"SafeReadBytes",
"(",
"self",
",",
"length",
")",
":",
"data",
"=",
"self",
".",
"ReadBytes",
"(",
"length",
")",
"if",
"len",
"(",
"data",
")",
"<",
"length",
":",
"raise",
"ValueError",
"(",
"\"Not enough data available\"",
")",
"else",
":",
"re... | Read exactly `length` number of bytes from the stream.
Raises:
ValueError is not enough data
Returns:
bytes: `length` number of bytes | [
"Read",
"exactly",
"length",
"number",
"of",
"bytes",
"from",
"the",
"stream",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/IO/BinaryReader.py#L77-L91 |
CityOfZion/neo-python-core | neocore/IO/BinaryReader.py | BinaryReader.ReadVarInt | def ReadVarInt(self, max=sys.maxsize):
"""
Read a variable length integer from the stream.
The NEO network protocol supports encoded storage for space saving. See: http://docs.neo.org/en-us/node/network-protocol.html#convention
Args:
max (int): (Optional) maximum number of b... | python | def ReadVarInt(self, max=sys.maxsize):
"""
Read a variable length integer from the stream.
The NEO network protocol supports encoded storage for space saving. See: http://docs.neo.org/en-us/node/network-protocol.html#convention
Args:
max (int): (Optional) maximum number of b... | [
"def",
"ReadVarInt",
"(",
"self",
",",
"max",
"=",
"sys",
".",
"maxsize",
")",
":",
"fb",
"=",
"self",
".",
"ReadByte",
"(",
")",
"if",
"fb",
"is",
"0",
":",
"return",
"fb",
"value",
"=",
"0",
"if",
"hex",
"(",
"fb",
")",
"==",
"'0xfd'",
":",
... | Read a variable length integer from the stream.
The NEO network protocol supports encoded storage for space saving. See: http://docs.neo.org/en-us/node/network-protocol.html#convention
Args:
max (int): (Optional) maximum number of bytes to read.
Returns:
int: | [
"Read",
"a",
"variable",
"length",
"integer",
"from",
"the",
"stream",
".",
"The",
"NEO",
"network",
"protocol",
"supports",
"encoded",
"storage",
"for",
"space",
"saving",
".",
"See",
":",
"http",
":",
"//",
"docs",
".",
"neo",
".",
"org",
"/",
"en",
... | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/IO/BinaryReader.py#L231-L258 |
CityOfZion/neo-python-core | neocore/IO/BinaryReader.py | BinaryReader.ReadVarBytes | def ReadVarBytes(self, max=sys.maxsize):
"""
Read a variable length of bytes from the stream.
The NEO network protocol supports encoded storage for space saving. See: http://docs.neo.org/en-us/node/network-protocol.html#convention
Args:
max (int): (Optional) maximum number o... | python | def ReadVarBytes(self, max=sys.maxsize):
"""
Read a variable length of bytes from the stream.
The NEO network protocol supports encoded storage for space saving. See: http://docs.neo.org/en-us/node/network-protocol.html#convention
Args:
max (int): (Optional) maximum number o... | [
"def",
"ReadVarBytes",
"(",
"self",
",",
"max",
"=",
"sys",
".",
"maxsize",
")",
":",
"length",
"=",
"self",
".",
"ReadVarInt",
"(",
"max",
")",
"return",
"self",
".",
"ReadBytes",
"(",
"length",
")"
] | Read a variable length of bytes from the stream.
The NEO network protocol supports encoded storage for space saving. See: http://docs.neo.org/en-us/node/network-protocol.html#convention
Args:
max (int): (Optional) maximum number of bytes to read.
Returns:
bytes: | [
"Read",
"a",
"variable",
"length",
"of",
"bytes",
"from",
"the",
"stream",
".",
"The",
"NEO",
"network",
"protocol",
"supports",
"encoded",
"storage",
"for",
"space",
"saving",
".",
"See",
":",
"http",
":",
"//",
"docs",
".",
"neo",
".",
"org",
"/",
"e... | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/IO/BinaryReader.py#L260-L272 |
CityOfZion/neo-python-core | neocore/IO/BinaryReader.py | BinaryReader.ReadString | def ReadString(self):
"""
Read a string from the stream.
Returns:
str:
"""
length = self.ReadUInt8()
return self.unpack(str(length) + 's', length) | python | def ReadString(self):
"""
Read a string from the stream.
Returns:
str:
"""
length = self.ReadUInt8()
return self.unpack(str(length) + 's', length) | [
"def",
"ReadString",
"(",
"self",
")",
":",
"length",
"=",
"self",
".",
"ReadUInt8",
"(",
")",
"return",
"self",
".",
"unpack",
"(",
"str",
"(",
"length",
")",
"+",
"'s'",
",",
"length",
")"
] | Read a string from the stream.
Returns:
str: | [
"Read",
"a",
"string",
"from",
"the",
"stream",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/IO/BinaryReader.py#L274-L282 |
CityOfZion/neo-python-core | neocore/IO/BinaryReader.py | BinaryReader.ReadVarString | def ReadVarString(self, max=sys.maxsize):
"""
Similar to `ReadString` but expects a variable length indicator instead of the fixed 1 byte indicator.
Args:
max (int): (Optional) maximum number of bytes to read.
Returns:
bytes:
"""
length = self.Re... | python | def ReadVarString(self, max=sys.maxsize):
"""
Similar to `ReadString` but expects a variable length indicator instead of the fixed 1 byte indicator.
Args:
max (int): (Optional) maximum number of bytes to read.
Returns:
bytes:
"""
length = self.Re... | [
"def",
"ReadVarString",
"(",
"self",
",",
"max",
"=",
"sys",
".",
"maxsize",
")",
":",
"length",
"=",
"self",
".",
"ReadVarInt",
"(",
"max",
")",
"return",
"self",
".",
"unpack",
"(",
"str",
"(",
"length",
")",
"+",
"'s'",
",",
"length",
")"
] | Similar to `ReadString` but expects a variable length indicator instead of the fixed 1 byte indicator.
Args:
max (int): (Optional) maximum number of bytes to read.
Returns:
bytes: | [
"Similar",
"to",
"ReadString",
"but",
"expects",
"a",
"variable",
"length",
"indicator",
"instead",
"of",
"the",
"fixed",
"1",
"byte",
"indicator",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/IO/BinaryReader.py#L284-L295 |
CityOfZion/neo-python-core | neocore/IO/BinaryReader.py | BinaryReader.ReadSerializableArray | def ReadSerializableArray(self, class_name, max=sys.maxsize):
"""
Deserialize a stream into the object specific by `class_name`.
Args:
class_name (str): a full path to the class to be deserialized into. e.g. 'neo.Core.Block.Block'
max (int): (Optional) maximum number of ... | python | def ReadSerializableArray(self, class_name, max=sys.maxsize):
"""
Deserialize a stream into the object specific by `class_name`.
Args:
class_name (str): a full path to the class to be deserialized into. e.g. 'neo.Core.Block.Block'
max (int): (Optional) maximum number of ... | [
"def",
"ReadSerializableArray",
"(",
"self",
",",
"class_name",
",",
"max",
"=",
"sys",
".",
"maxsize",
")",
":",
"module",
"=",
"'.'",
".",
"join",
"(",
"class_name",
".",
"split",
"(",
"'.'",
")",
"[",
":",
"-",
"1",
"]",
")",
"klassname",
"=",
"... | Deserialize a stream into the object specific by `class_name`.
Args:
class_name (str): a full path to the class to be deserialized into. e.g. 'neo.Core.Block.Block'
max (int): (Optional) maximum number of bytes to read.
Returns:
list: list of `class_name` objects de... | [
"Deserialize",
"a",
"stream",
"into",
"the",
"object",
"specific",
"by",
"class_name",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/IO/BinaryReader.py#L308-L334 |
CityOfZion/neo-python-core | neocore/IO/BinaryReader.py | BinaryReader.Read2000256List | def Read2000256List(self):
"""
Read 2000 times a 64 byte value from the stream.
Returns:
list: a list containing 2000 64 byte values in reversed form.
"""
items = []
for i in range(0, 2000):
data = self.ReadBytes(64)
ba = bytearray(bin... | python | def Read2000256List(self):
"""
Read 2000 times a 64 byte value from the stream.
Returns:
list: a list containing 2000 64 byte values in reversed form.
"""
items = []
for i in range(0, 2000):
data = self.ReadBytes(64)
ba = bytearray(bin... | [
"def",
"Read2000256List",
"(",
"self",
")",
":",
"items",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"2000",
")",
":",
"data",
"=",
"self",
".",
"ReadBytes",
"(",
"64",
")",
"ba",
"=",
"bytearray",
"(",
"binascii",
".",
"unhexlify",
... | Read 2000 times a 64 byte value from the stream.
Returns:
list: a list containing 2000 64 byte values in reversed form. | [
"Read",
"2000",
"times",
"a",
"64",
"byte",
"value",
"from",
"the",
"stream",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/IO/BinaryReader.py#L354-L367 |
CityOfZion/neo-python-core | neocore/IO/BinaryReader.py | BinaryReader.ReadHashes | def ReadHashes(self):
"""
Read Hash values from the stream.
Returns:
list: a list of hash values. Each value is of the bytearray type.
"""
len = self.ReadVarInt()
items = []
for i in range(0, len):
ba = bytearray(self.ReadBytes(32))
... | python | def ReadHashes(self):
"""
Read Hash values from the stream.
Returns:
list: a list of hash values. Each value is of the bytearray type.
"""
len = self.ReadVarInt()
items = []
for i in range(0, len):
ba = bytearray(self.ReadBytes(32))
... | [
"def",
"ReadHashes",
"(",
"self",
")",
":",
"len",
"=",
"self",
".",
"ReadVarInt",
"(",
")",
"items",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"len",
")",
":",
"ba",
"=",
"bytearray",
"(",
"self",
".",
"ReadBytes",
"(",
"32",
")... | Read Hash values from the stream.
Returns:
list: a list of hash values. Each value is of the bytearray type. | [
"Read",
"Hash",
"values",
"from",
"the",
"stream",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/IO/BinaryReader.py#L369-L382 |
CityOfZion/neo-python-core | neocore/Cryptography/Crypto.py | Crypto.ToScriptHash | def ToScriptHash(data, unhex=True):
"""
Get a script hash of the data.
Args:
data (bytes): data to hash.
unhex (bool): (Default) True. Set to unhexlify the stream. Use when the bytes are not raw bytes; i.e. b'aabb'
Returns:
UInt160: script hash.
... | python | def ToScriptHash(data, unhex=True):
"""
Get a script hash of the data.
Args:
data (bytes): data to hash.
unhex (bool): (Default) True. Set to unhexlify the stream. Use when the bytes are not raw bytes; i.e. b'aabb'
Returns:
UInt160: script hash.
... | [
"def",
"ToScriptHash",
"(",
"data",
",",
"unhex",
"=",
"True",
")",
":",
"if",
"len",
"(",
"data",
")",
">",
"1",
"and",
"unhex",
":",
"data",
"=",
"binascii",
".",
"unhexlify",
"(",
"data",
")",
"return",
"UInt160",
"(",
"data",
"=",
"binascii",
"... | Get a script hash of the data.
Args:
data (bytes): data to hash.
unhex (bool): (Default) True. Set to unhexlify the stream. Use when the bytes are not raw bytes; i.e. b'aabb'
Returns:
UInt160: script hash. | [
"Get",
"a",
"script",
"hash",
"of",
"the",
"data",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/Crypto.py#L77-L90 |
CityOfZion/neo-python-core | neocore/Cryptography/Crypto.py | Crypto.Sign | def Sign(message, private_key):
"""
Sign the message with the given private key.
Args:
message (str): message to be signed
private_key (str): 32 byte key as a double digit hex string (e.g. having a length of 64)
Returns:
bytearray: the signature of th... | python | def Sign(message, private_key):
"""
Sign the message with the given private key.
Args:
message (str): message to be signed
private_key (str): 32 byte key as a double digit hex string (e.g. having a length of 64)
Returns:
bytearray: the signature of th... | [
"def",
"Sign",
"(",
"message",
",",
"private_key",
")",
":",
"hash",
"=",
"hashlib",
".",
"sha256",
"(",
"binascii",
".",
"unhexlify",
"(",
"message",
")",
")",
".",
"hexdigest",
"(",
")",
"v",
",",
"r",
",",
"s",
"=",
"bitcoin",
".",
"ecdsa_raw_sign... | Sign the message with the given private key.
Args:
message (str): message to be signed
private_key (str): 32 byte key as a double digit hex string (e.g. having a length of 64)
Returns:
bytearray: the signature of the message. | [
"Sign",
"the",
"message",
"with",
"the",
"given",
"private",
"key",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/Crypto.py#L106-L126 |
CityOfZion/neo-python-core | neocore/Cryptography/Crypto.py | Crypto.VerifySignature | def VerifySignature(message, signature, public_key, unhex=True):
"""
Verify the integrity of the message.
Args:
message (str): the message to verify.
signature (bytearray): the signature belonging to the message.
public_key (ECPoint|bytes): the public key to ... | python | def VerifySignature(message, signature, public_key, unhex=True):
"""
Verify the integrity of the message.
Args:
message (str): the message to verify.
signature (bytearray): the signature belonging to the message.
public_key (ECPoint|bytes): the public key to ... | [
"def",
"VerifySignature",
"(",
"message",
",",
"signature",
",",
"public_key",
",",
"unhex",
"=",
"True",
")",
":",
"if",
"type",
"(",
"public_key",
")",
"is",
"EllipticCurve",
".",
"ECPoint",
":",
"pubkey_x",
"=",
"public_key",
".",
"x",
".",
"value",
"... | Verify the integrity of the message.
Args:
message (str): the message to verify.
signature (bytearray): the signature belonging to the message.
public_key (ECPoint|bytes): the public key to use for verifying the signature. If `public_key` is of type bytes then it should be r... | [
"Verify",
"the",
"integrity",
"of",
"the",
"message",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/Crypto.py#L129-L168 |
CityOfZion/neo-python-core | neocore/Cryptography/Crypto.py | CryptoInstance.VerifySignature | def VerifySignature(self, message, signature, public_key, unhex=True):
"""
Verify the integrity of the message.
Args:
message (str): the message to verify.
signature (bytearray): the signature belonging to the message.
public_key (ECPoint): the public key to ... | python | def VerifySignature(self, message, signature, public_key, unhex=True):
"""
Verify the integrity of the message.
Args:
message (str): the message to verify.
signature (bytearray): the signature belonging to the message.
public_key (ECPoint): the public key to ... | [
"def",
"VerifySignature",
"(",
"self",
",",
"message",
",",
"signature",
",",
"public_key",
",",
"unhex",
"=",
"True",
")",
":",
"return",
"Crypto",
".",
"VerifySignature",
"(",
"message",
",",
"signature",
",",
"public_key",
",",
"unhex",
"=",
"unhex",
")... | Verify the integrity of the message.
Args:
message (str): the message to verify.
signature (bytearray): the signature belonging to the message.
public_key (ECPoint): the public key to use for verifying the signature.
unhex (bool): whether the message should be un... | [
"Verify",
"the",
"integrity",
"of",
"the",
"message",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/Crypto.py#L212-L225 |
CityOfZion/neo-python-core | neocore/Cryptography/ECCurve.py | _lucas_sequence | def _lucas_sequence(n, P, Q, k):
"""Return the modular Lucas sequence (U_k, V_k, Q_k).
Given a Lucas sequence defined by P, Q, returns the kth values for
U and V, along with Q^k, all modulo n.
"""
D = P * P - 4 * Q
if n < 2:
raise ValueError("n must be >= 2")
if k < 0:
raise ... | python | def _lucas_sequence(n, P, Q, k):
"""Return the modular Lucas sequence (U_k, V_k, Q_k).
Given a Lucas sequence defined by P, Q, returns the kth values for
U and V, along with Q^k, all modulo n.
"""
D = P * P - 4 * Q
if n < 2:
raise ValueError("n must be >= 2")
if k < 0:
raise ... | [
"def",
"_lucas_sequence",
"(",
"n",
",",
"P",
",",
"Q",
",",
"k",
")",
":",
"D",
"=",
"P",
"*",
"P",
"-",
"4",
"*",
"Q",
"if",
"n",
"<",
"2",
":",
"raise",
"ValueError",
"(",
"\"n must be >= 2\"",
")",
"if",
"k",
"<",
"0",
":",
"raise",
"Valu... | Return the modular Lucas sequence (U_k, V_k, Q_k).
Given a Lucas sequence defined by P, Q, returns the kth values for
U and V, along with Q^k, all modulo n. | [
"Return",
"the",
"modular",
"Lucas",
"sequence",
"(",
"U_k",
"V_k",
"Q_k",
")",
".",
"Given",
"a",
"Lucas",
"sequence",
"defined",
"by",
"P",
"Q",
"returns",
"the",
"kth",
"values",
"for",
"U",
"and",
"V",
"along",
"with",
"Q^k",
"all",
"modulo",
"n",
... | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/ECCurve.py#L67-L144 |
CityOfZion/neo-python-core | neocore/Cryptography/ECCurve.py | FiniteField.sqrt | def sqrt(self, val, flag):
"""
calculate the square root modulus p
"""
if val.iszero():
return val
sw = self.p % 8
if sw == 3 or sw == 7:
res = val ** ((self.p + 1) / 4)
elif sw == 5:
x = val ** ((self.p + 1) / 4)
if... | python | def sqrt(self, val, flag):
"""
calculate the square root modulus p
"""
if val.iszero():
return val
sw = self.p % 8
if sw == 3 or sw == 7:
res = val ** ((self.p + 1) / 4)
elif sw == 5:
x = val ** ((self.p + 1) / 4)
if... | [
"def",
"sqrt",
"(",
"self",
",",
"val",
",",
"flag",
")",
":",
"if",
"val",
".",
"iszero",
"(",
")",
":",
"return",
"val",
"sw",
"=",
"self",
".",
"p",
"%",
"8",
"if",
"sw",
"==",
"3",
"or",
"sw",
"==",
"7",
":",
"res",
"=",
"val",
"**",
... | calculate the square root modulus p | [
"calculate",
"the",
"square",
"root",
"modulus",
"p"
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/ECCurve.py#L287-L308 |
CityOfZion/neo-python-core | neocore/Cryptography/ECCurve.py | FiniteField.value | def value(self, x):
"""
converts an integer or FinitField.Value to a value of this FiniteField.
"""
return x if isinstance(x, FiniteField.Value) and x.field == self else FiniteField.Value(self, x) | python | def value(self, x):
"""
converts an integer or FinitField.Value to a value of this FiniteField.
"""
return x if isinstance(x, FiniteField.Value) and x.field == self else FiniteField.Value(self, x) | [
"def",
"value",
"(",
"self",
",",
"x",
")",
":",
"return",
"x",
"if",
"isinstance",
"(",
"x",
",",
"FiniteField",
".",
"Value",
")",
"and",
"x",
".",
"field",
"==",
"self",
"else",
"FiniteField",
".",
"Value",
"(",
"self",
",",
"x",
")"
] | converts an integer or FinitField.Value to a value of this FiniteField. | [
"converts",
"an",
"integer",
"or",
"FinitField",
".",
"Value",
"to",
"a",
"value",
"of",
"this",
"FiniteField",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/ECCurve.py#L316-L320 |
CityOfZion/neo-python-core | neocore/Cryptography/ECCurve.py | FiniteField.integer | def integer(self, x):
"""
returns a plain integer
"""
if type(x) is str:
hex = binascii.unhexlify(x)
return int.from_bytes(hex, 'big')
return x.value if isinstance(x, FiniteField.Value) else x | python | def integer(self, x):
"""
returns a plain integer
"""
if type(x) is str:
hex = binascii.unhexlify(x)
return int.from_bytes(hex, 'big')
return x.value if isinstance(x, FiniteField.Value) else x | [
"def",
"integer",
"(",
"self",
",",
"x",
")",
":",
"if",
"type",
"(",
"x",
")",
"is",
"str",
":",
"hex",
"=",
"binascii",
".",
"unhexlify",
"(",
"x",
")",
"return",
"int",
".",
"from_bytes",
"(",
"hex",
",",
"'big'",
")",
"return",
"x",
".",
"v... | returns a plain integer | [
"returns",
"a",
"plain",
"integer"
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/ECCurve.py#L322-L330 |
CityOfZion/neo-python-core | neocore/Cryptography/ECCurve.py | EllipticCurve.add | def add(self, p, q):
"""
perform elliptic curve addition
"""
if p.iszero():
return q
if q.iszero():
return p
lft = 0
# calculate the slope of the intersection line
if p == q:
if p.y == 0:
return self.zer... | python | def add(self, p, q):
"""
perform elliptic curve addition
"""
if p.iszero():
return q
if q.iszero():
return p
lft = 0
# calculate the slope of the intersection line
if p == q:
if p.y == 0:
return self.zer... | [
"def",
"add",
"(",
"self",
",",
"p",
",",
"q",
")",
":",
"if",
"p",
".",
"iszero",
"(",
")",
":",
"return",
"q",
"if",
"q",
".",
"iszero",
"(",
")",
":",
"return",
"p",
"lft",
"=",
"0",
"# calculate the slope of the intersection line",
"if",
"p",
"... | perform elliptic curve addition | [
"perform",
"elliptic",
"curve",
"addition"
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/ECCurve.py#L486-L509 |
CityOfZion/neo-python-core | neocore/Cryptography/ECCurve.py | EllipticCurve.zero | def zero(self):
"""
Return the additive identity point ( aka '0' )
P + 0 = P
"""
return self.point(self.field.zero(), self.field.zero()) | python | def zero(self):
"""
Return the additive identity point ( aka '0' )
P + 0 = P
"""
return self.point(self.field.zero(), self.field.zero()) | [
"def",
"zero",
"(",
"self",
")",
":",
"return",
"self",
".",
"point",
"(",
"self",
".",
"field",
".",
"zero",
"(",
")",
",",
"self",
".",
"field",
".",
"zero",
"(",
")",
")"
] | Return the additive identity point ( aka '0' )
P + 0 = P | [
"Return",
"the",
"additive",
"identity",
"point",
"(",
"aka",
"0",
")",
"P",
"+",
"0",
"=",
"P"
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/ECCurve.py#L543-L548 |
CityOfZion/neo-python-core | neocore/Cryptography/ECCurve.py | EllipticCurve.point | def point(self, x, y):
"""
construct a point from 2 values
"""
return EllipticCurve.ECPoint(self, self.field.value(x), self.field.value(y)) | python | def point(self, x, y):
"""
construct a point from 2 values
"""
return EllipticCurve.ECPoint(self, self.field.value(x), self.field.value(y)) | [
"def",
"point",
"(",
"self",
",",
"x",
",",
"y",
")",
":",
"return",
"EllipticCurve",
".",
"ECPoint",
"(",
"self",
",",
"self",
".",
"field",
".",
"value",
"(",
"x",
")",
",",
"self",
".",
"field",
".",
"value",
"(",
"y",
")",
")"
] | construct a point from 2 values | [
"construct",
"a",
"point",
"from",
"2",
"values"
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/ECCurve.py#L550-L554 |
CityOfZion/neo-python-core | neocore/Cryptography/ECCurve.py | EllipticCurve.isoncurve | def isoncurve(self, p):
"""
verifies if a point is on the curve
"""
return p.iszero() or p.y ** 2 == p.x ** 3 + self.a * p.x + self.b | python | def isoncurve(self, p):
"""
verifies if a point is on the curve
"""
return p.iszero() or p.y ** 2 == p.x ** 3 + self.a * p.x + self.b | [
"def",
"isoncurve",
"(",
"self",
",",
"p",
")",
":",
"return",
"p",
".",
"iszero",
"(",
")",
"or",
"p",
".",
"y",
"**",
"2",
"==",
"p",
".",
"x",
"**",
"3",
"+",
"self",
".",
"a",
"*",
"p",
".",
"x",
"+",
"self",
".",
"b"
] | verifies if a point is on the curve | [
"verifies",
"if",
"a",
"point",
"is",
"on",
"the",
"curve"
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/ECCurve.py#L556-L560 |
CityOfZion/neo-python-core | neocore/Cryptography/ECCurve.py | EllipticCurve.decompress | def decompress(self, x, flag):
"""
calculate the y coordinate given only the x value.
there are 2 possible solutions, use 'flag' to select.
"""
x = self.field.value(x)
ysquare = x ** 3 + self.a * x + self.b
return self.point(x, ysquare.sqrt(flag)) | python | def decompress(self, x, flag):
"""
calculate the y coordinate given only the x value.
there are 2 possible solutions, use 'flag' to select.
"""
x = self.field.value(x)
ysquare = x ** 3 + self.a * x + self.b
return self.point(x, ysquare.sqrt(flag)) | [
"def",
"decompress",
"(",
"self",
",",
"x",
",",
"flag",
")",
":",
"x",
"=",
"self",
".",
"field",
".",
"value",
"(",
"x",
")",
"ysquare",
"=",
"x",
"**",
"3",
"+",
"self",
".",
"a",
"*",
"x",
"+",
"self",
".",
"b",
"return",
"self",
".",
"... | calculate the y coordinate given only the x value.
there are 2 possible solutions, use 'flag' to select. | [
"calculate",
"the",
"y",
"coordinate",
"given",
"only",
"the",
"x",
"value",
".",
"there",
"are",
"2",
"possible",
"solutions",
"use",
"flag",
"to",
"select",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/ECCurve.py#L562-L570 |
CityOfZion/neo-python-core | neocore/Cryptography/ECCurve.py | EllipticCurve.decompress_from_curve | def decompress_from_curve(self, x, flag):
"""
calculate the y coordinate given only the x value.
there are 2 possible solutions, use 'flag' to select.
"""
cq = self.field.p
x = self.field.value(x)
ysquare = x ** 3 + self.a * x + self.b
ysquare_root = sq... | python | def decompress_from_curve(self, x, flag):
"""
calculate the y coordinate given only the x value.
there are 2 possible solutions, use 'flag' to select.
"""
cq = self.field.p
x = self.field.value(x)
ysquare = x ** 3 + self.a * x + self.b
ysquare_root = sq... | [
"def",
"decompress_from_curve",
"(",
"self",
",",
"x",
",",
"flag",
")",
":",
"cq",
"=",
"self",
".",
"field",
".",
"p",
"x",
"=",
"self",
".",
"field",
".",
"value",
"(",
"x",
")",
"ysquare",
"=",
"x",
"**",
"3",
"+",
"self",
".",
"a",
"*",
... | calculate the y coordinate given only the x value.
there are 2 possible solutions, use 'flag' to select. | [
"calculate",
"the",
"y",
"coordinate",
"given",
"only",
"the",
"x",
"value",
".",
"there",
"are",
"2",
"possible",
"solutions",
"use",
"flag",
"to",
"select",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/ECCurve.py#L648-L670 |
CityOfZion/neo-python-core | neocore/Cryptography/ECCurve.py | ECDSA.sign | def sign(self, message, privkey, secret):
"""
sign the message using private key and sign secret
for signsecret k, message m, privatekey x
return (G*k, (m+x*r)/k)
"""
m = self.GFn.value(message)
x = self.GFn.value(privkey)
k = self.GFn.value(secret)
... | python | def sign(self, message, privkey, secret):
"""
sign the message using private key and sign secret
for signsecret k, message m, privatekey x
return (G*k, (m+x*r)/k)
"""
m = self.GFn.value(message)
x = self.GFn.value(privkey)
k = self.GFn.value(secret)
... | [
"def",
"sign",
"(",
"self",
",",
"message",
",",
"privkey",
",",
"secret",
")",
":",
"m",
"=",
"self",
".",
"GFn",
".",
"value",
"(",
"message",
")",
"x",
"=",
"self",
".",
"GFn",
".",
"value",
"(",
"privkey",
")",
"k",
"=",
"self",
".",
"GFn",... | sign the message using private key and sign secret
for signsecret k, message m, privatekey x
return (G*k, (m+x*r)/k) | [
"sign",
"the",
"message",
"using",
"private",
"key",
"and",
"sign",
"secret",
"for",
"signsecret",
"k",
"message",
"m",
"privatekey",
"x",
"return",
"(",
"G",
"*",
"k",
"(",
"m",
"+",
"x",
"*",
"r",
")",
"/",
"k",
")"
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/ECCurve.py#L694-L709 |
CityOfZion/neo-python-core | neocore/Cryptography/ECCurve.py | ECDSA.verify | def verify(self, message, pubkey, rnum, snum):
"""
Verify the signature
for message m, pubkey Y, signature (r,s)
r = xcoord(R)
verify that : G*m+Y*r=R*s
this is true because: { Y=G*x, and R=G*k, s=(m+x*r)/k }
G*m+G*x*r = G*k*(m+x*r)/k ->
G*(m+x*r) = G*(... | python | def verify(self, message, pubkey, rnum, snum):
"""
Verify the signature
for message m, pubkey Y, signature (r,s)
r = xcoord(R)
verify that : G*m+Y*r=R*s
this is true because: { Y=G*x, and R=G*k, s=(m+x*r)/k }
G*m+G*x*r = G*k*(m+x*r)/k ->
G*(m+x*r) = G*(... | [
"def",
"verify",
"(",
"self",
",",
"message",
",",
"pubkey",
",",
"rnum",
",",
"snum",
")",
":",
"m",
"=",
"self",
".",
"GFn",
".",
"value",
"(",
"message",
")",
"r",
"=",
"self",
".",
"GFn",
".",
"value",
"(",
"rnum",
")",
"s",
"=",
"self",
... | Verify the signature
for message m, pubkey Y, signature (r,s)
r = xcoord(R)
verify that : G*m+Y*r=R*s
this is true because: { Y=G*x, and R=G*k, s=(m+x*r)/k }
G*m+G*x*r = G*k*(m+x*r)/k ->
G*(m+x*r) = G*(m+x*r)
several ways to do the verification:
r =... | [
"Verify",
"the",
"signature",
"for",
"message",
"m",
"pubkey",
"Y",
"signature",
"(",
"r",
"s",
")",
"r",
"=",
"xcoord",
"(",
"R",
")",
"verify",
"that",
":",
"G",
"*",
"m",
"+",
"Y",
"*",
"r",
"=",
"R",
"*",
"s",
"this",
"is",
"true",
"because... | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/ECCurve.py#L711-L740 |
CityOfZion/neo-python-core | neocore/Cryptography/ECCurve.py | ECDSA.findpk | def findpk(self, message, rnum, snum, flag):
"""
find pubkey Y from message m, signature (r,s)
Y = (R*s-G*m)/r
note that there are 2 pubkeys related to a signature
"""
m = self.GFn.value(message)
r = self.GFn.value(rnum)
s = self.GFn.value(snum)
R... | python | def findpk(self, message, rnum, snum, flag):
"""
find pubkey Y from message m, signature (r,s)
Y = (R*s-G*m)/r
note that there are 2 pubkeys related to a signature
"""
m = self.GFn.value(message)
r = self.GFn.value(rnum)
s = self.GFn.value(snum)
R... | [
"def",
"findpk",
"(",
"self",
",",
"message",
",",
"rnum",
",",
"snum",
",",
"flag",
")",
":",
"m",
"=",
"self",
".",
"GFn",
".",
"value",
"(",
"message",
")",
"r",
"=",
"self",
".",
"GFn",
".",
"value",
"(",
"rnum",
")",
"s",
"=",
"self",
".... | find pubkey Y from message m, signature (r,s)
Y = (R*s-G*m)/r
note that there are 2 pubkeys related to a signature | [
"find",
"pubkey",
"Y",
"from",
"message",
"m",
"signature",
"(",
"r",
"s",
")",
"Y",
"=",
"(",
"R",
"*",
"s",
"-",
"G",
"*",
"m",
")",
"/",
"r",
"note",
"that",
"there",
"are",
"2",
"pubkeys",
"related",
"to",
"a",
"signature"
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/ECCurve.py#L742-L755 |
CityOfZion/neo-python-core | neocore/Cryptography/ECCurve.py | ECDSA.findpk2 | def findpk2(self, r1, s1, r2, s2, flag1, flag2):
"""
find pubkey Y from 2 different signature on the same message
sigs: (r1,s1) and (r2,s2)
returns (R1*s1-R2*s2)/(r1-r2)
"""
R1 = self.ec.decompress(r1, flag1)
R2 = self.ec.decompress(r2, flag2)
rdiff = se... | python | def findpk2(self, r1, s1, r2, s2, flag1, flag2):
"""
find pubkey Y from 2 different signature on the same message
sigs: (r1,s1) and (r2,s2)
returns (R1*s1-R2*s2)/(r1-r2)
"""
R1 = self.ec.decompress(r1, flag1)
R2 = self.ec.decompress(r2, flag2)
rdiff = se... | [
"def",
"findpk2",
"(",
"self",
",",
"r1",
",",
"s1",
",",
"r2",
",",
"s2",
",",
"flag1",
",",
"flag2",
")",
":",
"R1",
"=",
"self",
".",
"ec",
".",
"decompress",
"(",
"r1",
",",
"flag1",
")",
"R2",
"=",
"self",
".",
"ec",
".",
"decompress",
"... | find pubkey Y from 2 different signature on the same message
sigs: (r1,s1) and (r2,s2)
returns (R1*s1-R2*s2)/(r1-r2) | [
"find",
"pubkey",
"Y",
"from",
"2",
"different",
"signature",
"on",
"the",
"same",
"message",
"sigs",
":",
"(",
"r1",
"s1",
")",
"and",
"(",
"r2",
"s2",
")",
"returns",
"(",
"R1",
"*",
"s1",
"-",
"R2",
"*",
"s2",
")",
"/",
"(",
"r1",
"-",
"r2",... | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/ECCurve.py#L757-L768 |
CityOfZion/neo-python-core | neocore/Cryptography/ECCurve.py | ECDSA.crack2 | def crack2(self, r, s1, s2, m1, m2):
"""
find signsecret and privkey from duplicate 'r'
signature (r,s1) for message m1
and signature (r,s2) for message m2
s1= (m1 + x*r)/k
s2= (m2 + x*r)/k
subtract -> (s1-s2) = (m1-m2)/k -> k = (m1-m2)/(s1-s2)
-> privke... | python | def crack2(self, r, s1, s2, m1, m2):
"""
find signsecret and privkey from duplicate 'r'
signature (r,s1) for message m1
and signature (r,s2) for message m2
s1= (m1 + x*r)/k
s2= (m2 + x*r)/k
subtract -> (s1-s2) = (m1-m2)/k -> k = (m1-m2)/(s1-s2)
-> privke... | [
"def",
"crack2",
"(",
"self",
",",
"r",
",",
"s1",
",",
"s2",
",",
"m1",
",",
"m2",
")",
":",
"sdelta",
"=",
"self",
".",
"GFn",
".",
"value",
"(",
"s1",
"-",
"s2",
")",
"mdelta",
"=",
"self",
".",
"GFn",
".",
"value",
"(",
"m1",
"-",
"m2",... | find signsecret and privkey from duplicate 'r'
signature (r,s1) for message m1
and signature (r,s2) for message m2
s1= (m1 + x*r)/k
s2= (m2 + x*r)/k
subtract -> (s1-s2) = (m1-m2)/k -> k = (m1-m2)/(s1-s2)
-> privkey = (s1*k-m1)/r .. or (s2*k-m2)/r | [
"find",
"signsecret",
"and",
"privkey",
"from",
"duplicate",
"r",
"signature",
"(",
"r",
"s1",
")",
"for",
"message",
"m1",
"and",
"signature",
"(",
"r",
"s2",
")",
"for",
"message",
"m2",
"s1",
"=",
"(",
"m1",
"+",
"x",
"*",
"r",
")",
"/",
"k",
... | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/ECCurve.py#L770-L791 |
CityOfZion/neo-python-core | neocore/Cryptography/ECCurve.py | ECDSA.crack1 | def crack1(self, rnum, snum, message, signsecret):
"""
find privkey, given signsecret k, message m, signature (r,s)
x= (s*k-m)/r
"""
m = self.GFn.value(message)
r = self.GFn.value(rnum)
s = self.GFn.value(snum)
k = self.GFn.value(signsecret)
return... | python | def crack1(self, rnum, snum, message, signsecret):
"""
find privkey, given signsecret k, message m, signature (r,s)
x= (s*k-m)/r
"""
m = self.GFn.value(message)
r = self.GFn.value(rnum)
s = self.GFn.value(snum)
k = self.GFn.value(signsecret)
return... | [
"def",
"crack1",
"(",
"self",
",",
"rnum",
",",
"snum",
",",
"message",
",",
"signsecret",
")",
":",
"m",
"=",
"self",
".",
"GFn",
".",
"value",
"(",
"message",
")",
"r",
"=",
"self",
".",
"GFn",
".",
"value",
"(",
"rnum",
")",
"s",
"=",
"self"... | find privkey, given signsecret k, message m, signature (r,s)
x= (s*k-m)/r | [
"find",
"privkey",
"given",
"signsecret",
"k",
"message",
"m",
"signature",
"(",
"r",
"s",
")",
"x",
"=",
"(",
"s",
"*",
"k",
"-",
"m",
")",
"/",
"r"
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/ECCurve.py#L793-L802 |
CityOfZion/neo-python-core | neocore/Cryptography/ECCurve.py | ECDSA.secp256r1 | def secp256r1():
"""
create the secp256r1 curve
"""
GFp = FiniteField(int("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", 16))
ec = EllipticCurve(GFp, 115792089210356248762697446949407573530086143415290314195533631308867097853948, 41058363725152142129326129780... | python | def secp256r1():
"""
create the secp256r1 curve
"""
GFp = FiniteField(int("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", 16))
ec = EllipticCurve(GFp, 115792089210356248762697446949407573530086143415290314195533631308867097853948, 41058363725152142129326129780... | [
"def",
"secp256r1",
"(",
")",
":",
"GFp",
"=",
"FiniteField",
"(",
"int",
"(",
"\"FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF\"",
",",
"16",
")",
")",
"ec",
"=",
"EllipticCurve",
"(",
"GFp",
",",
"115792089210356248762697446949407573530086143415290314... | create the secp256r1 curve | [
"create",
"the",
"secp256r1",
"curve"
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/ECCurve.py#L805-L814 |
CityOfZion/neo-python-core | neocore/Cryptography/ECCurve.py | ECDSA.decode_secp256r1 | def decode_secp256r1(str, unhex=True, check_on_curve=True):
"""
decode a public key on the secp256r1 curve
"""
GFp = FiniteField(int("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", 16))
ec = EllipticCurve(GFp, 1157920892103562487626974469494075735300861434152... | python | def decode_secp256r1(str, unhex=True, check_on_curve=True):
"""
decode a public key on the secp256r1 curve
"""
GFp = FiniteField(int("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", 16))
ec = EllipticCurve(GFp, 1157920892103562487626974469494075735300861434152... | [
"def",
"decode_secp256r1",
"(",
"str",
",",
"unhex",
"=",
"True",
",",
"check_on_curve",
"=",
"True",
")",
":",
"GFp",
"=",
"FiniteField",
"(",
"int",
"(",
"\"FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF\"",
",",
"16",
")",
")",
"ec",
"=",
"E... | decode a public key on the secp256r1 curve | [
"decode",
"a",
"public",
"key",
"on",
"the",
"secp256r1",
"curve"
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/ECCurve.py#L817-L834 |
CityOfZion/neo-python-core | neocore/Cryptography/ECCurve.py | ECDSA.secp256k1 | def secp256k1():
"""
create the secp256k1 curve
"""
GFp = FiniteField(2 ** 256 - 2 ** 32 - 977) # This is P from below... aka FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F
ec = EllipticCurve(GFp, 0, 7)
return ECDSA(ec, ec.point(0x79BE667EF9DCBBAC55A062... | python | def secp256k1():
"""
create the secp256k1 curve
"""
GFp = FiniteField(2 ** 256 - 2 ** 32 - 977) # This is P from below... aka FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F
ec = EllipticCurve(GFp, 0, 7)
return ECDSA(ec, ec.point(0x79BE667EF9DCBBAC55A062... | [
"def",
"secp256k1",
"(",
")",
":",
"GFp",
"=",
"FiniteField",
"(",
"2",
"**",
"256",
"-",
"2",
"**",
"32",
"-",
"977",
")",
"# This is P from below... aka FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F",
"ec",
"=",
"EllipticCurve",
"(",
"GFp",
",",... | create the secp256k1 curve | [
"create",
"the",
"secp256k1",
"curve"
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/ECCurve.py#L864-L870 |
CityOfZion/neo-python-core | neocore/UIntBase.py | UIntBase.GetHashCode | def GetHashCode(self):
"""uint32 identifier"""
slice_length = 4 if len(self.Data) >= 4 else len(self.Data)
return int.from_bytes(self.Data[:slice_length], 'little') | python | def GetHashCode(self):
"""uint32 identifier"""
slice_length = 4 if len(self.Data) >= 4 else len(self.Data)
return int.from_bytes(self.Data[:slice_length], 'little') | [
"def",
"GetHashCode",
"(",
"self",
")",
":",
"slice_length",
"=",
"4",
"if",
"len",
"(",
"self",
".",
"Data",
")",
">=",
"4",
"else",
"len",
"(",
"self",
".",
"Data",
")",
"return",
"int",
".",
"from_bytes",
"(",
"self",
".",
"Data",
"[",
":",
"s... | uint32 identifier | [
"uint32",
"identifier"
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/UIntBase.py#L33-L36 |
CityOfZion/neo-python-core | neocore/Utils.py | isValidPublicAddress | def isValidPublicAddress(address: str) -> bool:
"""Check if address is a valid NEO address"""
valid = False
if len(address) == 34 and address[0] == 'A':
try:
base58.b58decode_check(address.encode())
valid = True
except ValueError:
# checksum mismatch
... | python | def isValidPublicAddress(address: str) -> bool:
"""Check if address is a valid NEO address"""
valid = False
if len(address) == 34 and address[0] == 'A':
try:
base58.b58decode_check(address.encode())
valid = True
except ValueError:
# checksum mismatch
... | [
"def",
"isValidPublicAddress",
"(",
"address",
":",
"str",
")",
"->",
"bool",
":",
"valid",
"=",
"False",
"if",
"len",
"(",
"address",
")",
"==",
"34",
"and",
"address",
"[",
"0",
"]",
"==",
"'A'",
":",
"try",
":",
"base58",
".",
"b58decode_check",
"... | Check if address is a valid NEO address | [
"Check",
"if",
"address",
"is",
"a",
"valid",
"NEO",
"address"
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Utils.py#L4-L16 |
CityOfZion/neo-python-core | neocore/Cryptography/MerkleTree.py | MerkleTree.__Build | def __Build(leaves):
"""
Build the merkle tree.
Args:
leaves (list): items are of type MerkleTreeNode.
Returns:
MerkleTreeNode: the root node.
"""
if len(leaves) < 1:
raise Exception('Leaves must have length')
if len(leaves) =... | python | def __Build(leaves):
"""
Build the merkle tree.
Args:
leaves (list): items are of type MerkleTreeNode.
Returns:
MerkleTreeNode: the root node.
"""
if len(leaves) < 1:
raise Exception('Leaves must have length')
if len(leaves) =... | [
"def",
"__Build",
"(",
"leaves",
")",
":",
"if",
"len",
"(",
"leaves",
")",
"<",
"1",
":",
"raise",
"Exception",
"(",
"'Leaves must have length'",
")",
"if",
"len",
"(",
"leaves",
")",
"==",
"1",
":",
"return",
"leaves",
"[",
"0",
"]",
"num_parents",
... | Build the merkle tree.
Args:
leaves (list): items are of type MerkleTreeNode.
Returns:
MerkleTreeNode: the root node. | [
"Build",
"the",
"merkle",
"tree",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/MerkleTree.py#L70-L101 |
CityOfZion/neo-python-core | neocore/Cryptography/MerkleTree.py | MerkleTree.ComputeRoot | def ComputeRoot(hashes):
"""
Compute the root hash.
Args:
hashes (list): the list of hashes to build the root from.
Returns:
bytes: the root hash.
"""
if not len(hashes):
raise Exception('Hashes must have length')
if len(hashe... | python | def ComputeRoot(hashes):
"""
Compute the root hash.
Args:
hashes (list): the list of hashes to build the root from.
Returns:
bytes: the root hash.
"""
if not len(hashes):
raise Exception('Hashes must have length')
if len(hashe... | [
"def",
"ComputeRoot",
"(",
"hashes",
")",
":",
"if",
"not",
"len",
"(",
"hashes",
")",
":",
"raise",
"Exception",
"(",
"'Hashes must have length'",
")",
"if",
"len",
"(",
"hashes",
")",
"==",
"1",
":",
"return",
"hashes",
"[",
"0",
"]",
"tree",
"=",
... | Compute the root hash.
Args:
hashes (list): the list of hashes to build the root from.
Returns:
bytes: the root hash. | [
"Compute",
"the",
"root",
"hash",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/MerkleTree.py#L109-L125 |
CityOfZion/neo-python-core | neocore/Cryptography/MerkleTree.py | MerkleTree.__DepthFirstSearch | def __DepthFirstSearch(node, hashes):
"""
Internal helper method.
Args:
node (MerkleTreeNode):
hashes (list): each item is a bytearray.
"""
if node.LeftChild is None:
hashes.add(node.Hash)
else:
MerkleTree.__DepthFirstSearc... | python | def __DepthFirstSearch(node, hashes):
"""
Internal helper method.
Args:
node (MerkleTreeNode):
hashes (list): each item is a bytearray.
"""
if node.LeftChild is None:
hashes.add(node.Hash)
else:
MerkleTree.__DepthFirstSearc... | [
"def",
"__DepthFirstSearch",
"(",
"node",
",",
"hashes",
")",
":",
"if",
"node",
".",
"LeftChild",
"is",
"None",
":",
"hashes",
".",
"add",
"(",
"node",
".",
"Hash",
")",
"else",
":",
"MerkleTree",
".",
"__DepthFirstSearch",
"(",
"node",
".",
"LeftChild"... | Internal helper method.
Args:
node (MerkleTreeNode):
hashes (list): each item is a bytearray. | [
"Internal",
"helper",
"method",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/MerkleTree.py#L128-L140 |
CityOfZion/neo-python-core | neocore/Cryptography/MerkleTree.py | MerkleTree.ToHashArray | def ToHashArray(self):
"""
Turn the tree into a list of hashes.
Returns:
list:
"""
hashes = set()
MerkleTree.__DepthFirstSearch(self.Root, hashes)
return list(hashes) | python | def ToHashArray(self):
"""
Turn the tree into a list of hashes.
Returns:
list:
"""
hashes = set()
MerkleTree.__DepthFirstSearch(self.Root, hashes)
return list(hashes) | [
"def",
"ToHashArray",
"(",
"self",
")",
":",
"hashes",
"=",
"set",
"(",
")",
"MerkleTree",
".",
"__DepthFirstSearch",
"(",
"self",
".",
"Root",
",",
"hashes",
")",
"return",
"list",
"(",
"hashes",
")"
] | Turn the tree into a list of hashes.
Returns:
list: | [
"Turn",
"the",
"tree",
"into",
"a",
"list",
"of",
"hashes",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/MerkleTree.py#L142-L151 |
CityOfZion/neo-python-core | neocore/Cryptography/MerkleTree.py | MerkleTree.Trim | def Trim(self, flags):
"""
Trim the nodes from the tree keeping only the root hash.
Args:
flags: "0000" for trimming, any other value for keeping the nodes.
"""
logger.info("Trimming!")
flags = bytearray(flags)
length = 1 << self.Depth - 1
whi... | python | def Trim(self, flags):
"""
Trim the nodes from the tree keeping only the root hash.
Args:
flags: "0000" for trimming, any other value for keeping the nodes.
"""
logger.info("Trimming!")
flags = bytearray(flags)
length = 1 << self.Depth - 1
whi... | [
"def",
"Trim",
"(",
"self",
",",
"flags",
")",
":",
"logger",
".",
"info",
"(",
"\"Trimming!\"",
")",
"flags",
"=",
"bytearray",
"(",
"flags",
")",
"length",
"=",
"1",
"<<",
"self",
".",
"Depth",
"-",
"1",
"while",
"len",
"(",
"flags",
")",
"<",
... | Trim the nodes from the tree keeping only the root hash.
Args:
flags: "0000" for trimming, any other value for keeping the nodes. | [
"Trim",
"the",
"nodes",
"from",
"the",
"tree",
"keeping",
"only",
"the",
"root",
"hash",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/MerkleTree.py#L153-L166 |
CityOfZion/neo-python-core | neocore/Cryptography/MerkleTree.py | MerkleTree._TrimNode | def _TrimNode(node, index, depth, flags):
"""
Internal helper method to trim a node.
Args:
node (MerkleTreeNode):
index (int): flag index.
depth (int): node tree depth to start trim from.
flags (bytearray): of left/right pairs. 1 byte for the left... | python | def _TrimNode(node, index, depth, flags):
"""
Internal helper method to trim a node.
Args:
node (MerkleTreeNode):
index (int): flag index.
depth (int): node tree depth to start trim from.
flags (bytearray): of left/right pairs. 1 byte for the left... | [
"def",
"_TrimNode",
"(",
"node",
",",
"index",
",",
"depth",
",",
"flags",
")",
":",
"if",
"depth",
"==",
"1",
"or",
"node",
".",
"LeftChild",
"is",
"None",
":",
"return",
"if",
"depth",
"==",
"2",
":",
"if",
"not",
"flags",
"[",
"index",
"*",
"2... | Internal helper method to trim a node.
Args:
node (MerkleTreeNode):
index (int): flag index.
depth (int): node tree depth to start trim from.
flags (bytearray): of left/right pairs. 1 byte for the left node, 1 byte for the right node.
... | [
"Internal",
"helper",
"method",
"to",
"trim",
"a",
"node",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/MerkleTree.py#L169-L195 |
CityOfZion/neo-python-core | neocore/Cryptography/Helper.py | double_sha256 | def double_sha256(ba):
"""
Perform two SHA256 operations on the input.
Args:
ba (bytes): data to hash.
Returns:
str: hash as a double digit hex string.
"""
d1 = hashlib.sha256(ba)
d2 = hashlib.sha256()
d1.hexdigest()
d2.update(d1.digest())
return d2.hexdigest() | python | def double_sha256(ba):
"""
Perform two SHA256 operations on the input.
Args:
ba (bytes): data to hash.
Returns:
str: hash as a double digit hex string.
"""
d1 = hashlib.sha256(ba)
d2 = hashlib.sha256()
d1.hexdigest()
d2.update(d1.digest())
return d2.hexdigest() | [
"def",
"double_sha256",
"(",
"ba",
")",
":",
"d1",
"=",
"hashlib",
".",
"sha256",
"(",
"ba",
")",
"d2",
"=",
"hashlib",
".",
"sha256",
"(",
")",
"d1",
".",
"hexdigest",
"(",
")",
"d2",
".",
"update",
"(",
"d1",
".",
"digest",
"(",
")",
")",
"re... | Perform two SHA256 operations on the input.
Args:
ba (bytes): data to hash.
Returns:
str: hash as a double digit hex string. | [
"Perform",
"two",
"SHA256",
"operations",
"on",
"the",
"input",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/Helper.py#L28-L42 |
CityOfZion/neo-python-core | neocore/Cryptography/Helper.py | scripthash_to_address | def scripthash_to_address(scripthash):
"""
Convert a script hash to a public address.
Args:
scripthash (bytes):
Returns:
str: base58 encoded string representing the wallet address.
"""
sb = bytearray([ADDRESS_VERSION]) + scripthash
c256 = bin_dbl_sha256(sb)[0:4]
outb = ... | python | def scripthash_to_address(scripthash):
"""
Convert a script hash to a public address.
Args:
scripthash (bytes):
Returns:
str: base58 encoded string representing the wallet address.
"""
sb = bytearray([ADDRESS_VERSION]) + scripthash
c256 = bin_dbl_sha256(sb)[0:4]
outb = ... | [
"def",
"scripthash_to_address",
"(",
"scripthash",
")",
":",
"sb",
"=",
"bytearray",
"(",
"[",
"ADDRESS_VERSION",
"]",
")",
"+",
"scripthash",
"c256",
"=",
"bin_dbl_sha256",
"(",
"sb",
")",
"[",
"0",
":",
"4",
"]",
"outb",
"=",
"sb",
"+",
"bytearray",
... | Convert a script hash to a public address.
Args:
scripthash (bytes):
Returns:
str: base58 encoded string representing the wallet address. | [
"Convert",
"a",
"script",
"hash",
"to",
"a",
"public",
"address",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/Helper.py#L71-L84 |
CityOfZion/neo-python-core | neocore/Cryptography/Helper.py | bin_hash160Bytes | def bin_hash160Bytes(bts):
"""
Get a hash of the provided message using the ripemd160 algorithm.
Args:
bts (str): message to hash.
Returns:
bytes: hash.
"""
intermed = hashlib.sha256(bts).digest()
return hashlib.new('ripemd160', intermed).digest() | python | def bin_hash160Bytes(bts):
"""
Get a hash of the provided message using the ripemd160 algorithm.
Args:
bts (str): message to hash.
Returns:
bytes: hash.
"""
intermed = hashlib.sha256(bts).digest()
return hashlib.new('ripemd160', intermed).digest() | [
"def",
"bin_hash160Bytes",
"(",
"bts",
")",
":",
"intermed",
"=",
"hashlib",
".",
"sha256",
"(",
"bts",
")",
".",
"digest",
"(",
")",
"return",
"hashlib",
".",
"new",
"(",
"'ripemd160'",
",",
"intermed",
")",
".",
"digest",
"(",
")"
] | Get a hash of the provided message using the ripemd160 algorithm.
Args:
bts (str): message to hash.
Returns:
bytes: hash. | [
"Get",
"a",
"hash",
"of",
"the",
"provided",
"message",
"using",
"the",
"ripemd160",
"algorithm",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/Helper.py#L113-L124 |
CityOfZion/neo-python-core | neocore/Cryptography/Helper.py | bin_hash160 | def bin_hash160(string):
"""
Get a hash of the provided message using the ripemd160 algorithm.
Args:
string (str): message to hash.
Returns:
str: hash as a double digit hex string.
"""
intermed = hashlib.sha256(string).digest()
return hashlib.new('ripemd160', intermed).hexd... | python | def bin_hash160(string):
"""
Get a hash of the provided message using the ripemd160 algorithm.
Args:
string (str): message to hash.
Returns:
str: hash as a double digit hex string.
"""
intermed = hashlib.sha256(string).digest()
return hashlib.new('ripemd160', intermed).hexd... | [
"def",
"bin_hash160",
"(",
"string",
")",
":",
"intermed",
"=",
"hashlib",
".",
"sha256",
"(",
"string",
")",
".",
"digest",
"(",
")",
"return",
"hashlib",
".",
"new",
"(",
"'ripemd160'",
",",
"intermed",
")",
".",
"hexdigest",
"(",
")"
] | Get a hash of the provided message using the ripemd160 algorithm.
Args:
string (str): message to hash.
Returns:
str: hash as a double digit hex string. | [
"Get",
"a",
"hash",
"of",
"the",
"provided",
"message",
"using",
"the",
"ripemd160",
"algorithm",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/Helper.py#L127-L138 |
CityOfZion/neo-python-core | neocore/Cryptography/Helper.py | base256_encode | def base256_encode(n, minwidth=0): # int/long to byte array
"""
Encode the input with base256.
Args:
n (int): input value.
minwidth: minimum return value length.
Raises:
ValueError: if a negative number is provided.
Returns:
bytearray:
"""
if n > 0:
... | python | def base256_encode(n, minwidth=0): # int/long to byte array
"""
Encode the input with base256.
Args:
n (int): input value.
minwidth: minimum return value length.
Raises:
ValueError: if a negative number is provided.
Returns:
bytearray:
"""
if n > 0:
... | [
"def",
"base256_encode",
"(",
"n",
",",
"minwidth",
"=",
"0",
")",
":",
"# int/long to byte array",
"if",
"n",
">",
"0",
":",
"arr",
"=",
"[",
"]",
"while",
"n",
":",
"n",
",",
"rem",
"=",
"divmod",
"(",
"n",
",",
"256",
")",
"arr",
".",
"append"... | Encode the input with base256.
Args:
n (int): input value.
minwidth: minimum return value length.
Raises:
ValueError: if a negative number is provided.
Returns:
bytearray: | [
"Encode",
"the",
"input",
"with",
"base256",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/Helper.py#L141-L171 |
CityOfZion/neo-python-core | neocore/Cryptography/Helper.py | xor_bytes | def xor_bytes(a, b):
"""
XOR on two bytes objects
Args:
a (bytes): object 1
b (bytes): object 2
Returns:
bytes: The XOR result
"""
assert isinstance(a, bytes)
assert isinstance(b, bytes)
assert len(a) == len(b)
res = bytearray()
for i in range(len(a)):
... | python | def xor_bytes(a, b):
"""
XOR on two bytes objects
Args:
a (bytes): object 1
b (bytes): object 2
Returns:
bytes: The XOR result
"""
assert isinstance(a, bytes)
assert isinstance(b, bytes)
assert len(a) == len(b)
res = bytearray()
for i in range(len(a)):
... | [
"def",
"xor_bytes",
"(",
"a",
",",
"b",
")",
":",
"assert",
"isinstance",
"(",
"a",
",",
"bytes",
")",
"assert",
"isinstance",
"(",
"b",
",",
"bytes",
")",
"assert",
"len",
"(",
"a",
")",
"==",
"len",
"(",
"b",
")",
"res",
"=",
"bytearray",
"(",
... | XOR on two bytes objects
Args:
a (bytes): object 1
b (bytes): object 2
Returns:
bytes: The XOR result | [
"XOR",
"on",
"two",
"bytes",
"objects"
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/Cryptography/Helper.py#L174-L191 |
CityOfZion/neo-python-core | neocore/IO/BinaryWriter.py | BinaryWriter.WriteBytes | def WriteBytes(self, value, unhex=True):
"""
Write a `bytes` type to the stream.
Args:
value (bytes): array of bytes to write to the stream.
unhex (bool): (Default) True. Set to unhexlify the stream. Use when the bytes are not raw bytes; i.e. b'aabb'
Returns:
... | python | def WriteBytes(self, value, unhex=True):
"""
Write a `bytes` type to the stream.
Args:
value (bytes): array of bytes to write to the stream.
unhex (bool): (Default) True. Set to unhexlify the stream. Use when the bytes are not raw bytes; i.e. b'aabb'
Returns:
... | [
"def",
"WriteBytes",
"(",
"self",
",",
"value",
",",
"unhex",
"=",
"True",
")",
":",
"if",
"unhex",
":",
"try",
":",
"value",
"=",
"binascii",
".",
"unhexlify",
"(",
"value",
")",
"except",
"binascii",
".",
"Error",
":",
"pass",
"return",
"self",
"."... | Write a `bytes` type to the stream.
Args:
value (bytes): array of bytes to write to the stream.
unhex (bool): (Default) True. Set to unhexlify the stream. Use when the bytes are not raw bytes; i.e. b'aabb'
Returns:
int: the number of bytes written. | [
"Write",
"a",
"bytes",
"type",
"to",
"the",
"stream",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/IO/BinaryWriter.py#L88-L104 |
CityOfZion/neo-python-core | neocore/IO/BinaryWriter.py | BinaryWriter.pack | def pack(self, fmt, data):
"""
Write bytes by packing them according to the provided format `fmt`.
For more information about the `fmt` format see: https://docs.python.org/3/library/struct.html
Args:
fmt (str): format string.
data (object): the data to write to t... | python | def pack(self, fmt, data):
"""
Write bytes by packing them according to the provided format `fmt`.
For more information about the `fmt` format see: https://docs.python.org/3/library/struct.html
Args:
fmt (str): format string.
data (object): the data to write to t... | [
"def",
"pack",
"(",
"self",
",",
"fmt",
",",
"data",
")",
":",
"return",
"self",
".",
"WriteBytes",
"(",
"struct",
".",
"pack",
"(",
"fmt",
",",
"data",
")",
",",
"unhex",
"=",
"False",
")"
] | Write bytes by packing them according to the provided format `fmt`.
For more information about the `fmt` format see: https://docs.python.org/3/library/struct.html
Args:
fmt (str): format string.
data (object): the data to write to the raw stream.
Returns:
in... | [
"Write",
"bytes",
"by",
"packing",
"them",
"according",
"to",
"the",
"provided",
"format",
"fmt",
".",
"For",
"more",
"information",
"about",
"the",
"fmt",
"format",
"see",
":",
"https",
":",
"//",
"docs",
".",
"python",
".",
"org",
"/",
"3",
"/",
"lib... | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/IO/BinaryWriter.py#L106-L118 |
CityOfZion/neo-python-core | neocore/IO/BinaryWriter.py | BinaryWriter.WriteUInt160 | def WriteUInt160(self, value):
"""
Write a UInt160 type to the stream.
Args:
value (UInt160):
Raises:
Exception: when `value` is not of neocore.UInt160 type.
"""
if type(value) is UInt160:
value.Serialize(self)
else:
... | python | def WriteUInt160(self, value):
"""
Write a UInt160 type to the stream.
Args:
value (UInt160):
Raises:
Exception: when `value` is not of neocore.UInt160 type.
"""
if type(value) is UInt160:
value.Serialize(self)
else:
... | [
"def",
"WriteUInt160",
"(",
"self",
",",
"value",
")",
":",
"if",
"type",
"(",
"value",
")",
"is",
"UInt160",
":",
"value",
".",
"Serialize",
"(",
"self",
")",
"else",
":",
"raise",
"Exception",
"(",
"\"value must be UInt160 instance \"",
")"
] | Write a UInt160 type to the stream.
Args:
value (UInt160):
Raises:
Exception: when `value` is not of neocore.UInt160 type. | [
"Write",
"a",
"UInt160",
"type",
"to",
"the",
"stream",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/IO/BinaryWriter.py#L274-L287 |
CityOfZion/neo-python-core | neocore/IO/BinaryWriter.py | BinaryWriter.WriteUInt256 | def WriteUInt256(self, value):
"""
Write a UInt256 type to the stream.
Args:
value (UInt256):
Raises:
Exception: when `value` is not of neocore.UInt256 type.
"""
if type(value) is UInt256:
value.Serialize(self)
else:
... | python | def WriteUInt256(self, value):
"""
Write a UInt256 type to the stream.
Args:
value (UInt256):
Raises:
Exception: when `value` is not of neocore.UInt256 type.
"""
if type(value) is UInt256:
value.Serialize(self)
else:
... | [
"def",
"WriteUInt256",
"(",
"self",
",",
"value",
")",
":",
"if",
"type",
"(",
"value",
")",
"is",
"UInt256",
":",
"value",
".",
"Serialize",
"(",
"self",
")",
"else",
":",
"raise",
"Exception",
"(",
"\"Cannot write value that is not UInt256\"",
")"
] | Write a UInt256 type to the stream.
Args:
value (UInt256):
Raises:
Exception: when `value` is not of neocore.UInt256 type. | [
"Write",
"a",
"UInt256",
"type",
"to",
"the",
"stream",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/IO/BinaryWriter.py#L289-L302 |
CityOfZion/neo-python-core | neocore/IO/BinaryWriter.py | BinaryWriter.WriteVarBytes | def WriteVarBytes(self, value, endian="<"):
"""
Write an integer value in a space saving way to the stream.
Read more about variable size encoding here: http://docs.neo.org/en-us/node/network-protocol.html#convention
Args:
value (bytes):
endian (str): specify the... | python | def WriteVarBytes(self, value, endian="<"):
"""
Write an integer value in a space saving way to the stream.
Read more about variable size encoding here: http://docs.neo.org/en-us/node/network-protocol.html#convention
Args:
value (bytes):
endian (str): specify the... | [
"def",
"WriteVarBytes",
"(",
"self",
",",
"value",
",",
"endian",
"=",
"\"<\"",
")",
":",
"length",
"=",
"len",
"(",
"value",
")",
"self",
".",
"WriteVarInt",
"(",
"length",
",",
"endian",
")",
"return",
"self",
".",
"WriteBytes",
"(",
"value",
",",
... | Write an integer value in a space saving way to the stream.
Read more about variable size encoding here: http://docs.neo.org/en-us/node/network-protocol.html#convention
Args:
value (bytes):
endian (str): specify the endianness. (Default) Little endian ('<'). Use '>' for big endi... | [
"Write",
"an",
"integer",
"value",
"in",
"a",
"space",
"saving",
"way",
"to",
"the",
"stream",
".",
"Read",
"more",
"about",
"variable",
"size",
"encoding",
"here",
":",
"http",
":",
"//",
"docs",
".",
"neo",
".",
"org",
"/",
"en",
"-",
"us",
"/",
... | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/IO/BinaryWriter.py#L341-L356 |
CityOfZion/neo-python-core | neocore/IO/BinaryWriter.py | BinaryWriter.WriteVarString | def WriteVarString(self, value, encoding="utf-8"):
"""
Write a string value to the stream.
Read more about variable size encoding here: http://docs.neo.org/en-us/node/network-protocol.html#convention
Args:
value (string): value to write to the stream.
encoding (s... | python | def WriteVarString(self, value, encoding="utf-8"):
"""
Write a string value to the stream.
Read more about variable size encoding here: http://docs.neo.org/en-us/node/network-protocol.html#convention
Args:
value (string): value to write to the stream.
encoding (s... | [
"def",
"WriteVarString",
"(",
"self",
",",
"value",
",",
"encoding",
"=",
"\"utf-8\"",
")",
":",
"if",
"type",
"(",
"value",
")",
"is",
"str",
":",
"value",
"=",
"value",
".",
"encode",
"(",
"encoding",
")",
"length",
"=",
"len",
"(",
"value",
")",
... | Write a string value to the stream.
Read more about variable size encoding here: http://docs.neo.org/en-us/node/network-protocol.html#convention
Args:
value (string): value to write to the stream.
encoding (str): string encoding format. | [
"Write",
"a",
"string",
"value",
"to",
"the",
"stream",
".",
"Read",
"more",
"about",
"variable",
"size",
"encoding",
"here",
":",
"http",
":",
"//",
"docs",
".",
"neo",
".",
"org",
"/",
"en",
"-",
"us",
"/",
"node",
"/",
"network",
"-",
"protocol",
... | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/IO/BinaryWriter.py#L358-L375 |
CityOfZion/neo-python-core | neocore/IO/BinaryWriter.py | BinaryWriter.WriteFixedString | def WriteFixedString(self, value, length):
"""
Write a string value to the stream.
Args:
value (str): value to write to the stream.
length (int): length of the string to write.
"""
towrite = value.encode('utf-8')
slen = len(towrite)
if sle... | python | def WriteFixedString(self, value, length):
"""
Write a string value to the stream.
Args:
value (str): value to write to the stream.
length (int): length of the string to write.
"""
towrite = value.encode('utf-8')
slen = len(towrite)
if sle... | [
"def",
"WriteFixedString",
"(",
"self",
",",
"value",
",",
"length",
")",
":",
"towrite",
"=",
"value",
".",
"encode",
"(",
"'utf-8'",
")",
"slen",
"=",
"len",
"(",
"towrite",
")",
"if",
"slen",
">",
"length",
":",
"raise",
"Exception",
"(",
"\"string ... | Write a string value to the stream.
Args:
value (str): value to write to the stream.
length (int): length of the string to write. | [
"Write",
"a",
"string",
"value",
"to",
"the",
"stream",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/IO/BinaryWriter.py#L377-L394 |
CityOfZion/neo-python-core | neocore/IO/BinaryWriter.py | BinaryWriter.WriteSerializableArray | def WriteSerializableArray(self, array):
"""
Write an array of serializable objects to the stream.
Args:
array(list): a list of serializable objects. i.e. extending neo.IO.Mixins.SerializableMixin
"""
if array is None:
self.WriteByte(0)
else:
... | python | def WriteSerializableArray(self, array):
"""
Write an array of serializable objects to the stream.
Args:
array(list): a list of serializable objects. i.e. extending neo.IO.Mixins.SerializableMixin
"""
if array is None:
self.WriteByte(0)
else:
... | [
"def",
"WriteSerializableArray",
"(",
"self",
",",
"array",
")",
":",
"if",
"array",
"is",
"None",
":",
"self",
".",
"WriteByte",
"(",
"0",
")",
"else",
":",
"self",
".",
"WriteVarInt",
"(",
"len",
"(",
"array",
")",
")",
"for",
"item",
"in",
"array"... | Write an array of serializable objects to the stream.
Args:
array(list): a list of serializable objects. i.e. extending neo.IO.Mixins.SerializableMixin | [
"Write",
"an",
"array",
"of",
"serializable",
"objects",
"to",
"the",
"stream",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/IO/BinaryWriter.py#L396-L408 |
CityOfZion/neo-python-core | neocore/IO/BinaryWriter.py | BinaryWriter.Write2000256List | def Write2000256List(self, arr):
"""
Write an array of 64 byte items to the stream.
Args:
arr (list): a list of 2000 items of 64 bytes in size.
"""
for item in arr:
ba = bytearray(binascii.unhexlify(item))
ba.reverse()
self.WriteBy... | python | def Write2000256List(self, arr):
"""
Write an array of 64 byte items to the stream.
Args:
arr (list): a list of 2000 items of 64 bytes in size.
"""
for item in arr:
ba = bytearray(binascii.unhexlify(item))
ba.reverse()
self.WriteBy... | [
"def",
"Write2000256List",
"(",
"self",
",",
"arr",
")",
":",
"for",
"item",
"in",
"arr",
":",
"ba",
"=",
"bytearray",
"(",
"binascii",
".",
"unhexlify",
"(",
"item",
")",
")",
"ba",
".",
"reverse",
"(",
")",
"self",
".",
"WriteBytes",
"(",
"ba",
"... | Write an array of 64 byte items to the stream.
Args:
arr (list): a list of 2000 items of 64 bytes in size. | [
"Write",
"an",
"array",
"of",
"64",
"byte",
"items",
"to",
"the",
"stream",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/IO/BinaryWriter.py#L410-L420 |
CityOfZion/neo-python-core | neocore/IO/BinaryWriter.py | BinaryWriter.WriteHashes | def WriteHashes(self, arr):
"""
Write an array of hashes to the stream.
Args:
arr (list): a list of 32 byte hashes.
"""
length = len(arr)
self.WriteVarInt(length)
for item in arr:
ba = bytearray(binascii.unhexlify(item))
ba.rev... | python | def WriteHashes(self, arr):
"""
Write an array of hashes to the stream.
Args:
arr (list): a list of 32 byte hashes.
"""
length = len(arr)
self.WriteVarInt(length)
for item in arr:
ba = bytearray(binascii.unhexlify(item))
ba.rev... | [
"def",
"WriteHashes",
"(",
"self",
",",
"arr",
")",
":",
"length",
"=",
"len",
"(",
"arr",
")",
"self",
".",
"WriteVarInt",
"(",
"length",
")",
"for",
"item",
"in",
"arr",
":",
"ba",
"=",
"bytearray",
"(",
"binascii",
".",
"unhexlify",
"(",
"item",
... | Write an array of hashes to the stream.
Args:
arr (list): a list of 32 byte hashes. | [
"Write",
"an",
"array",
"of",
"hashes",
"to",
"the",
"stream",
"."
] | train | https://github.com/CityOfZion/neo-python-core/blob/786c02cc2f41712d70b1f064ae3d67f86167107f/neocore/IO/BinaryWriter.py#L422-L435 |
OTA-Insight/djangosaml2idp | djangosaml2idp/processors.py | BaseProcessor.get_user_id | def get_user_id(self, user):
""" Get identifier for a user. Take the one defined in settings.SAML_IDP_DJANGO_USERNAME_FIELD first, if not set
use the USERNAME_FIELD property which is set on the user Model. This defaults to the user.username field.
"""
user_field = getattr(settings, '... | python | def get_user_id(self, user):
""" Get identifier for a user. Take the one defined in settings.SAML_IDP_DJANGO_USERNAME_FIELD first, if not set
use the USERNAME_FIELD property which is set on the user Model. This defaults to the user.username field.
"""
user_field = getattr(settings, '... | [
"def",
"get_user_id",
"(",
"self",
",",
"user",
")",
":",
"user_field",
"=",
"getattr",
"(",
"settings",
",",
"'SAML_IDP_DJANGO_USERNAME_FIELD'",
",",
"None",
")",
"or",
"getattr",
"(",
"user",
",",
"'USERNAME_FIELD'",
",",
"'username'",
")",
"return",
"str",
... | Get identifier for a user. Take the one defined in settings.SAML_IDP_DJANGO_USERNAME_FIELD first, if not set
use the USERNAME_FIELD property which is set on the user Model. This defaults to the user.username field. | [
"Get",
"identifier",
"for",
"a",
"user",
".",
"Take",
"the",
"one",
"defined",
"in",
"settings",
".",
"SAML_IDP_DJANGO_USERNAME_FIELD",
"first",
"if",
"not",
"set",
"use",
"the",
"USERNAME_FIELD",
"property",
"which",
"is",
"set",
"on",
"the",
"user",
"Model",... | train | https://github.com/OTA-Insight/djangosaml2idp/blob/8a238063da55bf4823bdc2192168171767c4e056/djangosaml2idp/processors.py#L22-L28 |
OTA-Insight/djangosaml2idp | djangosaml2idp/processors.py | BaseProcessor.create_identity | def create_identity(self, user, sp_mapping, **extra_config):
""" Generate an identity dictionary of the user based on the given mapping of desired user attributes by the SP
"""
return {
out_attr: getattr(user, user_attr)
for user_attr, out_attr in sp_mapping.items()
... | python | def create_identity(self, user, sp_mapping, **extra_config):
""" Generate an identity dictionary of the user based on the given mapping of desired user attributes by the SP
"""
return {
out_attr: getattr(user, user_attr)
for user_attr, out_attr in sp_mapping.items()
... | [
"def",
"create_identity",
"(",
"self",
",",
"user",
",",
"sp_mapping",
",",
"*",
"*",
"extra_config",
")",
":",
"return",
"{",
"out_attr",
":",
"getattr",
"(",
"user",
",",
"user_attr",
")",
"for",
"user_attr",
",",
"out_attr",
"in",
"sp_mapping",
".",
"... | Generate an identity dictionary of the user based on the given mapping of desired user attributes by the SP | [
"Generate",
"an",
"identity",
"dictionary",
"of",
"the",
"user",
"based",
"on",
"the",
"given",
"mapping",
"of",
"desired",
"user",
"attributes",
"by",
"the",
"SP"
] | train | https://github.com/OTA-Insight/djangosaml2idp/blob/8a238063da55bf4823bdc2192168171767c4e056/djangosaml2idp/processors.py#L30-L38 |
OTA-Insight/djangosaml2idp | djangosaml2idp/views.py | sso_entry | def sso_entry(request):
""" Entrypoint view for SSO. Gathers the parameters from the HTTP request, stores them in the session
and redirects the requester to the login_process view.
"""
if request.method == 'POST':
passed_data = request.POST
binding = BINDING_HTTP_POST
else:
... | python | def sso_entry(request):
""" Entrypoint view for SSO. Gathers the parameters from the HTTP request, stores them in the session
and redirects the requester to the login_process view.
"""
if request.method == 'POST':
passed_data = request.POST
binding = BINDING_HTTP_POST
else:
... | [
"def",
"sso_entry",
"(",
"request",
")",
":",
"if",
"request",
".",
"method",
"==",
"'POST'",
":",
"passed_data",
"=",
"request",
".",
"POST",
"binding",
"=",
"BINDING_HTTP_POST",
"else",
":",
"passed_data",
"=",
"request",
".",
"GET",
"binding",
"=",
"BIN... | Entrypoint view for SSO. Gathers the parameters from the HTTP request, stores them in the session
and redirects the requester to the login_process view. | [
"Entrypoint",
"view",
"for",
"SSO",
".",
"Gathers",
"the",
"parameters",
"from",
"the",
"HTTP",
"request",
"stores",
"them",
"in",
"the",
"session",
"and",
"redirects",
"the",
"requester",
"to",
"the",
"login_process",
"view",
"."
] | train | https://github.com/OTA-Insight/djangosaml2idp/blob/8a238063da55bf4823bdc2192168171767c4e056/djangosaml2idp/views.py#L41-L63 |
OTA-Insight/djangosaml2idp | djangosaml2idp/views.py | metadata | def metadata(request):
""" Returns an XML with the SAML 2.0 metadata for this Idp.
The metadata is constructed on-the-fly based on the config dict in the django settings.
"""
conf = IdPConfig()
conf.load(copy.deepcopy(settings.SAML_IDP_CONFIG))
metadata = entity_descriptor(conf)
return H... | python | def metadata(request):
""" Returns an XML with the SAML 2.0 metadata for this Idp.
The metadata is constructed on-the-fly based on the config dict in the django settings.
"""
conf = IdPConfig()
conf.load(copy.deepcopy(settings.SAML_IDP_CONFIG))
metadata = entity_descriptor(conf)
return H... | [
"def",
"metadata",
"(",
"request",
")",
":",
"conf",
"=",
"IdPConfig",
"(",
")",
"conf",
".",
"load",
"(",
"copy",
".",
"deepcopy",
"(",
"settings",
".",
"SAML_IDP_CONFIG",
")",
")",
"metadata",
"=",
"entity_descriptor",
"(",
"conf",
")",
"return",
"Http... | Returns an XML with the SAML 2.0 metadata for this Idp.
The metadata is constructed on-the-fly based on the config dict in the django settings. | [
"Returns",
"an",
"XML",
"with",
"the",
"SAML",
"2",
".",
"0",
"metadata",
"for",
"this",
"Idp",
".",
"The",
"metadata",
"is",
"constructed",
"on",
"-",
"the",
"-",
"fly",
"based",
"on",
"the",
"config",
"dict",
"in",
"the",
"django",
"settings",
"."
] | train | https://github.com/OTA-Insight/djangosaml2idp/blob/8a238063da55bf4823bdc2192168171767c4e056/djangosaml2idp/views.py#L284-L291 |
OTA-Insight/djangosaml2idp | djangosaml2idp/views.py | IdPHandlerViewMixin.dispatch | def dispatch(self, request, *args, **kwargs):
""" Construct IDP server with config from settings dict
"""
conf = IdPConfig()
try:
conf.load(copy.deepcopy(settings.SAML_IDP_CONFIG))
self.IDP = Server(config=conf)
except Exception as e:
return se... | python | def dispatch(self, request, *args, **kwargs):
""" Construct IDP server with config from settings dict
"""
conf = IdPConfig()
try:
conf.load(copy.deepcopy(settings.SAML_IDP_CONFIG))
self.IDP = Server(config=conf)
except Exception as e:
return se... | [
"def",
"dispatch",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"conf",
"=",
"IdPConfig",
"(",
")",
"try",
":",
"conf",
".",
"load",
"(",
"copy",
".",
"deepcopy",
"(",
"settings",
".",
"SAML_IDP_CONFIG",
")",
")... | Construct IDP server with config from settings dict | [
"Construct",
"IDP",
"server",
"with",
"config",
"from",
"settings",
"dict"
] | train | https://github.com/OTA-Insight/djangosaml2idp/blob/8a238063da55bf4823bdc2192168171767c4e056/djangosaml2idp/views.py#L74-L83 |
OTA-Insight/djangosaml2idp | djangosaml2idp/views.py | IdPHandlerViewMixin.get_processor | def get_processor(self, entity_id, sp_config):
""" Instantiate user-specified processor or default to an all-access base processor.
Raises an exception if the configured processor class can not be found or initialized.
"""
processor_string = sp_config.get('processor', None)
i... | python | def get_processor(self, entity_id, sp_config):
""" Instantiate user-specified processor or default to an all-access base processor.
Raises an exception if the configured processor class can not be found or initialized.
"""
processor_string = sp_config.get('processor', None)
i... | [
"def",
"get_processor",
"(",
"self",
",",
"entity_id",
",",
"sp_config",
")",
":",
"processor_string",
"=",
"sp_config",
".",
"get",
"(",
"'processor'",
",",
"None",
")",
"if",
"processor_string",
":",
"try",
":",
"return",
"import_string",
"(",
"processor_str... | Instantiate user-specified processor or default to an all-access base processor.
Raises an exception if the configured processor class can not be found or initialized. | [
"Instantiate",
"user",
"-",
"specified",
"processor",
"or",
"default",
"to",
"an",
"all",
"-",
"access",
"base",
"processor",
".",
"Raises",
"an",
"exception",
"if",
"the",
"configured",
"processor",
"class",
"can",
"not",
"be",
"found",
"or",
"initialized",
... | train | https://github.com/OTA-Insight/djangosaml2idp/blob/8a238063da55bf4823bdc2192168171767c4e056/djangosaml2idp/views.py#L85-L96 |
OTA-Insight/djangosaml2idp | djangosaml2idp/views.py | IdPHandlerViewMixin.get_identity | def get_identity(self, processor, user, sp_config):
""" Create Identity dict (using SP-specific mapping)
"""
sp_mapping = sp_config.get('attribute_mapping', {'username': 'username'})
return processor.create_identity(user, sp_mapping, **sp_config.get('extra_config', {})) | python | def get_identity(self, processor, user, sp_config):
""" Create Identity dict (using SP-specific mapping)
"""
sp_mapping = sp_config.get('attribute_mapping', {'username': 'username'})
return processor.create_identity(user, sp_mapping, **sp_config.get('extra_config', {})) | [
"def",
"get_identity",
"(",
"self",
",",
"processor",
",",
"user",
",",
"sp_config",
")",
":",
"sp_mapping",
"=",
"sp_config",
".",
"get",
"(",
"'attribute_mapping'",
",",
"{",
"'username'",
":",
"'username'",
"}",
")",
"return",
"processor",
".",
"create_id... | Create Identity dict (using SP-specific mapping) | [
"Create",
"Identity",
"dict",
"(",
"using",
"SP",
"-",
"specific",
"mapping",
")"
] | train | https://github.com/OTA-Insight/djangosaml2idp/blob/8a238063da55bf4823bdc2192168171767c4e056/djangosaml2idp/views.py#L98-L102 |
OTA-Insight/djangosaml2idp | example_setup/sp/sp/views.py | custom_update_user | def custom_update_user(sender, instance, attributes, user_modified, **kargs):
""" Default behaviour does not play nice with booleans encoded in SAML as u'true'/u'false'.
This will convert those attributes to real booleans when saving.
"""
for k, v in attributes.items():
u = set.intersection(... | python | def custom_update_user(sender, instance, attributes, user_modified, **kargs):
""" Default behaviour does not play nice with booleans encoded in SAML as u'true'/u'false'.
This will convert those attributes to real booleans when saving.
"""
for k, v in attributes.items():
u = set.intersection(... | [
"def",
"custom_update_user",
"(",
"sender",
",",
"instance",
",",
"attributes",
",",
"user_modified",
",",
"*",
"*",
"kargs",
")",
":",
"for",
"k",
",",
"v",
"in",
"attributes",
".",
"items",
"(",
")",
":",
"u",
"=",
"set",
".",
"intersection",
"(",
... | Default behaviour does not play nice with booleans encoded in SAML as u'true'/u'false'.
This will convert those attributes to real booleans when saving. | [
"Default",
"behaviour",
"does",
"not",
"play",
"nice",
"with",
"booleans",
"encoded",
"in",
"SAML",
"as",
"u",
"true",
"/",
"u",
"false",
".",
"This",
"will",
"convert",
"those",
"attributes",
"to",
"real",
"booleans",
"when",
"saving",
"."
] | train | https://github.com/OTA-Insight/djangosaml2idp/blob/8a238063da55bf4823bdc2192168171767c4e056/example_setup/sp/sp/views.py#L26-L34 |
MartijnBraam/python-isc-dhcp-leases | isc_dhcp_leases/iscdhcpleases.py | parse_time | def parse_time(s):
"""
Like datetime.datetime.strptime(s, "%w %Y/%m/%d %H:%M:%S") but 5x faster.
"""
result = None
if "epoch" in s:
epoch_time = float(s.rstrip().split(' ')[1][:-1])
result = datetime.datetime.utcfromtimestamp(epoch_time)
else:
_, date_part, time_part = s... | python | def parse_time(s):
"""
Like datetime.datetime.strptime(s, "%w %Y/%m/%d %H:%M:%S") but 5x faster.
"""
result = None
if "epoch" in s:
epoch_time = float(s.rstrip().split(' ')[1][:-1])
result = datetime.datetime.utcfromtimestamp(epoch_time)
else:
_, date_part, time_part = s... | [
"def",
"parse_time",
"(",
"s",
")",
":",
"result",
"=",
"None",
"if",
"\"epoch\"",
"in",
"s",
":",
"epoch_time",
"=",
"float",
"(",
"s",
".",
"rstrip",
"(",
")",
".",
"split",
"(",
"' '",
")",
"[",
"1",
"]",
"[",
":",
"-",
"1",
"]",
")",
"res... | Like datetime.datetime.strptime(s, "%w %Y/%m/%d %H:%M:%S") but 5x faster. | [
"Like",
"datetime",
".",
"datetime",
".",
"strptime",
"(",
"s",
"%w",
"%Y",
"/",
"%m",
"/",
"%d",
"%H",
":",
"%M",
":",
"%S",
")",
"but",
"5x",
"faster",
"."
] | train | https://github.com/MartijnBraam/python-isc-dhcp-leases/blob/e96c00e31f3a52c01ef98193577d614d08a93285/isc_dhcp_leases/iscdhcpleases.py#L11-L26 |
MartijnBraam/python-isc-dhcp-leases | isc_dhcp_leases/iscdhcpleases.py | _extract_prop_option | def _extract_prop_option(line):
"""
Extract the (key,value)-tuple from a string like:
>>> "option foobar 123"
:param line:
:return: tuple (key, value)
"""
line = line[7:]
pos = line.find(' ')
return line[:pos], line[pos + 1:] | python | def _extract_prop_option(line):
"""
Extract the (key,value)-tuple from a string like:
>>> "option foobar 123"
:param line:
:return: tuple (key, value)
"""
line = line[7:]
pos = line.find(' ')
return line[:pos], line[pos + 1:] | [
"def",
"_extract_prop_option",
"(",
"line",
")",
":",
"line",
"=",
"line",
"[",
"7",
":",
"]",
"pos",
"=",
"line",
".",
"find",
"(",
"' '",
")",
"return",
"line",
"[",
":",
"pos",
"]",
",",
"line",
"[",
"pos",
"+",
"1",
":",
"]"
] | Extract the (key,value)-tuple from a string like:
>>> "option foobar 123"
:param line:
:return: tuple (key, value) | [
"Extract",
"the",
"(",
"key",
"value",
")",
"-",
"tuple",
"from",
"a",
"string",
"like",
":",
">>>",
"option",
"foobar",
"123",
":",
"param",
"line",
":",
":",
"return",
":",
"tuple",
"(",
"key",
"value",
")"
] | train | https://github.com/MartijnBraam/python-isc-dhcp-leases/blob/e96c00e31f3a52c01ef98193577d614d08a93285/isc_dhcp_leases/iscdhcpleases.py#L29-L38 |
MartijnBraam/python-isc-dhcp-leases | isc_dhcp_leases/iscdhcpleases.py | _extract_prop_set | def _extract_prop_set(line):
"""
Extract the (key, value)-tuple from a string like:
>>> 'set foo = "bar"'
:param line:
:return: tuple (key, value)
"""
token = ' = "'
line = line[4:]
pos = line.find(token)
return line[:pos], line[pos + 4:-1] | python | def _extract_prop_set(line):
"""
Extract the (key, value)-tuple from a string like:
>>> 'set foo = "bar"'
:param line:
:return: tuple (key, value)
"""
token = ' = "'
line = line[4:]
pos = line.find(token)
return line[:pos], line[pos + 4:-1] | [
"def",
"_extract_prop_set",
"(",
"line",
")",
":",
"token",
"=",
"' = \"'",
"line",
"=",
"line",
"[",
"4",
":",
"]",
"pos",
"=",
"line",
".",
"find",
"(",
"token",
")",
"return",
"line",
"[",
":",
"pos",
"]",
",",
"line",
"[",
"pos",
"+",
"4",
... | Extract the (key, value)-tuple from a string like:
>>> 'set foo = "bar"'
:param line:
:return: tuple (key, value) | [
"Extract",
"the",
"(",
"key",
"value",
")",
"-",
"tuple",
"from",
"a",
"string",
"like",
":",
">>>",
"set",
"foo",
"=",
"bar",
":",
"param",
"line",
":",
":",
"return",
":",
"tuple",
"(",
"key",
"value",
")"
] | train | https://github.com/MartijnBraam/python-isc-dhcp-leases/blob/e96c00e31f3a52c01ef98193577d614d08a93285/isc_dhcp_leases/iscdhcpleases.py#L41-L51 |
MartijnBraam/python-isc-dhcp-leases | isc_dhcp_leases/iscdhcpleases.py | _extract_properties | def _extract_properties(config):
"""
Parse a line within a lease block
The line should basically match the expression:
>>> r"\s+(?P<key>(?:option|set)\s+\S+|\S+) (?P<value>[\s\S]+?);"
For easier seperation of the cases and faster parsing this is done using substrings etc..
:param config:
:re... | python | def _extract_properties(config):
"""
Parse a line within a lease block
The line should basically match the expression:
>>> r"\s+(?P<key>(?:option|set)\s+\S+|\S+) (?P<value>[\s\S]+?);"
For easier seperation of the cases and faster parsing this is done using substrings etc..
:param config:
:re... | [
"def",
"_extract_properties",
"(",
"config",
")",
":",
"general",
",",
"options",
",",
"sets",
"=",
"{",
"}",
",",
"{",
"}",
",",
"{",
"}",
"for",
"line",
"in",
"config",
".",
"splitlines",
"(",
")",
":",
"# skip empty & malformed lines",
"if",
"not",
... | Parse a line within a lease block
The line should basically match the expression:
>>> r"\s+(?P<key>(?:option|set)\s+\S+|\S+) (?P<value>[\s\S]+?);"
For easier seperation of the cases and faster parsing this is done using substrings etc..
:param config:
:return: tuple of properties dict, options dict ... | [
"Parse",
"a",
"line",
"within",
"a",
"lease",
"block",
"The",
"line",
"should",
"basically",
"match",
"the",
"expression",
":",
">>>",
"r",
"\\",
"s",
"+",
"(",
"?P<key",
">",
"(",
"?",
":",
"option|set",
")",
"\\",
"s",
"+",
"\\",
"S",
"+",
"|",
... | train | https://github.com/MartijnBraam/python-isc-dhcp-leases/blob/e96c00e31f3a52c01ef98193577d614d08a93285/isc_dhcp_leases/iscdhcpleases.py#L65-L98 |
MartijnBraam/python-isc-dhcp-leases | isc_dhcp_leases/iscdhcpleases.py | IscDhcpLeases.get | def get(self, include_backups=False):
"""
Parse the lease file and return a list of Lease instances.
"""
leases = []
with open(self.filename) if not self.gzip else gzip.open(self.filename) as lease_file:
lease_data = lease_file.read()
if self.gzip:
... | python | def get(self, include_backups=False):
"""
Parse the lease file and return a list of Lease instances.
"""
leases = []
with open(self.filename) if not self.gzip else gzip.open(self.filename) as lease_file:
lease_data = lease_file.read()
if self.gzip:
... | [
"def",
"get",
"(",
"self",
",",
"include_backups",
"=",
"False",
")",
":",
"leases",
"=",
"[",
"]",
"with",
"open",
"(",
"self",
".",
"filename",
")",
"if",
"not",
"self",
".",
"gzip",
"else",
"gzip",
".",
"open",
"(",
"self",
".",
"filename",
")",... | Parse the lease file and return a list of Lease instances. | [
"Parse",
"the",
"lease",
"file",
"and",
"return",
"a",
"list",
"of",
"Lease",
"instances",
"."
] | train | https://github.com/MartijnBraam/python-isc-dhcp-leases/blob/e96c00e31f3a52c01ef98193577d614d08a93285/isc_dhcp_leases/iscdhcpleases.py#L115-L151 |
MartijnBraam/python-isc-dhcp-leases | isc_dhcp_leases/iscdhcpleases.py | IscDhcpLeases.get_current | def get_current(self):
"""
Parse the lease file and return a dict of active and valid Lease instances.
The key for this dict is the ethernet address of the lease.
"""
all_leases = self.get()
leases = {}
for lease in all_leases:
if lease.valid and lease... | python | def get_current(self):
"""
Parse the lease file and return a dict of active and valid Lease instances.
The key for this dict is the ethernet address of the lease.
"""
all_leases = self.get()
leases = {}
for lease in all_leases:
if lease.valid and lease... | [
"def",
"get_current",
"(",
"self",
")",
":",
"all_leases",
"=",
"self",
".",
"get",
"(",
")",
"leases",
"=",
"{",
"}",
"for",
"lease",
"in",
"all_leases",
":",
"if",
"lease",
".",
"valid",
"and",
"lease",
".",
"active",
":",
"if",
"type",
"(",
"lea... | Parse the lease file and return a dict of active and valid Lease instances.
The key for this dict is the ethernet address of the lease. | [
"Parse",
"the",
"lease",
"file",
"and",
"return",
"a",
"dict",
"of",
"active",
"and",
"valid",
"Lease",
"instances",
".",
"The",
"key",
"for",
"this",
"dict",
"is",
"the",
"ethernet",
"address",
"of",
"the",
"lease",
"."
] | train | https://github.com/MartijnBraam/python-isc-dhcp-leases/blob/e96c00e31f3a52c01ef98193577d614d08a93285/isc_dhcp_leases/iscdhcpleases.py#L153-L166 |
MartijnBraam/python-isc-dhcp-leases | isc_dhcp_leases/iscdhcpleases.py | Lease.valid | def valid(self):
"""
Checks if the lease is currently valid (not expired and not in the future)
:return: bool: True if lease is valid
"""
if self.end is None:
if self.start is not None:
return self.start <= datetime.datetime.utcnow()
else:
... | python | def valid(self):
"""
Checks if the lease is currently valid (not expired and not in the future)
:return: bool: True if lease is valid
"""
if self.end is None:
if self.start is not None:
return self.start <= datetime.datetime.utcnow()
else:
... | [
"def",
"valid",
"(",
"self",
")",
":",
"if",
"self",
".",
"end",
"is",
"None",
":",
"if",
"self",
".",
"start",
"is",
"not",
"None",
":",
"return",
"self",
".",
"start",
"<=",
"datetime",
".",
"datetime",
".",
"utcnow",
"(",
")",
"else",
":",
"re... | Checks if the lease is currently valid (not expired and not in the future)
:return: bool: True if lease is valid | [
"Checks",
"if",
"the",
"lease",
"is",
"currently",
"valid",
"(",
"not",
"expired",
"and",
"not",
"in",
"the",
"future",
")",
":",
"return",
":",
"bool",
":",
"True",
"if",
"lease",
"is",
"valid"
] | train | https://github.com/MartijnBraam/python-isc-dhcp-leases/blob/e96c00e31f3a52c01ef98193577d614d08a93285/isc_dhcp_leases/iscdhcpleases.py#L238-L252 |
MartijnBraam/python-isc-dhcp-leases | isc_dhcp_leases/iscdhcpleases.py | Lease6.valid | def valid(self):
"""
Checks if the lease is currently valid (not expired)
:return: bool: True if lease is valid
"""
if self.end is None:
return True
else:
return datetime.datetime.utcnow() <= self.end | python | def valid(self):
"""
Checks if the lease is currently valid (not expired)
:return: bool: True if lease is valid
"""
if self.end is None:
return True
else:
return datetime.datetime.utcnow() <= self.end | [
"def",
"valid",
"(",
"self",
")",
":",
"if",
"self",
".",
"end",
"is",
"None",
":",
"return",
"True",
"else",
":",
"return",
"datetime",
".",
"datetime",
".",
"utcnow",
"(",
")",
"<=",
"self",
".",
"end"
] | Checks if the lease is currently valid (not expired)
:return: bool: True if lease is valid | [
"Checks",
"if",
"the",
"lease",
"is",
"currently",
"valid",
"(",
"not",
"expired",
")",
":",
"return",
":",
"bool",
":",
"True",
"if",
"lease",
"is",
"valid"
] | train | https://github.com/MartijnBraam/python-isc-dhcp-leases/blob/e96c00e31f3a52c01ef98193577d614d08a93285/isc_dhcp_leases/iscdhcpleases.py#L310-L318 |
crate/crash | src/crate/crash/tabulate.py | _padleft | def _padleft(width, s, has_invisible=True):
"""Flush right.
>>> _padleft(6, '\u044f\u0439\u0446\u0430') == ' \u044f\u0439\u0446\u0430'
True
"""
def impl(val):
iwidth = width + len(val) - len(_strip_invisible(val)) if has_invisible else width
fmt = "{0:>%ds}" % iwidth
retu... | python | def _padleft(width, s, has_invisible=True):
"""Flush right.
>>> _padleft(6, '\u044f\u0439\u0446\u0430') == ' \u044f\u0439\u0446\u0430'
True
"""
def impl(val):
iwidth = width + len(val) - len(_strip_invisible(val)) if has_invisible else width
fmt = "{0:>%ds}" % iwidth
retu... | [
"def",
"_padleft",
"(",
"width",
",",
"s",
",",
"has_invisible",
"=",
"True",
")",
":",
"def",
"impl",
"(",
"val",
")",
":",
"iwidth",
"=",
"width",
"+",
"len",
"(",
"val",
")",
"-",
"len",
"(",
"_strip_invisible",
"(",
"val",
")",
")",
"if",
"ha... | Flush right.
>>> _padleft(6, '\u044f\u0439\u0446\u0430') == ' \u044f\u0439\u0446\u0430'
True | [
"Flush",
"right",
"."
] | train | https://github.com/crate/crash/blob/32d3ddc78fd2f7848ed2b99d9cd8889e322528d9/src/crate/crash/tabulate.py#L392-L406 |
crate/crash | src/crate/crash/tabulate.py | _visible_width | def _visible_width(s):
"""Visible width of a printed string. ANSI color codes are removed.
>>> _visible_width('\x1b[31mhello\x1b[0m'), _visible_width("world")
(5, 5)
"""
if isinstance(s, _text_type) or isinstance(s, _binary_type):
return _max_line_width(_strip_invisible(s))
else:
... | python | def _visible_width(s):
"""Visible width of a printed string. ANSI color codes are removed.
>>> _visible_width('\x1b[31mhello\x1b[0m'), _visible_width("world")
(5, 5)
"""
if isinstance(s, _text_type) or isinstance(s, _binary_type):
return _max_line_width(_strip_invisible(s))
else:
... | [
"def",
"_visible_width",
"(",
"s",
")",
":",
"if",
"isinstance",
"(",
"s",
",",
"_text_type",
")",
"or",
"isinstance",
"(",
"s",
",",
"_binary_type",
")",
":",
"return",
"_max_line_width",
"(",
"_strip_invisible",
"(",
"s",
")",
")",
"else",
":",
"return... | Visible width of a printed string. ANSI color codes are removed.
>>> _visible_width('\x1b[31mhello\x1b[0m'), _visible_width("world")
(5, 5) | [
"Visible",
"width",
"of",
"a",
"printed",
"string",
".",
"ANSI",
"color",
"codes",
"are",
"removed",
"."
] | train | https://github.com/crate/crash/blob/32d3ddc78fd2f7848ed2b99d9cd8889e322528d9/src/crate/crash/tabulate.py#L468-L478 |
crate/crash | src/crate/crash/tabulate.py | _column_type | def _column_type(values, has_invisible=True):
"""The least generic type all column values are convertible to.
>>> _column_type(["1", "2"]) is _int_type
True
>>> _column_type(["1", "2.3"]) is _float_type
True
>>> _column_type(["1", "2.3", "four"]) is _text_type
True
>>> _column_type(["fo... | python | def _column_type(values, has_invisible=True):
"""The least generic type all column values are convertible to.
>>> _column_type(["1", "2"]) is _int_type
True
>>> _column_type(["1", "2.3"]) is _float_type
True
>>> _column_type(["1", "2.3", "four"]) is _text_type
True
>>> _column_type(["fo... | [
"def",
"_column_type",
"(",
"values",
",",
"has_invisible",
"=",
"True",
")",
":",
"return",
"reduce",
"(",
"_more_generic",
",",
"[",
"type",
"(",
"v",
")",
"for",
"v",
"in",
"values",
"]",
",",
"int",
")"
] | The least generic type all column values are convertible to.
>>> _column_type(["1", "2"]) is _int_type
True
>>> _column_type(["1", "2.3"]) is _float_type
True
>>> _column_type(["1", "2.3", "four"]) is _text_type
True
>>> _column_type(["four", '\u043f\u044f\u0442\u044c']) is _text_type
T... | [
"The",
"least",
"generic",
"type",
"all",
"column",
"values",
"are",
"convertible",
"to",
"."
] | train | https://github.com/crate/crash/blob/32d3ddc78fd2f7848ed2b99d9cd8889e322528d9/src/crate/crash/tabulate.py#L582-L602 |
crate/crash | src/crate/crash/tabulate.py | _normalize_tabular_data | def _normalize_tabular_data(tabular_data, headers):
"""Transform a supported data type to a list of lists, and a list of headers.
Supported tabular data types:
* list-of-lists or another iterable of iterables
* list of named tuples (usually used with headers="keys")
* list of dicts (usually used... | python | def _normalize_tabular_data(tabular_data, headers):
"""Transform a supported data type to a list of lists, and a list of headers.
Supported tabular data types:
* list-of-lists or another iterable of iterables
* list of named tuples (usually used with headers="keys")
* list of dicts (usually used... | [
"def",
"_normalize_tabular_data",
"(",
"tabular_data",
",",
"headers",
")",
":",
"if",
"hasattr",
"(",
"tabular_data",
",",
"\"keys\"",
")",
"and",
"hasattr",
"(",
"tabular_data",
",",
"\"values\"",
")",
":",
"# dict-like and pandas.DataFrame?",
"if",
"hasattr",
"... | Transform a supported data type to a list of lists, and a list of headers.
Supported tabular data types:
* list-of-lists or another iterable of iterables
* list of named tuples (usually used with headers="keys")
* list of dicts (usually used with headers="keys")
* list of OrderedDicts (usually ... | [
"Transform",
"a",
"supported",
"data",
"type",
"to",
"a",
"list",
"of",
"lists",
"and",
"a",
"list",
"of",
"headers",
"."
] | train | https://github.com/crate/crash/blob/32d3ddc78fd2f7848ed2b99d9cd8889e322528d9/src/crate/crash/tabulate.py#L659-L767 |
crate/crash | src/crate/crash/tabulate.py | tabulate | def tabulate(tabular_data, headers=(), tablefmt="simple",
floatfmt="g", numalign="decimal", stralign="left",
missingval=""):
"""Format a fixed width table for pretty printing.
>>> print(tabulate([[1, 2.34], [-56, "8.999"], ["2", "10001"]]))
--- ---------
1 2.34
-56... | python | def tabulate(tabular_data, headers=(), tablefmt="simple",
floatfmt="g", numalign="decimal", stralign="left",
missingval=""):
"""Format a fixed width table for pretty printing.
>>> print(tabulate([[1, 2.34], [-56, "8.999"], ["2", "10001"]]))
--- ---------
1 2.34
-56... | [
"def",
"tabulate",
"(",
"tabular_data",
",",
"headers",
"=",
"(",
")",
",",
"tablefmt",
"=",
"\"simple\"",
",",
"floatfmt",
"=",
"\"g\"",
",",
"numalign",
"=",
"\"decimal\"",
",",
"stralign",
"=",
"\"left\"",
",",
"missingval",
"=",
"\"\"",
")",
":",
"if... | Format a fixed width table for pretty printing.
>>> print(tabulate([[1, 2.34], [-56, "8.999"], ["2", "10001"]]))
--- ---------
1 2.34
-56 8.999
2 10001
--- ---------
The first required argument (`tabular_data`) can be a
list-of-lists (or another iterable of iterables),... | [
"Format",
"a",
"fixed",
"width",
"table",
"for",
"pretty",
"printing",
"."
] | train | https://github.com/crate/crash/blob/32d3ddc78fd2f7848ed2b99d9cd8889e322528d9/src/crate/crash/tabulate.py#L770-L1055 |
crate/crash | src/crate/crash/tabulate.py | _format_table | def _format_table(fmt, headers, rows, colwidths, colaligns, is_multiline):
"""Produce a plain-text representation of the table."""
lines = []
hidden = fmt.with_header_hide if (headers and fmt.with_header_hide) else []
pad = fmt.padding
headerrow = fmt.headerrow
padded_widths = [(w + 2 * pad) fo... | python | def _format_table(fmt, headers, rows, colwidths, colaligns, is_multiline):
"""Produce a plain-text representation of the table."""
lines = []
hidden = fmt.with_header_hide if (headers and fmt.with_header_hide) else []
pad = fmt.padding
headerrow = fmt.headerrow
padded_widths = [(w + 2 * pad) fo... | [
"def",
"_format_table",
"(",
"fmt",
",",
"headers",
",",
"rows",
",",
"colwidths",
",",
"colaligns",
",",
"is_multiline",
")",
":",
"lines",
"=",
"[",
"]",
"hidden",
"=",
"fmt",
".",
"with_header_hide",
"if",
"(",
"headers",
"and",
"fmt",
".",
"with_head... | Produce a plain-text representation of the table. | [
"Produce",
"a",
"plain",
"-",
"text",
"representation",
"of",
"the",
"table",
"."
] | train | https://github.com/crate/crash/blob/32d3ddc78fd2f7848ed2b99d9cd8889e322528d9/src/crate/crash/tabulate.py#L1118-L1158 |
crate/crash | src/crate/crash/layout.py | create_layout | def create_layout(lexer=None,
reserve_space_for_menu=8,
get_prompt_tokens=None,
get_bottom_toolbar_tokens=None,
extra_input_processors=None, multiline=False,
wrap_lines=True):
"""
Creates a custom `Layout` for the Crash in... | python | def create_layout(lexer=None,
reserve_space_for_menu=8,
get_prompt_tokens=None,
get_bottom_toolbar_tokens=None,
extra_input_processors=None, multiline=False,
wrap_lines=True):
"""
Creates a custom `Layout` for the Crash in... | [
"def",
"create_layout",
"(",
"lexer",
"=",
"None",
",",
"reserve_space_for_menu",
"=",
"8",
",",
"get_prompt_tokens",
"=",
"None",
",",
"get_bottom_toolbar_tokens",
"=",
"None",
",",
"extra_input_processors",
"=",
"None",
",",
"multiline",
"=",
"False",
",",
"wr... | Creates a custom `Layout` for the Crash input REPL
This layout includes:
* a bottom left-aligned session toolbar container
* a bottom right-aligned side-bar container
+-------------------------------------------+
| cr> select 1; |
| ... | [
"Creates",
"a",
"custom",
"Layout",
"for",
"the",
"Crash",
"input",
"REPL"
] | train | https://github.com/crate/crash/blob/32d3ddc78fd2f7848ed2b99d9cd8889e322528d9/src/crate/crash/layout.py#L39-L157 |
crate/crash | src/crate/crash/command.py | parse_config_path | def parse_config_path(args=sys.argv):
"""
Preprocess sys.argv and extract --config argument.
"""
config = CONFIG_PATH
if '--config' in args:
idx = args.index('--config')
if len(args) > idx + 1:
config = args.pop(idx + 1)
args.pop(idx)
return config | python | def parse_config_path(args=sys.argv):
"""
Preprocess sys.argv and extract --config argument.
"""
config = CONFIG_PATH
if '--config' in args:
idx = args.index('--config')
if len(args) > idx + 1:
config = args.pop(idx + 1)
args.pop(idx)
return config | [
"def",
"parse_config_path",
"(",
"args",
"=",
"sys",
".",
"argv",
")",
":",
"config",
"=",
"CONFIG_PATH",
"if",
"'--config'",
"in",
"args",
":",
"idx",
"=",
"args",
".",
"index",
"(",
"'--config'",
")",
"if",
"len",
"(",
"args",
")",
">",
"idx",
"+",... | Preprocess sys.argv and extract --config argument. | [
"Preprocess",
"sys",
".",
"argv",
"and",
"extract",
"--",
"config",
"argument",
"."
] | train | https://github.com/crate/crash/blob/32d3ddc78fd2f7848ed2b99d9cd8889e322528d9/src/crate/crash/command.py#L85-L96 |
crate/crash | src/crate/crash/command.py | get_parser | def get_parser(output_formats=[], conf=None):
"""
Create an argument parser that reads default values from a
configuration file if provided.
"""
def _conf_or_default(key, value):
return value if conf is None else conf.get_or_set(key, value)
parser = ArgumentParser(description='crate sh... | python | def get_parser(output_formats=[], conf=None):
"""
Create an argument parser that reads default values from a
configuration file if provided.
"""
def _conf_or_default(key, value):
return value if conf is None else conf.get_or_set(key, value)
parser = ArgumentParser(description='crate sh... | [
"def",
"get_parser",
"(",
"output_formats",
"=",
"[",
"]",
",",
"conf",
"=",
"None",
")",
":",
"def",
"_conf_or_default",
"(",
"key",
",",
"value",
")",
":",
"return",
"value",
"if",
"conf",
"is",
"None",
"else",
"conf",
".",
"get_or_set",
"(",
"key",
... | Create an argument parser that reads default values from a
configuration file if provided. | [
"Create",
"an",
"argument",
"parser",
"that",
"reads",
"default",
"values",
"from",
"a",
"configuration",
"file",
"if",
"provided",
"."
] | train | https://github.com/crate/crash/blob/32d3ddc78fd2f7848ed2b99d9cd8889e322528d9/src/crate/crash/command.py#L121-L178 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.