repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens listlengths 20 707 | docstring stringlengths 3 17.3k | docstring_tokens listlengths 3 222 | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value | idx int64 0 252k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
vbwagner/ctypescrypto | ctypescrypto/pkey.py | PKey.exportpub | def exportpub(self, format="PEM"):
"""
Returns public key as PEM or DER structure.
"""
bio = Membio()
if format == "PEM":
retcode = libcrypto.PEM_write_bio_PUBKEY(bio.bio, self.key)
else:
retcode = libcrypto.i2d_PUBKEY_bio(bio.bio, self.key)
... | python | def exportpub(self, format="PEM"):
"""
Returns public key as PEM or DER structure.
"""
bio = Membio()
if format == "PEM":
retcode = libcrypto.PEM_write_bio_PUBKEY(bio.bio, self.key)
else:
retcode = libcrypto.i2d_PUBKEY_bio(bio.bio, self.key)
... | [
"def",
"exportpub",
"(",
"self",
",",
"format",
"=",
"\"PEM\"",
")",
":",
"bio",
"=",
"Membio",
"(",
")",
"if",
"format",
"==",
"\"PEM\"",
":",
"retcode",
"=",
"libcrypto",
".",
"PEM_write_bio_PUBKEY",
"(",
"bio",
".",
"bio",
",",
"self",
".",
"key",
... | Returns public key as PEM or DER structure. | [
"Returns",
"public",
"key",
"as",
"PEM",
"or",
"DER",
"structure",
"."
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/pkey.py#L307-L318 | train | 59,100 |
vbwagner/ctypescrypto | ctypescrypto/pkey.py | PKey.exportpriv | def exportpriv(self, format="PEM", password=None, cipher=None):
"""
Returns private key as PEM or DER Structure.
If password and cipher are specified, encrypts key
on given password, using given algorithm. Cipher must be
an ctypescrypto.cipher.CipherType object
Password ... | python | def exportpriv(self, format="PEM", password=None, cipher=None):
"""
Returns private key as PEM or DER Structure.
If password and cipher are specified, encrypts key
on given password, using given algorithm. Cipher must be
an ctypescrypto.cipher.CipherType object
Password ... | [
"def",
"exportpriv",
"(",
"self",
",",
"format",
"=",
"\"PEM\"",
",",
"password",
"=",
"None",
",",
"cipher",
"=",
"None",
")",
":",
"bio",
"=",
"Membio",
"(",
")",
"if",
"cipher",
"is",
"None",
":",
"evp_cipher",
"=",
"None",
"else",
":",
"evp_ciphe... | Returns private key as PEM or DER Structure.
If password and cipher are specified, encrypts key
on given password, using given algorithm. Cipher must be
an ctypescrypto.cipher.CipherType object
Password can be either string or function with one argument,
which returns password. ... | [
"Returns",
"private",
"key",
"as",
"PEM",
"or",
"DER",
"Structure",
".",
"If",
"password",
"and",
"cipher",
"are",
"specified",
"encrypts",
"key",
"on",
"given",
"password",
"using",
"given",
"algorithm",
".",
"Cipher",
"must",
"be",
"an",
"ctypescrypto",
".... | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/pkey.py#L320-L352 | train | 59,101 |
vbwagner/ctypescrypto | ctypescrypto/pkey.py | PKey._configure_context | def _configure_context(ctx, opts, skip=()):
"""
Configures context of public key operations
@param ctx - context to configure
@param opts - dictionary of options (from kwargs of calling
function)
@param skip - list of options which shouldn't be passed to
c... | python | def _configure_context(ctx, opts, skip=()):
"""
Configures context of public key operations
@param ctx - context to configure
@param opts - dictionary of options (from kwargs of calling
function)
@param skip - list of options which shouldn't be passed to
c... | [
"def",
"_configure_context",
"(",
"ctx",
",",
"opts",
",",
"skip",
"=",
"(",
")",
")",
":",
"for",
"oper",
"in",
"opts",
":",
"if",
"oper",
"in",
"skip",
":",
"continue",
"if",
"isinstance",
"(",
"oper",
",",
"chartype",
")",
":",
"op",
"=",
"oper"... | Configures context of public key operations
@param ctx - context to configure
@param opts - dictionary of options (from kwargs of calling
function)
@param skip - list of options which shouldn't be passed to
context | [
"Configures",
"context",
"of",
"public",
"key",
"operations"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/pkey.py#L355-L385 | train | 59,102 |
vbwagner/ctypescrypto | ctypescrypto/bio.py | Membio.read | def read(self, length=None):
"""
Reads data from readble BIO. For test purposes.
@param length - if specifed, limits amount of data read.
If not BIO is read until end of buffer
"""
if not length is None:
if not isinstance(length, inttype) :
rai... | python | def read(self, length=None):
"""
Reads data from readble BIO. For test purposes.
@param length - if specifed, limits amount of data read.
If not BIO is read until end of buffer
"""
if not length is None:
if not isinstance(length, inttype) :
rai... | [
"def",
"read",
"(",
"self",
",",
"length",
"=",
"None",
")",
":",
"if",
"not",
"length",
"is",
"None",
":",
"if",
"not",
"isinstance",
"(",
"length",
",",
"inttype",
")",
":",
"raise",
"TypeError",
"(",
"\"length to read should be number\"",
")",
"buf",
... | Reads data from readble BIO. For test purposes.
@param length - if specifed, limits amount of data read.
If not BIO is read until end of buffer | [
"Reads",
"data",
"from",
"readble",
"BIO",
".",
"For",
"test",
"purposes",
"."
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/bio.py#L62-L94 | train | 59,103 |
vbwagner/ctypescrypto | ctypescrypto/bio.py | Membio.write | def write(self, data):
"""
Writes data to writable bio. For test purposes
"""
if pyver == 2:
if isinstance(data, unicode):
data = data.encode("utf-8")
else:
data = str(data)
else:
if not isinstance(data, bytes... | python | def write(self, data):
"""
Writes data to writable bio. For test purposes
"""
if pyver == 2:
if isinstance(data, unicode):
data = data.encode("utf-8")
else:
data = str(data)
else:
if not isinstance(data, bytes... | [
"def",
"write",
"(",
"self",
",",
"data",
")",
":",
"if",
"pyver",
"==",
"2",
":",
"if",
"isinstance",
"(",
"data",
",",
"unicode",
")",
":",
"data",
"=",
"data",
".",
"encode",
"(",
"\"utf-8\"",
")",
"else",
":",
"data",
"=",
"str",
"(",
"data",... | Writes data to writable bio. For test purposes | [
"Writes",
"data",
"to",
"writable",
"bio",
".",
"For",
"test",
"purposes"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/bio.py#L96-L113 | train | 59,104 |
vbwagner/ctypescrypto | ctypescrypto/cms.py | CMS | def CMS(data, format="PEM"):
"""
Factory function to create CMS objects from received messages.
Parses CMS data and returns either SignedData or EnvelopedData
object. format argument can be either "PEM" or "DER".
It determines object type from the contents of received CMS
structure.
""... | python | def CMS(data, format="PEM"):
"""
Factory function to create CMS objects from received messages.
Parses CMS data and returns either SignedData or EnvelopedData
object. format argument can be either "PEM" or "DER".
It determines object type from the contents of received CMS
structure.
""... | [
"def",
"CMS",
"(",
"data",
",",
"format",
"=",
"\"PEM\"",
")",
":",
"bio",
"=",
"Membio",
"(",
"data",
")",
"if",
"format",
"==",
"\"PEM\"",
":",
"ptr",
"=",
"libcrypto",
".",
"PEM_read_bio_CMS",
"(",
"bio",
".",
"bio",
",",
"None",
",",
"None",
",... | Factory function to create CMS objects from received messages.
Parses CMS data and returns either SignedData or EnvelopedData
object. format argument can be either "PEM" or "DER".
It determines object type from the contents of received CMS
structure. | [
"Factory",
"function",
"to",
"create",
"CMS",
"objects",
"from",
"received",
"messages",
".",
"Parses",
"CMS",
"data",
"and",
"returns",
"either",
"SignedData",
"or",
"EnvelopedData",
"object",
".",
"format",
"argument",
"can",
"be",
"either",
"PEM",
"or",
"DE... | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/cms.py#L58-L83 | train | 59,105 |
vbwagner/ctypescrypto | ctypescrypto/cms.py | CMSBase.pem | def pem(self):
"""
Serialize in PEM format
"""
bio = Membio()
if not libcrypto.PEM_write_bio_CMS(bio.bio, self.ptr):
raise CMSError("writing CMS to PEM")
return str(bio) | python | def pem(self):
"""
Serialize in PEM format
"""
bio = Membio()
if not libcrypto.PEM_write_bio_CMS(bio.bio, self.ptr):
raise CMSError("writing CMS to PEM")
return str(bio) | [
"def",
"pem",
"(",
"self",
")",
":",
"bio",
"=",
"Membio",
"(",
")",
"if",
"not",
"libcrypto",
".",
"PEM_write_bio_CMS",
"(",
"bio",
".",
"bio",
",",
"self",
".",
"ptr",
")",
":",
"raise",
"CMSError",
"(",
"\"writing CMS to PEM\"",
")",
"return",
"str"... | Serialize in PEM format | [
"Serialize",
"in",
"PEM",
"format"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/cms.py#L107-L114 | train | 59,106 |
vbwagner/ctypescrypto | ctypescrypto/cms.py | SignedData.create | def create(data, cert, pkey, flags=Flags.BINARY, certs=None):
"""
Creates SignedData message by signing data with pkey and
certificate.
@param data - data to sign
@param cert - signer's certificate
@param pkey - pkey object with private key to sign
... | python | def create(data, cert, pkey, flags=Flags.BINARY, certs=None):
"""
Creates SignedData message by signing data with pkey and
certificate.
@param data - data to sign
@param cert - signer's certificate
@param pkey - pkey object with private key to sign
... | [
"def",
"create",
"(",
"data",
",",
"cert",
",",
"pkey",
",",
"flags",
"=",
"Flags",
".",
"BINARY",
",",
"certs",
"=",
"None",
")",
":",
"if",
"not",
"pkey",
".",
"cansign",
":",
"raise",
"ValueError",
"(",
"\"Specified keypair has no private part\"",
")",
... | Creates SignedData message by signing data with pkey and
certificate.
@param data - data to sign
@param cert - signer's certificate
@param pkey - pkey object with private key to sign
@param flags - OReed combination of Flags constants
@param certs... | [
"Creates",
"SignedData",
"message",
"by",
"signing",
"data",
"with",
"pkey",
"and",
"certificate",
"."
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/cms.py#L131-L155 | train | 59,107 |
vbwagner/ctypescrypto | ctypescrypto/cms.py | SignedData.sign | def sign(self, cert, pkey, digest_type=None, data=None, flags=Flags.BINARY):
"""
Adds another signer to already signed message
@param cert - signer's certificate
@param pkey - signer's private key
@param digest_type - message digest to use as DigestType object
... | python | def sign(self, cert, pkey, digest_type=None, data=None, flags=Flags.BINARY):
"""
Adds another signer to already signed message
@param cert - signer's certificate
@param pkey - signer's private key
@param digest_type - message digest to use as DigestType object
... | [
"def",
"sign",
"(",
"self",
",",
"cert",
",",
"pkey",
",",
"digest_type",
"=",
"None",
",",
"data",
"=",
"None",
",",
"flags",
"=",
"Flags",
".",
"BINARY",
")",
":",
"if",
"not",
"pkey",
".",
"cansign",
":",
"raise",
"ValueError",
"(",
"\"Specified k... | Adds another signer to already signed message
@param cert - signer's certificate
@param pkey - signer's private key
@param digest_type - message digest to use as DigestType object
(if None - default for key would be used)
@param data - data to sign (if det... | [
"Adds",
"another",
"signer",
"to",
"already",
"signed",
"message"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/cms.py#L156-L182 | train | 59,108 |
vbwagner/ctypescrypto | ctypescrypto/cms.py | SignedData.verify | def verify(self, store, flags, data=None, certs=None):
"""
Verifies signature under CMS message using trusted cert store
@param store - X509Store object with trusted certs
@param flags - OR-ed combination of flag consants
@param data - message data, if messge has detached signa... | python | def verify(self, store, flags, data=None, certs=None):
"""
Verifies signature under CMS message using trusted cert store
@param store - X509Store object with trusted certs
@param flags - OR-ed combination of flag consants
@param data - message data, if messge has detached signa... | [
"def",
"verify",
"(",
"self",
",",
"store",
",",
"flags",
",",
"data",
"=",
"None",
",",
"certs",
"=",
"None",
")",
":",
"bio",
"=",
"None",
"if",
"data",
"!=",
"None",
":",
"bio_obj",
"=",
"Membio",
"(",
"data",
")",
"bio",
"=",
"bio_obj",
".",
... | Verifies signature under CMS message using trusted cert store
@param store - X509Store object with trusted certs
@param flags - OR-ed combination of flag consants
@param data - message data, if messge has detached signature
param certs - list of certificates to use during verification
... | [
"Verifies",
"signature",
"under",
"CMS",
"message",
"using",
"trusted",
"cert",
"store"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/cms.py#L183-L206 | train | 59,109 |
vbwagner/ctypescrypto | ctypescrypto/cms.py | SignedData.signers | def signers(self):
"""
Return list of signer's certificates
"""
signerlist = libcrypto.CMS_get0_signers(self.ptr)
if signerlist is None:
raise CMSError("Cannot get signers")
return StackOfX509(ptr=signerlist, disposable=False) | python | def signers(self):
"""
Return list of signer's certificates
"""
signerlist = libcrypto.CMS_get0_signers(self.ptr)
if signerlist is None:
raise CMSError("Cannot get signers")
return StackOfX509(ptr=signerlist, disposable=False) | [
"def",
"signers",
"(",
"self",
")",
":",
"signerlist",
"=",
"libcrypto",
".",
"CMS_get0_signers",
"(",
"self",
".",
"ptr",
")",
"if",
"signerlist",
"is",
"None",
":",
"raise",
"CMSError",
"(",
"\"Cannot get signers\"",
")",
"return",
"StackOfX509",
"(",
"ptr... | Return list of signer's certificates | [
"Return",
"list",
"of",
"signer",
"s",
"certificates"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/cms.py#L209-L216 | train | 59,110 |
vbwagner/ctypescrypto | ctypescrypto/cms.py | SignedData.data | def data(self):
"""
Returns signed data if present in the message
"""
# Check if signatire is detached
if self.detached:
return None
bio = Membio()
if not libcrypto.CMS_verify(self.ptr, None, None, None, bio.bio,
Fla... | python | def data(self):
"""
Returns signed data if present in the message
"""
# Check if signatire is detached
if self.detached:
return None
bio = Membio()
if not libcrypto.CMS_verify(self.ptr, None, None, None, bio.bio,
Fla... | [
"def",
"data",
"(",
"self",
")",
":",
"# Check if signatire is detached",
"if",
"self",
".",
"detached",
":",
"return",
"None",
"bio",
"=",
"Membio",
"(",
")",
"if",
"not",
"libcrypto",
".",
"CMS_verify",
"(",
"self",
".",
"ptr",
",",
"None",
",",
"None"... | Returns signed data if present in the message | [
"Returns",
"signed",
"data",
"if",
"present",
"in",
"the",
"message"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/cms.py#L226-L237 | train | 59,111 |
vbwagner/ctypescrypto | ctypescrypto/cms.py | SignedData.certs | def certs(self):
"""
List of the certificates contained in the structure
"""
certstack = libcrypto.CMS_get1_certs(self.ptr)
if certstack is None:
raise CMSError("getting certs")
return StackOfX509(ptr=certstack, disposable=True) | python | def certs(self):
"""
List of the certificates contained in the structure
"""
certstack = libcrypto.CMS_get1_certs(self.ptr)
if certstack is None:
raise CMSError("getting certs")
return StackOfX509(ptr=certstack, disposable=True) | [
"def",
"certs",
"(",
"self",
")",
":",
"certstack",
"=",
"libcrypto",
".",
"CMS_get1_certs",
"(",
"self",
".",
"ptr",
")",
"if",
"certstack",
"is",
"None",
":",
"raise",
"CMSError",
"(",
"\"getting certs\"",
")",
"return",
"StackOfX509",
"(",
"ptr",
"=",
... | List of the certificates contained in the structure | [
"List",
"of",
"the",
"certificates",
"contained",
"in",
"the",
"structure"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/cms.py#L252-L259 | train | 59,112 |
vbwagner/ctypescrypto | ctypescrypto/cms.py | EnvelopedData.create | def create(recipients, data, cipher, flags=0):
"""
Creates and encrypts message
@param recipients - list of X509 objects
@param data - contents of the message
@param cipher - CipherType object
@param flags - flag
"""
recp = StackOfX509(recipients)
... | python | def create(recipients, data, cipher, flags=0):
"""
Creates and encrypts message
@param recipients - list of X509 objects
@param data - contents of the message
@param cipher - CipherType object
@param flags - flag
"""
recp = StackOfX509(recipients)
... | [
"def",
"create",
"(",
"recipients",
",",
"data",
",",
"cipher",
",",
"flags",
"=",
"0",
")",
":",
"recp",
"=",
"StackOfX509",
"(",
"recipients",
")",
"bio",
"=",
"Membio",
"(",
"data",
")",
"cms_ptr",
"=",
"libcrypto",
".",
"CMS_encrypt",
"(",
"recp",
... | Creates and encrypts message
@param recipients - list of X509 objects
@param data - contents of the message
@param cipher - CipherType object
@param flags - flag | [
"Creates",
"and",
"encrypts",
"message"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/cms.py#L281-L295 | train | 59,113 |
vbwagner/ctypescrypto | ctypescrypto/cms.py | EncryptedData.create | def create(data, cipher, key, flags=0):
"""
Creates an EncryptedData message.
@param data data to encrypt
@param cipher cipher.CipherType object represening required
cipher type
@param key - byte array used as simmetic key
@param flags - OR-ed combination ... | python | def create(data, cipher, key, flags=0):
"""
Creates an EncryptedData message.
@param data data to encrypt
@param cipher cipher.CipherType object represening required
cipher type
@param key - byte array used as simmetic key
@param flags - OR-ed combination ... | [
"def",
"create",
"(",
"data",
",",
"cipher",
",",
"key",
",",
"flags",
"=",
"0",
")",
":",
"bio",
"=",
"Membio",
"(",
"data",
")",
"ptr",
"=",
"libcrypto",
".",
"CMS_EncryptedData_encrypt",
"(",
"bio",
".",
"bio",
",",
"cipher",
".",
"cipher",
",",
... | Creates an EncryptedData message.
@param data data to encrypt
@param cipher cipher.CipherType object represening required
cipher type
@param key - byte array used as simmetic key
@param flags - OR-ed combination of Flags constant | [
"Creates",
"an",
"EncryptedData",
"message",
"."
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/cms.py#L323-L337 | train | 59,114 |
vbwagner/ctypescrypto | ctypescrypto/cms.py | EncryptedData.decrypt | def decrypt(self, key, flags=0):
"""
Decrypts encrypted data message
@param key - symmetic key to decrypt
@param flags - OR-ed combination of Flags constant
"""
bio = Membio()
if libcrypto.CMS_EncryptedData_decrypt(self.ptr, key, len(key), None,
... | python | def decrypt(self, key, flags=0):
"""
Decrypts encrypted data message
@param key - symmetic key to decrypt
@param flags - OR-ed combination of Flags constant
"""
bio = Membio()
if libcrypto.CMS_EncryptedData_decrypt(self.ptr, key, len(key), None,
... | [
"def",
"decrypt",
"(",
"self",
",",
"key",
",",
"flags",
"=",
"0",
")",
":",
"bio",
"=",
"Membio",
"(",
")",
"if",
"libcrypto",
".",
"CMS_EncryptedData_decrypt",
"(",
"self",
".",
"ptr",
",",
"key",
",",
"len",
"(",
"key",
")",
",",
"None",
",",
... | Decrypts encrypted data message
@param key - symmetic key to decrypt
@param flags - OR-ed combination of Flags constant | [
"Decrypts",
"encrypted",
"data",
"message"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/cms.py#L339-L349 | train | 59,115 |
vbwagner/ctypescrypto | ctypescrypto/digest.py | DigestType.name | def name(self):
""" Returns name of the digest """
if not hasattr(self, 'digest_name'):
self.digest_name = Oid(libcrypto.EVP_MD_type(self.digest)
).longname()
return self.digest_name | python | def name(self):
""" Returns name of the digest """
if not hasattr(self, 'digest_name'):
self.digest_name = Oid(libcrypto.EVP_MD_type(self.digest)
).longname()
return self.digest_name | [
"def",
"name",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'digest_name'",
")",
":",
"self",
".",
"digest_name",
"=",
"Oid",
"(",
"libcrypto",
".",
"EVP_MD_type",
"(",
"self",
".",
"digest",
")",
")",
".",
"longname",
"(",
")",
... | Returns name of the digest | [
"Returns",
"name",
"of",
"the",
"digest"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/digest.py#L64-L69 | train | 59,116 |
vbwagner/ctypescrypto | ctypescrypto/digest.py | Digest.update | def update(self, data, length=None):
"""
Hashes given byte string
@param data - string to hash
@param length - if not specifed, entire string is hashed,
otherwise only first length bytes
"""
if self.digest_finalized:
raise DigestError("No upda... | python | def update(self, data, length=None):
"""
Hashes given byte string
@param data - string to hash
@param length - if not specifed, entire string is hashed,
otherwise only first length bytes
"""
if self.digest_finalized:
raise DigestError("No upda... | [
"def",
"update",
"(",
"self",
",",
"data",
",",
"length",
"=",
"None",
")",
":",
"if",
"self",
".",
"digest_finalized",
":",
"raise",
"DigestError",
"(",
"\"No updates allowed\"",
")",
"if",
"not",
"isinstance",
"(",
"data",
",",
"bintype",
")",
":",
"ra... | Hashes given byte string
@param data - string to hash
@param length - if not specifed, entire string is hashed,
otherwise only first length bytes | [
"Hashes",
"given",
"byte",
"string"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/digest.py#L117-L135 | train | 59,117 |
vbwagner/ctypescrypto | ctypescrypto/digest.py | Digest.digest | def digest(self, data=None):
"""
Finalizes digest operation and return digest value
Optionally hashes more data before finalizing
"""
if self.digest_finalized:
return self.digest_out.raw[:self.digest_size]
if data is not None:
self.update(data)
... | python | def digest(self, data=None):
"""
Finalizes digest operation and return digest value
Optionally hashes more data before finalizing
"""
if self.digest_finalized:
return self.digest_out.raw[:self.digest_size]
if data is not None:
self.update(data)
... | [
"def",
"digest",
"(",
"self",
",",
"data",
"=",
"None",
")",
":",
"if",
"self",
".",
"digest_finalized",
":",
"return",
"self",
".",
"digest_out",
".",
"raw",
"[",
":",
"self",
".",
"digest_size",
"]",
"if",
"data",
"is",
"not",
"None",
":",
"self",
... | Finalizes digest operation and return digest value
Optionally hashes more data before finalizing | [
"Finalizes",
"digest",
"operation",
"and",
"return",
"digest",
"value",
"Optionally",
"hashes",
"more",
"data",
"before",
"finalizing"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/digest.py#L137-L153 | train | 59,118 |
vbwagner/ctypescrypto | ctypescrypto/digest.py | Digest.copy | def copy(self):
"""
Creates copy of the digest CTX to allow to compute digest
while being able to hash more data
"""
new_digest = Digest(self.digest_type)
libcrypto.EVP_MD_CTX_copy(new_digest.ctx, self.ctx)
return new_digest | python | def copy(self):
"""
Creates copy of the digest CTX to allow to compute digest
while being able to hash more data
"""
new_digest = Digest(self.digest_type)
libcrypto.EVP_MD_CTX_copy(new_digest.ctx, self.ctx)
return new_digest | [
"def",
"copy",
"(",
"self",
")",
":",
"new_digest",
"=",
"Digest",
"(",
"self",
".",
"digest_type",
")",
"libcrypto",
".",
"EVP_MD_CTX_copy",
"(",
"new_digest",
".",
"ctx",
",",
"self",
".",
"ctx",
")",
"return",
"new_digest"
] | Creates copy of the digest CTX to allow to compute digest
while being able to hash more data | [
"Creates",
"copy",
"of",
"the",
"digest",
"CTX",
"to",
"allow",
"to",
"compute",
"digest",
"while",
"being",
"able",
"to",
"hash",
"more",
"data"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/digest.py#L154-L162 | train | 59,119 |
vbwagner/ctypescrypto | ctypescrypto/digest.py | Digest._clean_ctx | def _clean_ctx(self):
"""
Clears and deallocates context
"""
try:
if self.ctx is not None:
libcrypto.EVP_MD_CTX_free(self.ctx)
del self.ctx
except AttributeError:
pass
self.digest_out = None
self.digest_final... | python | def _clean_ctx(self):
"""
Clears and deallocates context
"""
try:
if self.ctx is not None:
libcrypto.EVP_MD_CTX_free(self.ctx)
del self.ctx
except AttributeError:
pass
self.digest_out = None
self.digest_final... | [
"def",
"_clean_ctx",
"(",
"self",
")",
":",
"try",
":",
"if",
"self",
".",
"ctx",
"is",
"not",
"None",
":",
"libcrypto",
".",
"EVP_MD_CTX_free",
"(",
"self",
".",
"ctx",
")",
"del",
"self",
".",
"ctx",
"except",
"AttributeError",
":",
"pass",
"self",
... | Clears and deallocates context | [
"Clears",
"and",
"deallocates",
"context"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/digest.py#L164-L175 | train | 59,120 |
vbwagner/ctypescrypto | ctypescrypto/digest.py | Digest.hexdigest | def hexdigest(self, data=None):
"""
Returns digest in the hexadecimal form. For compatibility
with hashlib
"""
from base64 import b16encode
if pyver == 2:
return b16encode(self.digest(data))
else:
return b16encode(self.digest(data))... | python | def hexdigest(self, data=None):
"""
Returns digest in the hexadecimal form. For compatibility
with hashlib
"""
from base64 import b16encode
if pyver == 2:
return b16encode(self.digest(data))
else:
return b16encode(self.digest(data))... | [
"def",
"hexdigest",
"(",
"self",
",",
"data",
"=",
"None",
")",
":",
"from",
"base64",
"import",
"b16encode",
"if",
"pyver",
"==",
"2",
":",
"return",
"b16encode",
"(",
"self",
".",
"digest",
"(",
"data",
")",
")",
"else",
":",
"return",
"b16encode",
... | Returns digest in the hexadecimal form. For compatibility
with hashlib | [
"Returns",
"digest",
"in",
"the",
"hexadecimal",
"form",
".",
"For",
"compatibility",
"with",
"hashlib"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/digest.py#L177-L186 | train | 59,121 |
vbwagner/ctypescrypto | ctypescrypto/x509.py | _X509__asn1date_to_datetime | def _X509__asn1date_to_datetime(asn1date):
"""
Converts openssl ASN1_TIME object to python datetime.datetime
"""
bio = Membio()
libcrypto.ASN1_TIME_print(bio.bio, asn1date)
pydate = datetime.strptime(str(bio), "%b %d %H:%M:%S %Y %Z")
return pydate.replace(tzinfo=utc) | python | def _X509__asn1date_to_datetime(asn1date):
"""
Converts openssl ASN1_TIME object to python datetime.datetime
"""
bio = Membio()
libcrypto.ASN1_TIME_print(bio.bio, asn1date)
pydate = datetime.strptime(str(bio), "%b %d %H:%M:%S %Y %Z")
return pydate.replace(tzinfo=utc) | [
"def",
"_X509__asn1date_to_datetime",
"(",
"asn1date",
")",
":",
"bio",
"=",
"Membio",
"(",
")",
"libcrypto",
".",
"ASN1_TIME_print",
"(",
"bio",
".",
"bio",
",",
"asn1date",
")",
"pydate",
"=",
"datetime",
".",
"strptime",
"(",
"str",
"(",
"bio",
")",
"... | Converts openssl ASN1_TIME object to python datetime.datetime | [
"Converts",
"openssl",
"ASN1_TIME",
"object",
"to",
"python",
"datetime",
".",
"datetime"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/x509.py#L344-L351 | train | 59,122 |
vbwagner/ctypescrypto | ctypescrypto/x509.py | _X509extlist.find | def find(self, oid):
"""
Return list of extensions with given Oid
"""
if not isinstance(oid, Oid):
raise TypeError("Need crytypescrypto.oid.Oid as argument")
found = []
index = -1
end = len(self)
while True:
index = libcrypto.X509_g... | python | def find(self, oid):
"""
Return list of extensions with given Oid
"""
if not isinstance(oid, Oid):
raise TypeError("Need crytypescrypto.oid.Oid as argument")
found = []
index = -1
end = len(self)
while True:
index = libcrypto.X509_g... | [
"def",
"find",
"(",
"self",
",",
"oid",
")",
":",
"if",
"not",
"isinstance",
"(",
"oid",
",",
"Oid",
")",
":",
"raise",
"TypeError",
"(",
"\"Need crytypescrypto.oid.Oid as argument\"",
")",
"found",
"=",
"[",
"]",
"index",
"=",
"-",
"1",
"end",
"=",
"l... | Return list of extensions with given Oid | [
"Return",
"list",
"of",
"extensions",
"with",
"given",
"Oid"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/x509.py#L307-L322 | train | 59,123 |
vbwagner/ctypescrypto | ctypescrypto/x509.py | _X509extlist.find_critical | def find_critical(self, crit=True):
"""
Return list of critical extensions (or list of non-cricital, if
optional second argument is False
"""
if crit:
flag = 1
else:
flag = 0
found = []
end = len(self)
index = -1
whi... | python | def find_critical(self, crit=True):
"""
Return list of critical extensions (or list of non-cricital, if
optional second argument is False
"""
if crit:
flag = 1
else:
flag = 0
found = []
end = len(self)
index = -1
whi... | [
"def",
"find_critical",
"(",
"self",
",",
"crit",
"=",
"True",
")",
":",
"if",
"crit",
":",
"flag",
"=",
"1",
"else",
":",
"flag",
"=",
"0",
"found",
"=",
"[",
"]",
"end",
"=",
"len",
"(",
"self",
")",
"index",
"=",
"-",
"1",
"while",
"True",
... | Return list of critical extensions (or list of non-cricital, if
optional second argument is False | [
"Return",
"list",
"of",
"critical",
"extensions",
"(",
"or",
"list",
"of",
"non",
"-",
"cricital",
"if",
"optional",
"second",
"argument",
"is",
"False"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/x509.py#L324-L342 | train | 59,124 |
vbwagner/ctypescrypto | ctypescrypto/x509.py | X509.pem | def pem(self):
""" Returns PEM represntation of the certificate """
bio = Membio()
if libcrypto.PEM_write_bio_X509(bio.bio, self.cert) == 0:
raise X509Error("error serializing certificate")
return str(bio) | python | def pem(self):
""" Returns PEM represntation of the certificate """
bio = Membio()
if libcrypto.PEM_write_bio_X509(bio.bio, self.cert) == 0:
raise X509Error("error serializing certificate")
return str(bio) | [
"def",
"pem",
"(",
"self",
")",
":",
"bio",
"=",
"Membio",
"(",
")",
"if",
"libcrypto",
".",
"PEM_write_bio_X509",
"(",
"bio",
".",
"bio",
",",
"self",
".",
"cert",
")",
"==",
"0",
":",
"raise",
"X509Error",
"(",
"\"error serializing certificate\"",
")",... | Returns PEM represntation of the certificate | [
"Returns",
"PEM",
"represntation",
"of",
"the",
"certificate"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/x509.py#L401-L406 | train | 59,125 |
vbwagner/ctypescrypto | ctypescrypto/x509.py | X509.serial | def serial(self):
""" Serial number of certificate as integer """
asnint = libcrypto.X509_get_serialNumber(self.cert)
bio = Membio()
libcrypto.i2a_ASN1_INTEGER(bio.bio, asnint)
return int(str(bio), 16) | python | def serial(self):
""" Serial number of certificate as integer """
asnint = libcrypto.X509_get_serialNumber(self.cert)
bio = Membio()
libcrypto.i2a_ASN1_INTEGER(bio.bio, asnint)
return int(str(bio), 16) | [
"def",
"serial",
"(",
"self",
")",
":",
"asnint",
"=",
"libcrypto",
".",
"X509_get_serialNumber",
"(",
"self",
".",
"cert",
")",
"bio",
"=",
"Membio",
"(",
")",
"libcrypto",
".",
"i2a_ASN1_INTEGER",
"(",
"bio",
".",
"bio",
",",
"asnint",
")",
"return",
... | Serial number of certificate as integer | [
"Serial",
"number",
"of",
"certificate",
"as",
"integer"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/x509.py#L456-L461 | train | 59,126 |
vbwagner/ctypescrypto | ctypescrypto/x509.py | X509Store.add_cert | def add_cert(self, cert):
"""
Explicitely adds certificate to set of trusted in the store
@param cert - X509 object to add
"""
if not isinstance(cert, X509):
raise TypeError("cert should be X509")
libcrypto.X509_STORE_add_cert(self.store, cert.cert) | python | def add_cert(self, cert):
"""
Explicitely adds certificate to set of trusted in the store
@param cert - X509 object to add
"""
if not isinstance(cert, X509):
raise TypeError("cert should be X509")
libcrypto.X509_STORE_add_cert(self.store, cert.cert) | [
"def",
"add_cert",
"(",
"self",
",",
"cert",
")",
":",
"if",
"not",
"isinstance",
"(",
"cert",
",",
"X509",
")",
":",
"raise",
"TypeError",
"(",
"\"cert should be X509\"",
")",
"libcrypto",
".",
"X509_STORE_add_cert",
"(",
"self",
".",
"store",
",",
"cert"... | Explicitely adds certificate to set of trusted in the store
@param cert - X509 object to add | [
"Explicitely",
"adds",
"certificate",
"to",
"set",
"of",
"trusted",
"in",
"the",
"store"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/x509.py#L531-L538 | train | 59,127 |
vbwagner/ctypescrypto | ctypescrypto/x509.py | X509Store.setpurpose | def setpurpose(self, purpose):
"""
Sets certificate purpose which verified certificate should match
@param purpose - number from 1 to 9 or standard strind defined
in Openssl
possible strings - sslcient,sslserver, nssslserver, smimesign,i
... | python | def setpurpose(self, purpose):
"""
Sets certificate purpose which verified certificate should match
@param purpose - number from 1 to 9 or standard strind defined
in Openssl
possible strings - sslcient,sslserver, nssslserver, smimesign,i
... | [
"def",
"setpurpose",
"(",
"self",
",",
"purpose",
")",
":",
"if",
"isinstance",
"(",
"purpose",
",",
"str",
")",
":",
"purp_no",
"=",
"libcrypto",
".",
"X509_PURPOSE_get_by_sname",
"(",
"purpose",
")",
"if",
"purp_no",
"<=",
"0",
":",
"raise",
"X509Error",... | Sets certificate purpose which verified certificate should match
@param purpose - number from 1 to 9 or standard strind defined
in Openssl
possible strings - sslcient,sslserver, nssslserver, smimesign,i
smimeencrypt, crlsign, any, ocsphelper | [
"Sets",
"certificate",
"purpose",
"which",
"verified",
"certificate",
"should",
"match"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/x509.py#L551-L566 | train | 59,128 |
vbwagner/ctypescrypto | ctypescrypto/x509.py | X509Store.settime | def settime(self, time):
"""
Set point in time used to check validity of certificates for
Time can be either python datetime object or number of seconds
sinse epoch
"""
if isinstance(time, datetime) or isinstance(time,
... | python | def settime(self, time):
"""
Set point in time used to check validity of certificates for
Time can be either python datetime object or number of seconds
sinse epoch
"""
if isinstance(time, datetime) or isinstance(time,
... | [
"def",
"settime",
"(",
"self",
",",
"time",
")",
":",
"if",
"isinstance",
"(",
"time",
",",
"datetime",
")",
"or",
"isinstance",
"(",
"time",
",",
"datetime",
".",
"date",
")",
":",
"seconds",
"=",
"int",
"(",
"time",
".",
"strftime",
"(",
"\"%s\"",
... | Set point in time used to check validity of certificates for
Time can be either python datetime object or number of seconds
sinse epoch | [
"Set",
"point",
"in",
"time",
"used",
"to",
"check",
"validity",
"of",
"certificates",
"for",
"Time",
"can",
"be",
"either",
"python",
"datetime",
"object",
"or",
"number",
"of",
"seconds",
"sinse",
"epoch"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/x509.py#L573-L587 | train | 59,129 |
vbwagner/ctypescrypto | ctypescrypto/x509.py | StackOfX509.append | def append(self, value):
""" Adds certificate to stack """
if not self.need_free:
raise ValueError("Stack is read-only")
if not isinstance(value, X509):
raise TypeError('StackOfX509 can contain only X509 objects')
sk_push(self.ptr, libcrypto.X509_dup(value.cert)) | python | def append(self, value):
""" Adds certificate to stack """
if not self.need_free:
raise ValueError("Stack is read-only")
if not isinstance(value, X509):
raise TypeError('StackOfX509 can contain only X509 objects')
sk_push(self.ptr, libcrypto.X509_dup(value.cert)) | [
"def",
"append",
"(",
"self",
",",
"value",
")",
":",
"if",
"not",
"self",
".",
"need_free",
":",
"raise",
"ValueError",
"(",
"\"Stack is read-only\"",
")",
"if",
"not",
"isinstance",
"(",
"value",
",",
"X509",
")",
":",
"raise",
"TypeError",
"(",
"'Stac... | Adds certificate to stack | [
"Adds",
"certificate",
"to",
"stack"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/x509.py#L644-L650 | train | 59,130 |
vbwagner/ctypescrypto | ctypescrypto/ec.py | create | def create(curve, data):
"""
Creates EC keypair from the just secret key and curve name
@param curve - name of elliptic curve
@param num - byte array or long number representing key
"""
ec_key = libcrypto.EC_KEY_new_by_curve_name(curve.nid)
if ec_key is None:
raise PKeyError("EC_KEY... | python | def create(curve, data):
"""
Creates EC keypair from the just secret key and curve name
@param curve - name of elliptic curve
@param num - byte array or long number representing key
"""
ec_key = libcrypto.EC_KEY_new_by_curve_name(curve.nid)
if ec_key is None:
raise PKeyError("EC_KEY... | [
"def",
"create",
"(",
"curve",
",",
"data",
")",
":",
"ec_key",
"=",
"libcrypto",
".",
"EC_KEY_new_by_curve_name",
"(",
"curve",
".",
"nid",
")",
"if",
"ec_key",
"is",
"None",
":",
"raise",
"PKeyError",
"(",
"\"EC_KEY_new_by_curvename\"",
")",
"group",
"=",
... | Creates EC keypair from the just secret key and curve name
@param curve - name of elliptic curve
@param num - byte array or long number representing key | [
"Creates",
"EC",
"keypair",
"from",
"the",
"just",
"secret",
"key",
"and",
"curve",
"name"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/ec.py#L10-L64 | train | 59,131 |
vbwagner/ctypescrypto | ctypescrypto/cipher.py | new | def new(algname, key, encrypt=True, iv=None):
"""
Returns new cipher object ready to encrypt-decrypt data
@param algname - string algorithm name like in opemssl command
line
@param key - binary string representing ciher key
@param encrypt - if True (default) cipher would be ini... | python | def new(algname, key, encrypt=True, iv=None):
"""
Returns new cipher object ready to encrypt-decrypt data
@param algname - string algorithm name like in opemssl command
line
@param key - binary string representing ciher key
@param encrypt - if True (default) cipher would be ini... | [
"def",
"new",
"(",
"algname",
",",
"key",
",",
"encrypt",
"=",
"True",
",",
"iv",
"=",
"None",
")",
":",
"ciph_type",
"=",
"CipherType",
"(",
"algname",
")",
"return",
"Cipher",
"(",
"ciph_type",
",",
"key",
",",
"iv",
",",
"encrypt",
")"
] | Returns new cipher object ready to encrypt-decrypt data
@param algname - string algorithm name like in opemssl command
line
@param key - binary string representing ciher key
@param encrypt - if True (default) cipher would be initialized
for encryption, otherwise - f... | [
"Returns",
"new",
"cipher",
"object",
"ready",
"to",
"encrypt",
"-",
"decrypt",
"data"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/cipher.py#L24-L36 | train | 59,132 |
vbwagner/ctypescrypto | ctypescrypto/cipher.py | Cipher.padding | def padding(self, padding=True):
"""
Sets padding mode of the cipher
"""
padding_flag = 1 if padding else 0
libcrypto.EVP_CIPHER_CTX_set_padding(self.ctx, padding_flag) | python | def padding(self, padding=True):
"""
Sets padding mode of the cipher
"""
padding_flag = 1 if padding else 0
libcrypto.EVP_CIPHER_CTX_set_padding(self.ctx, padding_flag) | [
"def",
"padding",
"(",
"self",
",",
"padding",
"=",
"True",
")",
":",
"padding_flag",
"=",
"1",
"if",
"padding",
"else",
"0",
"libcrypto",
".",
"EVP_CIPHER_CTX_set_padding",
"(",
"self",
".",
"ctx",
",",
"padding_flag",
")"
] | Sets padding mode of the cipher | [
"Sets",
"padding",
"mode",
"of",
"the",
"cipher"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/cipher.py#L174-L179 | train | 59,133 |
vbwagner/ctypescrypto | ctypescrypto/cipher.py | Cipher.finish | def finish(self):
"""
Finalizes processing. If some data are kept in the internal
state, they would be processed and returned.
"""
if self.cipher_finalized:
raise CipherError("Cipher operation is already completed")
outbuf = create_string_buffer(self.block_siz... | python | def finish(self):
"""
Finalizes processing. If some data are kept in the internal
state, they would be processed and returned.
"""
if self.cipher_finalized:
raise CipherError("Cipher operation is already completed")
outbuf = create_string_buffer(self.block_siz... | [
"def",
"finish",
"(",
"self",
")",
":",
"if",
"self",
".",
"cipher_finalized",
":",
"raise",
"CipherError",
"(",
"\"Cipher operation is already completed\"",
")",
"outbuf",
"=",
"create_string_buffer",
"(",
"self",
".",
"block_size",
")",
"self",
".",
"cipher_fina... | Finalizes processing. If some data are kept in the internal
state, they would be processed and returned. | [
"Finalizes",
"processing",
".",
"If",
"some",
"data",
"are",
"kept",
"in",
"the",
"internal",
"state",
"they",
"would",
"be",
"processed",
"and",
"returned",
"."
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/cipher.py#L209-L226 | train | 59,134 |
vbwagner/ctypescrypto | ctypescrypto/cipher.py | Cipher._clean_ctx | def _clean_ctx(self):
"""
Cleans up cipher ctx and deallocates it
"""
try:
if self.ctx is not None:
self.__ctxcleanup(self.ctx)
libcrypto.EVP_CIPHER_CTX_free(self.ctx)
del self.ctx
except AttributeError:
pass... | python | def _clean_ctx(self):
"""
Cleans up cipher ctx and deallocates it
"""
try:
if self.ctx is not None:
self.__ctxcleanup(self.ctx)
libcrypto.EVP_CIPHER_CTX_free(self.ctx)
del self.ctx
except AttributeError:
pass... | [
"def",
"_clean_ctx",
"(",
"self",
")",
":",
"try",
":",
"if",
"self",
".",
"ctx",
"is",
"not",
"None",
":",
"self",
".",
"__ctxcleanup",
"(",
"self",
".",
"ctx",
")",
"libcrypto",
".",
"EVP_CIPHER_CTX_free",
"(",
"self",
".",
"ctx",
")",
"del",
"self... | Cleans up cipher ctx and deallocates it | [
"Cleans",
"up",
"cipher",
"ctx",
"and",
"deallocates",
"it"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/cipher.py#L228-L239 | train | 59,135 |
vbwagner/ctypescrypto | ctypescrypto/engine.py | set_default | def set_default(eng, algorithms=0xFFFF):
"""
Sets specified engine as default for all
algorithms, supported by it
For compatibility with 0.2.x if string is passed instead
of engine, attempts to load engine with this id
"""
if not isinstance(eng,Engine):
eng=Engine(eng)
global d... | python | def set_default(eng, algorithms=0xFFFF):
"""
Sets specified engine as default for all
algorithms, supported by it
For compatibility with 0.2.x if string is passed instead
of engine, attempts to load engine with this id
"""
if not isinstance(eng,Engine):
eng=Engine(eng)
global d... | [
"def",
"set_default",
"(",
"eng",
",",
"algorithms",
"=",
"0xFFFF",
")",
":",
"if",
"not",
"isinstance",
"(",
"eng",
",",
"Engine",
")",
":",
"eng",
"=",
"Engine",
"(",
"eng",
")",
"global",
"default",
"libcrypto",
".",
"ENGINE_set_default",
"(",
"eng",
... | Sets specified engine as default for all
algorithms, supported by it
For compatibility with 0.2.x if string is passed instead
of engine, attempts to load engine with this id | [
"Sets",
"specified",
"engine",
"as",
"default",
"for",
"all",
"algorithms",
"supported",
"by",
"it"
] | 33c32904cf5e04901f87f90e2499634b8feecd3e | https://github.com/vbwagner/ctypescrypto/blob/33c32904cf5e04901f87f90e2499634b8feecd3e/ctypescrypto/engine.py#L53-L65 | train | 59,136 |
haaksmash/pyutils | utils/dicts/helpers.py | from_keyed_iterable | def from_keyed_iterable(iterable, key, filter_func=None):
"""Construct a dictionary out of an iterable, using an attribute name as
the key. Optionally provide a filter function, to determine what should be
kept in the dictionary."""
generated = {}
for element in iterable:
try:
... | python | def from_keyed_iterable(iterable, key, filter_func=None):
"""Construct a dictionary out of an iterable, using an attribute name as
the key. Optionally provide a filter function, to determine what should be
kept in the dictionary."""
generated = {}
for element in iterable:
try:
... | [
"def",
"from_keyed_iterable",
"(",
"iterable",
",",
"key",
",",
"filter_func",
"=",
"None",
")",
":",
"generated",
"=",
"{",
"}",
"for",
"element",
"in",
"iterable",
":",
"try",
":",
"k",
"=",
"getattr",
"(",
"element",
",",
"key",
")",
"except",
"Attr... | Construct a dictionary out of an iterable, using an attribute name as
the key. Optionally provide a filter function, to determine what should be
kept in the dictionary. | [
"Construct",
"a",
"dictionary",
"out",
"of",
"an",
"iterable",
"using",
"an",
"attribute",
"name",
"as",
"the",
"key",
".",
"Optionally",
"provide",
"a",
"filter",
"function",
"to",
"determine",
"what",
"should",
"be",
"kept",
"in",
"the",
"dictionary",
"."
... | 6ba851d11e53812dfc9017537a4f2de198851708 | https://github.com/haaksmash/pyutils/blob/6ba851d11e53812dfc9017537a4f2de198851708/utils/dicts/helpers.py#L4-L25 | train | 59,137 |
haaksmash/pyutils | utils/dicts/helpers.py | subtract_by_key | def subtract_by_key(dict_a, dict_b):
"""given two dicts, a and b, this function returns c = a - b, where
a - b is defined as the key difference between a and b.
e.g.,
{1:None, 2:3, 3:"yellow", 4:True} - {2:4, 1:"green"} =
{3:"yellow", 4:True}
"""
difference_dict = {}
for key in dic... | python | def subtract_by_key(dict_a, dict_b):
"""given two dicts, a and b, this function returns c = a - b, where
a - b is defined as the key difference between a and b.
e.g.,
{1:None, 2:3, 3:"yellow", 4:True} - {2:4, 1:"green"} =
{3:"yellow", 4:True}
"""
difference_dict = {}
for key in dic... | [
"def",
"subtract_by_key",
"(",
"dict_a",
",",
"dict_b",
")",
":",
"difference_dict",
"=",
"{",
"}",
"for",
"key",
"in",
"dict_a",
":",
"if",
"key",
"not",
"in",
"dict_b",
":",
"difference_dict",
"[",
"key",
"]",
"=",
"dict_a",
"[",
"key",
"]",
"return"... | given two dicts, a and b, this function returns c = a - b, where
a - b is defined as the key difference between a and b.
e.g.,
{1:None, 2:3, 3:"yellow", 4:True} - {2:4, 1:"green"} =
{3:"yellow", 4:True} | [
"given",
"two",
"dicts",
"a",
"and",
"b",
"this",
"function",
"returns",
"c",
"=",
"a",
"-",
"b",
"where",
"a",
"-",
"b",
"is",
"defined",
"as",
"the",
"key",
"difference",
"between",
"a",
"and",
"b",
"."
] | 6ba851d11e53812dfc9017537a4f2de198851708 | https://github.com/haaksmash/pyutils/blob/6ba851d11e53812dfc9017537a4f2de198851708/utils/dicts/helpers.py#L28-L42 | train | 59,138 |
haaksmash/pyutils | utils/dicts/helpers.py | winnow_by_keys | def winnow_by_keys(dct, keys=None, filter_func=None):
"""separates a dict into has-keys and not-has-keys pairs, using either
a list of keys or a filtering function."""
has = {}
has_not = {}
for key in dct:
key_passes_check = False
if keys is not None:
key_passes_check = ... | python | def winnow_by_keys(dct, keys=None, filter_func=None):
"""separates a dict into has-keys and not-has-keys pairs, using either
a list of keys or a filtering function."""
has = {}
has_not = {}
for key in dct:
key_passes_check = False
if keys is not None:
key_passes_check = ... | [
"def",
"winnow_by_keys",
"(",
"dct",
",",
"keys",
"=",
"None",
",",
"filter_func",
"=",
"None",
")",
":",
"has",
"=",
"{",
"}",
"has_not",
"=",
"{",
"}",
"for",
"key",
"in",
"dct",
":",
"key_passes_check",
"=",
"False",
"if",
"keys",
"is",
"not",
"... | separates a dict into has-keys and not-has-keys pairs, using either
a list of keys or a filtering function. | [
"separates",
"a",
"dict",
"into",
"has",
"-",
"keys",
"and",
"not",
"-",
"has",
"-",
"keys",
"pairs",
"using",
"either",
"a",
"list",
"of",
"keys",
"or",
"a",
"filtering",
"function",
"."
] | 6ba851d11e53812dfc9017537a4f2de198851708 | https://github.com/haaksmash/pyutils/blob/6ba851d11e53812dfc9017537a4f2de198851708/utils/dicts/helpers.py#L61-L79 | train | 59,139 |
haaksmash/pyutils | utils/lists.py | flat_map | def flat_map(iterable, func):
"""func must take an item and return an interable that contains that
item. this is flatmap in the classic mode"""
results = []
for element in iterable:
result = func(element)
if len(result) > 0:
results.extend(result)
return results | python | def flat_map(iterable, func):
"""func must take an item and return an interable that contains that
item. this is flatmap in the classic mode"""
results = []
for element in iterable:
result = func(element)
if len(result) > 0:
results.extend(result)
return results | [
"def",
"flat_map",
"(",
"iterable",
",",
"func",
")",
":",
"results",
"=",
"[",
"]",
"for",
"element",
"in",
"iterable",
":",
"result",
"=",
"func",
"(",
"element",
")",
"if",
"len",
"(",
"result",
")",
">",
"0",
":",
"results",
".",
"extend",
"(",... | func must take an item and return an interable that contains that
item. this is flatmap in the classic mode | [
"func",
"must",
"take",
"an",
"item",
"and",
"return",
"an",
"interable",
"that",
"contains",
"that",
"item",
".",
"this",
"is",
"flatmap",
"in",
"the",
"classic",
"mode"
] | 6ba851d11e53812dfc9017537a4f2de198851708 | https://github.com/haaksmash/pyutils/blob/6ba851d11e53812dfc9017537a4f2de198851708/utils/lists.py#L34-L42 | train | 59,140 |
haaksmash/pyutils | utils/math.py | product | def product(sequence, initial=1):
"""like the built-in sum, but for multiplication."""
if not isinstance(sequence, collections.Iterable):
raise TypeError("'{}' object is not iterable".format(type(sequence).__name__))
return reduce(operator.mul, sequence, initial) | python | def product(sequence, initial=1):
"""like the built-in sum, but for multiplication."""
if not isinstance(sequence, collections.Iterable):
raise TypeError("'{}' object is not iterable".format(type(sequence).__name__))
return reduce(operator.mul, sequence, initial) | [
"def",
"product",
"(",
"sequence",
",",
"initial",
"=",
"1",
")",
":",
"if",
"not",
"isinstance",
"(",
"sequence",
",",
"collections",
".",
"Iterable",
")",
":",
"raise",
"TypeError",
"(",
"\"'{}' object is not iterable\"",
".",
"format",
"(",
"type",
"(",
... | like the built-in sum, but for multiplication. | [
"like",
"the",
"built",
"-",
"in",
"sum",
"but",
"for",
"multiplication",
"."
] | 6ba851d11e53812dfc9017537a4f2de198851708 | https://github.com/haaksmash/pyutils/blob/6ba851d11e53812dfc9017537a4f2de198851708/utils/math.py#L11-L16 | train | 59,141 |
haaksmash/pyutils | utils/dates.py | date_from_string | def date_from_string(string, format_string=None):
"""Runs through a few common string formats for datetimes,
and attempts to coerce them into a datetime. Alternatively,
format_string can provide either a single string to attempt
or an iterable of strings to attempt."""
if isinstance(format_string, ... | python | def date_from_string(string, format_string=None):
"""Runs through a few common string formats for datetimes,
and attempts to coerce them into a datetime. Alternatively,
format_string can provide either a single string to attempt
or an iterable of strings to attempt."""
if isinstance(format_string, ... | [
"def",
"date_from_string",
"(",
"string",
",",
"format_string",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"format_string",
",",
"str",
")",
":",
"return",
"datetime",
".",
"datetime",
".",
"strptime",
"(",
"string",
",",
"format_string",
")",
".",
"d... | Runs through a few common string formats for datetimes,
and attempts to coerce them into a datetime. Alternatively,
format_string can provide either a single string to attempt
or an iterable of strings to attempt. | [
"Runs",
"through",
"a",
"few",
"common",
"string",
"formats",
"for",
"datetimes",
"and",
"attempts",
"to",
"coerce",
"them",
"into",
"a",
"datetime",
".",
"Alternatively",
"format_string",
"can",
"provide",
"either",
"a",
"single",
"string",
"to",
"attempt",
"... | 6ba851d11e53812dfc9017537a4f2de198851708 | https://github.com/haaksmash/pyutils/blob/6ba851d11e53812dfc9017537a4f2de198851708/utils/dates.py#L5-L28 | train | 59,142 |
haaksmash/pyutils | utils/dates.py | to_datetime | def to_datetime(plain_date, hours=0, minutes=0, seconds=0, ms=0):
"""given a datetime.date, gives back a datetime.datetime"""
# don't mess with datetimes
if isinstance(plain_date, datetime.datetime):
return plain_date
return datetime.datetime(
plain_date.year,
plain_date.month,
... | python | def to_datetime(plain_date, hours=0, minutes=0, seconds=0, ms=0):
"""given a datetime.date, gives back a datetime.datetime"""
# don't mess with datetimes
if isinstance(plain_date, datetime.datetime):
return plain_date
return datetime.datetime(
plain_date.year,
plain_date.month,
... | [
"def",
"to_datetime",
"(",
"plain_date",
",",
"hours",
"=",
"0",
",",
"minutes",
"=",
"0",
",",
"seconds",
"=",
"0",
",",
"ms",
"=",
"0",
")",
":",
"# don't mess with datetimes",
"if",
"isinstance",
"(",
"plain_date",
",",
"datetime",
".",
"datetime",
")... | given a datetime.date, gives back a datetime.datetime | [
"given",
"a",
"datetime",
".",
"date",
"gives",
"back",
"a",
"datetime",
".",
"datetime"
] | 6ba851d11e53812dfc9017537a4f2de198851708 | https://github.com/haaksmash/pyutils/blob/6ba851d11e53812dfc9017537a4f2de198851708/utils/dates.py#L31-L44 | train | 59,143 |
haaksmash/pyutils | utils/dates.py | TimePeriod.get_containing_period | def get_containing_period(cls, *periods):
"""Given a bunch of TimePeriods, return a TimePeriod that most closely
contains them."""
if any(not isinstance(period, TimePeriod) for period in periods):
raise TypeError("periods must all be TimePeriods: {}".format(periods))
latest... | python | def get_containing_period(cls, *periods):
"""Given a bunch of TimePeriods, return a TimePeriod that most closely
contains them."""
if any(not isinstance(period, TimePeriod) for period in periods):
raise TypeError("periods must all be TimePeriods: {}".format(periods))
latest... | [
"def",
"get_containing_period",
"(",
"cls",
",",
"*",
"periods",
")",
":",
"if",
"any",
"(",
"not",
"isinstance",
"(",
"period",
",",
"TimePeriod",
")",
"for",
"period",
"in",
"periods",
")",
":",
"raise",
"TypeError",
"(",
"\"periods must all be TimePeriods: ... | Given a bunch of TimePeriods, return a TimePeriod that most closely
contains them. | [
"Given",
"a",
"bunch",
"of",
"TimePeriods",
"return",
"a",
"TimePeriod",
"that",
"most",
"closely",
"contains",
"them",
"."
] | 6ba851d11e53812dfc9017537a4f2de198851708 | https://github.com/haaksmash/pyutils/blob/6ba851d11e53812dfc9017537a4f2de198851708/utils/dates.py#L133-L155 | train | 59,144 |
major/supernova | supernova/credentials.py | get_user_password | def get_user_password(env, param, force=False):
"""
Allows the user to print the credential for a particular keyring entry
to the screen
"""
username = utils.assemble_username(env, param)
if not utils.confirm_credential_display(force):
return
# Retrieve the credential from the keyc... | python | def get_user_password(env, param, force=False):
"""
Allows the user to print the credential for a particular keyring entry
to the screen
"""
username = utils.assemble_username(env, param)
if not utils.confirm_credential_display(force):
return
# Retrieve the credential from the keyc... | [
"def",
"get_user_password",
"(",
"env",
",",
"param",
",",
"force",
"=",
"False",
")",
":",
"username",
"=",
"utils",
".",
"assemble_username",
"(",
"env",
",",
"param",
")",
"if",
"not",
"utils",
".",
"confirm_credential_display",
"(",
"force",
")",
":",
... | Allows the user to print the credential for a particular keyring entry
to the screen | [
"Allows",
"the",
"user",
"to",
"print",
"the",
"credential",
"for",
"a",
"particular",
"keyring",
"entry",
"to",
"the",
"screen"
] | 4a217ae53c1c05567014b047c0b6b9dea2d383b3 | https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/credentials.py#L34-L50 | train | 59,145 |
major/supernova | supernova/credentials.py | password_get | def password_get(username=None):
"""
Retrieves a password from the keychain based on the environment and
configuration parameter pair.
If this fails, None is returned.
"""
password = keyring.get_password('supernova', username)
if password is None:
split_username = tuple(username.spl... | python | def password_get(username=None):
"""
Retrieves a password from the keychain based on the environment and
configuration parameter pair.
If this fails, None is returned.
"""
password = keyring.get_password('supernova', username)
if password is None:
split_username = tuple(username.spl... | [
"def",
"password_get",
"(",
"username",
"=",
"None",
")",
":",
"password",
"=",
"keyring",
".",
"get_password",
"(",
"'supernova'",
",",
"username",
")",
"if",
"password",
"is",
"None",
":",
"split_username",
"=",
"tuple",
"(",
"username",
".",
"split",
"(... | Retrieves a password from the keychain based on the environment and
configuration parameter pair.
If this fails, None is returned. | [
"Retrieves",
"a",
"password",
"from",
"the",
"keychain",
"based",
"on",
"the",
"environment",
"and",
"configuration",
"parameter",
"pair",
"."
] | 4a217ae53c1c05567014b047c0b6b9dea2d383b3 | https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/credentials.py#L73-L87 | train | 59,146 |
major/supernova | supernova/credentials.py | set_user_password | def set_user_password(environment, parameter, password):
"""
Sets a user's password in the keyring storage
"""
username = '%s:%s' % (environment, parameter)
return password_set(username, password) | python | def set_user_password(environment, parameter, password):
"""
Sets a user's password in the keyring storage
"""
username = '%s:%s' % (environment, parameter)
return password_set(username, password) | [
"def",
"set_user_password",
"(",
"environment",
",",
"parameter",
",",
"password",
")",
":",
"username",
"=",
"'%s:%s'",
"%",
"(",
"environment",
",",
"parameter",
")",
"return",
"password_set",
"(",
"username",
",",
"password",
")"
] | Sets a user's password in the keyring storage | [
"Sets",
"a",
"user",
"s",
"password",
"in",
"the",
"keyring",
"storage"
] | 4a217ae53c1c05567014b047c0b6b9dea2d383b3 | https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/credentials.py#L90-L95 | train | 59,147 |
major/supernova | supernova/credentials.py | password_set | def password_set(username=None, password=None):
"""
Stores a password in a keychain for a particular environment and
configuration parameter pair.
"""
result = keyring.set_password('supernova', username, password)
# NOTE: keyring returns None when the storage is successful. That's weird.
i... | python | def password_set(username=None, password=None):
"""
Stores a password in a keychain for a particular environment and
configuration parameter pair.
"""
result = keyring.set_password('supernova', username, password)
# NOTE: keyring returns None when the storage is successful. That's weird.
i... | [
"def",
"password_set",
"(",
"username",
"=",
"None",
",",
"password",
"=",
"None",
")",
":",
"result",
"=",
"keyring",
".",
"set_password",
"(",
"'supernova'",
",",
"username",
",",
"password",
")",
"# NOTE: keyring returns None when the storage is successful. That's... | Stores a password in a keychain for a particular environment and
configuration parameter pair. | [
"Stores",
"a",
"password",
"in",
"a",
"keychain",
"for",
"a",
"particular",
"environment",
"and",
"configuration",
"parameter",
"pair",
"."
] | 4a217ae53c1c05567014b047c0b6b9dea2d383b3 | https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/credentials.py#L98-L109 | train | 59,148 |
major/supernova | supernova/credentials.py | prep_shell_environment | def prep_shell_environment(nova_env, nova_creds):
"""
Appends new variables to the current shell environment temporarily.
"""
new_env = {}
for key, value in prep_nova_creds(nova_env, nova_creds):
if type(value) == six.binary_type:
value = value.decode()
new_env[key] = va... | python | def prep_shell_environment(nova_env, nova_creds):
"""
Appends new variables to the current shell environment temporarily.
"""
new_env = {}
for key, value in prep_nova_creds(nova_env, nova_creds):
if type(value) == six.binary_type:
value = value.decode()
new_env[key] = va... | [
"def",
"prep_shell_environment",
"(",
"nova_env",
",",
"nova_creds",
")",
":",
"new_env",
"=",
"{",
"}",
"for",
"key",
",",
"value",
"in",
"prep_nova_creds",
"(",
"nova_env",
",",
"nova_creds",
")",
":",
"if",
"type",
"(",
"value",
")",
"==",
"six",
".",... | Appends new variables to the current shell environment temporarily. | [
"Appends",
"new",
"variables",
"to",
"the",
"current",
"shell",
"environment",
"temporarily",
"."
] | 4a217ae53c1c05567014b047c0b6b9dea2d383b3 | https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/credentials.py#L112-L123 | train | 59,149 |
major/supernova | supernova/credentials.py | prep_nova_creds | def prep_nova_creds(nova_env, nova_creds):
"""
Finds relevant config options in the supernova config and cleans them
up for novaclient.
"""
try:
raw_creds = dict(nova_creds.get('DEFAULT', {}), **nova_creds[nova_env])
except KeyError:
msg = "{0} was not found in your supernova con... | python | def prep_nova_creds(nova_env, nova_creds):
"""
Finds relevant config options in the supernova config and cleans them
up for novaclient.
"""
try:
raw_creds = dict(nova_creds.get('DEFAULT', {}), **nova_creds[nova_env])
except KeyError:
msg = "{0} was not found in your supernova con... | [
"def",
"prep_nova_creds",
"(",
"nova_env",
",",
"nova_creds",
")",
":",
"try",
":",
"raw_creds",
"=",
"dict",
"(",
"nova_creds",
".",
"get",
"(",
"'DEFAULT'",
",",
"{",
"}",
")",
",",
"*",
"*",
"nova_creds",
"[",
"nova_env",
"]",
")",
"except",
"KeyErr... | Finds relevant config options in the supernova config and cleans them
up for novaclient. | [
"Finds",
"relevant",
"config",
"options",
"in",
"the",
"supernova",
"config",
"and",
"cleans",
"them",
"up",
"for",
"novaclient",
"."
] | 4a217ae53c1c05567014b047c0b6b9dea2d383b3 | https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/credentials.py#L126-L162 | train | 59,150 |
major/supernova | supernova/config.py | load_config | def load_config(config_file_override=False):
"""
Pulls the supernova configuration file and reads it
"""
supernova_config = get_config_file(config_file_override)
supernova_config_dir = get_config_directory(config_file_override)
if not supernova_config and not supernova_config_dir:
raise... | python | def load_config(config_file_override=False):
"""
Pulls the supernova configuration file and reads it
"""
supernova_config = get_config_file(config_file_override)
supernova_config_dir = get_config_directory(config_file_override)
if not supernova_config and not supernova_config_dir:
raise... | [
"def",
"load_config",
"(",
"config_file_override",
"=",
"False",
")",
":",
"supernova_config",
"=",
"get_config_file",
"(",
"config_file_override",
")",
"supernova_config_dir",
"=",
"get_config_directory",
"(",
"config_file_override",
")",
"if",
"not",
"supernova_config",... | Pulls the supernova configuration file and reads it | [
"Pulls",
"the",
"supernova",
"configuration",
"file",
"and",
"reads",
"it"
] | 4a217ae53c1c05567014b047c0b6b9dea2d383b3 | https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/config.py#L40-L69 | train | 59,151 |
major/supernova | supernova/config.py | get_config_file | def get_config_file(override_files=False):
"""
Looks for the most specific configuration file available. An override
can be provided as a string if needed.
"""
if override_files:
if isinstance(override_files, six.string_types):
possible_configs = [override_files]
else:
... | python | def get_config_file(override_files=False):
"""
Looks for the most specific configuration file available. An override
can be provided as a string if needed.
"""
if override_files:
if isinstance(override_files, six.string_types):
possible_configs = [override_files]
else:
... | [
"def",
"get_config_file",
"(",
"override_files",
"=",
"False",
")",
":",
"if",
"override_files",
":",
"if",
"isinstance",
"(",
"override_files",
",",
"six",
".",
"string_types",
")",
":",
"possible_configs",
"=",
"[",
"override_files",
"]",
"else",
":",
"raise... | Looks for the most specific configuration file available. An override
can be provided as a string if needed. | [
"Looks",
"for",
"the",
"most",
"specific",
"configuration",
"file",
"available",
".",
"An",
"override",
"can",
"be",
"provided",
"as",
"a",
"string",
"if",
"needed",
"."
] | 4a217ae53c1c05567014b047c0b6b9dea2d383b3 | https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/config.py#L72-L93 | train | 59,152 |
major/supernova | supernova/config.py | get_config_directory | def get_config_directory(override_files=False):
"""
Looks for the most specific configuration directory possible, in order to
load individual configuration files.
"""
if override_files:
possible_dirs = [override_files]
else:
xdg_config_home = os.environ.get('XDG_CONFIG_HOME') or... | python | def get_config_directory(override_files=False):
"""
Looks for the most specific configuration directory possible, in order to
load individual configuration files.
"""
if override_files:
possible_dirs = [override_files]
else:
xdg_config_home = os.environ.get('XDG_CONFIG_HOME') or... | [
"def",
"get_config_directory",
"(",
"override_files",
"=",
"False",
")",
":",
"if",
"override_files",
":",
"possible_dirs",
"=",
"[",
"override_files",
"]",
"else",
":",
"xdg_config_home",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'XDG_CONFIG_HOME'",
")",
"... | Looks for the most specific configuration directory possible, in order to
load individual configuration files. | [
"Looks",
"for",
"the",
"most",
"specific",
"configuration",
"directory",
"possible",
"in",
"order",
"to",
"load",
"individual",
"configuration",
"files",
"."
] | 4a217ae53c1c05567014b047c0b6b9dea2d383b3 | https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/config.py#L96-L115 | train | 59,153 |
major/supernova | supernova/supernova.py | execute_executable | def execute_executable(nova_args, env_vars):
"""
Executes the executable given by the user.
Hey, I know this method has a silly name, but I write the code here and
I'm silly.
"""
process = subprocess.Popen(nova_args,
stdout=sys.stdout,
... | python | def execute_executable(nova_args, env_vars):
"""
Executes the executable given by the user.
Hey, I know this method has a silly name, but I write the code here and
I'm silly.
"""
process = subprocess.Popen(nova_args,
stdout=sys.stdout,
... | [
"def",
"execute_executable",
"(",
"nova_args",
",",
"env_vars",
")",
":",
"process",
"=",
"subprocess",
".",
"Popen",
"(",
"nova_args",
",",
"stdout",
"=",
"sys",
".",
"stdout",
",",
"stderr",
"=",
"subprocess",
".",
"PIPE",
",",
"env",
"=",
"env_vars",
... | Executes the executable given by the user.
Hey, I know this method has a silly name, but I write the code here and
I'm silly. | [
"Executes",
"the",
"executable",
"given",
"by",
"the",
"user",
"."
] | 4a217ae53c1c05567014b047c0b6b9dea2d383b3 | https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/supernova.py#L32-L44 | train | 59,154 |
major/supernova | supernova/supernova.py | check_for_debug | def check_for_debug(supernova_args, nova_args):
"""
If the user wanted to run the executable with debugging enabled, we need
to apply the correct arguments to the executable.
Heat is a corner case since it uses -d instead of --debug.
"""
# Heat requires special handling for debug arguments
... | python | def check_for_debug(supernova_args, nova_args):
"""
If the user wanted to run the executable with debugging enabled, we need
to apply the correct arguments to the executable.
Heat is a corner case since it uses -d instead of --debug.
"""
# Heat requires special handling for debug arguments
... | [
"def",
"check_for_debug",
"(",
"supernova_args",
",",
"nova_args",
")",
":",
"# Heat requires special handling for debug arguments",
"if",
"supernova_args",
"[",
"'debug'",
"]",
"and",
"supernova_args",
"[",
"'executable'",
"]",
"==",
"'heat'",
":",
"nova_args",
".",
... | If the user wanted to run the executable with debugging enabled, we need
to apply the correct arguments to the executable.
Heat is a corner case since it uses -d instead of --debug. | [
"If",
"the",
"user",
"wanted",
"to",
"run",
"the",
"executable",
"with",
"debugging",
"enabled",
"we",
"need",
"to",
"apply",
"the",
"correct",
"arguments",
"to",
"the",
"executable",
"."
] | 4a217ae53c1c05567014b047c0b6b9dea2d383b3 | https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/supernova.py#L47-L60 | train | 59,155 |
major/supernova | supernova/supernova.py | check_for_executable | def check_for_executable(supernova_args, env_vars):
"""
It's possible that a user might set their custom executable via an
environment variable. If we detect one, we should add it to supernova's
arguments ONLY IF an executable wasn't set on the command line. The
command line executable must take p... | python | def check_for_executable(supernova_args, env_vars):
"""
It's possible that a user might set their custom executable via an
environment variable. If we detect one, we should add it to supernova's
arguments ONLY IF an executable wasn't set on the command line. The
command line executable must take p... | [
"def",
"check_for_executable",
"(",
"supernova_args",
",",
"env_vars",
")",
":",
"exe",
"=",
"supernova_args",
".",
"get",
"(",
"'executable'",
",",
"'default'",
")",
"if",
"exe",
"!=",
"'default'",
":",
"return",
"supernova_args",
"if",
"'OS_EXECUTABLE'",
"in",... | It's possible that a user might set their custom executable via an
environment variable. If we detect one, we should add it to supernova's
arguments ONLY IF an executable wasn't set on the command line. The
command line executable must take priority. | [
"It",
"s",
"possible",
"that",
"a",
"user",
"might",
"set",
"their",
"custom",
"executable",
"via",
"an",
"environment",
"variable",
".",
"If",
"we",
"detect",
"one",
"we",
"should",
"add",
"it",
"to",
"supernova",
"s",
"arguments",
"ONLY",
"IF",
"an",
"... | 4a217ae53c1c05567014b047c0b6b9dea2d383b3 | https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/supernova.py#L63-L77 | train | 59,156 |
major/supernova | supernova/supernova.py | check_for_bypass_url | def check_for_bypass_url(raw_creds, nova_args):
"""
Return a list of extra args that need to be passed on cmdline to nova.
"""
if 'BYPASS_URL' in raw_creds.keys():
bypass_args = ['--bypass-url', raw_creds['BYPASS_URL']]
nova_args = bypass_args + nova_args
return nova_args | python | def check_for_bypass_url(raw_creds, nova_args):
"""
Return a list of extra args that need to be passed on cmdline to nova.
"""
if 'BYPASS_URL' in raw_creds.keys():
bypass_args = ['--bypass-url', raw_creds['BYPASS_URL']]
nova_args = bypass_args + nova_args
return nova_args | [
"def",
"check_for_bypass_url",
"(",
"raw_creds",
",",
"nova_args",
")",
":",
"if",
"'BYPASS_URL'",
"in",
"raw_creds",
".",
"keys",
"(",
")",
":",
"bypass_args",
"=",
"[",
"'--bypass-url'",
",",
"raw_creds",
"[",
"'BYPASS_URL'",
"]",
"]",
"nova_args",
"=",
"b... | Return a list of extra args that need to be passed on cmdline to nova. | [
"Return",
"a",
"list",
"of",
"extra",
"args",
"that",
"need",
"to",
"be",
"passed",
"on",
"cmdline",
"to",
"nova",
"."
] | 4a217ae53c1c05567014b047c0b6b9dea2d383b3 | https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/supernova.py#L80-L88 | train | 59,157 |
major/supernova | supernova/supernova.py | run_command | def run_command(nova_creds, nova_args, supernova_args):
"""
Sets the environment variables for the executable, runs the executable,
and handles the output.
"""
nova_env = supernova_args['nova_env']
# (gtmanfred) make a copy of this object. If we don't copy it, the insert
# to 0 happens mult... | python | def run_command(nova_creds, nova_args, supernova_args):
"""
Sets the environment variables for the executable, runs the executable,
and handles the output.
"""
nova_env = supernova_args['nova_env']
# (gtmanfred) make a copy of this object. If we don't copy it, the insert
# to 0 happens mult... | [
"def",
"run_command",
"(",
"nova_creds",
",",
"nova_args",
",",
"supernova_args",
")",
":",
"nova_env",
"=",
"supernova_args",
"[",
"'nova_env'",
"]",
"# (gtmanfred) make a copy of this object. If we don't copy it, the insert",
"# to 0 happens multiple times because it is the same... | Sets the environment variables for the executable, runs the executable,
and handles the output. | [
"Sets",
"the",
"environment",
"variables",
"for",
"the",
"executable",
"runs",
"the",
"executable",
"and",
"handles",
"the",
"output",
"."
] | 4a217ae53c1c05567014b047c0b6b9dea2d383b3 | https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/supernova.py#L106-L150 | train | 59,158 |
major/supernova | supernova/utils.py | check_environment_presets | def check_environment_presets():
"""
Checks for environment variables that can cause problems with supernova
"""
presets = [x for x in os.environ.copy().keys() if x.startswith('NOVA_') or
x.startswith('OS_')]
if len(presets) < 1:
return True
else:
click.echo("_" * ... | python | def check_environment_presets():
"""
Checks for environment variables that can cause problems with supernova
"""
presets = [x for x in os.environ.copy().keys() if x.startswith('NOVA_') or
x.startswith('OS_')]
if len(presets) < 1:
return True
else:
click.echo("_" * ... | [
"def",
"check_environment_presets",
"(",
")",
":",
"presets",
"=",
"[",
"x",
"for",
"x",
"in",
"os",
".",
"environ",
".",
"copy",
"(",
")",
".",
"keys",
"(",
")",
"if",
"x",
".",
"startswith",
"(",
"'NOVA_'",
")",
"or",
"x",
".",
"startswith",
"(",... | Checks for environment variables that can cause problems with supernova | [
"Checks",
"for",
"environment",
"variables",
"that",
"can",
"cause",
"problems",
"with",
"supernova"
] | 4a217ae53c1c05567014b047c0b6b9dea2d383b3 | https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/utils.py#L29-L44 | train | 59,159 |
major/supernova | supernova/utils.py | get_envs_in_group | def get_envs_in_group(group_name, nova_creds):
"""
Takes a group_name and finds any environments that have a SUPERNOVA_GROUP
configuration line that matches the group_name.
"""
envs = []
for key, value in nova_creds.items():
supernova_groups = value.get('SUPERNOVA_GROUP', [])
if ... | python | def get_envs_in_group(group_name, nova_creds):
"""
Takes a group_name and finds any environments that have a SUPERNOVA_GROUP
configuration line that matches the group_name.
"""
envs = []
for key, value in nova_creds.items():
supernova_groups = value.get('SUPERNOVA_GROUP', [])
if ... | [
"def",
"get_envs_in_group",
"(",
"group_name",
",",
"nova_creds",
")",
":",
"envs",
"=",
"[",
"]",
"for",
"key",
",",
"value",
"in",
"nova_creds",
".",
"items",
"(",
")",
":",
"supernova_groups",
"=",
"value",
".",
"get",
"(",
"'SUPERNOVA_GROUP'",
",",
"... | Takes a group_name and finds any environments that have a SUPERNOVA_GROUP
configuration line that matches the group_name. | [
"Takes",
"a",
"group_name",
"and",
"finds",
"any",
"environments",
"that",
"have",
"a",
"SUPERNOVA_GROUP",
"configuration",
"line",
"that",
"matches",
"the",
"group_name",
"."
] | 4a217ae53c1c05567014b047c0b6b9dea2d383b3 | https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/utils.py#L59-L73 | train | 59,160 |
major/supernova | supernova/utils.py | is_valid_group | def is_valid_group(group_name, nova_creds):
"""
Checks to see if the configuration file contains a SUPERNOVA_GROUP
configuration option.
"""
valid_groups = []
for key, value in nova_creds.items():
supernova_groups = value.get('SUPERNOVA_GROUP', [])
if hasattr(supernova_groups, 's... | python | def is_valid_group(group_name, nova_creds):
"""
Checks to see if the configuration file contains a SUPERNOVA_GROUP
configuration option.
"""
valid_groups = []
for key, value in nova_creds.items():
supernova_groups = value.get('SUPERNOVA_GROUP', [])
if hasattr(supernova_groups, 's... | [
"def",
"is_valid_group",
"(",
"group_name",
",",
"nova_creds",
")",
":",
"valid_groups",
"=",
"[",
"]",
"for",
"key",
",",
"value",
"in",
"nova_creds",
".",
"items",
"(",
")",
":",
"supernova_groups",
"=",
"value",
".",
"get",
"(",
"'SUPERNOVA_GROUP'",
","... | Checks to see if the configuration file contains a SUPERNOVA_GROUP
configuration option. | [
"Checks",
"to",
"see",
"if",
"the",
"configuration",
"file",
"contains",
"a",
"SUPERNOVA_GROUP",
"configuration",
"option",
"."
] | 4a217ae53c1c05567014b047c0b6b9dea2d383b3 | https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/utils.py#L87-L102 | train | 59,161 |
major/supernova | supernova/utils.py | rm_prefix | def rm_prefix(name):
"""
Removes nova_ os_ novaclient_ prefix from string.
"""
if name.startswith('nova_'):
return name[5:]
elif name.startswith('novaclient_'):
return name[11:]
elif name.startswith('os_'):
return name[3:]
else:
return name | python | def rm_prefix(name):
"""
Removes nova_ os_ novaclient_ prefix from string.
"""
if name.startswith('nova_'):
return name[5:]
elif name.startswith('novaclient_'):
return name[11:]
elif name.startswith('os_'):
return name[3:]
else:
return name | [
"def",
"rm_prefix",
"(",
"name",
")",
":",
"if",
"name",
".",
"startswith",
"(",
"'nova_'",
")",
":",
"return",
"name",
"[",
"5",
":",
"]",
"elif",
"name",
".",
"startswith",
"(",
"'novaclient_'",
")",
":",
"return",
"name",
"[",
"11",
":",
"]",
"e... | Removes nova_ os_ novaclient_ prefix from string. | [
"Removes",
"nova_",
"os_",
"novaclient_",
"prefix",
"from",
"string",
"."
] | 4a217ae53c1c05567014b047c0b6b9dea2d383b3 | https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/utils.py#L105-L116 | train | 59,162 |
corydolphin/flask-jsonpify | flask_jsonpify.py | __pad | def __pad(strdata):
""" Pads `strdata` with a Request's callback argument, if specified, or does
nothing.
"""
if request.args.get('callback'):
return "%s(%s);" % (request.args.get('callback'), strdata)
else:
return strdata | python | def __pad(strdata):
""" Pads `strdata` with a Request's callback argument, if specified, or does
nothing.
"""
if request.args.get('callback'):
return "%s(%s);" % (request.args.get('callback'), strdata)
else:
return strdata | [
"def",
"__pad",
"(",
"strdata",
")",
":",
"if",
"request",
".",
"args",
".",
"get",
"(",
"'callback'",
")",
":",
"return",
"\"%s(%s);\"",
"%",
"(",
"request",
".",
"args",
".",
"get",
"(",
"'callback'",
")",
",",
"strdata",
")",
"else",
":",
"return"... | Pads `strdata` with a Request's callback argument, if specified, or does
nothing. | [
"Pads",
"strdata",
"with",
"a",
"Request",
"s",
"callback",
"argument",
"if",
"specified",
"or",
"does",
"nothing",
"."
] | a875ebe9b8e5bd74b8b44058aa36b099fa6bc84f | https://github.com/corydolphin/flask-jsonpify/blob/a875ebe9b8e5bd74b8b44058aa36b099fa6bc84f/flask_jsonpify.py#L4-L11 | train | 59,163 |
corydolphin/flask-jsonpify | flask_jsonpify.py | __dumps | def __dumps(*args, **kwargs):
""" Serializes `args` and `kwargs` as JSON. Supports serializing an array
as the top-level object, if it is the only argument.
"""
indent = None
if (current_app.config.get('JSONIFY_PRETTYPRINT_REGULAR', False) and
not request.is_xhr):
indent =... | python | def __dumps(*args, **kwargs):
""" Serializes `args` and `kwargs` as JSON. Supports serializing an array
as the top-level object, if it is the only argument.
"""
indent = None
if (current_app.config.get('JSONIFY_PRETTYPRINT_REGULAR', False) and
not request.is_xhr):
indent =... | [
"def",
"__dumps",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"indent",
"=",
"None",
"if",
"(",
"current_app",
".",
"config",
".",
"get",
"(",
"'JSONIFY_PRETTYPRINT_REGULAR'",
",",
"False",
")",
"and",
"not",
"request",
".",
"is_xhr",
")",
":"... | Serializes `args` and `kwargs` as JSON. Supports serializing an array
as the top-level object, if it is the only argument. | [
"Serializes",
"args",
"and",
"kwargs",
"as",
"JSON",
".",
"Supports",
"serializing",
"an",
"array",
"as",
"the",
"top",
"-",
"level",
"object",
"if",
"it",
"is",
"the",
"only",
"argument",
"."
] | a875ebe9b8e5bd74b8b44058aa36b099fa6bc84f | https://github.com/corydolphin/flask-jsonpify/blob/a875ebe9b8e5bd74b8b44058aa36b099fa6bc84f/flask_jsonpify.py#L21-L30 | train | 59,164 |
frejanordsiek/hdf5storage | hdf5storage/Marshallers.py | TypeMarshaller.update_type_lookups | def update_type_lookups(self):
""" Update type and typestring lookup dicts.
Must be called once the ``types`` and ``python_type_strings``
attributes are set so that ``type_to_typestring`` and
``typestring_to_type`` are constructed.
.. versionadded:: 0.2
Notes
-... | python | def update_type_lookups(self):
""" Update type and typestring lookup dicts.
Must be called once the ``types`` and ``python_type_strings``
attributes are set so that ``type_to_typestring`` and
``typestring_to_type`` are constructed.
.. versionadded:: 0.2
Notes
-... | [
"def",
"update_type_lookups",
"(",
"self",
")",
":",
"self",
".",
"type_to_typestring",
"=",
"dict",
"(",
"zip",
"(",
"self",
".",
"types",
",",
"self",
".",
"python_type_strings",
")",
")",
"self",
".",
"typestring_to_type",
"=",
"dict",
"(",
"zip",
"(",
... | Update type and typestring lookup dicts.
Must be called once the ``types`` and ``python_type_strings``
attributes are set so that ``type_to_typestring`` and
``typestring_to_type`` are constructed.
.. versionadded:: 0.2
Notes
-----
Subclasses need to call this f... | [
"Update",
"type",
"and",
"typestring",
"lookup",
"dicts",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/Marshallers.py#L245-L262 | train | 59,165 |
frejanordsiek/hdf5storage | hdf5storage/Marshallers.py | TypeMarshaller.get_type_string | def get_type_string(self, data, type_string):
""" Gets type string.
Finds the type string for 'data' contained in
``python_type_strings`` using its ``type``. Non-``None``
'type_string` overrides whatever type string is looked up.
The override makes it easier for subclasses to co... | python | def get_type_string(self, data, type_string):
""" Gets type string.
Finds the type string for 'data' contained in
``python_type_strings`` using its ``type``. Non-``None``
'type_string` overrides whatever type string is looked up.
The override makes it easier for subclasses to co... | [
"def",
"get_type_string",
"(",
"self",
",",
"data",
",",
"type_string",
")",
":",
"if",
"type_string",
"is",
"not",
"None",
":",
"return",
"type_string",
"else",
":",
"tp",
"=",
"type",
"(",
"data",
")",
"try",
":",
"return",
"self",
".",
"type_to_typest... | Gets type string.
Finds the type string for 'data' contained in
``python_type_strings`` using its ``type``. Non-``None``
'type_string` overrides whatever type string is looked up.
The override makes it easier for subclasses to convert something
that the parent marshaller can wri... | [
"Gets",
"type",
"string",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/Marshallers.py#L264-L301 | train | 59,166 |
frejanordsiek/hdf5storage | hdf5storage/Marshallers.py | TypeMarshaller.write | def write(self, f, grp, name, data, type_string, options):
""" Writes an object's metadata to file.
Writes the Python object 'data' to 'name' in h5py.Group 'grp'.
.. versionchanged:: 0.2
Arguements changed.
Parameters
----------
f : h5py.File
The... | python | def write(self, f, grp, name, data, type_string, options):
""" Writes an object's metadata to file.
Writes the Python object 'data' to 'name' in h5py.Group 'grp'.
.. versionchanged:: 0.2
Arguements changed.
Parameters
----------
f : h5py.File
The... | [
"def",
"write",
"(",
"self",
",",
"f",
",",
"grp",
",",
"name",
",",
"data",
",",
"type_string",
",",
"options",
")",
":",
"raise",
"NotImplementedError",
"(",
"'Can'",
"'t write data type: '",
"+",
"str",
"(",
"type",
"(",
"data",
")",
")",
")"
] | Writes an object's metadata to file.
Writes the Python object 'data' to 'name' in h5py.Group 'grp'.
.. versionchanged:: 0.2
Arguements changed.
Parameters
----------
f : h5py.File
The HDF5 file handle that is open.
grp : h5py.Group or h5py.File
... | [
"Writes",
"an",
"object",
"s",
"metadata",
"to",
"file",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/Marshallers.py#L303-L348 | train | 59,167 |
frejanordsiek/hdf5storage | hdf5storage/Marshallers.py | TypeMarshaller.write_metadata | def write_metadata(self, f, dsetgrp, data, type_string, options,
attributes=None):
""" Writes an object to file.
Writes the metadata for a Python object `data` to file at `name`
in h5py.Group `grp`. Metadata is written to HDF5
Attributes. Existing Attributes that ... | python | def write_metadata(self, f, dsetgrp, data, type_string, options,
attributes=None):
""" Writes an object to file.
Writes the metadata for a Python object `data` to file at `name`
in h5py.Group `grp`. Metadata is written to HDF5
Attributes. Existing Attributes that ... | [
"def",
"write_metadata",
"(",
"self",
",",
"f",
",",
"dsetgrp",
",",
"data",
",",
"type_string",
",",
"options",
",",
"attributes",
"=",
"None",
")",
":",
"if",
"attributes",
"is",
"None",
":",
"attributes",
"=",
"dict",
"(",
")",
"# Make sure we have a co... | Writes an object to file.
Writes the metadata for a Python object `data` to file at `name`
in h5py.Group `grp`. Metadata is written to HDF5
Attributes. Existing Attributes that are not being used are
deleted.
.. versionchanged:: 0.2
Arguements changed.
Param... | [
"Writes",
"an",
"object",
"to",
"file",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/Marshallers.py#L350-L408 | train | 59,168 |
frejanordsiek/hdf5storage | hdf5storage/utilities.py | process_path | def process_path(pth):
""" Processes paths.
Processes the provided path and breaks it into it Group part
(`groupname`) and target part (`targetname`). ``bytes`` paths are
converted to ``str``. Separated paths are given as an iterable of
``str`` and ``bytes``. Each part of a separated path is escape... | python | def process_path(pth):
""" Processes paths.
Processes the provided path and breaks it into it Group part
(`groupname`) and target part (`targetname`). ``bytes`` paths are
converted to ``str``. Separated paths are given as an iterable of
``str`` and ``bytes``. Each part of a separated path is escape... | [
"def",
"process_path",
"(",
"pth",
")",
":",
"# Do conversions and possibly escapes.",
"if",
"isinstance",
"(",
"pth",
",",
"bytes",
")",
":",
"p",
"=",
"pth",
".",
"decode",
"(",
"'utf-8'",
")",
"elif",
"(",
"sys",
".",
"hexversion",
">=",
"0x03000000",
"... | Processes paths.
Processes the provided path and breaks it into it Group part
(`groupname`) and target part (`targetname`). ``bytes`` paths are
converted to ``str``. Separated paths are given as an iterable of
``str`` and ``bytes``. Each part of a separated path is escaped
using ``escape_path``. Ot... | [
"Processes",
"paths",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L245-L339 | train | 59,169 |
frejanordsiek/hdf5storage | hdf5storage/utilities.py | write_object_array | def write_object_array(f, data, options):
""" Writes an array of objects recursively.
Writes the elements of the given object array recursively in the
HDF5 Group ``options.group_for_references`` and returns an
``h5py.Reference`` array to all the elements.
Parameters
----------
f : h5py.Fil... | python | def write_object_array(f, data, options):
""" Writes an array of objects recursively.
Writes the elements of the given object array recursively in the
HDF5 Group ``options.group_for_references`` and returns an
``h5py.Reference`` array to all the elements.
Parameters
----------
f : h5py.Fil... | [
"def",
"write_object_array",
"(",
"f",
",",
"data",
",",
"options",
")",
":",
"# We need to grab the special reference dtype and make an empty",
"# array to store all the references in.",
"ref_dtype",
"=",
"h5py",
".",
"special_dtype",
"(",
"ref",
"=",
"h5py",
".",
"Refer... | Writes an array of objects recursively.
Writes the elements of the given object array recursively in the
HDF5 Group ``options.group_for_references`` and returns an
``h5py.Reference`` array to all the elements.
Parameters
----------
f : h5py.File
The HDF5 file handle that is open.
d... | [
"Writes",
"an",
"array",
"of",
"objects",
"recursively",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L548-L654 | train | 59,170 |
frejanordsiek/hdf5storage | hdf5storage/utilities.py | read_object_array | def read_object_array(f, data, options):
""" Reads an array of objects recursively.
Read the elements of the given HDF5 Reference array recursively
in the and constructs a ``numpy.object_`` array from its elements,
which is returned.
Parameters
----------
f : h5py.File
The HDF5 fil... | python | def read_object_array(f, data, options):
""" Reads an array of objects recursively.
Read the elements of the given HDF5 Reference array recursively
in the and constructs a ``numpy.object_`` array from its elements,
which is returned.
Parameters
----------
f : h5py.File
The HDF5 fil... | [
"def",
"read_object_array",
"(",
"f",
",",
"data",
",",
"options",
")",
":",
"# Go through all the elements of data and read them using their",
"# references, and the putting the output in new object array.",
"data_derefed",
"=",
"np",
".",
"zeros",
"(",
"shape",
"=",
"data",... | Reads an array of objects recursively.
Read the elements of the given HDF5 Reference array recursively
in the and constructs a ``numpy.object_`` array from its elements,
which is returned.
Parameters
----------
f : h5py.File
The HDF5 file handle that is open.
data : numpy.ndarray o... | [
"Reads",
"an",
"array",
"of",
"objects",
"recursively",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L657-L699 | train | 59,171 |
frejanordsiek/hdf5storage | hdf5storage/utilities.py | next_unused_name_in_group | def next_unused_name_in_group(grp, length):
""" Gives a name that isn't used in a Group.
Generates a name of the desired length that is not a Dataset or
Group in the given group. Note, if length is not large enough and
`grp` is full enough, there may be no available names meaning that
this function... | python | def next_unused_name_in_group(grp, length):
""" Gives a name that isn't used in a Group.
Generates a name of the desired length that is not a Dataset or
Group in the given group. Note, if length is not large enough and
`grp` is full enough, there may be no available names meaning that
this function... | [
"def",
"next_unused_name_in_group",
"(",
"grp",
",",
"length",
")",
":",
"# While",
"#",
"# ltrs = string.ascii_letters + string.digits",
"# name = ''.join([random.choice(ltrs) for i in range(length)])",
"#",
"# seems intuitive, its performance is abysmal compared to",
"#",
"# '%0{0}x'... | Gives a name that isn't used in a Group.
Generates a name of the desired length that is not a Dataset or
Group in the given group. Note, if length is not large enough and
`grp` is full enough, there may be no available names meaning that
this function will hang.
Parameters
----------
grp :... | [
"Gives",
"a",
"name",
"that",
"isn",
"t",
"used",
"in",
"a",
"Group",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L702-L743 | train | 59,172 |
frejanordsiek/hdf5storage | hdf5storage/utilities.py | convert_numpy_str_to_uint16 | def convert_numpy_str_to_uint16(data):
""" Converts a numpy.unicode\_ to UTF-16 in numpy.uint16 form.
Convert a ``numpy.unicode_`` or an array of them (they are UTF-32
strings) to UTF-16 in the equivalent array of ``numpy.uint16``. The
conversion will throw an exception if any characters cannot be
... | python | def convert_numpy_str_to_uint16(data):
""" Converts a numpy.unicode\_ to UTF-16 in numpy.uint16 form.
Convert a ``numpy.unicode_`` or an array of them (they are UTF-32
strings) to UTF-16 in the equivalent array of ``numpy.uint16``. The
conversion will throw an exception if any characters cannot be
... | [
"def",
"convert_numpy_str_to_uint16",
"(",
"data",
")",
":",
"# An empty string should be an empty uint16",
"if",
"data",
".",
"nbytes",
"==",
"0",
":",
"return",
"np",
".",
"uint16",
"(",
"[",
"]",
")",
"# We need to use the UTF-16 codec for our endianness. Using the",
... | Converts a numpy.unicode\_ to UTF-16 in numpy.uint16 form.
Convert a ``numpy.unicode_`` or an array of them (they are UTF-32
strings) to UTF-16 in the equivalent array of ``numpy.uint16``. The
conversion will throw an exception if any characters cannot be
converted to UTF-16. Strings are expanded along... | [
"Converts",
"a",
"numpy",
".",
"unicode",
"\\",
"_",
"to",
"UTF",
"-",
"16",
"in",
"numpy",
".",
"uint16",
"form",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L745-L797 | train | 59,173 |
frejanordsiek/hdf5storage | hdf5storage/utilities.py | convert_numpy_str_to_uint32 | def convert_numpy_str_to_uint32(data):
""" Converts a numpy.unicode\_ to its numpy.uint32 representation.
Convert a ``numpy.unicode_`` or an array of them (they are UTF-32
strings) into the equivalent array of ``numpy.uint32`` that is byte
for byte identical. Strings are expanded along rows (across col... | python | def convert_numpy_str_to_uint32(data):
""" Converts a numpy.unicode\_ to its numpy.uint32 representation.
Convert a ``numpy.unicode_`` or an array of them (they are UTF-32
strings) into the equivalent array of ``numpy.uint32`` that is byte
for byte identical. Strings are expanded along rows (across col... | [
"def",
"convert_numpy_str_to_uint32",
"(",
"data",
")",
":",
"if",
"data",
".",
"nbytes",
"==",
"0",
":",
"# An empty string should be an empty uint32.",
"return",
"np",
".",
"uint32",
"(",
"[",
"]",
")",
"else",
":",
"# We need to calculate the new shape from the cur... | Converts a numpy.unicode\_ to its numpy.uint32 representation.
Convert a ``numpy.unicode_`` or an array of them (they are UTF-32
strings) into the equivalent array of ``numpy.uint32`` that is byte
for byte identical. Strings are expanded along rows (across columns)
so a 2x3x4 array of 10 element string... | [
"Converts",
"a",
"numpy",
".",
"unicode",
"\\",
"_",
"to",
"its",
"numpy",
".",
"uint32",
"representation",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L800-L838 | train | 59,174 |
frejanordsiek/hdf5storage | hdf5storage/utilities.py | decode_complex | def decode_complex(data, complex_names=(None, None)):
""" Decodes possibly complex data read from an HDF5 file.
Decodes possibly complex datasets read from an HDF5 file. HDF5
doesn't have a native complex type, so they are stored as
H5T_COMPOUND types with fields such as 'r' and 'i' for the real and
... | python | def decode_complex(data, complex_names=(None, None)):
""" Decodes possibly complex data read from an HDF5 file.
Decodes possibly complex datasets read from an HDF5 file. HDF5
doesn't have a native complex type, so they are stored as
H5T_COMPOUND types with fields such as 'r' and 'i' for the real and
... | [
"def",
"decode_complex",
"(",
"data",
",",
"complex_names",
"=",
"(",
"None",
",",
"None",
")",
")",
":",
"# Now, complex types are stored in HDF5 files as an H5T_COMPOUND type",
"# with fields along the lines of ('r', 're', 'real') and ('i', 'im',",
"# 'imag', 'imaginary') for the r... | Decodes possibly complex data read from an HDF5 file.
Decodes possibly complex datasets read from an HDF5 file. HDF5
doesn't have a native complex type, so they are stored as
H5T_COMPOUND types with fields such as 'r' and 'i' for the real and
imaginary parts. As there is no standardization for field na... | [
"Decodes",
"possibly",
"complex",
"data",
"read",
"from",
"an",
"HDF5",
"file",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L1177-L1262 | train | 59,175 |
frejanordsiek/hdf5storage | hdf5storage/utilities.py | encode_complex | def encode_complex(data, complex_names):
""" Encodes complex data to having arbitrary complex field names.
Encodes complex `data` to have the real and imaginary field names
given in `complex_numbers`. This is needed because the field names
have to be set so that it can be written to an HDF5 file with t... | python | def encode_complex(data, complex_names):
""" Encodes complex data to having arbitrary complex field names.
Encodes complex `data` to have the real and imaginary field names
given in `complex_numbers`. This is needed because the field names
have to be set so that it can be written to an HDF5 file with t... | [
"def",
"encode_complex",
"(",
"data",
",",
"complex_names",
")",
":",
"# Grab the dtype name, and convert it to the right non-complex type",
"# if it isn't already one.",
"dtype_name",
"=",
"data",
".",
"dtype",
".",
"name",
"if",
"dtype_name",
"[",
"0",
":",
"7",
"]",
... | Encodes complex data to having arbitrary complex field names.
Encodes complex `data` to have the real and imaginary field names
given in `complex_numbers`. This is needed because the field names
have to be set so that it can be written to an HDF5 file with the
right field names (HDF5 doesn't have a nat... | [
"Encodes",
"complex",
"data",
"to",
"having",
"arbitrary",
"complex",
"field",
"names",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L1265-L1305 | train | 59,176 |
frejanordsiek/hdf5storage | hdf5storage/utilities.py | convert_attribute_to_string | def convert_attribute_to_string(value):
""" Convert an attribute value to a string.
Converts the attribute value to a string if possible (get ``None``
if isn't a string type).
.. versionadded:: 0.2
Parameters
----------
value :
The Attribute value.
Returns
-------
s :... | python | def convert_attribute_to_string(value):
""" Convert an attribute value to a string.
Converts the attribute value to a string if possible (get ``None``
if isn't a string type).
.. versionadded:: 0.2
Parameters
----------
value :
The Attribute value.
Returns
-------
s :... | [
"def",
"convert_attribute_to_string",
"(",
"value",
")",
":",
"if",
"value",
"is",
"None",
":",
"return",
"value",
"elif",
"(",
"sys",
".",
"hexversion",
">=",
"0x03000000",
"and",
"isinstance",
"(",
"value",
",",
"str",
")",
")",
"or",
"(",
"sys",
".",
... | Convert an attribute value to a string.
Converts the attribute value to a string if possible (get ``None``
if isn't a string type).
.. versionadded:: 0.2
Parameters
----------
value :
The Attribute value.
Returns
-------
s : str or None
The ``str`` value of the at... | [
"Convert",
"an",
"attribute",
"value",
"to",
"a",
"string",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L1334-L1367 | train | 59,177 |
frejanordsiek/hdf5storage | hdf5storage/utilities.py | set_attribute | def set_attribute(target, name, value):
""" Sets an attribute on a Dataset or Group.
If the attribute `name` doesn't exist yet, it is created. If it
already exists, it is overwritten if it differs from `value`.
Notes
-----
``set_attributes_all`` is the fastest way to set and delete
Attribu... | python | def set_attribute(target, name, value):
""" Sets an attribute on a Dataset or Group.
If the attribute `name` doesn't exist yet, it is created. If it
already exists, it is overwritten if it differs from `value`.
Notes
-----
``set_attributes_all`` is the fastest way to set and delete
Attribu... | [
"def",
"set_attribute",
"(",
"target",
",",
"name",
",",
"value",
")",
":",
"try",
":",
"target",
".",
"attrs",
".",
"modify",
"(",
"name",
",",
"value",
")",
"except",
":",
"target",
".",
"attrs",
".",
"create",
"(",
"name",
",",
"value",
")"
] | Sets an attribute on a Dataset or Group.
If the attribute `name` doesn't exist yet, it is created. If it
already exists, it is overwritten if it differs from `value`.
Notes
-----
``set_attributes_all`` is the fastest way to set and delete
Attributes in bulk.
Parameters
----------
... | [
"Sets",
"an",
"attribute",
"on",
"a",
"Dataset",
"or",
"Group",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L1442-L1470 | train | 59,178 |
frejanordsiek/hdf5storage | hdf5storage/utilities.py | set_attribute_string | def set_attribute_string(target, name, value):
""" Sets an attribute to a string on a Dataset or Group.
If the attribute `name` doesn't exist yet, it is created. If it
already exists, it is overwritten if it differs from `value`.
Notes
-----
``set_attributes_all`` is the fastest way to set and... | python | def set_attribute_string(target, name, value):
""" Sets an attribute to a string on a Dataset or Group.
If the attribute `name` doesn't exist yet, it is created. If it
already exists, it is overwritten if it differs from `value`.
Notes
-----
``set_attributes_all`` is the fastest way to set and... | [
"def",
"set_attribute_string",
"(",
"target",
",",
"name",
",",
"value",
")",
":",
"set_attribute",
"(",
"target",
",",
"name",
",",
"np",
".",
"bytes_",
"(",
"value",
")",
")"
] | Sets an attribute to a string on a Dataset or Group.
If the attribute `name` doesn't exist yet, it is created. If it
already exists, it is overwritten if it differs from `value`.
Notes
-----
``set_attributes_all`` is the fastest way to set and delete
Attributes in bulk.
Parameters
---... | [
"Sets",
"an",
"attribute",
"to",
"a",
"string",
"on",
"a",
"Dataset",
"or",
"Group",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L1473-L1499 | train | 59,179 |
frejanordsiek/hdf5storage | hdf5storage/utilities.py | set_attribute_string_array | def set_attribute_string_array(target, name, string_list):
""" Sets an attribute to an array of string on a Dataset or Group.
If the attribute `name` doesn't exist yet, it is created. If it
already exists, it is overwritten with the list of string
`string_list` (they will be vlen strings).
Notes
... | python | def set_attribute_string_array(target, name, string_list):
""" Sets an attribute to an array of string on a Dataset or Group.
If the attribute `name` doesn't exist yet, it is created. If it
already exists, it is overwritten with the list of string
`string_list` (they will be vlen strings).
Notes
... | [
"def",
"set_attribute_string_array",
"(",
"target",
",",
"name",
",",
"string_list",
")",
":",
"s_list",
"=",
"[",
"convert_to_str",
"(",
"s",
")",
"for",
"s",
"in",
"string_list",
"]",
"if",
"sys",
".",
"hexversion",
">=",
"0x03000000",
":",
"target",
"."... | Sets an attribute to an array of string on a Dataset or Group.
If the attribute `name` doesn't exist yet, it is created. If it
already exists, it is overwritten with the list of string
`string_list` (they will be vlen strings).
Notes
-----
``set_attributes_all`` is the fastest way to set and d... | [
"Sets",
"an",
"attribute",
"to",
"an",
"array",
"of",
"string",
"on",
"a",
"Dataset",
"or",
"Group",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L1502-L1534 | train | 59,180 |
frejanordsiek/hdf5storage | hdf5storage/utilities.py | set_attributes_all | def set_attributes_all(target, attributes, discard_others=True):
""" Set Attributes in bulk and optionally discard others.
Sets each Attribute in turn (modifying it in place if possible if it
is already present) and optionally discarding all other Attributes
not explicitly set. This function yields muc... | python | def set_attributes_all(target, attributes, discard_others=True):
""" Set Attributes in bulk and optionally discard others.
Sets each Attribute in turn (modifying it in place if possible if it
is already present) and optionally discarding all other Attributes
not explicitly set. This function yields muc... | [
"def",
"set_attributes_all",
"(",
"target",
",",
"attributes",
",",
"discard_others",
"=",
"True",
")",
":",
"attrs",
"=",
"target",
".",
"attrs",
"existing",
"=",
"dict",
"(",
"attrs",
".",
"items",
"(",
")",
")",
"# Generate special dtype for string arrays.",
... | Set Attributes in bulk and optionally discard others.
Sets each Attribute in turn (modifying it in place if possible if it
is already present) and optionally discarding all other Attributes
not explicitly set. This function yields much greater performance
than the required individual calls to ``set_att... | [
"Set",
"Attributes",
"in",
"bulk",
"and",
"optionally",
"discard",
"others",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L1537-L1599 | train | 59,181 |
frejanordsiek/hdf5storage | hdf5storage/__init__.py | find_thirdparty_marshaller_plugins | def find_thirdparty_marshaller_plugins():
""" Find, but don't load, all third party marshaller plugins.
Third party marshaller plugins declare the entry point
``'hdf5storage.marshallers.plugins'`` with the name being the
Marshaller API version and the target being a function that returns
a ``tuple`... | python | def find_thirdparty_marshaller_plugins():
""" Find, but don't load, all third party marshaller plugins.
Third party marshaller plugins declare the entry point
``'hdf5storage.marshallers.plugins'`` with the name being the
Marshaller API version and the target being a function that returns
a ``tuple`... | [
"def",
"find_thirdparty_marshaller_plugins",
"(",
")",
":",
"all_plugins",
"=",
"tuple",
"(",
"pkg_resources",
".",
"iter_entry_points",
"(",
"'hdf5storage.marshallers.plugins'",
")",
")",
"return",
"{",
"ver",
":",
"{",
"p",
".",
"module_name",
":",
"p",
"for",
... | Find, but don't load, all third party marshaller plugins.
Third party marshaller plugins declare the entry point
``'hdf5storage.marshallers.plugins'`` with the name being the
Marshaller API version and the target being a function that returns
a ``tuple`` or ``list`` of all the marshallers provided by t... | [
"Find",
"but",
"don",
"t",
"load",
"all",
"third",
"party",
"marshaller",
"plugins",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/__init__.py#L85-L115 | train | 59,182 |
frejanordsiek/hdf5storage | hdf5storage/__init__.py | savemat | def savemat(file_name, mdict, appendmat=True, format='7.3',
oned_as='row', store_python_metadata=True,
action_for_matlab_incompatible='error',
marshaller_collection=None, truncate_existing=False,
truncate_invalid_matlab=False, **keywords):
""" Save a dictionary of pyt... | python | def savemat(file_name, mdict, appendmat=True, format='7.3',
oned_as='row', store_python_metadata=True,
action_for_matlab_incompatible='error',
marshaller_collection=None, truncate_existing=False,
truncate_invalid_matlab=False, **keywords):
""" Save a dictionary of pyt... | [
"def",
"savemat",
"(",
"file_name",
",",
"mdict",
",",
"appendmat",
"=",
"True",
",",
"format",
"=",
"'7.3'",
",",
"oned_as",
"=",
"'row'",
",",
"store_python_metadata",
"=",
"True",
",",
"action_for_matlab_incompatible",
"=",
"'error'",
",",
"marshaller_collect... | Save a dictionary of python types to a MATLAB MAT file.
Saves the data provided in the dictionary `mdict` to a MATLAB MAT
file. `format` determines which kind/vesion of file to use. The
'7.3' version, which is HDF5 based, is handled by this package and
all types that this package can write are supporte... | [
"Save",
"a",
"dictionary",
"of",
"python",
"types",
"to",
"a",
"MATLAB",
"MAT",
"file",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/__init__.py#L1855-L1964 | train | 59,183 |
frejanordsiek/hdf5storage | hdf5storage/__init__.py | loadmat | def loadmat(file_name, mdict=None, appendmat=True,
variable_names=None,
marshaller_collection=None, **keywords):
""" Loads data to a MATLAB MAT file.
Reads data from the specified variables (or all) in a MATLAB MAT
file. There are many different formats of MAT files. This package
... | python | def loadmat(file_name, mdict=None, appendmat=True,
variable_names=None,
marshaller_collection=None, **keywords):
""" Loads data to a MATLAB MAT file.
Reads data from the specified variables (or all) in a MATLAB MAT
file. There are many different formats of MAT files. This package
... | [
"def",
"loadmat",
"(",
"file_name",
",",
"mdict",
"=",
"None",
",",
"appendmat",
"=",
"True",
",",
"variable_names",
"=",
"None",
",",
"marshaller_collection",
"=",
"None",
",",
"*",
"*",
"keywords",
")",
":",
"# Will first assume that it is the HDF5 based 7.3 for... | Loads data to a MATLAB MAT file.
Reads data from the specified variables (or all) in a MATLAB MAT
file. There are many different formats of MAT files. This package
can only handle the HDF5 based ones (the version 7.3 and later).
As SciPy's ``scipy.io.loadmat`` function can handle the earlier
forma... | [
"Loads",
"data",
"to",
"a",
"MATLAB",
"MAT",
"file",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/__init__.py#L1967-L2084 | train | 59,184 |
frejanordsiek/hdf5storage | hdf5storage/__init__.py | MarshallerCollection._update_marshallers | def _update_marshallers(self):
""" Update the full marshaller list and other data structures.
Makes a full list of both builtin and user marshallers and
rebuilds internal data structures used for looking up which
marshaller to use for reading/writing Python objects to/from
file.... | python | def _update_marshallers(self):
""" Update the full marshaller list and other data structures.
Makes a full list of both builtin and user marshallers and
rebuilds internal data structures used for looking up which
marshaller to use for reading/writing Python objects to/from
file.... | [
"def",
"_update_marshallers",
"(",
"self",
")",
":",
"# Combine all sets of marshallers.",
"self",
".",
"_marshallers",
"=",
"[",
"]",
"for",
"v",
"in",
"self",
".",
"_priority",
":",
"if",
"v",
"==",
"'builtin'",
":",
"self",
".",
"_marshallers",
".",
"exte... | Update the full marshaller list and other data structures.
Makes a full list of both builtin and user marshallers and
rebuilds internal data structures used for looking up which
marshaller to use for reading/writing Python objects to/from
file.
Also checks for whether the requi... | [
"Update",
"the",
"full",
"marshaller",
"list",
"and",
"other",
"data",
"structures",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/__init__.py#L1173-L1277 | train | 59,185 |
frejanordsiek/hdf5storage | hdf5storage/__init__.py | MarshallerCollection._import_marshaller_modules | def _import_marshaller_modules(self, m):
""" Imports the modules required by the marshaller.
Parameters
----------
m : marshaller
The marshaller to load the modules for.
Returns
-------
success : bool
Whether the modules `m` requires coul... | python | def _import_marshaller_modules(self, m):
""" Imports the modules required by the marshaller.
Parameters
----------
m : marshaller
The marshaller to load the modules for.
Returns
-------
success : bool
Whether the modules `m` requires coul... | [
"def",
"_import_marshaller_modules",
"(",
"self",
",",
"m",
")",
":",
"try",
":",
"for",
"name",
"in",
"m",
".",
"required_modules",
":",
"if",
"name",
"not",
"in",
"sys",
".",
"modules",
":",
"if",
"_has_importlib",
":",
"importlib",
".",
"import_module",... | Imports the modules required by the marshaller.
Parameters
----------
m : marshaller
The marshaller to load the modules for.
Returns
-------
success : bool
Whether the modules `m` requires could be imported
successfully or not. | [
"Imports",
"the",
"modules",
"required",
"by",
"the",
"marshaller",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/__init__.py#L1279-L1306 | train | 59,186 |
frejanordsiek/hdf5storage | hdf5storage/__init__.py | MarshallerCollection.get_marshaller_for_type | def get_marshaller_for_type(self, tp):
""" Gets the appropriate marshaller for a type.
Retrieves the marshaller, if any, that can be used to read/write
a Python object with type 'tp'. The modules it requires, if
available, will be loaded.
Parameters
----------
t... | python | def get_marshaller_for_type(self, tp):
""" Gets the appropriate marshaller for a type.
Retrieves the marshaller, if any, that can be used to read/write
a Python object with type 'tp'. The modules it requires, if
available, will be loaded.
Parameters
----------
t... | [
"def",
"get_marshaller_for_type",
"(",
"self",
",",
"tp",
")",
":",
"if",
"not",
"isinstance",
"(",
"tp",
",",
"str",
")",
":",
"tp",
"=",
"tp",
".",
"__module__",
"+",
"'.'",
"+",
"tp",
".",
"__name__",
"if",
"tp",
"in",
"self",
".",
"_types",
":"... | Gets the appropriate marshaller for a type.
Retrieves the marshaller, if any, that can be used to read/write
a Python object with type 'tp'. The modules it requires, if
available, will be loaded.
Parameters
----------
tp : type or str
Python object ``type`` ... | [
"Gets",
"the",
"appropriate",
"marshaller",
"for",
"a",
"type",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/__init__.py#L1382-L1423 | train | 59,187 |
frejanordsiek/hdf5storage | hdf5storage/__init__.py | MarshallerCollection.get_marshaller_for_type_string | def get_marshaller_for_type_string(self, type_string):
""" Gets the appropriate marshaller for a type string.
Retrieves the marshaller, if any, that can be used to read/write
a Python object with the given type string. The modules it
requires, if available, will be loaded.
Para... | python | def get_marshaller_for_type_string(self, type_string):
""" Gets the appropriate marshaller for a type string.
Retrieves the marshaller, if any, that can be used to read/write
a Python object with the given type string. The modules it
requires, if available, will be loaded.
Para... | [
"def",
"get_marshaller_for_type_string",
"(",
"self",
",",
"type_string",
")",
":",
"if",
"type_string",
"in",
"self",
".",
"_type_strings",
":",
"index",
"=",
"self",
".",
"_type_strings",
"[",
"type_string",
"]",
"m",
"=",
"self",
".",
"_marshallers",
"[",
... | Gets the appropriate marshaller for a type string.
Retrieves the marshaller, if any, that can be used to read/write
a Python object with the given type string. The modules it
requires, if available, will be loaded.
Parameters
----------
type_string : str
Typ... | [
"Gets",
"the",
"appropriate",
"marshaller",
"for",
"a",
"type",
"string",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/__init__.py#L1425-L1463 | train | 59,188 |
frejanordsiek/hdf5storage | hdf5storage/__init__.py | MarshallerCollection.get_marshaller_for_matlab_class | def get_marshaller_for_matlab_class(self, matlab_class):
""" Gets the appropriate marshaller for a MATLAB class string.
Retrieves the marshaller, if any, that can be used to read/write
a Python object associated with the given MATLAB class
string. The modules it requires, if available, ... | python | def get_marshaller_for_matlab_class(self, matlab_class):
""" Gets the appropriate marshaller for a MATLAB class string.
Retrieves the marshaller, if any, that can be used to read/write
a Python object associated with the given MATLAB class
string. The modules it requires, if available, ... | [
"def",
"get_marshaller_for_matlab_class",
"(",
"self",
",",
"matlab_class",
")",
":",
"if",
"matlab_class",
"in",
"self",
".",
"_matlab_classes",
":",
"index",
"=",
"self",
".",
"_matlab_classes",
"[",
"matlab_class",
"]",
"m",
"=",
"self",
".",
"_marshallers",
... | Gets the appropriate marshaller for a MATLAB class string.
Retrieves the marshaller, if any, that can be used to read/write
a Python object associated with the given MATLAB class
string. The modules it requires, if available, will be loaded.
Parameters
----------
matlab... | [
"Gets",
"the",
"appropriate",
"marshaller",
"for",
"a",
"MATLAB",
"class",
"string",
"."
] | 539275141dd3a4efbbbfd9bdb978f3ed59e3f05d | https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/__init__.py#L1465-L1503 | train | 59,189 |
jciskey/pygraph | pygraph/classes/directed_graph.py | DirectedGraph.new_node | def new_node(self):
"""Adds a new, blank node to the graph.
Returns the node id of the new node."""
node_id = self.generate_node_id()
node = {'id': node_id,
'edges': [],
'data': {}
}
self.nodes[node_id] = node
self._num_nodes += ... | python | def new_node(self):
"""Adds a new, blank node to the graph.
Returns the node id of the new node."""
node_id = self.generate_node_id()
node = {'id': node_id,
'edges': [],
'data': {}
}
self.nodes[node_id] = node
self._num_nodes += ... | [
"def",
"new_node",
"(",
"self",
")",
":",
"node_id",
"=",
"self",
".",
"generate_node_id",
"(",
")",
"node",
"=",
"{",
"'id'",
":",
"node_id",
",",
"'edges'",
":",
"[",
"]",
",",
"'data'",
":",
"{",
"}",
"}",
"self",
".",
"nodes",
"[",
"node_id",
... | Adds a new, blank node to the graph.
Returns the node id of the new node. | [
"Adds",
"a",
"new",
"blank",
"node",
"to",
"the",
"graph",
".",
"Returns",
"the",
"node",
"id",
"of",
"the",
"new",
"node",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/directed_graph.py#L48-L62 | train | 59,190 |
jciskey/pygraph | pygraph/classes/directed_graph.py | DirectedGraph.new_edge | def new_edge(self, node_a, node_b, cost=1):
"""Adds a new edge from node_a to node_b that has a cost.
Returns the edge id of the new edge."""
# Verify that both nodes exist in the graph
try:
self.nodes[node_a]
except KeyError:
raise NonexistentNodeError(n... | python | def new_edge(self, node_a, node_b, cost=1):
"""Adds a new edge from node_a to node_b that has a cost.
Returns the edge id of the new edge."""
# Verify that both nodes exist in the graph
try:
self.nodes[node_a]
except KeyError:
raise NonexistentNodeError(n... | [
"def",
"new_edge",
"(",
"self",
",",
"node_a",
",",
"node_b",
",",
"cost",
"=",
"1",
")",
":",
"# Verify that both nodes exist in the graph",
"try",
":",
"self",
".",
"nodes",
"[",
"node_a",
"]",
"except",
"KeyError",
":",
"raise",
"NonexistentNodeError",
"(",... | Adds a new edge from node_a to node_b that has a cost.
Returns the edge id of the new edge. | [
"Adds",
"a",
"new",
"edge",
"from",
"node_a",
"to",
"node_b",
"that",
"has",
"a",
"cost",
".",
"Returns",
"the",
"edge",
"id",
"of",
"the",
"new",
"edge",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/directed_graph.py#L64-L92 | train | 59,191 |
jciskey/pygraph | pygraph/classes/directed_graph.py | DirectedGraph.adjacent | def adjacent(self, node_a, node_b):
"""Determines whether there is an edge from node_a to node_b.
Returns True if such an edge exists, otherwise returns False."""
neighbors = self.neighbors(node_a)
return node_b in neighbors | python | def adjacent(self, node_a, node_b):
"""Determines whether there is an edge from node_a to node_b.
Returns True if such an edge exists, otherwise returns False."""
neighbors = self.neighbors(node_a)
return node_b in neighbors | [
"def",
"adjacent",
"(",
"self",
",",
"node_a",
",",
"node_b",
")",
":",
"neighbors",
"=",
"self",
".",
"neighbors",
"(",
"node_a",
")",
"return",
"node_b",
"in",
"neighbors"
] | Determines whether there is an edge from node_a to node_b.
Returns True if such an edge exists, otherwise returns False. | [
"Determines",
"whether",
"there",
"is",
"an",
"edge",
"from",
"node_a",
"to",
"node_b",
".",
"Returns",
"True",
"if",
"such",
"an",
"edge",
"exists",
"otherwise",
"returns",
"False",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/directed_graph.py#L100-L104 | train | 59,192 |
jciskey/pygraph | pygraph/classes/directed_graph.py | DirectedGraph.edge_cost | def edge_cost(self, node_a, node_b):
"""Returns the cost of moving between the edge that connects node_a to node_b.
Returns +inf if no such edge exists."""
cost = float('inf')
node_object_a = self.get_node(node_a)
for edge_id in node_object_a['edges']:
edge = self.get... | python | def edge_cost(self, node_a, node_b):
"""Returns the cost of moving between the edge that connects node_a to node_b.
Returns +inf if no such edge exists."""
cost = float('inf')
node_object_a = self.get_node(node_a)
for edge_id in node_object_a['edges']:
edge = self.get... | [
"def",
"edge_cost",
"(",
"self",
",",
"node_a",
",",
"node_b",
")",
":",
"cost",
"=",
"float",
"(",
"'inf'",
")",
"node_object_a",
"=",
"self",
".",
"get_node",
"(",
"node_a",
")",
"for",
"edge_id",
"in",
"node_object_a",
"[",
"'edges'",
"]",
":",
"edg... | Returns the cost of moving between the edge that connects node_a to node_b.
Returns +inf if no such edge exists. | [
"Returns",
"the",
"cost",
"of",
"moving",
"between",
"the",
"edge",
"that",
"connects",
"node_a",
"to",
"node_b",
".",
"Returns",
"+",
"inf",
"if",
"no",
"such",
"edge",
"exists",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/directed_graph.py#L106-L117 | train | 59,193 |
jciskey/pygraph | pygraph/classes/directed_graph.py | DirectedGraph.get_node | def get_node(self, node_id):
"""Returns the node object identified by "node_id"."""
try:
node_object = self.nodes[node_id]
except KeyError:
raise NonexistentNodeError(node_id)
return node_object | python | def get_node(self, node_id):
"""Returns the node object identified by "node_id"."""
try:
node_object = self.nodes[node_id]
except KeyError:
raise NonexistentNodeError(node_id)
return node_object | [
"def",
"get_node",
"(",
"self",
",",
"node_id",
")",
":",
"try",
":",
"node_object",
"=",
"self",
".",
"nodes",
"[",
"node_id",
"]",
"except",
"KeyError",
":",
"raise",
"NonexistentNodeError",
"(",
"node_id",
")",
"return",
"node_object"
] | Returns the node object identified by "node_id". | [
"Returns",
"the",
"node",
"object",
"identified",
"by",
"node_id",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/directed_graph.py#L119-L125 | train | 59,194 |
jciskey/pygraph | pygraph/classes/directed_graph.py | DirectedGraph.get_edge | def get_edge(self, edge_id):
"""Returns the edge object identified by "edge_id"."""
try:
edge_object = self.edges[edge_id]
except KeyError:
raise NonexistentEdgeError(edge_id)
return edge_object | python | def get_edge(self, edge_id):
"""Returns the edge object identified by "edge_id"."""
try:
edge_object = self.edges[edge_id]
except KeyError:
raise NonexistentEdgeError(edge_id)
return edge_object | [
"def",
"get_edge",
"(",
"self",
",",
"edge_id",
")",
":",
"try",
":",
"edge_object",
"=",
"self",
".",
"edges",
"[",
"edge_id",
"]",
"except",
"KeyError",
":",
"raise",
"NonexistentEdgeError",
"(",
"edge_id",
")",
"return",
"edge_object"
] | Returns the edge object identified by "edge_id". | [
"Returns",
"the",
"edge",
"object",
"identified",
"by",
"edge_id",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/directed_graph.py#L135-L141 | train | 59,195 |
jciskey/pygraph | pygraph/classes/directed_graph.py | DirectedGraph.delete_edge_by_nodes | def delete_edge_by_nodes(self, node_a, node_b):
"""Removes all the edges from node_a to node_b from the graph."""
node = self.get_node(node_a)
# Determine the edge ids
edge_ids = []
for e_id in node['edges']:
edge = self.get_edge(e_id)
if edge['vertices']... | python | def delete_edge_by_nodes(self, node_a, node_b):
"""Removes all the edges from node_a to node_b from the graph."""
node = self.get_node(node_a)
# Determine the edge ids
edge_ids = []
for e_id in node['edges']:
edge = self.get_edge(e_id)
if edge['vertices']... | [
"def",
"delete_edge_by_nodes",
"(",
"self",
",",
"node_a",
",",
"node_b",
")",
":",
"node",
"=",
"self",
".",
"get_node",
"(",
"node_a",
")",
"# Determine the edge ids",
"edge_ids",
"=",
"[",
"]",
"for",
"e_id",
"in",
"node",
"[",
"'edges'",
"]",
":",
"e... | Removes all the edges from node_a to node_b from the graph. | [
"Removes",
"all",
"the",
"edges",
"from",
"node_a",
"to",
"node_b",
"from",
"the",
"graph",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/directed_graph.py#L168-L181 | train | 59,196 |
jciskey/pygraph | pygraph/classes/directed_graph.py | DirectedGraph.delete_node | def delete_node(self, node_id):
"""Removes the node identified by node_id from the graph."""
node = self.get_node(node_id)
# Remove all edges from the node
for e in node['edges']:
self.delete_edge_by_id(e)
# Remove all edges to the node
edges = [edge_id for ... | python | def delete_node(self, node_id):
"""Removes the node identified by node_id from the graph."""
node = self.get_node(node_id)
# Remove all edges from the node
for e in node['edges']:
self.delete_edge_by_id(e)
# Remove all edges to the node
edges = [edge_id for ... | [
"def",
"delete_node",
"(",
"self",
",",
"node_id",
")",
":",
"node",
"=",
"self",
".",
"get_node",
"(",
"node_id",
")",
"# Remove all edges from the node",
"for",
"e",
"in",
"node",
"[",
"'edges'",
"]",
":",
"self",
".",
"delete_edge_by_id",
"(",
"e",
")",... | Removes the node identified by node_id from the graph. | [
"Removes",
"the",
"node",
"identified",
"by",
"node_id",
"from",
"the",
"graph",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/directed_graph.py#L183-L199 | train | 59,197 |
jciskey/pygraph | pygraph/classes/directed_graph.py | DirectedGraph.move_edge_source | def move_edge_source(self, edge_id, node_a, node_b):
"""Moves an edge originating from node_a so that it originates from node_b."""
# Grab the edge
edge = self.get_edge(edge_id)
# Alter the vertices
edge['vertices'] = (node_b, edge['vertices'][1])
# Remove the edge from... | python | def move_edge_source(self, edge_id, node_a, node_b):
"""Moves an edge originating from node_a so that it originates from node_b."""
# Grab the edge
edge = self.get_edge(edge_id)
# Alter the vertices
edge['vertices'] = (node_b, edge['vertices'][1])
# Remove the edge from... | [
"def",
"move_edge_source",
"(",
"self",
",",
"edge_id",
",",
"node_a",
",",
"node_b",
")",
":",
"# Grab the edge",
"edge",
"=",
"self",
".",
"get_edge",
"(",
"edge_id",
")",
"# Alter the vertices",
"edge",
"[",
"'vertices'",
"]",
"=",
"(",
"node_b",
",",
"... | Moves an edge originating from node_a so that it originates from node_b. | [
"Moves",
"an",
"edge",
"originating",
"from",
"node_a",
"so",
"that",
"it",
"originates",
"from",
"node_b",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/directed_graph.py#L201-L215 | train | 59,198 |
jciskey/pygraph | pygraph/classes/directed_graph.py | DirectedGraph.get_edge_ids_by_node_ids | def get_edge_ids_by_node_ids(self, node_a, node_b):
"""Returns a list of edge ids connecting node_a to node_b."""
# Check if the nodes are adjacent
if not self.adjacent(node_a, node_b):
return []
# They're adjacent, so pull the list of edges from node_a and determine which o... | python | def get_edge_ids_by_node_ids(self, node_a, node_b):
"""Returns a list of edge ids connecting node_a to node_b."""
# Check if the nodes are adjacent
if not self.adjacent(node_a, node_b):
return []
# They're adjacent, so pull the list of edges from node_a and determine which o... | [
"def",
"get_edge_ids_by_node_ids",
"(",
"self",
",",
"node_a",
",",
"node_b",
")",
":",
"# Check if the nodes are adjacent",
"if",
"not",
"self",
".",
"adjacent",
"(",
"node_a",
",",
"node_b",
")",
":",
"return",
"[",
"]",
"# They're adjacent, so pull the list of ed... | Returns a list of edge ids connecting node_a to node_b. | [
"Returns",
"a",
"list",
"of",
"edge",
"ids",
"connecting",
"node_a",
"to",
"node_b",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/directed_graph.py#L225-L233 | train | 59,199 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.