repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
hubo1016/vlcp | vlcp/config/config.py | Manager.savetostr | def savetostr(self, sortkey = True):
"""
Save configurations to a single string
"""
return ''.join(k + '=' + repr(v) + '\n' for k,v in self.config_items(sortkey)) | python | def savetostr(self, sortkey = True):
"""
Save configurations to a single string
"""
return ''.join(k + '=' + repr(v) + '\n' for k,v in self.config_items(sortkey)) | [
"def",
"savetostr",
"(",
"self",
",",
"sortkey",
"=",
"True",
")",
":",
"return",
"''",
".",
"join",
"(",
"k",
"+",
"'='",
"+",
"repr",
"(",
"v",
")",
"+",
"'\\n'",
"for",
"k",
",",
"v",
"in",
"self",
".",
"config_items",
"(",
"sortkey",
")",
"... | Save configurations to a single string | [
"Save",
"configurations",
"to",
"a",
"single",
"string"
] | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/config/config.py#L276-L280 | train |
hubo1016/vlcp | vlcp/config/config.py | Manager.savetofile | def savetofile(self, filelike, sortkey = True):
"""
Save configurations to a file-like object which supports `writelines`
"""
filelike.writelines(k + '=' + repr(v) + '\n' for k,v in self.config_items(sortkey)) | python | def savetofile(self, filelike, sortkey = True):
"""
Save configurations to a file-like object which supports `writelines`
"""
filelike.writelines(k + '=' + repr(v) + '\n' for k,v in self.config_items(sortkey)) | [
"def",
"savetofile",
"(",
"self",
",",
"filelike",
",",
"sortkey",
"=",
"True",
")",
":",
"filelike",
".",
"writelines",
"(",
"k",
"+",
"'='",
"+",
"repr",
"(",
"v",
")",
"+",
"'\\n'",
"for",
"k",
",",
"v",
"in",
"self",
".",
"config_items",
"(",
... | Save configurations to a file-like object which supports `writelines` | [
"Save",
"configurations",
"to",
"a",
"file",
"-",
"like",
"object",
"which",
"supports",
"writelines"
] | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/config/config.py#L281-L285 | train |
hubo1016/vlcp | vlcp/config/config.py | Manager.saveto | def saveto(self, path, sortkey = True):
"""
Save configurations to path
"""
with open(path, 'w') as f:
self.savetofile(f, sortkey) | python | def saveto(self, path, sortkey = True):
"""
Save configurations to path
"""
with open(path, 'w') as f:
self.savetofile(f, sortkey) | [
"def",
"saveto",
"(",
"self",
",",
"path",
",",
"sortkey",
"=",
"True",
")",
":",
"with",
"open",
"(",
"path",
",",
"'w'",
")",
"as",
"f",
":",
"self",
".",
"savetofile",
"(",
"f",
",",
"sortkey",
")"
] | Save configurations to path | [
"Save",
"configurations",
"to",
"path"
] | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/config/config.py#L286-L291 | train |
hubo1016/vlcp | vlcp/config/config.py | Configurable.getConfigurableParent | def getConfigurableParent(cls):
"""
Return the parent from which this class inherits configurations
"""
for p in cls.__bases__:
if isinstance(p, Configurable) and p is not Configurable:
return p
return None | python | def getConfigurableParent(cls):
"""
Return the parent from which this class inherits configurations
"""
for p in cls.__bases__:
if isinstance(p, Configurable) and p is not Configurable:
return p
return None | [
"def",
"getConfigurableParent",
"(",
"cls",
")",
":",
"for",
"p",
"in",
"cls",
".",
"__bases__",
":",
"if",
"isinstance",
"(",
"p",
",",
"Configurable",
")",
"and",
"p",
"is",
"not",
"Configurable",
":",
"return",
"p",
"return",
"None"
] | Return the parent from which this class inherits configurations | [
"Return",
"the",
"parent",
"from",
"which",
"this",
"class",
"inherits",
"configurations"
] | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/config/config.py#L346-L353 | train |
hubo1016/vlcp | vlcp/config/config.py | Configurable.getConfigRoot | def getConfigRoot(cls, create = False):
"""
Return the mapped configuration root node
"""
try:
return manager.gettree(getattr(cls, 'configkey'), create)
except AttributeError:
return None | python | def getConfigRoot(cls, create = False):
"""
Return the mapped configuration root node
"""
try:
return manager.gettree(getattr(cls, 'configkey'), create)
except AttributeError:
return None | [
"def",
"getConfigRoot",
"(",
"cls",
",",
"create",
"=",
"False",
")",
":",
"try",
":",
"return",
"manager",
".",
"gettree",
"(",
"getattr",
"(",
"cls",
",",
"'configkey'",
")",
",",
"create",
")",
"except",
"AttributeError",
":",
"return",
"None"
] | Return the mapped configuration root node | [
"Return",
"the",
"mapped",
"configuration",
"root",
"node"
] | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/config/config.py#L355-L362 | train |
hubo1016/vlcp | vlcp/config/config.py | Configurable.config_value_keys | def config_value_keys(self, sortkey = False):
"""
Return all mapped configuration keys for this object
"""
ret = set()
cls = type(self)
while True:
root = cls.getConfigRoot()
if root:
ret = ret.union(set(root.config_value_keys()))
... | python | def config_value_keys(self, sortkey = False):
"""
Return all mapped configuration keys for this object
"""
ret = set()
cls = type(self)
while True:
root = cls.getConfigRoot()
if root:
ret = ret.union(set(root.config_value_keys()))
... | [
"def",
"config_value_keys",
"(",
"self",
",",
"sortkey",
"=",
"False",
")",
":",
"ret",
"=",
"set",
"(",
")",
"cls",
"=",
"type",
"(",
"self",
")",
"while",
"True",
":",
"root",
"=",
"cls",
".",
"getConfigRoot",
"(",
")",
"if",
"root",
":",
"ret",
... | Return all mapped configuration keys for this object | [
"Return",
"all",
"mapped",
"configuration",
"keys",
"for",
"this",
"object"
] | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/config/config.py#L363-L383 | train |
hubo1016/vlcp | vlcp/config/config.py | Configurable.config_value_items | def config_value_items(self, sortkey = False):
"""
Return `(key, value)` tuples for all mapped configurations for this object
"""
return ((k, getattr(self, k)) for k in self.config_value_keys(sortkey)) | python | def config_value_items(self, sortkey = False):
"""
Return `(key, value)` tuples for all mapped configurations for this object
"""
return ((k, getattr(self, k)) for k in self.config_value_keys(sortkey)) | [
"def",
"config_value_items",
"(",
"self",
",",
"sortkey",
"=",
"False",
")",
":",
"return",
"(",
"(",
"k",
",",
"getattr",
"(",
"self",
",",
"k",
")",
")",
"for",
"k",
"in",
"self",
".",
"config_value_keys",
"(",
"sortkey",
")",
")"
] | Return `(key, value)` tuples for all mapped configurations for this object | [
"Return",
"(",
"key",
"value",
")",
"tuples",
"for",
"all",
"mapped",
"configurations",
"for",
"this",
"object"
] | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/config/config.py#L385-L389 | train |
hubo1016/vlcp | vlcp/server/server.py | main | def main(configpath = None, startup = None, daemon = False, pidfile = None, fork = None):
"""
The most simple way to start the VLCP framework
:param configpath: path of a configuration file to be loaded
:param startup: startup modules list. If None, `server.startup` in the configuration files
... | python | def main(configpath = None, startup = None, daemon = False, pidfile = None, fork = None):
"""
The most simple way to start the VLCP framework
:param configpath: path of a configuration file to be loaded
:param startup: startup modules list. If None, `server.startup` in the configuration files
... | [
"def",
"main",
"(",
"configpath",
"=",
"None",
",",
"startup",
"=",
"None",
",",
"daemon",
"=",
"False",
",",
"pidfile",
"=",
"None",
",",
"fork",
"=",
"None",
")",
":",
"if",
"configpath",
"is",
"not",
"None",
":",
"manager",
".",
"loadfrom",
"(",
... | The most simple way to start the VLCP framework
:param configpath: path of a configuration file to be loaded
:param startup: startup modules list. If None, `server.startup` in the configuration files
is used; if `server.startup` is not configured, any module defined or imported
... | [
"The",
"most",
"simple",
"way",
"to",
"start",
"the",
"VLCP",
"framework",
":",
"param",
"configpath",
":",
"path",
"of",
"a",
"configuration",
"file",
"to",
"be",
"loaded",
":",
"param",
"startup",
":",
"startup",
"modules",
"list",
".",
"If",
"None",
"... | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/server/server.py#L174-L312 | train |
hubo1016/vlcp | vlcp/service/sdn/vxlancast.py | VXLANUpdater.wait_for_group | async def wait_for_group(self, container, networkid, timeout = 120):
"""
Wait for a VXLAN group to be created
"""
if networkid in self._current_groups:
return self._current_groups[networkid]
else:
if not self._connection.connected:
raise Co... | python | async def wait_for_group(self, container, networkid, timeout = 120):
"""
Wait for a VXLAN group to be created
"""
if networkid in self._current_groups:
return self._current_groups[networkid]
else:
if not self._connection.connected:
raise Co... | [
"async",
"def",
"wait_for_group",
"(",
"self",
",",
"container",
",",
"networkid",
",",
"timeout",
"=",
"120",
")",
":",
"if",
"networkid",
"in",
"self",
".",
"_current_groups",
":",
"return",
"self",
".",
"_current_groups",
"[",
"networkid",
"]",
"else",
... | Wait for a VXLAN group to be created | [
"Wait",
"for",
"a",
"VXLAN",
"group",
"to",
"be",
"created"
] | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/service/sdn/vxlancast.py#L80-L97 | train |
hubo1016/vlcp | vlcp/event/stream.py | BaseStream.read | async def read(self, container = None, size = None):
"""
Coroutine method to read from the stream and return the data. Raises EOFError
when the stream end has been reached; raises IOError if there are other errors.
:param container: A routine container
:param si... | python | async def read(self, container = None, size = None):
"""
Coroutine method to read from the stream and return the data. Raises EOFError
when the stream end has been reached; raises IOError if there are other errors.
:param container: A routine container
:param si... | [
"async",
"def",
"read",
"(",
"self",
",",
"container",
"=",
"None",
",",
"size",
"=",
"None",
")",
":",
"ret",
"=",
"[",
"]",
"retsize",
"=",
"0",
"if",
"self",
".",
"eof",
":",
"raise",
"EOFError",
"if",
"self",
".",
"errored",
":",
"raise",
"IO... | Coroutine method to read from the stream and return the data. Raises EOFError
when the stream end has been reached; raises IOError if there are other errors.
:param container: A routine container
:param size: maximum read size, or unlimited if is None | [
"Coroutine",
"method",
"to",
"read",
"from",
"the",
"stream",
"and",
"return",
"the",
"data",
".",
"Raises",
"EOFError",
"when",
"the",
"stream",
"end",
"has",
"been",
"reached",
";",
"raises",
"IOError",
"if",
"there",
"are",
"other",
"errors",
".",
":",
... | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/event/stream.py#L58-L97 | train |
hubo1016/vlcp | vlcp/event/stream.py | BaseStream.readonce | def readonce(self, size = None):
"""
Read from current buffer. If current buffer is empty, returns an empty string. You can use `prepareRead`
to read the next chunk of data.
This is not a coroutine method.
"""
if self.eof:
raise EOFError
if se... | python | def readonce(self, size = None):
"""
Read from current buffer. If current buffer is empty, returns an empty string. You can use `prepareRead`
to read the next chunk of data.
This is not a coroutine method.
"""
if self.eof:
raise EOFError
if se... | [
"def",
"readonce",
"(",
"self",
",",
"size",
"=",
"None",
")",
":",
"if",
"self",
".",
"eof",
":",
"raise",
"EOFError",
"if",
"self",
".",
"errored",
":",
"raise",
"IOError",
"(",
"'Stream is broken before EOF'",
")",
"if",
"size",
"is",
"not",
"None",
... | Read from current buffer. If current buffer is empty, returns an empty string. You can use `prepareRead`
to read the next chunk of data.
This is not a coroutine method. | [
"Read",
"from",
"current",
"buffer",
".",
"If",
"current",
"buffer",
"is",
"empty",
"returns",
"an",
"empty",
"string",
".",
"You",
"can",
"use",
"prepareRead",
"to",
"read",
"the",
"next",
"chunk",
"of",
"data",
".",
"This",
"is",
"not",
"a",
"coroutine... | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/event/stream.py#L98-L118 | train |
hubo1016/vlcp | vlcp/event/stream.py | BaseStream.readline | async def readline(self, container = None, size = None):
"""
Coroutine method which reads the next line or until EOF or size exceeds
"""
ret = []
retsize = 0
if self.eof:
raise EOFError
if self.errored:
raise IOError('Stream is broken befor... | python | async def readline(self, container = None, size = None):
"""
Coroutine method which reads the next line or until EOF or size exceeds
"""
ret = []
retsize = 0
if self.eof:
raise EOFError
if self.errored:
raise IOError('Stream is broken befor... | [
"async",
"def",
"readline",
"(",
"self",
",",
"container",
"=",
"None",
",",
"size",
"=",
"None",
")",
":",
"ret",
"=",
"[",
"]",
"retsize",
"=",
"0",
"if",
"self",
".",
"eof",
":",
"raise",
"EOFError",
"if",
"self",
".",
"errored",
":",
"raise",
... | Coroutine method which reads the next line or until EOF or size exceeds | [
"Coroutine",
"method",
"which",
"reads",
"the",
"next",
"line",
"or",
"until",
"EOF",
"or",
"size",
"exceeds"
] | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/event/stream.py#L125-L177 | train |
hubo1016/vlcp | vlcp/event/stream.py | BaseStream.copy_to | async def copy_to(self, dest, container, buffering = True):
"""
Coroutine method to copy content from this stream to another stream.
"""
if self.eof:
await dest.write(u'' if self.isunicode else b'', True)
elif self.errored:
await dest.error(container)
... | python | async def copy_to(self, dest, container, buffering = True):
"""
Coroutine method to copy content from this stream to another stream.
"""
if self.eof:
await dest.write(u'' if self.isunicode else b'', True)
elif self.errored:
await dest.error(container)
... | [
"async",
"def",
"copy_to",
"(",
"self",
",",
"dest",
",",
"container",
",",
"buffering",
"=",
"True",
")",
":",
"if",
"self",
".",
"eof",
":",
"await",
"dest",
".",
"write",
"(",
"u''",
"if",
"self",
".",
"isunicode",
"else",
"b''",
",",
"True",
")... | Coroutine method to copy content from this stream to another stream. | [
"Coroutine",
"method",
"to",
"copy",
"content",
"from",
"this",
"stream",
"to",
"another",
"stream",
"."
] | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/event/stream.py#L178-L204 | train |
hubo1016/vlcp | vlcp/event/stream.py | BaseStream.write | async def write(self, data, container, eof = False, ignoreexception = False, buffering = True, split = True):
"""
Coroutine method to write data to this stream.
:param data: data to write
:param container: the routine container
:param eof: if True, this... | python | async def write(self, data, container, eof = False, ignoreexception = False, buffering = True, split = True):
"""
Coroutine method to write data to this stream.
:param data: data to write
:param container: the routine container
:param eof: if True, this... | [
"async",
"def",
"write",
"(",
"self",
",",
"data",
",",
"container",
",",
"eof",
"=",
"False",
",",
"ignoreexception",
"=",
"False",
",",
"buffering",
"=",
"True",
",",
"split",
"=",
"True",
")",
":",
"if",
"not",
"ignoreexception",
":",
"raise",
"IOEr... | Coroutine method to write data to this stream.
:param data: data to write
:param container: the routine container
:param eof: if True, this is the last chunk of this stream. The other end will receive an EOF after reading
this chunk.
... | [
"Coroutine",
"method",
"to",
"write",
"data",
"to",
"this",
"stream",
".",
":",
"param",
"data",
":",
"data",
"to",
"write",
":",
"param",
"container",
":",
"the",
"routine",
"container",
":",
"param",
"eof",
":",
"if",
"True",
"this",
"is",
"the",
"la... | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/event/stream.py#L208-L228 | train |
hubo1016/vlcp | vlcp/event/matchtree.py | MatchTree.subtree | def subtree(self, matcher, create = False):
'''
Find a subtree from a matcher
:param matcher: the matcher to locate the subtree. If None, return the root of the tree.
:param create: if True, the subtree is created if not exists; otherwise return None if not exists
... | python | def subtree(self, matcher, create = False):
'''
Find a subtree from a matcher
:param matcher: the matcher to locate the subtree. If None, return the root of the tree.
:param create: if True, the subtree is created if not exists; otherwise return None if not exists
... | [
"def",
"subtree",
"(",
"self",
",",
"matcher",
",",
"create",
"=",
"False",
")",
":",
"if",
"matcher",
"is",
"None",
":",
"return",
"self",
"current",
"=",
"self",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"depth",
",",
"len",
"(",
"matcher",
".... | Find a subtree from a matcher
:param matcher: the matcher to locate the subtree. If None, return the root of the tree.
:param create: if True, the subtree is created if not exists; otherwise return None if not exists | [
"Find",
"a",
"subtree",
"from",
"a",
"matcher",
":",
"param",
"matcher",
":",
"the",
"matcher",
"to",
"locate",
"the",
"subtree",
".",
"If",
"None",
"return",
"the",
"root",
"of",
"the",
"tree",
".",
":",
"param",
"create",
":",
"if",
"True",
"the",
... | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/event/matchtree.py#L29-L66 | train |
hubo1016/vlcp | vlcp/event/matchtree.py | MatchTree.insert | def insert(self, matcher, obj):
'''
Insert a new matcher
:param matcher: an EventMatcher
:param obj: object to return
'''
current = self.subtree(matcher, True)
#current.matchers[(obj, matcher)] = None
if current._use_dict:
cur... | python | def insert(self, matcher, obj):
'''
Insert a new matcher
:param matcher: an EventMatcher
:param obj: object to return
'''
current = self.subtree(matcher, True)
#current.matchers[(obj, matcher)] = None
if current._use_dict:
cur... | [
"def",
"insert",
"(",
"self",
",",
"matcher",
",",
"obj",
")",
":",
"current",
"=",
"self",
".",
"subtree",
"(",
"matcher",
",",
"True",
")",
"#current.matchers[(obj, matcher)] = None",
"if",
"current",
".",
"_use_dict",
":",
"current",
".",
"matchers_dict",
... | Insert a new matcher
:param matcher: an EventMatcher
:param obj: object to return | [
"Insert",
"a",
"new",
"matcher",
":",
"param",
"matcher",
":",
"an",
"EventMatcher",
":",
"param",
"obj",
":",
"object",
"to",
"return"
] | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/event/matchtree.py#L67-L81 | train |
hubo1016/vlcp | vlcp/event/matchtree.py | MatchTree.remove | def remove(self, matcher, obj):
'''
Remove the matcher
:param matcher: an EventMatcher
:param obj: the object to remove
'''
current = self.subtree(matcher, False)
if current is None:
return
# Assume that this pair only appears... | python | def remove(self, matcher, obj):
'''
Remove the matcher
:param matcher: an EventMatcher
:param obj: the object to remove
'''
current = self.subtree(matcher, False)
if current is None:
return
# Assume that this pair only appears... | [
"def",
"remove",
"(",
"self",
",",
"matcher",
",",
"obj",
")",
":",
"current",
"=",
"self",
".",
"subtree",
"(",
"matcher",
",",
"False",
")",
"if",
"current",
"is",
"None",
":",
"return",
"# Assume that this pair only appears once",
"if",
"current",
".",
... | Remove the matcher
:param matcher: an EventMatcher
:param obj: the object to remove | [
"Remove",
"the",
"matcher",
":",
"param",
"matcher",
":",
"an",
"EventMatcher",
":",
"param",
"obj",
":",
"the",
"object",
"to",
"remove"
] | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/event/matchtree.py#L82-L124 | train |
hubo1016/vlcp | vlcp/event/matchtree.py | MatchTree.matchesWithMatchers | def matchesWithMatchers(self, event):
'''
Return all matches for this event. The first matcher is also returned for each matched object.
:param event: an input event
'''
ret = []
self._matches(event, set(), ret)
return tuple(ret) | python | def matchesWithMatchers(self, event):
'''
Return all matches for this event. The first matcher is also returned for each matched object.
:param event: an input event
'''
ret = []
self._matches(event, set(), ret)
return tuple(ret) | [
"def",
"matchesWithMatchers",
"(",
"self",
",",
"event",
")",
":",
"ret",
"=",
"[",
"]",
"self",
".",
"_matches",
"(",
"event",
",",
"set",
"(",
")",
",",
"ret",
")",
"return",
"tuple",
"(",
"ret",
")"
] | Return all matches for this event. The first matcher is also returned for each matched object.
:param event: an input event | [
"Return",
"all",
"matches",
"for",
"this",
"event",
".",
"The",
"first",
"matcher",
"is",
"also",
"returned",
"for",
"each",
"matched",
"object",
".",
":",
"param",
"event",
":",
"an",
"input",
"event"
] | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/event/matchtree.py#L125-L133 | train |
hubo1016/vlcp | vlcp/event/matchtree.py | MatchTree.matches | def matches(self, event):
'''
Return all matches for this event. The first matcher is also returned for each matched object.
:param event: an input event
'''
ret = []
self._matches(event, set(), ret)
return tuple(r[0] for r in ret) | python | def matches(self, event):
'''
Return all matches for this event. The first matcher is also returned for each matched object.
:param event: an input event
'''
ret = []
self._matches(event, set(), ret)
return tuple(r[0] for r in ret) | [
"def",
"matches",
"(",
"self",
",",
"event",
")",
":",
"ret",
"=",
"[",
"]",
"self",
".",
"_matches",
"(",
"event",
",",
"set",
"(",
")",
",",
"ret",
")",
"return",
"tuple",
"(",
"r",
"[",
"0",
"]",
"for",
"r",
"in",
"ret",
")"
] | Return all matches for this event. The first matcher is also returned for each matched object.
:param event: an input event | [
"Return",
"all",
"matches",
"for",
"this",
"event",
".",
"The",
"first",
"matcher",
"is",
"also",
"returned",
"for",
"each",
"matched",
"object",
".",
":",
"param",
"event",
":",
"an",
"input",
"event"
] | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/event/matchtree.py#L134-L142 | train |
hubo1016/vlcp | vlcp/event/matchtree.py | MatchTree.matchfirst | def matchfirst(self, event):
'''
Return first match for this event
:param event: an input event
'''
# 1. matches(self.index[ind], event)
# 2. matches(self.any, event)
# 3. self.matches
if self.depth < len(event.indices):
ind = event.in... | python | def matchfirst(self, event):
'''
Return first match for this event
:param event: an input event
'''
# 1. matches(self.index[ind], event)
# 2. matches(self.any, event)
# 3. self.matches
if self.depth < len(event.indices):
ind = event.in... | [
"def",
"matchfirst",
"(",
"self",
",",
"event",
")",
":",
"# 1. matches(self.index[ind], event)",
"# 2. matches(self.any, event)",
"# 3. self.matches",
"if",
"self",
".",
"depth",
"<",
"len",
"(",
"event",
".",
"indices",
")",
":",
"ind",
"=",
"event",
".",
"ind... | Return first match for this event
:param event: an input event | [
"Return",
"first",
"match",
"for",
"this",
"event",
":",
"param",
"event",
":",
"an",
"input",
"event"
] | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/event/matchtree.py#L166-L192 | train |
hubo1016/vlcp | vlcp/event/matchtree.py | EventTree.subtree | def subtree(self, event, create = False):
'''
Find a subtree from an event
'''
current = self
for i in range(self.depth, len(event.indices)):
if not hasattr(current, 'index'):
return current
ind = event.indices[i]
if create:
... | python | def subtree(self, event, create = False):
'''
Find a subtree from an event
'''
current = self
for i in range(self.depth, len(event.indices)):
if not hasattr(current, 'index'):
return current
ind = event.indices[i]
if create:
... | [
"def",
"subtree",
"(",
"self",
",",
"event",
",",
"create",
"=",
"False",
")",
":",
"current",
"=",
"self",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"depth",
",",
"len",
"(",
"event",
".",
"indices",
")",
")",
":",
"if",
"not",
"hasattr",
"("... | Find a subtree from an event | [
"Find",
"a",
"subtree",
"from",
"an",
"event"
] | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/event/matchtree.py#L242-L258 | train |
hubo1016/vlcp | vlcp/utils/vxlandiscover.py | lognet_vxlan_walker | def lognet_vxlan_walker(prepush = True):
"""
Return a walker function to retrieve necessary information from ObjectDB
"""
def _walk_lognet(key, value, walk, save):
save(key)
if value is None:
return
try:
phynet = walk(value.physicalnetwork.getkey())
... | python | def lognet_vxlan_walker(prepush = True):
"""
Return a walker function to retrieve necessary information from ObjectDB
"""
def _walk_lognet(key, value, walk, save):
save(key)
if value is None:
return
try:
phynet = walk(value.physicalnetwork.getkey())
... | [
"def",
"lognet_vxlan_walker",
"(",
"prepush",
"=",
"True",
")",
":",
"def",
"_walk_lognet",
"(",
"key",
",",
"value",
",",
"walk",
",",
"save",
")",
":",
"save",
"(",
"key",
")",
"if",
"value",
"is",
"None",
":",
"return",
"try",
":",
"phynet",
"=",
... | Return a walker function to retrieve necessary information from ObjectDB | [
"Return",
"a",
"walker",
"function",
"to",
"retrieve",
"necessary",
"information",
"from",
"ObjectDB"
] | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/utils/vxlandiscover.py#L15-L59 | train |
hubo1016/vlcp | vlcp/utils/vxlandiscover.py | update_vxlaninfo | async def update_vxlaninfo(container, network_ip_dict, created_ports, removed_ports,
ovsdb_vhost, system_id, bridge,
allowedmigrationtime, refreshinterval):
'''
Do an ObjectDB transact to update all VXLAN informations
:param container: Routine container
:param n... | python | async def update_vxlaninfo(container, network_ip_dict, created_ports, removed_ports,
ovsdb_vhost, system_id, bridge,
allowedmigrationtime, refreshinterval):
'''
Do an ObjectDB transact to update all VXLAN informations
:param container: Routine container
:param n... | [
"async",
"def",
"update_vxlaninfo",
"(",
"container",
",",
"network_ip_dict",
",",
"created_ports",
",",
"removed_ports",
",",
"ovsdb_vhost",
",",
"system_id",
",",
"bridge",
",",
"allowedmigrationtime",
",",
"refreshinterval",
")",
":",
"network_list",
"=",
"list",... | Do an ObjectDB transact to update all VXLAN informations
:param container: Routine container
:param network_ip_dict: a {logicalnetwork_id: tunnel_ip} dictionary
:param created_ports: logical ports to be added, a {logicalport_id: tunnel_ip} dictionary
:param removed_ports: logical por... | [
"Do",
"an",
"ObjectDB",
"transact",
"to",
"update",
"all",
"VXLAN",
"informations",
":",
"param",
"container",
":",
"Routine",
"container",
":",
"param",
"network_ip_dict",
":",
"a",
"{",
"logicalnetwork_id",
":",
"tunnel_ip",
"}",
"dictionary",
":",
"param",
... | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/utils/vxlandiscover.py#L61-L148 | train |
hubo1016/vlcp | vlcp/utils/vxlandiscover.py | get_broadcast_ips | def get_broadcast_ips(vxlan_endpointset, local_ip, ovsdb_vhost, system_id, bridge):
'''
Get all IP addresses that are not local
:param vxlan_endpointset: a VXLANEndpointSet object
:param local_ips: list of local IP address to exclude with
:param ovsdb_vhost: identifier, vhost
... | python | def get_broadcast_ips(vxlan_endpointset, local_ip, ovsdb_vhost, system_id, bridge):
'''
Get all IP addresses that are not local
:param vxlan_endpointset: a VXLANEndpointSet object
:param local_ips: list of local IP address to exclude with
:param ovsdb_vhost: identifier, vhost
... | [
"def",
"get_broadcast_ips",
"(",
"vxlan_endpointset",
",",
"local_ip",
",",
"ovsdb_vhost",
",",
"system_id",
",",
"bridge",
")",
":",
"localip_addr",
"=",
"_get_ip",
"(",
"local_ip",
")",
"allips",
"=",
"[",
"(",
"ip",
",",
"ipnum",
")",
"for",
"ip",
",",
... | Get all IP addresses that are not local
:param vxlan_endpointset: a VXLANEndpointSet object
:param local_ips: list of local IP address to exclude with
:param ovsdb_vhost: identifier, vhost
:param system_id: identifier, system-id
:param bridge: identifier, bridge name
... | [
"Get",
"all",
"IP",
"addresses",
"that",
"are",
"not",
"local",
":",
"param",
"vxlan_endpointset",
":",
"a",
"VXLANEndpointSet",
"object",
":",
"param",
"local_ips",
":",
"list",
"of",
"local",
"IP",
"address",
"to",
"exclude",
"with",
":",
"param",
"ovsdb_v... | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/utils/vxlandiscover.py#L157-L178 | train |
hubo1016/vlcp | vlcp/event/future.py | Future.result | def result(self):
'''
:return: None if the result is not ready, the result from set_result, or raise the exception
from set_exception. If the result can be None, it is not possible to tell if the result is
available; use done() to determine that.
'''
try... | python | def result(self):
'''
:return: None if the result is not ready, the result from set_result, or raise the exception
from set_exception. If the result can be None, it is not possible to tell if the result is
available; use done() to determine that.
'''
try... | [
"def",
"result",
"(",
"self",
")",
":",
"try",
":",
"r",
"=",
"getattr",
"(",
"self",
",",
"'_result'",
")",
"except",
"AttributeError",
":",
"return",
"None",
"else",
":",
"if",
"hasattr",
"(",
"self",
",",
"'_exception'",
")",
":",
"raise",
"self",
... | :return: None if the result is not ready, the result from set_result, or raise the exception
from set_exception. If the result can be None, it is not possible to tell if the result is
available; use done() to determine that. | [
":",
"return",
":",
"None",
"if",
"the",
"result",
"is",
"not",
"ready",
"the",
"result",
"from",
"set_result",
"or",
"raise",
"the",
"exception",
"from",
"set_exception",
".",
"If",
"the",
"result",
"can",
"be",
"None",
"it",
"is",
"not",
"possible",
"t... | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/event/future.py#L57-L71 | train |
hubo1016/vlcp | vlcp/event/future.py | Future.wait | async def wait(self, container = None):
'''
:param container: DEPRECATED container of current routine
:return: The result, or raise the exception from set_exception.
'''
if hasattr(self, '_result'):
if hasattr(self, '_exception'):
raise self._... | python | async def wait(self, container = None):
'''
:param container: DEPRECATED container of current routine
:return: The result, or raise the exception from set_exception.
'''
if hasattr(self, '_result'):
if hasattr(self, '_exception'):
raise self._... | [
"async",
"def",
"wait",
"(",
"self",
",",
"container",
"=",
"None",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"'_result'",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"'_exception'",
")",
":",
"raise",
"self",
".",
"_exception",
"else",
":",
"ret... | :param container: DEPRECATED container of current routine
:return: The result, or raise the exception from set_exception. | [
":",
"param",
"container",
":",
"DEPRECATED",
"container",
"of",
"current",
"routine",
":",
"return",
":",
"The",
"result",
"or",
"raise",
"the",
"exception",
"from",
"set_exception",
"."
] | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/event/future.py#L72-L88 | train |
hubo1016/vlcp | vlcp/event/future.py | Future.set_result | def set_result(self, result):
'''
Set the result to Future object, wake up all the waiters
:param result: result to set
'''
if hasattr(self, '_result'):
raise ValueError('Cannot set the result twice')
self._result = result
self._scheduler.emer... | python | def set_result(self, result):
'''
Set the result to Future object, wake up all the waiters
:param result: result to set
'''
if hasattr(self, '_result'):
raise ValueError('Cannot set the result twice')
self._result = result
self._scheduler.emer... | [
"def",
"set_result",
"(",
"self",
",",
"result",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"'_result'",
")",
":",
"raise",
"ValueError",
"(",
"'Cannot set the result twice'",
")",
"self",
".",
"_result",
"=",
"result",
"self",
".",
"_scheduler",
".",
"e... | Set the result to Future object, wake up all the waiters
:param result: result to set | [
"Set",
"the",
"result",
"to",
"Future",
"object",
"wake",
"up",
"all",
"the",
"waiters",
":",
"param",
"result",
":",
"result",
"to",
"set"
] | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/event/future.py#L89-L98 | train |
hubo1016/vlcp | vlcp/event/future.py | Future.set_exception | def set_exception(self, exception):
'''
Set an exception to Future object, wake up all the waiters
:param exception: exception to set
'''
if hasattr(self, '_result'):
raise ValueError('Cannot set the result twice')
self._result = None
self._ex... | python | def set_exception(self, exception):
'''
Set an exception to Future object, wake up all the waiters
:param exception: exception to set
'''
if hasattr(self, '_result'):
raise ValueError('Cannot set the result twice')
self._result = None
self._ex... | [
"def",
"set_exception",
"(",
"self",
",",
"exception",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"'_result'",
")",
":",
"raise",
"ValueError",
"(",
"'Cannot set the result twice'",
")",
"self",
".",
"_result",
"=",
"None",
"self",
".",
"_exception",
"=",
... | Set an exception to Future object, wake up all the waiters
:param exception: exception to set | [
"Set",
"an",
"exception",
"to",
"Future",
"object",
"wake",
"up",
"all",
"the",
"waiters",
":",
"param",
"exception",
":",
"exception",
"to",
"set"
] | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/event/future.py#L99-L109 | train |
hubo1016/vlcp | vlcp/event/future.py | Future.ensure_result | def ensure_result(self, supress_exception = False, defaultresult = None):
'''
Context manager to ensure returning the result
'''
try:
yield self
except Exception as exc:
if not self.done():
self.set_exception(exc)
if not supress... | python | def ensure_result(self, supress_exception = False, defaultresult = None):
'''
Context manager to ensure returning the result
'''
try:
yield self
except Exception as exc:
if not self.done():
self.set_exception(exc)
if not supress... | [
"def",
"ensure_result",
"(",
"self",
",",
"supress_exception",
"=",
"False",
",",
"defaultresult",
"=",
"None",
")",
":",
"try",
":",
"yield",
"self",
"except",
"Exception",
"as",
"exc",
":",
"if",
"not",
"self",
".",
"done",
"(",
")",
":",
"self",
"."... | Context manager to ensure returning the result | [
"Context",
"manager",
"to",
"ensure",
"returning",
"the",
"result"
] | 239055229ec93a99cc7e15208075724ccf543bd1 | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/event/future.py#L111-L128 | train |
pudo/datafreeze | datafreeze/app.py | freeze | def freeze(result, format='csv', filename='freeze.csv', fileobj=None,
prefix='.', mode='list', **kw):
"""
Perform a data export of a given result set. This is a very
flexible exporter, allowing for various output formats, metadata
assignment, and file name templating to dump each record (or a... | python | def freeze(result, format='csv', filename='freeze.csv', fileobj=None,
prefix='.', mode='list', **kw):
"""
Perform a data export of a given result set. This is a very
flexible exporter, allowing for various output formats, metadata
assignment, and file name templating to dump each record (or a... | [
"def",
"freeze",
"(",
"result",
",",
"format",
"=",
"'csv'",
",",
"filename",
"=",
"'freeze.csv'",
",",
"fileobj",
"=",
"None",
",",
"prefix",
"=",
"'.'",
",",
"mode",
"=",
"'list'",
",",
"*",
"*",
"kw",
")",
":",
"kw",
".",
"update",
"(",
"{",
"... | Perform a data export of a given result set. This is a very
flexible exporter, allowing for various output formats, metadata
assignment, and file name templating to dump each record (or a set
of records) into individual files.
::
result = db['person'].all()
dataset.freeze(result, forma... | [
"Perform",
"a",
"data",
"export",
"of",
"a",
"given",
"result",
"set",
".",
"This",
"is",
"a",
"very",
"flexible",
"exporter",
"allowing",
"for",
"various",
"output",
"formats",
"metadata",
"assignment",
"and",
"file",
"name",
"templating",
"to",
"dump",
"ea... | adbb19ad71a9a6cec1fbec650ee1e784c33eae8e | https://github.com/pudo/datafreeze/blob/adbb19ad71a9a6cec1fbec650ee1e784c33eae8e/datafreeze/app.py#L26-L124 | train |
rbit/pydtls | dtls/x509.py | decode_cert | def decode_cert(cert):
"""Convert an X509 certificate into a Python dictionary
This function converts the given X509 certificate into a Python dictionary
in the manner established by the Python standard library's ssl module.
"""
ret_dict = {}
subject_xname = X509_get_subject_name(cert.value)
... | python | def decode_cert(cert):
"""Convert an X509 certificate into a Python dictionary
This function converts the given X509 certificate into a Python dictionary
in the manner established by the Python standard library's ssl module.
"""
ret_dict = {}
subject_xname = X509_get_subject_name(cert.value)
... | [
"def",
"decode_cert",
"(",
"cert",
")",
":",
"ret_dict",
"=",
"{",
"}",
"subject_xname",
"=",
"X509_get_subject_name",
"(",
"cert",
".",
"value",
")",
"ret_dict",
"[",
"\"subject\"",
"]",
"=",
"_create_tuple_for_X509_NAME",
"(",
"subject_xname",
")",
"notAfter",... | Convert an X509 certificate into a Python dictionary
This function converts the given X509 certificate into a Python dictionary
in the manner established by the Python standard library's ssl module. | [
"Convert",
"an",
"X509",
"certificate",
"into",
"a",
"Python",
"dictionary"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/x509.py#L61-L79 | train |
rbit/pydtls | dtls/patch.py | _get_server_certificate | def _get_server_certificate(addr, ssl_version=PROTOCOL_SSLv23, ca_certs=None):
"""Retrieve a server certificate
Retrieve the certificate from the server at the specified address,
and return it as a PEM-encoded string.
If 'ca_certs' is specified, validate the server cert against it.
If 'ssl_version'... | python | def _get_server_certificate(addr, ssl_version=PROTOCOL_SSLv23, ca_certs=None):
"""Retrieve a server certificate
Retrieve the certificate from the server at the specified address,
and return it as a PEM-encoded string.
If 'ca_certs' is specified, validate the server cert against it.
If 'ssl_version'... | [
"def",
"_get_server_certificate",
"(",
"addr",
",",
"ssl_version",
"=",
"PROTOCOL_SSLv23",
",",
"ca_certs",
"=",
"None",
")",
":",
"if",
"ssl_version",
"not",
"in",
"(",
"PROTOCOL_DTLS",
",",
"PROTOCOL_DTLSv1",
",",
"PROTOCOL_DTLSv1_2",
")",
":",
"return",
"_ori... | Retrieve a server certificate
Retrieve the certificate from the server at the specified address,
and return it as a PEM-encoded string.
If 'ca_certs' is specified, validate the server cert against it.
If 'ssl_version' is specified, use it in the connection attempt. | [
"Retrieve",
"a",
"server",
"certificate"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/patch.py#L100-L123 | train |
rbit/pydtls | dtls/sslconnection.py | SSLContext.set_curves | def set_curves(self, curves):
u''' Set supported curves by name, nid or nist.
:param str | tuple(int) curves: Example "secp384r1:secp256k1", (715, 714), "P-384", "K-409:B-409:K-571", ...
:return: 1 for success and 0 for failure
'''
retVal = None
if isinstance(curves, str... | python | def set_curves(self, curves):
u''' Set supported curves by name, nid or nist.
:param str | tuple(int) curves: Example "secp384r1:secp256k1", (715, 714), "P-384", "K-409:B-409:K-571", ...
:return: 1 for success and 0 for failure
'''
retVal = None
if isinstance(curves, str... | [
"def",
"set_curves",
"(",
"self",
",",
"curves",
")",
":",
"retVal",
"=",
"None",
"if",
"isinstance",
"(",
"curves",
",",
"str",
")",
":",
"retVal",
"=",
"SSL_CTX_set1_curves_list",
"(",
"self",
".",
"_ctx",
",",
"curves",
")",
"elif",
"isinstance",
"(",... | u''' Set supported curves by name, nid or nist.
:param str | tuple(int) curves: Example "secp384r1:secp256k1", (715, 714), "P-384", "K-409:B-409:K-571", ...
:return: 1 for success and 0 for failure | [
"u",
"Set",
"supported",
"curves",
"by",
"name",
"nid",
"or",
"nist",
"."
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/sslconnection.py#L206-L217 | train |
rbit/pydtls | dtls/sslconnection.py | SSLContext.set_ecdh_curve | def set_ecdh_curve(self, curve_name=None):
u''' Select a curve to use for ECDH(E) key exchange or set it to auto mode
Used for server only!
s.a. openssl.exe ecparam -list_curves
:param None | str curve_name: None = Auto-mode, "secp256k1", "secp384r1", ...
:return: 1 for succes... | python | def set_ecdh_curve(self, curve_name=None):
u''' Select a curve to use for ECDH(E) key exchange or set it to auto mode
Used for server only!
s.a. openssl.exe ecparam -list_curves
:param None | str curve_name: None = Auto-mode, "secp256k1", "secp384r1", ...
:return: 1 for succes... | [
"def",
"set_ecdh_curve",
"(",
"self",
",",
"curve_name",
"=",
"None",
")",
":",
"if",
"curve_name",
":",
"retVal",
"=",
"SSL_CTX_set_ecdh_auto",
"(",
"self",
".",
"_ctx",
",",
"0",
")",
"avail_curves",
"=",
"get_elliptic_curves",
"(",
")",
"key",
"=",
"[",... | u''' Select a curve to use for ECDH(E) key exchange or set it to auto mode
Used for server only!
s.a. openssl.exe ecparam -list_curves
:param None | str curve_name: None = Auto-mode, "secp256k1", "secp384r1", ...
:return: 1 for success and 0 for failure | [
"u",
"Select",
"a",
"curve",
"to",
"use",
"for",
"ECDH",
"(",
"E",
")",
"key",
"exchange",
"or",
"set",
"it",
"to",
"auto",
"mode"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/sslconnection.py#L238-L255 | train |
rbit/pydtls | dtls/sslconnection.py | SSLContext.build_cert_chain | def build_cert_chain(self, flags=SSL_BUILD_CHAIN_FLAG_NONE):
u'''
Used for server side only!
:param flags:
:return: 1 for success and 0 for failure
'''
retVal = SSL_CTX_build_cert_chain(self._ctx, flags)
return retVal | python | def build_cert_chain(self, flags=SSL_BUILD_CHAIN_FLAG_NONE):
u'''
Used for server side only!
:param flags:
:return: 1 for success and 0 for failure
'''
retVal = SSL_CTX_build_cert_chain(self._ctx, flags)
return retVal | [
"def",
"build_cert_chain",
"(",
"self",
",",
"flags",
"=",
"SSL_BUILD_CHAIN_FLAG_NONE",
")",
":",
"retVal",
"=",
"SSL_CTX_build_cert_chain",
"(",
"self",
".",
"_ctx",
",",
"flags",
")",
"return",
"retVal"
] | u'''
Used for server side only!
:param flags:
:return: 1 for success and 0 for failure | [
"u",
"Used",
"for",
"server",
"side",
"only!"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/sslconnection.py#L257-L265 | train |
rbit/pydtls | dtls/sslconnection.py | SSLContext.set_ssl_logging | def set_ssl_logging(self, enable=False, func=_ssl_logging_cb):
u''' Enable or disable SSL logging
:param True | False enable: Enable or disable SSL logging
:param func: Callback function for logging
'''
if enable:
SSL_CTX_set_info_callback(self._ctx, func)
el... | python | def set_ssl_logging(self, enable=False, func=_ssl_logging_cb):
u''' Enable or disable SSL logging
:param True | False enable: Enable or disable SSL logging
:param func: Callback function for logging
'''
if enable:
SSL_CTX_set_info_callback(self._ctx, func)
el... | [
"def",
"set_ssl_logging",
"(",
"self",
",",
"enable",
"=",
"False",
",",
"func",
"=",
"_ssl_logging_cb",
")",
":",
"if",
"enable",
":",
"SSL_CTX_set_info_callback",
"(",
"self",
".",
"_ctx",
",",
"func",
")",
"else",
":",
"SSL_CTX_set_info_callback",
"(",
"s... | u''' Enable or disable SSL logging
:param True | False enable: Enable or disable SSL logging
:param func: Callback function for logging | [
"u",
"Enable",
"or",
"disable",
"SSL",
"logging"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/sslconnection.py#L267-L276 | train |
rbit/pydtls | dtls/sslconnection.py | SSLConnection.get_socket | def get_socket(self, inbound):
"""Retrieve a socket used by this connection
When inbound is True, then the socket from which this connection reads
data is retrieved. Otherwise the socket to which this connection writes
data is retrieved.
Read and write sockets differ depending ... | python | def get_socket(self, inbound):
"""Retrieve a socket used by this connection
When inbound is True, then the socket from which this connection reads
data is retrieved. Otherwise the socket to which this connection writes
data is retrieved.
Read and write sockets differ depending ... | [
"def",
"get_socket",
"(",
"self",
",",
"inbound",
")",
":",
"if",
"inbound",
"and",
"hasattr",
"(",
"self",
",",
"\"_rsock\"",
")",
":",
"return",
"self",
".",
"_rsock",
"return",
"self",
".",
"_sock"
] | Retrieve a socket used by this connection
When inbound is True, then the socket from which this connection reads
data is retrieved. Otherwise the socket to which this connection writes
data is retrieved.
Read and write sockets differ depending on whether this is a server- or
a ... | [
"Retrieve",
"a",
"socket",
"used",
"by",
"this",
"connection"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/sslconnection.py#L575-L588 | train |
rbit/pydtls | dtls/sslconnection.py | SSLConnection.listen | def listen(self):
"""Server-side cookie exchange
This method reads datagrams from the socket and initiates cookie
exchange, upon whose successful conclusion one can then proceed to
the accept method. Alternatively, accept can be called directly, in
which case it will call this m... | python | def listen(self):
"""Server-side cookie exchange
This method reads datagrams from the socket and initiates cookie
exchange, upon whose successful conclusion one can then proceed to
the accept method. Alternatively, accept can be called directly, in
which case it will call this m... | [
"def",
"listen",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"\"_listening\"",
")",
":",
"raise",
"InvalidSocketError",
"(",
"\"listen called on non-listening socket\"",
")",
"self",
".",
"_pending_peer_address",
"=",
"None",
"try",
":",
"pe... | Server-side cookie exchange
This method reads datagrams from the socket and initiates cookie
exchange, upon whose successful conclusion one can then proceed to
the accept method. Alternatively, accept can be called directly, in
which case it will call this method. In order to prevent de... | [
"Server",
"-",
"side",
"cookie",
"exchange"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/sslconnection.py#L590-L664 | train |
rbit/pydtls | dtls/sslconnection.py | SSLConnection.accept | def accept(self):
"""Server-side UDP connection establishment
This method returns a server-side SSLConnection object, connected to
that peer most recently returned from the listen method and not yet
connected. If there is no such peer, then the listen method is invoked.
Return ... | python | def accept(self):
"""Server-side UDP connection establishment
This method returns a server-side SSLConnection object, connected to
that peer most recently returned from the listen method and not yet
connected. If there is no such peer, then the listen method is invoked.
Return ... | [
"def",
"accept",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_pending_peer_address",
":",
"if",
"not",
"self",
".",
"listen",
"(",
")",
":",
"_logger",
".",
"debug",
"(",
"\"Accept returning without connection\"",
")",
"return",
"new_conn",
"=",
"SSLCo... | Server-side UDP connection establishment
This method returns a server-side SSLConnection object, connected to
that peer most recently returned from the listen method and not yet
connected. If there is no such peer, then the listen method is invoked.
Return value: SSLConnection connecte... | [
"Server",
"-",
"side",
"UDP",
"connection",
"establishment"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/sslconnection.py#L666-L697 | train |
rbit/pydtls | dtls/sslconnection.py | SSLConnection.connect | def connect(self, peer_address):
"""Client-side UDP connection establishment
This method connects this object's underlying socket. It subsequently
performs a handshake if do_handshake_on_connect was set during
initialization.
Arguments:
peer_address - address tuple of s... | python | def connect(self, peer_address):
"""Client-side UDP connection establishment
This method connects this object's underlying socket. It subsequently
performs a handshake if do_handshake_on_connect was set during
initialization.
Arguments:
peer_address - address tuple of s... | [
"def",
"connect",
"(",
"self",
",",
"peer_address",
")",
":",
"self",
".",
"_sock",
".",
"connect",
"(",
"peer_address",
")",
"peer_address",
"=",
"self",
".",
"_sock",
".",
"getpeername",
"(",
")",
"# substituted host addrinfo",
"BIO_dgram_set_connected",
"(",
... | Client-side UDP connection establishment
This method connects this object's underlying socket. It subsequently
performs a handshake if do_handshake_on_connect was set during
initialization.
Arguments:
peer_address - address tuple of server peer | [
"Client",
"-",
"side",
"UDP",
"connection",
"establishment"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/sslconnection.py#L699-L715 | train |
rbit/pydtls | dtls/sslconnection.py | SSLConnection.do_handshake | def do_handshake(self):
"""Perform a handshake with the peer
This method forces an explicit handshake to be performed with either
the client or server peer.
"""
_logger.debug("Initiating handshake...")
try:
self._wrap_socket_library_call(
lam... | python | def do_handshake(self):
"""Perform a handshake with the peer
This method forces an explicit handshake to be performed with either
the client or server peer.
"""
_logger.debug("Initiating handshake...")
try:
self._wrap_socket_library_call(
lam... | [
"def",
"do_handshake",
"(",
"self",
")",
":",
"_logger",
".",
"debug",
"(",
"\"Initiating handshake...\"",
")",
"try",
":",
"self",
".",
"_wrap_socket_library_call",
"(",
"lambda",
":",
"SSL_do_handshake",
"(",
"self",
".",
"_ssl",
".",
"value",
")",
",",
"E... | Perform a handshake with the peer
This method forces an explicit handshake to be performed with either
the client or server peer. | [
"Perform",
"a",
"handshake",
"with",
"the",
"peer"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/sslconnection.py#L717-L734 | train |
rbit/pydtls | dtls/sslconnection.py | SSLConnection.read | def read(self, len=1024, buffer=None):
"""Read data from connection
Read up to len bytes and return them.
Arguments:
len -- maximum number of bytes to read
Return value:
string containing read bytes
"""
try:
return self._wrap_socket_library_... | python | def read(self, len=1024, buffer=None):
"""Read data from connection
Read up to len bytes and return them.
Arguments:
len -- maximum number of bytes to read
Return value:
string containing read bytes
"""
try:
return self._wrap_socket_library_... | [
"def",
"read",
"(",
"self",
",",
"len",
"=",
"1024",
",",
"buffer",
"=",
"None",
")",
":",
"try",
":",
"return",
"self",
".",
"_wrap_socket_library_call",
"(",
"lambda",
":",
"SSL_read",
"(",
"self",
".",
"_ssl",
".",
"value",
",",
"len",
",",
"buffe... | Read data from connection
Read up to len bytes and return them.
Arguments:
len -- maximum number of bytes to read
Return value:
string containing read bytes | [
"Read",
"data",
"from",
"connection"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/sslconnection.py#L736-L753 | train |
rbit/pydtls | dtls/sslconnection.py | SSLConnection.write | def write(self, data):
"""Write data to connection
Write data as string of bytes.
Arguments:
data -- buffer containing data to be written
Return value:
number of bytes actually transmitted
"""
try:
ret = self._wrap_socket_library_call(
... | python | def write(self, data):
"""Write data to connection
Write data as string of bytes.
Arguments:
data -- buffer containing data to be written
Return value:
number of bytes actually transmitted
"""
try:
ret = self._wrap_socket_library_call(
... | [
"def",
"write",
"(",
"self",
",",
"data",
")",
":",
"try",
":",
"ret",
"=",
"self",
".",
"_wrap_socket_library_call",
"(",
"lambda",
":",
"SSL_write",
"(",
"self",
".",
"_ssl",
".",
"value",
",",
"data",
")",
",",
"ERR_WRITE_TIMEOUT",
")",
"except",
"o... | Write data to connection
Write data as string of bytes.
Arguments:
data -- buffer containing data to be written
Return value:
number of bytes actually transmitted | [
"Write",
"data",
"to",
"connection"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/sslconnection.py#L755-L776 | train |
rbit/pydtls | dtls/sslconnection.py | SSLConnection.shutdown | def shutdown(self):
"""Shut down the DTLS connection
This method attemps to complete a bidirectional shutdown between
peers. For non-blocking sockets, it should be called repeatedly until
it no longer raises continuation request exceptions.
"""
if hasattr(self, "_listen... | python | def shutdown(self):
"""Shut down the DTLS connection
This method attemps to complete a bidirectional shutdown between
peers. For non-blocking sockets, it should be called repeatedly until
it no longer raises continuation request exceptions.
"""
if hasattr(self, "_listen... | [
"def",
"shutdown",
"(",
"self",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"\"_listening\"",
")",
":",
"# Listening server-side sockets cannot be shut down",
"return",
"try",
":",
"self",
".",
"_wrap_socket_library_call",
"(",
"lambda",
":",
"SSL_shutdown",
"(",
... | Shut down the DTLS connection
This method attemps to complete a bidirectional shutdown between
peers. For non-blocking sockets, it should be called repeatedly until
it no longer raises continuation request exceptions. | [
"Shut",
"down",
"the",
"DTLS",
"connection"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/sslconnection.py#L778-L811 | train |
rbit/pydtls | dtls/sslconnection.py | SSLConnection.getpeercert | def getpeercert(self, binary_form=False):
"""Retrieve the peer's certificate
When binary form is requested, the peer's DER-encoded certficate is
returned if it was transmitted during the handshake.
When binary form is not requested, and the peer's certificate has been
validated... | python | def getpeercert(self, binary_form=False):
"""Retrieve the peer's certificate
When binary form is requested, the peer's DER-encoded certficate is
returned if it was transmitted during the handshake.
When binary form is not requested, and the peer's certificate has been
validated... | [
"def",
"getpeercert",
"(",
"self",
",",
"binary_form",
"=",
"False",
")",
":",
"try",
":",
"peer_cert",
"=",
"_X509",
"(",
"SSL_get_peer_certificate",
"(",
"self",
".",
"_ssl",
".",
"value",
")",
")",
"except",
"openssl_error",
"(",
")",
":",
"return",
"... | Retrieve the peer's certificate
When binary form is requested, the peer's DER-encoded certficate is
returned if it was transmitted during the handshake.
When binary form is not requested, and the peer's certificate has been
validated, then a certificate dictionary is returned. If the c... | [
"Retrieve",
"the",
"peer",
"s",
"certificate"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/sslconnection.py#L813-L836 | train |
rbit/pydtls | dtls/sslconnection.py | SSLConnection.cipher | def cipher(self):
"""Retrieve information about the current cipher
Return a triple consisting of cipher name, SSL protocol version defining
its use, and the number of secret bits. Return None if handshaking
has not been completed.
"""
if not self._handshake_done:
... | python | def cipher(self):
"""Retrieve information about the current cipher
Return a triple consisting of cipher name, SSL protocol version defining
its use, and the number of secret bits. Return None if handshaking
has not been completed.
"""
if not self._handshake_done:
... | [
"def",
"cipher",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_handshake_done",
":",
"return",
"current_cipher",
"=",
"SSL_get_current_cipher",
"(",
"self",
".",
"_ssl",
".",
"value",
")",
"cipher_name",
"=",
"SSL_CIPHER_get_name",
"(",
"current_cipher",
... | Retrieve information about the current cipher
Return a triple consisting of cipher name, SSL protocol version defining
its use, and the number of secret bits. Return None if handshaking
has not been completed. | [
"Retrieve",
"information",
"about",
"the",
"current",
"cipher"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/sslconnection.py#L855-L870 | train |
rbit/pydtls | dtls/__init__.py | _prep_bins | def _prep_bins():
"""
Support for running straight out of a cloned source directory instead
of an installed distribution
"""
from os import path
from sys import platform, maxsize
from shutil import copy
bit_suffix = "-x86_64" if maxsize > 2**32 else "-x86"
package_root = path.abspat... | python | def _prep_bins():
"""
Support for running straight out of a cloned source directory instead
of an installed distribution
"""
from os import path
from sys import platform, maxsize
from shutil import copy
bit_suffix = "-x86_64" if maxsize > 2**32 else "-x86"
package_root = path.abspat... | [
"def",
"_prep_bins",
"(",
")",
":",
"from",
"os",
"import",
"path",
"from",
"sys",
"import",
"platform",
",",
"maxsize",
"from",
"shutil",
"import",
"copy",
"bit_suffix",
"=",
"\"-x86_64\"",
"if",
"maxsize",
">",
"2",
"**",
"32",
"else",
"\"-x86\"",
"packa... | Support for running straight out of a cloned source directory instead
of an installed distribution | [
"Support",
"for",
"running",
"straight",
"out",
"of",
"a",
"cloned",
"source",
"directory",
"instead",
"of",
"an",
"installed",
"distribution"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/__init__.py#L37-L59 | train |
rbit/pydtls | dtls/demux/osnet.py | UDPDemux.get_connection | def get_connection(self, address):
"""Create or retrieve a muxed connection
Arguments:
address -- a peer endpoint in IPv4/v6 address format; None refers
to the connection for unknown peers
Return:
a bound, connected datagram socket instance, or the root socke... | python | def get_connection(self, address):
"""Create or retrieve a muxed connection
Arguments:
address -- a peer endpoint in IPv4/v6 address format; None refers
to the connection for unknown peers
Return:
a bound, connected datagram socket instance, or the root socke... | [
"def",
"get_connection",
"(",
"self",
",",
"address",
")",
":",
"if",
"not",
"address",
":",
"return",
"self",
".",
"_datagram_socket",
"# Create a new datagram socket bound to the same interface and port as",
"# the root socket, but connected to the given peer",
"conn",
"=",
... | Create or retrieve a muxed connection
Arguments:
address -- a peer endpoint in IPv4/v6 address format; None refers
to the connection for unknown peers
Return:
a bound, connected datagram socket instance, or the root socket
in case address was None | [
"Create",
"or",
"retrieve",
"a",
"muxed",
"connection"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/demux/osnet.py#L86-L110 | train |
rbit/pydtls | dtls/openssl.py | SSL_CTX_set_info_callback | def SSL_CTX_set_info_callback(ctx, app_info_cb):
"""
Set the info callback
:param callback: The Python callback to use
:return: None
"""
def py_info_callback(ssl, where, ret):
try:
app_info_cb(SSL(ssl), where, ret)
except:
pass
return
global ... | python | def SSL_CTX_set_info_callback(ctx, app_info_cb):
"""
Set the info callback
:param callback: The Python callback to use
:return: None
"""
def py_info_callback(ssl, where, ret):
try:
app_info_cb(SSL(ssl), where, ret)
except:
pass
return
global ... | [
"def",
"SSL_CTX_set_info_callback",
"(",
"ctx",
",",
"app_info_cb",
")",
":",
"def",
"py_info_callback",
"(",
"ssl",
",",
"where",
",",
"ret",
")",
":",
"try",
":",
"app_info_cb",
"(",
"SSL",
"(",
"ssl",
")",
",",
"where",
",",
"ret",
")",
"except",
":... | Set the info callback
:param callback: The Python callback to use
:return: None | [
"Set",
"the",
"info",
"callback"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/openssl.py#L876-L892 | train |
rbit/pydtls | dtls/err.py | raise_ssl_error | def raise_ssl_error(code, nested=None):
"""Raise an SSL error with the given error code"""
err_string = str(code) + ": " + _ssl_errors[code]
if nested:
raise SSLError(code, err_string + str(nested))
raise SSLError(code, err_string) | python | def raise_ssl_error(code, nested=None):
"""Raise an SSL error with the given error code"""
err_string = str(code) + ": " + _ssl_errors[code]
if nested:
raise SSLError(code, err_string + str(nested))
raise SSLError(code, err_string) | [
"def",
"raise_ssl_error",
"(",
"code",
",",
"nested",
"=",
"None",
")",
":",
"err_string",
"=",
"str",
"(",
"code",
")",
"+",
"\": \"",
"+",
"_ssl_errors",
"[",
"code",
"]",
"if",
"nested",
":",
"raise",
"SSLError",
"(",
"code",
",",
"err_string",
"+",... | Raise an SSL error with the given error code | [
"Raise",
"an",
"SSL",
"error",
"with",
"the",
"given",
"error",
"code"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/err.py#L108-L113 | train |
rbit/pydtls | dtls/demux/router.py | UDPDemux.get_connection | def get_connection(self, address):
"""Create or retrieve a muxed connection
Arguments:
address -- a peer endpoint in IPv4/v6 address format; None refers
to the connection for unknown peers
Return:
a bound, connected datagram socket instance
"""
... | python | def get_connection(self, address):
"""Create or retrieve a muxed connection
Arguments:
address -- a peer endpoint in IPv4/v6 address format; None refers
to the connection for unknown peers
Return:
a bound, connected datagram socket instance
"""
... | [
"def",
"get_connection",
"(",
"self",
",",
"address",
")",
":",
"if",
"self",
".",
"connections",
".",
"has_key",
"(",
"address",
")",
":",
"return",
"self",
".",
"connections",
"[",
"address",
"]",
"# We need a new datagram socket on a dynamically assigned ephemera... | Create or retrieve a muxed connection
Arguments:
address -- a peer endpoint in IPv4/v6 address format; None refers
to the connection for unknown peers
Return:
a bound, connected datagram socket instance | [
"Create",
"or",
"retrieve",
"a",
"muxed",
"connection"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/demux/router.py#L94-L118 | train |
rbit/pydtls | dtls/demux/router.py | UDPDemux.service | def service(self):
"""Service the root socket
Read from the root socket and forward one datagram to a
connection. The call will return without forwarding data
if any of the following occurs:
* An error is encountered while reading from the root socket
* Reading from... | python | def service(self):
"""Service the root socket
Read from the root socket and forward one datagram to a
connection. The call will return without forwarding data
if any of the following occurs:
* An error is encountered while reading from the root socket
* Reading from... | [
"def",
"service",
"(",
"self",
")",
":",
"self",
".",
"payload",
",",
"self",
".",
"payload_peer_address",
"=",
"self",
".",
"datagram_socket",
".",
"recvfrom",
"(",
"UDP_MAX_DGRAM_LENGTH",
")",
"_logger",
".",
"debug",
"(",
"\"Received datagram from peer: %s\"",
... | Service the root socket
Read from the root socket and forward one datagram to a
connection. The call will return without forwarding data
if any of the following occurs:
* An error is encountered while reading from the root socket
* Reading from the root socket times out
... | [
"Service",
"the",
"root",
"socket"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/demux/router.py#L133-L164 | train |
rbit/pydtls | dtls/demux/router.py | UDPDemux.forward | def forward(self):
"""Forward a stored datagram
When the service method returns the address of a new peer, it holds
the datagram from that peer in this instance. In this case, this
method will perform the forwarding step. The target connection is the
one associated with address ... | python | def forward(self):
"""Forward a stored datagram
When the service method returns the address of a new peer, it holds
the datagram from that peer in this instance. In this case, this
method will perform the forwarding step. The target connection is the
one associated with address ... | [
"def",
"forward",
"(",
"self",
")",
":",
"assert",
"self",
".",
"payload",
"assert",
"self",
".",
"payload_peer_address",
"if",
"self",
".",
"connections",
".",
"has_key",
"(",
"self",
".",
"payload_peer_address",
")",
":",
"conn",
"=",
"self",
".",
"conne... | Forward a stored datagram
When the service method returns the address of a new peer, it holds
the datagram from that peer in this instance. In this case, this
method will perform the forwarding step. The target connection is the
one associated with address None if get_connection has not... | [
"Forward",
"a",
"stored",
"datagram"
] | 41a71fccd990347d0de5f42418fea1e4e733359c | https://github.com/rbit/pydtls/blob/41a71fccd990347d0de5f42418fea1e4e733359c/dtls/demux/router.py#L166-L189 | train |
glasnt/emojificate | emojificate/templatetags/emojificate.py | emojificate_filter | def emojificate_filter(content, autoescape=True):
"Convert any emoji in a string into accessible content."
# return mark_safe(emojificate(content))
if autoescape:
esc = conditional_escape
else:
esc = lambda x: x
return mark_safe(emojificate(esc(content))) | python | def emojificate_filter(content, autoescape=True):
"Convert any emoji in a string into accessible content."
# return mark_safe(emojificate(content))
if autoescape:
esc = conditional_escape
else:
esc = lambda x: x
return mark_safe(emojificate(esc(content))) | [
"def",
"emojificate_filter",
"(",
"content",
",",
"autoescape",
"=",
"True",
")",
":",
"# return mark_safe(emojificate(content))",
"if",
"autoescape",
":",
"esc",
"=",
"conditional_escape",
"else",
":",
"esc",
"=",
"lambda",
"x",
":",
"x",
"return",
"mark_safe",
... | Convert any emoji in a string into accessible content. | [
"Convert",
"any",
"emoji",
"in",
"a",
"string",
"into",
"accessible",
"content",
"."
] | 701baad443022043870389c0e0030ed6b7127448 | https://github.com/glasnt/emojificate/blob/701baad443022043870389c0e0030ed6b7127448/emojificate/templatetags/emojificate.py#L12-L19 | train |
xeroc/stakemachine | stakemachine/strategies/walls.py | Walls.updateorders | def updateorders(self):
""" Update the orders
"""
log.info("Replacing orders")
# Canceling orders
self.cancelall()
# Target
target = self.bot.get("target", {})
price = self.getprice()
# prices
buy_price = price * (1 - target["offsets"]["... | python | def updateorders(self):
""" Update the orders
"""
log.info("Replacing orders")
# Canceling orders
self.cancelall()
# Target
target = self.bot.get("target", {})
price = self.getprice()
# prices
buy_price = price * (1 - target["offsets"]["... | [
"def",
"updateorders",
"(",
"self",
")",
":",
"log",
".",
"info",
"(",
"\"Replacing orders\"",
")",
"# Canceling orders",
"self",
".",
"cancelall",
"(",
")",
"# Target",
"target",
"=",
"self",
".",
"bot",
".",
"get",
"(",
"\"target\"",
",",
"{",
"}",
")"... | Update the orders | [
"Update",
"the",
"orders"
] | c2d5bcfe7c013a93c8c7293bec44ef5690883b16 | https://github.com/xeroc/stakemachine/blob/c2d5bcfe7c013a93c8c7293bec44ef5690883b16/stakemachine/strategies/walls.py#L35-L78 | train |
xeroc/stakemachine | stakemachine/strategies/walls.py | Walls.getprice | def getprice(self):
""" Here we obtain the price for the quote and make sure it has
a feed price
"""
target = self.bot.get("target", {})
if target.get("reference") == "feed":
assert self.market == self.market.core_quote_market(), "Wrong market for 'feed' reference... | python | def getprice(self):
""" Here we obtain the price for the quote and make sure it has
a feed price
"""
target = self.bot.get("target", {})
if target.get("reference") == "feed":
assert self.market == self.market.core_quote_market(), "Wrong market for 'feed' reference... | [
"def",
"getprice",
"(",
"self",
")",
":",
"target",
"=",
"self",
".",
"bot",
".",
"get",
"(",
"\"target\"",
",",
"{",
"}",
")",
"if",
"target",
".",
"get",
"(",
"\"reference\"",
")",
"==",
"\"feed\"",
":",
"assert",
"self",
".",
"market",
"==",
"se... | Here we obtain the price for the quote and make sure it has
a feed price | [
"Here",
"we",
"obtain",
"the",
"price",
"for",
"the",
"quote",
"and",
"make",
"sure",
"it",
"has",
"a",
"feed",
"price"
] | c2d5bcfe7c013a93c8c7293bec44ef5690883b16 | https://github.com/xeroc/stakemachine/blob/c2d5bcfe7c013a93c8c7293bec44ef5690883b16/stakemachine/strategies/walls.py#L80-L90 | train |
xeroc/stakemachine | stakemachine/strategies/walls.py | Walls.tick | def tick(self, d):
""" ticks come in on every block
"""
if self.test_blocks:
if not (self.counter["blocks"] or 0) % self.test_blocks:
self.test()
self.counter["blocks"] += 1 | python | def tick(self, d):
""" ticks come in on every block
"""
if self.test_blocks:
if not (self.counter["blocks"] or 0) % self.test_blocks:
self.test()
self.counter["blocks"] += 1 | [
"def",
"tick",
"(",
"self",
",",
"d",
")",
":",
"if",
"self",
".",
"test_blocks",
":",
"if",
"not",
"(",
"self",
".",
"counter",
"[",
"\"blocks\"",
"]",
"or",
"0",
")",
"%",
"self",
".",
"test_blocks",
":",
"self",
".",
"test",
"(",
")",
"self",
... | ticks come in on every block | [
"ticks",
"come",
"in",
"on",
"every",
"block"
] | c2d5bcfe7c013a93c8c7293bec44ef5690883b16 | https://github.com/xeroc/stakemachine/blob/c2d5bcfe7c013a93c8c7293bec44ef5690883b16/stakemachine/strategies/walls.py#L92-L98 | train |
xeroc/stakemachine | stakemachine/basestrategy.py | BaseStrategy.orders | def orders(self):
""" Return the bot's open accounts in the current market
"""
self.account.refresh()
return [o for o in self.account.openorders if self.bot["market"] == o.market and self.account.openorders] | python | def orders(self):
""" Return the bot's open accounts in the current market
"""
self.account.refresh()
return [o for o in self.account.openorders if self.bot["market"] == o.market and self.account.openorders] | [
"def",
"orders",
"(",
"self",
")",
":",
"self",
".",
"account",
".",
"refresh",
"(",
")",
"return",
"[",
"o",
"for",
"o",
"in",
"self",
".",
"account",
".",
"openorders",
"if",
"self",
".",
"bot",
"[",
"\"market\"",
"]",
"==",
"o",
".",
"market",
... | Return the bot's open accounts in the current market | [
"Return",
"the",
"bot",
"s",
"open",
"accounts",
"in",
"the",
"current",
"market"
] | c2d5bcfe7c013a93c8c7293bec44ef5690883b16 | https://github.com/xeroc/stakemachine/blob/c2d5bcfe7c013a93c8c7293bec44ef5690883b16/stakemachine/basestrategy.py#L116-L120 | train |
xeroc/stakemachine | stakemachine/basestrategy.py | BaseStrategy._callbackPlaceFillOrders | def _callbackPlaceFillOrders(self, d):
""" This method distringuishes notifications caused by Matched orders
from those caused by placed orders
"""
if isinstance(d, FilledOrder):
self.onOrderMatched(d)
elif isinstance(d, Order):
self.onOrderPlaced(d)
... | python | def _callbackPlaceFillOrders(self, d):
""" This method distringuishes notifications caused by Matched orders
from those caused by placed orders
"""
if isinstance(d, FilledOrder):
self.onOrderMatched(d)
elif isinstance(d, Order):
self.onOrderPlaced(d)
... | [
"def",
"_callbackPlaceFillOrders",
"(",
"self",
",",
"d",
")",
":",
"if",
"isinstance",
"(",
"d",
",",
"FilledOrder",
")",
":",
"self",
".",
"onOrderMatched",
"(",
"d",
")",
"elif",
"isinstance",
"(",
"d",
",",
"Order",
")",
":",
"self",
".",
"onOrderP... | This method distringuishes notifications caused by Matched orders
from those caused by placed orders | [
"This",
"method",
"distringuishes",
"notifications",
"caused",
"by",
"Matched",
"orders",
"from",
"those",
"caused",
"by",
"placed",
"orders"
] | c2d5bcfe7c013a93c8c7293bec44ef5690883b16 | https://github.com/xeroc/stakemachine/blob/c2d5bcfe7c013a93c8c7293bec44ef5690883b16/stakemachine/basestrategy.py#L147-L158 | train |
xeroc/stakemachine | stakemachine/basestrategy.py | BaseStrategy.execute | def execute(self):
""" Execute a bundle of operations
"""
self.bitshares.blocking = "head"
r = self.bitshares.txbuffer.broadcast()
self.bitshares.blocking = False
return r | python | def execute(self):
""" Execute a bundle of operations
"""
self.bitshares.blocking = "head"
r = self.bitshares.txbuffer.broadcast()
self.bitshares.blocking = False
return r | [
"def",
"execute",
"(",
"self",
")",
":",
"self",
".",
"bitshares",
".",
"blocking",
"=",
"\"head\"",
"r",
"=",
"self",
".",
"bitshares",
".",
"txbuffer",
".",
"broadcast",
"(",
")",
"self",
".",
"bitshares",
".",
"blocking",
"=",
"False",
"return",
"r"... | Execute a bundle of operations | [
"Execute",
"a",
"bundle",
"of",
"operations"
] | c2d5bcfe7c013a93c8c7293bec44ef5690883b16 | https://github.com/xeroc/stakemachine/blob/c2d5bcfe7c013a93c8c7293bec44ef5690883b16/stakemachine/basestrategy.py#L160-L166 | train |
xeroc/stakemachine | stakemachine/basestrategy.py | BaseStrategy.cancelall | def cancelall(self):
""" Cancel all orders of this bot
"""
if self.orders:
return self.bitshares.cancel(
[o["id"] for o in self.orders],
account=self.account
) | python | def cancelall(self):
""" Cancel all orders of this bot
"""
if self.orders:
return self.bitshares.cancel(
[o["id"] for o in self.orders],
account=self.account
) | [
"def",
"cancelall",
"(",
"self",
")",
":",
"if",
"self",
".",
"orders",
":",
"return",
"self",
".",
"bitshares",
".",
"cancel",
"(",
"[",
"o",
"[",
"\"id\"",
"]",
"for",
"o",
"in",
"self",
".",
"orders",
"]",
",",
"account",
"=",
"self",
".",
"ac... | Cancel all orders of this bot | [
"Cancel",
"all",
"orders",
"of",
"this",
"bot"
] | c2d5bcfe7c013a93c8c7293bec44ef5690883b16 | https://github.com/xeroc/stakemachine/blob/c2d5bcfe7c013a93c8c7293bec44ef5690883b16/stakemachine/basestrategy.py#L168-L175 | train |
erinxocon/requests-xml | requests_xml.py | BaseParser.raw_xml | def raw_xml(self) -> _RawXML:
"""Bytes representation of the XML content.
(`learn more <http://www.diveintopython3.net/strings.html>`_).
"""
if self._xml:
return self._xml
else:
return etree.tostring(self.element, encoding='unicode').strip().encode(self.en... | python | def raw_xml(self) -> _RawXML:
"""Bytes representation of the XML content.
(`learn more <http://www.diveintopython3.net/strings.html>`_).
"""
if self._xml:
return self._xml
else:
return etree.tostring(self.element, encoding='unicode').strip().encode(self.en... | [
"def",
"raw_xml",
"(",
"self",
")",
"->",
"_RawXML",
":",
"if",
"self",
".",
"_xml",
":",
"return",
"self",
".",
"_xml",
"else",
":",
"return",
"etree",
".",
"tostring",
"(",
"self",
".",
"element",
",",
"encoding",
"=",
"'unicode'",
")",
".",
"strip... | Bytes representation of the XML content.
(`learn more <http://www.diveintopython3.net/strings.html>`_). | [
"Bytes",
"representation",
"of",
"the",
"XML",
"content",
".",
"(",
"learn",
"more",
"<http",
":",
"//",
"www",
".",
"diveintopython3",
".",
"net",
"/",
"strings",
".",
"html",
">",
"_",
")",
"."
] | 923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1 | https://github.com/erinxocon/requests-xml/blob/923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1/requests_xml.py#L72-L79 | train |
erinxocon/requests-xml | requests_xml.py | BaseParser.xml | def xml(self) -> _BaseXML:
"""Unicode representation of the XML content
(`learn more <http://www.diveintopython3.net/strings.html>`_).
"""
if self._xml:
return self.raw_xml.decode(self.encoding)
else:
return etree.tostring(self.element, encoding='unicode')... | python | def xml(self) -> _BaseXML:
"""Unicode representation of the XML content
(`learn more <http://www.diveintopython3.net/strings.html>`_).
"""
if self._xml:
return self.raw_xml.decode(self.encoding)
else:
return etree.tostring(self.element, encoding='unicode')... | [
"def",
"xml",
"(",
"self",
")",
"->",
"_BaseXML",
":",
"if",
"self",
".",
"_xml",
":",
"return",
"self",
".",
"raw_xml",
".",
"decode",
"(",
"self",
".",
"encoding",
")",
"else",
":",
"return",
"etree",
".",
"tostring",
"(",
"self",
".",
"element",
... | Unicode representation of the XML content
(`learn more <http://www.diveintopython3.net/strings.html>`_). | [
"Unicode",
"representation",
"of",
"the",
"XML",
"content",
"(",
"learn",
"more",
"<http",
":",
"//",
"www",
".",
"diveintopython3",
".",
"net",
"/",
"strings",
".",
"html",
">",
"_",
")",
"."
] | 923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1 | https://github.com/erinxocon/requests-xml/blob/923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1/requests_xml.py#L83-L90 | train |
erinxocon/requests-xml | requests_xml.py | BaseParser.pq | def pq(self) -> PyQuery:
"""`PyQuery <https://pythonhosted.org/pyquery/>`_ representation
of the :class:`Element <Element>` or :class:`HTML <HTML>`.
"""
if self._pq is None:
self._pq = PyQuery(self.raw_xml)
return self._pq | python | def pq(self) -> PyQuery:
"""`PyQuery <https://pythonhosted.org/pyquery/>`_ representation
of the :class:`Element <Element>` or :class:`HTML <HTML>`.
"""
if self._pq is None:
self._pq = PyQuery(self.raw_xml)
return self._pq | [
"def",
"pq",
"(",
"self",
")",
"->",
"PyQuery",
":",
"if",
"self",
".",
"_pq",
"is",
"None",
":",
"self",
".",
"_pq",
"=",
"PyQuery",
"(",
"self",
".",
"raw_xml",
")",
"return",
"self",
".",
"_pq"
] | `PyQuery <https://pythonhosted.org/pyquery/>`_ representation
of the :class:`Element <Element>` or :class:`HTML <HTML>`. | [
"PyQuery",
"<https",
":",
"//",
"pythonhosted",
".",
"org",
"/",
"pyquery",
"/",
">",
"_",
"representation",
"of",
"the",
":",
"class",
":",
"Element",
"<Element",
">",
"or",
":",
"class",
":",
"HTML",
"<HTML",
">",
"."
] | 923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1 | https://github.com/erinxocon/requests-xml/blob/923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1/requests_xml.py#L105-L112 | train |
erinxocon/requests-xml | requests_xml.py | BaseParser.lxml | def lxml(self) -> _LXML:
"""`lxml <http://lxml.de>`_ representation of the
:class:`Element <Element>` or :class:`XML <XML>`.
"""
if self._lxml is None:
self._lxml = etree.fromstring(self.raw_xml)
return self._lxml | python | def lxml(self) -> _LXML:
"""`lxml <http://lxml.de>`_ representation of the
:class:`Element <Element>` or :class:`XML <XML>`.
"""
if self._lxml is None:
self._lxml = etree.fromstring(self.raw_xml)
return self._lxml | [
"def",
"lxml",
"(",
"self",
")",
"->",
"_LXML",
":",
"if",
"self",
".",
"_lxml",
"is",
"None",
":",
"self",
".",
"_lxml",
"=",
"etree",
".",
"fromstring",
"(",
"self",
".",
"raw_xml",
")",
"return",
"self",
".",
"_lxml"
] | `lxml <http://lxml.de>`_ representation of the
:class:`Element <Element>` or :class:`XML <XML>`. | [
"lxml",
"<http",
":",
"//",
"lxml",
".",
"de",
">",
"_",
"representation",
"of",
"the",
":",
"class",
":",
"Element",
"<Element",
">",
"or",
":",
"class",
":",
"XML",
"<XML",
">",
"."
] | 923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1 | https://github.com/erinxocon/requests-xml/blob/923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1/requests_xml.py#L115-L122 | train |
erinxocon/requests-xml | requests_xml.py | BaseParser.links | def links(self) -> _Links:
"""All found links on page, in as–is form. Only works for Atom feeds."""
return list(set(x.text for x in self.xpath('//link'))) | python | def links(self) -> _Links:
"""All found links on page, in as–is form. Only works for Atom feeds."""
return list(set(x.text for x in self.xpath('//link'))) | [
"def",
"links",
"(",
"self",
")",
"->",
"_Links",
":",
"return",
"list",
"(",
"set",
"(",
"x",
".",
"text",
"for",
"x",
"in",
"self",
".",
"xpath",
"(",
"'//link'",
")",
")",
")"
] | All found links on page, in as–is form. Only works for Atom feeds. | [
"All",
"found",
"links",
"on",
"page",
"in",
"as–is",
"form",
".",
"Only",
"works",
"for",
"Atom",
"feeds",
"."
] | 923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1 | https://github.com/erinxocon/requests-xml/blob/923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1/requests_xml.py#L133-L135 | train |
erinxocon/requests-xml | requests_xml.py | BaseParser.encoding | def encoding(self) -> _Encoding:
"""The encoding string to be used, extracted from the XML and
:class:`XMLResponse <XMLResponse>` header.
"""
if self._encoding:
return self._encoding
# Scan meta tags for charset.
if self._xml:
self._encoding = htm... | python | def encoding(self) -> _Encoding:
"""The encoding string to be used, extracted from the XML and
:class:`XMLResponse <XMLResponse>` header.
"""
if self._encoding:
return self._encoding
# Scan meta tags for charset.
if self._xml:
self._encoding = htm... | [
"def",
"encoding",
"(",
"self",
")",
"->",
"_Encoding",
":",
"if",
"self",
".",
"_encoding",
":",
"return",
"self",
".",
"_encoding",
"# Scan meta tags for charset.",
"if",
"self",
".",
"_xml",
":",
"self",
".",
"_encoding",
"=",
"html_to_unicode",
"(",
"sel... | The encoding string to be used, extracted from the XML and
:class:`XMLResponse <XMLResponse>` header. | [
"The",
"encoding",
"string",
"to",
"be",
"used",
"extracted",
"from",
"the",
"XML",
"and",
":",
"class",
":",
"XMLResponse",
"<XMLResponse",
">",
"header",
"."
] | 923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1 | https://github.com/erinxocon/requests-xml/blob/923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1/requests_xml.py#L157-L168 | train |
erinxocon/requests-xml | requests_xml.py | BaseParser.json | def json(self, conversion: _Text = 'badgerfish') -> Mapping:
"""A JSON Representation of the XML. Default is badgerfish.
:param conversion: Which conversion method to use. (`learn more <https://github.com/sanand0/xmljson#conventions>`_)
"""
if not self._json:
if conversion ... | python | def json(self, conversion: _Text = 'badgerfish') -> Mapping:
"""A JSON Representation of the XML. Default is badgerfish.
:param conversion: Which conversion method to use. (`learn more <https://github.com/sanand0/xmljson#conventions>`_)
"""
if not self._json:
if conversion ... | [
"def",
"json",
"(",
"self",
",",
"conversion",
":",
"_Text",
"=",
"'badgerfish'",
")",
"->",
"Mapping",
":",
"if",
"not",
"self",
".",
"_json",
":",
"if",
"conversion",
"is",
"'badgerfish'",
":",
"from",
"xmljson",
"import",
"badgerfish",
"as",
"serializer... | A JSON Representation of the XML. Default is badgerfish.
:param conversion: Which conversion method to use. (`learn more <https://github.com/sanand0/xmljson#conventions>`_) | [
"A",
"JSON",
"Representation",
"of",
"the",
"XML",
".",
"Default",
"is",
"badgerfish",
".",
":",
"param",
"conversion",
":",
"Which",
"conversion",
"method",
"to",
"use",
".",
"(",
"learn",
"more",
"<https",
":",
"//",
"github",
".",
"com",
"/",
"sanand0... | 923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1 | https://github.com/erinxocon/requests-xml/blob/923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1/requests_xml.py#L177-L203 | train |
erinxocon/requests-xml | requests_xml.py | BaseParser.xpath | def xpath(self, selector: str, *, first: bool = False, _encoding: str = None) -> _XPath:
"""Given an XPath selector, returns a list of
:class:`Element <Element>` objects or a single one.
:param selector: XPath Selector to use.
:param first: Whether or not to return just the first result... | python | def xpath(self, selector: str, *, first: bool = False, _encoding: str = None) -> _XPath:
"""Given an XPath selector, returns a list of
:class:`Element <Element>` objects or a single one.
:param selector: XPath Selector to use.
:param first: Whether or not to return just the first result... | [
"def",
"xpath",
"(",
"self",
",",
"selector",
":",
"str",
",",
"*",
",",
"first",
":",
"bool",
"=",
"False",
",",
"_encoding",
":",
"str",
"=",
"None",
")",
"->",
"_XPath",
":",
"selected",
"=",
"self",
".",
"lxml",
".",
"xpath",
"(",
"selector",
... | Given an XPath selector, returns a list of
:class:`Element <Element>` objects or a single one.
:param selector: XPath Selector to use.
:param first: Whether or not to return just the first result.
:param _encoding: The encoding format.
If a sub-selector is specified (e.g. ``//a... | [
"Given",
"an",
"XPath",
"selector",
"returns",
"a",
"list",
"of",
":",
"class",
":",
"Element",
"<Element",
">",
"objects",
"or",
"a",
"single",
"one",
"."
] | 923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1 | https://github.com/erinxocon/requests-xml/blob/923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1/requests_xml.py#L206-L232 | train |
erinxocon/requests-xml | requests_xml.py | BaseParser.search | def search(self, template: str, first: bool = False) -> _Result:
"""Search the :class:`Element <Element>` for the given parse
template.
:param template: The Parse template to use.
"""
elements = [r for r in findall(template, self.xml)]
return _get_first_or_list(elements... | python | def search(self, template: str, first: bool = False) -> _Result:
"""Search the :class:`Element <Element>` for the given parse
template.
:param template: The Parse template to use.
"""
elements = [r for r in findall(template, self.xml)]
return _get_first_or_list(elements... | [
"def",
"search",
"(",
"self",
",",
"template",
":",
"str",
",",
"first",
":",
"bool",
"=",
"False",
")",
"->",
"_Result",
":",
"elements",
"=",
"[",
"r",
"for",
"r",
"in",
"findall",
"(",
"template",
",",
"self",
".",
"xml",
")",
"]",
"return",
"... | Search the :class:`Element <Element>` for the given parse
template.
:param template: The Parse template to use. | [
"Search",
"the",
":",
"class",
":",
"Element",
"<Element",
">",
"for",
"the",
"given",
"parse",
"template",
"."
] | 923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1 | https://github.com/erinxocon/requests-xml/blob/923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1/requests_xml.py#L235-L243 | train |
erinxocon/requests-xml | requests_xml.py | BaseParser.find | def find(self, selector: str = '*', containing: _Containing = None, first: bool = False, _encoding: str = None) -> _Find:
"""Given a simple element name, returns a list of
:class:`Element <Element>` objects or a single one.
:param selector: Element name to find.
:param c... | python | def find(self, selector: str = '*', containing: _Containing = None, first: bool = False, _encoding: str = None) -> _Find:
"""Given a simple element name, returns a list of
:class:`Element <Element>` objects or a single one.
:param selector: Element name to find.
:param c... | [
"def",
"find",
"(",
"self",
",",
"selector",
":",
"str",
"=",
"'*'",
",",
"containing",
":",
"_Containing",
"=",
"None",
",",
"first",
":",
"bool",
"=",
"False",
",",
"_encoding",
":",
"str",
"=",
"None",
")",
"->",
"_Find",
":",
"# Convert a single co... | Given a simple element name, returns a list of
:class:`Element <Element>` objects or a single one.
:param selector: Element name to find.
:param containing: If specified, only return elements that contain the provided text.
:param first: Whether or not to return just the... | [
"Given",
"a",
"simple",
"element",
"name",
"returns",
"a",
"list",
"of",
":",
"class",
":",
"Element",
"<Element",
">",
"objects",
"or",
"a",
"single",
"one",
"."
] | 923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1 | https://github.com/erinxocon/requests-xml/blob/923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1/requests_xml.py#L246-L279 | train |
erinxocon/requests-xml | requests_xml.py | XMLSession._handle_response | def _handle_response(response, **kwargs) -> XMLResponse:
"""Requests HTTP Response handler. Attaches .html property to
class:`requests.Response <requests.Response>` objects.
"""
if not response.encoding:
response.encoding = DEFAULT_ENCODING
return response | python | def _handle_response(response, **kwargs) -> XMLResponse:
"""Requests HTTP Response handler. Attaches .html property to
class:`requests.Response <requests.Response>` objects.
"""
if not response.encoding:
response.encoding = DEFAULT_ENCODING
return response | [
"def",
"_handle_response",
"(",
"response",
",",
"*",
"*",
"kwargs",
")",
"->",
"XMLResponse",
":",
"if",
"not",
"response",
".",
"encoding",
":",
"response",
".",
"encoding",
"=",
"DEFAULT_ENCODING",
"return",
"response"
] | Requests HTTP Response handler. Attaches .html property to
class:`requests.Response <requests.Response>` objects. | [
"Requests",
"HTTP",
"Response",
"handler",
".",
"Attaches",
".",
"html",
"property",
"to",
"class",
":",
"requests",
".",
"Response",
"<requests",
".",
"Response",
">",
"objects",
"."
] | 923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1 | https://github.com/erinxocon/requests-xml/blob/923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1/requests_xml.py#L410-L417 | train |
erinxocon/requests-xml | requests_xml.py | XMLSession.request | def request(self, *args, **kwargs) -> XMLResponse:
"""Makes an HTTP Request, with mocked User–Agent headers.
Returns a class:`HTTPResponse <HTTPResponse>`.
"""
# Convert Request object into HTTPRequest object.
r = super(XMLSession, self).request(*args, **kwargs)
return X... | python | def request(self, *args, **kwargs) -> XMLResponse:
"""Makes an HTTP Request, with mocked User–Agent headers.
Returns a class:`HTTPResponse <HTTPResponse>`.
"""
# Convert Request object into HTTPRequest object.
r = super(XMLSession, self).request(*args, **kwargs)
return X... | [
"def",
"request",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"->",
"XMLResponse",
":",
"# Convert Request object into HTTPRequest object.",
"r",
"=",
"super",
"(",
"XMLSession",
",",
"self",
")",
".",
"request",
"(",
"*",
"args",
",",
"*"... | Makes an HTTP Request, with mocked User–Agent headers.
Returns a class:`HTTPResponse <HTTPResponse>`. | [
"Makes",
"an",
"HTTP",
"Request",
"with",
"mocked",
"User–Agent",
"headers",
".",
"Returns",
"a",
"class",
":",
"HTTPResponse",
"<HTTPResponse",
">",
"."
] | 923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1 | https://github.com/erinxocon/requests-xml/blob/923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1/requests_xml.py#L419-L426 | train |
erinxocon/requests-xml | requests_xml.py | AsyncXMLSession.response_hook | def response_hook(response, **kwargs) -> XMLResponse:
""" Change response enconding and replace it by a HTMLResponse. """
response.encoding = DEFAULT_ENCODING
return XMLResponse._from_response(response) | python | def response_hook(response, **kwargs) -> XMLResponse:
""" Change response enconding and replace it by a HTMLResponse. """
response.encoding = DEFAULT_ENCODING
return XMLResponse._from_response(response) | [
"def",
"response_hook",
"(",
"response",
",",
"*",
"*",
"kwargs",
")",
"->",
"XMLResponse",
":",
"response",
".",
"encoding",
"=",
"DEFAULT_ENCODING",
"return",
"XMLResponse",
".",
"_from_response",
"(",
"response",
")"
] | Change response enconding and replace it by a HTMLResponse. | [
"Change",
"response",
"enconding",
"and",
"replace",
"it",
"by",
"a",
"HTMLResponse",
"."
] | 923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1 | https://github.com/erinxocon/requests-xml/blob/923571ceae4ddd4f2f57a2fc8780d89b50f3e7a1/requests_xml.py#L452-L455 | train |
itamarst/crochet | examples/scheduling.py | _ExchangeRate.start | def start(self):
"""Start the background process."""
self._lc = LoopingCall(self._download)
# Run immediately, and then every 30 seconds:
self._lc.start(30, now=True) | python | def start(self):
"""Start the background process."""
self._lc = LoopingCall(self._download)
# Run immediately, and then every 30 seconds:
self._lc.start(30, now=True) | [
"def",
"start",
"(",
"self",
")",
":",
"self",
".",
"_lc",
"=",
"LoopingCall",
"(",
"self",
".",
"_download",
")",
"# Run immediately, and then every 30 seconds:",
"self",
".",
"_lc",
".",
"start",
"(",
"30",
",",
"now",
"=",
"True",
")"
] | Start the background process. | [
"Start",
"the",
"background",
"process",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/examples/scheduling.py#L42-L46 | train |
itamarst/crochet | examples/scheduling.py | _ExchangeRate._download | def _download(self):
"""Download the page."""
print("Downloading!")
def parse(result):
print("Got %r back from Yahoo." % (result,))
values = result.strip().split(",")
self._value = float(values[1])
d = getPage(
"http://download.finance.yaho... | python | def _download(self):
"""Download the page."""
print("Downloading!")
def parse(result):
print("Got %r back from Yahoo." % (result,))
values = result.strip().split(",")
self._value = float(values[1])
d = getPage(
"http://download.finance.yaho... | [
"def",
"_download",
"(",
"self",
")",
":",
"print",
"(",
"\"Downloading!\"",
")",
"def",
"parse",
"(",
"result",
")",
":",
"print",
"(",
"\"Got %r back from Yahoo.\"",
"%",
"(",
"result",
",",
")",
")",
"values",
"=",
"result",
".",
"strip",
"(",
")",
... | Download the page. | [
"Download",
"the",
"page",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/examples/scheduling.py#L48-L60 | train |
itamarst/crochet | crochet/_eventloop.py | ResultRegistry.register | def register(self, result):
"""
Register an EventualResult.
May be called in any thread.
"""
if self._stopped:
raise ReactorStopped()
self._results.add(result) | python | def register(self, result):
"""
Register an EventualResult.
May be called in any thread.
"""
if self._stopped:
raise ReactorStopped()
self._results.add(result) | [
"def",
"register",
"(",
"self",
",",
"result",
")",
":",
"if",
"self",
".",
"_stopped",
":",
"raise",
"ReactorStopped",
"(",
")",
"self",
".",
"_results",
".",
"add",
"(",
"result",
")"
] | Register an EventualResult.
May be called in any thread. | [
"Register",
"an",
"EventualResult",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/crochet/_eventloop.py#L80-L88 | train |
itamarst/crochet | crochet/_eventloop.py | ResultRegistry.stop | def stop(self):
"""
Indicate no more results will get pushed into EventualResults, since
the reactor has stopped.
This should be called in the reactor thread.
"""
self._stopped = True
for result in self._results:
result._set_result(Failure(ReactorStop... | python | def stop(self):
"""
Indicate no more results will get pushed into EventualResults, since
the reactor has stopped.
This should be called in the reactor thread.
"""
self._stopped = True
for result in self._results:
result._set_result(Failure(ReactorStop... | [
"def",
"stop",
"(",
"self",
")",
":",
"self",
".",
"_stopped",
"=",
"True",
"for",
"result",
"in",
"self",
".",
"_results",
":",
"result",
".",
"_set_result",
"(",
"Failure",
"(",
"ReactorStopped",
"(",
")",
")",
")"
] | Indicate no more results will get pushed into EventualResults, since
the reactor has stopped.
This should be called in the reactor thread. | [
"Indicate",
"no",
"more",
"results",
"will",
"get",
"pushed",
"into",
"EventualResults",
"since",
"the",
"reactor",
"has",
"stopped",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/crochet/_eventloop.py#L91-L100 | train |
itamarst/crochet | crochet/_eventloop.py | EventualResult._connect_deferred | def _connect_deferred(self, deferred):
"""
Hook up the Deferred that that this will be the result of.
Should only be run in Twisted thread, and only called once.
"""
self._deferred = deferred
# Because we use __del__, we need to make sure there are no cycles
# i... | python | def _connect_deferred(self, deferred):
"""
Hook up the Deferred that that this will be the result of.
Should only be run in Twisted thread, and only called once.
"""
self._deferred = deferred
# Because we use __del__, we need to make sure there are no cycles
# i... | [
"def",
"_connect_deferred",
"(",
"self",
",",
"deferred",
")",
":",
"self",
".",
"_deferred",
"=",
"deferred",
"# Because we use __del__, we need to make sure there are no cycles",
"# involving this object, which is why we use a weakref:",
"def",
"put",
"(",
"result",
",",
"e... | Hook up the Deferred that that this will be the result of.
Should only be run in Twisted thread, and only called once. | [
"Hook",
"up",
"the",
"Deferred",
"that",
"that",
"this",
"will",
"be",
"the",
"result",
"of",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/crochet/_eventloop.py#L127-L144 | train |
itamarst/crochet | crochet/_eventloop.py | EventualResult._set_result | def _set_result(self, result):
"""
Set the result of the EventualResult, if not already set.
This can only happen in the reactor thread, either as a result of
Deferred firing, or as a result of ResultRegistry.stop(). So, no need
for thread-safety.
"""
if self._re... | python | def _set_result(self, result):
"""
Set the result of the EventualResult, if not already set.
This can only happen in the reactor thread, either as a result of
Deferred firing, or as a result of ResultRegistry.stop(). So, no need
for thread-safety.
"""
if self._re... | [
"def",
"_set_result",
"(",
"self",
",",
"result",
")",
":",
"if",
"self",
".",
"_result_set",
".",
"isSet",
"(",
")",
":",
"return",
"self",
".",
"_value",
"=",
"result",
"self",
".",
"_result_set",
".",
"set",
"(",
")"
] | Set the result of the EventualResult, if not already set.
This can only happen in the reactor thread, either as a result of
Deferred firing, or as a result of ResultRegistry.stop(). So, no need
for thread-safety. | [
"Set",
"the",
"result",
"of",
"the",
"EventualResult",
"if",
"not",
"already",
"set",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/crochet/_eventloop.py#L146-L157 | train |
itamarst/crochet | crochet/_eventloop.py | EventualResult._result | def _result(self, timeout=None):
"""
Return the result, if available.
It may take an unknown amount of time to return the result, so a
timeout option is provided. If the given number of seconds pass with
no result, a TimeoutError will be thrown.
If a previous call timed... | python | def _result(self, timeout=None):
"""
Return the result, if available.
It may take an unknown amount of time to return the result, so a
timeout option is provided. If the given number of seconds pass with
no result, a TimeoutError will be thrown.
If a previous call timed... | [
"def",
"_result",
"(",
"self",
",",
"timeout",
"=",
"None",
")",
":",
"if",
"timeout",
"is",
"None",
":",
"warnings",
".",
"warn",
"(",
"\"Unlimited timeouts are deprecated.\"",
",",
"DeprecationWarning",
",",
"stacklevel",
"=",
"3",
")",
"# Queue.get(None) won'... | Return the result, if available.
It may take an unknown amount of time to return the result, so a
timeout option is provided. If the given number of seconds pass with
no result, a TimeoutError will be thrown.
If a previous call timed out, additional calls to this function will
... | [
"Return",
"the",
"result",
"if",
"available",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/crochet/_eventloop.py#L177-L203 | train |
itamarst/crochet | crochet/_eventloop.py | EventualResult.wait | def wait(self, timeout=None):
"""
Return the result, or throw the exception if result is a failure.
It may take an unknown amount of time to return the result, so a
timeout option is provided. If the given number of seconds pass with
no result, a TimeoutError will be thrown.
... | python | def wait(self, timeout=None):
"""
Return the result, or throw the exception if result is a failure.
It may take an unknown amount of time to return the result, so a
timeout option is provided. If the given number of seconds pass with
no result, a TimeoutError will be thrown.
... | [
"def",
"wait",
"(",
"self",
",",
"timeout",
"=",
"None",
")",
":",
"if",
"threadable",
".",
"isInIOThread",
"(",
")",
":",
"raise",
"RuntimeError",
"(",
"\"EventualResult.wait() must not be run in the reactor thread.\"",
")",
"if",
"imp",
".",
"lock_held",
"(",
... | Return the result, or throw the exception if result is a failure.
It may take an unknown amount of time to return the result, so a
timeout option is provided. If the given number of seconds pass with
no result, a TimeoutError will be thrown.
If a previous call timed out, additional cal... | [
"Return",
"the",
"result",
"or",
"throw",
"the",
"exception",
"if",
"result",
"is",
"a",
"failure",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/crochet/_eventloop.py#L205-L242 | train |
itamarst/crochet | crochet/_eventloop.py | EventualResult.original_failure | def original_failure(self):
"""
Return the underlying Failure object, if the result is an error.
If no result is yet available, or the result was not an error, None is
returned.
This method is useful if you want to get the original traceback for an
error result.
... | python | def original_failure(self):
"""
Return the underlying Failure object, if the result is an error.
If no result is yet available, or the result was not an error, None is
returned.
This method is useful if you want to get the original traceback for an
error result.
... | [
"def",
"original_failure",
"(",
"self",
")",
":",
"try",
":",
"result",
"=",
"self",
".",
"_result",
"(",
"0.0",
")",
"except",
"TimeoutError",
":",
"return",
"None",
"if",
"isinstance",
"(",
"result",
",",
"Failure",
")",
":",
"return",
"result",
"else"... | Return the underlying Failure object, if the result is an error.
If no result is yet available, or the result was not an error, None is
returned.
This method is useful if you want to get the original traceback for an
error result. | [
"Return",
"the",
"underlying",
"Failure",
"object",
"if",
"the",
"result",
"is",
"an",
"error",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/crochet/_eventloop.py#L253-L270 | train |
itamarst/crochet | crochet/_eventloop.py | EventLoop._startReapingProcesses | def _startReapingProcesses(self):
"""
Start a LoopingCall that calls reapAllProcesses.
"""
lc = LoopingCall(self._reapAllProcesses)
lc.clock = self._reactor
lc.start(0.1, False) | python | def _startReapingProcesses(self):
"""
Start a LoopingCall that calls reapAllProcesses.
"""
lc = LoopingCall(self._reapAllProcesses)
lc.clock = self._reactor
lc.start(0.1, False) | [
"def",
"_startReapingProcesses",
"(",
"self",
")",
":",
"lc",
"=",
"LoopingCall",
"(",
"self",
".",
"_reapAllProcesses",
")",
"lc",
".",
"clock",
"=",
"self",
".",
"_reactor",
"lc",
".",
"start",
"(",
"0.1",
",",
"False",
")"
] | Start a LoopingCall that calls reapAllProcesses. | [
"Start",
"a",
"LoopingCall",
"that",
"calls",
"reapAllProcesses",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/crochet/_eventloop.py#L357-L363 | train |
itamarst/crochet | crochet/_eventloop.py | EventLoop._common_setup | def _common_setup(self):
"""
The minimal amount of setup done by both setup() and no_setup().
"""
self._started = True
self._reactor = self._reactorFactory()
self._registry = ResultRegistry()
# We want to unblock EventualResult regardless of how the reactor is
... | python | def _common_setup(self):
"""
The minimal amount of setup done by both setup() and no_setup().
"""
self._started = True
self._reactor = self._reactorFactory()
self._registry = ResultRegistry()
# We want to unblock EventualResult regardless of how the reactor is
... | [
"def",
"_common_setup",
"(",
"self",
")",
":",
"self",
".",
"_started",
"=",
"True",
"self",
".",
"_reactor",
"=",
"self",
".",
"_reactorFactory",
"(",
")",
"self",
".",
"_registry",
"=",
"ResultRegistry",
"(",
")",
"# We want to unblock EventualResult regardles... | The minimal amount of setup done by both setup() and no_setup(). | [
"The",
"minimal",
"amount",
"of",
"setup",
"done",
"by",
"both",
"setup",
"()",
"and",
"no_setup",
"()",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/crochet/_eventloop.py#L365-L375 | train |
itamarst/crochet | crochet/_eventloop.py | EventLoop.setup | def setup(self):
"""
Initialize the crochet library.
This starts the reactor in a thread, and connect's Twisted's logs to
Python's standard library logging module.
This must be called at least once before the library can be used, and
can be called multiple times.
... | python | def setup(self):
"""
Initialize the crochet library.
This starts the reactor in a thread, and connect's Twisted's logs to
Python's standard library logging module.
This must be called at least once before the library can be used, and
can be called multiple times.
... | [
"def",
"setup",
"(",
"self",
")",
":",
"if",
"self",
".",
"_started",
":",
"return",
"self",
".",
"_common_setup",
"(",
")",
"if",
"platform",
".",
"type",
"==",
"\"posix\"",
":",
"self",
".",
"_reactor",
".",
"callFromThread",
"(",
"self",
".",
"_star... | Initialize the crochet library.
This starts the reactor in a thread, and connect's Twisted's logs to
Python's standard library logging module.
This must be called at least once before the library can be used, and
can be called multiple times. | [
"Initialize",
"the",
"crochet",
"library",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/crochet/_eventloop.py#L378-L418 | train |
itamarst/crochet | crochet/_eventloop.py | EventLoop._run_in_reactor | def _run_in_reactor(self, function, _, args, kwargs):
"""
Implementation: A decorator that ensures the wrapped function runs in
the reactor thread.
When the wrapped function is called, an EventualResult is returned.
"""
def runs_in_reactor(result, args, kwargs):
... | python | def _run_in_reactor(self, function, _, args, kwargs):
"""
Implementation: A decorator that ensures the wrapped function runs in
the reactor thread.
When the wrapped function is called, an EventualResult is returned.
"""
def runs_in_reactor(result, args, kwargs):
... | [
"def",
"_run_in_reactor",
"(",
"self",
",",
"function",
",",
"_",
",",
"args",
",",
"kwargs",
")",
":",
"def",
"runs_in_reactor",
"(",
"result",
",",
"args",
",",
"kwargs",
")",
":",
"d",
"=",
"maybeDeferred",
"(",
"function",
",",
"*",
"args",
",",
... | Implementation: A decorator that ensures the wrapped function runs in
the reactor thread.
When the wrapped function is called, an EventualResult is returned. | [
"Implementation",
":",
"A",
"decorator",
"that",
"ensures",
"the",
"wrapped",
"function",
"runs",
"in",
"the",
"reactor",
"thread",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/crochet/_eventloop.py#L440-L455 | train |
itamarst/crochet | crochet/_eventloop.py | EventLoop.run_in_reactor | def run_in_reactor(self, function):
"""
A decorator that ensures the wrapped function runs in the
reactor thread.
When the wrapped function is called, an EventualResult is returned.
"""
result = self._run_in_reactor(function)
# Backwards compatibility; use __wrap... | python | def run_in_reactor(self, function):
"""
A decorator that ensures the wrapped function runs in the
reactor thread.
When the wrapped function is called, an EventualResult is returned.
"""
result = self._run_in_reactor(function)
# Backwards compatibility; use __wrap... | [
"def",
"run_in_reactor",
"(",
"self",
",",
"function",
")",
":",
"result",
"=",
"self",
".",
"_run_in_reactor",
"(",
"function",
")",
"# Backwards compatibility; use __wrapped__ instead.",
"try",
":",
"result",
".",
"wrapped_function",
"=",
"function",
"except",
"At... | A decorator that ensures the wrapped function runs in the
reactor thread.
When the wrapped function is called, an EventualResult is returned. | [
"A",
"decorator",
"that",
"ensures",
"the",
"wrapped",
"function",
"runs",
"in",
"the",
"reactor",
"thread",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/crochet/_eventloop.py#L457-L470 | train |
itamarst/crochet | crochet/_eventloop.py | EventLoop.wait_for_reactor | def wait_for_reactor(self, function):
"""
DEPRECATED, use wait_for(timeout) instead.
A decorator that ensures the wrapped function runs in the reactor
thread.
When the wrapped function is called, its result is returned or its
exception raised. Deferreds are handled tran... | python | def wait_for_reactor(self, function):
"""
DEPRECATED, use wait_for(timeout) instead.
A decorator that ensures the wrapped function runs in the reactor
thread.
When the wrapped function is called, its result is returned or its
exception raised. Deferreds are handled tran... | [
"def",
"wait_for_reactor",
"(",
"self",
",",
"function",
")",
":",
"warnings",
".",
"warn",
"(",
"\"@wait_for_reactor is deprecated, use @wait_for instead\"",
",",
"DeprecationWarning",
",",
"stacklevel",
"=",
"2",
")",
"# This will timeout, in theory. In practice the process... | DEPRECATED, use wait_for(timeout) instead.
A decorator that ensures the wrapped function runs in the reactor
thread.
When the wrapped function is called, its result is returned or its
exception raised. Deferreds are handled transparently. | [
"DEPRECATED",
"use",
"wait_for",
"(",
"timeout",
")",
"instead",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/crochet/_eventloop.py#L472-L488 | train |
itamarst/crochet | crochet/_eventloop.py | EventLoop.wait_for | def wait_for(self, timeout):
"""
A decorator factory that ensures the wrapped function runs in the
reactor thread.
When the wrapped function is called, its result is returned or its
exception raised. Deferreds are handled transparently. Calls will
timeout after the given... | python | def wait_for(self, timeout):
"""
A decorator factory that ensures the wrapped function runs in the
reactor thread.
When the wrapped function is called, its result is returned or its
exception raised. Deferreds are handled transparently. Calls will
timeout after the given... | [
"def",
"wait_for",
"(",
"self",
",",
"timeout",
")",
":",
"def",
"decorator",
"(",
"function",
")",
":",
"@",
"wrapt",
".",
"decorator",
"def",
"wrapper",
"(",
"function",
",",
"_",
",",
"args",
",",
"kwargs",
")",
":",
"@",
"self",
".",
"run_in_reac... | A decorator factory that ensures the wrapped function runs in the
reactor thread.
When the wrapped function is called, its result is returned or its
exception raised. Deferreds are handled transparently. Calls will
timeout after the given number of seconds (a float), raising a
c... | [
"A",
"decorator",
"factory",
"that",
"ensures",
"the",
"wrapped",
"function",
"runs",
"in",
"the",
"reactor",
"thread",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/crochet/_eventloop.py#L490-L524 | train |
itamarst/crochet | crochet/_eventloop.py | EventLoop.in_reactor | def in_reactor(self, function):
"""
DEPRECATED, use run_in_reactor.
A decorator that ensures the wrapped function runs in the reactor
thread.
The wrapped function will get the reactor passed in as a first
argument, in addition to any arguments it is called with.
... | python | def in_reactor(self, function):
"""
DEPRECATED, use run_in_reactor.
A decorator that ensures the wrapped function runs in the reactor
thread.
The wrapped function will get the reactor passed in as a first
argument, in addition to any arguments it is called with.
... | [
"def",
"in_reactor",
"(",
"self",
",",
"function",
")",
":",
"warnings",
".",
"warn",
"(",
"\"@in_reactor is deprecated, use @run_in_reactor\"",
",",
"DeprecationWarning",
",",
"stacklevel",
"=",
"2",
")",
"@",
"self",
".",
"run_in_reactor",
"@",
"wraps",
"(",
"... | DEPRECATED, use run_in_reactor.
A decorator that ensures the wrapped function runs in the reactor
thread.
The wrapped function will get the reactor passed in as a first
argument, in addition to any arguments it is called with.
When the wrapped function is called, an EventualRe... | [
"DEPRECATED",
"use",
"run_in_reactor",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/crochet/_eventloop.py#L526-L548 | train |
itamarst/crochet | examples/mxquery.py | _mx | def _mx(domain):
"""
Return Deferred that fires with a list of (priority, MX domain) tuples for
a given domain.
"""
def got_records(result):
return sorted(
[(int(record.payload.preference), str(record.payload.name))
for record in result[0]])
d = lookupMailExchang... | python | def _mx(domain):
"""
Return Deferred that fires with a list of (priority, MX domain) tuples for
a given domain.
"""
def got_records(result):
return sorted(
[(int(record.payload.preference), str(record.payload.name))
for record in result[0]])
d = lookupMailExchang... | [
"def",
"_mx",
"(",
"domain",
")",
":",
"def",
"got_records",
"(",
"result",
")",
":",
"return",
"sorted",
"(",
"[",
"(",
"int",
"(",
"record",
".",
"payload",
".",
"preference",
")",
",",
"str",
"(",
"record",
".",
"payload",
".",
"name",
")",
")",... | Return Deferred that fires with a list of (priority, MX domain) tuples for
a given domain. | [
"Return",
"Deferred",
"that",
"fires",
"with",
"a",
"list",
"of",
"(",
"priority",
"MX",
"domain",
")",
"tuples",
"for",
"a",
"given",
"domain",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/examples/mxquery.py#L14-L25 | train |
itamarst/crochet | crochet/_resultstore.py | ResultStore.store | def store(self, deferred_result):
"""
Store a EventualResult.
Return an integer, a unique identifier that can be used to retrieve
the object.
"""
self._counter += 1
self._stored[self._counter] = deferred_result
return self._counter | python | def store(self, deferred_result):
"""
Store a EventualResult.
Return an integer, a unique identifier that can be used to retrieve
the object.
"""
self._counter += 1
self._stored[self._counter] = deferred_result
return self._counter | [
"def",
"store",
"(",
"self",
",",
"deferred_result",
")",
":",
"self",
".",
"_counter",
"+=",
"1",
"self",
".",
"_stored",
"[",
"self",
".",
"_counter",
"]",
"=",
"deferred_result",
"return",
"self",
".",
"_counter"
] | Store a EventualResult.
Return an integer, a unique identifier that can be used to retrieve
the object. | [
"Store",
"a",
"EventualResult",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/crochet/_resultstore.py#L30-L39 | train |
itamarst/crochet | crochet/_resultstore.py | ResultStore.log_errors | def log_errors(self):
"""
Log errors for all stored EventualResults that have error results.
"""
for result in self._stored.values():
failure = result.original_failure()
if failure is not None:
log.err(failure, "Unhandled error in stashed EventualR... | python | def log_errors(self):
"""
Log errors for all stored EventualResults that have error results.
"""
for result in self._stored.values():
failure = result.original_failure()
if failure is not None:
log.err(failure, "Unhandled error in stashed EventualR... | [
"def",
"log_errors",
"(",
"self",
")",
":",
"for",
"result",
"in",
"self",
".",
"_stored",
".",
"values",
"(",
")",
":",
"failure",
"=",
"result",
".",
"original_failure",
"(",
")",
"if",
"failure",
"is",
"not",
"None",
":",
"log",
".",
"err",
"(",
... | Log errors for all stored EventualResults that have error results. | [
"Log",
"errors",
"for",
"all",
"stored",
"EventualResults",
"that",
"have",
"error",
"results",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/crochet/_resultstore.py#L49-L56 | train |
itamarst/crochet | examples/ssh.py | start_ssh_server | def start_ssh_server(port, username, password, namespace):
"""
Start an SSH server on the given port, exposing a Python prompt with the
given namespace.
"""
# This is a lot of boilerplate, see http://tm.tl/6429 for a ticket to
# provide a utility function that simplifies this.
from twisted.i... | python | def start_ssh_server(port, username, password, namespace):
"""
Start an SSH server on the given port, exposing a Python prompt with the
given namespace.
"""
# This is a lot of boilerplate, see http://tm.tl/6429 for a ticket to
# provide a utility function that simplifies this.
from twisted.i... | [
"def",
"start_ssh_server",
"(",
"port",
",",
"username",
",",
"password",
",",
"namespace",
")",
":",
"# This is a lot of boilerplate, see http://tm.tl/6429 for a ticket to",
"# provide a utility function that simplifies this.",
"from",
"twisted",
".",
"internet",
"import",
"re... | Start an SSH server on the given port, exposing a Python prompt with the
given namespace. | [
"Start",
"an",
"SSH",
"server",
"on",
"the",
"given",
"port",
"exposing",
"a",
"Python",
"prompt",
"with",
"the",
"given",
"namespace",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/examples/ssh.py#L40-L61 | train |
itamarst/crochet | crochet/_util.py | _synced | def _synced(method, self, args, kwargs):
"""Underlying synchronized wrapper."""
with self._lock:
return method(*args, **kwargs) | python | def _synced(method, self, args, kwargs):
"""Underlying synchronized wrapper."""
with self._lock:
return method(*args, **kwargs) | [
"def",
"_synced",
"(",
"method",
",",
"self",
",",
"args",
",",
"kwargs",
")",
":",
"with",
"self",
".",
"_lock",
":",
"return",
"method",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | Underlying synchronized wrapper. | [
"Underlying",
"synchronized",
"wrapper",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/crochet/_util.py#L9-L12 | train |
itamarst/crochet | crochet/_shutdown.py | FunctionRegistry.register | def register(self, f, *args, **kwargs):
"""
Register a function and arguments to be called later.
"""
self._functions.append(lambda: f(*args, **kwargs)) | python | def register(self, f, *args, **kwargs):
"""
Register a function and arguments to be called later.
"""
self._functions.append(lambda: f(*args, **kwargs)) | [
"def",
"register",
"(",
"self",
",",
"f",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_functions",
".",
"append",
"(",
"lambda",
":",
"f",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
")"
] | Register a function and arguments to be called later. | [
"Register",
"a",
"function",
"and",
"arguments",
"to",
"be",
"called",
"later",
"."
] | ecfc22cefa90f3dfbafa71883c1470e7294f2b6d | https://github.com/itamarst/crochet/blob/ecfc22cefa90f3dfbafa71883c1470e7294f2b6d/crochet/_shutdown.py#L40-L44 | train |
tkf/python-epc | epc/core.py | EPCDispatcher.register_function | def register_function(self, function, name=None):
"""
Register function to be called from EPC client.
:type function: callable
:arg function: Function to publish.
:type name: str
:arg name: Name by which function is published.
This method returns t... | python | def register_function(self, function, name=None):
"""
Register function to be called from EPC client.
:type function: callable
:arg function: Function to publish.
:type name: str
:arg name: Name by which function is published.
This method returns t... | [
"def",
"register_function",
"(",
"self",
",",
"function",
",",
"name",
"=",
"None",
")",
":",
"if",
"name",
"is",
"None",
":",
"name",
"=",
"function",
".",
"__name__",
"self",
".",
"funcs",
"[",
"name",
"]",
"=",
"function",
"return",
"function"
] | Register function to be called from EPC client.
:type function: callable
:arg function: Function to publish.
:type name: str
:arg name: Name by which function is published.
This method returns the given `function` as-is, so that you
can use it as a decorat... | [
"Register",
"function",
"to",
"be",
"called",
"from",
"EPC",
"client",
"."
] | f3673ae5c35f20a0f71546ab34c28e3dde3595c1 | https://github.com/tkf/python-epc/blob/f3673ae5c35f20a0f71546ab34c28e3dde3595c1/epc/core.py#L57-L73 | train |
tkf/python-epc | epc/core.py | EPCDispatcher.get_method | def get_method(self, name):
"""
Get registered method callend `name`.
"""
try:
return self.funcs[name]
except KeyError:
try:
return self.instance._get_method(name)
except AttributeError:
return SimpleXMLRPCServer... | python | def get_method(self, name):
"""
Get registered method callend `name`.
"""
try:
return self.funcs[name]
except KeyError:
try:
return self.instance._get_method(name)
except AttributeError:
return SimpleXMLRPCServer... | [
"def",
"get_method",
"(",
"self",
",",
"name",
")",
":",
"try",
":",
"return",
"self",
".",
"funcs",
"[",
"name",
"]",
"except",
"KeyError",
":",
"try",
":",
"return",
"self",
".",
"instance",
".",
"_get_method",
"(",
"name",
")",
"except",
"AttributeE... | Get registered method callend `name`. | [
"Get",
"registered",
"method",
"callend",
"name",
"."
] | f3673ae5c35f20a0f71546ab34c28e3dde3595c1 | https://github.com/tkf/python-epc/blob/f3673ae5c35f20a0f71546ab34c28e3dde3595c1/epc/core.py#L75-L86 | train |
tkf/python-epc | epc/core.py | EPCCore.set_debugger | def set_debugger(self, debugger):
"""
Set debugger to run when an error occurs in published method.
You can also set debugger by passing `debugger` argument to
the class constructor.
:type debugger: {'pdb', 'ipdb', None}
:arg debugger: type of debugger.
"""
... | python | def set_debugger(self, debugger):
"""
Set debugger to run when an error occurs in published method.
You can also set debugger by passing `debugger` argument to
the class constructor.
:type debugger: {'pdb', 'ipdb', None}
:arg debugger: type of debugger.
"""
... | [
"def",
"set_debugger",
"(",
"self",
",",
"debugger",
")",
":",
"if",
"debugger",
"==",
"'pdb'",
":",
"import",
"pdb",
"self",
".",
"debugger",
"=",
"pdb",
"elif",
"debugger",
"==",
"'ipdb'",
":",
"import",
"ipdb",
"self",
".",
"debugger",
"=",
"ipdb",
... | Set debugger to run when an error occurs in published method.
You can also set debugger by passing `debugger` argument to
the class constructor.
:type debugger: {'pdb', 'ipdb', None}
:arg debugger: type of debugger. | [
"Set",
"debugger",
"to",
"run",
"when",
"an",
"error",
"occurs",
"in",
"published",
"method",
"."
] | f3673ae5c35f20a0f71546ab34c28e3dde3595c1 | https://github.com/tkf/python-epc/blob/f3673ae5c35f20a0f71546ab34c28e3dde3595c1/epc/core.py#L102-L120 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.