repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens listlengths 20 707 | docstring stringlengths 3 17.3k | docstring_tokens listlengths 3 222 | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value | idx int64 0 252k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
Nekroze/partpy | setup.py | CleanUp.run | def run(self):
"""Run CleanUp."""
import fnmatch
import shutil
import glob
matches = []
matches.extend(glob.glob('./*.pyc'))
matches.extend(glob.glob('./*.pyd'))
matches.extend(glob.glob('./*.pyo'))
matches.extend(glob.glob('./*.so'))
dirs ... | python | def run(self):
"""Run CleanUp."""
import fnmatch
import shutil
import glob
matches = []
matches.extend(glob.glob('./*.pyc'))
matches.extend(glob.glob('./*.pyd'))
matches.extend(glob.glob('./*.pyo'))
matches.extend(glob.glob('./*.so'))
dirs ... | [
"def",
"run",
"(",
"self",
")",
":",
"import",
"fnmatch",
"import",
"shutil",
"import",
"glob",
"matches",
"=",
"[",
"]",
"matches",
".",
"extend",
"(",
"glob",
".",
"glob",
"(",
"'./*.pyc'",
")",
")",
"matches",
".",
"extend",
"(",
"glob",
".",
"glo... | Run CleanUp. | [
"Run",
"CleanUp",
"."
] | dbb7d2fb285464fc43d85bc31f5af46192d301f6 | https://github.com/Nekroze/partpy/blob/dbb7d2fb285464fc43d85bc31f5af46192d301f6/setup.py#L48-L81 | train | 58,800 |
Nekroze/partpy | setup.py | GitCommit.run | def run(self):
"""Run git add and commit with message if provided."""
if os.system('git add .'):
sys.exit(1)
if self.message is not None:
os.system('git commit -a -m "' + self.message + '"')
else:
os.system('git commit -a') | python | def run(self):
"""Run git add and commit with message if provided."""
if os.system('git add .'):
sys.exit(1)
if self.message is not None:
os.system('git commit -a -m "' + self.message + '"')
else:
os.system('git commit -a') | [
"def",
"run",
"(",
"self",
")",
":",
"if",
"os",
".",
"system",
"(",
"'git add .'",
")",
":",
"sys",
".",
"exit",
"(",
"1",
")",
"if",
"self",
".",
"message",
"is",
"not",
"None",
":",
"os",
".",
"system",
"(",
"'git commit -a -m \"'",
"+",
"self",... | Run git add and commit with message if provided. | [
"Run",
"git",
"add",
"and",
"commit",
"with",
"message",
"if",
"provided",
"."
] | dbb7d2fb285464fc43d85bc31f5af46192d301f6 | https://github.com/Nekroze/partpy/blob/dbb7d2fb285464fc43d85bc31f5af46192d301f6/setup.py#L156-L163 | train | 58,801 |
inveniosoftware-attic/invenio-documents | invenio_documents/api.py | Document.uri | def uri(self, value):
"""Set new uri value in record.
It will not change the location of the underlying file!
"""
jsonpointer.set_pointer(self.record, self.pointer, value) | python | def uri(self, value):
"""Set new uri value in record.
It will not change the location of the underlying file!
"""
jsonpointer.set_pointer(self.record, self.pointer, value) | [
"def",
"uri",
"(",
"self",
",",
"value",
")",
":",
"jsonpointer",
".",
"set_pointer",
"(",
"self",
".",
"record",
",",
"self",
".",
"pointer",
",",
"value",
")"
] | Set new uri value in record.
It will not change the location of the underlying file! | [
"Set",
"new",
"uri",
"value",
"in",
"record",
"."
] | cdfcd21ea5d9ad26f4405f418863fcc3df636176 | https://github.com/inveniosoftware-attic/invenio-documents/blob/cdfcd21ea5d9ad26f4405f418863fcc3df636176/invenio_documents/api.py#L48-L53 | train | 58,802 |
inveniosoftware-attic/invenio-documents | invenio_documents/api.py | Document.open | def open(self, mode='r', **kwargs):
"""Open file ``uri`` under the pointer."""
_fs, filename = opener.parse(self.uri)
return _fs.open(filename, mode=mode, **kwargs) | python | def open(self, mode='r', **kwargs):
"""Open file ``uri`` under the pointer."""
_fs, filename = opener.parse(self.uri)
return _fs.open(filename, mode=mode, **kwargs) | [
"def",
"open",
"(",
"self",
",",
"mode",
"=",
"'r'",
",",
"*",
"*",
"kwargs",
")",
":",
"_fs",
",",
"filename",
"=",
"opener",
".",
"parse",
"(",
"self",
".",
"uri",
")",
"return",
"_fs",
".",
"open",
"(",
"filename",
",",
"mode",
"=",
"mode",
... | Open file ``uri`` under the pointer. | [
"Open",
"file",
"uri",
"under",
"the",
"pointer",
"."
] | cdfcd21ea5d9ad26f4405f418863fcc3df636176 | https://github.com/inveniosoftware-attic/invenio-documents/blob/cdfcd21ea5d9ad26f4405f418863fcc3df636176/invenio_documents/api.py#L55-L58 | train | 58,803 |
inveniosoftware-attic/invenio-documents | invenio_documents/api.py | Document.move | def move(self, dst, **kwargs):
"""Move file to a new destination and update ``uri``."""
_fs, filename = opener.parse(self.uri)
_fs_dst, filename_dst = opener.parse(dst)
movefile(_fs, filename, _fs_dst, filename_dst, **kwargs)
self.uri = dst | python | def move(self, dst, **kwargs):
"""Move file to a new destination and update ``uri``."""
_fs, filename = opener.parse(self.uri)
_fs_dst, filename_dst = opener.parse(dst)
movefile(_fs, filename, _fs_dst, filename_dst, **kwargs)
self.uri = dst | [
"def",
"move",
"(",
"self",
",",
"dst",
",",
"*",
"*",
"kwargs",
")",
":",
"_fs",
",",
"filename",
"=",
"opener",
".",
"parse",
"(",
"self",
".",
"uri",
")",
"_fs_dst",
",",
"filename_dst",
"=",
"opener",
".",
"parse",
"(",
"dst",
")",
"movefile",
... | Move file to a new destination and update ``uri``. | [
"Move",
"file",
"to",
"a",
"new",
"destination",
"and",
"update",
"uri",
"."
] | cdfcd21ea5d9ad26f4405f418863fcc3df636176 | https://github.com/inveniosoftware-attic/invenio-documents/blob/cdfcd21ea5d9ad26f4405f418863fcc3df636176/invenio_documents/api.py#L60-L65 | train | 58,804 |
inveniosoftware-attic/invenio-documents | invenio_documents/api.py | Document.setcontents | def setcontents(self, source, **kwargs):
"""Create a new file from a string or file-like object."""
if isinstance(source, six.string_types):
_file = opener.open(source, 'rb')
else:
_file = source
# signals.document_before_content_set.send(self)
data = _f... | python | def setcontents(self, source, **kwargs):
"""Create a new file from a string or file-like object."""
if isinstance(source, six.string_types):
_file = opener.open(source, 'rb')
else:
_file = source
# signals.document_before_content_set.send(self)
data = _f... | [
"def",
"setcontents",
"(",
"self",
",",
"source",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"isinstance",
"(",
"source",
",",
"six",
".",
"string_types",
")",
":",
"_file",
"=",
"opener",
".",
"open",
"(",
"source",
",",
"'rb'",
")",
"else",
":",
"_... | Create a new file from a string or file-like object. | [
"Create",
"a",
"new",
"file",
"from",
"a",
"string",
"or",
"file",
"-",
"like",
"object",
"."
] | cdfcd21ea5d9ad26f4405f418863fcc3df636176 | https://github.com/inveniosoftware-attic/invenio-documents/blob/cdfcd21ea5d9ad26f4405f418863fcc3df636176/invenio_documents/api.py#L77-L94 | train | 58,805 |
inveniosoftware-attic/invenio-documents | invenio_documents/api.py | Document.remove | def remove(self, force=False):
"""Remove file reference from record.
If force is True it removes the file from filesystem
"""
if force:
_fs, filename = opener.parse(self.uri)
_fs.remove(filename)
self.uri = None | python | def remove(self, force=False):
"""Remove file reference from record.
If force is True it removes the file from filesystem
"""
if force:
_fs, filename = opener.parse(self.uri)
_fs.remove(filename)
self.uri = None | [
"def",
"remove",
"(",
"self",
",",
"force",
"=",
"False",
")",
":",
"if",
"force",
":",
"_fs",
",",
"filename",
"=",
"opener",
".",
"parse",
"(",
"self",
".",
"uri",
")",
"_fs",
".",
"remove",
"(",
"filename",
")",
"self",
".",
"uri",
"=",
"None"... | Remove file reference from record.
If force is True it removes the file from filesystem | [
"Remove",
"file",
"reference",
"from",
"record",
"."
] | cdfcd21ea5d9ad26f4405f418863fcc3df636176 | https://github.com/inveniosoftware-attic/invenio-documents/blob/cdfcd21ea5d9ad26f4405f418863fcc3df636176/invenio_documents/api.py#L96-L104 | train | 58,806 |
BlackEarth/bxml | bxml/xml.py | XML.tobytes | def tobytes(
self,
root=None,
encoding='UTF-8',
doctype=None,
canonicalized=True,
xml_declaration=True,
pretty_print=True,
with_comments=True,
):
"""return the content of the XML document as a byte string suitable for writing"""
... | python | def tobytes(
self,
root=None,
encoding='UTF-8',
doctype=None,
canonicalized=True,
xml_declaration=True,
pretty_print=True,
with_comments=True,
):
"""return the content of the XML document as a byte string suitable for writing"""
... | [
"def",
"tobytes",
"(",
"self",
",",
"root",
"=",
"None",
",",
"encoding",
"=",
"'UTF-8'",
",",
"doctype",
"=",
"None",
",",
"canonicalized",
"=",
"True",
",",
"xml_declaration",
"=",
"True",
",",
"pretty_print",
"=",
"True",
",",
"with_comments",
"=",
"T... | return the content of the XML document as a byte string suitable for writing | [
"return",
"the",
"content",
"of",
"the",
"XML",
"document",
"as",
"a",
"byte",
"string",
"suitable",
"for",
"writing"
] | 8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77 | https://github.com/BlackEarth/bxml/blob/8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77/bxml/xml.py#L176-L199 | train | 58,807 |
BlackEarth/bxml | bxml/xml.py | XML.tostring | def tostring(self, root=None, doctype=None, pretty_print=True):
"""return the content of the XML document as a unicode string"""
if root is None:
root = self.root
return etree.tounicode(
root, doctype=doctype or self.info.doctype, pretty_print=pretty_print
) | python | def tostring(self, root=None, doctype=None, pretty_print=True):
"""return the content of the XML document as a unicode string"""
if root is None:
root = self.root
return etree.tounicode(
root, doctype=doctype or self.info.doctype, pretty_print=pretty_print
) | [
"def",
"tostring",
"(",
"self",
",",
"root",
"=",
"None",
",",
"doctype",
"=",
"None",
",",
"pretty_print",
"=",
"True",
")",
":",
"if",
"root",
"is",
"None",
":",
"root",
"=",
"self",
".",
"root",
"return",
"etree",
".",
"tounicode",
"(",
"root",
... | return the content of the XML document as a unicode string | [
"return",
"the",
"content",
"of",
"the",
"XML",
"document",
"as",
"a",
"unicode",
"string"
] | 8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77 | https://github.com/BlackEarth/bxml/blob/8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77/bxml/xml.py#L204-L210 | train | 58,808 |
BlackEarth/bxml | bxml/xml.py | XML.digest | def digest(self, **args):
"""calculate a digest based on the hash of the XML content"""
return String(XML.canonicalized_string(self.root)).digest(**args) | python | def digest(self, **args):
"""calculate a digest based on the hash of the XML content"""
return String(XML.canonicalized_string(self.root)).digest(**args) | [
"def",
"digest",
"(",
"self",
",",
"*",
"*",
"args",
")",
":",
"return",
"String",
"(",
"XML",
".",
"canonicalized_string",
"(",
"self",
".",
"root",
")",
")",
".",
"digest",
"(",
"*",
"*",
"args",
")"
] | calculate a digest based on the hash of the XML content | [
"calculate",
"a",
"digest",
"based",
"on",
"the",
"hash",
"of",
"the",
"XML",
"content"
] | 8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77 | https://github.com/BlackEarth/bxml/blob/8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77/bxml/xml.py#L218-L220 | train | 58,809 |
BlackEarth/bxml | bxml/xml.py | XML.element | def element(self, tag_path, test=None, **attributes):
"""given a tag in xpath form and optional attributes, find the element in self.root or return a new one."""
xpath = tag_path
tests = ["@%s='%s'" % (k, attributes[k]) for k in attributes]
if test is not None:
tests.ins... | python | def element(self, tag_path, test=None, **attributes):
"""given a tag in xpath form and optional attributes, find the element in self.root or return a new one."""
xpath = tag_path
tests = ["@%s='%s'" % (k, attributes[k]) for k in attributes]
if test is not None:
tests.ins... | [
"def",
"element",
"(",
"self",
",",
"tag_path",
",",
"test",
"=",
"None",
",",
"*",
"*",
"attributes",
")",
":",
"xpath",
"=",
"tag_path",
"tests",
"=",
"[",
"\"@%s='%s'\"",
"%",
"(",
"k",
",",
"attributes",
"[",
"k",
"]",
")",
"for",
"k",
"in",
... | given a tag in xpath form and optional attributes, find the element in self.root or return a new one. | [
"given",
"a",
"tag",
"in",
"xpath",
"form",
"and",
"optional",
"attributes",
"find",
"the",
"element",
"in",
"self",
".",
"root",
"or",
"return",
"a",
"new",
"one",
"."
] | 8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77 | https://github.com/BlackEarth/bxml/blob/8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77/bxml/xml.py#L243-L259 | train | 58,810 |
BlackEarth/bxml | bxml/xml.py | XML.namespace | def namespace(self, elem=None):
"""return the URL, if any, for the doc root or elem, if given."""
if elem is None:
elem = self.root
return XML.tag_namespace(elem.tag) | python | def namespace(self, elem=None):
"""return the URL, if any, for the doc root or elem, if given."""
if elem is None:
elem = self.root
return XML.tag_namespace(elem.tag) | [
"def",
"namespace",
"(",
"self",
",",
"elem",
"=",
"None",
")",
":",
"if",
"elem",
"is",
"None",
":",
"elem",
"=",
"self",
".",
"root",
"return",
"XML",
".",
"tag_namespace",
"(",
"elem",
".",
"tag",
")"
] | return the URL, if any, for the doc root or elem, if given. | [
"return",
"the",
"URL",
"if",
"any",
"for",
"the",
"doc",
"root",
"or",
"elem",
"if",
"given",
"."
] | 8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77 | https://github.com/BlackEarth/bxml/blob/8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77/bxml/xml.py#L462-L466 | train | 58,811 |
BlackEarth/bxml | bxml/xml.py | XML.tag_namespace | def tag_namespace(cls, tag):
"""return the namespace for a given tag, or '' if no namespace given"""
md = re.match("^(?:\{([^\}]*)\})", tag)
if md is not None:
return md.group(1) | python | def tag_namespace(cls, tag):
"""return the namespace for a given tag, or '' if no namespace given"""
md = re.match("^(?:\{([^\}]*)\})", tag)
if md is not None:
return md.group(1) | [
"def",
"tag_namespace",
"(",
"cls",
",",
"tag",
")",
":",
"md",
"=",
"re",
".",
"match",
"(",
"\"^(?:\\{([^\\}]*)\\})\"",
",",
"tag",
")",
"if",
"md",
"is",
"not",
"None",
":",
"return",
"md",
".",
"group",
"(",
"1",
")"
] | return the namespace for a given tag, or '' if no namespace given | [
"return",
"the",
"namespace",
"for",
"a",
"given",
"tag",
"or",
"if",
"no",
"namespace",
"given"
] | 8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77 | https://github.com/BlackEarth/bxml/blob/8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77/bxml/xml.py#L469-L473 | train | 58,812 |
BlackEarth/bxml | bxml/xml.py | XML.tag_name | def tag_name(cls, tag):
"""return the name of the tag, with the namespace removed"""
while isinstance(tag, etree._Element):
tag = tag.tag
return tag.split('}')[-1] | python | def tag_name(cls, tag):
"""return the name of the tag, with the namespace removed"""
while isinstance(tag, etree._Element):
tag = tag.tag
return tag.split('}')[-1] | [
"def",
"tag_name",
"(",
"cls",
",",
"tag",
")",
":",
"while",
"isinstance",
"(",
"tag",
",",
"etree",
".",
"_Element",
")",
":",
"tag",
"=",
"tag",
".",
"tag",
"return",
"tag",
".",
"split",
"(",
"'}'",
")",
"[",
"-",
"1",
"]"
] | return the name of the tag, with the namespace removed | [
"return",
"the",
"name",
"of",
"the",
"tag",
"with",
"the",
"namespace",
"removed"
] | 8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77 | https://github.com/BlackEarth/bxml/blob/8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77/bxml/xml.py#L476-L480 | train | 58,813 |
BlackEarth/bxml | bxml/xml.py | XML.element_map | def element_map(
self,
tags=None,
xpath="//*",
exclude_attribs=[],
include_attribs=[],
attrib_vals=False,
hierarchy=False,
minimize=False,
):
"""return a dict of element tags, their attribute names, and optionally attribute values,
... | python | def element_map(
self,
tags=None,
xpath="//*",
exclude_attribs=[],
include_attribs=[],
attrib_vals=False,
hierarchy=False,
minimize=False,
):
"""return a dict of element tags, their attribute names, and optionally attribute values,
... | [
"def",
"element_map",
"(",
"self",
",",
"tags",
"=",
"None",
",",
"xpath",
"=",
"\"//*\"",
",",
"exclude_attribs",
"=",
"[",
"]",
",",
"include_attribs",
"=",
"[",
"]",
",",
"attrib_vals",
"=",
"False",
",",
"hierarchy",
"=",
"False",
",",
"minimize",
... | return a dict of element tags, their attribute names, and optionally attribute values,
in the XML document | [
"return",
"a",
"dict",
"of",
"element",
"tags",
"their",
"attribute",
"names",
"and",
"optionally",
"attribute",
"values",
"in",
"the",
"XML",
"document"
] | 8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77 | https://github.com/BlackEarth/bxml/blob/8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77/bxml/xml.py#L505-L552 | train | 58,814 |
BlackEarth/bxml | bxml/xml.py | XML.dict_key_tag | def dict_key_tag(Class, key, namespaces=None):
"""convert a dict key into an element or attribute name"""
namespaces = namespaces or Class.NS
ns = Class.tag_namespace(key)
tag = Class.tag_name(key)
if ns is None and ':' in key:
prefix, tag = key.split(':')
... | python | def dict_key_tag(Class, key, namespaces=None):
"""convert a dict key into an element or attribute name"""
namespaces = namespaces or Class.NS
ns = Class.tag_namespace(key)
tag = Class.tag_name(key)
if ns is None and ':' in key:
prefix, tag = key.split(':')
... | [
"def",
"dict_key_tag",
"(",
"Class",
",",
"key",
",",
"namespaces",
"=",
"None",
")",
":",
"namespaces",
"=",
"namespaces",
"or",
"Class",
".",
"NS",
"ns",
"=",
"Class",
".",
"tag_namespace",
"(",
"key",
")",
"tag",
"=",
"Class",
".",
"tag_name",
"(",
... | convert a dict key into an element or attribute name | [
"convert",
"a",
"dict",
"key",
"into",
"an",
"element",
"or",
"attribute",
"name"
] | 8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77 | https://github.com/BlackEarth/bxml/blob/8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77/bxml/xml.py#L616-L627 | train | 58,815 |
BlackEarth/bxml | bxml/xml.py | XML.replace_with_contents | def replace_with_contents(c, elem):
"removes an element and leaves its contents in its place. Namespaces supported."
parent = elem.getparent()
index = parent.index(elem)
children = elem.getchildren()
previous = elem.getprevious()
# text
if index == 0:
... | python | def replace_with_contents(c, elem):
"removes an element and leaves its contents in its place. Namespaces supported."
parent = elem.getparent()
index = parent.index(elem)
children = elem.getchildren()
previous = elem.getprevious()
# text
if index == 0:
... | [
"def",
"replace_with_contents",
"(",
"c",
",",
"elem",
")",
":",
"parent",
"=",
"elem",
".",
"getparent",
"(",
")",
"index",
"=",
"parent",
".",
"index",
"(",
"elem",
")",
"children",
"=",
"elem",
".",
"getchildren",
"(",
")",
"previous",
"=",
"elem",
... | removes an element and leaves its contents in its place. Namespaces supported. | [
"removes",
"an",
"element",
"and",
"leaves",
"its",
"contents",
"in",
"its",
"place",
".",
"Namespaces",
"supported",
"."
] | 8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77 | https://github.com/BlackEarth/bxml/blob/8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77/bxml/xml.py#L685-L709 | train | 58,816 |
BlackEarth/bxml | bxml/xml.py | XML.remove_range | def remove_range(cls, elem, end_elem, delete_end=True):
"""delete everything from elem to end_elem, including elem.
if delete_end==True, also including end_elem; otherwise, leave it."""
while elem is not None and elem != end_elem and end_elem not in elem.xpath("descendant::*"):
p... | python | def remove_range(cls, elem, end_elem, delete_end=True):
"""delete everything from elem to end_elem, including elem.
if delete_end==True, also including end_elem; otherwise, leave it."""
while elem is not None and elem != end_elem and end_elem not in elem.xpath("descendant::*"):
p... | [
"def",
"remove_range",
"(",
"cls",
",",
"elem",
",",
"end_elem",
",",
"delete_end",
"=",
"True",
")",
":",
"while",
"elem",
"is",
"not",
"None",
"and",
"elem",
"!=",
"end_elem",
"and",
"end_elem",
"not",
"in",
"elem",
".",
"xpath",
"(",
"\"descendant::*\... | delete everything from elem to end_elem, including elem.
if delete_end==True, also including end_elem; otherwise, leave it. | [
"delete",
"everything",
"from",
"elem",
"to",
"end_elem",
"including",
"elem",
".",
"if",
"delete_end",
"==",
"True",
"also",
"including",
"end_elem",
";",
"otherwise",
"leave",
"it",
"."
] | 8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77 | https://github.com/BlackEarth/bxml/blob/8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77/bxml/xml.py#L723-L748 | train | 58,817 |
BlackEarth/bxml | bxml/xml.py | XML.wrap_content | def wrap_content(cls, container, wrapper):
"wrap the content of container element with wrapper element"
wrapper.text = (container.text or '') + (wrapper.text or '')
container.text = ''
for ch in container:
wrapper.append(ch)
container.insert(0, wrapper)
... | python | def wrap_content(cls, container, wrapper):
"wrap the content of container element with wrapper element"
wrapper.text = (container.text or '') + (wrapper.text or '')
container.text = ''
for ch in container:
wrapper.append(ch)
container.insert(0, wrapper)
... | [
"def",
"wrap_content",
"(",
"cls",
",",
"container",
",",
"wrapper",
")",
":",
"wrapper",
".",
"text",
"=",
"(",
"container",
".",
"text",
"or",
"''",
")",
"+",
"(",
"wrapper",
".",
"text",
"or",
"''",
")",
"container",
".",
"text",
"=",
"''",
"for... | wrap the content of container element with wrapper element | [
"wrap",
"the",
"content",
"of",
"container",
"element",
"with",
"wrapper",
"element"
] | 8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77 | https://github.com/BlackEarth/bxml/blob/8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77/bxml/xml.py#L751-L758 | train | 58,818 |
BlackEarth/bxml | bxml/xml.py | XML.merge_contiguous | def merge_contiguous(C, node, xpath, namespaces=None):
"""Within a given node, merge elements that are next to each other
if they have the same tag and attributes.
"""
new_node = deepcopy(node)
elems = XML.xpath(new_node, xpath, namespaces=namespaces)
elems.reverse... | python | def merge_contiguous(C, node, xpath, namespaces=None):
"""Within a given node, merge elements that are next to each other
if they have the same tag and attributes.
"""
new_node = deepcopy(node)
elems = XML.xpath(new_node, xpath, namespaces=namespaces)
elems.reverse... | [
"def",
"merge_contiguous",
"(",
"C",
",",
"node",
",",
"xpath",
",",
"namespaces",
"=",
"None",
")",
":",
"new_node",
"=",
"deepcopy",
"(",
"node",
")",
"elems",
"=",
"XML",
".",
"xpath",
"(",
"new_node",
",",
"xpath",
",",
"namespaces",
"=",
"namespac... | Within a given node, merge elements that are next to each other
if they have the same tag and attributes. | [
"Within",
"a",
"given",
"node",
"merge",
"elements",
"that",
"are",
"next",
"to",
"each",
"other",
"if",
"they",
"have",
"the",
"same",
"tag",
"and",
"attributes",
"."
] | 8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77 | https://github.com/BlackEarth/bxml/blob/8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77/bxml/xml.py#L779-L808 | train | 58,819 |
BlackEarth/bxml | bxml/xml.py | XML.unnest | def unnest(c, elem, ignore_whitespace=False):
"""unnest the element from its parent within doc. MUTABLE CHANGES"""
parent = elem.getparent()
gparent = parent.getparent()
index = parent.index(elem)
# put everything up to elem into a new parent element right before the current... | python | def unnest(c, elem, ignore_whitespace=False):
"""unnest the element from its parent within doc. MUTABLE CHANGES"""
parent = elem.getparent()
gparent = parent.getparent()
index = parent.index(elem)
# put everything up to elem into a new parent element right before the current... | [
"def",
"unnest",
"(",
"c",
",",
"elem",
",",
"ignore_whitespace",
"=",
"False",
")",
":",
"parent",
"=",
"elem",
".",
"getparent",
"(",
")",
"gparent",
"=",
"parent",
".",
"getparent",
"(",
")",
"index",
"=",
"parent",
".",
"index",
"(",
"elem",
")",... | unnest the element from its parent within doc. MUTABLE CHANGES | [
"unnest",
"the",
"element",
"from",
"its",
"parent",
"within",
"doc",
".",
"MUTABLE",
"CHANGES"
] | 8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77 | https://github.com/BlackEarth/bxml/blob/8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77/bxml/xml.py#L813-L833 | train | 58,820 |
BlackEarth/bxml | bxml/xml.py | XML.interior_nesting | def interior_nesting(cls, elem1, xpath, namespaces=None):
"""for elem1 containing elements at xpath, embed elem1 inside each of those elements,
and then remove the original elem1"""
for elem2 in elem1.xpath(xpath, namespaces=namespaces):
child_elem1 = etree.Element(elem1.tag)
... | python | def interior_nesting(cls, elem1, xpath, namespaces=None):
"""for elem1 containing elements at xpath, embed elem1 inside each of those elements,
and then remove the original elem1"""
for elem2 in elem1.xpath(xpath, namespaces=namespaces):
child_elem1 = etree.Element(elem1.tag)
... | [
"def",
"interior_nesting",
"(",
"cls",
",",
"elem1",
",",
"xpath",
",",
"namespaces",
"=",
"None",
")",
":",
"for",
"elem2",
"in",
"elem1",
".",
"xpath",
"(",
"xpath",
",",
"namespaces",
"=",
"namespaces",
")",
":",
"child_elem1",
"=",
"etree",
".",
"E... | for elem1 containing elements at xpath, embed elem1 inside each of those elements,
and then remove the original elem1 | [
"for",
"elem1",
"containing",
"elements",
"at",
"xpath",
"embed",
"elem1",
"inside",
"each",
"of",
"those",
"elements",
"and",
"then",
"remove",
"the",
"original",
"elem1"
] | 8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77 | https://github.com/BlackEarth/bxml/blob/8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77/bxml/xml.py#L836-L847 | train | 58,821 |
BlackEarth/bxml | bxml/xml.py | XML.fragment_nesting | def fragment_nesting(cls, elem1, tag2, namespaces=None):
"""for elem1 containing elements with tag2,
fragment elem1 into elems that are adjacent to and nested within tag2"""
elems2 = elem1.xpath("child::%s" % tag2, namespaces=namespaces)
while len(elems2) > 0:
elem2 = e... | python | def fragment_nesting(cls, elem1, tag2, namespaces=None):
"""for elem1 containing elements with tag2,
fragment elem1 into elems that are adjacent to and nested within tag2"""
elems2 = elem1.xpath("child::%s" % tag2, namespaces=namespaces)
while len(elems2) > 0:
elem2 = e... | [
"def",
"fragment_nesting",
"(",
"cls",
",",
"elem1",
",",
"tag2",
",",
"namespaces",
"=",
"None",
")",
":",
"elems2",
"=",
"elem1",
".",
"xpath",
"(",
"\"child::%s\"",
"%",
"tag2",
",",
"namespaces",
"=",
"namespaces",
")",
"while",
"len",
"(",
"elems2",... | for elem1 containing elements with tag2,
fragment elem1 into elems that are adjacent to and nested within tag2 | [
"for",
"elem1",
"containing",
"elements",
"with",
"tag2",
"fragment",
"elem1",
"into",
"elems",
"that",
"are",
"adjacent",
"to",
"and",
"nested",
"within",
"tag2"
] | 8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77 | https://github.com/BlackEarth/bxml/blob/8fbea5dad7fadc7b854ddbeff6ecfb55aaceeb77/bxml/xml.py#L850-L890 | train | 58,822 |
shawnsilva/steamwebapi | steamwebapi/profiles.py | User.communityvisibilitystate | def communityvisibilitystate(self):
"""Return the Visibility State of the Users Profile"""
if self._communityvisibilitystate == None:
return None
elif self._communityvisibilitystate in self.VisibilityState:
return self.VisibilityState[self._communityvisibilitystate]
... | python | def communityvisibilitystate(self):
"""Return the Visibility State of the Users Profile"""
if self._communityvisibilitystate == None:
return None
elif self._communityvisibilitystate in self.VisibilityState:
return self.VisibilityState[self._communityvisibilitystate]
... | [
"def",
"communityvisibilitystate",
"(",
"self",
")",
":",
"if",
"self",
".",
"_communityvisibilitystate",
"==",
"None",
":",
"return",
"None",
"elif",
"self",
".",
"_communityvisibilitystate",
"in",
"self",
".",
"VisibilityState",
":",
"return",
"self",
".",
"Vi... | Return the Visibility State of the Users Profile | [
"Return",
"the",
"Visibility",
"State",
"of",
"the",
"Users",
"Profile"
] | dc16538ebe985cc7ea170f660169ebc2366efbf2 | https://github.com/shawnsilva/steamwebapi/blob/dc16538ebe985cc7ea170f660169ebc2366efbf2/steamwebapi/profiles.py#L61-L69 | train | 58,823 |
shawnsilva/steamwebapi | steamwebapi/profiles.py | User.personastate | def personastate(self):
"""Return the Persona State of the Users Profile"""
if self._personastate == None:
return None
elif self._personastate in self.PersonaState:
return self.PersonaState[self._personastate]
else:
#Invalid State
return No... | python | def personastate(self):
"""Return the Persona State of the Users Profile"""
if self._personastate == None:
return None
elif self._personastate in self.PersonaState:
return self.PersonaState[self._personastate]
else:
#Invalid State
return No... | [
"def",
"personastate",
"(",
"self",
")",
":",
"if",
"self",
".",
"_personastate",
"==",
"None",
":",
"return",
"None",
"elif",
"self",
".",
"_personastate",
"in",
"self",
".",
"PersonaState",
":",
"return",
"self",
".",
"PersonaState",
"[",
"self",
".",
... | Return the Persona State of the Users Profile | [
"Return",
"the",
"Persona",
"State",
"of",
"the",
"Users",
"Profile"
] | dc16538ebe985cc7ea170f660169ebc2366efbf2 | https://github.com/shawnsilva/steamwebapi/blob/dc16538ebe985cc7ea170f660169ebc2366efbf2/steamwebapi/profiles.py#L76-L84 | train | 58,824 |
ponty/confduino | confduino/mculist.py | mcus | def mcus():
"""MCU list."""
ls = []
for h in hwpack_names():
for b in board_names(h):
ls += [mcu(b, h)]
ls = sorted(list(set(ls)))
return ls | python | def mcus():
"""MCU list."""
ls = []
for h in hwpack_names():
for b in board_names(h):
ls += [mcu(b, h)]
ls = sorted(list(set(ls)))
return ls | [
"def",
"mcus",
"(",
")",
":",
"ls",
"=",
"[",
"]",
"for",
"h",
"in",
"hwpack_names",
"(",
")",
":",
"for",
"b",
"in",
"board_names",
"(",
"h",
")",
":",
"ls",
"+=",
"[",
"mcu",
"(",
"b",
",",
"h",
")",
"]",
"ls",
"=",
"sorted",
"(",
"list",... | MCU list. | [
"MCU",
"list",
"."
] | f4c261e5e84997f145a8bdd001f471db74c9054b | https://github.com/ponty/confduino/blob/f4c261e5e84997f145a8bdd001f471db74c9054b/confduino/mculist.py#L10-L17 | train | 58,825 |
foobarbecue/afterflight | afterflight/af_utils.py | logpath2dt | def logpath2dt(filepath):
"""
given a dataflashlog in the format produced by Mission Planner,
return a datetime which says when the file was downloaded from the APM
"""
return datetime.datetime.strptime(re.match(r'.*/(.*) .*$',filepath).groups()[0],'%Y-%m-%d %H-%M') | python | def logpath2dt(filepath):
"""
given a dataflashlog in the format produced by Mission Planner,
return a datetime which says when the file was downloaded from the APM
"""
return datetime.datetime.strptime(re.match(r'.*/(.*) .*$',filepath).groups()[0],'%Y-%m-%d %H-%M') | [
"def",
"logpath2dt",
"(",
"filepath",
")",
":",
"return",
"datetime",
".",
"datetime",
".",
"strptime",
"(",
"re",
".",
"match",
"(",
"r'.*/(.*) .*$'",
",",
"filepath",
")",
".",
"groups",
"(",
")",
"[",
"0",
"]",
",",
"'%Y-%m-%d %H-%M'",
")"
] | given a dataflashlog in the format produced by Mission Planner,
return a datetime which says when the file was downloaded from the APM | [
"given",
"a",
"dataflashlog",
"in",
"the",
"format",
"produced",
"by",
"Mission",
"Planner",
"return",
"a",
"datetime",
"which",
"says",
"when",
"the",
"file",
"was",
"downloaded",
"from",
"the",
"APM"
] | 7085f719593f88999dce93f35caec5f15d2991b6 | https://github.com/foobarbecue/afterflight/blob/7085f719593f88999dce93f35caec5f15d2991b6/afterflight/af_utils.py#L24-L29 | train | 58,826 |
andy29485/embypy | embypy/objects/object.py | EmbyObject.url | def url(self):
'''url of the item
Notes
-----
if remote-adderes was given, then that is used as the base
'''
path = '/web/itemdetails.html?id={}'.format(self.id)
return self.connector.get_url(path, attach_api_key=False) | python | def url(self):
'''url of the item
Notes
-----
if remote-adderes was given, then that is used as the base
'''
path = '/web/itemdetails.html?id={}'.format(self.id)
return self.connector.get_url(path, attach_api_key=False) | [
"def",
"url",
"(",
"self",
")",
":",
"path",
"=",
"'/web/itemdetails.html?id={}'",
".",
"format",
"(",
"self",
".",
"id",
")",
"return",
"self",
".",
"connector",
".",
"get_url",
"(",
"path",
",",
"attach_api_key",
"=",
"False",
")"
] | url of the item
Notes
-----
if remote-adderes was given, then that is used as the base | [
"url",
"of",
"the",
"item"
] | cde658d380965caaf4789d4d182d045b0346797b | https://github.com/andy29485/embypy/blob/cde658d380965caaf4789d4d182d045b0346797b/embypy/objects/object.py#L233-L241 | train | 58,827 |
andy29485/embypy | embypy/objects/object.py | EmbyObject.update | async def update(self, fields=''):
'''reload object info from emby
|coro|
Parameters
----------
fields : str
additional fields to request when updating
See Also
--------
refresh : same thing
send :
post :
'''
path = 'Users/{{UserId}}/Items/{}'.format(self.i... | python | async def update(self, fields=''):
'''reload object info from emby
|coro|
Parameters
----------
fields : str
additional fields to request when updating
See Also
--------
refresh : same thing
send :
post :
'''
path = 'Users/{{UserId}}/Items/{}'.format(self.i... | [
"async",
"def",
"update",
"(",
"self",
",",
"fields",
"=",
"''",
")",
":",
"path",
"=",
"'Users/{{UserId}}/Items/{}'",
".",
"format",
"(",
"self",
".",
"id",
")",
"info",
"=",
"await",
"self",
".",
"connector",
".",
"getJson",
"(",
"path",
",",
"remote... | reload object info from emby
|coro|
Parameters
----------
fields : str
additional fields to request when updating
See Also
--------
refresh : same thing
send :
post : | [
"reload",
"object",
"info",
"from",
"emby"
] | cde658d380965caaf4789d4d182d045b0346797b | https://github.com/andy29485/embypy/blob/cde658d380965caaf4789d4d182d045b0346797b/embypy/objects/object.py#L249-L272 | train | 58,828 |
andy29485/embypy | embypy/objects/object.py | EmbyObject.send | async def send(self):
'''send data that was changed to emby
|coro|
This should be used after using any of the setter. Not necessarily
immediately, but soon after.
See Also
--------
post: same thing
update :
refresh :
Returns
-------
aiohttp.ClientResponse or N... | python | async def send(self):
'''send data that was changed to emby
|coro|
This should be used after using any of the setter. Not necessarily
immediately, but soon after.
See Also
--------
post: same thing
update :
refresh :
Returns
-------
aiohttp.ClientResponse or N... | [
"async",
"def",
"send",
"(",
"self",
")",
":",
"# Why does the whole dict need to be sent?",
"# because emby is dumb, and will break if I don't",
"path",
"=",
"'Items/{}'",
".",
"format",
"(",
"self",
".",
"id",
")",
"resp",
"=",
"await",
"self",
".",
"connector",
... | send data that was changed to emby
|coro|
This should be used after using any of the setter. Not necessarily
immediately, but soon after.
See Also
--------
post: same thing
update :
refresh :
Returns
-------
aiohttp.ClientResponse or None if nothing needed updatin... | [
"send",
"data",
"that",
"was",
"changed",
"to",
"emby"
] | cde658d380965caaf4789d4d182d045b0346797b | https://github.com/andy29485/embypy/blob/cde658d380965caaf4789d4d182d045b0346797b/embypy/objects/object.py#L291-L316 | train | 58,829 |
ponty/confduino | confduino/libremove.py | remove_lib | def remove_lib(lib_name):
"""remove library.
:param lib_name: library name (e.g. 'PS2Keyboard')
:rtype: None
"""
targ_dlib = libraries_dir() / lib_name
log.debug('remove %s', targ_dlib)
targ_dlib.rmtree() | python | def remove_lib(lib_name):
"""remove library.
:param lib_name: library name (e.g. 'PS2Keyboard')
:rtype: None
"""
targ_dlib = libraries_dir() / lib_name
log.debug('remove %s', targ_dlib)
targ_dlib.rmtree() | [
"def",
"remove_lib",
"(",
"lib_name",
")",
":",
"targ_dlib",
"=",
"libraries_dir",
"(",
")",
"/",
"lib_name",
"log",
".",
"debug",
"(",
"'remove %s'",
",",
"targ_dlib",
")",
"targ_dlib",
".",
"rmtree",
"(",
")"
] | remove library.
:param lib_name: library name (e.g. 'PS2Keyboard')
:rtype: None | [
"remove",
"library",
"."
] | f4c261e5e84997f145a8bdd001f471db74c9054b | https://github.com/ponty/confduino/blob/f4c261e5e84997f145a8bdd001f471db74c9054b/confduino/libremove.py#L9-L18 | train | 58,830 |
Caramel/treacle | treacle/treacle.py | Office._read_holidays | def _read_holidays(self, filename):
"""
Read holidays from an iCalendar-format file.
"""
cal = Calendar.from_ical(open(filename, 'rb').read())
holidays = []
for component in cal.walk('VEVENT'):
start = component.decoded('DTSTART')
try:
end = component.decoded('DTEND')
except KeyError:
# RF... | python | def _read_holidays(self, filename):
"""
Read holidays from an iCalendar-format file.
"""
cal = Calendar.from_ical(open(filename, 'rb').read())
holidays = []
for component in cal.walk('VEVENT'):
start = component.decoded('DTSTART')
try:
end = component.decoded('DTEND')
except KeyError:
# RF... | [
"def",
"_read_holidays",
"(",
"self",
",",
"filename",
")",
":",
"cal",
"=",
"Calendar",
".",
"from_ical",
"(",
"open",
"(",
"filename",
",",
"'rb'",
")",
".",
"read",
"(",
")",
")",
"holidays",
"=",
"[",
"]",
"for",
"component",
"in",
"cal",
".",
... | Read holidays from an iCalendar-format file. | [
"Read",
"holidays",
"from",
"an",
"iCalendar",
"-",
"format",
"file",
"."
] | 70f85a505c0f345659850aec1715c46c687d0e48 | https://github.com/Caramel/treacle/blob/70f85a505c0f345659850aec1715c46c687d0e48/treacle/treacle.py#L101-L137 | train | 58,831 |
Caramel/treacle | treacle/treacle.py | Treacle.in_hours | def in_hours(self, office=None, when=None):
"""
Finds if it is business hours in the given office.
:param office: Office ID to look up, or None to check if any office is in business hours.
:type office: str or None
:param datetime.datetime when: When to check the office is open, or None for now.
:returns... | python | def in_hours(self, office=None, when=None):
"""
Finds if it is business hours in the given office.
:param office: Office ID to look up, or None to check if any office is in business hours.
:type office: str or None
:param datetime.datetime when: When to check the office is open, or None for now.
:returns... | [
"def",
"in_hours",
"(",
"self",
",",
"office",
"=",
"None",
",",
"when",
"=",
"None",
")",
":",
"if",
"when",
"==",
"None",
":",
"when",
"=",
"datetime",
".",
"now",
"(",
"tz",
"=",
"utc",
")",
"if",
"office",
"==",
"None",
":",
"for",
"office",
... | Finds if it is business hours in the given office.
:param office: Office ID to look up, or None to check if any office is in business hours.
:type office: str or None
:param datetime.datetime when: When to check the office is open, or None for now.
:returns: True if it is business hours, False otherwise.
:... | [
"Finds",
"if",
"it",
"is",
"business",
"hours",
"in",
"the",
"given",
"office",
"."
] | 70f85a505c0f345659850aec1715c46c687d0e48 | https://github.com/Caramel/treacle/blob/70f85a505c0f345659850aec1715c46c687d0e48/treacle/treacle.py#L202-L230 | train | 58,832 |
crosenth/csvpandas | csvpandas/__init__.py | setup_logging | def setup_logging(namespace):
"""
setup global logging
"""
loglevel = {
0: logging.ERROR,
1: logging.WARNING,
2: logging.INFO,
3: logging.DEBUG,
}.get(namespace.verbosity, logging.DEBUG)
if namespace.verbosity > 1:
logformat = '%(levelname)s csvpandas %(... | python | def setup_logging(namespace):
"""
setup global logging
"""
loglevel = {
0: logging.ERROR,
1: logging.WARNING,
2: logging.INFO,
3: logging.DEBUG,
}.get(namespace.verbosity, logging.DEBUG)
if namespace.verbosity > 1:
logformat = '%(levelname)s csvpandas %(... | [
"def",
"setup_logging",
"(",
"namespace",
")",
":",
"loglevel",
"=",
"{",
"0",
":",
"logging",
".",
"ERROR",
",",
"1",
":",
"logging",
".",
"WARNING",
",",
"2",
":",
"logging",
".",
"INFO",
",",
"3",
":",
"logging",
".",
"DEBUG",
",",
"}",
".",
"... | setup global logging | [
"setup",
"global",
"logging"
] | 4c2027192761150a9a6383595d7324df37f36429 | https://github.com/crosenth/csvpandas/blob/4c2027192761150a9a6383595d7324df37f36429/csvpandas/__init__.py#L73-L90 | train | 58,833 |
crosenth/csvpandas | csvpandas/__init__.py | parse_subcommands | def parse_subcommands(parser, subcommands, argv):
"""
Setup all sub-commands
"""
subparsers = parser.add_subparsers(dest='subparser_name')
# add help sub-command
parser_help = subparsers.add_parser(
'help', help='Detailed help for actions using `help <action>`')
parser_help.add_arg... | python | def parse_subcommands(parser, subcommands, argv):
"""
Setup all sub-commands
"""
subparsers = parser.add_subparsers(dest='subparser_name')
# add help sub-command
parser_help = subparsers.add_parser(
'help', help='Detailed help for actions using `help <action>`')
parser_help.add_arg... | [
"def",
"parse_subcommands",
"(",
"parser",
",",
"subcommands",
",",
"argv",
")",
":",
"subparsers",
"=",
"parser",
".",
"add_subparsers",
"(",
"dest",
"=",
"'subparser_name'",
")",
"# add help sub-command",
"parser_help",
"=",
"subparsers",
".",
"add_parser",
"(",... | Setup all sub-commands | [
"Setup",
"all",
"sub",
"-",
"commands"
] | 4c2027192761150a9a6383595d7324df37f36429 | https://github.com/crosenth/csvpandas/blob/4c2027192761150a9a6383595d7324df37f36429/csvpandas/__init__.py#L127-L177 | train | 58,834 |
crosenth/csvpandas | csvpandas/utils.py | opener | def opener(mode='r'):
"""Factory for creating file objects
Keyword Arguments:
- mode -- A string indicating how the file is to be opened. Accepts the
same values as the builtin open() function.
- bufsize -- The file's desired buffer size. Accepts the same values as
the b... | python | def opener(mode='r'):
"""Factory for creating file objects
Keyword Arguments:
- mode -- A string indicating how the file is to be opened. Accepts the
same values as the builtin open() function.
- bufsize -- The file's desired buffer size. Accepts the same values as
the b... | [
"def",
"opener",
"(",
"mode",
"=",
"'r'",
")",
":",
"def",
"open_file",
"(",
"f",
")",
":",
"if",
"f",
"is",
"sys",
".",
"stdout",
"or",
"f",
"is",
"sys",
".",
"stdin",
":",
"return",
"f",
"elif",
"f",
"==",
"'-'",
":",
"return",
"sys",
".",
... | Factory for creating file objects
Keyword Arguments:
- mode -- A string indicating how the file is to be opened. Accepts the
same values as the builtin open() function.
- bufsize -- The file's desired buffer size. Accepts the same values as
the builtin open() function. | [
"Factory",
"for",
"creating",
"file",
"objects"
] | 4c2027192761150a9a6383595d7324df37f36429 | https://github.com/crosenth/csvpandas/blob/4c2027192761150a9a6383595d7324df37f36429/csvpandas/utils.py#L21-L43 | train | 58,835 |
rackerlabs/python-lunrclient | lunrclient/lunr_shell.py | Account.get | def get(self, id, no_summary=False):
""" List details for a specific tenant id """
resp = self.client.accounts.get(id)
if no_summary:
return self.display(resp)
results = []
# Get a list of all volumes for this tenant id
client = LunrClient(self.get_admin(), d... | python | def get(self, id, no_summary=False):
""" List details for a specific tenant id """
resp = self.client.accounts.get(id)
if no_summary:
return self.display(resp)
results = []
# Get a list of all volumes for this tenant id
client = LunrClient(self.get_admin(), d... | [
"def",
"get",
"(",
"self",
",",
"id",
",",
"no_summary",
"=",
"False",
")",
":",
"resp",
"=",
"self",
".",
"client",
".",
"accounts",
".",
"get",
"(",
"id",
")",
"if",
"no_summary",
":",
"return",
"self",
".",
"display",
"(",
"resp",
")",
"results"... | List details for a specific tenant id | [
"List",
"details",
"for",
"a",
"specific",
"tenant",
"id"
] | f26a450a422600f492480bfa42cbee50a5c7016f | https://github.com/rackerlabs/python-lunrclient/blob/f26a450a422600f492480bfa42cbee50a5c7016f/lunrclient/lunr_shell.py#L298-L321 | train | 58,836 |
rackerlabs/python-lunrclient | lunrclient/lunr_shell.py | Account.create | def create(self, id):
""" Create a new tenant id """
resp = self.client.accounts.create(id=id)
self.display(resp) | python | def create(self, id):
""" Create a new tenant id """
resp = self.client.accounts.create(id=id)
self.display(resp) | [
"def",
"create",
"(",
"self",
",",
"id",
")",
":",
"resp",
"=",
"self",
".",
"client",
".",
"accounts",
".",
"create",
"(",
"id",
"=",
"id",
")",
"self",
".",
"display",
"(",
"resp",
")"
] | Create a new tenant id | [
"Create",
"a",
"new",
"tenant",
"id"
] | f26a450a422600f492480bfa42cbee50a5c7016f | https://github.com/rackerlabs/python-lunrclient/blob/f26a450a422600f492480bfa42cbee50a5c7016f/lunrclient/lunr_shell.py#L324-L327 | train | 58,837 |
rackerlabs/python-lunrclient | lunrclient/lunr_shell.py | Account.delete | def delete(self, id):
""" Delete an tenant id """
resp = self.client.accounts.delete(id)
self.display(resp) | python | def delete(self, id):
""" Delete an tenant id """
resp = self.client.accounts.delete(id)
self.display(resp) | [
"def",
"delete",
"(",
"self",
",",
"id",
")",
":",
"resp",
"=",
"self",
".",
"client",
".",
"accounts",
".",
"delete",
"(",
"id",
")",
"self",
".",
"display",
"(",
"resp",
")"
] | Delete an tenant id | [
"Delete",
"an",
"tenant",
"id"
] | f26a450a422600f492480bfa42cbee50a5c7016f | https://github.com/rackerlabs/python-lunrclient/blob/f26a450a422600f492480bfa42cbee50a5c7016f/lunrclient/lunr_shell.py#L330-L333 | train | 58,838 |
bimbar/pykwb | pykwb/kwb.py | main | def main():
"""Main method for debug purposes."""
parser = argparse.ArgumentParser()
group_tcp = parser.add_argument_group('TCP')
group_tcp.add_argument('--tcp', dest='mode', action='store_const', const=PROP_MODE_TCP, help="Set tcp mode")
group_tcp.add_argument('--host', dest='hostname', help="Speci... | python | def main():
"""Main method for debug purposes."""
parser = argparse.ArgumentParser()
group_tcp = parser.add_argument_group('TCP')
group_tcp.add_argument('--tcp', dest='mode', action='store_const', const=PROP_MODE_TCP, help="Set tcp mode")
group_tcp.add_argument('--host', dest='hostname', help="Speci... | [
"def",
"main",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
")",
"group_tcp",
"=",
"parser",
".",
"add_argument_group",
"(",
"'TCP'",
")",
"group_tcp",
".",
"add_argument",
"(",
"'--tcp'",
",",
"dest",
"=",
"'mode'",
",",
"action",... | Main method for debug purposes. | [
"Main",
"method",
"for",
"debug",
"purposes",
"."
] | 3f607c064cc53b8310d22d42506ce817a5b735fe | https://github.com/bimbar/pykwb/blob/3f607c064cc53b8310d22d42506ce817a5b735fe/pykwb/kwb.py#L427-L446 | train | 58,839 |
bimbar/pykwb | pykwb/kwb.py | KWBEasyfire._open_connection | def _open_connection(self):
"""Open a connection to the easyfire unit."""
if (self._mode == PROP_MODE_SERIAL):
self._serial = serial.Serial(self._serial_device, self._serial_speed)
elif (self._mode == PROP_MODE_TCP):
self._socket = socket.socket(socket.AF_INET, socket.SOC... | python | def _open_connection(self):
"""Open a connection to the easyfire unit."""
if (self._mode == PROP_MODE_SERIAL):
self._serial = serial.Serial(self._serial_device, self._serial_speed)
elif (self._mode == PROP_MODE_TCP):
self._socket = socket.socket(socket.AF_INET, socket.SOC... | [
"def",
"_open_connection",
"(",
"self",
")",
":",
"if",
"(",
"self",
".",
"_mode",
"==",
"PROP_MODE_SERIAL",
")",
":",
"self",
".",
"_serial",
"=",
"serial",
".",
"Serial",
"(",
"self",
".",
"_serial_device",
",",
"self",
".",
"_serial_speed",
")",
"elif... | Open a connection to the easyfire unit. | [
"Open",
"a",
"connection",
"to",
"the",
"easyfire",
"unit",
"."
] | 3f607c064cc53b8310d22d42506ce817a5b735fe | https://github.com/bimbar/pykwb/blob/3f607c064cc53b8310d22d42506ce817a5b735fe/pykwb/kwb.py#L187-L195 | train | 58,840 |
bimbar/pykwb | pykwb/kwb.py | KWBEasyfire._close_connection | def _close_connection(self):
"""Close the connection to the easyfire unit."""
if (self._mode == PROP_MODE_SERIAL):
self._serial.close()
elif (self._mode == PROP_MODE_TCP):
self._socket.close()
elif (self._mode == PROP_MODE_FILE):
self._file.close() | python | def _close_connection(self):
"""Close the connection to the easyfire unit."""
if (self._mode == PROP_MODE_SERIAL):
self._serial.close()
elif (self._mode == PROP_MODE_TCP):
self._socket.close()
elif (self._mode == PROP_MODE_FILE):
self._file.close() | [
"def",
"_close_connection",
"(",
"self",
")",
":",
"if",
"(",
"self",
".",
"_mode",
"==",
"PROP_MODE_SERIAL",
")",
":",
"self",
".",
"_serial",
".",
"close",
"(",
")",
"elif",
"(",
"self",
".",
"_mode",
"==",
"PROP_MODE_TCP",
")",
":",
"self",
".",
"... | Close the connection to the easyfire unit. | [
"Close",
"the",
"connection",
"to",
"the",
"easyfire",
"unit",
"."
] | 3f607c064cc53b8310d22d42506ce817a5b735fe | https://github.com/bimbar/pykwb/blob/3f607c064cc53b8310d22d42506ce817a5b735fe/pykwb/kwb.py#L197-L204 | train | 58,841 |
bimbar/pykwb | pykwb/kwb.py | KWBEasyfire._add_to_checksum | def _add_to_checksum(self, checksum, value):
"""Add a byte to the checksum."""
checksum = self._byte_rot_left(checksum, 1)
checksum = checksum + value
if (checksum > 255):
checksum = checksum - 255
self._debug(PROP_LOGLEVEL_TRACE, "C: " + str(checksum) + " V: " + str(... | python | def _add_to_checksum(self, checksum, value):
"""Add a byte to the checksum."""
checksum = self._byte_rot_left(checksum, 1)
checksum = checksum + value
if (checksum > 255):
checksum = checksum - 255
self._debug(PROP_LOGLEVEL_TRACE, "C: " + str(checksum) + " V: " + str(... | [
"def",
"_add_to_checksum",
"(",
"self",
",",
"checksum",
",",
"value",
")",
":",
"checksum",
"=",
"self",
".",
"_byte_rot_left",
"(",
"checksum",
",",
"1",
")",
"checksum",
"=",
"checksum",
"+",
"value",
"if",
"(",
"checksum",
">",
"255",
")",
":",
"ch... | Add a byte to the checksum. | [
"Add",
"a",
"byte",
"to",
"the",
"checksum",
"."
] | 3f607c064cc53b8310d22d42506ce817a5b735fe | https://github.com/bimbar/pykwb/blob/3f607c064cc53b8310d22d42506ce817a5b735fe/pykwb/kwb.py#L211-L218 | train | 58,842 |
bimbar/pykwb | pykwb/kwb.py | KWBEasyfire._read_byte | def _read_byte(self):
"""Read a byte from input."""
to_return = ""
if (self._mode == PROP_MODE_SERIAL):
to_return = self._serial.read(1)
elif (self._mode == PROP_MODE_TCP):
to_return = self._socket.recv(1)
elif (self._mode == PROP_MODE_FILE):
... | python | def _read_byte(self):
"""Read a byte from input."""
to_return = ""
if (self._mode == PROP_MODE_SERIAL):
to_return = self._serial.read(1)
elif (self._mode == PROP_MODE_TCP):
to_return = self._socket.recv(1)
elif (self._mode == PROP_MODE_FILE):
... | [
"def",
"_read_byte",
"(",
"self",
")",
":",
"to_return",
"=",
"\"\"",
"if",
"(",
"self",
".",
"_mode",
"==",
"PROP_MODE_SERIAL",
")",
":",
"to_return",
"=",
"self",
".",
"_serial",
".",
"read",
"(",
"1",
")",
"elif",
"(",
"self",
".",
"_mode",
"==",
... | Read a byte from input. | [
"Read",
"a",
"byte",
"from",
"input",
"."
] | 3f607c064cc53b8310d22d42506ce817a5b735fe | https://github.com/bimbar/pykwb/blob/3f607c064cc53b8310d22d42506ce817a5b735fe/pykwb/kwb.py#L220-L238 | train | 58,843 |
bimbar/pykwb | pykwb/kwb.py | KWBEasyfire._decode_temp | def _decode_temp(byte_1, byte_2):
"""Decode a signed short temperature as two bytes to a single number."""
temp = (byte_1 << 8) + byte_2
if (temp > 32767):
temp = temp - 65536
temp = temp / 10
return temp | python | def _decode_temp(byte_1, byte_2):
"""Decode a signed short temperature as two bytes to a single number."""
temp = (byte_1 << 8) + byte_2
if (temp > 32767):
temp = temp - 65536
temp = temp / 10
return temp | [
"def",
"_decode_temp",
"(",
"byte_1",
",",
"byte_2",
")",
":",
"temp",
"=",
"(",
"byte_1",
"<<",
"8",
")",
"+",
"byte_2",
"if",
"(",
"temp",
">",
"32767",
")",
":",
"temp",
"=",
"temp",
"-",
"65536",
"temp",
"=",
"temp",
"/",
"10",
"return",
"tem... | Decode a signed short temperature as two bytes to a single number. | [
"Decode",
"a",
"signed",
"short",
"temperature",
"as",
"two",
"bytes",
"to",
"a",
"single",
"number",
"."
] | 3f607c064cc53b8310d22d42506ce817a5b735fe | https://github.com/bimbar/pykwb/blob/3f607c064cc53b8310d22d42506ce817a5b735fe/pykwb/kwb.py#L259-L265 | train | 58,844 |
bimbar/pykwb | pykwb/kwb.py | KWBEasyfire._read_packet | def _read_packet(self):
"""Read a packet from the input."""
status = STATUS_WAITING
mode = 0
checksum = 0
checksum_calculated = 0
length = 0
version = 0
i = 0
cnt = 0
packet = bytearray(0)
while (status != STATUS_PACKET_DONE):
... | python | def _read_packet(self):
"""Read a packet from the input."""
status = STATUS_WAITING
mode = 0
checksum = 0
checksum_calculated = 0
length = 0
version = 0
i = 0
cnt = 0
packet = bytearray(0)
while (status != STATUS_PACKET_DONE):
... | [
"def",
"_read_packet",
"(",
"self",
")",
":",
"status",
"=",
"STATUS_WAITING",
"mode",
"=",
"0",
"checksum",
"=",
"0",
"checksum_calculated",
"=",
"0",
"length",
"=",
"0",
"version",
"=",
"0",
"i",
"=",
"0",
"cnt",
"=",
"0",
"packet",
"=",
"bytearray",... | Read a packet from the input. | [
"Read",
"a",
"packet",
"from",
"the",
"input",
"."
] | 3f607c064cc53b8310d22d42506ce817a5b735fe | https://github.com/bimbar/pykwb/blob/3f607c064cc53b8310d22d42506ce817a5b735fe/pykwb/kwb.py#L268-L346 | train | 58,845 |
bimbar/pykwb | pykwb/kwb.py | KWBEasyfire._decode_sense_packet | def _decode_sense_packet(self, version, packet):
"""Decode a sense packet into the list of sensors."""
data = self._sense_packet_to_data(packet)
offset = 4
i = 0
datalen = len(data) - offset - 6
temp_count = int(datalen / 2)
temp = []
for i in range(te... | python | def _decode_sense_packet(self, version, packet):
"""Decode a sense packet into the list of sensors."""
data = self._sense_packet_to_data(packet)
offset = 4
i = 0
datalen = len(data) - offset - 6
temp_count = int(datalen / 2)
temp = []
for i in range(te... | [
"def",
"_decode_sense_packet",
"(",
"self",
",",
"version",
",",
"packet",
")",
":",
"data",
"=",
"self",
".",
"_sense_packet_to_data",
"(",
"packet",
")",
"offset",
"=",
"4",
"i",
"=",
"0",
"datalen",
"=",
"len",
"(",
"data",
")",
"-",
"offset",
"-",
... | Decode a sense packet into the list of sensors. | [
"Decode",
"a",
"sense",
"packet",
"into",
"the",
"list",
"of",
"sensors",
"."
] | 3f607c064cc53b8310d22d42506ce817a5b735fe | https://github.com/bimbar/pykwb/blob/3f607c064cc53b8310d22d42506ce817a5b735fe/pykwb/kwb.py#L348-L372 | train | 58,846 |
bimbar/pykwb | pykwb/kwb.py | KWBEasyfire._decode_ctrl_packet | def _decode_ctrl_packet(self, version, packet):
"""Decode a control packet into the list of sensors."""
for i in range(5):
input_bit = packet[i]
self._debug(PROP_LOGLEVEL_DEBUG, "Byte " + str(i) + ": " + str((input_bit >> 7) & 1) + str((input_bit >> 6) & 1) + str((input_bit >> 5... | python | def _decode_ctrl_packet(self, version, packet):
"""Decode a control packet into the list of sensors."""
for i in range(5):
input_bit = packet[i]
self._debug(PROP_LOGLEVEL_DEBUG, "Byte " + str(i) + ": " + str((input_bit >> 7) & 1) + str((input_bit >> 6) & 1) + str((input_bit >> 5... | [
"def",
"_decode_ctrl_packet",
"(",
"self",
",",
"version",
",",
"packet",
")",
":",
"for",
"i",
"in",
"range",
"(",
"5",
")",
":",
"input_bit",
"=",
"packet",
"[",
"i",
"]",
"self",
".",
"_debug",
"(",
"PROP_LOGLEVEL_DEBUG",
",",
"\"Byte \"",
"+",
"str... | Decode a control packet into the list of sensors. | [
"Decode",
"a",
"control",
"packet",
"into",
"the",
"list",
"of",
"sensors",
"."
] | 3f607c064cc53b8310d22d42506ce817a5b735fe | https://github.com/bimbar/pykwb/blob/3f607c064cc53b8310d22d42506ce817a5b735fe/pykwb/kwb.py#L374-L385 | train | 58,847 |
bimbar/pykwb | pykwb/kwb.py | KWBEasyfire.run | def run(self):
"""Main thread that reads from input and populates the sensors."""
while (self._run_thread):
(mode, version, packet) = self._read_packet()
if (mode == PROP_PACKET_SENSE):
self._decode_sense_packet(version, packet)
elif (mode == PROP_PACK... | python | def run(self):
"""Main thread that reads from input and populates the sensors."""
while (self._run_thread):
(mode, version, packet) = self._read_packet()
if (mode == PROP_PACKET_SENSE):
self._decode_sense_packet(version, packet)
elif (mode == PROP_PACK... | [
"def",
"run",
"(",
"self",
")",
":",
"while",
"(",
"self",
".",
"_run_thread",
")",
":",
"(",
"mode",
",",
"version",
",",
"packet",
")",
"=",
"self",
".",
"_read_packet",
"(",
")",
"if",
"(",
"mode",
"==",
"PROP_PACKET_SENSE",
")",
":",
"self",
".... | Main thread that reads from input and populates the sensors. | [
"Main",
"thread",
"that",
"reads",
"from",
"input",
"and",
"populates",
"the",
"sensors",
"."
] | 3f607c064cc53b8310d22d42506ce817a5b735fe | https://github.com/bimbar/pykwb/blob/3f607c064cc53b8310d22d42506ce817a5b735fe/pykwb/kwb.py#L403-L410 | train | 58,848 |
bimbar/pykwb | pykwb/kwb.py | KWBEasyfire.run_thread | def run_thread(self):
"""Run the main thread."""
self._run_thread = True
self._thread.setDaemon(True)
self._thread.start() | python | def run_thread(self):
"""Run the main thread."""
self._run_thread = True
self._thread.setDaemon(True)
self._thread.start() | [
"def",
"run_thread",
"(",
"self",
")",
":",
"self",
".",
"_run_thread",
"=",
"True",
"self",
".",
"_thread",
".",
"setDaemon",
"(",
"True",
")",
"self",
".",
"_thread",
".",
"start",
"(",
")"
] | Run the main thread. | [
"Run",
"the",
"main",
"thread",
"."
] | 3f607c064cc53b8310d22d42506ce817a5b735fe | https://github.com/bimbar/pykwb/blob/3f607c064cc53b8310d22d42506ce817a5b735fe/pykwb/kwb.py#L412-L416 | train | 58,849 |
rackerlabs/python-lunrclient | lunrclient/base.py | BaseAPI.unused | def unused(self, _dict):
"""
Remove empty parameters from the dict
"""
for key, value in _dict.items():
if value is None:
del _dict[key]
return _dict | python | def unused(self, _dict):
"""
Remove empty parameters from the dict
"""
for key, value in _dict.items():
if value is None:
del _dict[key]
return _dict | [
"def",
"unused",
"(",
"self",
",",
"_dict",
")",
":",
"for",
"key",
",",
"value",
"in",
"_dict",
".",
"items",
"(",
")",
":",
"if",
"value",
"is",
"None",
":",
"del",
"_dict",
"[",
"key",
"]",
"return",
"_dict"
] | Remove empty parameters from the dict | [
"Remove",
"empty",
"parameters",
"from",
"the",
"dict"
] | f26a450a422600f492480bfa42cbee50a5c7016f | https://github.com/rackerlabs/python-lunrclient/blob/f26a450a422600f492480bfa42cbee50a5c7016f/lunrclient/base.py#L115-L122 | train | 58,850 |
rackerlabs/python-lunrclient | lunrclient/base.py | BaseAPI.required | def required(self, method, _dict, require):
"""
Ensure the required items are in the dictionary
"""
for key in require:
if key not in _dict:
raise LunrError("'%s' is required argument for method '%s'"
% (key, method)) | python | def required(self, method, _dict, require):
"""
Ensure the required items are in the dictionary
"""
for key in require:
if key not in _dict:
raise LunrError("'%s' is required argument for method '%s'"
% (key, method)) | [
"def",
"required",
"(",
"self",
",",
"method",
",",
"_dict",
",",
"require",
")",
":",
"for",
"key",
"in",
"require",
":",
"if",
"key",
"not",
"in",
"_dict",
":",
"raise",
"LunrError",
"(",
"\"'%s' is required argument for method '%s'\"",
"%",
"(",
"key",
... | Ensure the required items are in the dictionary | [
"Ensure",
"the",
"required",
"items",
"are",
"in",
"the",
"dictionary"
] | f26a450a422600f492480bfa42cbee50a5c7016f | https://github.com/rackerlabs/python-lunrclient/blob/f26a450a422600f492480bfa42cbee50a5c7016f/lunrclient/base.py#L124-L131 | train | 58,851 |
rackerlabs/python-lunrclient | lunrclient/base.py | BaseAPI.allowed | def allowed(self, method, _dict, allow):
"""
Only these items are allowed in the dictionary
"""
for key in _dict.keys():
if key not in allow:
raise LunrError("'%s' is not an argument for method '%s'"
% (key, method)) | python | def allowed(self, method, _dict, allow):
"""
Only these items are allowed in the dictionary
"""
for key in _dict.keys():
if key not in allow:
raise LunrError("'%s' is not an argument for method '%s'"
% (key, method)) | [
"def",
"allowed",
"(",
"self",
",",
"method",
",",
"_dict",
",",
"allow",
")",
":",
"for",
"key",
"in",
"_dict",
".",
"keys",
"(",
")",
":",
"if",
"key",
"not",
"in",
"allow",
":",
"raise",
"LunrError",
"(",
"\"'%s' is not an argument for method '%s'\"",
... | Only these items are allowed in the dictionary | [
"Only",
"these",
"items",
"are",
"allowed",
"in",
"the",
"dictionary"
] | f26a450a422600f492480bfa42cbee50a5c7016f | https://github.com/rackerlabs/python-lunrclient/blob/f26a450a422600f492480bfa42cbee50a5c7016f/lunrclient/base.py#L133-L140 | train | 58,852 |
Yipit/eventlib | eventlib/core.py | parse_event_name | def parse_event_name(name):
"""Returns the python module and obj given an event name
"""
try:
app, event = name.split('.')
return '{}.{}'.format(app, EVENTS_MODULE_NAME), event
except ValueError:
raise InvalidEventNameError(
(u'The name "{}" is invalid. '
... | python | def parse_event_name(name):
"""Returns the python module and obj given an event name
"""
try:
app, event = name.split('.')
return '{}.{}'.format(app, EVENTS_MODULE_NAME), event
except ValueError:
raise InvalidEventNameError(
(u'The name "{}" is invalid. '
... | [
"def",
"parse_event_name",
"(",
"name",
")",
":",
"try",
":",
"app",
",",
"event",
"=",
"name",
".",
"split",
"(",
"'.'",
")",
"return",
"'{}.{}'",
".",
"format",
"(",
"app",
",",
"EVENTS_MODULE_NAME",
")",
",",
"event",
"except",
"ValueError",
":",
"r... | Returns the python module and obj given an event name | [
"Returns",
"the",
"python",
"module",
"and",
"obj",
"given",
"an",
"event",
"name"
] | 0cf29e5251a59fcbfc727af5f5157a3bb03832e2 | https://github.com/Yipit/eventlib/blob/0cf29e5251a59fcbfc727af5f5157a3bb03832e2/eventlib/core.py#L44-L54 | train | 58,853 |
Yipit/eventlib | eventlib/core.py | find_event | def find_event(name):
"""Actually import the event represented by name
Raises the `EventNotFoundError` if it's not possible to find the
event class refered by `name`.
"""
try:
module, klass = parse_event_name(name)
return getattr(import_module(module), klass)
except (ImportError... | python | def find_event(name):
"""Actually import the event represented by name
Raises the `EventNotFoundError` if it's not possible to find the
event class refered by `name`.
"""
try:
module, klass = parse_event_name(name)
return getattr(import_module(module), klass)
except (ImportError... | [
"def",
"find_event",
"(",
"name",
")",
":",
"try",
":",
"module",
",",
"klass",
"=",
"parse_event_name",
"(",
"name",
")",
"return",
"getattr",
"(",
"import_module",
"(",
"module",
")",
",",
"klass",
")",
"except",
"(",
"ImportError",
",",
"AttributeError"... | Actually import the event represented by name
Raises the `EventNotFoundError` if it's not possible to find the
event class refered by `name`. | [
"Actually",
"import",
"the",
"event",
"represented",
"by",
"name"
] | 0cf29e5251a59fcbfc727af5f5157a3bb03832e2 | https://github.com/Yipit/eventlib/blob/0cf29e5251a59fcbfc727af5f5157a3bb03832e2/eventlib/core.py#L63-L76 | train | 58,854 |
Yipit/eventlib | eventlib/core.py | cleanup_handlers | def cleanup_handlers(event=None):
"""Remove handlers of a given `event`. If no event is informed, wipe
out all events registered.
Be careful!! This function is intended to help when writing tests
and for debugging purposes. If you call it, all handlers associated
to an event (or to all of them) wil... | python | def cleanup_handlers(event=None):
"""Remove handlers of a given `event`. If no event is informed, wipe
out all events registered.
Be careful!! This function is intended to help when writing tests
and for debugging purposes. If you call it, all handlers associated
to an event (or to all of them) wil... | [
"def",
"cleanup_handlers",
"(",
"event",
"=",
"None",
")",
":",
"if",
"event",
":",
"if",
"event",
"in",
"HANDLER_REGISTRY",
":",
"del",
"HANDLER_REGISTRY",
"[",
"event",
"]",
"if",
"event",
"in",
"EXTERNAL_HANDLER_REGISTRY",
":",
"del",
"EXTERNAL_HANDLER_REGIST... | Remove handlers of a given `event`. If no event is informed, wipe
out all events registered.
Be careful!! This function is intended to help when writing tests
and for debugging purposes. If you call it, all handlers associated
to an event (or to all of them) will be disassociated. Which means
that ... | [
"Remove",
"handlers",
"of",
"a",
"given",
"event",
".",
"If",
"no",
"event",
"is",
"informed",
"wipe",
"out",
"all",
"events",
"registered",
"."
] | 0cf29e5251a59fcbfc727af5f5157a3bb03832e2 | https://github.com/Yipit/eventlib/blob/0cf29e5251a59fcbfc727af5f5157a3bb03832e2/eventlib/core.py#L79-L96 | train | 58,855 |
Yipit/eventlib | eventlib/core.py | find_handlers | def find_handlers(event_name, registry=HANDLER_REGISTRY):
"""Small helper to find all handlers associated to a given event
If the event can't be found, an empty list will be returned, since
this is an internal function and all validation against the event
name and its existence was already performed.
... | python | def find_handlers(event_name, registry=HANDLER_REGISTRY):
"""Small helper to find all handlers associated to a given event
If the event can't be found, an empty list will be returned, since
this is an internal function and all validation against the event
name and its existence was already performed.
... | [
"def",
"find_handlers",
"(",
"event_name",
",",
"registry",
"=",
"HANDLER_REGISTRY",
")",
":",
"handlers",
"=",
"[",
"]",
"# event_name can be a BaseEvent or the string representation",
"if",
"isinstance",
"(",
"event_name",
",",
"basestring",
")",
":",
"matched_events"... | Small helper to find all handlers associated to a given event
If the event can't be found, an empty list will be returned, since
this is an internal function and all validation against the event
name and its existence was already performed. | [
"Small",
"helper",
"to",
"find",
"all",
"handlers",
"associated",
"to",
"a",
"given",
"event"
] | 0cf29e5251a59fcbfc727af5f5157a3bb03832e2 | https://github.com/Yipit/eventlib/blob/0cf29e5251a59fcbfc727af5f5157a3bb03832e2/eventlib/core.py#L99-L117 | train | 58,856 |
Yipit/eventlib | eventlib/core.py | get_default_values | def get_default_values(data):
"""Return all default values that an event should have"""
request = data.get('request')
result = {}
result['__datetime__'] = datetime.now()
result['__ip_address__'] = request and get_ip(request) or '0.0.0.0'
return result | python | def get_default_values(data):
"""Return all default values that an event should have"""
request = data.get('request')
result = {}
result['__datetime__'] = datetime.now()
result['__ip_address__'] = request and get_ip(request) or '0.0.0.0'
return result | [
"def",
"get_default_values",
"(",
"data",
")",
":",
"request",
"=",
"data",
".",
"get",
"(",
"'request'",
")",
"result",
"=",
"{",
"}",
"result",
"[",
"'__datetime__'",
"]",
"=",
"datetime",
".",
"now",
"(",
")",
"result",
"[",
"'__ip_address__'",
"]",
... | Return all default values that an event should have | [
"Return",
"all",
"default",
"values",
"that",
"an",
"event",
"should",
"have"
] | 0cf29e5251a59fcbfc727af5f5157a3bb03832e2 | https://github.com/Yipit/eventlib/blob/0cf29e5251a59fcbfc727af5f5157a3bb03832e2/eventlib/core.py#L176-L182 | train | 58,857 |
Yipit/eventlib | eventlib/core.py | filter_data_values | def filter_data_values(data):
"""Remove special values that log function can take
There are some special values, like "request" that the `log()`
function can take, but they're not meant to be passed to the celery
task neither for the event handlers. This function filter these keys
and return anothe... | python | def filter_data_values(data):
"""Remove special values that log function can take
There are some special values, like "request" that the `log()`
function can take, but they're not meant to be passed to the celery
task neither for the event handlers. This function filter these keys
and return anothe... | [
"def",
"filter_data_values",
"(",
"data",
")",
":",
"banned",
"=",
"(",
"'request'",
",",
")",
"return",
"{",
"key",
":",
"val",
"for",
"key",
",",
"val",
"in",
"data",
".",
"items",
"(",
")",
"if",
"not",
"key",
"in",
"banned",
"}"
] | Remove special values that log function can take
There are some special values, like "request" that the `log()`
function can take, but they're not meant to be passed to the celery
task neither for the event handlers. This function filter these keys
and return another dict without them. | [
"Remove",
"special",
"values",
"that",
"log",
"function",
"can",
"take"
] | 0cf29e5251a59fcbfc727af5f5157a3bb03832e2 | https://github.com/Yipit/eventlib/blob/0cf29e5251a59fcbfc727af5f5157a3bb03832e2/eventlib/core.py#L185-L194 | train | 58,858 |
Yipit/eventlib | eventlib/core.py | import_event_modules | def import_event_modules():
"""Import all events declared for all currently installed apps
This function walks through the list of installed apps and tries to
import a module named `EVENTS_MODULE_NAME`.
"""
for installed_app in getsetting('INSTALLED_APPS'):
module_name = u'{}.{}'.format(ins... | python | def import_event_modules():
"""Import all events declared for all currently installed apps
This function walks through the list of installed apps and tries to
import a module named `EVENTS_MODULE_NAME`.
"""
for installed_app in getsetting('INSTALLED_APPS'):
module_name = u'{}.{}'.format(ins... | [
"def",
"import_event_modules",
"(",
")",
":",
"for",
"installed_app",
"in",
"getsetting",
"(",
"'INSTALLED_APPS'",
")",
":",
"module_name",
"=",
"u'{}.{}'",
".",
"format",
"(",
"installed_app",
",",
"EVENTS_MODULE_NAME",
")",
"try",
":",
"import_module",
"(",
"m... | Import all events declared for all currently installed apps
This function walks through the list of installed apps and tries to
import a module named `EVENTS_MODULE_NAME`. | [
"Import",
"all",
"events",
"declared",
"for",
"all",
"currently",
"installed",
"apps"
] | 0cf29e5251a59fcbfc727af5f5157a3bb03832e2 | https://github.com/Yipit/eventlib/blob/0cf29e5251a59fcbfc727af5f5157a3bb03832e2/eventlib/core.py#L197-L208 | train | 58,859 |
callowayproject/Calloway | calloway/apps/custom_registration/backends/email/__init__.py | handle_expired_accounts | def handle_expired_accounts():
"""
Check of expired accounts.
"""
ACTIVATED = RegistrationProfile.ACTIVATED
expiration_date = datetime.timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS)
to_delete = []
print "Processing %s registration profiles..." % str(RegistrationProfile.objects.all().c... | python | def handle_expired_accounts():
"""
Check of expired accounts.
"""
ACTIVATED = RegistrationProfile.ACTIVATED
expiration_date = datetime.timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS)
to_delete = []
print "Processing %s registration profiles..." % str(RegistrationProfile.objects.all().c... | [
"def",
"handle_expired_accounts",
"(",
")",
":",
"ACTIVATED",
"=",
"RegistrationProfile",
".",
"ACTIVATED",
"expiration_date",
"=",
"datetime",
".",
"timedelta",
"(",
"days",
"=",
"settings",
".",
"ACCOUNT_ACTIVATION_DAYS",
")",
"to_delete",
"=",
"[",
"]",
"print"... | Check of expired accounts. | [
"Check",
"of",
"expired",
"accounts",
"."
] | d22e98d41fbd298ab6393ba7bd84a75528be9f81 | https://github.com/callowayproject/Calloway/blob/d22e98d41fbd298ab6393ba7bd84a75528be9f81/calloway/apps/custom_registration/backends/email/__init__.py#L203-L250 | train | 58,860 |
callowayproject/Calloway | calloway/apps/custom_registration/backends/email/__init__.py | EmailBackend.activate | def activate(self, request, activation_key):
"""
Override default activation process. This will activate the user
even if its passed its expiration date.
"""
if SHA1_RE.search(activation_key):
try:
profile = RegistrationProfile.objects.get(activation... | python | def activate(self, request, activation_key):
"""
Override default activation process. This will activate the user
even if its passed its expiration date.
"""
if SHA1_RE.search(activation_key):
try:
profile = RegistrationProfile.objects.get(activation... | [
"def",
"activate",
"(",
"self",
",",
"request",
",",
"activation_key",
")",
":",
"if",
"SHA1_RE",
".",
"search",
"(",
"activation_key",
")",
":",
"try",
":",
"profile",
"=",
"RegistrationProfile",
".",
"objects",
".",
"get",
"(",
"activation_key",
"=",
"ac... | Override default activation process. This will activate the user
even if its passed its expiration date. | [
"Override",
"default",
"activation",
"process",
".",
"This",
"will",
"activate",
"the",
"user",
"even",
"if",
"its",
"passed",
"its",
"expiration",
"date",
"."
] | d22e98d41fbd298ab6393ba7bd84a75528be9f81 | https://github.com/callowayproject/Calloway/blob/d22e98d41fbd298ab6393ba7bd84a75528be9f81/calloway/apps/custom_registration/backends/email/__init__.py#L59-L76 | train | 58,861 |
callowayproject/Calloway | calloway/apps/custom_registration/backends/email/__init__.py | EmailBackend.register | def register(self, request, **kwargs):
"""
Create and immediately log in a new user.
Only require a email to register, username is generated
automatically and a password is random generated and emailed
to the user.
Activation is still required for accou... | python | def register(self, request, **kwargs):
"""
Create and immediately log in a new user.
Only require a email to register, username is generated
automatically and a password is random generated and emailed
to the user.
Activation is still required for accou... | [
"def",
"register",
"(",
"self",
",",
"request",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"Site",
".",
"_meta",
".",
"installed",
":",
"site",
"=",
"Site",
".",
"objects",
".",
"get_current",
"(",
")",
"else",
":",
"site",
"=",
"RequestSite",
"(",
"... | Create and immediately log in a new user.
Only require a email to register, username is generated
automatically and a password is random generated and emailed
to the user.
Activation is still required for account uses after specified number
of days. | [
"Create",
"and",
"immediately",
"log",
"in",
"a",
"new",
"user",
".",
"Only",
"require",
"a",
"email",
"to",
"register",
"username",
"is",
"generated",
"automatically",
"and",
"a",
"password",
"is",
"random",
"generated",
"and",
"emailed",
"to",
"the",
"user... | d22e98d41fbd298ab6393ba7bd84a75528be9f81 | https://github.com/callowayproject/Calloway/blob/d22e98d41fbd298ab6393ba7bd84a75528be9f81/calloway/apps/custom_registration/backends/email/__init__.py#L78-L145 | train | 58,862 |
callowayproject/Calloway | calloway/apps/custom_registration/backends/email/__init__.py | EmailBackend.send_activation_email | def send_activation_email(self, user, profile, password, site):
"""
Custom send email method to supplied the activation link and
new generated password.
"""
ctx_dict = { 'password': password,
'site': site,
'activation_key': profile.act... | python | def send_activation_email(self, user, profile, password, site):
"""
Custom send email method to supplied the activation link and
new generated password.
"""
ctx_dict = { 'password': password,
'site': site,
'activation_key': profile.act... | [
"def",
"send_activation_email",
"(",
"self",
",",
"user",
",",
"profile",
",",
"password",
",",
"site",
")",
":",
"ctx_dict",
"=",
"{",
"'password'",
":",
"password",
",",
"'site'",
":",
"site",
",",
"'activation_key'",
":",
"profile",
".",
"activation_key",... | Custom send email method to supplied the activation link and
new generated password. | [
"Custom",
"send",
"email",
"method",
"to",
"supplied",
"the",
"activation",
"link",
"and",
"new",
"generated",
"password",
"."
] | d22e98d41fbd298ab6393ba7bd84a75528be9f81 | https://github.com/callowayproject/Calloway/blob/d22e98d41fbd298ab6393ba7bd84a75528be9f81/calloway/apps/custom_registration/backends/email/__init__.py#L147-L169 | train | 58,863 |
callowayproject/Calloway | calloway/apps/custom_registration/backends/email/__init__.py | EmailBackend.post_registration_redirect | def post_registration_redirect(self, request, user):
"""
After registration, redirect to the home page or supplied "next"
query string or hidden field value.
"""
next_url = "/registration/register/complete/"
if "next" in request.GET or "next" in request.POST:
... | python | def post_registration_redirect(self, request, user):
"""
After registration, redirect to the home page or supplied "next"
query string or hidden field value.
"""
next_url = "/registration/register/complete/"
if "next" in request.GET or "next" in request.POST:
... | [
"def",
"post_registration_redirect",
"(",
"self",
",",
"request",
",",
"user",
")",
":",
"next_url",
"=",
"\"/registration/register/complete/\"",
"if",
"\"next\"",
"in",
"request",
".",
"GET",
"or",
"\"next\"",
"in",
"request",
".",
"POST",
":",
"next_url",
"=",... | After registration, redirect to the home page or supplied "next"
query string or hidden field value. | [
"After",
"registration",
"redirect",
"to",
"the",
"home",
"page",
"or",
"supplied",
"next",
"query",
"string",
"or",
"hidden",
"field",
"value",
"."
] | d22e98d41fbd298ab6393ba7bd84a75528be9f81 | https://github.com/callowayproject/Calloway/blob/d22e98d41fbd298ab6393ba7bd84a75528be9f81/calloway/apps/custom_registration/backends/email/__init__.py#L190-L200 | train | 58,864 |
helixyte/everest | everest/batch.py | Batch.next | def next(self):
"""
Returns the next batch for the batched sequence or `None`, if
this batch is already the last batch.
:rtype: :class:`Batch` instance or `None`.
"""
if self.start + self.size > self.total_size:
result = None
else:
result ... | python | def next(self):
"""
Returns the next batch for the batched sequence or `None`, if
this batch is already the last batch.
:rtype: :class:`Batch` instance or `None`.
"""
if self.start + self.size > self.total_size:
result = None
else:
result ... | [
"def",
"next",
"(",
"self",
")",
":",
"if",
"self",
".",
"start",
"+",
"self",
".",
"size",
">",
"self",
".",
"total_size",
":",
"result",
"=",
"None",
"else",
":",
"result",
"=",
"Batch",
"(",
"self",
".",
"start",
"+",
"self",
".",
"size",
",",... | Returns the next batch for the batched sequence or `None`, if
this batch is already the last batch.
:rtype: :class:`Batch` instance or `None`. | [
"Returns",
"the",
"next",
"batch",
"for",
"the",
"batched",
"sequence",
"or",
"None",
"if",
"this",
"batch",
"is",
"already",
"the",
"last",
"batch",
"."
] | 70c9b93c3061db5cb62428349d18b8fb8566411b | https://github.com/helixyte/everest/blob/70c9b93c3061db5cb62428349d18b8fb8566411b/everest/batch.py#L35-L46 | train | 58,865 |
helixyte/everest | everest/batch.py | Batch.previous | def previous(self):
"""
Returns the previous batch for the batched sequence or `None`, if
this batch is already the first batch.
:rtype: :class:`Batch` instance or `None`.
"""
if self.start - self.size < 0:
result = None
else:
result = Bat... | python | def previous(self):
"""
Returns the previous batch for the batched sequence or `None`, if
this batch is already the first batch.
:rtype: :class:`Batch` instance or `None`.
"""
if self.start - self.size < 0:
result = None
else:
result = Bat... | [
"def",
"previous",
"(",
"self",
")",
":",
"if",
"self",
".",
"start",
"-",
"self",
".",
"size",
"<",
"0",
":",
"result",
"=",
"None",
"else",
":",
"result",
"=",
"Batch",
"(",
"self",
".",
"start",
"-",
"self",
".",
"size",
",",
"self",
".",
"s... | Returns the previous batch for the batched sequence or `None`, if
this batch is already the first batch.
:rtype: :class:`Batch` instance or `None`. | [
"Returns",
"the",
"previous",
"batch",
"for",
"the",
"batched",
"sequence",
"or",
"None",
"if",
"this",
"batch",
"is",
"already",
"the",
"first",
"batch",
"."
] | 70c9b93c3061db5cb62428349d18b8fb8566411b | https://github.com/helixyte/everest/blob/70c9b93c3061db5cb62428349d18b8fb8566411b/everest/batch.py#L49-L60 | train | 58,866 |
helixyte/everest | everest/batch.py | Batch.last | def last(self):
"""
Returns the last batch for the batched sequence.
:rtype: :class:`Batch` instance.
"""
start = max(self.number - 1, 0) * self.size
return Batch(start, self.size, self.total_size) | python | def last(self):
"""
Returns the last batch for the batched sequence.
:rtype: :class:`Batch` instance.
"""
start = max(self.number - 1, 0) * self.size
return Batch(start, self.size, self.total_size) | [
"def",
"last",
"(",
"self",
")",
":",
"start",
"=",
"max",
"(",
"self",
".",
"number",
"-",
"1",
",",
"0",
")",
"*",
"self",
".",
"size",
"return",
"Batch",
"(",
"start",
",",
"self",
".",
"size",
",",
"self",
".",
"total_size",
")"
] | Returns the last batch for the batched sequence.
:rtype: :class:`Batch` instance. | [
"Returns",
"the",
"last",
"batch",
"for",
"the",
"batched",
"sequence",
"."
] | 70c9b93c3061db5cb62428349d18b8fb8566411b | https://github.com/helixyte/everest/blob/70c9b93c3061db5cb62428349d18b8fb8566411b/everest/batch.py#L72-L79 | train | 58,867 |
helixyte/everest | everest/batch.py | Batch.number | def number(self):
"""
Returns the number of batches the batched sequence contains.
:rtype: integer.
"""
return int(math.ceil(self.total_size / float(self.size))) | python | def number(self):
"""
Returns the number of batches the batched sequence contains.
:rtype: integer.
"""
return int(math.ceil(self.total_size / float(self.size))) | [
"def",
"number",
"(",
"self",
")",
":",
"return",
"int",
"(",
"math",
".",
"ceil",
"(",
"self",
".",
"total_size",
"/",
"float",
"(",
"self",
".",
"size",
")",
")",
")"
] | Returns the number of batches the batched sequence contains.
:rtype: integer. | [
"Returns",
"the",
"number",
"of",
"batches",
"the",
"batched",
"sequence",
"contains",
"."
] | 70c9b93c3061db5cb62428349d18b8fb8566411b | https://github.com/helixyte/everest/blob/70c9b93c3061db5cb62428349d18b8fb8566411b/everest/batch.py#L82-L88 | train | 58,868 |
bashu/django-watermark | watermarker/templatetags/watermark.py | watermark | def watermark(url, args=''):
"""
Returns the URL to a watermarked copy of the image specified.
"""
# initialize some variables
args = args.split(',')
params = dict(
name=args.pop(0),
opacity=0.5,
tile=False,
scale=1.0,
greyscale=False,
rotation=0... | python | def watermark(url, args=''):
"""
Returns the URL to a watermarked copy of the image specified.
"""
# initialize some variables
args = args.split(',')
params = dict(
name=args.pop(0),
opacity=0.5,
tile=False,
scale=1.0,
greyscale=False,
rotation=0... | [
"def",
"watermark",
"(",
"url",
",",
"args",
"=",
"''",
")",
":",
"# initialize some variables",
"args",
"=",
"args",
".",
"split",
"(",
"','",
")",
"params",
"=",
"dict",
"(",
"name",
"=",
"args",
".",
"pop",
"(",
"0",
")",
",",
"opacity",
"=",
"0... | Returns the URL to a watermarked copy of the image specified. | [
"Returns",
"the",
"URL",
"to",
"a",
"watermarked",
"copy",
"of",
"the",
"image",
"specified",
"."
] | 0ed47b35156d9a3dd893ca744789f38fdfe08fbe | https://github.com/bashu/django-watermark/blob/0ed47b35156d9a3dd893ca744789f38fdfe08fbe/watermarker/templatetags/watermark.py#L262-L308 | train | 58,869 |
bashu/django-watermark | watermarker/templatetags/watermark.py | Watermarker._get_filesystem_path | def _get_filesystem_path(self, url_path, basedir=settings.MEDIA_ROOT):
"""Makes a filesystem path from the specified URL path"""
if url_path.startswith(settings.MEDIA_URL):
url_path = url_path[len(settings.MEDIA_URL):] # strip media root url
return os.path.normpath(os.path.join(ba... | python | def _get_filesystem_path(self, url_path, basedir=settings.MEDIA_ROOT):
"""Makes a filesystem path from the specified URL path"""
if url_path.startswith(settings.MEDIA_URL):
url_path = url_path[len(settings.MEDIA_URL):] # strip media root url
return os.path.normpath(os.path.join(ba... | [
"def",
"_get_filesystem_path",
"(",
"self",
",",
"url_path",
",",
"basedir",
"=",
"settings",
".",
"MEDIA_ROOT",
")",
":",
"if",
"url_path",
".",
"startswith",
"(",
"settings",
".",
"MEDIA_URL",
")",
":",
"url_path",
"=",
"url_path",
"[",
"len",
"(",
"sett... | Makes a filesystem path from the specified URL path | [
"Makes",
"a",
"filesystem",
"path",
"from",
"the",
"specified",
"URL",
"path"
] | 0ed47b35156d9a3dd893ca744789f38fdfe08fbe | https://github.com/bashu/django-watermark/blob/0ed47b35156d9a3dd893ca744789f38fdfe08fbe/watermarker/templatetags/watermark.py#L181-L187 | train | 58,870 |
bashu/django-watermark | watermarker/templatetags/watermark.py | Watermarker.generate_filename | def generate_filename(self, mark, **kwargs):
"""Comes up with a good filename for the watermarked image"""
kwargs = kwargs.copy()
kwargs['opacity'] = int(kwargs['opacity'] * 100)
kwargs['st_mtime'] = kwargs['fstat'].st_mtime
kwargs['st_size'] = kwargs['fstat'].st_size
... | python | def generate_filename(self, mark, **kwargs):
"""Comes up with a good filename for the watermarked image"""
kwargs = kwargs.copy()
kwargs['opacity'] = int(kwargs['opacity'] * 100)
kwargs['st_mtime'] = kwargs['fstat'].st_mtime
kwargs['st_size'] = kwargs['fstat'].st_size
... | [
"def",
"generate_filename",
"(",
"self",
",",
"mark",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
"=",
"kwargs",
".",
"copy",
"(",
")",
"kwargs",
"[",
"'opacity'",
"]",
"=",
"int",
"(",
"kwargs",
"[",
"'opacity'",
"]",
"*",
"100",
")",
"kwargs",
"... | Comes up with a good filename for the watermarked image | [
"Comes",
"up",
"with",
"a",
"good",
"filename",
"for",
"the",
"watermarked",
"image"
] | 0ed47b35156d9a3dd893ca744789f38fdfe08fbe | https://github.com/bashu/django-watermark/blob/0ed47b35156d9a3dd893ca744789f38fdfe08fbe/watermarker/templatetags/watermark.py#L189-L220 | train | 58,871 |
bashu/django-watermark | watermarker/templatetags/watermark.py | Watermarker.get_url_path | def get_url_path(self, basedir, original_basename, ext, name, obscure=True):
"""Determines an appropriate watermark path"""
try:
hash = hashlib.sha1(smart_str(name)).hexdigest()
except TypeError:
hash = hashlib.sha1(smart_str(name).encode('utf-8')).hexdigest()
#... | python | def get_url_path(self, basedir, original_basename, ext, name, obscure=True):
"""Determines an appropriate watermark path"""
try:
hash = hashlib.sha1(smart_str(name)).hexdigest()
except TypeError:
hash = hashlib.sha1(smart_str(name).encode('utf-8')).hexdigest()
#... | [
"def",
"get_url_path",
"(",
"self",
",",
"basedir",
",",
"original_basename",
",",
"ext",
",",
"name",
",",
"obscure",
"=",
"True",
")",
":",
"try",
":",
"hash",
"=",
"hashlib",
".",
"sha1",
"(",
"smart_str",
"(",
"name",
")",
")",
".",
"hexdigest",
... | Determines an appropriate watermark path | [
"Determines",
"an",
"appropriate",
"watermark",
"path"
] | 0ed47b35156d9a3dd893ca744789f38fdfe08fbe | https://github.com/bashu/django-watermark/blob/0ed47b35156d9a3dd893ca744789f38fdfe08fbe/watermarker/templatetags/watermark.py#L222-L251 | train | 58,872 |
bashu/django-watermark | watermarker/templatetags/watermark.py | Watermarker.create_watermark | def create_watermark(self, target, mark, fpath, quality=QUALITY, **kwargs):
"""Create the watermarked image on the filesystem"""
im = utils.watermark(target, mark, **kwargs)
im.save(fpath, quality=quality)
return im | python | def create_watermark(self, target, mark, fpath, quality=QUALITY, **kwargs):
"""Create the watermarked image on the filesystem"""
im = utils.watermark(target, mark, **kwargs)
im.save(fpath, quality=quality)
return im | [
"def",
"create_watermark",
"(",
"self",
",",
"target",
",",
"mark",
",",
"fpath",
",",
"quality",
"=",
"QUALITY",
",",
"*",
"*",
"kwargs",
")",
":",
"im",
"=",
"utils",
".",
"watermark",
"(",
"target",
",",
"mark",
",",
"*",
"*",
"kwargs",
")",
"im... | Create the watermarked image on the filesystem | [
"Create",
"the",
"watermarked",
"image",
"on",
"the",
"filesystem"
] | 0ed47b35156d9a3dd893ca744789f38fdfe08fbe | https://github.com/bashu/django-watermark/blob/0ed47b35156d9a3dd893ca744789f38fdfe08fbe/watermarker/templatetags/watermark.py#L253-L258 | train | 58,873 |
bashu/django-watermark | watermarker/utils.py | _val | def _val(var, is_percent=False):
"""
Tries to determine the appropriate value of a particular variable that is
passed in. If the value is supposed to be a percentage, a whole integer
will be sought after and then turned into a floating point number between
0 and 1. If the value is supposed to be a... | python | def _val(var, is_percent=False):
"""
Tries to determine the appropriate value of a particular variable that is
passed in. If the value is supposed to be a percentage, a whole integer
will be sought after and then turned into a floating point number between
0 and 1. If the value is supposed to be a... | [
"def",
"_val",
"(",
"var",
",",
"is_percent",
"=",
"False",
")",
":",
"try",
":",
"if",
"is_percent",
":",
"var",
"=",
"float",
"(",
"int",
"(",
"var",
".",
"strip",
"(",
"'%'",
")",
")",
"/",
"100.0",
")",
"else",
":",
"var",
"=",
"int",
"(",
... | Tries to determine the appropriate value of a particular variable that is
passed in. If the value is supposed to be a percentage, a whole integer
will be sought after and then turned into a floating point number between
0 and 1. If the value is supposed to be an integer, the variable is cast
into an i... | [
"Tries",
"to",
"determine",
"the",
"appropriate",
"value",
"of",
"a",
"particular",
"variable",
"that",
"is",
"passed",
"in",
".",
"If",
"the",
"value",
"is",
"supposed",
"to",
"be",
"a",
"percentage",
"a",
"whole",
"integer",
"will",
"be",
"sought",
"afte... | 0ed47b35156d9a3dd893ca744789f38fdfe08fbe | https://github.com/bashu/django-watermark/blob/0ed47b35156d9a3dd893ca744789f38fdfe08fbe/watermarker/utils.py#L34-L50 | train | 58,874 |
bashu/django-watermark | watermarker/utils.py | reduce_opacity | def reduce_opacity(img, opacity):
"""
Returns an image with reduced opacity.
"""
assert opacity >= 0 and opacity <= 1
if img.mode != 'RGBA':
img = img.convert('RGBA')
else:
img = img.copy()
alpha = img.split()[3]
alpha = ImageEnhance.Brightness(alpha).enhance(opacity)
... | python | def reduce_opacity(img, opacity):
"""
Returns an image with reduced opacity.
"""
assert opacity >= 0 and opacity <= 1
if img.mode != 'RGBA':
img = img.convert('RGBA')
else:
img = img.copy()
alpha = img.split()[3]
alpha = ImageEnhance.Brightness(alpha).enhance(opacity)
... | [
"def",
"reduce_opacity",
"(",
"img",
",",
"opacity",
")",
":",
"assert",
"opacity",
">=",
"0",
"and",
"opacity",
"<=",
"1",
"if",
"img",
".",
"mode",
"!=",
"'RGBA'",
":",
"img",
"=",
"img",
".",
"convert",
"(",
"'RGBA'",
")",
"else",
":",
"img",
"=... | Returns an image with reduced opacity. | [
"Returns",
"an",
"image",
"with",
"reduced",
"opacity",
"."
] | 0ed47b35156d9a3dd893ca744789f38fdfe08fbe | https://github.com/bashu/django-watermark/blob/0ed47b35156d9a3dd893ca744789f38fdfe08fbe/watermarker/utils.py#L53-L68 | train | 58,875 |
bashu/django-watermark | watermarker/utils.py | determine_scale | def determine_scale(scale, img, mark):
"""
Scales an image using a specified ratio, 'F' or 'R'. If `scale` is
'F', the image is scaled to be as big as possible to fit in `img`
without falling off the edges. If `scale` is 'R', the watermark
resizes to a percentage of minimum size of source image. R... | python | def determine_scale(scale, img, mark):
"""
Scales an image using a specified ratio, 'F' or 'R'. If `scale` is
'F', the image is scaled to be as big as possible to fit in `img`
without falling off the edges. If `scale` is 'R', the watermark
resizes to a percentage of minimum size of source image. R... | [
"def",
"determine_scale",
"(",
"scale",
",",
"img",
",",
"mark",
")",
":",
"if",
"scale",
":",
"try",
":",
"scale",
"=",
"float",
"(",
"scale",
")",
"except",
"(",
"ValueError",
",",
"TypeError",
")",
":",
"pass",
"if",
"isinstance",
"(",
"scale",
",... | Scales an image using a specified ratio, 'F' or 'R'. If `scale` is
'F', the image is scaled to be as big as possible to fit in `img`
without falling off the edges. If `scale` is 'R', the watermark
resizes to a percentage of minimum size of source image. Returns
the scaled `mark`. | [
"Scales",
"an",
"image",
"using",
"a",
"specified",
"ratio",
"F",
"or",
"R",
".",
"If",
"scale",
"is",
"F",
"the",
"image",
"is",
"scaled",
"to",
"be",
"as",
"big",
"as",
"possible",
"to",
"fit",
"in",
"img",
"without",
"falling",
"off",
"the",
"edge... | 0ed47b35156d9a3dd893ca744789f38fdfe08fbe | https://github.com/bashu/django-watermark/blob/0ed47b35156d9a3dd893ca744789f38fdfe08fbe/watermarker/utils.py#L71-L111 | train | 58,876 |
bashu/django-watermark | watermarker/utils.py | determine_rotation | def determine_rotation(rotation, mark):
"""
Determines the number of degrees to rotate the watermark image.
"""
if isinstance(rotation, six.string_types) and rotation.lower() == 'r':
rotation = random.randint(0, 359)
else:
rotation = _int(rotation)
return rotation | python | def determine_rotation(rotation, mark):
"""
Determines the number of degrees to rotate the watermark image.
"""
if isinstance(rotation, six.string_types) and rotation.lower() == 'r':
rotation = random.randint(0, 359)
else:
rotation = _int(rotation)
return rotation | [
"def",
"determine_rotation",
"(",
"rotation",
",",
"mark",
")",
":",
"if",
"isinstance",
"(",
"rotation",
",",
"six",
".",
"string_types",
")",
"and",
"rotation",
".",
"lower",
"(",
")",
"==",
"'r'",
":",
"rotation",
"=",
"random",
".",
"randint",
"(",
... | Determines the number of degrees to rotate the watermark image. | [
"Determines",
"the",
"number",
"of",
"degrees",
"to",
"rotate",
"the",
"watermark",
"image",
"."
] | 0ed47b35156d9a3dd893ca744789f38fdfe08fbe | https://github.com/bashu/django-watermark/blob/0ed47b35156d9a3dd893ca744789f38fdfe08fbe/watermarker/utils.py#L114-L123 | train | 58,877 |
bashu/django-watermark | watermarker/utils.py | watermark | def watermark(img, mark, position=(0, 0), opacity=1, scale=1.0, tile=False,
greyscale=False, rotation=0, return_name=False, **kwargs):
"""Adds a watermark to an image"""
if opacity < 1:
mark = reduce_opacity(mark, opacity)
if not isinstance(scale, tuple):
scale = determine_sc... | python | def watermark(img, mark, position=(0, 0), opacity=1, scale=1.0, tile=False,
greyscale=False, rotation=0, return_name=False, **kwargs):
"""Adds a watermark to an image"""
if opacity < 1:
mark = reduce_opacity(mark, opacity)
if not isinstance(scale, tuple):
scale = determine_sc... | [
"def",
"watermark",
"(",
"img",
",",
"mark",
",",
"position",
"=",
"(",
"0",
",",
"0",
")",
",",
"opacity",
"=",
"1",
",",
"scale",
"=",
"1.0",
",",
"tile",
"=",
"False",
",",
"greyscale",
"=",
"False",
",",
"rotation",
"=",
"0",
",",
"return_nam... | Adds a watermark to an image | [
"Adds",
"a",
"watermark",
"to",
"an",
"image"
] | 0ed47b35156d9a3dd893ca744789f38fdfe08fbe | https://github.com/bashu/django-watermark/blob/0ed47b35156d9a3dd893ca744789f38fdfe08fbe/watermarker/utils.py#L197-L249 | train | 58,878 |
icemac/toll | src/toll/config.py | parsed_file | def parsed_file(config_file):
"""Parse an ini-style config file."""
parser = ConfigParser(allow_no_value=True)
parser.readfp(config_file)
return parser | python | def parsed_file(config_file):
"""Parse an ini-style config file."""
parser = ConfigParser(allow_no_value=True)
parser.readfp(config_file)
return parser | [
"def",
"parsed_file",
"(",
"config_file",
")",
":",
"parser",
"=",
"ConfigParser",
"(",
"allow_no_value",
"=",
"True",
")",
"parser",
".",
"readfp",
"(",
"config_file",
")",
"return",
"parser"
] | Parse an ini-style config file. | [
"Parse",
"an",
"ini",
"-",
"style",
"config",
"file",
"."
] | aa25480fcbc2017519516ec1e7fe60d78fb2f30b | https://github.com/icemac/toll/blob/aa25480fcbc2017519516ec1e7fe60d78fb2f30b/src/toll/config.py#L7-L11 | train | 58,879 |
icemac/toll | src/toll/config.py | commands | def commands(config, names):
"""Return the list of commands to run."""
commands = {cmd: Command(**dict((minus_to_underscore(k), v)
for k, v in config.items(cmd)))
for cmd in config.sections()
if cmd != 'packages'}
try:
return tuple(... | python | def commands(config, names):
"""Return the list of commands to run."""
commands = {cmd: Command(**dict((minus_to_underscore(k), v)
for k, v in config.items(cmd)))
for cmd in config.sections()
if cmd != 'packages'}
try:
return tuple(... | [
"def",
"commands",
"(",
"config",
",",
"names",
")",
":",
"commands",
"=",
"{",
"cmd",
":",
"Command",
"(",
"*",
"*",
"dict",
"(",
"(",
"minus_to_underscore",
"(",
"k",
")",
",",
"v",
")",
"for",
"k",
",",
"v",
"in",
"config",
".",
"items",
"(",
... | Return the list of commands to run. | [
"Return",
"the",
"list",
"of",
"commands",
"to",
"run",
"."
] | aa25480fcbc2017519516ec1e7fe60d78fb2f30b | https://github.com/icemac/toll/blob/aa25480fcbc2017519516ec1e7fe60d78fb2f30b/src/toll/config.py#L52-L63 | train | 58,880 |
icemac/toll | setup.py | project_path | def project_path(*names):
"""Path to a file in the project."""
return os.path.join(os.path.dirname(__file__), *names) | python | def project_path(*names):
"""Path to a file in the project."""
return os.path.join(os.path.dirname(__file__), *names) | [
"def",
"project_path",
"(",
"*",
"names",
")",
":",
"return",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
",",
"*",
"names",
")"
] | Path to a file in the project. | [
"Path",
"to",
"a",
"file",
"in",
"the",
"project",
"."
] | aa25480fcbc2017519516ec1e7fe60d78fb2f30b | https://github.com/icemac/toll/blob/aa25480fcbc2017519516ec1e7fe60d78fb2f30b/setup.py#L8-L10 | train | 58,881 |
rcbops/rpc_differ | rpc_differ/rpc_differ.py | get_osa_commit | def get_osa_commit(repo, ref, rpc_product=None):
"""Get the OSA sha referenced by an RPCO Repo."""
osa_differ.checkout(repo, ref)
functions_path = os.path.join(repo.working_tree_dir,
'scripts/functions.sh')
release_path = os.path.join(repo.working_tree_dir,
... | python | def get_osa_commit(repo, ref, rpc_product=None):
"""Get the OSA sha referenced by an RPCO Repo."""
osa_differ.checkout(repo, ref)
functions_path = os.path.join(repo.working_tree_dir,
'scripts/functions.sh')
release_path = os.path.join(repo.working_tree_dir,
... | [
"def",
"get_osa_commit",
"(",
"repo",
",",
"ref",
",",
"rpc_product",
"=",
"None",
")",
":",
"osa_differ",
".",
"checkout",
"(",
"repo",
",",
"ref",
")",
"functions_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"repo",
".",
"working_tree_dir",
",",
... | Get the OSA sha referenced by an RPCO Repo. | [
"Get",
"the",
"OSA",
"sha",
"referenced",
"by",
"an",
"RPCO",
"Repo",
"."
] | 07c9e645b13f9af15d58bad533753d3a9447b78a | https://github.com/rcbops/rpc_differ/blob/07c9e645b13f9af15d58bad533753d3a9447b78a/rpc_differ/rpc_differ.py#L189-L225 | train | 58,882 |
rcbops/rpc_differ | rpc_differ/rpc_differ.py | publish_report | def publish_report(report, args, old_commit, new_commit):
"""Publish the RST report based on the user request."""
# Print the report to stdout unless the user specified --quiet.
output = ""
if not args.quiet and not args.gist and not args.file:
return report
if args.gist:
gist_url ... | python | def publish_report(report, args, old_commit, new_commit):
"""Publish the RST report based on the user request."""
# Print the report to stdout unless the user specified --quiet.
output = ""
if not args.quiet and not args.gist and not args.file:
return report
if args.gist:
gist_url ... | [
"def",
"publish_report",
"(",
"report",
",",
"args",
",",
"old_commit",
",",
"new_commit",
")",
":",
"# Print the report to stdout unless the user specified --quiet.",
"output",
"=",
"\"\"",
"if",
"not",
"args",
".",
"quiet",
"and",
"not",
"args",
".",
"gist",
"an... | Publish the RST report based on the user request. | [
"Publish",
"the",
"RST",
"report",
"based",
"on",
"the",
"user",
"request",
"."
] | 07c9e645b13f9af15d58bad533753d3a9447b78a | https://github.com/rcbops/rpc_differ/blob/07c9e645b13f9af15d58bad533753d3a9447b78a/rpc_differ/rpc_differ.py#L308-L325 | train | 58,883 |
rcbops/rpc_differ | rpc_differ/rpc_differ.py | run_rpc_differ | def run_rpc_differ():
"""The script starts here."""
args = parse_arguments()
# Set up DEBUG logging if needed
if args.debug:
log.setLevel(logging.DEBUG)
elif args.verbose:
log.setLevel(logging.INFO)
# Create the storage directory if it doesn't exist already.
try:
st... | python | def run_rpc_differ():
"""The script starts here."""
args = parse_arguments()
# Set up DEBUG logging if needed
if args.debug:
log.setLevel(logging.DEBUG)
elif args.verbose:
log.setLevel(logging.INFO)
# Create the storage directory if it doesn't exist already.
try:
st... | [
"def",
"run_rpc_differ",
"(",
")",
":",
"args",
"=",
"parse_arguments",
"(",
")",
"# Set up DEBUG logging if needed",
"if",
"args",
".",
"debug",
":",
"log",
".",
"setLevel",
"(",
"logging",
".",
"DEBUG",
")",
"elif",
"args",
".",
"verbose",
":",
"log",
".... | The script starts here. | [
"The",
"script",
"starts",
"here",
"."
] | 07c9e645b13f9af15d58bad533753d3a9447b78a | https://github.com/rcbops/rpc_differ/blob/07c9e645b13f9af15d58bad533753d3a9447b78a/rpc_differ/rpc_differ.py#L343-L489 | train | 58,884 |
icemac/toll | src/toll/main.py | main | def main(raw_args=None):
"""Console script entry point."""
parser = argparse.ArgumentParser(
description="poor man's integration testing")
parser.add_argument(
'cmds', metavar='cmd', default=['test'], nargs='*',
help='Run command(s) defined in the configuration file. Each command '
... | python | def main(raw_args=None):
"""Console script entry point."""
parser = argparse.ArgumentParser(
description="poor man's integration testing")
parser.add_argument(
'cmds', metavar='cmd', default=['test'], nargs='*',
help='Run command(s) defined in the configuration file. Each command '
... | [
"def",
"main",
"(",
"raw_args",
"=",
"None",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"\"poor man's integration testing\"",
")",
"parser",
".",
"add_argument",
"(",
"'cmds'",
",",
"metavar",
"=",
"'cmd'",
",",
"defau... | Console script entry point. | [
"Console",
"script",
"entry",
"point",
"."
] | aa25480fcbc2017519516ec1e7fe60d78fb2f30b | https://github.com/icemac/toll/blob/aa25480fcbc2017519516ec1e7fe60d78fb2f30b/src/toll/main.py#L6-L29 | train | 58,885 |
ox-it/python-sharepoint | sharepoint/lists/__init__.py | SharePointLists.remove | def remove(self, list):
"""
Removes a list from the site.
"""
xml = SP.DeleteList(SP.listName(list.id))
self.opener.post_soap(LIST_WEBSERVICE, xml,
soapaction='http://schemas.microsoft.com/sharepoint/soap/DeleteList')
self.all_lists.remove(li... | python | def remove(self, list):
"""
Removes a list from the site.
"""
xml = SP.DeleteList(SP.listName(list.id))
self.opener.post_soap(LIST_WEBSERVICE, xml,
soapaction='http://schemas.microsoft.com/sharepoint/soap/DeleteList')
self.all_lists.remove(li... | [
"def",
"remove",
"(",
"self",
",",
"list",
")",
":",
"xml",
"=",
"SP",
".",
"DeleteList",
"(",
"SP",
".",
"listName",
"(",
"list",
".",
"id",
")",
")",
"self",
".",
"opener",
".",
"post_soap",
"(",
"LIST_WEBSERVICE",
",",
"xml",
",",
"soapaction",
... | Removes a list from the site. | [
"Removes",
"a",
"list",
"from",
"the",
"site",
"."
] | f1a1e19189d78115fcfc25850d27319e34d7e699 | https://github.com/ox-it/python-sharepoint/blob/f1a1e19189d78115fcfc25850d27319e34d7e699/sharepoint/lists/__init__.py#L44-L51 | train | 58,886 |
ox-it/python-sharepoint | sharepoint/lists/__init__.py | SharePointLists.create | def create(self, name, description='', template=100):
"""
Creates a new list in the site.
"""
try:
template = int(template)
except ValueError:
template = LIST_TEMPLATES[template]
if name in self:
raise ValueError("List already exists: '... | python | def create(self, name, description='', template=100):
"""
Creates a new list in the site.
"""
try:
template = int(template)
except ValueError:
template = LIST_TEMPLATES[template]
if name in self:
raise ValueError("List already exists: '... | [
"def",
"create",
"(",
"self",
",",
"name",
",",
"description",
"=",
"''",
",",
"template",
"=",
"100",
")",
":",
"try",
":",
"template",
"=",
"int",
"(",
"template",
")",
"except",
"ValueError",
":",
"template",
"=",
"LIST_TEMPLATES",
"[",
"template",
... | Creates a new list in the site. | [
"Creates",
"a",
"new",
"list",
"in",
"the",
"site",
"."
] | f1a1e19189d78115fcfc25850d27319e34d7e699 | https://github.com/ox-it/python-sharepoint/blob/f1a1e19189d78115fcfc25850d27319e34d7e699/sharepoint/lists/__init__.py#L53-L71 | train | 58,887 |
ox-it/python-sharepoint | sharepoint/lists/__init__.py | SharePointList.Row | def Row(self):
"""
The class for a row in this list.
"""
if not hasattr(self, '_row_class'):
attrs = {'fields': self.fields, 'list': self, 'opener': self.opener}
for field in self.fields.values():
attrs[field.name] = field.descriptor
se... | python | def Row(self):
"""
The class for a row in this list.
"""
if not hasattr(self, '_row_class'):
attrs = {'fields': self.fields, 'list': self, 'opener': self.opener}
for field in self.fields.values():
attrs[field.name] = field.descriptor
se... | [
"def",
"Row",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'_row_class'",
")",
":",
"attrs",
"=",
"{",
"'fields'",
":",
"self",
".",
"fields",
",",
"'list'",
":",
"self",
",",
"'opener'",
":",
"self",
".",
"opener",
"}",
"for",... | The class for a row in this list. | [
"The",
"class",
"for",
"a",
"row",
"in",
"this",
"list",
"."
] | f1a1e19189d78115fcfc25850d27319e34d7e699 | https://github.com/ox-it/python-sharepoint/blob/f1a1e19189d78115fcfc25850d27319e34d7e699/sharepoint/lists/__init__.py#L201-L210 | train | 58,888 |
ox-it/python-sharepoint | sharepoint/lists/__init__.py | SharePointList.append | def append(self, row):
"""
Appends a row to the list. Takes a dictionary, returns a row.
"""
if isinstance(row, dict):
row = self.Row(row)
elif isinstance(row, self.Row):
pass
elif isinstance(row, SharePointListRow):
raise TypeError("ro... | python | def append(self, row):
"""
Appends a row to the list. Takes a dictionary, returns a row.
"""
if isinstance(row, dict):
row = self.Row(row)
elif isinstance(row, self.Row):
pass
elif isinstance(row, SharePointListRow):
raise TypeError("ro... | [
"def",
"append",
"(",
"self",
",",
"row",
")",
":",
"if",
"isinstance",
"(",
"row",
",",
"dict",
")",
":",
"row",
"=",
"self",
".",
"Row",
"(",
"row",
")",
"elif",
"isinstance",
"(",
"row",
",",
"self",
".",
"Row",
")",
":",
"pass",
"elif",
"is... | Appends a row to the list. Takes a dictionary, returns a row. | [
"Appends",
"a",
"row",
"to",
"the",
"list",
".",
"Takes",
"a",
"dictionary",
"returns",
"a",
"row",
"."
] | f1a1e19189d78115fcfc25850d27319e34d7e699 | https://github.com/ox-it/python-sharepoint/blob/f1a1e19189d78115fcfc25850d27319e34d7e699/sharepoint/lists/__init__.py#L237-L251 | train | 58,889 |
ox-it/python-sharepoint | sharepoint/lists/__init__.py | SharePointList.remove | def remove(self, row):
"""
Removes the row from the list.
"""
self._rows.remove(row)
self._deleted_rows.add(row) | python | def remove(self, row):
"""
Removes the row from the list.
"""
self._rows.remove(row)
self._deleted_rows.add(row) | [
"def",
"remove",
"(",
"self",
",",
"row",
")",
":",
"self",
".",
"_rows",
".",
"remove",
"(",
"row",
")",
"self",
".",
"_deleted_rows",
".",
"add",
"(",
"row",
")"
] | Removes the row from the list. | [
"Removes",
"the",
"row",
"from",
"the",
"list",
"."
] | f1a1e19189d78115fcfc25850d27319e34d7e699 | https://github.com/ox-it/python-sharepoint/blob/f1a1e19189d78115fcfc25850d27319e34d7e699/sharepoint/lists/__init__.py#L257-L262 | train | 58,890 |
ox-it/python-sharepoint | sharepoint/lists/__init__.py | SharePointList.save | def save(self):
"""
Updates the list with changes.
"""
# Based on the documentation at
# http://msdn.microsoft.com/en-us/library/lists.lists.updatelistitems%28v=office.12%29.aspx
# Note, this ends up un-namespaced. SharePoint doesn't care about
# namespaces on th... | python | def save(self):
"""
Updates the list with changes.
"""
# Based on the documentation at
# http://msdn.microsoft.com/en-us/library/lists.lists.updatelistitems%28v=office.12%29.aspx
# Note, this ends up un-namespaced. SharePoint doesn't care about
# namespaces on th... | [
"def",
"save",
"(",
"self",
")",
":",
"# Based on the documentation at",
"# http://msdn.microsoft.com/en-us/library/lists.lists.updatelistitems%28v=office.12%29.aspx",
"# Note, this ends up un-namespaced. SharePoint doesn't care about",
"# namespaces on this XML node, and will bork if any of these... | Updates the list with changes. | [
"Updates",
"the",
"list",
"with",
"changes",
"."
] | f1a1e19189d78115fcfc25850d27319e34d7e699 | https://github.com/ox-it/python-sharepoint/blob/f1a1e19189d78115fcfc25850d27319e34d7e699/sharepoint/lists/__init__.py#L270-L331 | train | 58,891 |
ox-it/python-sharepoint | sharepoint/lists/__init__.py | SharePointListRow.get_batch_method | def get_batch_method(self):
"""
Returns a change batch for SharePoint's UpdateListItems operation.
"""
if not self._changed:
return None
batch_method = E.Method(Cmd='Update' if self.id else 'New')
batch_method.append(E.Field(text_type(self.id) if self.id else... | python | def get_batch_method(self):
"""
Returns a change batch for SharePoint's UpdateListItems operation.
"""
if not self._changed:
return None
batch_method = E.Method(Cmd='Update' if self.id else 'New')
batch_method.append(E.Field(text_type(self.id) if self.id else... | [
"def",
"get_batch_method",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_changed",
":",
"return",
"None",
"batch_method",
"=",
"E",
".",
"Method",
"(",
"Cmd",
"=",
"'Update'",
"if",
"self",
".",
"id",
"else",
"'New'",
")",
"batch_method",
".",
"ap... | Returns a change batch for SharePoint's UpdateListItems operation. | [
"Returns",
"a",
"change",
"batch",
"for",
"SharePoint",
"s",
"UpdateListItems",
"operation",
"."
] | f1a1e19189d78115fcfc25850d27319e34d7e699 | https://github.com/ox-it/python-sharepoint/blob/f1a1e19189d78115fcfc25850d27319e34d7e699/sharepoint/lists/__init__.py#L374-L388 | train | 58,892 |
maxcutler/python-wordpress-xmlrpc | wordpress_xmlrpc/fieldmaps.py | FieldMap.convert_to_python | def convert_to_python(self, xmlrpc=None):
"""
Extracts a value for the field from an XML-RPC response.
"""
if xmlrpc:
return xmlrpc.get(self.name, self.default)
elif self.default:
return self.default
else:
return None | python | def convert_to_python(self, xmlrpc=None):
"""
Extracts a value for the field from an XML-RPC response.
"""
if xmlrpc:
return xmlrpc.get(self.name, self.default)
elif self.default:
return self.default
else:
return None | [
"def",
"convert_to_python",
"(",
"self",
",",
"xmlrpc",
"=",
"None",
")",
":",
"if",
"xmlrpc",
":",
"return",
"xmlrpc",
".",
"get",
"(",
"self",
".",
"name",
",",
"self",
".",
"default",
")",
"elif",
"self",
".",
"default",
":",
"return",
"self",
"."... | Extracts a value for the field from an XML-RPC response. | [
"Extracts",
"a",
"value",
"for",
"the",
"field",
"from",
"an",
"XML",
"-",
"RPC",
"response",
"."
] | 7ac0a6e9934fdbf02c2250932e0c026cf530d400 | https://github.com/maxcutler/python-wordpress-xmlrpc/blob/7ac0a6e9934fdbf02c2250932e0c026cf530d400/wordpress_xmlrpc/fieldmaps.py#L24-L33 | train | 58,893 |
maxcutler/python-wordpress-xmlrpc | wordpress_xmlrpc/fieldmaps.py | FieldMap.get_outputs | def get_outputs(self, input_value):
"""
Generate a set of output values for a given input.
"""
output_value = self.convert_to_xmlrpc(input_value)
output = {}
for name in self.output_names:
output[name] = output_value
return output | python | def get_outputs(self, input_value):
"""
Generate a set of output values for a given input.
"""
output_value = self.convert_to_xmlrpc(input_value)
output = {}
for name in self.output_names:
output[name] = output_value
return output | [
"def",
"get_outputs",
"(",
"self",
",",
"input_value",
")",
":",
"output_value",
"=",
"self",
".",
"convert_to_xmlrpc",
"(",
"input_value",
")",
"output",
"=",
"{",
"}",
"for",
"name",
"in",
"self",
".",
"output_names",
":",
"output",
"[",
"name",
"]",
"... | Generate a set of output values for a given input. | [
"Generate",
"a",
"set",
"of",
"output",
"values",
"for",
"a",
"given",
"input",
"."
] | 7ac0a6e9934fdbf02c2250932e0c026cf530d400 | https://github.com/maxcutler/python-wordpress-xmlrpc/blob/7ac0a6e9934fdbf02c2250932e0c026cf530d400/wordpress_xmlrpc/fieldmaps.py#L44-L54 | train | 58,894 |
maxcutler/python-wordpress-xmlrpc | wordpress_xmlrpc/wordpress.py | WordPressBase.struct | def struct(self):
"""
XML-RPC-friendly representation of the current object state
"""
data = {}
for var, fmap in self._def.items():
if hasattr(self, var):
data.update(fmap.get_outputs(getattr(self, var)))
return data | python | def struct(self):
"""
XML-RPC-friendly representation of the current object state
"""
data = {}
for var, fmap in self._def.items():
if hasattr(self, var):
data.update(fmap.get_outputs(getattr(self, var)))
return data | [
"def",
"struct",
"(",
"self",
")",
":",
"data",
"=",
"{",
"}",
"for",
"var",
",",
"fmap",
"in",
"self",
".",
"_def",
".",
"items",
"(",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"var",
")",
":",
"data",
".",
"update",
"(",
"fmap",
".",
"ge... | XML-RPC-friendly representation of the current object state | [
"XML",
"-",
"RPC",
"-",
"friendly",
"representation",
"of",
"the",
"current",
"object",
"state"
] | 7ac0a6e9934fdbf02c2250932e0c026cf530d400 | https://github.com/maxcutler/python-wordpress-xmlrpc/blob/7ac0a6e9934fdbf02c2250932e0c026cf530d400/wordpress_xmlrpc/wordpress.py#L40-L48 | train | 58,895 |
maxcutler/python-wordpress-xmlrpc | wordpress_xmlrpc/base.py | XmlrpcMethod.get_args | def get_args(self, client):
"""
Builds final set of XML-RPC method arguments based on
the method's arguments, any default arguments, and their
defined respective ordering.
"""
default_args = self.default_args(client)
if self.method_args or self.optional_a... | python | def get_args(self, client):
"""
Builds final set of XML-RPC method arguments based on
the method's arguments, any default arguments, and their
defined respective ordering.
"""
default_args = self.default_args(client)
if self.method_args or self.optional_a... | [
"def",
"get_args",
"(",
"self",
",",
"client",
")",
":",
"default_args",
"=",
"self",
".",
"default_args",
"(",
"client",
")",
"if",
"self",
".",
"method_args",
"or",
"self",
".",
"optional_args",
":",
"optional_args",
"=",
"getattr",
"(",
"self",
",",
"... | Builds final set of XML-RPC method arguments based on
the method's arguments, any default arguments, and their
defined respective ordering. | [
"Builds",
"final",
"set",
"of",
"XML",
"-",
"RPC",
"method",
"arguments",
"based",
"on",
"the",
"method",
"s",
"arguments",
"any",
"default",
"arguments",
"and",
"their",
"defined",
"respective",
"ordering",
"."
] | 7ac0a6e9934fdbf02c2250932e0c026cf530d400 | https://github.com/maxcutler/python-wordpress-xmlrpc/blob/7ac0a6e9934fdbf02c2250932e0c026cf530d400/wordpress_xmlrpc/base.py#L95-L117 | train | 58,896 |
maxcutler/python-wordpress-xmlrpc | wordpress_xmlrpc/base.py | XmlrpcMethod.process_result | def process_result(self, raw_result):
"""
Performs actions on the raw result from the XML-RPC response.
If a `results_class` is defined, the response will be converted
into one or more object instances of that class.
"""
if self.results_class and raw_result:
... | python | def process_result(self, raw_result):
"""
Performs actions on the raw result from the XML-RPC response.
If a `results_class` is defined, the response will be converted
into one or more object instances of that class.
"""
if self.results_class and raw_result:
... | [
"def",
"process_result",
"(",
"self",
",",
"raw_result",
")",
":",
"if",
"self",
".",
"results_class",
"and",
"raw_result",
":",
"if",
"isinstance",
"(",
"raw_result",
",",
"dict_type",
")",
":",
"return",
"self",
".",
"results_class",
"(",
"raw_result",
")"... | Performs actions on the raw result from the XML-RPC response.
If a `results_class` is defined, the response will be converted
into one or more object instances of that class. | [
"Performs",
"actions",
"on",
"the",
"raw",
"result",
"from",
"the",
"XML",
"-",
"RPC",
"response",
".",
"If",
"a",
"results_class",
"is",
"defined",
"the",
"response",
"will",
"be",
"converted",
"into",
"one",
"or",
"more",
"object",
"instances",
"of",
"th... | 7ac0a6e9934fdbf02c2250932e0c026cf530d400 | https://github.com/maxcutler/python-wordpress-xmlrpc/blob/7ac0a6e9934fdbf02c2250932e0c026cf530d400/wordpress_xmlrpc/base.py#L119-L132 | train | 58,897 |
vladimarius/pyap | pyap/parser.py | AddressParser.parse | def parse(self, text):
'''Returns a list of addresses found in text
together with parsed address parts
'''
results = []
if isinstance(text, str):
if six.PY2:
text = unicode(text, 'utf-8')
self.clean_text = self._normalize_string(text)
... | python | def parse(self, text):
'''Returns a list of addresses found in text
together with parsed address parts
'''
results = []
if isinstance(text, str):
if six.PY2:
text = unicode(text, 'utf-8')
self.clean_text = self._normalize_string(text)
... | [
"def",
"parse",
"(",
"self",
",",
"text",
")",
":",
"results",
"=",
"[",
"]",
"if",
"isinstance",
"(",
"text",
",",
"str",
")",
":",
"if",
"six",
".",
"PY2",
":",
"text",
"=",
"unicode",
"(",
"text",
",",
"'utf-8'",
")",
"self",
".",
"clean_text"... | Returns a list of addresses found in text
together with parsed address parts | [
"Returns",
"a",
"list",
"of",
"addresses",
"found",
"in",
"text",
"together",
"with",
"parsed",
"address",
"parts"
] | 7896b5293982a30c1443e0c81c1ca32eeb8db15c | https://github.com/vladimarius/pyap/blob/7896b5293982a30c1443e0c81c1ca32eeb8db15c/pyap/parser.py#L50-L66 | train | 58,898 |
vladimarius/pyap | pyap/parser.py | AddressParser._parse_address | def _parse_address(self, address_string):
'''Parses address into parts'''
match = utils.match(self.rules, address_string, flags=re.VERBOSE | re.U)
if match:
match_as_dict = match.groupdict()
match_as_dict.update({'country_id': self.country})
# combine results
... | python | def _parse_address(self, address_string):
'''Parses address into parts'''
match = utils.match(self.rules, address_string, flags=re.VERBOSE | re.U)
if match:
match_as_dict = match.groupdict()
match_as_dict.update({'country_id': self.country})
# combine results
... | [
"def",
"_parse_address",
"(",
"self",
",",
"address_string",
")",
":",
"match",
"=",
"utils",
".",
"match",
"(",
"self",
".",
"rules",
",",
"address_string",
",",
"flags",
"=",
"re",
".",
"VERBOSE",
"|",
"re",
".",
"U",
")",
"if",
"match",
":",
"matc... | Parses address into parts | [
"Parses",
"address",
"into",
"parts"
] | 7896b5293982a30c1443e0c81c1ca32eeb8db15c | https://github.com/vladimarius/pyap/blob/7896b5293982a30c1443e0c81c1ca32eeb8db15c/pyap/parser.py#L68-L79 | train | 58,899 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.