partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
valid | LiveStreamProcess.stop | Stop streaming | pyfire/stream.py | def stop(self):
""" Stop streaming """
if self._protocol:
self._protocol.factory.continueTrying = 0
self._protocol.transport.loseConnection()
if self._reactor and self._reactor.running:
self._reactor.stop() | def stop(self):
""" Stop streaming """
if self._protocol:
self._protocol.factory.continueTrying = 0
self._protocol.transport.loseConnection()
if self._reactor and self._reactor.running:
self._reactor.stop() | [
"Stop",
"streaming"
] | mariano/pyfire | python | https://github.com/mariano/pyfire/blob/42e3490c138abc8e10f2e9f8f8f3b40240a80412/pyfire/stream.py#L316-L324 | [
"def",
"stop",
"(",
"self",
")",
":",
"if",
"self",
".",
"_protocol",
":",
"self",
".",
"_protocol",
".",
"factory",
".",
"continueTrying",
"=",
"0",
"self",
".",
"_protocol",
".",
"transport",
".",
"loseConnection",
"(",
")",
"if",
"self",
".",
"_reac... | 42e3490c138abc8e10f2e9f8f8f3b40240a80412 |
valid | LiveStreamProtocol.connectionMade | Called when a connection is made, and used to send out headers | pyfire/stream.py | def connectionMade(self):
""" Called when a connection is made, and used to send out headers """
headers = [
"GET %s HTTP/1.1" % ("/room/%s/live.json" % self.factory.get_stream().get_room_id())
]
connection_headers = self.factory.get_stream().get_connection().get_headers()
... | def connectionMade(self):
""" Called when a connection is made, and used to send out headers """
headers = [
"GET %s HTTP/1.1" % ("/room/%s/live.json" % self.factory.get_stream().get_room_id())
]
connection_headers = self.factory.get_stream().get_connection().get_headers()
... | [
"Called",
"when",
"a",
"connection",
"is",
"made",
"and",
"used",
"to",
"send",
"out",
"headers"
] | mariano/pyfire | python | https://github.com/mariano/pyfire/blob/42e3490c138abc8e10f2e9f8f8f3b40240a80412/pyfire/stream.py#L350-L364 | [
"def",
"connectionMade",
"(",
"self",
")",
":",
"headers",
"=",
"[",
"\"GET %s HTTP/1.1\"",
"%",
"(",
"\"/room/%s/live.json\"",
"%",
"self",
".",
"factory",
".",
"get_stream",
"(",
")",
".",
"get_room_id",
"(",
")",
")",
"]",
"connection_headers",
"=",
"self... | 42e3490c138abc8e10f2e9f8f8f3b40240a80412 |
valid | LiveStreamProtocol.lineReceived | Callback issued by twisted when new line arrives.
Args:
line (str): Incoming line | pyfire/stream.py | def lineReceived(self, line):
""" Callback issued by twisted when new line arrives.
Args:
line (str): Incoming line
"""
while self._in_header:
if line:
self._headers.append(line)
else:
http, status, message = self._head... | def lineReceived(self, line):
""" Callback issued by twisted when new line arrives.
Args:
line (str): Incoming line
"""
while self._in_header:
if line:
self._headers.append(line)
else:
http, status, message = self._head... | [
"Callback",
"issued",
"by",
"twisted",
"when",
"new",
"line",
"arrives",
"."
] | mariano/pyfire | python | https://github.com/mariano/pyfire/blob/42e3490c138abc8e10f2e9f8f8f3b40240a80412/pyfire/stream.py#L366-L393 | [
"def",
"lineReceived",
"(",
"self",
",",
"line",
")",
":",
"while",
"self",
".",
"_in_header",
":",
"if",
"line",
":",
"self",
".",
"_headers",
".",
"append",
"(",
"line",
")",
"else",
":",
"http",
",",
"status",
",",
"message",
"=",
"self",
".",
"... | 42e3490c138abc8e10f2e9f8f8f3b40240a80412 |
valid | LiveStreamProtocol.rawDataReceived | Process data.
Args:
data (str): Incoming data | pyfire/stream.py | def rawDataReceived(self, data):
""" Process data.
Args:
data (str): Incoming data
"""
if self._len_expected is not None:
data, extra = data[:self._len_expected], data[self._len_expected:]
self._len_expected -= len(data)
else:
extr... | def rawDataReceived(self, data):
""" Process data.
Args:
data (str): Incoming data
"""
if self._len_expected is not None:
data, extra = data[:self._len_expected], data[self._len_expected:]
self._len_expected -= len(data)
else:
extr... | [
"Process",
"data",
"."
] | mariano/pyfire | python | https://github.com/mariano/pyfire/blob/42e3490c138abc8e10f2e9f8f8f3b40240a80412/pyfire/stream.py#L395-L422 | [
"def",
"rawDataReceived",
"(",
"self",
",",
"data",
")",
":",
"if",
"self",
".",
"_len_expected",
"is",
"not",
"None",
":",
"data",
",",
"extra",
"=",
"data",
"[",
":",
"self",
".",
"_len_expected",
"]",
",",
"data",
"[",
"self",
".",
"_len_expected",
... | 42e3490c138abc8e10f2e9f8f8f3b40240a80412 |
valid | Router.get_func | :return: (func, methods) | bustard/router.py | def get_func(self, path):
"""
:return: (func, methods)
"""
for url_match, func_pair in self._urls_regex_map.items():
m = url_match.match(path)
if m is not None:
return func_pair.func, func_pair.methods, m.groupdict()
return None, None, None | def get_func(self, path):
"""
:return: (func, methods)
"""
for url_match, func_pair in self._urls_regex_map.items():
m = url_match.match(path)
if m is not None:
return func_pair.func, func_pair.methods, m.groupdict()
return None, None, None | [
":",
"return",
":",
"(",
"func",
"methods",
")"
] | mozillazg/bustard | python | https://github.com/mozillazg/bustard/blob/bd7b47f3ba5440cf6ea026c8b633060fedeb80b7/bustard/router.py#L24-L32 | [
"def",
"get_func",
"(",
"self",
",",
"path",
")",
":",
"for",
"url_match",
",",
"func_pair",
"in",
"self",
".",
"_urls_regex_map",
".",
"items",
"(",
")",
":",
"m",
"=",
"url_match",
".",
"match",
"(",
"path",
")",
"if",
"m",
"is",
"not",
"None",
"... | bd7b47f3ba5440cf6ea026c8b633060fedeb80b7 |
valid | URLBuilder._replace_type_to_regex | /<int:id> -> r'(?P<id>\d+)' | bustard/router.py | def _replace_type_to_regex(cls, match):
""" /<int:id> -> r'(?P<id>\d+)' """
groupdict = match.groupdict()
_type = groupdict.get('type')
type_regex = cls.TYPE_REGEX_MAP.get(_type, '[^/]+')
name = groupdict.get('name')
return r'(?P<{name}>{type_regex})'.format(
... | def _replace_type_to_regex(cls, match):
""" /<int:id> -> r'(?P<id>\d+)' """
groupdict = match.groupdict()
_type = groupdict.get('type')
type_regex = cls.TYPE_REGEX_MAP.get(_type, '[^/]+')
name = groupdict.get('name')
return r'(?P<{name}>{type_regex})'.format(
... | [
"/",
"<int",
":",
"id",
">",
"-",
">",
"r",
"(",
"?P<id",
">",
"\\",
"d",
"+",
")"
] | mozillazg/bustard | python | https://github.com/mozillazg/bustard/blob/bd7b47f3ba5440cf6ea026c8b633060fedeb80b7/bustard/router.py#L94-L102 | [
"def",
"_replace_type_to_regex",
"(",
"cls",
",",
"match",
")",
":",
"groupdict",
"=",
"match",
".",
"groupdict",
"(",
")",
"_type",
"=",
"groupdict",
".",
"get",
"(",
"'type'",
")",
"type_regex",
"=",
"cls",
".",
"TYPE_REGEX_MAP",
".",
"get",
"(",
"_typ... | bd7b47f3ba5440cf6ea026c8b633060fedeb80b7 |
valid | _InvenioCSLRESTState.styles | Get a dictionary of CSL styles. | invenio_csl_rest/ext.py | def styles(self):
"""Get a dictionary of CSL styles."""
styles = get_all_styles()
whitelist = self.app.config.get('CSL_STYLES_WHITELIST')
if whitelist:
return {k: v for k, v in styles.items() if k in whitelist}
return styles | def styles(self):
"""Get a dictionary of CSL styles."""
styles = get_all_styles()
whitelist = self.app.config.get('CSL_STYLES_WHITELIST')
if whitelist:
return {k: v for k, v in styles.items() if k in whitelist}
return styles | [
"Get",
"a",
"dictionary",
"of",
"CSL",
"styles",
"."
] | inveniosoftware/invenio-csl-rest | python | https://github.com/inveniosoftware/invenio-csl-rest/blob/a474a5b4caa9e6ae841a007fa52b30ad7e957560/invenio_csl_rest/ext.py#L43-L49 | [
"def",
"styles",
"(",
"self",
")",
":",
"styles",
"=",
"get_all_styles",
"(",
")",
"whitelist",
"=",
"self",
".",
"app",
".",
"config",
".",
"get",
"(",
"'CSL_STYLES_WHITELIST'",
")",
"if",
"whitelist",
":",
"return",
"{",
"k",
":",
"v",
"for",
"k",
... | a474a5b4caa9e6ae841a007fa52b30ad7e957560 |
valid | InvenioCSLREST.init_app | Flask application initialization. | invenio_csl_rest/ext.py | def init_app(self, app):
"""Flask application initialization."""
state = _InvenioCSLRESTState(app)
app.extensions['invenio-csl-rest'] = state
return state | def init_app(self, app):
"""Flask application initialization."""
state = _InvenioCSLRESTState(app)
app.extensions['invenio-csl-rest'] = state
return state | [
"Flask",
"application",
"initialization",
"."
] | inveniosoftware/invenio-csl-rest | python | https://github.com/inveniosoftware/invenio-csl-rest/blob/a474a5b4caa9e6ae841a007fa52b30ad7e957560/invenio_csl_rest/ext.py#L72-L76 | [
"def",
"init_app",
"(",
"self",
",",
"app",
")",
":",
"state",
"=",
"_InvenioCSLRESTState",
"(",
"app",
")",
"app",
".",
"extensions",
"[",
"'invenio-csl-rest'",
"]",
"=",
"state",
"return",
"state"
] | a474a5b4caa9e6ae841a007fa52b30ad7e957560 |
valid | MultiPartProducer.startProducing | Start producing.
Args:
consumer: Consumer | pyfire/twistedx/producer.py | def startProducing(self, consumer):
""" Start producing.
Args:
consumer: Consumer
"""
self._consumer = consumer
self._current_deferred = defer.Deferred()
self._sent = 0
self._paused = False
if not hasattr(self, "_chunk_headers"):
... | def startProducing(self, consumer):
""" Start producing.
Args:
consumer: Consumer
"""
self._consumer = consumer
self._current_deferred = defer.Deferred()
self._sent = 0
self._paused = False
if not hasattr(self, "_chunk_headers"):
... | [
"Start",
"producing",
"."
] | mariano/pyfire | python | https://github.com/mariano/pyfire/blob/42e3490c138abc8e10f2e9f8f8f3b40240a80412/pyfire/twistedx/producer.py#L42-L80 | [
"def",
"startProducing",
"(",
"self",
",",
"consumer",
")",
":",
"self",
".",
"_consumer",
"=",
"consumer",
"self",
".",
"_current_deferred",
"=",
"defer",
".",
"Deferred",
"(",
")",
"self",
".",
"_sent",
"=",
"0",
"self",
".",
"_paused",
"=",
"False",
... | 42e3490c138abc8e10f2e9f8f8f3b40240a80412 |
valid | MultiPartProducer.resumeProducing | Resume producing | pyfire/twistedx/producer.py | def resumeProducing(self):
""" Resume producing """
self._paused = False
result = self._produce()
if result:
return result | def resumeProducing(self):
""" Resume producing """
self._paused = False
result = self._produce()
if result:
return result | [
"Resume",
"producing"
] | mariano/pyfire | python | https://github.com/mariano/pyfire/blob/42e3490c138abc8e10f2e9f8f8f3b40240a80412/pyfire/twistedx/producer.py#L82-L87 | [
"def",
"resumeProducing",
"(",
"self",
")",
":",
"self",
".",
"_paused",
"=",
"False",
"result",
"=",
"self",
".",
"_produce",
"(",
")",
"if",
"result",
":",
"return",
"result"
] | 42e3490c138abc8e10f2e9f8f8f3b40240a80412 |
valid | MultiPartProducer.stopProducing | Stop producing | pyfire/twistedx/producer.py | def stopProducing(self):
""" Stop producing """
self._finish(True)
if self._deferred and self._sent < self.length:
self._deferred.errback(Exception("Consumer asked to stop production of request body (%d sent out of %d)" % (self._sent, self.length))) | def stopProducing(self):
""" Stop producing """
self._finish(True)
if self._deferred and self._sent < self.length:
self._deferred.errback(Exception("Consumer asked to stop production of request body (%d sent out of %d)" % (self._sent, self.length))) | [
"Stop",
"producing"
] | mariano/pyfire | python | https://github.com/mariano/pyfire/blob/42e3490c138abc8e10f2e9f8f8f3b40240a80412/pyfire/twistedx/producer.py#L93-L97 | [
"def",
"stopProducing",
"(",
"self",
")",
":",
"self",
".",
"_finish",
"(",
"True",
")",
"if",
"self",
".",
"_deferred",
"and",
"self",
".",
"_sent",
"<",
"self",
".",
"length",
":",
"self",
".",
"_deferred",
".",
"errback",
"(",
"Exception",
"(",
"\... | 42e3490c138abc8e10f2e9f8f8f3b40240a80412 |
valid | MultiPartProducer._finish | Cleanup code after asked to stop producing.
Kwargs:
forced (bool): If True, we were forced to stop | pyfire/twistedx/producer.py | def _finish(self, forced=False):
""" Cleanup code after asked to stop producing.
Kwargs:
forced (bool): If True, we were forced to stop
"""
if hasattr(self, "_current_file_handle") and self._current_file_handle:
self._current_file_handle.close()
... | def _finish(self, forced=False):
""" Cleanup code after asked to stop producing.
Kwargs:
forced (bool): If True, we were forced to stop
"""
if hasattr(self, "_current_file_handle") and self._current_file_handle:
self._current_file_handle.close()
... | [
"Cleanup",
"code",
"after",
"asked",
"to",
"stop",
"producing",
"."
] | mariano/pyfire | python | https://github.com/mariano/pyfire/blob/42e3490c138abc8e10f2e9f8f8f3b40240a80412/pyfire/twistedx/producer.py#L135-L149 | [
"def",
"_finish",
"(",
"self",
",",
"forced",
"=",
"False",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"\"_current_file_handle\"",
")",
"and",
"self",
".",
"_current_file_handle",
":",
"self",
".",
"_current_file_handle",
".",
"close",
"(",
")",
"if",
"s... | 42e3490c138abc8e10f2e9f8f8f3b40240a80412 |
valid | MultiPartProducer._send_to_consumer | Send a block of bytes to the consumer.
Args:
block (str): Block of bytes | pyfire/twistedx/producer.py | def _send_to_consumer(self, block):
""" Send a block of bytes to the consumer.
Args:
block (str): Block of bytes
"""
self._consumer.write(block)
self._sent += len(block)
if self._callback:
self._callback(self._sent, self.length) | def _send_to_consumer(self, block):
""" Send a block of bytes to the consumer.
Args:
block (str): Block of bytes
"""
self._consumer.write(block)
self._sent += len(block)
if self._callback:
self._callback(self._sent, self.length) | [
"Send",
"a",
"block",
"of",
"bytes",
"to",
"the",
"consumer",
"."
] | mariano/pyfire | python | https://github.com/mariano/pyfire/blob/42e3490c138abc8e10f2e9f8f8f3b40240a80412/pyfire/twistedx/producer.py#L151-L160 | [
"def",
"_send_to_consumer",
"(",
"self",
",",
"block",
")",
":",
"self",
".",
"_consumer",
".",
"write",
"(",
"block",
")",
"self",
".",
"_sent",
"+=",
"len",
"(",
"block",
")",
"if",
"self",
".",
"_callback",
":",
"self",
".",
"_callback",
"(",
"sel... | 42e3490c138abc8e10f2e9f8f8f3b40240a80412 |
valid | MultiPartProducer._length | Returns total length for this request.
Returns:
int. Length | pyfire/twistedx/producer.py | def _length(self):
""" Returns total length for this request.
Returns:
int. Length
"""
self._build_chunk_headers()
length = 0
if self._data:
for field in self._data:
length += len(self._chunk_headers[field])
lengt... | def _length(self):
""" Returns total length for this request.
Returns:
int. Length
"""
self._build_chunk_headers()
length = 0
if self._data:
for field in self._data:
length += len(self._chunk_headers[field])
lengt... | [
"Returns",
"total",
"length",
"for",
"this",
"request",
"."
] | mariano/pyfire | python | https://github.com/mariano/pyfire/blob/42e3490c138abc8e10f2e9f8f8f3b40240a80412/pyfire/twistedx/producer.py#L162-L187 | [
"def",
"_length",
"(",
"self",
")",
":",
"self",
".",
"_build_chunk_headers",
"(",
")",
"length",
"=",
"0",
"if",
"self",
".",
"_data",
":",
"for",
"field",
"in",
"self",
".",
"_data",
":",
"length",
"+=",
"len",
"(",
"self",
".",
"_chunk_headers",
"... | 42e3490c138abc8e10f2e9f8f8f3b40240a80412 |
valid | MultiPartProducer._build_chunk_headers | Build headers for each field. | pyfire/twistedx/producer.py | def _build_chunk_headers(self):
""" Build headers for each field. """
if hasattr(self, "_chunk_headers") and self._chunk_headers:
return
self._chunk_headers = {}
for field in self._files:
self._chunk_headers[field] = self._headers(field, True)
for field i... | def _build_chunk_headers(self):
""" Build headers for each field. """
if hasattr(self, "_chunk_headers") and self._chunk_headers:
return
self._chunk_headers = {}
for field in self._files:
self._chunk_headers[field] = self._headers(field, True)
for field i... | [
"Build",
"headers",
"for",
"each",
"field",
"."
] | mariano/pyfire | python | https://github.com/mariano/pyfire/blob/42e3490c138abc8e10f2e9f8f8f3b40240a80412/pyfire/twistedx/producer.py#L189-L198 | [
"def",
"_build_chunk_headers",
"(",
"self",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"\"_chunk_headers\"",
")",
"and",
"self",
".",
"_chunk_headers",
":",
"return",
"self",
".",
"_chunk_headers",
"=",
"{",
"}",
"for",
"field",
"in",
"self",
".",
"_file... | 42e3490c138abc8e10f2e9f8f8f3b40240a80412 |
valid | MultiPartProducer._headers | Returns the header of the encoding of this parameter.
Args:
name (str): Field name
Kwargs:
is_file (bool): If true, this is a file field
Returns:
array. Headers | pyfire/twistedx/producer.py | def _headers(self, name, is_file=False):
""" Returns the header of the encoding of this parameter.
Args:
name (str): Field name
Kwargs:
is_file (bool): If true, this is a file field
Returns:
array. Headers
"""
... | def _headers(self, name, is_file=False):
""" Returns the header of the encoding of this parameter.
Args:
name (str): Field name
Kwargs:
is_file (bool): If true, this is a file field
Returns:
array. Headers
"""
... | [
"Returns",
"the",
"header",
"of",
"the",
"encoding",
"of",
"this",
"parameter",
".",
"Args",
":",
"name",
"(",
"str",
")",
":",
"Field",
"name",
"Kwargs",
":",
"is_file",
"(",
"bool",
")",
":",
"If",
"true",
"this",
"is",
"a",
"file",
"field",
"Retur... | mariano/pyfire | python | https://github.com/mariano/pyfire/blob/42e3490c138abc8e10f2e9f8f8f3b40240a80412/pyfire/twistedx/producer.py#L200-L239 | [
"def",
"_headers",
"(",
"self",
",",
"name",
",",
"is_file",
"=",
"False",
")",
":",
"value",
"=",
"self",
".",
"_files",
"[",
"name",
"]",
"if",
"is_file",
"else",
"self",
".",
"_data",
"[",
"name",
"]",
"_boundary",
"=",
"self",
".",
"boundary",
... | 42e3490c138abc8e10f2e9f8f8f3b40240a80412 |
valid | MultiPartProducer._boundary | Returns a random string to use as the boundary for a message.
Returns:
string. Boundary | pyfire/twistedx/producer.py | def _boundary(self):
""" Returns a random string to use as the boundary for a message.
Returns:
string. Boundary
"""
boundary = None
try:
import uuid
boundary = uuid.uuid4().hex
except ImportError:
import random, sh... | def _boundary(self):
""" Returns a random string to use as the boundary for a message.
Returns:
string. Boundary
"""
boundary = None
try:
import uuid
boundary = uuid.uuid4().hex
except ImportError:
import random, sh... | [
"Returns",
"a",
"random",
"string",
"to",
"use",
"as",
"the",
"boundary",
"for",
"a",
"message",
".",
"Returns",
":",
"string",
".",
"Boundary"
] | mariano/pyfire | python | https://github.com/mariano/pyfire/blob/42e3490c138abc8e10f2e9f8f8f3b40240a80412/pyfire/twistedx/producer.py#L241-L255 | [
"def",
"_boundary",
"(",
"self",
")",
":",
"boundary",
"=",
"None",
"try",
":",
"import",
"uuid",
"boundary",
"=",
"uuid",
".",
"uuid4",
"(",
")",
".",
"hex",
"except",
"ImportError",
":",
"import",
"random",
",",
"sha",
"bits",
"=",
"random",
".",
"... | 42e3490c138abc8e10f2e9f8f8f3b40240a80412 |
valid | MultiPartProducer._file_type | Returns file type for given file field.
Args:
field (str): File field
Returns:
string. File type | pyfire/twistedx/producer.py | def _file_type(self, field):
""" Returns file type for given file field.
Args:
field (str): File field
Returns:
string. File type
"""
type = mimetypes.guess_type(self._files[field])[0]
return type.encode("utf-8") if isinstance(type, unico... | def _file_type(self, field):
""" Returns file type for given file field.
Args:
field (str): File field
Returns:
string. File type
"""
type = mimetypes.guess_type(self._files[field])[0]
return type.encode("utf-8") if isinstance(type, unico... | [
"Returns",
"file",
"type",
"for",
"given",
"file",
"field",
".",
"Args",
":",
"field",
"(",
"str",
")",
":",
"File",
"field"
] | mariano/pyfire | python | https://github.com/mariano/pyfire/blob/42e3490c138abc8e10f2e9f8f8f3b40240a80412/pyfire/twistedx/producer.py#L257-L267 | [
"def",
"_file_type",
"(",
"self",
",",
"field",
")",
":",
"type",
"=",
"mimetypes",
".",
"guess_type",
"(",
"self",
".",
"_files",
"[",
"field",
"]",
")",
"[",
"0",
"]",
"return",
"type",
".",
"encode",
"(",
"\"utf-8\"",
")",
"if",
"isinstance",
"(",... | 42e3490c138abc8e10f2e9f8f8f3b40240a80412 |
valid | MultiPartProducer._file_size | Returns the file size for given file field.
Args:
field (str): File field
Returns:
int. File size | pyfire/twistedx/producer.py | def _file_size(self, field):
""" Returns the file size for given file field.
Args:
field (str): File field
Returns:
int. File size
"""
size = 0
try:
handle = open(self._files[field], "r")
size = os.fstat(handle.fileno()).s... | def _file_size(self, field):
""" Returns the file size for given file field.
Args:
field (str): File field
Returns:
int. File size
"""
size = 0
try:
handle = open(self._files[field], "r")
size = os.fstat(handle.fileno()).s... | [
"Returns",
"the",
"file",
"size",
"for",
"given",
"file",
"field",
"."
] | mariano/pyfire | python | https://github.com/mariano/pyfire/blob/42e3490c138abc8e10f2e9f8f8f3b40240a80412/pyfire/twistedx/producer.py#L269-L286 | [
"def",
"_file_size",
"(",
"self",
",",
"field",
")",
":",
"size",
"=",
"0",
"try",
":",
"handle",
"=",
"open",
"(",
"self",
".",
"_files",
"[",
"field",
"]",
",",
"\"r\"",
")",
"size",
"=",
"os",
".",
"fstat",
"(",
"handle",
".",
"fileno",
"(",
... | 42e3490c138abc8e10f2e9f8f8f3b40240a80412 |
valid | _filename | Generate a path value of type result_type.
result_type can either be bytes or text_type | hypothesis_fspaths.py | def _filename(draw, result_type=None):
"""Generate a path value of type result_type.
result_type can either be bytes or text_type
"""
# Various ASCII chars have a special meaning for the operating system,
# so make them more common
ascii_char = characters(min_codepoint=0x01, max_codepoint=0x7f... | def _filename(draw, result_type=None):
"""Generate a path value of type result_type.
result_type can either be bytes or text_type
"""
# Various ASCII chars have a special meaning for the operating system,
# so make them more common
ascii_char = characters(min_codepoint=0x01, max_codepoint=0x7f... | [
"Generate",
"a",
"path",
"value",
"of",
"type",
"result_type",
"."
] | lazka/hypothesis-fspaths | python | https://github.com/lazka/hypothesis-fspaths/blob/19edb40a91ae4055bccf125a1e0b1796fa2e6a5c/hypothesis_fspaths.py#L53-L101 | [
"def",
"_filename",
"(",
"draw",
",",
"result_type",
"=",
"None",
")",
":",
"# Various ASCII chars have a special meaning for the operating system,",
"# so make them more common",
"ascii_char",
"=",
"characters",
"(",
"min_codepoint",
"=",
"0x01",
",",
"max_codepoint",
"=",... | 19edb40a91ae4055bccf125a1e0b1796fa2e6a5c |
valid | _str_to_path | Given an ASCII str, returns a path of the given type. | hypothesis_fspaths.py | def _str_to_path(s, result_type):
"""Given an ASCII str, returns a path of the given type."""
assert isinstance(s, str)
if isinstance(s, bytes) and result_type is text_type:
return s.decode('ascii')
elif isinstance(s, text_type) and result_type is bytes:
return s.encode('ascii')
ret... | def _str_to_path(s, result_type):
"""Given an ASCII str, returns a path of the given type."""
assert isinstance(s, str)
if isinstance(s, bytes) and result_type is text_type:
return s.decode('ascii')
elif isinstance(s, text_type) and result_type is bytes:
return s.encode('ascii')
ret... | [
"Given",
"an",
"ASCII",
"str",
"returns",
"a",
"path",
"of",
"the",
"given",
"type",
"."
] | lazka/hypothesis-fspaths | python | https://github.com/lazka/hypothesis-fspaths/blob/19edb40a91ae4055bccf125a1e0b1796fa2e6a5c/hypothesis_fspaths.py#L104-L112 | [
"def",
"_str_to_path",
"(",
"s",
",",
"result_type",
")",
":",
"assert",
"isinstance",
"(",
"s",
",",
"str",
")",
"if",
"isinstance",
"(",
"s",
",",
"bytes",
")",
"and",
"result_type",
"is",
"text_type",
":",
"return",
"s",
".",
"decode",
"(",
"'ascii'... | 19edb40a91ae4055bccf125a1e0b1796fa2e6a5c |
valid | _path_root | Generates a root component for a path. | hypothesis_fspaths.py | def _path_root(draw, result_type):
"""Generates a root component for a path."""
# Based on https://en.wikipedia.org/wiki/Path_(computing)
def tp(s=''):
return _str_to_path(s, result_type)
if os.name != 'nt':
return tp(os.sep)
sep = sampled_from([os.sep, os.altsep or os.sep]).map(... | def _path_root(draw, result_type):
"""Generates a root component for a path."""
# Based on https://en.wikipedia.org/wiki/Path_(computing)
def tp(s=''):
return _str_to_path(s, result_type)
if os.name != 'nt':
return tp(os.sep)
sep = sampled_from([os.sep, os.altsep or os.sep]).map(... | [
"Generates",
"a",
"root",
"component",
"for",
"a",
"path",
"."
] | lazka/hypothesis-fspaths | python | https://github.com/lazka/hypothesis-fspaths/blob/19edb40a91ae4055bccf125a1e0b1796fa2e6a5c/hypothesis_fspaths.py#L116-L156 | [
"def",
"_path_root",
"(",
"draw",
",",
"result_type",
")",
":",
"# Based on https://en.wikipedia.org/wiki/Path_(computing)",
"def",
"tp",
"(",
"s",
"=",
"''",
")",
":",
"return",
"_str_to_path",
"(",
"s",
",",
"result_type",
")",
"if",
"os",
".",
"name",
"!=",... | 19edb40a91ae4055bccf125a1e0b1796fa2e6a5c |
valid | fspaths | A strategy which generates filesystem path values.
The generated values include everything which the builtin
:func:`python:open` function accepts i.e. which won't lead to
:exc:`ValueError` or :exc:`TypeError` being raised.
Note that the range of the returned values depends on the operating
system,... | hypothesis_fspaths.py | def fspaths(draw, allow_pathlike=None):
"""A strategy which generates filesystem path values.
The generated values include everything which the builtin
:func:`python:open` function accepts i.e. which won't lead to
:exc:`ValueError` or :exc:`TypeError` being raised.
Note that the range of the retur... | def fspaths(draw, allow_pathlike=None):
"""A strategy which generates filesystem path values.
The generated values include everything which the builtin
:func:`python:open` function accepts i.e. which won't lead to
:exc:`ValueError` or :exc:`TypeError` being raised.
Note that the range of the retur... | [
"A",
"strategy",
"which",
"generates",
"filesystem",
"path",
"values",
"."
] | lazka/hypothesis-fspaths | python | https://github.com/lazka/hypothesis-fspaths/blob/19edb40a91ae4055bccf125a1e0b1796fa2e6a5c/hypothesis_fspaths.py#L161-L215 | [
"def",
"fspaths",
"(",
"draw",
",",
"allow_pathlike",
"=",
"None",
")",
":",
"has_pathlike",
"=",
"hasattr",
"(",
"os",
",",
"'PathLike'",
")",
"if",
"allow_pathlike",
"is",
"None",
":",
"allow_pathlike",
"=",
"has_pathlike",
"if",
"allow_pathlike",
"and",
"... | 19edb40a91ae4055bccf125a1e0b1796fa2e6a5c |
valid | CodeBuilder._exec | exec compiled code | bustard/template.py | def _exec(self, globals_dict=None):
"""exec compiled code"""
globals_dict = globals_dict or {}
globals_dict.setdefault('__builtins__', {})
exec(self._code, globals_dict)
return globals_dict | def _exec(self, globals_dict=None):
"""exec compiled code"""
globals_dict = globals_dict or {}
globals_dict.setdefault('__builtins__', {})
exec(self._code, globals_dict)
return globals_dict | [
"exec",
"compiled",
"code"
] | mozillazg/bustard | python | https://github.com/mozillazg/bustard/blob/bd7b47f3ba5440cf6ea026c8b633060fedeb80b7/bustard/template.py#L54-L59 | [
"def",
"_exec",
"(",
"self",
",",
"globals_dict",
"=",
"None",
")",
":",
"globals_dict",
"=",
"globals_dict",
"or",
"{",
"}",
"globals_dict",
".",
"setdefault",
"(",
"'__builtins__'",
",",
"{",
"}",
")",
"exec",
"(",
"self",
".",
"_code",
",",
"globals_d... | bd7b47f3ba5440cf6ea026c8b633060fedeb80b7 |
valid | Template.handle_extends | replace all blocks in extends with current blocks | bustard/template.py | def handle_extends(self, text):
"""replace all blocks in extends with current blocks"""
match = self.re_extends.match(text)
if match:
extra_text = self.re_extends.sub('', text, count=1)
blocks = self.get_blocks(extra_text)
path = os.path.join(self.base_dir, ma... | def handle_extends(self, text):
"""replace all blocks in extends with current blocks"""
match = self.re_extends.match(text)
if match:
extra_text = self.re_extends.sub('', text, count=1)
blocks = self.get_blocks(extra_text)
path = os.path.join(self.base_dir, ma... | [
"replace",
"all",
"blocks",
"in",
"extends",
"with",
"current",
"blocks"
] | mozillazg/bustard | python | https://github.com/mozillazg/bustard/blob/bd7b47f3ba5440cf6ea026c8b633060fedeb80b7/bustard/template.py#L267-L277 | [
"def",
"handle_extends",
"(",
"self",
",",
"text",
")",
":",
"match",
"=",
"self",
".",
"re_extends",
".",
"match",
"(",
"text",
")",
"if",
"match",
":",
"extra_text",
"=",
"self",
".",
"re_extends",
".",
"sub",
"(",
"''",
",",
"text",
",",
"count",
... | bd7b47f3ba5440cf6ea026c8b633060fedeb80b7 |
valid | Template.flush_buffer | flush all buffered string into code | bustard/template.py | def flush_buffer(self):
"""flush all buffered string into code"""
self.code_builder.add_line('{0}.extend([{1}])',
self.result_var, ','.join(self.buffered))
self.buffered = [] | def flush_buffer(self):
"""flush all buffered string into code"""
self.code_builder.add_line('{0}.extend([{1}])',
self.result_var, ','.join(self.buffered))
self.buffered = [] | [
"flush",
"all",
"buffered",
"string",
"into",
"code"
] | mozillazg/bustard | python | https://github.com/mozillazg/bustard/blob/bd7b47f3ba5440cf6ea026c8b633060fedeb80b7/bustard/template.py#L306-L310 | [
"def",
"flush_buffer",
"(",
"self",
")",
":",
"self",
".",
"code_builder",
".",
"add_line",
"(",
"'{0}.extend([{1}])'",
",",
"self",
".",
"result_var",
",",
"','",
".",
"join",
"(",
"self",
".",
"buffered",
")",
")",
"self",
".",
"buffered",
"=",
"[",
... | bd7b47f3ba5440cf6ea026c8b633060fedeb80b7 |
valid | Template.strip_token | {{ a }} -> a | bustard/template.py | def strip_token(self, text, start, end):
"""{{ a }} -> a"""
text = text.replace(start, '', 1)
text = text.replace(end, '', 1)
return text | def strip_token(self, text, start, end):
"""{{ a }} -> a"""
text = text.replace(start, '', 1)
text = text.replace(end, '', 1)
return text | [
"{{",
"a",
"}}",
"-",
">",
"a"
] | mozillazg/bustard | python | https://github.com/mozillazg/bustard/blob/bd7b47f3ba5440cf6ea026c8b633060fedeb80b7/bustard/template.py#L312-L316 | [
"def",
"strip_token",
"(",
"self",
",",
"text",
",",
"start",
",",
"end",
")",
":",
"text",
"=",
"text",
".",
"replace",
"(",
"start",
",",
"''",
",",
"1",
")",
"text",
"=",
"text",
".",
"replace",
"(",
"end",
",",
"''",
",",
"1",
")",
"return"... | bd7b47f3ba5440cf6ea026c8b633060fedeb80b7 |
valid | Upload.run | Called by the thread, it runs the process.
NEVER call this method directly. Instead call start() to start the thread.
Before finishing the thread using this thread, call join() | pyfire/upload.py | def run(self):
""" Called by the thread, it runs the process.
NEVER call this method directly. Instead call start() to start the thread.
Before finishing the thread using this thread, call join()
"""
queue = Queue()
process = UploadProcess(self._connection_settings, sel... | def run(self):
""" Called by the thread, it runs the process.
NEVER call this method directly. Instead call start() to start the thread.
Before finishing the thread using this thread, call join()
"""
queue = Queue()
process = UploadProcess(self._connection_settings, sel... | [
"Called",
"by",
"the",
"thread",
"it",
"runs",
"the",
"process",
"."
] | mariano/pyfire | python | https://github.com/mariano/pyfire/blob/42e3490c138abc8e10f2e9f8f8f3b40240a80412/pyfire/upload.py#L60-L110 | [
"def",
"run",
"(",
"self",
")",
":",
"queue",
"=",
"Queue",
"(",
")",
"process",
"=",
"UploadProcess",
"(",
"self",
".",
"_connection_settings",
",",
"self",
".",
"_room",
",",
"queue",
",",
"self",
".",
"_files",
")",
"if",
"self",
".",
"_data",
":"... | 42e3490c138abc8e10f2e9f8f8f3b40240a80412 |
valid | UploadProcess.add_data | Add POST data.
Args:
data (dict): key => value dictionary | pyfire/upload.py | def add_data(self, data):
""" Add POST data.
Args:
data (dict): key => value dictionary
"""
if not self._data:
self._data = {}
self._data.update(data) | def add_data(self, data):
""" Add POST data.
Args:
data (dict): key => value dictionary
"""
if not self._data:
self._data = {}
self._data.update(data) | [
"Add",
"POST",
"data",
"."
] | mariano/pyfire | python | https://github.com/mariano/pyfire/blob/42e3490c138abc8e10f2e9f8f8f3b40240a80412/pyfire/upload.py#L134-L142 | [
"def",
"add_data",
"(",
"self",
",",
"data",
")",
":",
"if",
"not",
"self",
".",
"_data",
":",
"self",
".",
"_data",
"=",
"{",
"}",
"self",
".",
"_data",
".",
"update",
"(",
"data",
")"
] | 42e3490c138abc8e10f2e9f8f8f3b40240a80412 |
valid | UploadProcess.run | Called by the process, it runs it.
NEVER call this method directly. Instead call start() to start the separate process.
If you don't want to use a second process, then call fetch() directly on this istance.
To stop, call terminate() | pyfire/upload.py | def run(self):
""" Called by the process, it runs it.
NEVER call this method directly. Instead call start() to start the separate process.
If you don't want to use a second process, then call fetch() directly on this istance.
To stop, call terminate()
"""
producer_defe... | def run(self):
""" Called by the process, it runs it.
NEVER call this method directly. Instead call start() to start the separate process.
If you don't want to use a second process, then call fetch() directly on this istance.
To stop, call terminate()
"""
producer_defe... | [
"Called",
"by",
"the",
"process",
"it",
"runs",
"it",
"."
] | mariano/pyfire | python | https://github.com/mariano/pyfire/blob/42e3490c138abc8e10f2e9f8f8f3b40240a80412/pyfire/upload.py#L144-L183 | [
"def",
"run",
"(",
"self",
")",
":",
"producer_deferred",
"=",
"defer",
".",
"Deferred",
"(",
")",
"producer_deferred",
".",
"addCallback",
"(",
"self",
".",
"_request_finished",
")",
"producer_deferred",
".",
"addErrback",
"(",
"self",
".",
"_request_error",
... | 42e3490c138abc8e10f2e9f8f8f3b40240a80412 |
valid | API.log_error | Given some error text it will log the text if self.log_errors is True
:param text: Error text to log | tweebo_parser/api.py | def log_error(self, text: str) -> None:
'''
Given some error text it will log the text if self.log_errors is True
:param text: Error text to log
'''
if self.log_errors:
with self._log_fp.open('a+') as log_file:
log_file.write(f'{text}\n') | def log_error(self, text: str) -> None:
'''
Given some error text it will log the text if self.log_errors is True
:param text: Error text to log
'''
if self.log_errors:
with self._log_fp.open('a+') as log_file:
log_file.write(f'{text}\n') | [
"Given",
"some",
"error",
"text",
"it",
"will",
"log",
"the",
"text",
"if",
"self",
".",
"log_errors",
"is",
"True"
] | apmoore1/tweebo_parser_python_api | python | https://github.com/apmoore1/tweebo_parser_python_api/blob/224be2570b8b2508d29771f5e5abe06e1889fd89/tweebo_parser/api.py#L47-L55 | [
"def",
"log_error",
"(",
"self",
",",
"text",
":",
"str",
")",
"->",
"None",
":",
"if",
"self",
".",
"log_errors",
":",
"with",
"self",
".",
"_log_fp",
".",
"open",
"(",
"'a+'",
")",
"as",
"log_file",
":",
"log_file",
".",
"write",
"(",
"f'{text}\\n'... | 224be2570b8b2508d29771f5e5abe06e1889fd89 |
valid | API.parse_conll | Processes the texts using TweeboParse and returns them in CoNLL format.
:param texts: The List of Strings to be processed by TweeboParse.
:param retry_count: The number of times it has retried for. Default
0 does not require setting, main purpose is for
... | tweebo_parser/api.py | def parse_conll(self, texts: List[str], retry_count: int = 0) -> List[str]:
'''
Processes the texts using TweeboParse and returns them in CoNLL format.
:param texts: The List of Strings to be processed by TweeboParse.
:param retry_count: The number of times it has retried for. Default
... | def parse_conll(self, texts: List[str], retry_count: int = 0) -> List[str]:
'''
Processes the texts using TweeboParse and returns them in CoNLL format.
:param texts: The List of Strings to be processed by TweeboParse.
:param retry_count: The number of times it has retried for. Default
... | [
"Processes",
"the",
"texts",
"using",
"TweeboParse",
"and",
"returns",
"them",
"in",
"CoNLL",
"format",
"."
] | apmoore1/tweebo_parser_python_api | python | https://github.com/apmoore1/tweebo_parser_python_api/blob/224be2570b8b2508d29771f5e5abe06e1889fd89/tweebo_parser/api.py#L57-L95 | [
"def",
"parse_conll",
"(",
"self",
",",
"texts",
":",
"List",
"[",
"str",
"]",
",",
"retry_count",
":",
"int",
"=",
"0",
")",
"->",
"List",
"[",
"str",
"]",
":",
"post_data",
"=",
"{",
"'texts'",
":",
"texts",
",",
"'output_type'",
":",
"'conll'",
... | 224be2570b8b2508d29771f5e5abe06e1889fd89 |
valid | CampfireEntity.set_data | Set entity data
Args:
data (dict): Entity data
datetime_fields (array): Fields that should be parsed as datetimes | pyfire/entity.py | def set_data(self, data={}, datetime_fields=[]):
""" Set entity data
Args:
data (dict): Entity data
datetime_fields (array): Fields that should be parsed as datetimes
"""
if datetime_fields:
for field in datetime_fields:
if field in da... | def set_data(self, data={}, datetime_fields=[]):
""" Set entity data
Args:
data (dict): Entity data
datetime_fields (array): Fields that should be parsed as datetimes
"""
if datetime_fields:
for field in datetime_fields:
if field in da... | [
"Set",
"entity",
"data"
] | mariano/pyfire | python | https://github.com/mariano/pyfire/blob/42e3490c138abc8e10f2e9f8f8f3b40240a80412/pyfire/entity.py#L90-L102 | [
"def",
"set_data",
"(",
"self",
",",
"data",
"=",
"{",
"}",
",",
"datetime_fields",
"=",
"[",
"]",
")",
":",
"if",
"datetime_fields",
":",
"for",
"field",
"in",
"datetime_fields",
":",
"if",
"field",
"in",
"data",
":",
"data",
"[",
"field",
"]",
"=",... | 42e3490c138abc8e10f2e9f8f8f3b40240a80412 |
valid | CampfireEntity._parse_datetime | Parses a datetime string from "YYYY/MM/DD HH:MM:SS +HHMM" format
Args:
value (str): String
Returns:
datetime. Datetime | pyfire/entity.py | def _parse_datetime(self, value):
""" Parses a datetime string from "YYYY/MM/DD HH:MM:SS +HHMM" format
Args:
value (str): String
Returns:
datetime. Datetime
"""
offset = 0
pattern = r"\s+([+-]{1}\d+)\Z"
matches = re.search(pattern, value)... | def _parse_datetime(self, value):
""" Parses a datetime string from "YYYY/MM/DD HH:MM:SS +HHMM" format
Args:
value (str): String
Returns:
datetime. Datetime
"""
offset = 0
pattern = r"\s+([+-]{1}\d+)\Z"
matches = re.search(pattern, value)... | [
"Parses",
"a",
"datetime",
"string",
"from",
"YYYY",
"/",
"MM",
"/",
"DD",
"HH",
":",
"MM",
":",
"SS",
"+",
"HHMM",
"format"
] | mariano/pyfire | python | https://github.com/mariano/pyfire/blob/42e3490c138abc8e10f2e9f8f8f3b40240a80412/pyfire/entity.py#L104-L119 | [
"def",
"_parse_datetime",
"(",
"self",
",",
"value",
")",
":",
"offset",
"=",
"0",
"pattern",
"=",
"r\"\\s+([+-]{1}\\d+)\\Z\"",
"matches",
"=",
"re",
".",
"search",
"(",
"pattern",
",",
"value",
")",
"if",
"matches",
":",
"value",
"=",
"re",
".",
"sub",
... | 42e3490c138abc8e10f2e9f8f8f3b40240a80412 |
valid | validate_xml_text | validates XML text | lxmlx/validate.py | def validate_xml_text(text):
"""validates XML text"""
bad_chars = __INVALID_XML_CHARS & set(text)
if bad_chars:
for offset,c in enumerate(text):
if c in bad_chars:
raise RuntimeError('invalid XML character: ' + repr(c) + ' at offset ' + str(offset)) | def validate_xml_text(text):
"""validates XML text"""
bad_chars = __INVALID_XML_CHARS & set(text)
if bad_chars:
for offset,c in enumerate(text):
if c in bad_chars:
raise RuntimeError('invalid XML character: ' + repr(c) + ' at offset ' + str(offset)) | [
"validates",
"XML",
"text"
] | innodatalabs/lxmlx | python | https://github.com/innodatalabs/lxmlx/blob/d0514f62127e51378be4e0c8cea2622c9786f99f/lxmlx/validate.py#L54-L60 | [
"def",
"validate_xml_text",
"(",
"text",
")",
":",
"bad_chars",
"=",
"__INVALID_XML_CHARS",
"&",
"set",
"(",
"text",
")",
"if",
"bad_chars",
":",
"for",
"offset",
",",
"c",
"in",
"enumerate",
"(",
"text",
")",
":",
"if",
"c",
"in",
"bad_chars",
":",
"r... | d0514f62127e51378be4e0c8cea2622c9786f99f |
valid | validate_xml_name | validates XML name | lxmlx/validate.py | def validate_xml_name(name):
"""validates XML name"""
if len(name) == 0:
raise RuntimeError('empty XML name')
if __INVALID_NAME_CHARS & set(name):
raise RuntimeError('XML name contains invalid character')
if name[0] in __INVALID_NAME_START_CHARS:
raise RuntimeError('XML name st... | def validate_xml_name(name):
"""validates XML name"""
if len(name) == 0:
raise RuntimeError('empty XML name')
if __INVALID_NAME_CHARS & set(name):
raise RuntimeError('XML name contains invalid character')
if name[0] in __INVALID_NAME_START_CHARS:
raise RuntimeError('XML name st... | [
"validates",
"XML",
"name"
] | innodatalabs/lxmlx | python | https://github.com/innodatalabs/lxmlx/blob/d0514f62127e51378be4e0c8cea2622c9786f99f/lxmlx/validate.py#L91-L100 | [
"def",
"validate_xml_name",
"(",
"name",
")",
":",
"if",
"len",
"(",
"name",
")",
"==",
"0",
":",
"raise",
"RuntimeError",
"(",
"'empty XML name'",
")",
"if",
"__INVALID_NAME_CHARS",
"&",
"set",
"(",
"name",
")",
":",
"raise",
"RuntimeError",
"(",
"'XML na... | d0514f62127e51378be4e0c8cea2622c9786f99f |
valid | Vehicle.update | Update acceleration. Accounts for the importance and
priority (order) of multiple behaviors. | kxg/misc/sprites.py | def update(self, time):
""" Update acceleration. Accounts for the importance and
priority (order) of multiple behaviors. """
# .... I feel this stuff could be done a lot better.
total_acceleration = Vector.null()
max_jerk = self.max_acceleration
for behavior in ... | def update(self, time):
""" Update acceleration. Accounts for the importance and
priority (order) of multiple behaviors. """
# .... I feel this stuff could be done a lot better.
total_acceleration = Vector.null()
max_jerk = self.max_acceleration
for behavior in ... | [
"Update",
"acceleration",
".",
"Accounts",
"for",
"the",
"importance",
"and",
"priority",
"(",
"order",
")",
"of",
"multiple",
"behaviors",
"."
] | kxgames/kxg | python | https://github.com/kxgames/kxg/blob/a68c01dc4aa1abf6b3780ba2c65a7828282566aa/kxg/misc/sprites.py#L113-L143 | [
"def",
"update",
"(",
"self",
",",
"time",
")",
":",
"# .... I feel this stuff could be done a lot better.",
"total_acceleration",
"=",
"Vector",
".",
"null",
"(",
")",
"max_jerk",
"=",
"self",
".",
"max_acceleration",
"for",
"behavior",
"in",
"self",
".",
"behavi... | a68c01dc4aa1abf6b3780ba2c65a7828282566aa |
valid | Flee.update | Calculate what the desired change in velocity is.
delta_velocity = acceleration * delta_time
Time will be dealt with by the sprite. | kxg/misc/sprites.py | def update (self):
""" Calculate what the desired change in velocity is.
delta_velocity = acceleration * delta_time
Time will be dealt with by the sprite. """
delta_velocity = Vector.null()
target_position = self.target.get_position()
sprite_position = self.sprite.get_po... | def update (self):
""" Calculate what the desired change in velocity is.
delta_velocity = acceleration * delta_time
Time will be dealt with by the sprite. """
delta_velocity = Vector.null()
target_position = self.target.get_position()
sprite_position = self.sprite.get_po... | [
"Calculate",
"what",
"the",
"desired",
"change",
"in",
"velocity",
"is",
".",
"delta_velocity",
"=",
"acceleration",
"*",
"delta_time",
"Time",
"will",
"be",
"dealt",
"with",
"by",
"the",
"sprite",
"."
] | kxgames/kxg | python | https://github.com/kxgames/kxg/blob/a68c01dc4aa1abf6b3780ba2c65a7828282566aa/kxg/misc/sprites.py#L223-L242 | [
"def",
"update",
"(",
"self",
")",
":",
"delta_velocity",
"=",
"Vector",
".",
"null",
"(",
")",
"target_position",
"=",
"self",
".",
"target",
".",
"get_position",
"(",
")",
"sprite_position",
"=",
"self",
".",
"sprite",
".",
"get_position",
"(",
")",
"d... | a68c01dc4aa1abf6b3780ba2c65a7828282566aa |
valid | GameStage.on_enter_stage | Prepare the actors, the world, and the messaging system to begin
playing the game.
This method is guaranteed to be called exactly once upon entering the
game stage. | kxg/theater.py | def on_enter_stage(self):
"""
Prepare the actors, the world, and the messaging system to begin
playing the game.
This method is guaranteed to be called exactly once upon entering the
game stage.
"""
with self.world._unlock_temporarily():
sel... | def on_enter_stage(self):
"""
Prepare the actors, the world, and the messaging system to begin
playing the game.
This method is guaranteed to be called exactly once upon entering the
game stage.
"""
with self.world._unlock_temporarily():
sel... | [
"Prepare",
"the",
"actors",
"the",
"world",
"and",
"the",
"messaging",
"system",
"to",
"begin",
"playing",
"the",
"game",
".",
"This",
"method",
"is",
"guaranteed",
"to",
"be",
"called",
"exactly",
"once",
"upon",
"entering",
"the",
"game",
"stage",
"."
] | kxgames/kxg | python | https://github.com/kxgames/kxg/blob/a68c01dc4aa1abf6b3780ba2c65a7828282566aa/kxg/theater.py#L169-L199 | [
"def",
"on_enter_stage",
"(",
"self",
")",
":",
"with",
"self",
".",
"world",
".",
"_unlock_temporarily",
"(",
")",
":",
"self",
".",
"forum",
".",
"connect_everyone",
"(",
"self",
".",
"world",
",",
"self",
".",
"actors",
")",
"# 1. Setup the forum.",
"se... | a68c01dc4aa1abf6b3780ba2c65a7828282566aa |
valid | GameStage.on_update_stage | Sequentially update the actors, the world, and the messaging system.
The theater terminates once all of the actors indicate that they are done. | kxg/theater.py | def on_update_stage(self, dt):
"""
Sequentially update the actors, the world, and the messaging system.
The theater terminates once all of the actors indicate that they are done.
"""
for actor in self.actors:
actor.on_update_game(dt)
self.forum.on_update_g... | def on_update_stage(self, dt):
"""
Sequentially update the actors, the world, and the messaging system.
The theater terminates once all of the actors indicate that they are done.
"""
for actor in self.actors:
actor.on_update_game(dt)
self.forum.on_update_g... | [
"Sequentially",
"update",
"the",
"actors",
"the",
"world",
"and",
"the",
"messaging",
"system",
".",
"The",
"theater",
"terminates",
"once",
"all",
"of",
"the",
"actors",
"indicate",
"that",
"they",
"are",
"done",
"."
] | kxgames/kxg | python | https://github.com/kxgames/kxg/blob/a68c01dc4aa1abf6b3780ba2c65a7828282566aa/kxg/theater.py#L201-L216 | [
"def",
"on_update_stage",
"(",
"self",
",",
"dt",
")",
":",
"for",
"actor",
"in",
"self",
".",
"actors",
":",
"actor",
".",
"on_update_game",
"(",
"dt",
")",
"self",
".",
"forum",
".",
"on_update_game",
"(",
")",
"with",
"self",
".",
"world",
".",
"_... | a68c01dc4aa1abf6b3780ba2c65a7828282566aa |
valid | GameStage.on_exit_stage | Give the actors, the world, and the messaging system a chance to react
to the end of the game. | kxg/theater.py | def on_exit_stage(self):
"""
Give the actors, the world, and the messaging system a chance to react
to the end of the game.
"""
# 1. Let the forum react to the end of the game. Local forums don't
# react to this, but remote forums take the opportunity to stop
... | def on_exit_stage(self):
"""
Give the actors, the world, and the messaging system a chance to react
to the end of the game.
"""
# 1. Let the forum react to the end of the game. Local forums don't
# react to this, but remote forums take the opportunity to stop
... | [
"Give",
"the",
"actors",
"the",
"world",
"and",
"the",
"messaging",
"system",
"a",
"chance",
"to",
"react",
"to",
"the",
"end",
"of",
"the",
"game",
"."
] | kxgames/kxg | python | https://github.com/kxgames/kxg/blob/a68c01dc4aa1abf6b3780ba2c65a7828282566aa/kxg/theater.py#L218-L238 | [
"def",
"on_exit_stage",
"(",
"self",
")",
":",
"# 1. Let the forum react to the end of the game. Local forums don't ",
"# react to this, but remote forums take the opportunity to stop ",
"# trying to extract tokens from messages.",
"self",
".",
"forum",
".",
"on_finish_game",
"(",... | a68c01dc4aa1abf6b3780ba2c65a7828282566aa |
valid | Message.tokens_referenced | Return a list of all the tokens that are referenced (i.e. contained in)
this message. Tokens that haven't been assigned an id yet are searched
recursively for tokens. So this method may return fewer results after
the message is sent. This information is used by the game engine to
... | kxg/messages.py | def tokens_referenced(self):
"""
Return a list of all the tokens that are referenced (i.e. contained in)
this message. Tokens that haven't been assigned an id yet are searched
recursively for tokens. So this method may return fewer results after
the message is sent. This in... | def tokens_referenced(self):
"""
Return a list of all the tokens that are referenced (i.e. contained in)
this message. Tokens that haven't been assigned an id yet are searched
recursively for tokens. So this method may return fewer results after
the message is sent. This in... | [
"Return",
"a",
"list",
"of",
"all",
"the",
"tokens",
"that",
"are",
"referenced",
"(",
"i",
".",
"e",
".",
"contained",
"in",
")",
"this",
"message",
".",
"Tokens",
"that",
"haven",
"t",
"been",
"assigned",
"an",
"id",
"yet",
"are",
"searched",
"recurs... | kxgames/kxg | python | https://github.com/kxgames/kxg/blob/a68c01dc4aa1abf6b3780ba2c65a7828282566aa/kxg/messages.py#L52-L92 | [
"def",
"tokens_referenced",
"(",
"self",
")",
":",
"tokens",
"=",
"set",
"(",
")",
"# Use the pickle machinery to find all the tokens contained at any ",
"# level of this message. When an object is being pickled, the Pickler ",
"# calls its persistent_id() method for each object it encoun... | a68c01dc4aa1abf6b3780ba2c65a7828282566aa |
valid | DebugPanel.wrap_handler | Enable/Disable handler. | muffin_peewee/debugtoolbar.py | def wrap_handler(self, handler, context_switcher):
"""Enable/Disable handler."""
context_switcher.add_context_in(lambda: LOGGER.addHandler(self.handler))
context_switcher.add_context_out(lambda: LOGGER.removeHandler(self.handler)) | def wrap_handler(self, handler, context_switcher):
"""Enable/Disable handler."""
context_switcher.add_context_in(lambda: LOGGER.addHandler(self.handler))
context_switcher.add_context_out(lambda: LOGGER.removeHandler(self.handler)) | [
"Enable",
"/",
"Disable",
"handler",
"."
] | klen/muffin-peewee | python | https://github.com/klen/muffin-peewee/blob/8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e/muffin_peewee/debugtoolbar.py#L44-L47 | [
"def",
"wrap_handler",
"(",
"self",
",",
"handler",
",",
"context_switcher",
")",
":",
"context_switcher",
".",
"add_context_in",
"(",
"lambda",
":",
"LOGGER",
".",
"addHandler",
"(",
"self",
".",
"handler",
")",
")",
"context_switcher",
".",
"add_context_out",
... | 8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e |
valid | DebugPanel.render_vars | Template variables. | muffin_peewee/debugtoolbar.py | def render_vars(self):
"""Template variables."""
return {
'records': [
{
'message': record.getMessage(),
'time': dt.datetime.fromtimestamp(record.created).strftime('%H:%M:%S'),
} for record in self.handler.records
... | def render_vars(self):
"""Template variables."""
return {
'records': [
{
'message': record.getMessage(),
'time': dt.datetime.fromtimestamp(record.created).strftime('%H:%M:%S'),
} for record in self.handler.records
... | [
"Template",
"variables",
"."
] | klen/muffin-peewee | python | https://github.com/klen/muffin-peewee/blob/8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e/muffin_peewee/debugtoolbar.py#L59-L68 | [
"def",
"render_vars",
"(",
"self",
")",
":",
"return",
"{",
"'records'",
":",
"[",
"{",
"'message'",
":",
"record",
".",
"getMessage",
"(",
")",
",",
"'time'",
":",
"dt",
".",
"datetime",
".",
"fromtimestamp",
"(",
"record",
".",
"created",
")",
".",
... | 8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e |
valid | AIODatabase.init_async | Use when application is starting. | muffin_peewee/mpeewee.py | def init_async(self, loop=None):
"""Use when application is starting."""
self._loop = loop or asyncio.get_event_loop()
self._async_lock = asyncio.Lock(loop=loop)
# FIX: SQLITE in memory database
if not self.database == ':memory:':
self._state = ConnectionLocal() | def init_async(self, loop=None):
"""Use when application is starting."""
self._loop = loop or asyncio.get_event_loop()
self._async_lock = asyncio.Lock(loop=loop)
# FIX: SQLITE in memory database
if not self.database == ':memory:':
self._state = ConnectionLocal() | [
"Use",
"when",
"application",
"is",
"starting",
"."
] | klen/muffin-peewee | python | https://github.com/klen/muffin-peewee/blob/8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e/muffin_peewee/mpeewee.py#L89-L96 | [
"def",
"init_async",
"(",
"self",
",",
"loop",
"=",
"None",
")",
":",
"self",
".",
"_loop",
"=",
"loop",
"or",
"asyncio",
".",
"get_event_loop",
"(",
")",
"self",
".",
"_async_lock",
"=",
"asyncio",
".",
"Lock",
"(",
"loop",
"=",
"loop",
")",
"# FIX:... | 8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e |
valid | AIODatabase.async_connect | Catch a connection asyncrounosly. | muffin_peewee/mpeewee.py | async def async_connect(self):
"""Catch a connection asyncrounosly."""
if self._async_lock is None:
raise Exception('Error, database not properly initialized before async connection')
async with self._async_lock:
self.connect(True)
return self._state.conn | async def async_connect(self):
"""Catch a connection asyncrounosly."""
if self._async_lock is None:
raise Exception('Error, database not properly initialized before async connection')
async with self._async_lock:
self.connect(True)
return self._state.conn | [
"Catch",
"a",
"connection",
"asyncrounosly",
"."
] | klen/muffin-peewee | python | https://github.com/klen/muffin-peewee/blob/8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e/muffin_peewee/mpeewee.py#L98-L106 | [
"async",
"def",
"async_connect",
"(",
"self",
")",
":",
"if",
"self",
".",
"_async_lock",
"is",
"None",
":",
"raise",
"Exception",
"(",
"'Error, database not properly initialized before async connection'",
")",
"async",
"with",
"self",
".",
"_async_lock",
":",
"self... | 8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e |
valid | PooledAIODatabase.init_async | Initialize self. | muffin_peewee/mpeewee.py | def init_async(self, loop):
"""Initialize self."""
super(PooledAIODatabase, self).init_async(loop)
self._waiters = collections.deque() | def init_async(self, loop):
"""Initialize self."""
super(PooledAIODatabase, self).init_async(loop)
self._waiters = collections.deque() | [
"Initialize",
"self",
"."
] | klen/muffin-peewee | python | https://github.com/klen/muffin-peewee/blob/8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e/muffin_peewee/mpeewee.py#L123-L126 | [
"def",
"init_async",
"(",
"self",
",",
"loop",
")",
":",
"super",
"(",
"PooledAIODatabase",
",",
"self",
")",
".",
"init_async",
"(",
"loop",
")",
"self",
".",
"_waiters",
"=",
"collections",
".",
"deque",
"(",
")"
] | 8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e |
valid | PooledAIODatabase.async_connect | Asyncronously wait for a connection from the pool. | muffin_peewee/mpeewee.py | async def async_connect(self):
"""Asyncronously wait for a connection from the pool."""
if self._waiters is None:
raise Exception('Error, database not properly initialized before async connection')
if self._waiters or self.max_connections and (len(self._in_use) >= self.max_connectio... | async def async_connect(self):
"""Asyncronously wait for a connection from the pool."""
if self._waiters is None:
raise Exception('Error, database not properly initialized before async connection')
if self._waiters or self.max_connections and (len(self._in_use) >= self.max_connectio... | [
"Asyncronously",
"wait",
"for",
"a",
"connection",
"from",
"the",
"pool",
"."
] | klen/muffin-peewee | python | https://github.com/klen/muffin-peewee/blob/8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e/muffin_peewee/mpeewee.py#L128-L144 | [
"async",
"def",
"async_connect",
"(",
"self",
")",
":",
"if",
"self",
".",
"_waiters",
"is",
"None",
":",
"raise",
"Exception",
"(",
"'Error, database not properly initialized before async connection'",
")",
"if",
"self",
".",
"_waiters",
"or",
"self",
".",
"max_c... | 8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e |
valid | PooledAIODatabase._close | Release waiters. | muffin_peewee/mpeewee.py | def _close(self, conn):
"""Release waiters."""
super(PooledAIODatabase, self)._close(conn)
for waiter in self._waiters:
if not waiter.done():
logger.debug('Release a waiter')
waiter.set_result(True)
break | def _close(self, conn):
"""Release waiters."""
super(PooledAIODatabase, self)._close(conn)
for waiter in self._waiters:
if not waiter.done():
logger.debug('Release a waiter')
waiter.set_result(True)
break | [
"Release",
"waiters",
"."
] | klen/muffin-peewee | python | https://github.com/klen/muffin-peewee/blob/8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e/muffin_peewee/mpeewee.py#L146-L153 | [
"def",
"_close",
"(",
"self",
",",
"conn",
")",
":",
"super",
"(",
"PooledAIODatabase",
",",
"self",
")",
".",
"_close",
"(",
"conn",
")",
"for",
"waiter",
"in",
"self",
".",
"_waiters",
":",
"if",
"not",
"waiter",
".",
"done",
"(",
")",
":",
"logg... | 8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e |
valid | ClientForum.receive_id_from_server | Listen for an id from the server.
At the beginning of a game, each client receives an IdFactory from the
server. This factory are used to give id numbers that are guaranteed
to be unique to tokens that created locally. This method checks to see if such
a factory has been received. ... | kxg/multiplayer.py | def receive_id_from_server(self):
"""
Listen for an id from the server.
At the beginning of a game, each client receives an IdFactory from the
server. This factory are used to give id numbers that are guaranteed
to be unique to tokens that created locally. This method checks... | def receive_id_from_server(self):
"""
Listen for an id from the server.
At the beginning of a game, each client receives an IdFactory from the
server. This factory are used to give id numbers that are guaranteed
to be unique to tokens that created locally. This method checks... | [
"Listen",
"for",
"an",
"id",
"from",
"the",
"server",
"."
] | kxgames/kxg | python | https://github.com/kxgames/kxg/blob/a68c01dc4aa1abf6b3780ba2c65a7828282566aa/kxg/multiplayer.py#L18-L34 | [
"def",
"receive_id_from_server",
"(",
"self",
")",
":",
"for",
"message",
"in",
"self",
".",
"pipe",
".",
"receive",
"(",
")",
":",
"if",
"isinstance",
"(",
"message",
",",
"IdFactory",
")",
":",
"self",
".",
"actor_id_factory",
"=",
"message",
"return",
... | a68c01dc4aa1abf6b3780ba2c65a7828282566aa |
valid | ClientForum.execute_sync | Respond when the server indicates that the client is out of sync.
The server can request a sync when this client sends a message that
fails the check() on the server. If the reason for the failure isn't
very serious, then the server can decide to send it as usual in the
interest of ... | kxg/multiplayer.py | def execute_sync(self, message):
"""
Respond when the server indicates that the client is out of sync.
The server can request a sync when this client sends a message that
fails the check() on the server. If the reason for the failure isn't
very serious, then the server can de... | def execute_sync(self, message):
"""
Respond when the server indicates that the client is out of sync.
The server can request a sync when this client sends a message that
fails the check() on the server. If the reason for the failure isn't
very serious, then the server can de... | [
"Respond",
"when",
"the",
"server",
"indicates",
"that",
"the",
"client",
"is",
"out",
"of",
"sync",
"."
] | kxgames/kxg | python | https://github.com/kxgames/kxg/blob/a68c01dc4aa1abf6b3780ba2c65a7828282566aa/kxg/multiplayer.py#L65-L87 | [
"def",
"execute_sync",
"(",
"self",
",",
"message",
")",
":",
"info",
"(",
"\"synchronizing message: {message}\"",
")",
"# Synchronize the world.",
"with",
"self",
".",
"world",
".",
"_unlock_temporarily",
"(",
")",
":",
"message",
".",
"_sync",
"(",
"self",
"."... | a68c01dc4aa1abf6b3780ba2c65a7828282566aa |
valid | ClientForum.execute_undo | Manage the response when the server rejects a message.
An undo is when required this client sends a message that the server
refuses to pass on to the other clients playing the game. When this
happens, the client must undo the changes that the message made to the
world before being s... | kxg/multiplayer.py | def execute_undo(self, message):
"""
Manage the response when the server rejects a message.
An undo is when required this client sends a message that the server
refuses to pass on to the other clients playing the game. When this
happens, the client must undo the changes that ... | def execute_undo(self, message):
"""
Manage the response when the server rejects a message.
An undo is when required this client sends a message that the server
refuses to pass on to the other clients playing the game. When this
happens, the client must undo the changes that ... | [
"Manage",
"the",
"response",
"when",
"the",
"server",
"rejects",
"a",
"message",
"."
] | kxgames/kxg | python | https://github.com/kxgames/kxg/blob/a68c01dc4aa1abf6b3780ba2c65a7828282566aa/kxg/multiplayer.py#L89-L113 | [
"def",
"execute_undo",
"(",
"self",
",",
"message",
")",
":",
"info",
"(",
"\"undoing message: {message}\"",
")",
"# Roll back changes that the original message made to the world.",
"with",
"self",
".",
"world",
".",
"_unlock_temporarily",
"(",
")",
":",
"message",
".",... | a68c01dc4aa1abf6b3780ba2c65a7828282566aa |
valid | ServerActor._relay_message | Relay messages from the forum on the server to the client represented
by this actor. | kxg/multiplayer.py | def _relay_message(self, message):
"""
Relay messages from the forum on the server to the client represented
by this actor.
"""
info("relaying message: {message}")
if not message.was_sent_by(self._id_factory):
self.pipe.send(message)
self.pipe.de... | def _relay_message(self, message):
"""
Relay messages from the forum on the server to the client represented
by this actor.
"""
info("relaying message: {message}")
if not message.was_sent_by(self._id_factory):
self.pipe.send(message)
self.pipe.de... | [
"Relay",
"messages",
"from",
"the",
"forum",
"on",
"the",
"server",
"to",
"the",
"client",
"represented",
"by",
"this",
"actor",
"."
] | kxgames/kxg | python | https://github.com/kxgames/kxg/blob/a68c01dc4aa1abf6b3780ba2c65a7828282566aa/kxg/multiplayer.py#L274-L283 | [
"def",
"_relay_message",
"(",
"self",
",",
"message",
")",
":",
"info",
"(",
"\"relaying message: {message}\"",
")",
"if",
"not",
"message",
".",
"was_sent_by",
"(",
"self",
".",
"_id_factory",
")",
":",
"self",
".",
"pipe",
".",
"send",
"(",
"message",
")... | a68c01dc4aa1abf6b3780ba2c65a7828282566aa |
valid | generate | Create a new DataItem. | example/views.py | def generate(request):
""" Create a new DataItem. """
models.DataItem.create(
content=''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(20))
)
return muffin.HTTPFound('/') | def generate(request):
""" Create a new DataItem. """
models.DataItem.create(
content=''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(20))
)
return muffin.HTTPFound('/') | [
"Create",
"a",
"new",
"DataItem",
"."
] | klen/muffin-peewee | python | https://github.com/klen/muffin-peewee/blob/8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e/example/views.py#L22-L27 | [
"def",
"generate",
"(",
"request",
")",
":",
"models",
".",
"DataItem",
".",
"create",
"(",
"content",
"=",
"''",
".",
"join",
"(",
"random",
".",
"choice",
"(",
"string",
".",
"ascii_uppercase",
"+",
"string",
".",
"digits",
")",
"for",
"_",
"in",
"... | 8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e |
valid | require_active_token | Raise an ApiUsageError if the given object is not a token that is currently
participating in the game. To be participating in the game, the given
token must have an id number and be associated with the world. | kxg/tokens.py | def require_active_token(object):
"""
Raise an ApiUsageError if the given object is not a token that is currently
participating in the game. To be participating in the game, the given
token must have an id number and be associated with the world.
"""
require_token(object)
token = object
... | def require_active_token(object):
"""
Raise an ApiUsageError if the given object is not a token that is currently
participating in the game. To be participating in the game, the given
token must have an id number and be associated with the world.
"""
require_token(object)
token = object
... | [
"Raise",
"an",
"ApiUsageError",
"if",
"the",
"given",
"object",
"is",
"not",
"a",
"token",
"that",
"is",
"currently",
"participating",
"in",
"the",
"game",
".",
"To",
"be",
"participating",
"in",
"the",
"game",
"the",
"given",
"token",
"must",
"have",
"an"... | kxgames/kxg | python | https://github.com/kxgames/kxg/blob/a68c01dc4aa1abf6b3780ba2c65a7828282566aa/kxg/tokens.py#L564-L589 | [
"def",
"require_active_token",
"(",
"object",
")",
":",
"require_token",
"(",
"object",
")",
"token",
"=",
"object",
"if",
"not",
"token",
".",
"has_id",
":",
"raise",
"ApiUsageError",
"(",
"\"\"\"\\\n token {token} should have an id, but doesn't.\n\n ... | a68c01dc4aa1abf6b3780ba2c65a7828282566aa |
valid | TokenSafetyChecks.add_safety_checks | Iterate through each member of the class being created and add a
safety check to every method that isn't marked as read-only. | kxg/tokens.py | def add_safety_checks(meta, members):
"""
Iterate through each member of the class being created and add a
safety check to every method that isn't marked as read-only.
"""
for member_name, member_value in members.items():
members[member_name] = meta.add_safety_check(... | def add_safety_checks(meta, members):
"""
Iterate through each member of the class being created and add a
safety check to every method that isn't marked as read-only.
"""
for member_name, member_value in members.items():
members[member_name] = meta.add_safety_check(... | [
"Iterate",
"through",
"each",
"member",
"of",
"the",
"class",
"being",
"created",
"and",
"add",
"a",
"safety",
"check",
"to",
"every",
"method",
"that",
"isn",
"t",
"marked",
"as",
"read",
"-",
"only",
"."
] | kxgames/kxg | python | https://github.com/kxgames/kxg/blob/a68c01dc4aa1abf6b3780ba2c65a7828282566aa/kxg/tokens.py#L59-L66 | [
"def",
"add_safety_checks",
"(",
"meta",
",",
"members",
")",
":",
"for",
"member_name",
",",
"member_value",
"in",
"members",
".",
"items",
"(",
")",
":",
"members",
"[",
"member_name",
"]",
"=",
"meta",
".",
"add_safety_check",
"(",
"member_name",
",",
"... | a68c01dc4aa1abf6b3780ba2c65a7828282566aa |
valid | TokenSafetyChecks.add_safety_check | If the given member is a method that is public (i.e. doesn't start with
an underscore) and hasn't been marked as read-only, replace it with a
version that will check to make sure the world is locked. This ensures
that methods that alter the token are only called from update methods
... | kxg/tokens.py | def add_safety_check(member_name, member_value):
"""
If the given member is a method that is public (i.e. doesn't start with
an underscore) and hasn't been marked as read-only, replace it with a
version that will check to make sure the world is locked. This ensures
that metho... | def add_safety_check(member_name, member_value):
"""
If the given member is a method that is public (i.e. doesn't start with
an underscore) and hasn't been marked as read-only, replace it with a
version that will check to make sure the world is locked. This ensures
that metho... | [
"If",
"the",
"given",
"member",
"is",
"a",
"method",
"that",
"is",
"public",
"(",
"i",
".",
"e",
".",
"doesn",
"t",
"start",
"with",
"an",
"underscore",
")",
"and",
"hasn",
"t",
"been",
"marked",
"as",
"read",
"-",
"only",
"replace",
"it",
"with",
... | kxgames/kxg | python | https://github.com/kxgames/kxg/blob/a68c01dc4aa1abf6b3780ba2c65a7828282566aa/kxg/tokens.py#L69-L139 | [
"def",
"add_safety_check",
"(",
"member_name",
",",
"member_value",
")",
":",
"import",
"functools",
"from",
"types",
"import",
"FunctionType",
"# Bail if the given member is read-only, private, or not a method.",
"is_method",
"=",
"isinstance",
"(",
"member_value",
",",
"F... | a68c01dc4aa1abf6b3780ba2c65a7828282566aa |
valid | Token.watch_method | Register the given callback to be called whenever the method with the
given name is called. You can easily take advantage of this feature in
token extensions by using the @watch_token decorator. | kxg/tokens.py | def watch_method(self, method_name, callback):
"""
Register the given callback to be called whenever the method with the
given name is called. You can easily take advantage of this feature in
token extensions by using the @watch_token decorator.
"""
# Make sure a toke... | def watch_method(self, method_name, callback):
"""
Register the given callback to be called whenever the method with the
given name is called. You can easily take advantage of this feature in
token extensions by using the @watch_token decorator.
"""
# Make sure a toke... | [
"Register",
"the",
"given",
"callback",
"to",
"be",
"called",
"whenever",
"the",
"method",
"with",
"the",
"given",
"name",
"is",
"called",
".",
"You",
"can",
"easily",
"take",
"advantage",
"of",
"this",
"feature",
"in",
"token",
"extensions",
"by",
"using",
... | kxgames/kxg | python | https://github.com/kxgames/kxg/blob/a68c01dc4aa1abf6b3780ba2c65a7828282566aa/kxg/tokens.py#L246-L279 | [
"def",
"watch_method",
"(",
"self",
",",
"method_name",
",",
"callback",
")",
":",
"# Make sure a token method with the given name exists, and complain if ",
"# nothing is found.",
"try",
":",
"method",
"=",
"getattr",
"(",
"self",
",",
"method_name",
")",
"except",
"At... | a68c01dc4aa1abf6b3780ba2c65a7828282566aa |
valid | Token._remove_from_world | Clear all the internal data the token needed while it was part of
the world.
Note that this method doesn't actually remove the token from the
world. That's what World._remove_token() does. This method is just
responsible for setting the internal state of the token being removed. | kxg/tokens.py | def _remove_from_world(self):
"""
Clear all the internal data the token needed while it was part of
the world.
Note that this method doesn't actually remove the token from the
world. That's what World._remove_token() does. This method is just
responsible for setting... | def _remove_from_world(self):
"""
Clear all the internal data the token needed while it was part of
the world.
Note that this method doesn't actually remove the token from the
world. That's what World._remove_token() does. This method is just
responsible for setting... | [
"Clear",
"all",
"the",
"internal",
"data",
"the",
"token",
"needed",
"while",
"it",
"was",
"part",
"of",
"the",
"world",
"."
] | kxgames/kxg | python | https://github.com/kxgames/kxg/blob/a68c01dc4aa1abf6b3780ba2c65a7828282566aa/kxg/tokens.py#L383-L396 | [
"def",
"_remove_from_world",
"(",
"self",
")",
":",
"self",
".",
"on_remove_from_world",
"(",
")",
"self",
".",
"_extensions",
"=",
"{",
"}",
"self",
".",
"_disable_forum_observation",
"(",
")",
"self",
".",
"_world",
"=",
"None",
"self",
".",
"_id",
"=",
... | a68c01dc4aa1abf6b3780ba2c65a7828282566aa |
valid | World._unlock_temporarily | Allow tokens to modify the world for the duration of a with-block.
It's important that tokens only modify the world at appropriate times,
otherwise the changes they make may not be communicated across the
network to other clients. To help catch and prevent these kinds of
errors, the... | kxg/tokens.py | def _unlock_temporarily(self):
"""
Allow tokens to modify the world for the duration of a with-block.
It's important that tokens only modify the world at appropriate times,
otherwise the changes they make may not be communicated across the
network to other clients. To help ca... | def _unlock_temporarily(self):
"""
Allow tokens to modify the world for the duration of a with-block.
It's important that tokens only modify the world at appropriate times,
otherwise the changes they make may not be communicated across the
network to other clients. To help ca... | [
"Allow",
"tokens",
"to",
"modify",
"the",
"world",
"for",
"the",
"duration",
"of",
"a",
"with",
"-",
"block",
"."
] | kxgames/kxg | python | https://github.com/kxgames/kxg/blob/a68c01dc4aa1abf6b3780ba2c65a7828282566aa/kxg/tokens.py#L488-L514 | [
"def",
"_unlock_temporarily",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_is_locked",
":",
"yield",
"else",
":",
"try",
":",
"self",
".",
"_is_locked",
"=",
"False",
"yield",
"finally",
":",
"self",
".",
"_is_locked",
"=",
"True"
] | a68c01dc4aa1abf6b3780ba2c65a7828282566aa |
valid | scan | Converts XML tree to event generator | lxmlx/event.py | def scan(xml):
"""Converts XML tree to event generator"""
if xml.tag is et.Comment:
yield {'type': COMMENT, 'text': xml.text}
return
if xml.tag is et.PI:
if xml.text:
yield {'type': PI, 'target': xml.target, 'text': xml.text}
else:
yield {'type': PI,... | def scan(xml):
"""Converts XML tree to event generator"""
if xml.tag is et.Comment:
yield {'type': COMMENT, 'text': xml.text}
return
if xml.tag is et.PI:
if xml.text:
yield {'type': PI, 'target': xml.target, 'text': xml.text}
else:
yield {'type': PI,... | [
"Converts",
"XML",
"tree",
"to",
"event",
"generator"
] | innodatalabs/lxmlx | python | https://github.com/innodatalabs/lxmlx/blob/d0514f62127e51378be4e0c8cea2622c9786f99f/lxmlx/event.py#L32-L59 | [
"def",
"scan",
"(",
"xml",
")",
":",
"if",
"xml",
".",
"tag",
"is",
"et",
".",
"Comment",
":",
"yield",
"{",
"'type'",
":",
"COMMENT",
",",
"'text'",
":",
"xml",
".",
"text",
"}",
"return",
"if",
"xml",
".",
"tag",
"is",
"et",
".",
"PI",
":",
... | d0514f62127e51378be4e0c8cea2622c9786f99f |
valid | unscan | Converts events stream into lXML tree | lxmlx/event.py | def unscan(events, nsmap=None):
"""Converts events stream into lXML tree"""
root = None
last_closed_elt = None
stack = []
for obj in events:
if obj['type'] == ENTER:
elt = _obj2elt(obj, nsmap=nsmap)
if stack:
stack[-1].append(elt)
elif ro... | def unscan(events, nsmap=None):
"""Converts events stream into lXML tree"""
root = None
last_closed_elt = None
stack = []
for obj in events:
if obj['type'] == ENTER:
elt = _obj2elt(obj, nsmap=nsmap)
if stack:
stack[-1].append(elt)
elif ro... | [
"Converts",
"events",
"stream",
"into",
"lXML",
"tree"
] | innodatalabs/lxmlx | python | https://github.com/innodatalabs/lxmlx/blob/d0514f62127e51378be4e0c8cea2622c9786f99f/lxmlx/event.py#L61-L106 | [
"def",
"unscan",
"(",
"events",
",",
"nsmap",
"=",
"None",
")",
":",
"root",
"=",
"None",
"last_closed_elt",
"=",
"None",
"stack",
"=",
"[",
"]",
"for",
"obj",
"in",
"events",
":",
"if",
"obj",
"[",
"'type'",
"]",
"==",
"ENTER",
":",
"elt",
"=",
... | d0514f62127e51378be4e0c8cea2622c9786f99f |
valid | parse | Parses file content into events stream | lxmlx/event.py | def parse(filename):
"""Parses file content into events stream"""
for event, elt in et.iterparse(filename, events= ('start', 'end', 'comment', 'pi'), huge_tree=True):
if event == 'start':
obj = _elt2obj(elt)
obj['type'] = ENTER
yield obj
if elt.text:
... | def parse(filename):
"""Parses file content into events stream"""
for event, elt in et.iterparse(filename, events= ('start', 'end', 'comment', 'pi'), huge_tree=True):
if event == 'start':
obj = _elt2obj(elt)
obj['type'] = ENTER
yield obj
if elt.text:
... | [
"Parses",
"file",
"content",
"into",
"events",
"stream"
] | innodatalabs/lxmlx | python | https://github.com/innodatalabs/lxmlx/blob/d0514f62127e51378be4e0c8cea2622c9786f99f/lxmlx/event.py#L109-L128 | [
"def",
"parse",
"(",
"filename",
")",
":",
"for",
"event",
",",
"elt",
"in",
"et",
".",
"iterparse",
"(",
"filename",
",",
"events",
"=",
"(",
"'start'",
",",
"'end'",
",",
"'comment'",
",",
"'pi'",
")",
",",
"huge_tree",
"=",
"True",
")",
":",
"if... | d0514f62127e51378be4e0c8cea2622c9786f99f |
valid | subtree | selects sub-tree events | lxmlx/event.py | def subtree(events):
"""selects sub-tree events"""
stack = 0
for obj in events:
if obj['type'] == ENTER:
stack += 1
elif obj['type'] == EXIT:
if stack == 0:
break
stack -= 1
yield obj | def subtree(events):
"""selects sub-tree events"""
stack = 0
for obj in events:
if obj['type'] == ENTER:
stack += 1
elif obj['type'] == EXIT:
if stack == 0:
break
stack -= 1
yield obj | [
"selects",
"sub",
"-",
"tree",
"events"
] | innodatalabs/lxmlx | python | https://github.com/innodatalabs/lxmlx/blob/d0514f62127e51378be4e0c8cea2622c9786f99f/lxmlx/event.py#L130-L140 | [
"def",
"subtree",
"(",
"events",
")",
":",
"stack",
"=",
"0",
"for",
"obj",
"in",
"events",
":",
"if",
"obj",
"[",
"'type'",
"]",
"==",
"ENTER",
":",
"stack",
"+=",
"1",
"elif",
"obj",
"[",
"'type'",
"]",
"==",
"EXIT",
":",
"if",
"stack",
"==",
... | d0514f62127e51378be4e0c8cea2622c9786f99f |
valid | merge_text | merges each run of successive text events into one text event | lxmlx/event.py | def merge_text(events):
"""merges each run of successive text events into one text event"""
text = []
for obj in events:
if obj['type'] == TEXT:
text.append(obj['text'])
else:
if text:
yield {'type': TEXT, 'text': ''.join(text)}
text.cl... | def merge_text(events):
"""merges each run of successive text events into one text event"""
text = []
for obj in events:
if obj['type'] == TEXT:
text.append(obj['text'])
else:
if text:
yield {'type': TEXT, 'text': ''.join(text)}
text.cl... | [
"merges",
"each",
"run",
"of",
"successive",
"text",
"events",
"into",
"one",
"text",
"event"
] | innodatalabs/lxmlx | python | https://github.com/innodatalabs/lxmlx/blob/d0514f62127e51378be4e0c8cea2622c9786f99f/lxmlx/event.py#L143-L155 | [
"def",
"merge_text",
"(",
"events",
")",
":",
"text",
"=",
"[",
"]",
"for",
"obj",
"in",
"events",
":",
"if",
"obj",
"[",
"'type'",
"]",
"==",
"TEXT",
":",
"text",
".",
"append",
"(",
"obj",
"[",
"'text'",
"]",
")",
"else",
":",
"if",
"text",
"... | d0514f62127e51378be4e0c8cea2622c9786f99f |
valid | with_peer | locates ENTER peer for each EXIT object. Convenient when selectively
filtering out XML markup | lxmlx/event.py | def with_peer(events):
"""locates ENTER peer for each EXIT object. Convenient when selectively
filtering out XML markup"""
stack = []
for obj in events:
if obj['type'] == ENTER:
stack.append(obj)
yield obj, None
elif obj['type'] == EXIT:
yield obj, st... | def with_peer(events):
"""locates ENTER peer for each EXIT object. Convenient when selectively
filtering out XML markup"""
stack = []
for obj in events:
if obj['type'] == ENTER:
stack.append(obj)
yield obj, None
elif obj['type'] == EXIT:
yield obj, st... | [
"locates",
"ENTER",
"peer",
"for",
"each",
"EXIT",
"object",
".",
"Convenient",
"when",
"selectively",
"filtering",
"out",
"XML",
"markup"
] | innodatalabs/lxmlx | python | https://github.com/innodatalabs/lxmlx/blob/d0514f62127e51378be4e0c8cea2622c9786f99f/lxmlx/event.py#L158-L170 | [
"def",
"with_peer",
"(",
"events",
")",
":",
"stack",
"=",
"[",
"]",
"for",
"obj",
"in",
"events",
":",
"if",
"obj",
"[",
"'type'",
"]",
"==",
"ENTER",
":",
"stack",
".",
"append",
"(",
"obj",
")",
"yield",
"obj",
",",
"None",
"elif",
"obj",
"[",... | d0514f62127e51378be4e0c8cea2622c9786f99f |
valid | easter | This method was ported from the work done by GM Arts,
on top of the algorithm by Claus Tondering, which was
based in part on the algorithm of Ouding (1940), as
quoted in "Explanatory Supplement to the Astronomical
Almanac", P. Kenneth Seidelmann, editor.
More about the algorithm may be found at:
... | businessdate/businessdate.py | def easter(year):
"""
This method was ported from the work done by GM Arts,
on top of the algorithm by Claus Tondering, which was
based in part on the algorithm of Ouding (1940), as
quoted in "Explanatory Supplement to the Astronomical
Almanac", P. Kenneth Seidelmann, editor.
More about th... | def easter(year):
"""
This method was ported from the work done by GM Arts,
on top of the algorithm by Claus Tondering, which was
based in part on the algorithm of Ouding (1940), as
quoted in "Explanatory Supplement to the Astronomical
Almanac", P. Kenneth Seidelmann, editor.
More about th... | [
"This",
"method",
"was",
"ported",
"from",
"the",
"work",
"done",
"by",
"GM",
"Arts",
"on",
"top",
"of",
"the",
"algorithm",
"by",
"Claus",
"Tondering",
"which",
"was",
"based",
"in",
"part",
"on",
"the",
"algorithm",
"of",
"Ouding",
"(",
"1940",
")",
... | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/businessdate.py#L1080-L1121 | [
"def",
"easter",
"(",
"year",
")",
":",
"# g - Golden year - 1",
"# c - Century",
"# h - (23 - Epact) mod 30",
"# i - Number of days from March 21 to Paschal Full Moon",
"# j - Weekday for PFM (0=Sunday, etc)",
"# p - Number of days from March 21 to Sunday on or before PFM",
"# (-6 to 28... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BusinessDate.from_date | construct BusinessDate instance from datetime.date instance,
raise ValueError exception if not possible
:param datetime.date datetime_date: calendar day
:return bool: | businessdate/businessdate.py | def from_date(datetime_date):
"""
construct BusinessDate instance from datetime.date instance,
raise ValueError exception if not possible
:param datetime.date datetime_date: calendar day
:return bool:
"""
return BusinessDate.from_ymd(datetime_date.year, datetime_... | def from_date(datetime_date):
"""
construct BusinessDate instance from datetime.date instance,
raise ValueError exception if not possible
:param datetime.date datetime_date: calendar day
:return bool:
"""
return BusinessDate.from_ymd(datetime_date.year, datetime_... | [
"construct",
"BusinessDate",
"instance",
"from",
"datetime",
".",
"date",
"instance",
"raise",
"ValueError",
"exception",
"if",
"not",
"possible"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/businessdate.py#L189-L197 | [
"def",
"from_date",
"(",
"datetime_date",
")",
":",
"return",
"BusinessDate",
".",
"from_ymd",
"(",
"datetime_date",
".",
"year",
",",
"datetime_date",
".",
"month",
",",
"datetime_date",
".",
"day",
")"
] | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BusinessDate.from_string | construction from the following string patterns
'%Y-%m-%d'
'%d.%m.%Y'
'%m/%d/%Y'
'%Y%m%d'
:param str date_str:
:return BusinessDate: | businessdate/businessdate.py | def from_string(date_str):
"""
construction from the following string patterns
'%Y-%m-%d'
'%d.%m.%Y'
'%m/%d/%Y'
'%Y%m%d'
:param str date_str:
:return BusinessDate:
"""
if date_str.count('-'):
str_format = '%Y-%m-%d'
eli... | def from_string(date_str):
"""
construction from the following string patterns
'%Y-%m-%d'
'%d.%m.%Y'
'%m/%d/%Y'
'%Y%m%d'
:param str date_str:
:return BusinessDate:
"""
if date_str.count('-'):
str_format = '%Y-%m-%d'
eli... | [
"construction",
"from",
"the",
"following",
"string",
"patterns",
"%Y",
"-",
"%m",
"-",
"%d",
"%d",
".",
"%m",
".",
"%Y",
"%m",
"/",
"%d",
"/",
"%Y",
"%Y%m%d"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/businessdate.py#L205-L235 | [
"def",
"from_string",
"(",
"date_str",
")",
":",
"if",
"date_str",
".",
"count",
"(",
"'-'",
")",
":",
"str_format",
"=",
"'%Y-%m-%d'",
"elif",
"date_str",
".",
"count",
"(",
"'.'",
")",
":",
"str_format",
"=",
"'%d.%m.%Y'",
"elif",
"date_str",
".",
"cou... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BusinessDate.to_date | construct datetime.date instance represented calendar date of BusinessDate instance
:return datetime.date: | businessdate/businessdate.py | def to_date(self):
"""
construct datetime.date instance represented calendar date of BusinessDate instance
:return datetime.date:
"""
y, m, d = self.to_ymd()
return date(y, m, d) | def to_date(self):
"""
construct datetime.date instance represented calendar date of BusinessDate instance
:return datetime.date:
"""
y, m, d = self.to_ymd()
return date(y, m, d) | [
"construct",
"datetime",
".",
"date",
"instance",
"represented",
"calendar",
"date",
"of",
"BusinessDate",
"instance"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/businessdate.py#L260-L267 | [
"def",
"to_date",
"(",
"self",
")",
":",
"y",
",",
"m",
",",
"d",
"=",
"self",
".",
"to_ymd",
"(",
")",
"return",
"date",
"(",
"y",
",",
"m",
",",
"d",
")"
] | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BusinessDate.is_businessdate | checks whether the provided date is a date
:param BusinessDate, int or float in_date:
:return bool: | businessdate/businessdate.py | def is_businessdate(in_date):
"""
checks whether the provided date is a date
:param BusinessDate, int or float in_date:
:return bool:
"""
# Note: if the data range has been created from pace_xl, then all the dates are bank dates
# and here it remains to check the ... | def is_businessdate(in_date):
"""
checks whether the provided date is a date
:param BusinessDate, int or float in_date:
:return bool:
"""
# Note: if the data range has been created from pace_xl, then all the dates are bank dates
# and here it remains to check the ... | [
"checks",
"whether",
"the",
"provided",
"date",
"is",
"a",
"date",
":",
"param",
"BusinessDate",
"int",
"or",
"float",
"in_date",
":",
":",
"return",
"bool",
":"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/businessdate.py#L319-L338 | [
"def",
"is_businessdate",
"(",
"in_date",
")",
":",
"# Note: if the data range has been created from pace_xl, then all the dates are bank dates",
"# and here it remains to check the validity.",
"# !!! However, if the data has been read from json string via json.load() function",
"# it does not rec... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BusinessDate.is_business_day | :param list holiday_obj : datetime.date list defining business holidays
:return: bool
method to check if a date falls neither on weekend nor is holiday | businessdate/businessdate.py | def is_business_day(self, holiday_obj=None):
"""
:param list holiday_obj : datetime.date list defining business holidays
:return: bool
method to check if a date falls neither on weekend nor is holiday
"""
y, m, d = BusinessDate.to_ymd(self)
if weekday(y, m, d) > ... | def is_business_day(self, holiday_obj=None):
"""
:param list holiday_obj : datetime.date list defining business holidays
:return: bool
method to check if a date falls neither on weekend nor is holiday
"""
y, m, d = BusinessDate.to_ymd(self)
if weekday(y, m, d) > ... | [
":",
"param",
"list",
"holiday_obj",
":",
"datetime",
".",
"date",
"list",
"defining",
"business",
"holidays",
":",
"return",
":",
"bool"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/businessdate.py#L350-L365 | [
"def",
"is_business_day",
"(",
"self",
",",
"holiday_obj",
"=",
"None",
")",
":",
"y",
",",
"m",
",",
"d",
"=",
"BusinessDate",
".",
"to_ymd",
"(",
"self",
")",
"if",
"weekday",
"(",
"y",
",",
"m",
",",
"d",
")",
">",
"FRIDAY",
":",
"return",
"Fa... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BusinessDate.add_period | addition of a period object
:param BusinessDate d:
:param p:
:type p: BusinessPeriod or str
:param list holiday_obj:
:return bankdate: | businessdate/businessdate.py | def add_period(self, p, holiday_obj=None):
"""
addition of a period object
:param BusinessDate d:
:param p:
:type p: BusinessPeriod or str
:param list holiday_obj:
:return bankdate:
"""
if isinstance(p, (list, tuple)):
return [Busines... | def add_period(self, p, holiday_obj=None):
"""
addition of a period object
:param BusinessDate d:
:param p:
:type p: BusinessPeriod or str
:param list holiday_obj:
:return bankdate:
"""
if isinstance(p, (list, tuple)):
return [Busines... | [
"addition",
"of",
"a",
"period",
"object"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/businessdate.py#L381-L410 | [
"def",
"add_period",
"(",
"self",
",",
"p",
",",
"holiday_obj",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"p",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"return",
"[",
"BusinessDate",
".",
"add_period",
"(",
"self",
",",
"pd",
")",
"for"... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BusinessDate.add_months | addition of a number of months
:param BusinessDate d:
:param int month_int:
:return bankdate: | businessdate/businessdate.py | def add_months(self, month_int):
"""
addition of a number of months
:param BusinessDate d:
:param int month_int:
:return bankdate:
"""
month_int += self.month
while month_int > 12:
self = BusinessDate.add_years(self, 1)
month_int ... | def add_months(self, month_int):
"""
addition of a number of months
:param BusinessDate d:
:param int month_int:
:return bankdate:
"""
month_int += self.month
while month_int > 12:
self = BusinessDate.add_years(self, 1)
month_int ... | [
"addition",
"of",
"a",
"number",
"of",
"months"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/businessdate.py#L412-L429 | [
"def",
"add_months",
"(",
"self",
",",
"month_int",
")",
":",
"month_int",
"+=",
"self",
".",
"month",
"while",
"month_int",
">",
"12",
":",
"self",
"=",
"BusinessDate",
".",
"add_years",
"(",
"self",
",",
"1",
")",
"month_int",
"-=",
"12",
"while",
"m... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BusinessDate.add_business_days | private method for the addition of business days, used in the addition of a BusinessPeriod only
:param BusinessDate d:
:param int days_int:
:param list holiday_obj:
:return: BusinessDate | businessdate/businessdate.py | def add_business_days(self, days_int, holiday_obj=None):
"""
private method for the addition of business days, used in the addition of a BusinessPeriod only
:param BusinessDate d:
:param int days_int:
:param list holiday_obj:
:return: BusinessDate
"""
re... | def add_business_days(self, days_int, holiday_obj=None):
"""
private method for the addition of business days, used in the addition of a BusinessPeriod only
:param BusinessDate d:
:param int days_int:
:param list holiday_obj:
:return: BusinessDate
"""
re... | [
"private",
"method",
"for",
"the",
"addition",
"of",
"business",
"days",
"used",
"in",
"the",
"addition",
"of",
"a",
"BusinessPeriod",
"only"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/businessdate.py#L431-L455 | [
"def",
"add_business_days",
"(",
"self",
",",
"days_int",
",",
"holiday_obj",
"=",
"None",
")",
":",
"res",
"=",
"self",
"if",
"days_int",
">=",
"0",
":",
"count",
"=",
"0",
"while",
"count",
"<",
"days_int",
":",
"res",
"=",
"BusinessDate",
".",
"add_... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BusinessDate.diff | difference expressed as a tuple of years, months, days
(see also the python lib dateutils.relativedelta)
:param BusinessDate start_date:
:param BusinessDate end_date:
:return (int, int, int): | businessdate/businessdate.py | def diff(self, end_date):
"""
difference expressed as a tuple of years, months, days
(see also the python lib dateutils.relativedelta)
:param BusinessDate start_date:
:param BusinessDate end_date:
:return (int, int, int):
"""
if end_date < self:
... | def diff(self, end_date):
"""
difference expressed as a tuple of years, months, days
(see also the python lib dateutils.relativedelta)
:param BusinessDate start_date:
:param BusinessDate end_date:
:return (int, int, int):
"""
if end_date < self:
... | [
"difference",
"expressed",
"as",
"a",
"tuple",
"of",
"years",
"months",
"days",
"(",
"see",
"also",
"the",
"python",
"lib",
"dateutils",
".",
"relativedelta",
")"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/businessdate.py#L457-L492 | [
"def",
"diff",
"(",
"self",
",",
"end_date",
")",
":",
"if",
"end_date",
"<",
"self",
":",
"y",
",",
"m",
",",
"d",
"=",
"BusinessDate",
".",
"diff",
"(",
"end_date",
",",
"self",
")",
"return",
"-",
"y",
",",
"-",
"m",
",",
"-",
"d",
"y",
"=... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BusinessDate.get_30_360 | implements 30/360 Day Count Convention (4.16(f) 2006 ISDA Definitions) | businessdate/businessdate.py | def get_30_360(self, end):
"""
implements 30/360 Day Count Convention (4.16(f) 2006 ISDA Definitions)
"""
start_day = min(self.day, 30)
end_day = 30 if (start_day == 30 and end.day == 31) else end.day
return (360 * (end.year - self.year) + 30 * (end.month - self.month... | def get_30_360(self, end):
"""
implements 30/360 Day Count Convention (4.16(f) 2006 ISDA Definitions)
"""
start_day = min(self.day, 30)
end_day = 30 if (start_day == 30 and end.day == 31) else end.day
return (360 * (end.year - self.year) + 30 * (end.month - self.month... | [
"implements",
"30",
"/",
"360",
"Day",
"Count",
"Convention",
"(",
"4",
".",
"16",
"(",
"f",
")",
"2006",
"ISDA",
"Definitions",
")"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/businessdate.py#L505-L511 | [
"def",
"get_30_360",
"(",
"self",
",",
"end",
")",
":",
"start_day",
"=",
"min",
"(",
"self",
".",
"day",
",",
"30",
")",
"end_day",
"=",
"30",
"if",
"(",
"start_day",
"==",
"30",
"and",
"end",
".",
"day",
"==",
"31",
")",
"else",
"end",
".",
"... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BusinessDate.get_act_act | implements Act/Act day count convention (4.16(b) 2006 ISDA Definitions) | businessdate/businessdate.py | def get_act_act(self, end):
"""
implements Act/Act day count convention (4.16(b) 2006 ISDA Definitions)
"""
# split end-self in year portions
# if the period does not lie within a year split the days in the period as following:
# restdays of start year / ye... | def get_act_act(self, end):
"""
implements Act/Act day count convention (4.16(b) 2006 ISDA Definitions)
"""
# split end-self in year portions
# if the period does not lie within a year split the days in the period as following:
# restdays of start year / ye... | [
"implements",
"Act",
"/",
"Act",
"day",
"count",
"convention",
"(",
"4",
".",
"16",
"(",
"b",
")",
"2006",
"ISDA",
"Definitions",
")"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/businessdate.py#L531-L560 | [
"def",
"get_act_act",
"(",
"self",
",",
"end",
")",
":",
"# split end-self in year portions",
"# if the period does not lie within a year split the days in the period as following:",
"# restdays of start year / years in between / days in the end year",
"# REMARK: following the affore... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BusinessDate.get_30E_360 | implements the 30E/360 Day Count Convention (4.16(g) 2006 ISDA Definitons) | businessdate/businessdate.py | def get_30E_360(self, end):
"""
implements the 30E/360 Day Count Convention (4.16(g) 2006 ISDA Definitons)
"""
y1, m1, d1 = self.to_ymd()
# adjust to date immediately following the the last day
y2, m2, d2 = end.add_days(0).to_ymd()
d1 = min(d1, 30)
d2 = ... | def get_30E_360(self, end):
"""
implements the 30E/360 Day Count Convention (4.16(g) 2006 ISDA Definitons)
"""
y1, m1, d1 = self.to_ymd()
# adjust to date immediately following the the last day
y2, m2, d2 = end.add_days(0).to_ymd()
d1 = min(d1, 30)
d2 = ... | [
"implements",
"the",
"30E",
"/",
"360",
"Day",
"Count",
"Convention",
"(",
"4",
".",
"16",
"(",
"g",
")",
"2006",
"ISDA",
"Definitons",
")"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/businessdate.py#L575-L587 | [
"def",
"get_30E_360",
"(",
"self",
",",
"end",
")",
":",
"y1",
",",
"m1",
",",
"d1",
"=",
"self",
".",
"to_ymd",
"(",
")",
"# adjust to date immediately following the the last day",
"y2",
",",
"m2",
",",
"d2",
"=",
"end",
".",
"add_days",
"(",
"0",
")",
... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BusinessDate.get_30E_360_ISDA | implements the 30E/360 (ISDA) Day Count Convention (4.16(h) 2006 ISDA Definitions)
:param end:
:return: | businessdate/businessdate.py | def get_30E_360_ISDA(self, end):
"""
implements the 30E/360 (ISDA) Day Count Convention (4.16(h) 2006 ISDA Definitions)
:param end:
:return:
"""
y1, m1, d1 = self.to_ymd()
# ajdust to date immediately following the last day
y2, m2, d2 = end.add_days(0).to_... | def get_30E_360_ISDA(self, end):
"""
implements the 30E/360 (ISDA) Day Count Convention (4.16(h) 2006 ISDA Definitions)
:param end:
:return:
"""
y1, m1, d1 = self.to_ymd()
# ajdust to date immediately following the last day
y2, m2, d2 = end.add_days(0).to_... | [
"implements",
"the",
"30E",
"/",
"360",
"(",
"ISDA",
")",
"Day",
"Count",
"Convention",
"(",
"4",
".",
"16",
"(",
"h",
")",
"2006",
"ISDA",
"Definitions",
")",
":",
"param",
"end",
":",
":",
"return",
":"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/businessdate.py#L589-L604 | [
"def",
"get_30E_360_ISDA",
"(",
"self",
",",
"end",
")",
":",
"y1",
",",
"m1",
",",
"d1",
"=",
"self",
".",
"to_ymd",
"(",
")",
"# ajdust to date immediately following the last day",
"y2",
",",
"m2",
",",
"d2",
"=",
"end",
".",
"add_days",
"(",
"0",
")",... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BusinessDate.adjust_previous | adjusts to Business Day Convention "Preceding" (4.12(a) (iii) 2006 ISDA Definitions). | businessdate/businessdate.py | def adjust_previous(self, holidays_obj=None):
"""
adjusts to Business Day Convention "Preceding" (4.12(a) (iii) 2006 ISDA Definitions).
"""
while not BusinessDate.is_business_day(self, holidays_obj):
self = BusinessDate.add_days(self, -1)
return self | def adjust_previous(self, holidays_obj=None):
"""
adjusts to Business Day Convention "Preceding" (4.12(a) (iii) 2006 ISDA Definitions).
"""
while not BusinessDate.is_business_day(self, holidays_obj):
self = BusinessDate.add_days(self, -1)
return self | [
"adjusts",
"to",
"Business",
"Day",
"Convention",
"Preceding",
"(",
"4",
".",
"12",
"(",
"a",
")",
"(",
"iii",
")",
"2006",
"ISDA",
"Definitions",
")",
"."
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/businessdate.py#L608-L614 | [
"def",
"adjust_previous",
"(",
"self",
",",
"holidays_obj",
"=",
"None",
")",
":",
"while",
"not",
"BusinessDate",
".",
"is_business_day",
"(",
"self",
",",
"holidays_obj",
")",
":",
"self",
"=",
"BusinessDate",
".",
"add_days",
"(",
"self",
",",
"-",
"1",... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BusinessDate.adjust_follow | adjusts to Business Day Convention "Following" (4.12(a) (i) 2006 ISDA Definitions). | businessdate/businessdate.py | def adjust_follow(self, holidays_obj=None):
"""
adjusts to Business Day Convention "Following" (4.12(a) (i) 2006 ISDA Definitions).
"""
while not BusinessDate.is_business_day(self, holidays_obj):
self = BusinessDate.add_days(self, 1)
return self | def adjust_follow(self, holidays_obj=None):
"""
adjusts to Business Day Convention "Following" (4.12(a) (i) 2006 ISDA Definitions).
"""
while not BusinessDate.is_business_day(self, holidays_obj):
self = BusinessDate.add_days(self, 1)
return self | [
"adjusts",
"to",
"Business",
"Day",
"Convention",
"Following",
"(",
"4",
".",
"12",
"(",
"a",
")",
"(",
"i",
")",
"2006",
"ISDA",
"Definitions",
")",
"."
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/businessdate.py#L616-L622 | [
"def",
"adjust_follow",
"(",
"self",
",",
"holidays_obj",
"=",
"None",
")",
":",
"while",
"not",
"BusinessDate",
".",
"is_business_day",
"(",
"self",
",",
"holidays_obj",
")",
":",
"self",
"=",
"BusinessDate",
".",
"add_days",
"(",
"self",
",",
"1",
")",
... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BusinessDate.adjust_mod_follow | adjusts to Business Day Convention "Modified [Following]" (4.12(a) (ii) 2006 ISDA Definitions). | businessdate/businessdate.py | def adjust_mod_follow(self, holidays_obj=None):
"""
adjusts to Business Day Convention "Modified [Following]" (4.12(a) (ii) 2006 ISDA Definitions).
"""
month = self.month
new = BusinessDate.adjust_follow(self, holidays_obj)
if month != new.month:
new = Busines... | def adjust_mod_follow(self, holidays_obj=None):
"""
adjusts to Business Day Convention "Modified [Following]" (4.12(a) (ii) 2006 ISDA Definitions).
"""
month = self.month
new = BusinessDate.adjust_follow(self, holidays_obj)
if month != new.month:
new = Busines... | [
"adjusts",
"to",
"Business",
"Day",
"Convention",
"Modified",
"[",
"Following",
"]",
"(",
"4",
".",
"12",
"(",
"a",
")",
"(",
"ii",
")",
"2006",
"ISDA",
"Definitions",
")",
"."
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/businessdate.py#L624-L633 | [
"def",
"adjust_mod_follow",
"(",
"self",
",",
"holidays_obj",
"=",
"None",
")",
":",
"month",
"=",
"self",
".",
"month",
"new",
"=",
"BusinessDate",
".",
"adjust_follow",
"(",
"self",
",",
"holidays_obj",
")",
"if",
"month",
"!=",
"new",
".",
"month",
":... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BusinessDate.adjust_mod_previous | ajusts to Business Day Convention "Modified Preceding" (not in 2006 ISDA Definitons). | businessdate/businessdate.py | def adjust_mod_previous(self, holidays_obj=None):
"""
ajusts to Business Day Convention "Modified Preceding" (not in 2006 ISDA Definitons).
"""
month = self.month
new = BusinessDate.adjust_previous(self, holidays_obj)
if month != new.month:
new = BusinessDate.... | def adjust_mod_previous(self, holidays_obj=None):
"""
ajusts to Business Day Convention "Modified Preceding" (not in 2006 ISDA Definitons).
"""
month = self.month
new = BusinessDate.adjust_previous(self, holidays_obj)
if month != new.month:
new = BusinessDate.... | [
"ajusts",
"to",
"Business",
"Day",
"Convention",
"Modified",
"Preceding",
"(",
"not",
"in",
"2006",
"ISDA",
"Definitons",
")",
"."
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/businessdate.py#L635-L644 | [
"def",
"adjust_mod_previous",
"(",
"self",
",",
"holidays_obj",
"=",
"None",
")",
":",
"month",
"=",
"self",
".",
"month",
"new",
"=",
"BusinessDate",
".",
"adjust_previous",
"(",
"self",
",",
"holidays_obj",
")",
"if",
"month",
"!=",
"new",
".",
"month",
... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BusinessPeriod.is_businessperiod | :param in_period: object to be checked
:type in_period: object, str, timedelta
:return: True if cast works
:rtype: Boolean
checks is argument con becasted to BusinessPeriod | businessdate/businessdate.py | def is_businessperiod(cls, in_period):
"""
:param in_period: object to be checked
:type in_period: object, str, timedelta
:return: True if cast works
:rtype: Boolean
checks is argument con becasted to BusinessPeriod
"""
try: # to be removed
i... | def is_businessperiod(cls, in_period):
"""
:param in_period: object to be checked
:type in_period: object, str, timedelta
:return: True if cast works
:rtype: Boolean
checks is argument con becasted to BusinessPeriod
"""
try: # to be removed
i... | [
":",
"param",
"in_period",
":",
"object",
"to",
"be",
"checked",
":",
"type",
"in_period",
":",
"object",
"str",
"timedelta",
":",
"return",
":",
"True",
"if",
"cast",
"works",
":",
"rtype",
":",
"Boolean"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/businessdate.py#L761-L777 | [
"def",
"is_businessperiod",
"(",
"cls",
",",
"in_period",
")",
":",
"try",
":",
"# to be removed",
"if",
"str",
"(",
"in_period",
")",
".",
"upper",
"(",
")",
"==",
"'0D'",
":",
"return",
"True",
"else",
":",
"p",
"=",
"BusinessPeriod",
"(",
"str",
"("... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | quoted | Parses as much as possible until it encounters a matching closing quote.
By default matches any_token, but can be provided with a more specific parser if required.
Returns a string | picoparse/text.py | def quoted(parser=any_token):
"""Parses as much as possible until it encounters a matching closing quote.
By default matches any_token, but can be provided with a more specific parser if required.
Returns a string
"""
quote_char = quote()
value, _ = many_until(parser, partial(one_of, quote_... | def quoted(parser=any_token):
"""Parses as much as possible until it encounters a matching closing quote.
By default matches any_token, but can be provided with a more specific parser if required.
Returns a string
"""
quote_char = quote()
value, _ = many_until(parser, partial(one_of, quote_... | [
"Parses",
"as",
"much",
"as",
"possible",
"until",
"it",
"encounters",
"a",
"matching",
"closing",
"quote",
".",
"By",
"default",
"matches",
"any_token",
"but",
"can",
"be",
"provided",
"with",
"a",
"more",
"specific",
"parser",
"if",
"required",
".",
"Retur... | brehaut/picoparse | python | https://github.com/brehaut/picoparse/blob/5e07c8e687a021bba58a5a2a76696c7a7ff35a1c/picoparse/text.py#L64-L72 | [
"def",
"quoted",
"(",
"parser",
"=",
"any_token",
")",
":",
"quote_char",
"=",
"quote",
"(",
")",
"value",
",",
"_",
"=",
"many_until",
"(",
"parser",
",",
"partial",
"(",
"one_of",
",",
"quote_char",
")",
")",
"return",
"build_string",
"(",
"value",
"... | 5e07c8e687a021bba58a5a2a76696c7a7ff35a1c |
valid | days_in_month | returns number of days for the given year and month
:param int year: calendar year
:param int month: calendar month
:return int: | businessdate/basedate.py | def days_in_month(year, month):
"""
returns number of days for the given year and month
:param int year: calendar year
:param int month: calendar month
:return int:
"""
eom = _days_per_month[month - 1]
if is_leap_year(year) and month == 2:
eom += 1
return eom | def days_in_month(year, month):
"""
returns number of days for the given year and month
:param int year: calendar year
:param int month: calendar month
:return int:
"""
eom = _days_per_month[month - 1]
if is_leap_year(year) and month == 2:
eom += 1
return eom | [
"returns",
"number",
"of",
"days",
"for",
"the",
"given",
"year",
"and",
"month"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/basedate.py#L54-L67 | [
"def",
"days_in_month",
"(",
"year",
",",
"month",
")",
":",
"eom",
"=",
"_days_per_month",
"[",
"month",
"-",
"1",
"]",
"if",
"is_leap_year",
"(",
"year",
")",
"and",
"month",
"==",
"2",
":",
"eom",
"+=",
"1",
"return",
"eom"
] | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | is_valid_ymd | return True if (year,month, day) can be represented in Excel-notation
(number of days since 30.12.1899) for calendar days, otherwise False
:param int year: calendar year
:param int month: calendar month
:param int day: calendar day
:return bool: | businessdate/basedate.py | def is_valid_ymd(year, month, day):
"""
return True if (year,month, day) can be represented in Excel-notation
(number of days since 30.12.1899) for calendar days, otherwise False
:param int year: calendar year
:param int month: calendar month
:param int day: calendar day
:return bool:
"... | def is_valid_ymd(year, month, day):
"""
return True if (year,month, day) can be represented in Excel-notation
(number of days since 30.12.1899) for calendar days, otherwise False
:param int year: calendar year
:param int month: calendar month
:param int day: calendar day
:return bool:
"... | [
"return",
"True",
"if",
"(",
"year",
"month",
"day",
")",
"can",
"be",
"represented",
"in",
"Excel",
"-",
"notation",
"(",
"number",
"of",
"days",
"since",
"30",
".",
"12",
".",
"1899",
")",
"for",
"calendar",
"days",
"otherwise",
"False"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/basedate.py#L70-L81 | [
"def",
"is_valid_ymd",
"(",
"year",
",",
"month",
",",
"day",
")",
":",
"return",
"1",
"<=",
"month",
"<=",
"12",
"and",
"1",
"<=",
"day",
"<=",
"days_in_month",
"(",
"year",
",",
"month",
")",
"and",
"year",
">=",
"1899"
] | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | from_excel_to_ymd | converts date in Microsoft Excel representation style and returns `(year, month, day)` tuple
:param int excel_int: date as int (days since 1899-12-31)
:return tuple(int, int, int): | businessdate/basedate.py | def from_excel_to_ymd(excel_int):
"""
converts date in Microsoft Excel representation style and returns `(year, month, day)` tuple
:param int excel_int: date as int (days since 1899-12-31)
:return tuple(int, int, int):
"""
int_date = int(floor(excel_int))
int_date -= 1 if excel_int > 60 e... | def from_excel_to_ymd(excel_int):
"""
converts date in Microsoft Excel representation style and returns `(year, month, day)` tuple
:param int excel_int: date as int (days since 1899-12-31)
:return tuple(int, int, int):
"""
int_date = int(floor(excel_int))
int_date -= 1 if excel_int > 60 e... | [
"converts",
"date",
"in",
"Microsoft",
"Excel",
"representation",
"style",
"and",
"returns",
"(",
"year",
"month",
"day",
")",
"tuple"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/basedate.py#L84-L118 | [
"def",
"from_excel_to_ymd",
"(",
"excel_int",
")",
":",
"int_date",
"=",
"int",
"(",
"floor",
"(",
"excel_int",
")",
")",
"int_date",
"-=",
"1",
"if",
"excel_int",
">",
"60",
"else",
"0",
"# jan dingerkus: There are two errors in excels own date <> int conversion.",
... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | from_ymd_to_excel | converts date as `(year, month, day)` tuple into Microsoft Excel representation style
:param tuple(int, int, int): int tuple `year, month, day`
:return int: | businessdate/basedate.py | def from_ymd_to_excel(year, month, day):
"""
converts date as `(year, month, day)` tuple into Microsoft Excel representation style
:param tuple(int, int, int): int tuple `year, month, day`
:return int:
"""
if not is_valid_ymd(year, month, day):
raise ValueError("Invalid date {0}.{1}.{2}... | def from_ymd_to_excel(year, month, day):
"""
converts date as `(year, month, day)` tuple into Microsoft Excel representation style
:param tuple(int, int, int): int tuple `year, month, day`
:return int:
"""
if not is_valid_ymd(year, month, day):
raise ValueError("Invalid date {0}.{1}.{2}... | [
"converts",
"date",
"as",
"(",
"year",
"month",
"day",
")",
"tuple",
"into",
"Microsoft",
"Excel",
"representation",
"style"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/basedate.py#L121-L140 | [
"def",
"from_ymd_to_excel",
"(",
"year",
",",
"month",
",",
"day",
")",
":",
"if",
"not",
"is_valid_ymd",
"(",
"year",
",",
"month",
",",
"day",
")",
":",
"raise",
"ValueError",
"(",
"\"Invalid date {0}.{1}.{2}\"",
".",
"format",
"(",
"year",
",",
"month",... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BaseDateFloat.add_years | adds number of years to a date
:param BaseDateFloat d: date to add years to
:param int years_int: number of years to add
:return BaseDate: resulting date | businessdate/basedate.py | def add_years(d, years_int):
"""
adds number of years to a date
:param BaseDateFloat d: date to add years to
:param int years_int: number of years to add
:return BaseDate: resulting date
"""
y, m, d = BaseDate.to_ymd(d)
if not is_leap_year(years_int) and ... | def add_years(d, years_int):
"""
adds number of years to a date
:param BaseDateFloat d: date to add years to
:param int years_int: number of years to add
:return BaseDate: resulting date
"""
y, m, d = BaseDate.to_ymd(d)
if not is_leap_year(years_int) and ... | [
"adds",
"number",
"of",
"years",
"to",
"a",
"date",
":",
"param",
"BaseDateFloat",
"d",
":",
"date",
"to",
"add",
"years",
"to",
":",
"param",
"int",
"years_int",
":",
"number",
"of",
"years",
"to",
"add",
":",
"return",
"BaseDate",
":",
"resulting",
"... | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/basedate.py#L204-L215 | [
"def",
"add_years",
"(",
"d",
",",
"years_int",
")",
":",
"y",
",",
"m",
",",
"d",
"=",
"BaseDate",
".",
"to_ymd",
"(",
"d",
")",
"if",
"not",
"is_leap_year",
"(",
"years_int",
")",
"and",
"m",
"==",
"2",
":",
"d",
"=",
"min",
"(",
"28",
",",
... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BaseDateDatetimeDate.add_days | addition of a number of days
:param BaseDateDatetimeDate d:
:param int days_int:
:return BaseDatetimeDate: | businessdate/basedate.py | def add_days(d, days_int):
"""
addition of a number of days
:param BaseDateDatetimeDate d:
:param int days_int:
:return BaseDatetimeDate:
"""
n = date(d.year, d.month, d.day) + timedelta(days_int)
return BaseDateDatetimeDate(n.year, n.month, n.day) | def add_days(d, days_int):
"""
addition of a number of days
:param BaseDateDatetimeDate d:
:param int days_int:
:return BaseDatetimeDate:
"""
n = date(d.year, d.month, d.day) + timedelta(days_int)
return BaseDateDatetimeDate(n.year, n.month, n.day) | [
"addition",
"of",
"a",
"number",
"of",
"days"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/basedate.py#L274-L283 | [
"def",
"add_days",
"(",
"d",
",",
"days_int",
")",
":",
"n",
"=",
"date",
"(",
"d",
".",
"year",
",",
"d",
".",
"month",
",",
"d",
".",
"day",
")",
"+",
"timedelta",
"(",
"days_int",
")",
"return",
"BaseDateDatetimeDate",
"(",
"n",
".",
"year",
"... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BaseDateDatetimeDate.add_years | addition of a number of years
:param BaseDateDatetimeDate d:
:param int years_int:
:return BaseDatetimeDate: | businessdate/basedate.py | def add_years(d, years_int):
"""
addition of a number of years
:param BaseDateDatetimeDate d:
:param int years_int:
:return BaseDatetimeDate:
"""
y, m, d = BaseDateDatetimeDate.to_ymd(d)
y += years_int
if not is_leap_year(y) and m == 2:
... | def add_years(d, years_int):
"""
addition of a number of years
:param BaseDateDatetimeDate d:
:param int years_int:
:return BaseDatetimeDate:
"""
y, m, d = BaseDateDatetimeDate.to_ymd(d)
y += years_int
if not is_leap_year(y) and m == 2:
... | [
"addition",
"of",
"a",
"number",
"of",
"years"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/basedate.py#L286-L298 | [
"def",
"add_years",
"(",
"d",
",",
"years_int",
")",
":",
"y",
",",
"m",
",",
"d",
"=",
"BaseDateDatetimeDate",
".",
"to_ymd",
"(",
"d",
")",
"y",
"+=",
"years_int",
"if",
"not",
"is_leap_year",
"(",
"y",
")",
"and",
"m",
"==",
"2",
":",
"d",
"="... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BaseDateDatetimeDate.diff_in_days | calculate difference between given dates in days
:param BaseDateDatetimeDate start: state date
:param BaseDateDatetimeDate end: end date
:return float: difference between end date and start date in days | businessdate/basedate.py | def diff_in_days(start, end):
"""
calculate difference between given dates in days
:param BaseDateDatetimeDate start: state date
:param BaseDateDatetimeDate end: end date
:return float: difference between end date and start date in days
"""
diff = date(end.year, ... | def diff_in_days(start, end):
"""
calculate difference between given dates in days
:param BaseDateDatetimeDate start: state date
:param BaseDateDatetimeDate end: end date
:return float: difference between end date and start date in days
"""
diff = date(end.year, ... | [
"calculate",
"difference",
"between",
"given",
"dates",
"in",
"days"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/basedate.py#L301-L310 | [
"def",
"diff_in_days",
"(",
"start",
",",
"end",
")",
":",
"diff",
"=",
"date",
"(",
"end",
".",
"year",
",",
"end",
".",
"month",
",",
"end",
".",
"day",
")",
"-",
"date",
"(",
"start",
".",
"year",
",",
"start",
".",
"month",
",",
"start",
".... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BaseDateTuple.add_days | addition of a number of days
:param BaseDateTuple d:
:param int days_int:
:return BaseDatetimeDate: | businessdate/basedate.py | def add_days(date_obj, days_int):
"""
addition of a number of days
:param BaseDateTuple d:
:param int days_int:
:return BaseDatetimeDate:
"""
n = from_ymd_to_excel(*date_obj.date) + days_int
return BaseDateTuple(*from_excel_to_ymd(n)) | def add_days(date_obj, days_int):
"""
addition of a number of days
:param BaseDateTuple d:
:param int days_int:
:return BaseDatetimeDate:
"""
n = from_ymd_to_excel(*date_obj.date) + days_int
return BaseDateTuple(*from_excel_to_ymd(n)) | [
"addition",
"of",
"a",
"number",
"of",
"days"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/basedate.py#L380-L390 | [
"def",
"add_days",
"(",
"date_obj",
",",
"days_int",
")",
":",
"n",
"=",
"from_ymd_to_excel",
"(",
"*",
"date_obj",
".",
"date",
")",
"+",
"days_int",
"return",
"BaseDateTuple",
"(",
"*",
"from_excel_to_ymd",
"(",
"n",
")",
")"
] | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BaseDateTuple.add_years | addition of a number of years
:param BaseDateTuple d:
:param int years_int:
:return BaseDatetimeDate: | businessdate/basedate.py | def add_years(date_obj, years_int):
"""
addition of a number of years
:param BaseDateTuple d:
:param int years_int:
:return BaseDatetimeDate:
"""
y, m, d = BaseDateTuple.to_ymd(date_obj)
y += years_int
if not is_leap_year(y) and m == 2:
... | def add_years(date_obj, years_int):
"""
addition of a number of years
:param BaseDateTuple d:
:param int years_int:
:return BaseDatetimeDate:
"""
y, m, d = BaseDateTuple.to_ymd(date_obj)
y += years_int
if not is_leap_year(y) and m == 2:
... | [
"addition",
"of",
"a",
"number",
"of",
"years"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/basedate.py#L393-L405 | [
"def",
"add_years",
"(",
"date_obj",
",",
"years_int",
")",
":",
"y",
",",
"m",
",",
"d",
"=",
"BaseDateTuple",
".",
"to_ymd",
"(",
"date_obj",
")",
"y",
"+=",
"years_int",
"if",
"not",
"is_leap_year",
"(",
"y",
")",
"and",
"m",
"==",
"2",
":",
"d"... | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | BaseDateTuple.diff_in_days | calculate difference between given dates in days
:param BaseDateTuple start: state date
:param BaseDateTuple end: end date
:return float: difference between end date and start date in days | businessdate/basedate.py | def diff_in_days(start, end):
"""
calculate difference between given dates in days
:param BaseDateTuple start: state date
:param BaseDateTuple end: end date
:return float: difference between end date and start date in days
"""
diff = from_ymd_to_excel(*end.date)... | def diff_in_days(start, end):
"""
calculate difference between given dates in days
:param BaseDateTuple start: state date
:param BaseDateTuple end: end date
:return float: difference between end date and start date in days
"""
diff = from_ymd_to_excel(*end.date)... | [
"calculate",
"difference",
"between",
"given",
"dates",
"in",
"days"
] | pbrisk/businessdate | python | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/basedate.py#L408-L418 | [
"def",
"diff_in_days",
"(",
"start",
",",
"end",
")",
":",
"diff",
"=",
"from_ymd_to_excel",
"(",
"*",
"end",
".",
"date",
")",
"-",
"from_ymd_to_excel",
"(",
"*",
"start",
".",
"date",
")",
"return",
"float",
"(",
"diff",
")"
] | 79a0c5a4e557cbacca82a430403b18413404a9bc |
valid | Plugin.setup | Initialize the application. | muffin_peewee/plugin.py | def setup(self, app): # noqa
"""Initialize the application."""
super().setup(app)
# Setup Database
self.database.initialize(connect(self.cfg.connection, **self.cfg.connection_params))
# Fix SQLite in-memory database
if self.database.database == ':memory:':
... | def setup(self, app): # noqa
"""Initialize the application."""
super().setup(app)
# Setup Database
self.database.initialize(connect(self.cfg.connection, **self.cfg.connection_params))
# Fix SQLite in-memory database
if self.database.database == ':memory:':
... | [
"Initialize",
"the",
"application",
"."
] | klen/muffin-peewee | python | https://github.com/klen/muffin-peewee/blob/8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e/muffin_peewee/plugin.py#L43-L109 | [
"def",
"setup",
"(",
"self",
",",
"app",
")",
":",
"# noqa",
"super",
"(",
")",
".",
"setup",
"(",
"app",
")",
"# Setup Database",
"self",
".",
"database",
".",
"initialize",
"(",
"connect",
"(",
"self",
".",
"cfg",
".",
"connection",
",",
"*",
"*",
... | 8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e |
valid | Plugin.startup | Register connection's middleware and prepare self database. | muffin_peewee/plugin.py | def startup(self, app):
"""Register connection's middleware and prepare self database."""
self.database.init_async(app.loop)
if not self.cfg.connection_manual:
app.middlewares.insert(0, self._middleware) | def startup(self, app):
"""Register connection's middleware and prepare self database."""
self.database.init_async(app.loop)
if not self.cfg.connection_manual:
app.middlewares.insert(0, self._middleware) | [
"Register",
"connection",
"s",
"middleware",
"and",
"prepare",
"self",
"database",
"."
] | klen/muffin-peewee | python | https://github.com/klen/muffin-peewee/blob/8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e/muffin_peewee/plugin.py#L111-L115 | [
"def",
"startup",
"(",
"self",
",",
"app",
")",
":",
"self",
".",
"database",
".",
"init_async",
"(",
"app",
".",
"loop",
")",
"if",
"not",
"self",
".",
"cfg",
".",
"connection_manual",
":",
"app",
".",
"middlewares",
".",
"insert",
"(",
"0",
",",
... | 8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e |
valid | Plugin.cleanup | Close all connections. | muffin_peewee/plugin.py | def cleanup(self, app):
"""Close all connections."""
if hasattr(self.database.obj, 'close_all'):
self.database.close_all() | def cleanup(self, app):
"""Close all connections."""
if hasattr(self.database.obj, 'close_all'):
self.database.close_all() | [
"Close",
"all",
"connections",
"."
] | klen/muffin-peewee | python | https://github.com/klen/muffin-peewee/blob/8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e/muffin_peewee/plugin.py#L117-L120 | [
"def",
"cleanup",
"(",
"self",
",",
"app",
")",
":",
"if",
"hasattr",
"(",
"self",
".",
"database",
".",
"obj",
",",
"'close_all'",
")",
":",
"self",
".",
"database",
".",
"close_all",
"(",
")"
] | 8e893e3ea1dfc82fbcfc6efe784308c8d4e2852e |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.