repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
bapakode/OmMongo | ommongo/session.py | Session.execute_update | def execute_update(self, update, safe=False):
''' Execute an update expression. Should generally only be called implicitly.
'''
# safe = self.safe
# if update.safe is not None:
# safe = remove.safe
assert len(update.update_data) > 0
self.queue.append(UpdateOp(self.transaction_id, self, update.query... | python | def execute_update(self, update, safe=False):
''' Execute an update expression. Should generally only be called implicitly.
'''
# safe = self.safe
# if update.safe is not None:
# safe = remove.safe
assert len(update.update_data) > 0
self.queue.append(UpdateOp(self.transaction_id, self, update.query... | [
"def",
"execute_update",
"(",
"self",
",",
"update",
",",
"safe",
"=",
"False",
")",
":",
"# safe = self.safe",
"# if update.safe is not None:",
"# safe = remove.safe",
"assert",
"len",
"(",
"update",
".",
"update_data",
")",
">",
"0",
"self",
".",
"queue",
... | Execute an update expression. Should generally only be called implicitly. | [
"Execute",
"an",
"update",
"expression",
".",
"Should",
"generally",
"only",
"be",
"called",
"implicitly",
"."
] | train | https://github.com/bapakode/OmMongo/blob/52b5a5420516dc709f2d2eb065818c7973991ce3/ommongo/session.py#L344-L355 |
bapakode/OmMongo | ommongo/session.py | Session.clear_queue | def clear_queue(self, trans_id=None):
''' Clear the queue of database operations without executing any of
the pending operations'''
if not self.queue:
return
if trans_id is None:
self.queue = []
return
for index, op in enumerate(self.queue):
if op.trans_id == trans_id:
break
self.queue = ... | python | def clear_queue(self, trans_id=None):
''' Clear the queue of database operations without executing any of
the pending operations'''
if not self.queue:
return
if trans_id is None:
self.queue = []
return
for index, op in enumerate(self.queue):
if op.trans_id == trans_id:
break
self.queue = ... | [
"def",
"clear_queue",
"(",
"self",
",",
"trans_id",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"queue",
":",
"return",
"if",
"trans_id",
"is",
"None",
":",
"self",
".",
"queue",
"=",
"[",
"]",
"return",
"for",
"index",
",",
"op",
"in",
"enume... | Clear the queue of database operations without executing any of
the pending operations | [
"Clear",
"the",
"queue",
"of",
"database",
"operations",
"without",
"executing",
"any",
"of",
"the",
"pending",
"operations"
] | train | https://github.com/bapakode/OmMongo/blob/52b5a5420516dc709f2d2eb065818c7973991ce3/ommongo/session.py#L425-L437 |
bapakode/OmMongo | ommongo/session.py | Session.clear_collection | def clear_collection(self, *classes):
''' Clear all objects from the collections associated with the
objects in `*cls`. **use with caution!**'''
for c in classes:
self.queue.append(ClearCollectionOp(self.transaction_id, self, c))
if self.autoflush:
self.flush() | python | def clear_collection(self, *classes):
''' Clear all objects from the collections associated with the
objects in `*cls`. **use with caution!**'''
for c in classes:
self.queue.append(ClearCollectionOp(self.transaction_id, self, c))
if self.autoflush:
self.flush() | [
"def",
"clear_collection",
"(",
"self",
",",
"*",
"classes",
")",
":",
"for",
"c",
"in",
"classes",
":",
"self",
".",
"queue",
".",
"append",
"(",
"ClearCollectionOp",
"(",
"self",
".",
"transaction_id",
",",
"self",
",",
"c",
")",
")",
"if",
"self",
... | Clear all objects from the collections associated with the
objects in `*cls`. **use with caution!** | [
"Clear",
"all",
"objects",
"from",
"the",
"collections",
"associated",
"with",
"the",
"objects",
"in",
"*",
"cls",
".",
"**",
"use",
"with",
"caution!",
"**"
] | train | https://github.com/bapakode/OmMongo/blob/52b5a5420516dc709f2d2eb065818c7973991ce3/ommongo/session.py#L442-L448 |
bapakode/OmMongo | ommongo/session.py | Session.flush | def flush(self, safe=None):
''' Perform all database operations currently in the queue'''
result = None
for index, op in enumerate(self.queue):
try:
result = op.execute()
except:
self.clear_queue()
self.clear_cache()
raise
self.clear_queue()
return result | python | def flush(self, safe=None):
''' Perform all database operations currently in the queue'''
result = None
for index, op in enumerate(self.queue):
try:
result = op.execute()
except:
self.clear_queue()
self.clear_cache()
raise
self.clear_queue()
return result | [
"def",
"flush",
"(",
"self",
",",
"safe",
"=",
"None",
")",
":",
"result",
"=",
"None",
"for",
"index",
",",
"op",
"in",
"enumerate",
"(",
"self",
".",
"queue",
")",
":",
"try",
":",
"result",
"=",
"op",
".",
"execute",
"(",
")",
"except",
":",
... | Perform all database operations currently in the queue | [
"Perform",
"all",
"database",
"operations",
"currently",
"in",
"the",
"queue"
] | train | https://github.com/bapakode/OmMongo/blob/52b5a5420516dc709f2d2eb065818c7973991ce3/ommongo/session.py#L450-L461 |
bapakode/OmMongo | ommongo/session.py | Session.refresh | def refresh(self, document):
""" Load a new copy of a document from the database. does not
replace the old one """
try:
old_cache_size = self.cache_size
self.cache_size = 0
obj = self.query(type(document)).filter_by(mongo_id=document.mongo_id).one()
finally:
self.cache_size = old_cache_size
self... | python | def refresh(self, document):
""" Load a new copy of a document from the database. does not
replace the old one """
try:
old_cache_size = self.cache_size
self.cache_size = 0
obj = self.query(type(document)).filter_by(mongo_id=document.mongo_id).one()
finally:
self.cache_size = old_cache_size
self... | [
"def",
"refresh",
"(",
"self",
",",
"document",
")",
":",
"try",
":",
"old_cache_size",
"=",
"self",
".",
"cache_size",
"self",
".",
"cache_size",
"=",
"0",
"obj",
"=",
"self",
".",
"query",
"(",
"type",
"(",
"document",
")",
")",
".",
"filter_by",
"... | Load a new copy of a document from the database. does not
replace the old one | [
"Load",
"a",
"new",
"copy",
"of",
"a",
"document",
"from",
"the",
"database",
".",
"does",
"not",
"replace",
"the",
"old",
"one"
] | train | https://github.com/bapakode/OmMongo/blob/52b5a5420516dc709f2d2eb065818c7973991ce3/ommongo/session.py#L492-L502 |
bapakode/OmMongo | ommongo/session.py | Session.clone | def clone(self, document):
''' Serialize a document, remove its _id, and deserialize as a new
object '''
wrapped = document.wrap()
if '_id' in wrapped:
del wrapped['_id']
return type(document).unwrap(wrapped, session=self) | python | def clone(self, document):
''' Serialize a document, remove its _id, and deserialize as a new
object '''
wrapped = document.wrap()
if '_id' in wrapped:
del wrapped['_id']
return type(document).unwrap(wrapped, session=self) | [
"def",
"clone",
"(",
"self",
",",
"document",
")",
":",
"wrapped",
"=",
"document",
".",
"wrap",
"(",
")",
"if",
"'_id'",
"in",
"wrapped",
":",
"del",
"wrapped",
"[",
"'_id'",
"]",
"return",
"type",
"(",
"document",
")",
".",
"unwrap",
"(",
"wrapped"... | Serialize a document, remove its _id, and deserialize as a new
object | [
"Serialize",
"a",
"document",
"remove",
"its",
"_id",
"and",
"deserialize",
"as",
"a",
"new",
"object"
] | train | https://github.com/bapakode/OmMongo/blob/52b5a5420516dc709f2d2eb065818c7973991ce3/ommongo/session.py#L504-L511 |
teddychoi/BynamoDB | bynamodb/patcher.py | patch_dynamodb_connection | def patch_dynamodb_connection(**kwargs):
""":class:`boto.dynamodb2.layer1.DynamoDBConnection` patcher.
It partially applies the keyword arguments to the
:class:`boto.dynamodb2.layer1.DynamoDBConnection` initializer method.
The common usage of this function would be patching host and port
to the loc... | python | def patch_dynamodb_connection(**kwargs):
""":class:`boto.dynamodb2.layer1.DynamoDBConnection` patcher.
It partially applies the keyword arguments to the
:class:`boto.dynamodb2.layer1.DynamoDBConnection` initializer method.
The common usage of this function would be patching host and port
to the loc... | [
"def",
"patch_dynamodb_connection",
"(",
"*",
"*",
"kwargs",
")",
":",
"if",
"hasattr",
"(",
"DynamoDBConnection",
",",
"'__original_init__'",
")",
":",
"return",
"DynamoDBConnection",
".",
"__original_init__",
"=",
"DynamoDBConnection",
".",
"__init__",
"def",
"ini... | :class:`boto.dynamodb2.layer1.DynamoDBConnection` patcher.
It partially applies the keyword arguments to the
:class:`boto.dynamodb2.layer1.DynamoDBConnection` initializer method.
The common usage of this function would be patching host and port
to the local DynamoDB or remote DynamoDB as the project co... | [
":",
"class",
":",
"boto",
".",
"dynamodb2",
".",
"layer1",
".",
"DynamoDBConnection",
"patcher",
"."
] | train | https://github.com/teddychoi/BynamoDB/blob/9b143d0554c89fb8edbfb99db5542e48bd126b39/bynamodb/patcher.py#L13-L32 |
chop-dbhi/varify-data-warehouse | vdw/samples/migrations/0003_remap_names_and_labels.py | Migration.forwards | def forwards(self, orm):
"Write your forwards methods here."
orm.Project.objects.update(label=F('name'))
orm.Cohort.objects.update(label=F('name'))
orm.Sample.objects.update(name=F('label')) | python | def forwards(self, orm):
"Write your forwards methods here."
orm.Project.objects.update(label=F('name'))
orm.Cohort.objects.update(label=F('name'))
orm.Sample.objects.update(name=F('label')) | [
"def",
"forwards",
"(",
"self",
",",
"orm",
")",
":",
"orm",
".",
"Project",
".",
"objects",
".",
"update",
"(",
"label",
"=",
"F",
"(",
"'name'",
")",
")",
"orm",
".",
"Cohort",
".",
"objects",
".",
"update",
"(",
"label",
"=",
"F",
"(",
"'name'... | Write your forwards methods here. | [
"Write",
"your",
"forwards",
"methods",
"here",
"."
] | train | https://github.com/chop-dbhi/varify-data-warehouse/blob/1600ee1bc5fae6c68fd03b23624467298570cca8/vdw/samples/migrations/0003_remap_names_and_labels.py#L10-L14 |
chop-dbhi/varify-data-warehouse | vdw/samples/migrations/0003_remap_names_and_labels.py | Migration.backwards | def backwards(self, orm):
"Write your backwards methods here."
orm.Project.objects.update(label=None)
orm.Cohort.objects.update(label=None)
orm.Sample.objects.update(name=None) | python | def backwards(self, orm):
"Write your backwards methods here."
orm.Project.objects.update(label=None)
orm.Cohort.objects.update(label=None)
orm.Sample.objects.update(name=None) | [
"def",
"backwards",
"(",
"self",
",",
"orm",
")",
":",
"orm",
".",
"Project",
".",
"objects",
".",
"update",
"(",
"label",
"=",
"None",
")",
"orm",
".",
"Cohort",
".",
"objects",
".",
"update",
"(",
"label",
"=",
"None",
")",
"orm",
".",
"Sample",
... | Write your backwards methods here. | [
"Write",
"your",
"backwards",
"methods",
"here",
"."
] | train | https://github.com/chop-dbhi/varify-data-warehouse/blob/1600ee1bc5fae6c68fd03b23624467298570cca8/vdw/samples/migrations/0003_remap_names_and_labels.py#L16-L20 |
Venti-/pubcode | pubcode/code128.py | Code128.width | def width(self, add_quiet_zone=False):
"""Return the barcodes width in modules for a given data and character set combination.
:param add_quiet_zone: Whether quiet zone should be included in the width.
:return: Width of barcode in modules, which for images translates to pixels.
"""
... | python | def width(self, add_quiet_zone=False):
"""Return the barcodes width in modules for a given data and character set combination.
:param add_quiet_zone: Whether quiet zone should be included in the width.
:return: Width of barcode in modules, which for images translates to pixels.
"""
... | [
"def",
"width",
"(",
"self",
",",
"add_quiet_zone",
"=",
"False",
")",
":",
"quiet_zone",
"=",
"self",
".",
"quiet_zone",
"if",
"add_quiet_zone",
"else",
"0",
"return",
"len",
"(",
"self",
".",
"modules",
")",
"+",
"2",
"*",
"quiet_zone"
] | Return the barcodes width in modules for a given data and character set combination.
:param add_quiet_zone: Whether quiet zone should be included in the width.
:return: Width of barcode in modules, which for images translates to pixels. | [
"Return",
"the",
"barcodes",
"width",
"in",
"modules",
"for",
"a",
"given",
"data",
"and",
"character",
"set",
"combination",
"."
] | train | https://github.com/Venti-/pubcode/blob/92af28ffbc524538ce33f17fcd08fb825641ad56/pubcode/code128.py#L133-L141 |
Venti-/pubcode | pubcode/code128.py | Code128._validate_charset | def _validate_charset(data, charset):
""""Validate that the charset is correct and throw an error if it isn't."""
if len(charset) > 1:
charset_data_length = 0
for symbol_charset in charset:
if symbol_charset not in ('A', 'B', 'C'):
raise Code12... | python | def _validate_charset(data, charset):
""""Validate that the charset is correct and throw an error if it isn't."""
if len(charset) > 1:
charset_data_length = 0
for symbol_charset in charset:
if symbol_charset not in ('A', 'B', 'C'):
raise Code12... | [
"def",
"_validate_charset",
"(",
"data",
",",
"charset",
")",
":",
"if",
"len",
"(",
"charset",
")",
">",
"1",
":",
"charset_data_length",
"=",
"0",
"for",
"symbol_charset",
"in",
"charset",
":",
"if",
"symbol_charset",
"not",
"in",
"(",
"'A'",
",",
"'B'... | Validate that the charset is correct and throw an error if it isn't. | [
"Validate",
"that",
"the",
"charset",
"is",
"correct",
"and",
"throw",
"an",
"error",
"if",
"it",
"isn",
"t",
"."
] | train | https://github.com/Venti-/pubcode/blob/92af28ffbc524538ce33f17fcd08fb825641ad56/pubcode/code128.py#L144-L158 |
Venti-/pubcode | pubcode/code128.py | Code128._encode | def _encode(cls, data, charsets):
"""Encode the data using the character sets in charsets.
:param data: Data to be encoded.
:param charsets: Sequence of charsets that are used to encode the barcode.
Must be the exact amount of symbols needed to encode the data.
... | python | def _encode(cls, data, charsets):
"""Encode the data using the character sets in charsets.
:param data: Data to be encoded.
:param charsets: Sequence of charsets that are used to encode the barcode.
Must be the exact amount of symbols needed to encode the data.
... | [
"def",
"_encode",
"(",
"cls",
",",
"data",
",",
"charsets",
")",
":",
"result",
"=",
"[",
"]",
"charset",
"=",
"charsets",
"[",
"0",
"]",
"start_symbol",
"=",
"cls",
".",
"_start_codes",
"[",
"charset",
"]",
"result",
".",
"append",
"(",
"cls",
".",
... | Encode the data using the character sets in charsets.
:param data: Data to be encoded.
:param charsets: Sequence of charsets that are used to encode the barcode.
Must be the exact amount of symbols needed to encode the data.
:return: List of the symbol values representi... | [
"Encode",
"the",
"data",
"using",
"the",
"character",
"sets",
"in",
"charsets",
"."
] | train | https://github.com/Venti-/pubcode/blob/92af28ffbc524538ce33f17fcd08fb825641ad56/pubcode/code128.py#L161-L202 |
Venti-/pubcode | pubcode/code128.py | Code128.symbols | def symbols(self):
"""List of the coded symbols as strings, with special characters included."""
def _iter_symbols(symbol_values):
# The initial charset doesn't matter, as the start codes have the same symbol values in all charsets.
charset = 'A'
shift_charset = None... | python | def symbols(self):
"""List of the coded symbols as strings, with special characters included."""
def _iter_symbols(symbol_values):
# The initial charset doesn't matter, as the start codes have the same symbol values in all charsets.
charset = 'A'
shift_charset = None... | [
"def",
"symbols",
"(",
"self",
")",
":",
"def",
"_iter_symbols",
"(",
"symbol_values",
")",
":",
"# The initial charset doesn't matter, as the start codes have the same symbol values in all charsets.",
"charset",
"=",
"'A'",
"shift_charset",
"=",
"None",
"for",
"symbol_value"... | List of the coded symbols as strings, with special characters included. | [
"List",
"of",
"the",
"coded",
"symbols",
"as",
"strings",
"with",
"special",
"characters",
"included",
"."
] | train | https://github.com/Venti-/pubcode/blob/92af28ffbc524538ce33f17fcd08fb825641ad56/pubcode/code128.py#L205-L232 |
Venti-/pubcode | pubcode/code128.py | Code128.bars | def bars(self):
"""A string of the bar and space weights of the barcode. Starting with a bar and alternating.
>>> barcode = Code128("Hello!", charset='B')
>>> barcode.bars
'2112142311131122142211142211141341112221221212412331112'
:rtype: string
"""
return ''.joi... | python | def bars(self):
"""A string of the bar and space weights of the barcode. Starting with a bar and alternating.
>>> barcode = Code128("Hello!", charset='B')
>>> barcode.bars
'2112142311131122142211142211141341112221221212412331112'
:rtype: string
"""
return ''.joi... | [
"def",
"bars",
"(",
"self",
")",
":",
"return",
"''",
".",
"join",
"(",
"map",
"(",
"(",
"lambda",
"val",
":",
"self",
".",
"_val2bars",
"[",
"val",
"]",
")",
",",
"self",
".",
"symbol_values",
")",
")"
] | A string of the bar and space weights of the barcode. Starting with a bar and alternating.
>>> barcode = Code128("Hello!", charset='B')
>>> barcode.bars
'2112142311131122142211142211141341112221221212412331112'
:rtype: string | [
"A",
"string",
"of",
"the",
"bar",
"and",
"space",
"weights",
"of",
"the",
"barcode",
".",
"Starting",
"with",
"a",
"bar",
"and",
"alternating",
"."
] | train | https://github.com/Venti-/pubcode/blob/92af28ffbc524538ce33f17fcd08fb825641ad56/pubcode/code128.py#L235-L244 |
Venti-/pubcode | pubcode/code128.py | Code128.modules | def modules(self):
"""A list of the modules, with 0 representing a bar and 1 representing a space.
>>> barcode = Code128("Hello!", charset='B')
>>> barcode.modules # doctest: +ELLIPSIS
[0, 0, 1, 0, 1, 1, 0, 1, ..., 0, 0, 0, 1, 0, 1, 0, 0]
:rtype: list[int]
"""
... | python | def modules(self):
"""A list of the modules, with 0 representing a bar and 1 representing a space.
>>> barcode = Code128("Hello!", charset='B')
>>> barcode.modules # doctest: +ELLIPSIS
[0, 0, 1, 0, 1, 1, 0, 1, ..., 0, 0, 0, 1, 0, 1, 0, 0]
:rtype: list[int]
"""
... | [
"def",
"modules",
"(",
"self",
")",
":",
"def",
"_iterate_modules",
"(",
"bars",
")",
":",
"is_bar",
"=",
"True",
"for",
"char",
"in",
"map",
"(",
"int",
",",
"bars",
")",
":",
"while",
"char",
">",
"0",
":",
"char",
"-=",
"1",
"yield",
"0",
"if"... | A list of the modules, with 0 representing a bar and 1 representing a space.
>>> barcode = Code128("Hello!", charset='B')
>>> barcode.modules # doctest: +ELLIPSIS
[0, 0, 1, 0, 1, 1, 0, 1, ..., 0, 0, 0, 1, 0, 1, 0, 0]
:rtype: list[int] | [
"A",
"list",
"of",
"the",
"modules",
"with",
"0",
"representing",
"a",
"bar",
"and",
"1",
"representing",
"a",
"space",
"."
] | train | https://github.com/Venti-/pubcode/blob/92af28ffbc524538ce33f17fcd08fb825641ad56/pubcode/code128.py#L247-L264 |
Venti-/pubcode | pubcode/code128.py | Code128._calc_checksum | def _calc_checksum(values):
"""Calculate the symbol check character."""
checksum = values[0]
for index, value in enumerate(values):
checksum += index * value
return checksum % 103 | python | def _calc_checksum(values):
"""Calculate the symbol check character."""
checksum = values[0]
for index, value in enumerate(values):
checksum += index * value
return checksum % 103 | [
"def",
"_calc_checksum",
"(",
"values",
")",
":",
"checksum",
"=",
"values",
"[",
"0",
"]",
"for",
"index",
",",
"value",
"in",
"enumerate",
"(",
"values",
")",
":",
"checksum",
"+=",
"index",
"*",
"value",
"return",
"checksum",
"%",
"103"
] | Calculate the symbol check character. | [
"Calculate",
"the",
"symbol",
"check",
"character",
"."
] | train | https://github.com/Venti-/pubcode/blob/92af28ffbc524538ce33f17fcd08fb825641ad56/pubcode/code128.py#L267-L272 |
Venti-/pubcode | pubcode/code128.py | Code128.image | def image(self, height=1, module_width=1, add_quiet_zone=True):
"""Get the barcode as PIL.Image.
By default the image is one pixel high and the number of modules pixels wide, with 10 empty modules added to
each side to act as the quiet zone. The size can be modified by setting height and module... | python | def image(self, height=1, module_width=1, add_quiet_zone=True):
"""Get the barcode as PIL.Image.
By default the image is one pixel high and the number of modules pixels wide, with 10 empty modules added to
each side to act as the quiet zone. The size can be modified by setting height and module... | [
"def",
"image",
"(",
"self",
",",
"height",
"=",
"1",
",",
"module_width",
"=",
"1",
",",
"add_quiet_zone",
"=",
"True",
")",
":",
"if",
"Image",
"is",
"None",
":",
"raise",
"Code128",
".",
"MissingDependencyError",
"(",
"\"PIL module is required to use image ... | Get the barcode as PIL.Image.
By default the image is one pixel high and the number of modules pixels wide, with 10 empty modules added to
each side to act as the quiet zone. The size can be modified by setting height and module_width, but if used in
a web page it might be a good idea to do the... | [
"Get",
"the",
"barcode",
"as",
"PIL",
".",
"Image",
"."
] | train | https://github.com/Venti-/pubcode/blob/92af28ffbc524538ce33f17fcd08fb825641ad56/pubcode/code128.py#L274-L304 |
Venti-/pubcode | pubcode/code128.py | Code128.data_url | def data_url(self, image_format='png', add_quiet_zone=True):
"""Get a data URL representing the barcode.
>>> barcode = Code128('Hello!', charset='B')
>>> barcode.data_url() # doctest: +ELLIPSIS
'data:image/png;base64,...'
:param image_format: Either 'png' or 'bmp'.
:pa... | python | def data_url(self, image_format='png', add_quiet_zone=True):
"""Get a data URL representing the barcode.
>>> barcode = Code128('Hello!', charset='B')
>>> barcode.data_url() # doctest: +ELLIPSIS
'data:image/png;base64,...'
:param image_format: Either 'png' or 'bmp'.
:pa... | [
"def",
"data_url",
"(",
"self",
",",
"image_format",
"=",
"'png'",
",",
"add_quiet_zone",
"=",
"True",
")",
":",
"memory_file",
"=",
"io",
".",
"BytesIO",
"(",
")",
"pil_image",
"=",
"self",
".",
"image",
"(",
"add_quiet_zone",
"=",
"add_quiet_zone",
")",
... | Get a data URL representing the barcode.
>>> barcode = Code128('Hello!', charset='B')
>>> barcode.data_url() # doctest: +ELLIPSIS
'data:image/png;base64,...'
:param image_format: Either 'png' or 'bmp'.
:param add_quiet_zone: Add a 10 white pixels on either side of the barcode.... | [
"Get",
"a",
"data",
"URL",
"representing",
"the",
"barcode",
"."
] | train | https://github.com/Venti-/pubcode/blob/92af28ffbc524538ce33f17fcd08fb825641ad56/pubcode/code128.py#L306-L346 |
uw-it-aca/uw-restclients | restclients/dao_implementation/o365.py | Live._get_auth_token | def _get_auth_token(self):
"""Given the office356 tenant and client id, and client secret
acquire a new authorization token
"""
url = '/%s/oauth2/token' % getattr(
settings, 'RESTCLIENTS_O365_TENANT', 'test')
headers = {'Accept': 'application/json'}
data = {
... | python | def _get_auth_token(self):
"""Given the office356 tenant and client id, and client secret
acquire a new authorization token
"""
url = '/%s/oauth2/token' % getattr(
settings, 'RESTCLIENTS_O365_TENANT', 'test')
headers = {'Accept': 'application/json'}
data = {
... | [
"def",
"_get_auth_token",
"(",
"self",
")",
":",
"url",
"=",
"'/%s/oauth2/token'",
"%",
"getattr",
"(",
"settings",
",",
"'RESTCLIENTS_O365_TENANT'",
",",
"'test'",
")",
"headers",
"=",
"{",
"'Accept'",
":",
"'application/json'",
"}",
"data",
"=",
"{",
"\"gran... | Given the office356 tenant and client id, and client secret
acquire a new authorization token | [
"Given",
"the",
"office356",
"tenant",
"and",
"client",
"id",
"and",
"client",
"secret",
"acquire",
"a",
"new",
"authorization",
"token"
] | train | https://github.com/uw-it-aca/uw-restclients/blob/e12dcd32bf5296b6ebdf71798031594afb7852cb/restclients/dao_implementation/o365.py#L150-L186 |
toumorokoshi/miura | miura/utils.py | get_method_from_module | def get_method_from_module(module_path, method_name):
""" from a valid python module path, get the run method name passed """
top_module = __import__(module_path)
module = top_module
# we tunnel down until we find the module we want
for submodule_name in module_path.split('.')[1:]:
module =... | python | def get_method_from_module(module_path, method_name):
""" from a valid python module path, get the run method name passed """
top_module = __import__(module_path)
module = top_module
# we tunnel down until we find the module we want
for submodule_name in module_path.split('.')[1:]:
module =... | [
"def",
"get_method_from_module",
"(",
"module_path",
",",
"method_name",
")",
":",
"top_module",
"=",
"__import__",
"(",
"module_path",
")",
"module",
"=",
"top_module",
"# we tunnel down until we find the module we want",
"for",
"submodule_name",
"in",
"module_path",
"."... | from a valid python module path, get the run method name passed | [
"from",
"a",
"valid",
"python",
"module",
"path",
"get",
"the",
"run",
"method",
"name",
"passed"
] | train | https://github.com/toumorokoshi/miura/blob/f23e270a9507e5946798b1e897220c9fb1b8d5fa/miura/utils.py#L5-L16 |
yufeiminds/toolkit | toolkit/tpl.py | proxy_register | def proxy_register(register_funtion):
"""
Proxy a function to a register function.
:param register_funtion: a function need to proxy.
:return: a proxy wrapper
"""
def wrapper(function):
@functools.wraps(function)
def register(excepted, filter_function=None):
if inspe... | python | def proxy_register(register_funtion):
"""
Proxy a function to a register function.
:param register_funtion: a function need to proxy.
:return: a proxy wrapper
"""
def wrapper(function):
@functools.wraps(function)
def register(excepted, filter_function=None):
if inspe... | [
"def",
"proxy_register",
"(",
"register_funtion",
")",
":",
"def",
"wrapper",
"(",
"function",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"function",
")",
"def",
"register",
"(",
"excepted",
",",
"filter_function",
"=",
"None",
")",
":",
"if",
"inspect... | Proxy a function to a register function.
:param register_funtion: a function need to proxy.
:return: a proxy wrapper | [
"Proxy",
"a",
"function",
"to",
"a",
"register",
"function",
"."
] | train | https://github.com/yufeiminds/toolkit/blob/2d3986f2711f0ee9ee9cd75c25752ef4d0f42ff7/toolkit/tpl.py#L30-L55 |
yufeiminds/toolkit | toolkit/tpl.py | create_env_by_folder | def create_env_by_folder(folder):
"""
Create :mod:`jinja2` environment with :meth:`jinja2.FileSystemLoader`
:param folder: folder path.
:return: jinja2 environment object.
"""
global _default_filters
global _default_tests
env = jinja2.Environment(loader=jinja2.FileSystemLoader(folder))
... | python | def create_env_by_folder(folder):
"""
Create :mod:`jinja2` environment with :meth:`jinja2.FileSystemLoader`
:param folder: folder path.
:return: jinja2 environment object.
"""
global _default_filters
global _default_tests
env = jinja2.Environment(loader=jinja2.FileSystemLoader(folder))
... | [
"def",
"create_env_by_folder",
"(",
"folder",
")",
":",
"global",
"_default_filters",
"global",
"_default_tests",
"env",
"=",
"jinja2",
".",
"Environment",
"(",
"loader",
"=",
"jinja2",
".",
"FileSystemLoader",
"(",
"folder",
")",
")",
"for",
"k",
",",
"f",
... | Create :mod:`jinja2` environment with :meth:`jinja2.FileSystemLoader`
:param folder: folder path.
:return: jinja2 environment object. | [
"Create",
":",
"mod",
":",
"jinja2",
"environment",
"with",
":",
"meth",
":",
"jinja2",
".",
"FileSystemLoader"
] | train | https://github.com/yufeiminds/toolkit/blob/2d3986f2711f0ee9ee9cd75c25752ef4d0f42ff7/toolkit/tpl.py#L110-L127 |
yufeiminds/toolkit | toolkit/tpl.py | get_template | def get_template(template_path):
"""
Get template object from absolute path.
For example, the template has:
.. code-block:: html
{% macro add(a, b) -%}
{{a + b}}
{%- endmacro %}
And call the macro as template object method.
.. code-block:: python
tpl = g... | python | def get_template(template_path):
"""
Get template object from absolute path.
For example, the template has:
.. code-block:: html
{% macro add(a, b) -%}
{{a + b}}
{%- endmacro %}
And call the macro as template object method.
.. code-block:: python
tpl = g... | [
"def",
"get_template",
"(",
"template_path",
")",
":",
"folder",
",",
"fname",
"=",
"os",
".",
"path",
".",
"split",
"(",
"template_path",
")",
"return",
"create_env_by_folder",
"(",
"folder",
")",
".",
"get_template",
"(",
"fname",
")"
] | Get template object from absolute path.
For example, the template has:
.. code-block:: html
{% macro add(a, b) -%}
{{a + b}}
{%- endmacro %}
And call the macro as template object method.
.. code-block:: python
tpl = get_template('template.tpl')
print(tpl... | [
"Get",
"template",
"object",
"from",
"absolute",
"path",
"."
] | train | https://github.com/yufeiminds/toolkit/blob/2d3986f2711f0ee9ee9cd75c25752ef4d0f42ff7/toolkit/tpl.py#L130-L155 |
yufeiminds/toolkit | toolkit/tpl.py | render | def render(template_path, output_file=None, **kwargs):
"""
Render jinja2 template file use absolute path.
**Usage**
A simple template as follow:
.. code-block:: jinja
This is a test template
{{ title }}
Then write render code by single line.
.. code-block:: python
... | python | def render(template_path, output_file=None, **kwargs):
"""
Render jinja2 template file use absolute path.
**Usage**
A simple template as follow:
.. code-block:: jinja
This is a test template
{{ title }}
Then write render code by single line.
.. code-block:: python
... | [
"def",
"render",
"(",
"template_path",
",",
"output_file",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"template",
"=",
"get_template",
"(",
"template_path",
")",
"rendered",
"=",
"template",
".",
"render",
"(",
"*",
"*",
"kwargs",
")",
"if",
"not",
... | Render jinja2 template file use absolute path.
**Usage**
A simple template as follow:
.. code-block:: jinja
This is a test template
{{ title }}
Then write render code by single line.
.. code-block:: python
render('template.tpl', name='toolkit')
:param template_pa... | [
"Render",
"jinja2",
"template",
"file",
"use",
"absolute",
"path",
"."
] | train | https://github.com/yufeiminds/toolkit/blob/2d3986f2711f0ee9ee9cd75c25752ef4d0f42ff7/toolkit/tpl.py#L158-L187 |
5j9/flake8-invalid-escape-sequences | flake8_invalid_escape_sequences/__init__.py | plugin | def plugin(tree, file_tokens):
"""Walk the tree and detect invalid escape sequences."""
for token in file_tokens:
if token[0] != STRING: # token[0] == token.type
continue
# token[1] == token.string # python 3
invalid_sequence_match = invalid_escape_sequence_match(token[1])
... | python | def plugin(tree, file_tokens):
"""Walk the tree and detect invalid escape sequences."""
for token in file_tokens:
if token[0] != STRING: # token[0] == token.type
continue
# token[1] == token.string # python 3
invalid_sequence_match = invalid_escape_sequence_match(token[1])
... | [
"def",
"plugin",
"(",
"tree",
",",
"file_tokens",
")",
":",
"for",
"token",
"in",
"file_tokens",
":",
"if",
"token",
"[",
"0",
"]",
"!=",
"STRING",
":",
"# token[0] == token.type",
"continue",
"# token[1] == token.string # python 3",
"invalid_sequence_match",
"=",
... | Walk the tree and detect invalid escape sequences. | [
"Walk",
"the",
"tree",
"and",
"detect",
"invalid",
"escape",
"sequences",
"."
] | train | https://github.com/5j9/flake8-invalid-escape-sequences/blob/3f7ba7ea7342862a9406d758a7adf756f67732a5/flake8_invalid_escape_sequences/__init__.py#L36-L50 |
operasoftware/twisted-apns | apns/listenable.py | Listenable.unlisten | def unlisten(self, event, callback):
"""
Remove previously assigned callback.
:return True in case the callback was successfully removed, False
otherwise.
"""
try:
self.listeners[event].remove(callback)
except ValueError:
return False
... | python | def unlisten(self, event, callback):
"""
Remove previously assigned callback.
:return True in case the callback was successfully removed, False
otherwise.
"""
try:
self.listeners[event].remove(callback)
except ValueError:
return False
... | [
"def",
"unlisten",
"(",
"self",
",",
"event",
",",
"callback",
")",
":",
"try",
":",
"self",
".",
"listeners",
"[",
"event",
"]",
".",
"remove",
"(",
"callback",
")",
"except",
"ValueError",
":",
"return",
"False",
"else",
":",
"return",
"True"
] | Remove previously assigned callback.
:return True in case the callback was successfully removed, False
otherwise. | [
"Remove",
"previously",
"assigned",
"callback",
".",
":",
"return",
"True",
"in",
"case",
"the",
"callback",
"was",
"successfully",
"removed",
"False",
"otherwise",
"."
] | train | https://github.com/operasoftware/twisted-apns/blob/c7bd460100067e0c96c440ac0f5516485ac7313f/apns/listenable.py#L21-L32 |
operasoftware/twisted-apns | apns/listenable.py | Listenable.dispatchEvent | def dispatchEvent(self, event, *args):
"""
Fire all callbacks assigned to a particular event. To be called by
derivative classes.
:param *args: Additional arguments to be passed to the callback
function.
"""
for callback in self.listeners[event]:
yield... | python | def dispatchEvent(self, event, *args):
"""
Fire all callbacks assigned to a particular event. To be called by
derivative classes.
:param *args: Additional arguments to be passed to the callback
function.
"""
for callback in self.listeners[event]:
yield... | [
"def",
"dispatchEvent",
"(",
"self",
",",
"event",
",",
"*",
"args",
")",
":",
"for",
"callback",
"in",
"self",
".",
"listeners",
"[",
"event",
"]",
":",
"yield",
"callback",
"(",
"event",
",",
"self",
",",
"*",
"args",
")"
] | Fire all callbacks assigned to a particular event. To be called by
derivative classes.
:param *args: Additional arguments to be passed to the callback
function. | [
"Fire",
"all",
"callbacks",
"assigned",
"to",
"a",
"particular",
"event",
".",
"To",
"be",
"called",
"by",
"derivative",
"classes",
".",
":",
"param",
"*",
"args",
":",
"Additional",
"arguments",
"to",
"be",
"passed",
"to",
"the",
"callback",
"function",
"... | train | https://github.com/operasoftware/twisted-apns/blob/c7bd460100067e0c96c440ac0f5516485ac7313f/apns/listenable.py#L35-L43 |
jeffh/pyconstraints | pyconstraints/constraints.py | BaseConstraint.extract_values | def extract_values(self, possible_solution, use_defaults=False):
"""Returns a tuple of the values that pertain to this constraint.
It simply filters all values to by the variables this constraint uses.
"""
defaults = self._vardefaults if use_defaults else {}
values = list(self._... | python | def extract_values(self, possible_solution, use_defaults=False):
"""Returns a tuple of the values that pertain to this constraint.
It simply filters all values to by the variables this constraint uses.
"""
defaults = self._vardefaults if use_defaults else {}
values = list(self._... | [
"def",
"extract_values",
"(",
"self",
",",
"possible_solution",
",",
"use_defaults",
"=",
"False",
")",
":",
"defaults",
"=",
"self",
".",
"_vardefaults",
"if",
"use_defaults",
"else",
"{",
"}",
"values",
"=",
"list",
"(",
"self",
".",
"_template",
")",
"f... | Returns a tuple of the values that pertain to this constraint.
It simply filters all values to by the variables this constraint uses. | [
"Returns",
"a",
"tuple",
"of",
"the",
"values",
"that",
"pertain",
"to",
"this",
"constraint",
"."
] | train | https://github.com/jeffh/pyconstraints/blob/923abce2f9ba484d1964165616a253bbccd1a630/pyconstraints/constraints.py#L12-L21 |
uw-it-aca/uw-restclients | restclients/hrpws/appointee.py | _get_appointee | def _get_appointee(id):
"""
Return a restclients.models.hrp.AppointeePerson object
"""
url = "%s%s.json" % (URL_PREFIX, id)
response = get_resource(url)
return process_json(response) | python | def _get_appointee(id):
"""
Return a restclients.models.hrp.AppointeePerson object
"""
url = "%s%s.json" % (URL_PREFIX, id)
response = get_resource(url)
return process_json(response) | [
"def",
"_get_appointee",
"(",
"id",
")",
":",
"url",
"=",
"\"%s%s.json\"",
"%",
"(",
"URL_PREFIX",
",",
"id",
")",
"response",
"=",
"get_resource",
"(",
"url",
")",
"return",
"process_json",
"(",
"response",
")"
] | Return a restclients.models.hrp.AppointeePerson object | [
"Return",
"a",
"restclients",
".",
"models",
".",
"hrp",
".",
"AppointeePerson",
"object"
] | train | https://github.com/uw-it-aca/uw-restclients/blob/e12dcd32bf5296b6ebdf71798031594afb7852cb/restclients/hrpws/appointee.py#L37-L43 |
JNRowe/upoints | upoints/cities.py | Cities.import_locations | def import_locations(self, data):
"""Parse `GNU miscfiles`_ cities data files.
``import_locations()`` returns a list containing :class:`City` objects.
It expects data files in the same format that `GNU miscfiles`_
provides, that is::
ID : 1
Type ... | python | def import_locations(self, data):
"""Parse `GNU miscfiles`_ cities data files.
``import_locations()`` returns a list containing :class:`City` objects.
It expects data files in the same format that `GNU miscfiles`_
provides, that is::
ID : 1
Type ... | [
"def",
"import_locations",
"(",
"self",
",",
"data",
")",
":",
"self",
".",
"_data",
"=",
"data",
"if",
"hasattr",
"(",
"data",
",",
"'read'",
")",
":",
"data",
"=",
"data",
".",
"read",
"(",
")",
".",
"split",
"(",
"'//\\n'",
")",
"elif",
"isinsta... | Parse `GNU miscfiles`_ cities data files.
``import_locations()`` returns a list containing :class:`City` objects.
It expects data files in the same format that `GNU miscfiles`_
provides, that is::
ID : 1
Type : City
Population : 210700
... | [
"Parse",
"GNU",
"miscfiles",
"_",
"cities",
"data",
"files",
"."
] | train | https://github.com/JNRowe/upoints/blob/1e4b7a53ed2a06cd854523d54c36aabdccea3830/upoints/cities.py#L115-L204 |
Robpol86/sphinxcontrib-imgur | sphinxcontrib/imgur/imgur_api.py | query_api | def query_api(app, client_id, imgur_id, is_album):
"""Query the Imgur API.
:raise APIError: When Imgur responds with errors or unexpected data.
:param sphinx.application.Sphinx app: Sphinx application object.
:param str client_id: Imgur API client ID to use. https://api.imgur.com/oauth2
:param str... | python | def query_api(app, client_id, imgur_id, is_album):
"""Query the Imgur API.
:raise APIError: When Imgur responds with errors or unexpected data.
:param sphinx.application.Sphinx app: Sphinx application object.
:param str client_id: Imgur API client ID to use. https://api.imgur.com/oauth2
:param str... | [
"def",
"query_api",
"(",
"app",
",",
"client_id",
",",
"imgur_id",
",",
"is_album",
")",
":",
"url",
"=",
"API_URL",
".",
"format",
"(",
"type",
"=",
"'album'",
"if",
"is_album",
"else",
"'image'",
",",
"id",
"=",
"imgur_id",
")",
"headers",
"=",
"{",
... | Query the Imgur API.
:raise APIError: When Imgur responds with errors or unexpected data.
:param sphinx.application.Sphinx app: Sphinx application object.
:param str client_id: Imgur API client ID to use. https://api.imgur.com/oauth2
:param str imgur_id: The Imgur ID to query.
:param bool is_album... | [
"Query",
"the",
"Imgur",
"API",
"."
] | train | https://github.com/Robpol86/sphinxcontrib-imgur/blob/5c178481d645147d10acb096793eda41c12c57af/sphinxcontrib/imgur/imgur_api.py#L31-L74 |
Robpol86/sphinxcontrib-imgur | sphinxcontrib/imgur/imgur_api.py | Base._parse | def _parse(self, data):
"""Parse API response.
:param dict data: Parsed JSON response from API 'data' key.
"""
self.description = data['description']
self.in_gallery = data['in_gallery']
self.mod_time = int(time.time())
self.title = data['title'] | python | def _parse(self, data):
"""Parse API response.
:param dict data: Parsed JSON response from API 'data' key.
"""
self.description = data['description']
self.in_gallery = data['in_gallery']
self.mod_time = int(time.time())
self.title = data['title'] | [
"def",
"_parse",
"(",
"self",
",",
"data",
")",
":",
"self",
".",
"description",
"=",
"data",
"[",
"'description'",
"]",
"self",
".",
"in_gallery",
"=",
"data",
"[",
"'in_gallery'",
"]",
"self",
".",
"mod_time",
"=",
"int",
"(",
"time",
".",
"time",
... | Parse API response.
:param dict data: Parsed JSON response from API 'data' key. | [
"Parse",
"API",
"response",
"."
] | train | https://github.com/Robpol86/sphinxcontrib-imgur/blob/5c178481d645147d10acb096793eda41c12c57af/sphinxcontrib/imgur/imgur_api.py#L96-L104 |
Robpol86/sphinxcontrib-imgur | sphinxcontrib/imgur/imgur_api.py | Base.seconds_remaining | def seconds_remaining(self, ttl):
"""Return number of seconds left before Imgur API needs to be queried for this instance.
:param int ttl: Number of seconds before this is considered out of date.
:return: Seconds left before this is expired. 0 indicated update needed (no negatives).
:r... | python | def seconds_remaining(self, ttl):
"""Return number of seconds left before Imgur API needs to be queried for this instance.
:param int ttl: Number of seconds before this is considered out of date.
:return: Seconds left before this is expired. 0 indicated update needed (no negatives).
:r... | [
"def",
"seconds_remaining",
"(",
"self",
",",
"ttl",
")",
":",
"return",
"max",
"(",
"0",
",",
"ttl",
"-",
"(",
"int",
"(",
"time",
".",
"time",
"(",
")",
")",
"-",
"self",
".",
"mod_time",
")",
")"
] | Return number of seconds left before Imgur API needs to be queried for this instance.
:param int ttl: Number of seconds before this is considered out of date.
:return: Seconds left before this is expired. 0 indicated update needed (no negatives).
:rtype: int | [
"Return",
"number",
"of",
"seconds",
"left",
"before",
"Imgur",
"API",
"needs",
"to",
"be",
"queried",
"for",
"this",
"instance",
"."
] | train | https://github.com/Robpol86/sphinxcontrib-imgur/blob/5c178481d645147d10acb096793eda41c12c57af/sphinxcontrib/imgur/imgur_api.py#L106-L114 |
Robpol86/sphinxcontrib-imgur | sphinxcontrib/imgur/imgur_api.py | Base.refresh | def refresh(self, app, client_id, ttl):
"""Query the API to update this instance.
:raise APIError: When Imgur responds with errors or unexpected data.
:param sphinx.application.Sphinx app: Sphinx application object.
:param str client_id: Imgur API client ID to use. https://api.imgur.co... | python | def refresh(self, app, client_id, ttl):
"""Query the API to update this instance.
:raise APIError: When Imgur responds with errors or unexpected data.
:param sphinx.application.Sphinx app: Sphinx application object.
:param str client_id: Imgur API client ID to use. https://api.imgur.co... | [
"def",
"refresh",
"(",
"self",
",",
"app",
",",
"client_id",
",",
"ttl",
")",
":",
"remaining",
"=",
"self",
".",
"seconds_remaining",
"(",
"ttl",
")",
"if",
"remaining",
":",
"app",
".",
"debug2",
"(",
"'Imgur ID %s still has %d seconds before needing refresh. ... | Query the API to update this instance.
:raise APIError: When Imgur responds with errors or unexpected data.
:param sphinx.application.Sphinx app: Sphinx application object.
:param str client_id: Imgur API client ID to use. https://api.imgur.com/oauth2
:param int ttl: Number of seconds ... | [
"Query",
"the",
"API",
"to",
"update",
"this",
"instance",
"."
] | train | https://github.com/Robpol86/sphinxcontrib-imgur/blob/5c178481d645147d10acb096793eda41c12c57af/sphinxcontrib/imgur/imgur_api.py#L116-L137 |
Robpol86/sphinxcontrib-imgur | sphinxcontrib/imgur/imgur_api.py | Image._parse | def _parse(self, data):
"""Parse API response.
:param dict data: Parsed JSON response from API 'data' key.
"""
super(Image, self)._parse(data)
self.height = data['height']
self.type = data['type']
self.width = data['width'] | python | def _parse(self, data):
"""Parse API response.
:param dict data: Parsed JSON response from API 'data' key.
"""
super(Image, self)._parse(data)
self.height = data['height']
self.type = data['type']
self.width = data['width'] | [
"def",
"_parse",
"(",
"self",
",",
"data",
")",
":",
"super",
"(",
"Image",
",",
"self",
")",
".",
"_parse",
"(",
"data",
")",
"self",
".",
"height",
"=",
"data",
"[",
"'height'",
"]",
"self",
".",
"type",
"=",
"data",
"[",
"'type'",
"]",
"self",... | Parse API response.
:param dict data: Parsed JSON response from API 'data' key. | [
"Parse",
"API",
"response",
"."
] | train | https://github.com/Robpol86/sphinxcontrib-imgur/blob/5c178481d645147d10acb096793eda41c12c57af/sphinxcontrib/imgur/imgur_api.py#L156-L164 |
Robpol86/sphinxcontrib-imgur | sphinxcontrib/imgur/imgur_api.py | Image.filename | def filename(self, display_width='', display_height='', full_size=False):
"""Determine which resized Imgur filename to use based on the display width/height. Includes the extension.
:param str display_width: Display width from Sphinx directive options (e.g. '100px', '50%').
:param str display_h... | python | def filename(self, display_width='', display_height='', full_size=False):
"""Determine which resized Imgur filename to use based on the display width/height. Includes the extension.
:param str display_width: Display width from Sphinx directive options (e.g. '100px', '50%').
:param str display_h... | [
"def",
"filename",
"(",
"self",
",",
"display_width",
"=",
"''",
",",
"display_height",
"=",
"''",
",",
"full_size",
"=",
"False",
")",
":",
"extension",
"=",
"self",
".",
"type",
"[",
"-",
"3",
":",
"]",
"if",
"self",
".",
"type",
"in",
"(",
"'ima... | Determine which resized Imgur filename to use based on the display width/height. Includes the extension.
:param str display_width: Display width from Sphinx directive options (e.g. '100px', '50%').
:param str display_height: Display height from Sphinx directive options (e.g. '100px', '50%').
:p... | [
"Determine",
"which",
"resized",
"Imgur",
"filename",
"to",
"use",
"based",
"on",
"the",
"display",
"width",
"/",
"height",
".",
"Includes",
"the",
"extension",
"."
] | train | https://github.com/Robpol86/sphinxcontrib-imgur/blob/5c178481d645147d10acb096793eda41c12c57af/sphinxcontrib/imgur/imgur_api.py#L166-L200 |
Robpol86/sphinxcontrib-imgur | sphinxcontrib/imgur/imgur_api.py | Album._parse | def _parse(self, data):
"""Parse API response.
:param dict data: Parsed JSON response from API 'data' key.
:return: Image instances.
:rtype: list.
"""
super(Album, self)._parse(data)
self.cover_id = data['cover']
images = [Image(i['id'], i) for i in data... | python | def _parse(self, data):
"""Parse API response.
:param dict data: Parsed JSON response from API 'data' key.
:return: Image instances.
:rtype: list.
"""
super(Album, self)._parse(data)
self.cover_id = data['cover']
images = [Image(i['id'], i) for i in data... | [
"def",
"_parse",
"(",
"self",
",",
"data",
")",
":",
"super",
"(",
"Album",
",",
"self",
")",
".",
"_parse",
"(",
"data",
")",
"self",
".",
"cover_id",
"=",
"data",
"[",
"'cover'",
"]",
"images",
"=",
"[",
"Image",
"(",
"i",
"[",
"'id'",
"]",
"... | Parse API response.
:param dict data: Parsed JSON response from API 'data' key.
:return: Image instances.
:rtype: list. | [
"Parse",
"API",
"response",
"."
] | train | https://github.com/Robpol86/sphinxcontrib-imgur/blob/5c178481d645147d10acb096793eda41c12c57af/sphinxcontrib/imgur/imgur_api.py#L231-L243 |
Robpol86/sphinxcontrib-imgur | sphinxcontrib/imgur/imgur_api.py | Album.refresh | def refresh(self, app, client_id, ttl):
"""Query the API to update this instance.
:raise APIError: When Imgur responds with errors or unexpected data.
:param sphinx.application.Sphinx app: Sphinx application object.
:param str client_id: Imgur API client ID to use. https://api.imgur.co... | python | def refresh(self, app, client_id, ttl):
"""Query the API to update this instance.
:raise APIError: When Imgur responds with errors or unexpected data.
:param sphinx.application.Sphinx app: Sphinx application object.
:param str client_id: Imgur API client ID to use. https://api.imgur.co... | [
"def",
"refresh",
"(",
"self",
",",
"app",
",",
"client_id",
",",
"ttl",
")",
":",
"return",
"super",
"(",
"Album",
",",
"self",
")",
".",
"refresh",
"(",
"app",
",",
"client_id",
",",
"ttl",
")",
"or",
"list",
"(",
")"
] | Query the API to update this instance.
:raise APIError: When Imgur responds with errors or unexpected data.
:param sphinx.application.Sphinx app: Sphinx application object.
:param str client_id: Imgur API client ID to use. https://api.imgur.com/oauth2
:param int ttl: Number of seconds ... | [
"Query",
"the",
"API",
"to",
"update",
"this",
"instance",
"."
] | train | https://github.com/Robpol86/sphinxcontrib-imgur/blob/5c178481d645147d10acb096793eda41c12c57af/sphinxcontrib/imgur/imgur_api.py#L245-L257 |
qwilka/vn-tree | vntree/node.py | Node.add_child | def add_child(self, node):
"""Add a child node to the current node instance.
:param node: the child node instance.
:type node: Node
:returns: The new child node instance.
:rtype: Node
"""
if not issubclass(node.__class__, Node):
raise TypeError("{... | python | def add_child(self, node):
"""Add a child node to the current node instance.
:param node: the child node instance.
:type node: Node
:returns: The new child node instance.
:rtype: Node
"""
if not issubclass(node.__class__, Node):
raise TypeError("{... | [
"def",
"add_child",
"(",
"self",
",",
"node",
")",
":",
"if",
"not",
"issubclass",
"(",
"node",
".",
"__class__",
",",
"Node",
")",
":",
"raise",
"TypeError",
"(",
"\"{}.add_child: arg «node»=«{}», type {} not valid.\".for",
"m",
"at(sel",
"f",
".__c",
"l",
"a... | Add a child node to the current node instance.
:param node: the child node instance.
:type node: Node
:returns: The new child node instance.
:rtype: Node | [
"Add",
"a",
"child",
"node",
"to",
"the",
"current",
"node",
"instance",
"."
] | train | https://github.com/qwilka/vn-tree/blob/f08106e9c7232d8748d78d1d39b019699a7407dd/vntree/node.py#L142-L154 |
qwilka/vn-tree | vntree/node.py | Node.remove_child | def remove_child(self, idx=None, *, name=None, node=None):
"""Remove a child node from the current node instance.
:param idx: Index of child node to be removed.
:type idx: int
:param name: The first child node found with «name» will be removed.
:type name: str
:param n... | python | def remove_child(self, idx=None, *, name=None, node=None):
"""Remove a child node from the current node instance.
:param idx: Index of child node to be removed.
:type idx: int
:param name: The first child node found with «name» will be removed.
:type name: str
:param n... | [
"def",
"remove_child",
"(",
"self",
",",
"idx",
"=",
"None",
",",
"*",
",",
"name",
"=",
"None",
",",
"node",
"=",
"None",
")",
":",
"if",
"(",
"idx",
"and",
"isinstance",
"(",
"idx",
",",
"int",
")",
"and",
"-",
"len",
"(",
"self",
".",
"child... | Remove a child node from the current node instance.
:param idx: Index of child node to be removed.
:type idx: int
:param name: The first child node found with «name» will be removed.
:type name: str
:param node: Child node to be removed.
:type node: Node
:retu... | [
"Remove",
"a",
"child",
"node",
"from",
"the",
"current",
"node",
"instance",
"."
] | train | https://github.com/qwilka/vn-tree/blob/f08106e9c7232d8748d78d1d39b019699a7407dd/vntree/node.py#L164-L191 |
qwilka/vn-tree | vntree/node.py | Node._path | def _path(self):
"""Attribute indicating the absolute node path for this node.
Note that the absolute node path starts with a forward slash
followed by the root node's name: e.g:
`/root.name/child.name/grandchild.name`
Warning: it should be noted that use of _path ass... | python | def _path(self):
"""Attribute indicating the absolute node path for this node.
Note that the absolute node path starts with a forward slash
followed by the root node's name: e.g:
`/root.name/child.name/grandchild.name`
Warning: it should be noted that use of _path ass... | [
"def",
"_path",
"(",
"self",
")",
":",
"_path",
"=",
"pathlib",
".",
"PurePosixPath",
"(",
"self",
".",
"name",
")",
"_node",
"=",
"self",
"while",
"_node",
".",
"parent",
":",
"_path",
"=",
"_node",
".",
"parent",
".",
"name",
"/",
"_path",
"_node",... | Attribute indicating the absolute node path for this node.
Note that the absolute node path starts with a forward slash
followed by the root node's name: e.g:
`/root.name/child.name/grandchild.name`
Warning: it should be noted that use of _path assumes
that sibling ... | [
"Attribute",
"indicating",
"the",
"absolute",
"node",
"path",
"for",
"this",
"node",
".",
"Note",
"that",
"the",
"absolute",
"node",
"path",
"starts",
"with",
"a",
"forward",
"slash",
"followed",
"by",
"the",
"root",
"node",
"s",
"name",
":",
"e",
".",
"... | train | https://github.com/qwilka/vn-tree/blob/f08106e9c7232d8748d78d1d39b019699a7407dd/vntree/node.py#L194-L213 |
qwilka/vn-tree | vntree/node.py | Node._coord | def _coord(self):
"""Attribute indicating the tree coordinates for this node.
The tree coordinates of a node are expressed as a tuple of the
indices of the node and its ancestors, for example:
A grandchild node with node path
`/root.name/root.childs[2].name/root.childs[2].child... | python | def _coord(self):
"""Attribute indicating the tree coordinates for this node.
The tree coordinates of a node are expressed as a tuple of the
indices of the node and its ancestors, for example:
A grandchild node with node path
`/root.name/root.childs[2].name/root.childs[2].child... | [
"def",
"_coord",
"(",
"self",
")",
":",
"_coord",
"=",
"[",
"]",
"_node",
"=",
"self",
"while",
"_node",
".",
"parent",
":",
"_idx",
"=",
"_node",
".",
"parent",
".",
"childs",
".",
"index",
"(",
"_node",
")",
"_coord",
".",
"insert",
"(",
"0",
"... | Attribute indicating the tree coordinates for this node.
The tree coordinates of a node are expressed as a tuple of the
indices of the node and its ancestors, for example:
A grandchild node with node path
`/root.name/root.childs[2].name/root.childs[2].childs[0].name`
would hav... | [
"Attribute",
"indicating",
"the",
"tree",
"coordinates",
"for",
"this",
"node",
"."
] | train | https://github.com/qwilka/vn-tree/blob/f08106e9c7232d8748d78d1d39b019699a7407dd/vntree/node.py#L216-L235 |
qwilka/vn-tree | vntree/node.py | Node.set_data | def set_data(self, *keys, value):
"""Set a value in the instance `data` dict.
:param keys: the `data` dict keys referencing the value in the `data` dict.
:type keys: str
:param value: the value to be set in the `data` dict. Note that
`value` is a keyword-only argument.
... | python | def set_data(self, *keys, value):
"""Set a value in the instance `data` dict.
:param keys: the `data` dict keys referencing the value in the `data` dict.
:type keys: str
:param value: the value to be set in the `data` dict. Note that
`value` is a keyword-only argument.
... | [
"def",
"set_data",
"(",
"self",
",",
"*",
"keys",
",",
"value",
")",
":",
"_datadict",
"=",
"self",
".",
"data",
"for",
"ii",
",",
"_key",
"in",
"enumerate",
"(",
"keys",
")",
":",
"if",
"ii",
"==",
"len",
"(",
"keys",
")",
"-",
"1",
":",
"_dat... | Set a value in the instance `data` dict.
:param keys: the `data` dict keys referencing the value in the `data` dict.
:type keys: str
:param value: the value to be set in the `data` dict. Note that
`value` is a keyword-only argument.
:returns: `True` if successful. | [
"Set",
"a",
"value",
"in",
"the",
"instance",
"data",
"dict",
"."
] | train | https://github.com/qwilka/vn-tree/blob/f08106e9c7232d8748d78d1d39b019699a7407dd/vntree/node.py#L275-L292 |
qwilka/vn-tree | vntree/node.py | Node._root | def _root(self):
"""Attribute referencing the root node of the tree.
:returns: the root node of the tree containing this instance.
:rtype: Node
"""
_n = self
while _n.parent:
_n = _n.parent
return _n | python | def _root(self):
"""Attribute referencing the root node of the tree.
:returns: the root node of the tree containing this instance.
:rtype: Node
"""
_n = self
while _n.parent:
_n = _n.parent
return _n | [
"def",
"_root",
"(",
"self",
")",
":",
"_n",
"=",
"self",
"while",
"_n",
".",
"parent",
":",
"_n",
"=",
"_n",
".",
"parent",
"return",
"_n"
] | Attribute referencing the root node of the tree.
:returns: the root node of the tree containing this instance.
:rtype: Node | [
"Attribute",
"referencing",
"the",
"root",
"node",
"of",
"the",
"tree",
"."
] | train | https://github.com/qwilka/vn-tree/blob/f08106e9c7232d8748d78d1d39b019699a7407dd/vntree/node.py#L296-L305 |
qwilka/vn-tree | vntree/node.py | Node._ancestors | def _ancestors(self):
"""Attribute referencing the tree ancestors of the node instance.
:returns: list of node ancestors in sequence, first item is
the current node instance (`self`), the last item is root.
:rtype: list of Node references
"""
# return list of ancest... | python | def _ancestors(self):
"""Attribute referencing the tree ancestors of the node instance.
:returns: list of node ancestors in sequence, first item is
the current node instance (`self`), the last item is root.
:rtype: list of Node references
"""
# return list of ancest... | [
"def",
"_ancestors",
"(",
"self",
")",
":",
"# return list of ancestor nodes starting with self.parent and ending with root",
"_ancestors",
"=",
"[",
"]",
"_n",
"=",
"self",
"while",
"_n",
".",
"parent",
":",
"_n",
"=",
"_n",
".",
"parent",
"_ancestors",
".",
"app... | Attribute referencing the tree ancestors of the node instance.
:returns: list of node ancestors in sequence, first item is
the current node instance (`self`), the last item is root.
:rtype: list of Node references | [
"Attribute",
"referencing",
"the",
"tree",
"ancestors",
"of",
"the",
"node",
"instance",
"."
] | train | https://github.com/qwilka/vn-tree/blob/f08106e9c7232d8748d78d1d39b019699a7407dd/vntree/node.py#L309-L322 |
qwilka/vn-tree | vntree/node.py | Node.get_child_by_name | def get_child_by_name(self, childname):
"""Get a child node of the current instance by its name.
:param childname: the name of the required child node.
:type childname: str
:returns: the first child node found with name `childname`.
:rtype: Node or None
"""
_chil... | python | def get_child_by_name(self, childname):
"""Get a child node of the current instance by its name.
:param childname: the name of the required child node.
:type childname: str
:returns: the first child node found with name `childname`.
:rtype: Node or None
"""
_chil... | [
"def",
"get_child_by_name",
"(",
"self",
",",
"childname",
")",
":",
"_childs",
"=",
"[",
"_child",
"for",
"_child",
"in",
"self",
".",
"childs",
"if",
"_child",
".",
"name",
"==",
"childname",
"]",
"if",
"len",
"(",
"_childs",
")",
">",
"1",
":",
"l... | Get a child node of the current instance by its name.
:param childname: the name of the required child node.
:type childname: str
:returns: the first child node found with name `childname`.
:rtype: Node or None | [
"Get",
"a",
"child",
"node",
"of",
"the",
"current",
"instance",
"by",
"its",
"name",
"."
] | train | https://github.com/qwilka/vn-tree/blob/f08106e9c7232d8748d78d1d39b019699a7407dd/vntree/node.py#L325-L340 |
qwilka/vn-tree | vntree/node.py | Node.get_node_by_path | def get_node_by_path(self, path):
"""Get a node from a node path.
Warning: use of this method assumes that sibling nodes have unique names,
if this is not assured the `get_node_by_coord` method can be used instead.
| Example with absolute node path:
| `node.get_node_by_path... | python | def get_node_by_path(self, path):
"""Get a node from a node path.
Warning: use of this method assumes that sibling nodes have unique names,
if this is not assured the `get_node_by_coord` method can be used instead.
| Example with absolute node path:
| `node.get_node_by_path... | [
"def",
"get_node_by_path",
"(",
"self",
",",
"path",
")",
":",
"if",
"path",
"==",
"\".\"",
":",
"return",
"self",
"elif",
"path",
".",
"lstrip",
"(",
")",
".",
"startswith",
"(",
"(",
"\".\"",
",",
"\"./\"",
")",
")",
"or",
"not",
"isinstance",
"(",... | Get a node from a node path.
Warning: use of this method assumes that sibling nodes have unique names,
if this is not assured the `get_node_by_coord` method can be used instead.
| Example with absolute node path:
| `node.get_node_by_path('/root.name/child.name/gchild.name')`
... | [
"Get",
"a",
"node",
"from",
"a",
"node",
"path",
"."
] | train | https://github.com/qwilka/vn-tree/blob/f08106e9c7232d8748d78d1d39b019699a7407dd/vntree/node.py#L343-L376 |
qwilka/vn-tree | vntree/node.py | Node.get_node_by_coord | def get_node_by_coord(self, coord, relative=False):
"""Get a node from a node coord.
:param coord: the coordinates of the required node.
:type coord: tuple or list
:param relative: `True` if coord is relative to the node instance,
`False` for absolute coordinates.
:... | python | def get_node_by_coord(self, coord, relative=False):
"""Get a node from a node coord.
:param coord: the coordinates of the required node.
:type coord: tuple or list
:param relative: `True` if coord is relative to the node instance,
`False` for absolute coordinates.
:... | [
"def",
"get_node_by_coord",
"(",
"self",
",",
"coord",
",",
"relative",
"=",
"False",
")",
":",
"if",
"not",
"isinstance",
"(",
"coord",
",",
"(",
"list",
",",
"tuple",
")",
")",
"or",
"False",
"in",
"list",
"(",
"map",
"(",
"lambda",
"i",
":",
"ty... | Get a node from a node coord.
:param coord: the coordinates of the required node.
:type coord: tuple or list
:param relative: `True` if coord is relative to the node instance,
`False` for absolute coordinates.
:type relative: bool
:returns: the node corresponding to... | [
"Get",
"a",
"node",
"from",
"a",
"node",
"coord",
"."
] | train | https://github.com/qwilka/vn-tree/blob/f08106e9c7232d8748d78d1d39b019699a7407dd/vntree/node.py#L379-L402 |
qwilka/vn-tree | vntree/node.py | Node.find_one_node | def find_one_node(self, *keys, value, decend=True):
"""Find a node on the branch of the instance with a
`keys=data` item in the `data` dict.
Nested values are accessed by specifying the keys in sequence.
e.g. `node.get_data("country", "city")` would access
`node.data["country"... | python | def find_one_node(self, *keys, value, decend=True):
"""Find a node on the branch of the instance with a
`keys=data` item in the `data` dict.
Nested values are accessed by specifying the keys in sequence.
e.g. `node.get_data("country", "city")` would access
`node.data["country"... | [
"def",
"find_one_node",
"(",
"self",
",",
"*",
"keys",
",",
"value",
",",
"decend",
"=",
"True",
")",
":",
"if",
"decend",
":",
"traversal",
"=",
"self",
"else",
":",
"traversal",
"=",
"self",
".",
"_ancestors",
"for",
"_node",
"in",
"traversal",
":",
... | Find a node on the branch of the instance with a
`keys=data` item in the `data` dict.
Nested values are accessed by specifying the keys in sequence.
e.g. `node.get_data("country", "city")` would access
`node.data["country"]["city"]`
:param keys: the `data` dict key(s) referen... | [
"Find",
"a",
"node",
"on",
"the",
"branch",
"of",
"the",
"instance",
"with",
"a",
"keys",
"=",
"data",
"item",
"in",
"the",
"data",
"dict",
"."
] | train | https://github.com/qwilka/vn-tree/blob/f08106e9c7232d8748d78d1d39b019699a7407dd/vntree/node.py#L405-L432 |
qwilka/vn-tree | vntree/node.py | Node.to_texttree | def to_texttree(self, indent=3, func=True, symbol='ascii'):
"""Method returning a text representation of the (sub-)tree
rooted at the current node instance (`self`).
:param indent: the indentation width for each tree level.
:type indent: int
:param func: function returning a s... | python | def to_texttree(self, indent=3, func=True, symbol='ascii'):
"""Method returning a text representation of the (sub-)tree
rooted at the current node instance (`self`).
:param indent: the indentation width for each tree level.
:type indent: int
:param func: function returning a s... | [
"def",
"to_texttree",
"(",
"self",
",",
"indent",
"=",
"3",
",",
"func",
"=",
"True",
",",
"symbol",
"=",
"'ascii'",
")",
":",
"if",
"indent",
"<",
"2",
":",
"indent",
"=",
"2",
"if",
"func",
"is",
"True",
":",
"# default func prints node.name",
"func"... | Method returning a text representation of the (sub-)tree
rooted at the current node instance (`self`).
:param indent: the indentation width for each tree level.
:type indent: int
:param func: function returning a string representation for
each node. e.g. `func=lambda n: s... | [
"Method",
"returning",
"a",
"text",
"representation",
"of",
"the",
"(",
"sub",
"-",
")",
"tree",
"rooted",
"at",
"the",
"current",
"node",
"instance",
"(",
"self",
")",
"."
] | train | https://github.com/qwilka/vn-tree/blob/f08106e9c7232d8748d78d1d39b019699a7407dd/vntree/node.py#L435-L507 |
qwilka/vn-tree | vntree/node.py | Node.tree_compare | def tree_compare(self, othertree, vntree_meta=False):
"""Compare the (sub-)tree rooted at `self` with another tree.
`tree_compare` converts the trees being compared into JSON string
representations, and uses `difflib.SequenceMatcher().ratio()` to
calculate a measure of the similarity of... | python | def tree_compare(self, othertree, vntree_meta=False):
"""Compare the (sub-)tree rooted at `self` with another tree.
`tree_compare` converts the trees being compared into JSON string
representations, and uses `difflib.SequenceMatcher().ratio()` to
calculate a measure of the similarity of... | [
"def",
"tree_compare",
"(",
"self",
",",
"othertree",
",",
"vntree_meta",
"=",
"False",
")",
":",
"return",
"SequenceMatcher",
"(",
"None",
",",
"json",
".",
"dumps",
"(",
"self",
".",
"to_treedict",
"(",
"vntree_meta",
"=",
"vntree_meta",
")",
",",
"defau... | Compare the (sub-)tree rooted at `self` with another tree.
`tree_compare` converts the trees being compared into JSON string
representations, and uses `difflib.SequenceMatcher().ratio()` to
calculate a measure of the similarity of the strings.
:param othertree: the other tree for compa... | [
"Compare",
"the",
"(",
"sub",
"-",
")",
"tree",
"rooted",
"at",
"self",
"with",
"another",
"tree",
"."
] | train | https://github.com/qwilka/vn-tree/blob/f08106e9c7232d8748d78d1d39b019699a7407dd/vntree/node.py#L553-L570 |
qwilka/vn-tree | vntree/node.py | Node.savefile | def savefile(self, filepath=None):
"""Save (dump) the tree in a pickle file.
Note that this method saves the complete tree even when invoked on
a non-root node.
It is recommended to use the extension `.vnpkl` for this type of file.
:param filepath: the file path for the pickle ... | python | def savefile(self, filepath=None):
"""Save (dump) the tree in a pickle file.
Note that this method saves the complete tree even when invoked on
a non-root node.
It is recommended to use the extension `.vnpkl` for this type of file.
:param filepath: the file path for the pickle ... | [
"def",
"savefile",
"(",
"self",
",",
"filepath",
"=",
"None",
")",
":",
"if",
"filepath",
":",
"self",
".",
"_vnpkl_fpath",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"filepath",
")",
"# if not _pfpath:",
"# logger.error(\"%s.save: «%s» file path «%s» not va... | Save (dump) the tree in a pickle file.
Note that this method saves the complete tree even when invoked on
a non-root node.
It is recommended to use the extension `.vnpkl` for this type of file.
:param filepath: the file path for the pickle file.
If `filepath=None` use `sel... | [
"Save",
"(",
"dump",
")",
"the",
"tree",
"in",
"a",
"pickle",
"file",
"."
] | train | https://github.com/qwilka/vn-tree/blob/f08106e9c7232d8748d78d1d39b019699a7407dd/vntree/node.py#L573-L597 |
qwilka/vn-tree | vntree/node.py | Node.openfile | def openfile(cls, filepath):
"""Class method that opens (load) a vntree pickle file.
:param filepath: the file path for the pickle file.
:type filepath: str
:returns: root node of tree or `False` if failure.
:rtype: Node or bool
"""
if not os.path.isfi... | python | def openfile(cls, filepath):
"""Class method that opens (load) a vntree pickle file.
:param filepath: the file path for the pickle file.
:type filepath: str
:returns: root node of tree or `False` if failure.
:rtype: Node or bool
"""
if not os.path.isfi... | [
"def",
"openfile",
"(",
"cls",
",",
"filepath",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"filepath",
")",
":",
"logger",
".",
"error",
"(",
"\"%s.openfile: arg `filepath`=«%s» not valid.\" %",
"(",
"l",
"s._",
"_",
"name__, ",
"f",
"le... | Class method that opens (load) a vntree pickle file.
:param filepath: the file path for the pickle file.
:type filepath: str
:returns: root node of tree or `False` if failure.
:rtype: Node or bool | [
"Class",
"method",
"that",
"opens",
"(",
"load",
")",
"a",
"vntree",
"pickle",
"file",
"."
] | train | https://github.com/qwilka/vn-tree/blob/f08106e9c7232d8748d78d1d39b019699a7407dd/vntree/node.py#L601-L620 |
qwilka/vn-tree | vntree/node.py | Node.yaml2tree | def yaml2tree(cls, yamltree):
"""Class method that creates a tree from YAML.
| # Example yamltree data:
| - !Node &root
| name: "root node"
| parent: null
| data:
| testpara: 111
| - !Node &child1
| name: "child node"
| paren... | python | def yaml2tree(cls, yamltree):
"""Class method that creates a tree from YAML.
| # Example yamltree data:
| - !Node &root
| name: "root node"
| parent: null
| data:
| testpara: 111
| - !Node &child1
| name: "child node"
| paren... | [
"def",
"yaml2tree",
"(",
"cls",
",",
"yamltree",
")",
":",
"if",
"not",
"cls",
".",
"YAML_setup",
":",
"cls",
".",
"setup_yaml",
"(",
")",
"cls",
".",
"YAML_setup",
"=",
"True",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"yamltree",
")",
":",
"wi... | Class method that creates a tree from YAML.
| # Example yamltree data:
| - !Node &root
| name: "root node"
| parent: null
| data:
| testpara: 111
| - !Node &child1
| name: "child node"
| parent: *root
| - !Node &gc1
|... | [
"Class",
"method",
"that",
"creates",
"a",
"tree",
"from",
"YAML",
"."
] | train | https://github.com/qwilka/vn-tree/blob/f08106e9c7232d8748d78d1d39b019699a7407dd/vntree/node.py#L636-L668 |
obfusk/m | m.py | dyn | def dyn(d, **kw): # {{{1
"""
Pseudo-dynamic variables.
>>> SOME_VAR = 42
>>> with dyn(vars(), SOME_VAR = 37): SOME_VAR
37
>>> SOME_VAR
42
>>> import threading
>>> D = threading.local()
>>> D.x, D.y = 1, 2
>>> with dyn(vars(D), x = 3, y = 4): (D.x, D.... | python | def dyn(d, **kw): # {{{1
"""
Pseudo-dynamic variables.
>>> SOME_VAR = 42
>>> with dyn(vars(), SOME_VAR = 37): SOME_VAR
37
>>> SOME_VAR
42
>>> import threading
>>> D = threading.local()
>>> D.x, D.y = 1, 2
>>> with dyn(vars(D), x = 3, y = 4): (D.x, D.... | [
"def",
"dyn",
"(",
"d",
",",
"*",
"*",
"kw",
")",
":",
"# {{{1",
"old",
"=",
"{",
"k",
":",
"d",
"[",
"k",
"]",
"for",
"k",
"in",
"kw",
"}",
"try",
":",
"d",
".",
"update",
"(",
"kw",
")",
"yield",
"finally",
":",
"d",
".",
"update",
"(",... | Pseudo-dynamic variables.
>>> SOME_VAR = 42
>>> with dyn(vars(), SOME_VAR = 37): SOME_VAR
37
>>> SOME_VAR
42
>>> import threading
>>> D = threading.local()
>>> D.x, D.y = 1, 2
>>> with dyn(vars(D), x = 3, y = 4): (D.x, D.y)
(3, 4)
>>> (D.x, D.y)
(1, 2) | [
"Pseudo",
"-",
"dynamic",
"variables",
"."
] | train | https://github.com/obfusk/m/blob/23ec2754abc9e945e5f01fcc64c13c833faf2e33/m.py#L1676-L1700 |
obfusk/m | m.py | zlines | def zlines(f = None, sep = "\0", osep = None, size = 8192): # {{{1
"""File iterator that uses alternative line terminators."""
if f is None: f = sys.stdin
if osep is None: osep = sep
buf = ""
while True:
chars = f.read(size)
if not chars: break
buf += chars; lines = buf.split(sep); buf = lines... | python | def zlines(f = None, sep = "\0", osep = None, size = 8192): # {{{1
"""File iterator that uses alternative line terminators."""
if f is None: f = sys.stdin
if osep is None: osep = sep
buf = ""
while True:
chars = f.read(size)
if not chars: break
buf += chars; lines = buf.split(sep); buf = lines... | [
"def",
"zlines",
"(",
"f",
"=",
"None",
",",
"sep",
"=",
"\"\\0\"",
",",
"osep",
"=",
"None",
",",
"size",
"=",
"8192",
")",
":",
"# {{{1",
"if",
"f",
"is",
"None",
":",
"f",
"=",
"sys",
".",
"stdin",
"if",
"osep",
"is",
"None",
":",
"osep",
... | File iterator that uses alternative line terminators. | [
"File",
"iterator",
"that",
"uses",
"alternative",
"line",
"terminators",
"."
] | train | https://github.com/obfusk/m/blob/23ec2754abc9e945e5f01fcc64c13c833faf2e33/m.py#L1705-L1715 |
deginner/mq-client | mq_client.py | _on_message | def _on_message(channel, method, header, body):
"""
Invoked by pika when a message is delivered from RabbitMQ. The
channel is passed for your convenience. The basic_deliver object that
is passed in carries the exchange, routing key, delivery tag and
a redelivered flag for the message. The properties... | python | def _on_message(channel, method, header, body):
"""
Invoked by pika when a message is delivered from RabbitMQ. The
channel is passed for your convenience. The basic_deliver object that
is passed in carries the exchange, routing key, delivery tag and
a redelivered flag for the message. The properties... | [
"def",
"_on_message",
"(",
"channel",
",",
"method",
",",
"header",
",",
"body",
")",
":",
"print",
"\"Message:\"",
"print",
"\"\\t%r\"",
"%",
"method",
"print",
"\"\\t%r\"",
"%",
"header",
"print",
"\"\\t%r\"",
"%",
"body",
"# Acknowledge message receipt",
"cha... | Invoked by pika when a message is delivered from RabbitMQ. The
channel is passed for your convenience. The basic_deliver object that
is passed in carries the exchange, routing key, delivery tag and
a redelivered flag for the message. The properties passed in is an
instance of BasicProperties with the me... | [
"Invoked",
"by",
"pika",
"when",
"a",
"message",
"is",
"delivered",
"from",
"RabbitMQ",
".",
"The",
"channel",
"is",
"passed",
"for",
"your",
"convenience",
".",
"The",
"basic_deliver",
"object",
"that",
"is",
"passed",
"in",
"carries",
"the",
"exchange",
"r... | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L10-L33 |
deginner/mq-client | mq_client.py | BlockingMQClient.publish | def publish(self, message):
"""
Publish a message to the queue.
:param str message: The message to send
"""
props = pika.BasicProperties(content_type='text/plain', delivery_mode=1)
self.channel.basic_publish(self._exchange,
self._routin... | python | def publish(self, message):
"""
Publish a message to the queue.
:param str message: The message to send
"""
props = pika.BasicProperties(content_type='text/plain', delivery_mode=1)
self.channel.basic_publish(self._exchange,
self._routin... | [
"def",
"publish",
"(",
"self",
",",
"message",
")",
":",
"props",
"=",
"pika",
".",
"BasicProperties",
"(",
"content_type",
"=",
"'text/plain'",
",",
"delivery_mode",
"=",
"1",
")",
"self",
".",
"channel",
".",
"basic_publish",
"(",
"self",
".",
"_exchange... | Publish a message to the queue.
:param str message: The message to send | [
"Publish",
"a",
"message",
"to",
"the",
"queue",
"."
] | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L51-L61 |
deginner/mq-client | mq_client.py | BlockingMQClient.consume | def consume(self, on_message, queue):
"""
Publish a message to the queue.
:param function on_message: Function to call upon recieving a message
:param str queue: The queue to publish to
"""
self.channel.queue_declare(queue=queue, durable=True, exclusive=False,
... | python | def consume(self, on_message, queue):
"""
Publish a message to the queue.
:param function on_message: Function to call upon recieving a message
:param str queue: The queue to publish to
"""
self.channel.queue_declare(queue=queue, durable=True, exclusive=False,
... | [
"def",
"consume",
"(",
"self",
",",
"on_message",
",",
"queue",
")",
":",
"self",
".",
"channel",
".",
"queue_declare",
"(",
"queue",
"=",
"queue",
",",
"durable",
"=",
"True",
",",
"exclusive",
"=",
"False",
",",
"auto_delete",
"=",
"False",
")",
"sel... | Publish a message to the queue.
:param function on_message: Function to call upon recieving a message
:param str queue: The queue to publish to | [
"Publish",
"a",
"message",
"to",
"the",
"queue",
"."
] | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L63-L79 |
deginner/mq-client | mq_client.py | AsyncMQClient.connect | def connect(self):
"""
This method connects to RabbitMQ, returning the connection handle.
When the connection is established, the on_connection_open method
will be invoked by pika.
:rtype: pika.SelectConnection
"""
self._logger.info('Connecting to %s' % self._url... | python | def connect(self):
"""
This method connects to RabbitMQ, returning the connection handle.
When the connection is established, the on_connection_open method
will be invoked by pika.
:rtype: pika.SelectConnection
"""
self._logger.info('Connecting to %s' % self._url... | [
"def",
"connect",
"(",
"self",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Connecting to %s'",
"%",
"self",
".",
"_url",
")",
"return",
"adapters",
".",
"TornadoConnection",
"(",
"pika",
".",
"URLParameters",
"(",
"self",
".",
"_url",
")",
",",... | This method connects to RabbitMQ, returning the connection handle.
When the connection is established, the on_connection_open method
will be invoked by pika.
:rtype: pika.SelectConnection | [
"This",
"method",
"connects",
"to",
"RabbitMQ",
"returning",
"the",
"connection",
"handle",
".",
"When",
"the",
"connection",
"is",
"established",
"the",
"on_connection_open",
"method",
"will",
"be",
"invoked",
"by",
"pika",
"."
] | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L125-L136 |
deginner/mq-client | mq_client.py | AsyncMQClient.on_connection_open | def on_connection_open(self, unused_connection):
"""
Called by pika once the connection to RabbitMQ has
been established. It passes the handle to the connection object in
case we need it, but in this case, we'll just mark it unused.
:type unused_connection: pika.SelectConnection... | python | def on_connection_open(self, unused_connection):
"""
Called by pika once the connection to RabbitMQ has
been established. It passes the handle to the connection object in
case we need it, but in this case, we'll just mark it unused.
:type unused_connection: pika.SelectConnection... | [
"def",
"on_connection_open",
"(",
"self",
",",
"unused_connection",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Connection opened'",
")",
"self",
".",
"add_on_connection_close_callback",
"(",
")",
"self",
".",
"open_channel",
"(",
")"
] | Called by pika once the connection to RabbitMQ has
been established. It passes the handle to the connection object in
case we need it, but in this case, we'll just mark it unused.
:type unused_connection: pika.SelectConnection | [
"Called",
"by",
"pika",
"once",
"the",
"connection",
"to",
"RabbitMQ",
"has",
"been",
"established",
".",
"It",
"passes",
"the",
"handle",
"to",
"the",
"connection",
"object",
"in",
"case",
"we",
"need",
"it",
"but",
"in",
"this",
"case",
"we",
"ll",
"ju... | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L138-L148 |
deginner/mq-client | mq_client.py | AsyncMQClient.add_on_connection_close_callback | def add_on_connection_close_callback(self):
"""
Add an on close callback that will be invoked by pika
when RabbitMQ closes the connection to the publisher unexpectedly.
"""
self._logger.debug('Adding connection close callback')
self._connection.add_on_close_callback(self.... | python | def add_on_connection_close_callback(self):
"""
Add an on close callback that will be invoked by pika
when RabbitMQ closes the connection to the publisher unexpectedly.
"""
self._logger.debug('Adding connection close callback')
self._connection.add_on_close_callback(self.... | [
"def",
"add_on_connection_close_callback",
"(",
"self",
")",
":",
"self",
".",
"_logger",
".",
"debug",
"(",
"'Adding connection close callback'",
")",
"self",
".",
"_connection",
".",
"add_on_close_callback",
"(",
"self",
".",
"on_connection_closed",
")"
] | Add an on close callback that will be invoked by pika
when RabbitMQ closes the connection to the publisher unexpectedly. | [
"Add",
"an",
"on",
"close",
"callback",
"that",
"will",
"be",
"invoked",
"by",
"pika",
"when",
"RabbitMQ",
"closes",
"the",
"connection",
"to",
"the",
"publisher",
"unexpectedly",
"."
] | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L150-L156 |
deginner/mq-client | mq_client.py | AsyncMQClient.reconnect | def reconnect(self):
"""
Invoked by the IOLoop timer if the connection is
closed. See the on_connection_closed method.
"""
# This is the old connection IOLoop instance, stop its ioloop
self._connection.ioloop.stop()
if not self._closing:
# Create a ne... | python | def reconnect(self):
"""
Invoked by the IOLoop timer if the connection is
closed. See the on_connection_closed method.
"""
# This is the old connection IOLoop instance, stop its ioloop
self._connection.ioloop.stop()
if not self._closing:
# Create a ne... | [
"def",
"reconnect",
"(",
"self",
")",
":",
"# This is the old connection IOLoop instance, stop its ioloop",
"self",
".",
"_connection",
".",
"ioloop",
".",
"stop",
"(",
")",
"if",
"not",
"self",
".",
"_closing",
":",
"# Create a new connection",
"self",
".",
"_conne... | Invoked by the IOLoop timer if the connection is
closed. See the on_connection_closed method. | [
"Invoked",
"by",
"the",
"IOLoop",
"timer",
"if",
"the",
"connection",
"is",
"closed",
".",
"See",
"the",
"on_connection_closed",
"method",
"."
] | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L175-L187 |
deginner/mq-client | mq_client.py | AsyncMQClient.open_channel | def open_channel(self):
"""
Open a new channel with RabbitMQ by issuing the Channel.Open RPC
command. When RabbitMQ responds that the channel is open, the
on_channel_open callback will be invoked by pika.
"""
self._logger.debug('Creating a new channel')
self._conn... | python | def open_channel(self):
"""
Open a new channel with RabbitMQ by issuing the Channel.Open RPC
command. When RabbitMQ responds that the channel is open, the
on_channel_open callback will be invoked by pika.
"""
self._logger.debug('Creating a new channel')
self._conn... | [
"def",
"open_channel",
"(",
"self",
")",
":",
"self",
".",
"_logger",
".",
"debug",
"(",
"'Creating a new channel'",
")",
"self",
".",
"_connection",
".",
"channel",
"(",
"on_open_callback",
"=",
"self",
".",
"on_channel_open",
")"
] | Open a new channel with RabbitMQ by issuing the Channel.Open RPC
command. When RabbitMQ responds that the channel is open, the
on_channel_open callback will be invoked by pika. | [
"Open",
"a",
"new",
"channel",
"with",
"RabbitMQ",
"by",
"issuing",
"the",
"Channel",
".",
"Open",
"RPC",
"command",
".",
"When",
"RabbitMQ",
"responds",
"that",
"the",
"channel",
"is",
"open",
"the",
"on_channel_open",
"callback",
"will",
"be",
"invoked",
"... | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L189-L196 |
deginner/mq-client | mq_client.py | AsyncMQClient.on_channel_open | def on_channel_open(self, channel):
"""
Invoked by pika when the channel has been opened.
The channel object is passed in so we can make use of it.
Since the channel is now open, we'll declare the exchange to use.
:param pika.channel.Channel channel: The channel object
... | python | def on_channel_open(self, channel):
"""
Invoked by pika when the channel has been opened.
The channel object is passed in so we can make use of it.
Since the channel is now open, we'll declare the exchange to use.
:param pika.channel.Channel channel: The channel object
... | [
"def",
"on_channel_open",
"(",
"self",
",",
"channel",
")",
":",
"self",
".",
"_logger",
".",
"debug",
"(",
"'Channel opened'",
")",
"self",
".",
"_channel",
"=",
"channel",
"self",
".",
"_channel",
".",
"parent_client",
"=",
"self",
"self",
".",
"add_on_c... | Invoked by pika when the channel has been opened.
The channel object is passed in so we can make use of it.
Since the channel is now open, we'll declare the exchange to use.
:param pika.channel.Channel channel: The channel object | [
"Invoked",
"by",
"pika",
"when",
"the",
"channel",
"has",
"been",
"opened",
".",
"The",
"channel",
"object",
"is",
"passed",
"in",
"so",
"we",
"can",
"make",
"use",
"of",
"it",
"."
] | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L198-L211 |
deginner/mq-client | mq_client.py | AsyncMQClient.add_on_channel_close_callback | def add_on_channel_close_callback(self):
"""
Tell pika to call the on_channel_closed method if
RabbitMQ unexpectedly closes the channel.
"""
self._logger.info('Adding channel close callback')
self._channel.add_on_close_callback(self.on_channel_closed) | python | def add_on_channel_close_callback(self):
"""
Tell pika to call the on_channel_closed method if
RabbitMQ unexpectedly closes the channel.
"""
self._logger.info('Adding channel close callback')
self._channel.add_on_close_callback(self.on_channel_closed) | [
"def",
"add_on_channel_close_callback",
"(",
"self",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Adding channel close callback'",
")",
"self",
".",
"_channel",
".",
"add_on_close_callback",
"(",
"self",
".",
"on_channel_closed",
")"
] | Tell pika to call the on_channel_closed method if
RabbitMQ unexpectedly closes the channel. | [
"Tell",
"pika",
"to",
"call",
"the",
"on_channel_closed",
"method",
"if",
"RabbitMQ",
"unexpectedly",
"closes",
"the",
"channel",
"."
] | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L213-L219 |
deginner/mq-client | mq_client.py | AsyncMQClient.on_channel_closed | def on_channel_closed(self, channel, reply_code, reply_text):
"""
Invoked by pika when RabbitMQ unexpectedly closes the channel.
Channels are usually closed if you attempt to do something that
violates the protocol, such as re-declare an exchange or queue with
different parameter... | python | def on_channel_closed(self, channel, reply_code, reply_text):
"""
Invoked by pika when RabbitMQ unexpectedly closes the channel.
Channels are usually closed if you attempt to do something that
violates the protocol, such as re-declare an exchange or queue with
different parameter... | [
"def",
"on_channel_closed",
"(",
"self",
",",
"channel",
",",
"reply_code",
",",
"reply_text",
")",
":",
"self",
".",
"_logger",
".",
"warning",
"(",
"'Channel was closed: (%s) %s'",
",",
"reply_code",
",",
"reply_text",
")",
"if",
"not",
"self",
".",
"_closin... | Invoked by pika when RabbitMQ unexpectedly closes the channel.
Channels are usually closed if you attempt to do something that
violates the protocol, such as re-declare an exchange or queue with
different parameters. In this case, we'll close the connection
to shutdown the object.
... | [
"Invoked",
"by",
"pika",
"when",
"RabbitMQ",
"unexpectedly",
"closes",
"the",
"channel",
".",
"Channels",
"are",
"usually",
"closed",
"if",
"you",
"attempt",
"to",
"do",
"something",
"that",
"violates",
"the",
"protocol",
"such",
"as",
"re",
"-",
"declare",
... | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L221-L235 |
deginner/mq-client | mq_client.py | AsyncMQClient.setup_exchange | def setup_exchange(self, exchange_name):
"""
Setup the exchange on RabbitMQ by invoking the Exchange.Declare RPC
command. When it is complete, the on_exchange_declareok method will
be invoked by pika.
:param str|unicode exchange_name: The name of the exchange to declare
... | python | def setup_exchange(self, exchange_name):
"""
Setup the exchange on RabbitMQ by invoking the Exchange.Declare RPC
command. When it is complete, the on_exchange_declareok method will
be invoked by pika.
:param str|unicode exchange_name: The name of the exchange to declare
... | [
"def",
"setup_exchange",
"(",
"self",
",",
"exchange_name",
")",
":",
"self",
".",
"_logger",
".",
"debug",
"(",
"'Declaring exchange %s'",
"%",
"exchange_name",
")",
"try",
":",
"self",
".",
"_channel",
".",
"exchange_declare",
"(",
"self",
".",
"on_exchange_... | Setup the exchange on RabbitMQ by invoking the Exchange.Declare RPC
command. When it is complete, the on_exchange_declareok method will
be invoked by pika.
:param str|unicode exchange_name: The name of the exchange to declare | [
"Setup",
"the",
"exchange",
"on",
"RabbitMQ",
"by",
"invoking",
"the",
"Exchange",
".",
"Declare",
"RPC",
"command",
".",
"When",
"it",
"is",
"complete",
"the",
"on_exchange_declareok",
"method",
"will",
"be",
"invoked",
"by",
"pika",
"."
] | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L237-L251 |
deginner/mq-client | mq_client.py | AsyncMQClient.on_exchange_declareok | def on_exchange_declareok(self, unused_frame):
"""
Invoked by pika when RabbitMQ has finished the Exchange.Declare RPC
command.
:param pika.Frame.Method unused_frame: Exchange.DeclareOk response frame
"""
self._logger.debug('Exchange declared')
self.setup_queue(s... | python | def on_exchange_declareok(self, unused_frame):
"""
Invoked by pika when RabbitMQ has finished the Exchange.Declare RPC
command.
:param pika.Frame.Method unused_frame: Exchange.DeclareOk response frame
"""
self._logger.debug('Exchange declared')
self.setup_queue(s... | [
"def",
"on_exchange_declareok",
"(",
"self",
",",
"unused_frame",
")",
":",
"self",
".",
"_logger",
".",
"debug",
"(",
"'Exchange declared'",
")",
"self",
".",
"setup_queue",
"(",
"self",
".",
"_queue",
")"
] | Invoked by pika when RabbitMQ has finished the Exchange.Declare RPC
command.
:param pika.Frame.Method unused_frame: Exchange.DeclareOk response frame | [
"Invoked",
"by",
"pika",
"when",
"RabbitMQ",
"has",
"finished",
"the",
"Exchange",
".",
"Declare",
"RPC",
"command",
"."
] | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L253-L261 |
deginner/mq-client | mq_client.py | AsyncMQClient.setup_queue | def setup_queue(self, queue_name):
"""
Setup the queue on RabbitMQ by invoking the Queue.Declare RPC
command. When it is complete, the on_queue_declareok method will
be invoked by pika.
:param str|unicode queue_name: The name of the queue to declare.
"""
self._lo... | python | def setup_queue(self, queue_name):
"""
Setup the queue on RabbitMQ by invoking the Queue.Declare RPC
command. When it is complete, the on_queue_declareok method will
be invoked by pika.
:param str|unicode queue_name: The name of the queue to declare.
"""
self._lo... | [
"def",
"setup_queue",
"(",
"self",
",",
"queue_name",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Declaring queue %s'",
",",
"queue_name",
")",
"self",
".",
"_channel",
".",
"queue_declare",
"(",
"self",
".",
"on_queue_declareok",
",",
"queue_name",
... | Setup the queue on RabbitMQ by invoking the Queue.Declare RPC
command. When it is complete, the on_queue_declareok method will
be invoked by pika.
:param str|unicode queue_name: The name of the queue to declare. | [
"Setup",
"the",
"queue",
"on",
"RabbitMQ",
"by",
"invoking",
"the",
"Queue",
".",
"Declare",
"RPC",
"command",
".",
"When",
"it",
"is",
"complete",
"the",
"on_queue_declareok",
"method",
"will",
"be",
"invoked",
"by",
"pika",
"."
] | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L263-L274 |
deginner/mq-client | mq_client.py | AsyncMQClient.on_queue_declareok | def on_queue_declareok(self, method_frame):
"""
Invoked by pika when the Queue.Declare RPC call made in
setup_queue has completed. In this method we will bind the queue
and exchange together with the routing key by issuing the Queue.Bind
RPC command. When this command is complete... | python | def on_queue_declareok(self, method_frame):
"""
Invoked by pika when the Queue.Declare RPC call made in
setup_queue has completed. In this method we will bind the queue
and exchange together with the routing key by issuing the Queue.Bind
RPC command. When this command is complete... | [
"def",
"on_queue_declareok",
"(",
"self",
",",
"method_frame",
")",
":",
"self",
".",
"_logger",
".",
"debug",
"(",
"'Binding %s to %s with %s'",
",",
"self",
".",
"_exchange",
",",
"self",
".",
"_queue",
",",
"self",
".",
"_routing_key",
")",
"self",
".",
... | Invoked by pika when the Queue.Declare RPC call made in
setup_queue has completed. In this method we will bind the queue
and exchange together with the routing key by issuing the Queue.Bind
RPC command. When this command is complete, the on_bindok method will
be invoked by pika.
... | [
"Invoked",
"by",
"pika",
"when",
"the",
"Queue",
".",
"Declare",
"RPC",
"call",
"made",
"in",
"setup_queue",
"has",
"completed",
".",
"In",
"this",
"method",
"we",
"will",
"bind",
"the",
"queue",
"and",
"exchange",
"together",
"with",
"the",
"routing",
"ke... | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L276-L290 |
deginner/mq-client | mq_client.py | AsyncMQClient.close_channel | def close_channel(self):
"""
Invoke this command to close the channel with RabbitMQ by sending
the Channel.Close RPC command.
"""
self._logger.info('Closing the channel')
if self._channel:
self._channel.close() | python | def close_channel(self):
"""
Invoke this command to close the channel with RabbitMQ by sending
the Channel.Close RPC command.
"""
self._logger.info('Closing the channel')
if self._channel:
self._channel.close() | [
"def",
"close_channel",
"(",
"self",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Closing the channel'",
")",
"if",
"self",
".",
"_channel",
":",
"self",
".",
"_channel",
".",
"close",
"(",
")"
] | Invoke this command to close the channel with RabbitMQ by sending
the Channel.Close RPC command. | [
"Invoke",
"this",
"command",
"to",
"close",
"the",
"channel",
"with",
"RabbitMQ",
"by",
"sending",
"the",
"Channel",
".",
"Close",
"RPC",
"command",
"."
] | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L292-L299 |
deginner/mq-client | mq_client.py | AsyncMQClient.close_connection | def close_connection(self):
"""This method closes the connection to RabbitMQ."""
self._logger.info('Closing connection')
self._closing = True
self._connection.close() | python | def close_connection(self):
"""This method closes the connection to RabbitMQ."""
self._logger.info('Closing connection')
self._closing = True
self._connection.close() | [
"def",
"close_connection",
"(",
"self",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Closing connection'",
")",
"self",
".",
"_closing",
"=",
"True",
"self",
".",
"_connection",
".",
"close",
"(",
")"
] | This method closes the connection to RabbitMQ. | [
"This",
"method",
"closes",
"the",
"connection",
"to",
"RabbitMQ",
"."
] | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L309-L313 |
deginner/mq-client | mq_client.py | AsyncMQPublisher.on_bindok | def on_bindok(self, unused_frame):
"""
This method is invoked by pika when it receives the Queue.BindOk
response from RabbitMQ.
"""
self._logger.info('Queue bound')
while not self._stopping:
# perform the action that publishes on this client
self.p... | python | def on_bindok(self, unused_frame):
"""
This method is invoked by pika when it receives the Queue.BindOk
response from RabbitMQ.
"""
self._logger.info('Queue bound')
while not self._stopping:
# perform the action that publishes on this client
self.p... | [
"def",
"on_bindok",
"(",
"self",
",",
"unused_frame",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Queue bound'",
")",
"while",
"not",
"self",
".",
"_stopping",
":",
"# perform the action that publishes on this client",
"self",
".",
"producer",
"(",
"se... | This method is invoked by pika when it receives the Queue.BindOk
response from RabbitMQ. | [
"This",
"method",
"is",
"invoked",
"by",
"pika",
"when",
"it",
"receives",
"the",
"Queue",
".",
"BindOk",
"response",
"from",
"RabbitMQ",
"."
] | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L343-L352 |
deginner/mq-client | mq_client.py | AsyncMQPublisher.publish | def publish(self, message):
"""
If not stopping, publish a message to RabbitMQ.
:param str message: The fully encoded message to publish
"""
if self._stopping:
return
self._logger.info("publishing\t%s" % message)
properties = pika.BasicProperties(cont... | python | def publish(self, message):
"""
If not stopping, publish a message to RabbitMQ.
:param str message: The fully encoded message to publish
"""
if self._stopping:
return
self._logger.info("publishing\t%s" % message)
properties = pika.BasicProperties(cont... | [
"def",
"publish",
"(",
"self",
",",
"message",
")",
":",
"if",
"self",
".",
"_stopping",
":",
"return",
"self",
".",
"_logger",
".",
"info",
"(",
"\"publishing\\t%s\"",
"%",
"message",
")",
"properties",
"=",
"pika",
".",
"BasicProperties",
"(",
"content_t... | If not stopping, publish a message to RabbitMQ.
:param str message: The fully encoded message to publish | [
"If",
"not",
"stopping",
"publish",
"a",
"message",
"to",
"RabbitMQ",
"."
] | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L354-L369 |
deginner/mq-client | mq_client.py | AsyncMQPublisher.stop | def stop(self):
"""
Stop the mq publisher by closing the channel and connection. We
set a flag here so that we stop scheduling new messages to be
published. The IOLoop is started because this method is
invoked by the Try/Catch below when KeyboardInterrupt is caught.
Start... | python | def stop(self):
"""
Stop the mq publisher by closing the channel and connection. We
set a flag here so that we stop scheduling new messages to be
published. The IOLoop is started because this method is
invoked by the Try/Catch below when KeyboardInterrupt is caught.
Start... | [
"def",
"stop",
"(",
"self",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Stopping'",
")",
"self",
".",
"_stopping",
"=",
"True",
"self",
".",
"close_connection",
"(",
")",
"try",
":",
"self",
".",
"_connection",
".",
"ioloop",
".",
"start",
... | Stop the mq publisher by closing the channel and connection. We
set a flag here so that we stop scheduling new messages to be
published. The IOLoop is started because this method is
invoked by the Try/Catch below when KeyboardInterrupt is caught.
Starting the IOLoop again will allow the ... | [
"Stop",
"the",
"mq",
"publisher",
"by",
"closing",
"the",
"channel",
"and",
"connection",
".",
"We",
"set",
"a",
"flag",
"here",
"so",
"that",
"we",
"stop",
"scheduling",
"new",
"messages",
"to",
"be",
"published",
".",
"The",
"IOLoop",
"is",
"started",
... | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L371-L387 |
deginner/mq-client | mq_client.py | AsyncMQConsumer.start_consuming | def start_consuming(self):
"""
This method sets up the consumer by first calling
add_on_cancel_callback so that the object is notified if RabbitMQ
cancels the consumer. It then issues the Basic.Consume RPC command
which returns the consumer tag that is used to uniquely identify t... | python | def start_consuming(self):
"""
This method sets up the consumer by first calling
add_on_cancel_callback so that the object is notified if RabbitMQ
cancels the consumer. It then issues the Basic.Consume RPC command
which returns the consumer tag that is used to uniquely identify t... | [
"def",
"start_consuming",
"(",
"self",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Issuing consumer related RPC commands'",
")",
"self",
".",
"add_on_cancel_callback",
"(",
")",
"self",
".",
"_consumer_tag",
"=",
"self",
".",
"_channel",
".",
"basic_co... | This method sets up the consumer by first calling
add_on_cancel_callback so that the object is notified if RabbitMQ
cancels the consumer. It then issues the Basic.Consume RPC command
which returns the consumer tag that is used to uniquely identify the
consumer with RabbitMQ. We keep the ... | [
"This",
"method",
"sets",
"up",
"the",
"consumer",
"by",
"first",
"calling",
"add_on_cancel_callback",
"so",
"that",
"the",
"object",
"is",
"notified",
"if",
"RabbitMQ",
"cancels",
"the",
"consumer",
".",
"It",
"then",
"issues",
"the",
"Basic",
".",
"Consume",... | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L419-L432 |
deginner/mq-client | mq_client.py | AsyncMQConsumer.add_on_cancel_callback | def add_on_cancel_callback(self):
"""
Add a callback that will be invoked if RabbitMQ cancels the consumer
for some reason. If RabbitMQ does cancel the consumer,
on_consumer_cancelled will be invoked by pika.
"""
self._logger.info('Adding consumer cancellation callback')
... | python | def add_on_cancel_callback(self):
"""
Add a callback that will be invoked if RabbitMQ cancels the consumer
for some reason. If RabbitMQ does cancel the consumer,
on_consumer_cancelled will be invoked by pika.
"""
self._logger.info('Adding consumer cancellation callback')
... | [
"def",
"add_on_cancel_callback",
"(",
"self",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Adding consumer cancellation callback'",
")",
"self",
".",
"_channel",
".",
"add_on_cancel_callback",
"(",
"self",
".",
"on_consumer_cancelled",
")"
] | Add a callback that will be invoked if RabbitMQ cancels the consumer
for some reason. If RabbitMQ does cancel the consumer,
on_consumer_cancelled will be invoked by pika. | [
"Add",
"a",
"callback",
"that",
"will",
"be",
"invoked",
"if",
"RabbitMQ",
"cancels",
"the",
"consumer",
"for",
"some",
"reason",
".",
"If",
"RabbitMQ",
"does",
"cancel",
"the",
"consumer",
"on_consumer_cancelled",
"will",
"be",
"invoked",
"by",
"pika",
"."
] | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L434-L441 |
deginner/mq-client | mq_client.py | AsyncMQConsumer.stop_consuming | def stop_consuming(self):
"""
Tell RabbitMQ that you would like to stop consuming by sending the
Basic.Cancel RPC command.
"""
if self._channel:
self._logger.info('Sending a Basic.Cancel RPC command to RabbitMQ')
self._channel.basic_cancel(self.on_cancelok... | python | def stop_consuming(self):
"""
Tell RabbitMQ that you would like to stop consuming by sending the
Basic.Cancel RPC command.
"""
if self._channel:
self._logger.info('Sending a Basic.Cancel RPC command to RabbitMQ')
self._channel.basic_cancel(self.on_cancelok... | [
"def",
"stop_consuming",
"(",
"self",
")",
":",
"if",
"self",
".",
"_channel",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Sending a Basic.Cancel RPC command to RabbitMQ'",
")",
"self",
".",
"_channel",
".",
"basic_cancel",
"(",
"self",
".",
"on_cancelok",
... | Tell RabbitMQ that you would like to stop consuming by sending the
Basic.Cancel RPC command. | [
"Tell",
"RabbitMQ",
"that",
"you",
"would",
"like",
"to",
"stop",
"consuming",
"by",
"sending",
"the",
"Basic",
".",
"Cancel",
"RPC",
"command",
"."
] | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L455-L462 |
deginner/mq-client | mq_client.py | AsyncMQConsumer.stop | def stop(self):
"""
Cleanly shutdown the connection to RabbitMQ by stopping the consumer
with RabbitMQ. When RabbitMQ confirms the cancellation, on_cancelok
will be invoked by pika, which will then closing the channel and
connection. The IOLoop is started again because this metho... | python | def stop(self):
"""
Cleanly shutdown the connection to RabbitMQ by stopping the consumer
with RabbitMQ. When RabbitMQ confirms the cancellation, on_cancelok
will be invoked by pika, which will then closing the channel and
connection. The IOLoop is started again because this metho... | [
"def",
"stop",
"(",
"self",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Stopping'",
")",
"self",
".",
"_closing",
"=",
"True",
"self",
".",
"stop_consuming",
"(",
")",
"try",
":",
"self",
".",
"_connection",
".",
"ioloop",
".",
"start",
"("... | Cleanly shutdown the connection to RabbitMQ by stopping the consumer
with RabbitMQ. When RabbitMQ confirms the cancellation, on_cancelok
will be invoked by pika, which will then closing the channel and
connection. The IOLoop is started again because this method is invoked
when CTRL-C is ... | [
"Cleanly",
"shutdown",
"the",
"connection",
"to",
"RabbitMQ",
"by",
"stopping",
"the",
"consumer",
"with",
"RabbitMQ",
".",
"When",
"RabbitMQ",
"confirms",
"the",
"cancellation",
"on_cancelok",
"will",
"be",
"invoked",
"by",
"pika",
"which",
"will",
"then",
"clo... | train | https://github.com/deginner/mq-client/blob/a20ab50ea18870c01e8d142b049233c355858872/mq_client.py#L477-L495 |
zvolsky/wfpdf | wfpdf.py | Utils.txt | def txt(self, txt, h=None, at_x=None, to_x=None, change_style=None, change_size=None):
"""print string to defined (at_x) position
to_x can apply only if at_x is None and if used then forces align='R'
"""
h = h or self.height
self._change_props(change_style, change_size)
a... | python | def txt(self, txt, h=None, at_x=None, to_x=None, change_style=None, change_size=None):
"""print string to defined (at_x) position
to_x can apply only if at_x is None and if used then forces align='R'
"""
h = h or self.height
self._change_props(change_style, change_size)
a... | [
"def",
"txt",
"(",
"self",
",",
"txt",
",",
"h",
"=",
"None",
",",
"at_x",
"=",
"None",
",",
"to_x",
"=",
"None",
",",
"change_style",
"=",
"None",
",",
"change_size",
"=",
"None",
")",
":",
"h",
"=",
"h",
"or",
"self",
".",
"height",
"self",
"... | print string to defined (at_x) position
to_x can apply only if at_x is None and if used then forces align='R' | [
"print",
"string",
"to",
"defined",
"(",
"at_x",
")",
"position",
"to_x",
"can",
"apply",
"only",
"if",
"at_x",
"is",
"None",
"and",
"if",
"used",
"then",
"forces",
"align",
"=",
"R"
] | train | https://github.com/zvolsky/wfpdf/blob/d3625a6420ae1fb6722d81cddf0636af496c42bb/wfpdf.py#L92-L109 |
zvolsky/wfpdf | wfpdf.py | Utils.num | def num(self, num, h=None, to_x=None, format="%.2f", change_style=None, change_size=None):
"""print number (int/float) right aligned before defined (to_x) position
"""
self.txt(format % num, h=h, to_x=to_x, change_style=change_style, change_size=change_size) | python | def num(self, num, h=None, to_x=None, format="%.2f", change_style=None, change_size=None):
"""print number (int/float) right aligned before defined (to_x) position
"""
self.txt(format % num, h=h, to_x=to_x, change_style=change_style, change_size=change_size) | [
"def",
"num",
"(",
"self",
",",
"num",
",",
"h",
"=",
"None",
",",
"to_x",
"=",
"None",
",",
"format",
"=",
"\"%.2f\"",
",",
"change_style",
"=",
"None",
",",
"change_size",
"=",
"None",
")",
":",
"self",
".",
"txt",
"(",
"format",
"%",
"num",
",... | print number (int/float) right aligned before defined (to_x) position | [
"print",
"number",
"(",
"int",
"/",
"float",
")",
"right",
"aligned",
"before",
"defined",
"(",
"to_x",
")",
"position"
] | train | https://github.com/zvolsky/wfpdf/blob/d3625a6420ae1fb6722d81cddf0636af496c42bb/wfpdf.py#L111-L114 |
zvolsky/wfpdf | wfpdf.py | Utils.header | def header(self, item0, *items):
"""print string item0 to the current position and next strings to defined positions
example: .header("Name", 75, "Quantity", 100, "Unit")
"""
self.txt(item0)
at_x = None
for item in items:
if at_x is None:
at_x ... | python | def header(self, item0, *items):
"""print string item0 to the current position and next strings to defined positions
example: .header("Name", 75, "Quantity", 100, "Unit")
"""
self.txt(item0)
at_x = None
for item in items:
if at_x is None:
at_x ... | [
"def",
"header",
"(",
"self",
",",
"item0",
",",
"*",
"items",
")",
":",
"self",
".",
"txt",
"(",
"item0",
")",
"at_x",
"=",
"None",
"for",
"item",
"in",
"items",
":",
"if",
"at_x",
"is",
"None",
":",
"at_x",
"=",
"item",
"else",
":",
"self",
"... | print string item0 to the current position and next strings to defined positions
example: .header("Name", 75, "Quantity", 100, "Unit") | [
"print",
"string",
"item0",
"to",
"the",
"current",
"position",
"and",
"next",
"strings",
"to",
"defined",
"positions",
"example",
":",
".",
"header",
"(",
"Name",
"75",
"Quantity",
"100",
"Unit",
")"
] | train | https://github.com/zvolsky/wfpdf/blob/d3625a6420ae1fb6722d81cddf0636af496c42bb/wfpdf.py#L116-L127 |
zvolsky/wfpdf | wfpdf.py | Utils.down | def down(self, h, cr=True):
"""moves current vertical position h mm down
cr True will navigate to the left margin
"""
if cr:
self.oPdf.ln(h=0)
self.oPdf.set_y(self.oPdf.get_y() + h) | python | def down(self, h, cr=True):
"""moves current vertical position h mm down
cr True will navigate to the left margin
"""
if cr:
self.oPdf.ln(h=0)
self.oPdf.set_y(self.oPdf.get_y() + h) | [
"def",
"down",
"(",
"self",
",",
"h",
",",
"cr",
"=",
"True",
")",
":",
"if",
"cr",
":",
"self",
".",
"oPdf",
".",
"ln",
"(",
"h",
"=",
"0",
")",
"self",
".",
"oPdf",
".",
"set_y",
"(",
"self",
".",
"oPdf",
".",
"get_y",
"(",
")",
"+",
"h... | moves current vertical position h mm down
cr True will navigate to the left margin | [
"moves",
"current",
"vertical",
"position",
"h",
"mm",
"down",
"cr",
"True",
"will",
"navigate",
"to",
"the",
"left",
"margin"
] | train | https://github.com/zvolsky/wfpdf/blob/d3625a6420ae1fb6722d81cddf0636af496c42bb/wfpdf.py#L129-L135 |
uw-it-aca/uw-restclients | restclients/amazon_sqs.py | AmazonSQS.read_queue | def read_queue(self):
"""
This is responsible for reading events off the queue, and sending
notifications to users, via email or SMS.
The following are necessary for AWS access:
RESTCLIENTS_AMAZON_AWS_ACCESS_KEY
RESTCLIENTS_AMAZON_AWS_SECRET_KEY
RESTCLIENTS_AMAZON... | python | def read_queue(self):
"""
This is responsible for reading events off the queue, and sending
notifications to users, via email or SMS.
The following are necessary for AWS access:
RESTCLIENTS_AMAZON_AWS_ACCESS_KEY
RESTCLIENTS_AMAZON_AWS_SECRET_KEY
RESTCLIENTS_AMAZON... | [
"def",
"read_queue",
"(",
"self",
")",
":",
"queue",
"=",
"AmazonSQS",
"(",
")",
".",
"create_queue",
"(",
"settings",
".",
"RESTCLIENTS_AMAZON_QUEUE",
")",
"queue",
".",
"set_message_class",
"(",
"RawMessage",
")",
"message",
"=",
"queue",
".",
"read",
"(",... | This is responsible for reading events off the queue, and sending
notifications to users, via email or SMS.
The following are necessary for AWS access:
RESTCLIENTS_AMAZON_AWS_ACCESS_KEY
RESTCLIENTS_AMAZON_AWS_SECRET_KEY
RESTCLIENTS_AMAZON_QUEUE - the AWS Queue name you want to re... | [
"This",
"is",
"responsible",
"for",
"reading",
"events",
"off",
"the",
"queue",
"and",
"sending",
"notifications",
"to",
"users",
"via",
"email",
"or",
"SMS",
".",
"The",
"following",
"are",
"necessary",
"for",
"AWS",
"access",
":",
"RESTCLIENTS_AMAZON_AWS_ACCES... | train | https://github.com/uw-it-aca/uw-restclients/blob/e12dcd32bf5296b6ebdf71798031594afb7852cb/restclients/amazon_sqs.py#L25-L44 |
nicholasbishop/shaderdef | shaderdef/rewrite_output.py | kwargs_as_assignments | def kwargs_as_assignments(call_node, parent):
"""Yield NoDeclAssign nodes from kwargs in a Call node."""
if not isinstance(call_node, ast.Call):
raise TypeError('node must be an ast.Call')
if len(call_node.args) > 0:
raise ValueError('positional args not allowed')
for keyword in call_n... | python | def kwargs_as_assignments(call_node, parent):
"""Yield NoDeclAssign nodes from kwargs in a Call node."""
if not isinstance(call_node, ast.Call):
raise TypeError('node must be an ast.Call')
if len(call_node.args) > 0:
raise ValueError('positional args not allowed')
for keyword in call_n... | [
"def",
"kwargs_as_assignments",
"(",
"call_node",
",",
"parent",
")",
":",
"if",
"not",
"isinstance",
"(",
"call_node",
",",
"ast",
".",
"Call",
")",
":",
"raise",
"TypeError",
"(",
"'node must be an ast.Call'",
")",
"if",
"len",
"(",
"call_node",
".",
"args... | Yield NoDeclAssign nodes from kwargs in a Call node. | [
"Yield",
"NoDeclAssign",
"nodes",
"from",
"kwargs",
"in",
"a",
"Call",
"node",
"."
] | train | https://github.com/nicholasbishop/shaderdef/blob/b68a9faf4c7cfa61e32a2e49eb2cae2f2e2b1f78/shaderdef/rewrite_output.py#L15-L34 |
nicholasbishop/shaderdef | shaderdef/rewrite_output.py | rewrite_return_as_assignments | def rewrite_return_as_assignments(func_node, interface):
"""Modify FunctionDef node to directly assign instead of return."""
func_node = _RewriteReturn(interface).visit(func_node)
ast.fix_missing_locations(func_node)
return func_node | python | def rewrite_return_as_assignments(func_node, interface):
"""Modify FunctionDef node to directly assign instead of return."""
func_node = _RewriteReturn(interface).visit(func_node)
ast.fix_missing_locations(func_node)
return func_node | [
"def",
"rewrite_return_as_assignments",
"(",
"func_node",
",",
"interface",
")",
":",
"func_node",
"=",
"_RewriteReturn",
"(",
"interface",
")",
".",
"visit",
"(",
"func_node",
")",
"ast",
".",
"fix_missing_locations",
"(",
"func_node",
")",
"return",
"func_node"
... | Modify FunctionDef node to directly assign instead of return. | [
"Modify",
"FunctionDef",
"node",
"to",
"directly",
"assign",
"instead",
"of",
"return",
"."
] | train | https://github.com/nicholasbishop/shaderdef/blob/b68a9faf4c7cfa61e32a2e49eb2cae2f2e2b1f78/shaderdef/rewrite_output.py#L57-L61 |
uw-it-aca/uw-restclients | restclients/iasystem/__init__.py | get_resource | def get_resource(url, subdomain):
"""
Issue a GET request to IASystem with the given url
and return a response in Collection+json format.
:returns: http response with content in json
"""
headers = {"Accept": "application/vnd.collection+json"}
response = IASYSTEM_DAO().getURL(url, headers, su... | python | def get_resource(url, subdomain):
"""
Issue a GET request to IASystem with the given url
and return a response in Collection+json format.
:returns: http response with content in json
"""
headers = {"Accept": "application/vnd.collection+json"}
response = IASYSTEM_DAO().getURL(url, headers, su... | [
"def",
"get_resource",
"(",
"url",
",",
"subdomain",
")",
":",
"headers",
"=",
"{",
"\"Accept\"",
":",
"\"application/vnd.collection+json\"",
"}",
"response",
"=",
"IASYSTEM_DAO",
"(",
")",
".",
"getURL",
"(",
"url",
",",
"headers",
",",
"subdomain",
")",
"l... | Issue a GET request to IASystem with the given url
and return a response in Collection+json format.
:returns: http response with content in json | [
"Issue",
"a",
"GET",
"request",
"to",
"IASystem",
"with",
"the",
"given",
"url",
"and",
"return",
"a",
"response",
"in",
"Collection",
"+",
"json",
"format",
".",
":",
"returns",
":",
"http",
"response",
"with",
"content",
"in",
"json"
] | train | https://github.com/uw-it-aca/uw-restclients/blob/e12dcd32bf5296b6ebdf71798031594afb7852cb/restclients/iasystem/__init__.py#L17-L32 |
liminspace/dju-common | dju_common/tools.py | int2base36 | def int2base36(n):
"""
Convert int base10 to base36.
Back convert: int('<base36>', 36)
"""
assert isinstance(n, (int, long))
c = '0123456789abcdefghijklmnopqrstuvwxyz'
if n < 0:
return '-' + int2base36(-n)
elif n < 36:
return c[n]
b36 = ''
while n != 0:
n,... | python | def int2base36(n):
"""
Convert int base10 to base36.
Back convert: int('<base36>', 36)
"""
assert isinstance(n, (int, long))
c = '0123456789abcdefghijklmnopqrstuvwxyz'
if n < 0:
return '-' + int2base36(-n)
elif n < 36:
return c[n]
b36 = ''
while n != 0:
n,... | [
"def",
"int2base36",
"(",
"n",
")",
":",
"assert",
"isinstance",
"(",
"n",
",",
"(",
"int",
",",
"long",
")",
")",
"c",
"=",
"'0123456789abcdefghijklmnopqrstuvwxyz'",
"if",
"n",
"<",
"0",
":",
"return",
"'-'",
"+",
"int2base36",
"(",
"-",
"n",
")",
"... | Convert int base10 to base36.
Back convert: int('<base36>', 36) | [
"Convert",
"int",
"base10",
"to",
"base36",
".",
"Back",
"convert",
":",
"int",
"(",
"<base36",
">",
"36",
")"
] | train | https://github.com/liminspace/dju-common/blob/c68860bb84d454a35e66275841c20f38375c2135/dju_common/tools.py#L23-L38 |
liminspace/dju-common | dju_common/tools.py | datetime_to_dtstr | def datetime_to_dtstr(dt=None):
"""
Comvert datetime to short text.
If datetime has timezone then it will be convert to UTC0.
"""
if dt is None:
dt = datetime.datetime.utcnow()
elif timezone.is_aware(dt):
dt = dt.astimezone(tz=pytz.UTC)
return int2base36(int(time.mktime(dt.ti... | python | def datetime_to_dtstr(dt=None):
"""
Comvert datetime to short text.
If datetime has timezone then it will be convert to UTC0.
"""
if dt is None:
dt = datetime.datetime.utcnow()
elif timezone.is_aware(dt):
dt = dt.astimezone(tz=pytz.UTC)
return int2base36(int(time.mktime(dt.ti... | [
"def",
"datetime_to_dtstr",
"(",
"dt",
"=",
"None",
")",
":",
"if",
"dt",
"is",
"None",
":",
"dt",
"=",
"datetime",
".",
"datetime",
".",
"utcnow",
"(",
")",
"elif",
"timezone",
".",
"is_aware",
"(",
"dt",
")",
":",
"dt",
"=",
"dt",
".",
"astimezon... | Comvert datetime to short text.
If datetime has timezone then it will be convert to UTC0. | [
"Comvert",
"datetime",
"to",
"short",
"text",
".",
"If",
"datetime",
"has",
"timezone",
"then",
"it",
"will",
"be",
"convert",
"to",
"UTC0",
"."
] | train | https://github.com/liminspace/dju-common/blob/c68860bb84d454a35e66275841c20f38375c2135/dju_common/tools.py#L41-L50 |
liminspace/dju-common | dju_common/tools.py | dtstr_to_datetime | def dtstr_to_datetime(dtstr, to_tz=None, fail_silently=True):
"""
Convert result from datetime_to_dtstr to datetime in timezone UTC0.
"""
try:
dt = datetime.datetime.utcfromtimestamp(int(dtstr, 36) / 1e3)
if to_tz:
dt = timezone.make_aware(dt, timezone=pytz.UTC)
i... | python | def dtstr_to_datetime(dtstr, to_tz=None, fail_silently=True):
"""
Convert result from datetime_to_dtstr to datetime in timezone UTC0.
"""
try:
dt = datetime.datetime.utcfromtimestamp(int(dtstr, 36) / 1e3)
if to_tz:
dt = timezone.make_aware(dt, timezone=pytz.UTC)
i... | [
"def",
"dtstr_to_datetime",
"(",
"dtstr",
",",
"to_tz",
"=",
"None",
",",
"fail_silently",
"=",
"True",
")",
":",
"try",
":",
"dt",
"=",
"datetime",
".",
"datetime",
".",
"utcfromtimestamp",
"(",
"int",
"(",
"dtstr",
",",
"36",
")",
"/",
"1e3",
")",
... | Convert result from datetime_to_dtstr to datetime in timezone UTC0. | [
"Convert",
"result",
"from",
"datetime_to_dtstr",
"to",
"datetime",
"in",
"timezone",
"UTC0",
"."
] | train | https://github.com/liminspace/dju-common/blob/c68860bb84d454a35e66275841c20f38375c2135/dju_common/tools.py#L53-L67 |
liminspace/dju-common | dju_common/tools.py | load_object_by_name | def load_object_by_name(obj_name):
"""
Import object by name (point-path).
Example:
MyForm = load_object_by_name('myapp.forms.MyAnyForm')
"""
parts = obj_name.split('.')
t = __import__('.'.join(parts[:-1]), fromlist=(parts[-1],))
return getattr(t, parts[-1]) | python | def load_object_by_name(obj_name):
"""
Import object by name (point-path).
Example:
MyForm = load_object_by_name('myapp.forms.MyAnyForm')
"""
parts = obj_name.split('.')
t = __import__('.'.join(parts[:-1]), fromlist=(parts[-1],))
return getattr(t, parts[-1]) | [
"def",
"load_object_by_name",
"(",
"obj_name",
")",
":",
"parts",
"=",
"obj_name",
".",
"split",
"(",
"'.'",
")",
"t",
"=",
"__import__",
"(",
"'.'",
".",
"join",
"(",
"parts",
"[",
":",
"-",
"1",
"]",
")",
",",
"fromlist",
"=",
"(",
"parts",
"[",
... | Import object by name (point-path).
Example:
MyForm = load_object_by_name('myapp.forms.MyAnyForm') | [
"Import",
"object",
"by",
"name",
"(",
"point",
"-",
"path",
")",
".",
"Example",
":",
"MyForm",
"=",
"load_object_by_name",
"(",
"myapp",
".",
"forms",
".",
"MyAnyForm",
")"
] | train | https://github.com/liminspace/dju-common/blob/c68860bb84d454a35e66275841c20f38375c2135/dju_common/tools.py#L70-L78 |
liminspace/dju-common | dju_common/tools.py | parse_datetime_aware | def parse_datetime_aware(s, tz=None):
"""
Parse text with datetime to aware datetime (with timezone).
"""
assert settings.USE_TZ
if isinstance(s, datetime.datetime):
return s
d = parse_datetime(s)
if d is None:
raise ValueError
return timezone.make_aware(d, tz or timezone... | python | def parse_datetime_aware(s, tz=None):
"""
Parse text with datetime to aware datetime (with timezone).
"""
assert settings.USE_TZ
if isinstance(s, datetime.datetime):
return s
d = parse_datetime(s)
if d is None:
raise ValueError
return timezone.make_aware(d, tz or timezone... | [
"def",
"parse_datetime_aware",
"(",
"s",
",",
"tz",
"=",
"None",
")",
":",
"assert",
"settings",
".",
"USE_TZ",
"if",
"isinstance",
"(",
"s",
",",
"datetime",
".",
"datetime",
")",
":",
"return",
"s",
"d",
"=",
"parse_datetime",
"(",
"s",
")",
"if",
... | Parse text with datetime to aware datetime (with timezone). | [
"Parse",
"text",
"with",
"datetime",
"to",
"aware",
"datetime",
"(",
"with",
"timezone",
")",
"."
] | train | https://github.com/liminspace/dju-common/blob/c68860bb84d454a35e66275841c20f38375c2135/dju_common/tools.py#L81-L91 |
liminspace/dju-common | dju_common/tools.py | long_number_readable | def long_number_readable(value):
"""
Convert big int (>=999) to readable form.
1000 => 1k.
2333 => 2.3k.
1000000 => 1 mln.
1258000 => 1.26 mln.
"""
value = int(value)
if value < 1000:
return value
for m, d, inf, fnf, n in _long_number_readable_formats:
if value < ... | python | def long_number_readable(value):
"""
Convert big int (>=999) to readable form.
1000 => 1k.
2333 => 2.3k.
1000000 => 1 mln.
1258000 => 1.26 mln.
"""
value = int(value)
if value < 1000:
return value
for m, d, inf, fnf, n in _long_number_readable_formats:
if value < ... | [
"def",
"long_number_readable",
"(",
"value",
")",
":",
"value",
"=",
"int",
"(",
"value",
")",
"if",
"value",
"<",
"1000",
":",
"return",
"value",
"for",
"m",
",",
"d",
",",
"inf",
",",
"fnf",
",",
"n",
"in",
"_long_number_readable_formats",
":",
"if",... | Convert big int (>=999) to readable form.
1000 => 1k.
2333 => 2.3k.
1000000 => 1 mln.
1258000 => 1.26 mln. | [
"Convert",
"big",
"int",
"(",
">",
"=",
"999",
")",
"to",
"readable",
"form",
".",
"1000",
"=",
">",
"1k",
".",
"2333",
"=",
">",
"2",
".",
"3k",
".",
"1000000",
"=",
">",
"1",
"mln",
".",
"1258000",
"=",
">",
"1",
".",
"26",
"mln",
"."
] | train | https://github.com/liminspace/dju-common/blob/c68860bb84d454a35e66275841c20f38375c2135/dju_common/tools.py#L101-L115 |
conchoecia/gloTK | gloTK/merparse.py | MerParse.name_gen | def name_gen(self, as_number, k, diploid_mode):
"""See the sweeper_output() method doctstring for format details."""
#how to add prefixes to numbers
#http://stackoverflow.com/a/135157
# ai_d_z_g_s_k_p.config
parts = {"1ai": "{0}{1:03d}_".format(self.as_a, as_number),
... | python | def name_gen(self, as_number, k, diploid_mode):
"""See the sweeper_output() method doctstring for format details."""
#how to add prefixes to numbers
#http://stackoverflow.com/a/135157
# ai_d_z_g_s_k_p.config
parts = {"1ai": "{0}{1:03d}_".format(self.as_a, as_number),
... | [
"def",
"name_gen",
"(",
"self",
",",
"as_number",
",",
"k",
",",
"diploid_mode",
")",
":",
"#how to add prefixes to numbers",
"#http://stackoverflow.com/a/135157",
"# ai_d_z_g_s_k_p.config",
"parts",
"=",
"{",
"\"1ai\"",
":",
"\"{0}{1:03d}_\"",
".",
"format",
"(... | See the sweeper_output() method doctstring for format details. | [
"See",
"the",
"sweeper_output",
"()",
"method",
"doctstring",
"for",
"format",
"details",
"."
] | train | https://github.com/conchoecia/gloTK/blob/58abee663fcfbbd09f4863c3ca3ae054e33184a8/gloTK/merparse.py#L138-L151 |
conchoecia/gloTK | gloTK/merparse.py | MerParse.sweeper_output | def sweeper_output(self):
"""This method outputs all of the config files in the configs directory
within the current working directory. It names the config files based on
the following format:
a = assembly prefix <default = as>
i = assembly start index <default = 000>
d ... | python | def sweeper_output(self):
"""This method outputs all of the config files in the configs directory
within the current working directory. It names the config files based on
the following format:
a = assembly prefix <default = as>
i = assembly start index <default = 000>
d ... | [
"def",
"sweeper_output",
"(",
"self",
")",
":",
"# 1. check if configs directory exists, if not, make it",
"config_dir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"getcwd",
"(",
")",
",",
"\"configs\"",
")",
"if",
"not",
"os",
".",
"path",
".",
"e... | This method outputs all of the config files in the configs directory
within the current working directory. It names the config files based on
the following format:
a = assembly prefix <default = as>
i = assembly start index <default = 000>
d = date in format YYYYMMDD <default=to... | [
"This",
"method",
"outputs",
"all",
"of",
"the",
"config",
"files",
"in",
"the",
"configs",
"directory",
"within",
"the",
"current",
"working",
"directory",
".",
"It",
"names",
"the",
"config",
"files",
"based",
"on",
"the",
"following",
"format",
":"
] | train | https://github.com/conchoecia/gloTK/blob/58abee663fcfbbd09f4863c3ca3ae054e33184a8/gloTK/merparse.py#L153-L245 |
conchoecia/gloTK | gloTK/merparse.py | ConfigParse.save_yaml | def save_yaml(self, outFile):
"""saves the config parameters to a json file"""
with open(outFile,'w') as myfile:
print(yaml.dump(self.params), file=myfile) | python | def save_yaml(self, outFile):
"""saves the config parameters to a json file"""
with open(outFile,'w') as myfile:
print(yaml.dump(self.params), file=myfile) | [
"def",
"save_yaml",
"(",
"self",
",",
"outFile",
")",
":",
"with",
"open",
"(",
"outFile",
",",
"'w'",
")",
"as",
"myfile",
":",
"print",
"(",
"yaml",
".",
"dump",
"(",
"self",
".",
"params",
")",
",",
"file",
"=",
"myfile",
")"
] | saves the config parameters to a json file | [
"saves",
"the",
"config",
"parameters",
"to",
"a",
"json",
"file"
] | train | https://github.com/conchoecia/gloTK/blob/58abee663fcfbbd09f4863c3ca3ae054e33184a8/gloTK/merparse.py#L306-L309 |
conchoecia/gloTK | gloTK/merparse.py | ConfigParse.sym_reads_new_config | def sym_reads_new_config(self, newDir, sym=False, mv=False):
"""This moves the read files and renames the glob, outputs a new
ConfigParse object with updated values"""
newParams = copy.copy(self)
for i in range(0,len(self.params["lib_seq"])):
lib_seq = self.params["lib_seq"][... | python | def sym_reads_new_config(self, newDir, sym=False, mv=False):
"""This moves the read files and renames the glob, outputs a new
ConfigParse object with updated values"""
newParams = copy.copy(self)
for i in range(0,len(self.params["lib_seq"])):
lib_seq = self.params["lib_seq"][... | [
"def",
"sym_reads_new_config",
"(",
"self",
",",
"newDir",
",",
"sym",
"=",
"False",
",",
"mv",
"=",
"False",
")",
":",
"newParams",
"=",
"copy",
".",
"copy",
"(",
"self",
")",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"self",
".",
"p... | This moves the read files and renames the glob, outputs a new
ConfigParse object with updated values | [
"This",
"moves",
"the",
"read",
"files",
"and",
"renames",
"the",
"glob",
"outputs",
"a",
"new",
"ConfigParse",
"object",
"with",
"updated",
"values"
] | train | https://github.com/conchoecia/gloTK/blob/58abee663fcfbbd09f4863c3ca3ae054e33184a8/gloTK/merparse.py#L311-L337 |
conchoecia/gloTK | gloTK/merparse.py | ConfigParse.assign | def assign(self, dict_name, key, value):
"""This assigns an input string to either a float or int and saves it in
the config params as such"""
if key in self.to_int:
getattr(self, dict_name)[key] = int(value)
elif key in self.to_float:
getattr(self, dict_name)[key... | python | def assign(self, dict_name, key, value):
"""This assigns an input string to either a float or int and saves it in
the config params as such"""
if key in self.to_int:
getattr(self, dict_name)[key] = int(value)
elif key in self.to_float:
getattr(self, dict_name)[key... | [
"def",
"assign",
"(",
"self",
",",
"dict_name",
",",
"key",
",",
"value",
")",
":",
"if",
"key",
"in",
"self",
".",
"to_int",
":",
"getattr",
"(",
"self",
",",
"dict_name",
")",
"[",
"key",
"]",
"=",
"int",
"(",
"value",
")",
"elif",
"key",
"in",... | This assigns an input string to either a float or int and saves it in
the config params as such | [
"This",
"assigns",
"an",
"input",
"string",
"to",
"either",
"a",
"float",
"or",
"int",
"and",
"saves",
"it",
"in",
"the",
"config",
"params",
"as",
"such"
] | train | https://github.com/conchoecia/gloTK/blob/58abee663fcfbbd09f4863c3ca3ae054e33184a8/gloTK/merparse.py#L339-L350 |
operasoftware/twisted-apns | apns/gatewayclient.py | GatewayClientFactory.send | def send(self, notification):
"""Send prepared notification to the APN."""
logger.debug('Gateway send notification')
if self.client is None:
raise GatewayClientNotSetError()
yield self.client.send(notification) | python | def send(self, notification):
"""Send prepared notification to the APN."""
logger.debug('Gateway send notification')
if self.client is None:
raise GatewayClientNotSetError()
yield self.client.send(notification) | [
"def",
"send",
"(",
"self",
",",
"notification",
")",
":",
"logger",
".",
"debug",
"(",
"'Gateway send notification'",
")",
"if",
"self",
".",
"client",
"is",
"None",
":",
"raise",
"GatewayClientNotSetError",
"(",
")",
"yield",
"self",
".",
"client",
".",
... | Send prepared notification to the APN. | [
"Send",
"prepared",
"notification",
"to",
"the",
"APN",
"."
] | train | https://github.com/operasoftware/twisted-apns/blob/c7bd460100067e0c96c440ac0f5516485ac7313f/apns/gatewayclient.py#L113-L120 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.