repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
srittau/python-asserts | asserts/__init__.py | assert_raises_regex | def assert_raises_regex(exception, regex, msg_fmt="{msg}"):
"""Fail unless an exception with a message that matches a regular
expression is raised within the context.
The regular expression can be a regular expression string or object.
>>> with assert_raises_regex(ValueError, r"\\d+"):
... ra... | python | def assert_raises_regex(exception, regex, msg_fmt="{msg}"):
"""Fail unless an exception with a message that matches a regular
expression is raised within the context.
The regular expression can be a regular expression string or object.
>>> with assert_raises_regex(ValueError, r"\\d+"):
... ra... | [
"def",
"assert_raises_regex",
"(",
"exception",
",",
"regex",
",",
"msg_fmt",
"=",
"\"{msg}\"",
")",
":",
"def",
"test",
"(",
"exc",
")",
":",
"compiled",
"=",
"re",
".",
"compile",
"(",
"regex",
")",
"if",
"not",
"exc",
".",
"args",
":",
"msg",
"=",... | Fail unless an exception with a message that matches a regular
expression is raised within the context.
The regular expression can be a regular expression string or object.
>>> with assert_raises_regex(ValueError, r"\\d+"):
... raise ValueError("Error #42")
...
>>> with assert_raises_rege... | [
"Fail",
"unless",
"an",
"exception",
"with",
"a",
"message",
"that",
"matches",
"a",
"regular",
"expression",
"is",
"raised",
"within",
"the",
"context",
"."
] | 1d5c797031c68ee27552d1c94e7f918c3d3d0453 | https://github.com/srittau/python-asserts/blob/1d5c797031c68ee27552d1c94e7f918c3d3d0453/asserts/__init__.py#L983-L1035 | train |
srittau/python-asserts | asserts/__init__.py | assert_raises_errno | def assert_raises_errno(exception, errno, msg_fmt="{msg}"):
"""Fail unless an exception with a specific errno is raised with the
context.
>>> with assert_raises_errno(OSError, 42):
... raise OSError(42, "OS Error")
...
>>> with assert_raises_errno(OSError, 44):
... raise OSError(17... | python | def assert_raises_errno(exception, errno, msg_fmt="{msg}"):
"""Fail unless an exception with a specific errno is raised with the
context.
>>> with assert_raises_errno(OSError, 42):
... raise OSError(42, "OS Error")
...
>>> with assert_raises_errno(OSError, 44):
... raise OSError(17... | [
"def",
"assert_raises_errno",
"(",
"exception",
",",
"errno",
",",
"msg_fmt",
"=",
"\"{msg}\"",
")",
":",
"def",
"check_errno",
"(",
"exc",
")",
":",
"if",
"errno",
"!=",
"exc",
".",
"errno",
":",
"msg",
"=",
"\"wrong errno: {!r} != {!r}\"",
".",
"format",
... | Fail unless an exception with a specific errno is raised with the
context.
>>> with assert_raises_errno(OSError, 42):
... raise OSError(42, "OS Error")
...
>>> with assert_raises_errno(OSError, 44):
... raise OSError(17, "OS Error")
...
Traceback (most recent call last):
... | [
"Fail",
"unless",
"an",
"exception",
"with",
"a",
"specific",
"errno",
"is",
"raised",
"with",
"the",
"context",
"."
] | 1d5c797031c68ee27552d1c94e7f918c3d3d0453 | https://github.com/srittau/python-asserts/blob/1d5c797031c68ee27552d1c94e7f918c3d3d0453/asserts/__init__.py#L1038-L1075 | train |
srittau/python-asserts | asserts/__init__.py | assert_succeeds | def assert_succeeds(exception, msg_fmt="{msg}"):
"""Fail if a specific exception is raised within the context.
This assertion should be used for cases, where successfully running a
function signals a successful test, and raising the exception of a
certain type signals a test failure. All other raised e... | python | def assert_succeeds(exception, msg_fmt="{msg}"):
"""Fail if a specific exception is raised within the context.
This assertion should be used for cases, where successfully running a
function signals a successful test, and raising the exception of a
certain type signals a test failure. All other raised e... | [
"def",
"assert_succeeds",
"(",
"exception",
",",
"msg_fmt",
"=",
"\"{msg}\"",
")",
":",
"class",
"_AssertSucceeds",
"(",
"object",
")",
":",
"def",
"__enter__",
"(",
"self",
")",
":",
"pass",
"def",
"__exit__",
"(",
"self",
",",
"exc_type",
",",
"exc_val",... | Fail if a specific exception is raised within the context.
This assertion should be used for cases, where successfully running a
function signals a successful test, and raising the exception of a
certain type signals a test failure. All other raised exceptions are
passed on and will usually still resul... | [
"Fail",
"if",
"a",
"specific",
"exception",
"is",
"raised",
"within",
"the",
"context",
"."
] | 1d5c797031c68ee27552d1c94e7f918c3d3d0453 | https://github.com/srittau/python-asserts/blob/1d5c797031c68ee27552d1c94e7f918c3d3d0453/asserts/__init__.py#L1078-L1127 | train |
srittau/python-asserts | asserts/__init__.py | assert_warns_regex | def assert_warns_regex(warning_type, regex, msg_fmt="{msg}"):
"""Fail unless a warning with a message is issued inside the context.
The message can be a regular expression string or object.
>>> from warnings import warn
>>> with assert_warns_regex(UserWarning, r"#\\d+"):
... warn("Error #42", ... | python | def assert_warns_regex(warning_type, regex, msg_fmt="{msg}"):
"""Fail unless a warning with a message is issued inside the context.
The message can be a regular expression string or object.
>>> from warnings import warn
>>> with assert_warns_regex(UserWarning, r"#\\d+"):
... warn("Error #42", ... | [
"def",
"assert_warns_regex",
"(",
"warning_type",
",",
"regex",
",",
"msg_fmt",
"=",
"\"{msg}\"",
")",
":",
"def",
"test",
"(",
"warning",
")",
":",
"return",
"re",
".",
"search",
"(",
"regex",
",",
"str",
"(",
"warning",
".",
"message",
")",
")",
"is"... | Fail unless a warning with a message is issued inside the context.
The message can be a regular expression string or object.
>>> from warnings import warn
>>> with assert_warns_regex(UserWarning, r"#\\d+"):
... warn("Error #42", UserWarning)
...
>>> with assert_warns_regex(UserWarning, r"E... | [
"Fail",
"unless",
"a",
"warning",
"with",
"a",
"message",
"is",
"issued",
"inside",
"the",
"context",
"."
] | 1d5c797031c68ee27552d1c94e7f918c3d3d0453 | https://github.com/srittau/python-asserts/blob/1d5c797031c68ee27552d1c94e7f918c3d3d0453/asserts/__init__.py#L1249-L1277 | train |
srittau/python-asserts | asserts/__init__.py | assert_json_subset | def assert_json_subset(first, second):
"""Assert that a JSON object or array is a subset of another JSON object
or array.
The first JSON object or array must be supplied as a JSON-compatible
dict or list, the JSON object or array to check must be a string, an
UTF-8 bytes object, or a JSON-compatibl... | python | def assert_json_subset(first, second):
"""Assert that a JSON object or array is a subset of another JSON object
or array.
The first JSON object or array must be supplied as a JSON-compatible
dict or list, the JSON object or array to check must be a string, an
UTF-8 bytes object, or a JSON-compatibl... | [
"def",
"assert_json_subset",
"(",
"first",
",",
"second",
")",
":",
"if",
"not",
"isinstance",
"(",
"second",
",",
"(",
"dict",
",",
"list",
",",
"str",
",",
"bytes",
")",
")",
":",
"raise",
"TypeError",
"(",
"\"second must be dict, list, str, or bytes\"",
"... | Assert that a JSON object or array is a subset of another JSON object
or array.
The first JSON object or array must be supplied as a JSON-compatible
dict or list, the JSON object or array to check must be a string, an
UTF-8 bytes object, or a JSON-compatible list or dict.
A JSON non-object, non-ar... | [
"Assert",
"that",
"a",
"JSON",
"object",
"or",
"array",
"is",
"a",
"subset",
"of",
"another",
"JSON",
"object",
"or",
"array",
"."
] | 1d5c797031c68ee27552d1c94e7f918c3d3d0453 | https://github.com/srittau/python-asserts/blob/1d5c797031c68ee27552d1c94e7f918c3d3d0453/asserts/__init__.py#L1286-L1341 | train |
scidam/cachepy | backends/base.py | BaseBackend.get_data | def get_data(self, data_key, key=''):
"""Get the data from the cache.
:param data_key: a key for accessing the data;
:param key: if provided (e.g. non-empty string), will be used to
decrypt the data as a password;
:returns: the data extracted from the cache, a pytho... | python | def get_data(self, data_key, key=''):
"""Get the data from the cache.
:param data_key: a key for accessing the data;
:param key: if provided (e.g. non-empty string), will be used to
decrypt the data as a password;
:returns: the data extracted from the cache, a pytho... | [
"def",
"get_data",
"(",
"self",
",",
"data_key",
",",
"key",
"=",
"''",
")",
":",
"flag",
"=",
"False",
"extracted",
"=",
"self",
".",
"get",
"(",
"data_key",
",",
"-",
"1",
")",
"if",
"extracted",
"!=",
"-",
"1",
":",
"try",
":",
"data",
",",
... | Get the data from the cache.
:param data_key: a key for accessing the data;
:param key: if provided (e.g. non-empty string), will be used to
decrypt the data as a password;
:returns: the data extracted from the cache, a python object. | [
"Get",
"the",
"data",
"from",
"the",
"cache",
"."
] | 680eeb7ff04ec9bb634b71cceb0841abaf2d530e | https://github.com/scidam/cachepy/blob/680eeb7ff04ec9bb634b71cceb0841abaf2d530e/backends/base.py#L99-L131 | train |
scidam/cachepy | utils.py | Helpers.encode_safely | def encode_safely(self, data):
"""Encode the data.
"""
encoder = self.base_encoder
result = settings.null
try:
result = encoder(pickle.dumps(data))
except:
warnings.warn("Data could not be serialized.", RuntimeWarning)
return resu... | python | def encode_safely(self, data):
"""Encode the data.
"""
encoder = self.base_encoder
result = settings.null
try:
result = encoder(pickle.dumps(data))
except:
warnings.warn("Data could not be serialized.", RuntimeWarning)
return resu... | [
"def",
"encode_safely",
"(",
"self",
",",
"data",
")",
":",
"encoder",
"=",
"self",
".",
"base_encoder",
"result",
"=",
"settings",
".",
"null",
"try",
":",
"result",
"=",
"encoder",
"(",
"pickle",
".",
"dumps",
"(",
"data",
")",
")",
"except",
":",
... | Encode the data. | [
"Encode",
"the",
"data",
"."
] | 680eeb7ff04ec9bb634b71cceb0841abaf2d530e | https://github.com/scidam/cachepy/blob/680eeb7ff04ec9bb634b71cceb0841abaf2d530e/utils.py#L49-L60 | train |
scidam/cachepy | utils.py | Helpers.decode_safely | def decode_safely(self, encoded_data):
"""Inverse for the `encode_safely` function.
"""
decoder = self.base_decoder
result = settings.null
try:
result = pickle.loads(decoder(encoded_data))
except:
warnings.warn("Could not load and deserialize the... | python | def decode_safely(self, encoded_data):
"""Inverse for the `encode_safely` function.
"""
decoder = self.base_decoder
result = settings.null
try:
result = pickle.loads(decoder(encoded_data))
except:
warnings.warn("Could not load and deserialize the... | [
"def",
"decode_safely",
"(",
"self",
",",
"encoded_data",
")",
":",
"decoder",
"=",
"self",
".",
"base_decoder",
"result",
"=",
"settings",
".",
"null",
"try",
":",
"result",
"=",
"pickle",
".",
"loads",
"(",
"decoder",
"(",
"encoded_data",
")",
")",
"ex... | Inverse for the `encode_safely` function. | [
"Inverse",
"for",
"the",
"encode_safely",
"function",
"."
] | 680eeb7ff04ec9bb634b71cceb0841abaf2d530e | https://github.com/scidam/cachepy/blob/680eeb7ff04ec9bb634b71cceb0841abaf2d530e/utils.py#L63-L74 | train |
scidam/cachepy | utils.py | Helpers.get_function_hash | def get_function_hash(self, func, args=None, kwargs=None, ttl=None, key=None, noc=None):
"""Compute the hash of the function to be evaluated.
"""
base_hash = settings.HASH_FUNCTION()
if PY3:
base_hash.update(func.__name__.encode(settings.DEFAULT_ENCODING))
else:
... | python | def get_function_hash(self, func, args=None, kwargs=None, ttl=None, key=None, noc=None):
"""Compute the hash of the function to be evaluated.
"""
base_hash = settings.HASH_FUNCTION()
if PY3:
base_hash.update(func.__name__.encode(settings.DEFAULT_ENCODING))
else:
... | [
"def",
"get_function_hash",
"(",
"self",
",",
"func",
",",
"args",
"=",
"None",
",",
"kwargs",
"=",
"None",
",",
"ttl",
"=",
"None",
",",
"key",
"=",
"None",
",",
"noc",
"=",
"None",
")",
":",
"base_hash",
"=",
"settings",
".",
"HASH_FUNCTION",
"(",
... | Compute the hash of the function to be evaluated. | [
"Compute",
"the",
"hash",
"of",
"the",
"function",
"to",
"be",
"evaluated",
"."
] | 680eeb7ff04ec9bb634b71cceb0841abaf2d530e | https://github.com/scidam/cachepy/blob/680eeb7ff04ec9bb634b71cceb0841abaf2d530e/utils.py#L76-L115 | train |
scidam/cachepy | crypter.py | to_bytes | def to_bytes(obj):
"""Ensures that the obj is of byte-type.
"""
if PY3:
if isinstance(obj, str):
return obj.encode(settings.DEFAULT_ENCODING)
else:
return obj if isinstance(obj, bytes) else b''
else:
if isinstance(obj, str):
return obj
... | python | def to_bytes(obj):
"""Ensures that the obj is of byte-type.
"""
if PY3:
if isinstance(obj, str):
return obj.encode(settings.DEFAULT_ENCODING)
else:
return obj if isinstance(obj, bytes) else b''
else:
if isinstance(obj, str):
return obj
... | [
"def",
"to_bytes",
"(",
"obj",
")",
":",
"if",
"PY3",
":",
"if",
"isinstance",
"(",
"obj",
",",
"str",
")",
":",
"return",
"obj",
".",
"encode",
"(",
"settings",
".",
"DEFAULT_ENCODING",
")",
"else",
":",
"return",
"obj",
"if",
"isinstance",
"(",
"ob... | Ensures that the obj is of byte-type. | [
"Ensures",
"that",
"the",
"obj",
"is",
"of",
"byte",
"-",
"type",
"."
] | 680eeb7ff04ec9bb634b71cceb0841abaf2d530e | https://github.com/scidam/cachepy/blob/680eeb7ff04ec9bb634b71cceb0841abaf2d530e/crypter.py#L14-L27 | train |
scidam/cachepy | crypter.py | padding | def padding(s, bs=AES.block_size):
"""Fills a bytes-like object with arbitrary symbols to make its length divisible by `bs`.
"""
s = to_bytes(s)
if len(s) % bs == 0:
res = s + b''.join(map(to_bytes, [random.SystemRandom().choice(string.ascii_lowercase + string.digits) for _ in range(bs - 1... | python | def padding(s, bs=AES.block_size):
"""Fills a bytes-like object with arbitrary symbols to make its length divisible by `bs`.
"""
s = to_bytes(s)
if len(s) % bs == 0:
res = s + b''.join(map(to_bytes, [random.SystemRandom().choice(string.ascii_lowercase + string.digits) for _ in range(bs - 1... | [
"def",
"padding",
"(",
"s",
",",
"bs",
"=",
"AES",
".",
"block_size",
")",
":",
"s",
"=",
"to_bytes",
"(",
"s",
")",
"if",
"len",
"(",
"s",
")",
"%",
"bs",
"==",
"0",
":",
"res",
"=",
"s",
"+",
"b''",
".",
"join",
"(",
"map",
"(",
"to_bytes... | Fills a bytes-like object with arbitrary symbols to make its length divisible by `bs`. | [
"Fills",
"a",
"bytes",
"-",
"like",
"object",
"with",
"arbitrary",
"symbols",
"to",
"make",
"its",
"length",
"divisible",
"by",
"bs",
"."
] | 680eeb7ff04ec9bb634b71cceb0841abaf2d530e | https://github.com/scidam/cachepy/blob/680eeb7ff04ec9bb634b71cceb0841abaf2d530e/crypter.py#L30-L42 | train |
DavidLP/pilight | pilight/pilight.py | Client.stop | def stop(self):
"""Called to stop the reveiver thread."""
self._stop_thread.set()
# f you want to close the connection in a timely fashion,
# call shutdown() before close().
with self._lock: # Receive thread might use the socket
self.receive_socket.shutdown(socket.SH... | python | def stop(self):
"""Called to stop the reveiver thread."""
self._stop_thread.set()
# f you want to close the connection in a timely fashion,
# call shutdown() before close().
with self._lock: # Receive thread might use the socket
self.receive_socket.shutdown(socket.SH... | [
"def",
"stop",
"(",
"self",
")",
":",
"self",
".",
"_stop_thread",
".",
"set",
"(",
")",
"with",
"self",
".",
"_lock",
":",
"self",
".",
"receive_socket",
".",
"shutdown",
"(",
"socket",
".",
"SHUT_RDWR",
")",
"self",
".",
"receive_socket",
".",
"close... | Called to stop the reveiver thread. | [
"Called",
"to",
"stop",
"the",
"reveiver",
"thread",
"."
] | a319404034e761892a89c7205b6f1aff6ad8e205 | https://github.com/DavidLP/pilight/blob/a319404034e761892a89c7205b6f1aff6ad8e205/pilight/pilight.py#L111-L121 | train |
DavidLP/pilight | pilight/pilight.py | Client.send_code | def send_code(self, data, acknowledge=True):
"""Send a RF code known to the pilight-daemon.
For protocols look at https://manual.pilight.org/en/api.
When acknowledge is set, it is checked if the code was issued.
:param data: Dictionary with the data
:param acknowledge: Raise IO ... | python | def send_code(self, data, acknowledge=True):
"""Send a RF code known to the pilight-daemon.
For protocols look at https://manual.pilight.org/en/api.
When acknowledge is set, it is checked if the code was issued.
:param data: Dictionary with the data
:param acknowledge: Raise IO ... | [
"def",
"send_code",
"(",
"self",
",",
"data",
",",
"acknowledge",
"=",
"True",
")",
":",
"if",
"\"protocol\"",
"not",
"in",
"data",
":",
"raise",
"ValueError",
"(",
"'Pilight data to send does not contain a protocol info. '",
"'Check the pilight-send doku!'",
",",
"st... | Send a RF code known to the pilight-daemon.
For protocols look at https://manual.pilight.org/en/api.
When acknowledge is set, it is checked if the code was issued.
:param data: Dictionary with the data
:param acknowledge: Raise IO exception if the code is not
send by the pilight... | [
"Send",
"a",
"RF",
"code",
"known",
"to",
"the",
"pilight",
"-",
"daemon",
"."
] | a319404034e761892a89c7205b6f1aff6ad8e205 | https://github.com/DavidLP/pilight/blob/a319404034e761892a89c7205b6f1aff6ad8e205/pilight/pilight.py#L156-L190 | train |
higlass/higlass-python | higlass/server.py | FuseProcess.setup | def setup(self):
"""
Set up filesystem in user space for http and https
so that we can retrieve tiles from remote sources.
Parameters
----------
tmp_dir: string
The temporary directory where to create the
http and https directories
"""
... | python | def setup(self):
"""
Set up filesystem in user space for http and https
so that we can retrieve tiles from remote sources.
Parameters
----------
tmp_dir: string
The temporary directory where to create the
http and https directories
"""
... | [
"def",
"setup",
"(",
"self",
")",
":",
"from",
"simple_httpfs",
"import",
"HttpFs",
"if",
"not",
"op",
".",
"exists",
"(",
"self",
".",
"http_directory",
")",
":",
"os",
".",
"makedirs",
"(",
"self",
".",
"http_directory",
")",
"if",
"not",
"op",
".",
... | Set up filesystem in user space for http and https
so that we can retrieve tiles from remote sources.
Parameters
----------
tmp_dir: string
The temporary directory where to create the
http and https directories | [
"Set",
"up",
"filesystem",
"in",
"user",
"space",
"for",
"http",
"and",
"https",
"so",
"that",
"we",
"can",
"retrieve",
"tiles",
"from",
"remote",
"sources",
"."
] | 0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7 | https://github.com/higlass/higlass-python/blob/0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7/higlass/server.py#L234-L284 | train |
higlass/higlass-python | higlass/server.py | Server.start | def start(self, log_file="/tmp/hgserver.log", log_level=logging.INFO):
"""
Start a lightweight higlass server.
Parameters
----------
log_file: string
Where to place diagnostic log files
log_level: logging.*
What level to log at
"""
... | python | def start(self, log_file="/tmp/hgserver.log", log_level=logging.INFO):
"""
Start a lightweight higlass server.
Parameters
----------
log_file: string
Where to place diagnostic log files
log_level: logging.*
What level to log at
"""
... | [
"def",
"start",
"(",
"self",
",",
"log_file",
"=",
"\"/tmp/hgserver.log\"",
",",
"log_level",
"=",
"logging",
".",
"INFO",
")",
":",
"for",
"puid",
"in",
"list",
"(",
"self",
".",
"processes",
".",
"keys",
"(",
")",
")",
":",
"print",
"(",
"\"terminati... | Start a lightweight higlass server.
Parameters
----------
log_file: string
Where to place diagnostic log files
log_level: logging.*
What level to log at | [
"Start",
"a",
"lightweight",
"higlass",
"server",
"."
] | 0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7 | https://github.com/higlass/higlass-python/blob/0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7/higlass/server.py#L339-L386 | train |
higlass/higlass-python | higlass/server.py | Server.stop | def stop(self):
"""
Stop this server so that the calling process can exit
"""
# unsetup_fuse()
self.fuse_process.teardown()
for uuid in self.processes:
self.processes[uuid].terminate() | python | def stop(self):
"""
Stop this server so that the calling process can exit
"""
# unsetup_fuse()
self.fuse_process.teardown()
for uuid in self.processes:
self.processes[uuid].terminate() | [
"def",
"stop",
"(",
"self",
")",
":",
"self",
".",
"fuse_process",
".",
"teardown",
"(",
")",
"for",
"uuid",
"in",
"self",
".",
"processes",
":",
"self",
".",
"processes",
"[",
"uuid",
"]",
".",
"terminate",
"(",
")"
] | Stop this server so that the calling process can exit | [
"Stop",
"this",
"server",
"so",
"that",
"the",
"calling",
"process",
"can",
"exit"
] | 0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7 | https://github.com/higlass/higlass-python/blob/0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7/higlass/server.py#L388-L395 | train |
higlass/higlass-python | higlass/server.py | Server.tileset_info | def tileset_info(self, uid):
"""
Return the tileset info for the given tileset
"""
url = "http://{host}:{port}/api/v1/tileset_info/?d={uid}".format(
host=self.host, port=self.port, uid=uid
)
req = requests.get(url)
if req.status_code != 200:
... | python | def tileset_info(self, uid):
"""
Return the tileset info for the given tileset
"""
url = "http://{host}:{port}/api/v1/tileset_info/?d={uid}".format(
host=self.host, port=self.port, uid=uid
)
req = requests.get(url)
if req.status_code != 200:
... | [
"def",
"tileset_info",
"(",
"self",
",",
"uid",
")",
":",
"url",
"=",
"\"http://{host}:{port}/api/v1/tileset_info/?d={uid}\"",
".",
"format",
"(",
"host",
"=",
"self",
".",
"host",
",",
"port",
"=",
"self",
".",
"port",
",",
"uid",
"=",
"uid",
")",
"req",
... | Return the tileset info for the given tileset | [
"Return",
"the",
"tileset",
"info",
"for",
"the",
"given",
"tileset"
] | 0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7 | https://github.com/higlass/higlass-python/blob/0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7/higlass/server.py#L397-L410 | train |
higlass/higlass-python | higlass/server.py | Server.chromsizes | def chromsizes(self, uid):
"""
Return the chromosome sizes from the given filename
"""
url = "http://{host}:{port}/api/v1/chrom-sizes/?id={uid}".format(
host=self.host, port=self.port, uid=uid
)
req = requests.get(url)
if req.status_code != 200:
... | python | def chromsizes(self, uid):
"""
Return the chromosome sizes from the given filename
"""
url = "http://{host}:{port}/api/v1/chrom-sizes/?id={uid}".format(
host=self.host, port=self.port, uid=uid
)
req = requests.get(url)
if req.status_code != 200:
... | [
"def",
"chromsizes",
"(",
"self",
",",
"uid",
")",
":",
"url",
"=",
"\"http://{host}:{port}/api/v1/chrom-sizes/?id={uid}\"",
".",
"format",
"(",
"host",
"=",
"self",
".",
"host",
",",
"port",
"=",
"self",
".",
"port",
",",
"uid",
"=",
"uid",
")",
"req",
... | Return the chromosome sizes from the given filename | [
"Return",
"the",
"chromosome",
"sizes",
"from",
"the",
"given",
"filename"
] | 0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7 | https://github.com/higlass/higlass-python/blob/0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7/higlass/server.py#L433-L445 | train |
higlass/higlass-python | higlass/viewer.py | display | def display(views, location_sync=[], zoom_sync=[], host='localhost', server_port=None):
'''
Instantiate a HiGlass display with the given views
'''
from .server import Server
from .client import ViewConf
tilesets = []
for view in views:
for track in view.tracks:
if track.... | python | def display(views, location_sync=[], zoom_sync=[], host='localhost', server_port=None):
'''
Instantiate a HiGlass display with the given views
'''
from .server import Server
from .client import ViewConf
tilesets = []
for view in views:
for track in view.tracks:
if track.... | [
"def",
"display",
"(",
"views",
",",
"location_sync",
"=",
"[",
"]",
",",
"zoom_sync",
"=",
"[",
"]",
",",
"host",
"=",
"'localhost'",
",",
"server_port",
"=",
"None",
")",
":",
"from",
".",
"server",
"import",
"Server",
"from",
".",
"client",
"import"... | Instantiate a HiGlass display with the given views | [
"Instantiate",
"a",
"HiGlass",
"display",
"with",
"the",
"given",
"views"
] | 0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7 | https://github.com/higlass/higlass-python/blob/0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7/higlass/viewer.py#L4-L42 | train |
higlass/higlass-python | higlass/viewer.py | view | def view(tilesets):
'''
Create a higlass viewer that displays the specified tilesets
Parameters:
-----------
Returns
-------
Nothing
'''
from .server import Server
from .client import View
curr_view = View()
server = Server()
server.start(tilesets)
for ts ... | python | def view(tilesets):
'''
Create a higlass viewer that displays the specified tilesets
Parameters:
-----------
Returns
-------
Nothing
'''
from .server import Server
from .client import View
curr_view = View()
server = Server()
server.start(tilesets)
for ts ... | [
"def",
"view",
"(",
"tilesets",
")",
":",
"from",
".",
"server",
"import",
"Server",
"from",
".",
"client",
"import",
"View",
"curr_view",
"=",
"View",
"(",
")",
"server",
"=",
"Server",
"(",
")",
"server",
".",
"start",
"(",
"tilesets",
")",
"for",
... | Create a higlass viewer that displays the specified tilesets
Parameters:
-----------
Returns
-------
Nothing | [
"Create",
"a",
"higlass",
"viewer",
"that",
"displays",
"the",
"specified",
"tilesets"
] | 0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7 | https://github.com/higlass/higlass-python/blob/0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7/higlass/viewer.py#L45-L73 | train |
higlass/higlass-python | higlass/client.py | Track.change_attributes | def change_attributes(self, **kwargs):
'''
Change an attribute of this track and return a new copy.
'''
new_track = Track(self.viewconf['type'])
new_track.position = self.position
new_track.tileset = self.tileset
new_track.viewconf = json.loads(json.dumps(self.vie... | python | def change_attributes(self, **kwargs):
'''
Change an attribute of this track and return a new copy.
'''
new_track = Track(self.viewconf['type'])
new_track.position = self.position
new_track.tileset = self.tileset
new_track.viewconf = json.loads(json.dumps(self.vie... | [
"def",
"change_attributes",
"(",
"self",
",",
"**",
"kwargs",
")",
":",
"new_track",
"=",
"Track",
"(",
"self",
".",
"viewconf",
"[",
"'type'",
"]",
")",
"new_track",
".",
"position",
"=",
"self",
".",
"position",
"new_track",
".",
"tileset",
"=",
"self"... | Change an attribute of this track and return a new copy. | [
"Change",
"an",
"attribute",
"of",
"this",
"track",
"and",
"return",
"a",
"new",
"copy",
"."
] | 0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7 | https://github.com/higlass/higlass-python/blob/0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7/higlass/client.py#L126-L136 | train |
higlass/higlass-python | higlass/client.py | Track.change_options | def change_options(self, **kwargs):
'''
Change one of the track's options in the viewconf
'''
new_options = json.loads(json.dumps(self.viewconf['options']))
new_options = {**new_options, **kwargs}
return self.change_attributes(options=new_options) | python | def change_options(self, **kwargs):
'''
Change one of the track's options in the viewconf
'''
new_options = json.loads(json.dumps(self.viewconf['options']))
new_options = {**new_options, **kwargs}
return self.change_attributes(options=new_options) | [
"def",
"change_options",
"(",
"self",
",",
"**",
"kwargs",
")",
":",
"new_options",
"=",
"json",
".",
"loads",
"(",
"json",
".",
"dumps",
"(",
"self",
".",
"viewconf",
"[",
"'options'",
"]",
")",
")",
"new_options",
"=",
"{",
"**",
"new_options",
",",
... | Change one of the track's options in the viewconf | [
"Change",
"one",
"of",
"the",
"track",
"s",
"options",
"in",
"the",
"viewconf"
] | 0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7 | https://github.com/higlass/higlass-python/blob/0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7/higlass/client.py#L138-L145 | train |
higlass/higlass-python | higlass/client.py | View.add_track | def add_track(self, *args, **kwargs):
"""
Add a track to a position.
Parameters
----------
track_type: string
The type of track to add (e.g. "heatmap", "line")
position: string
One of 'top', 'bottom', 'center', 'left', 'right'
tileset: hgf... | python | def add_track(self, *args, **kwargs):
"""
Add a track to a position.
Parameters
----------
track_type: string
The type of track to add (e.g. "heatmap", "line")
position: string
One of 'top', 'bottom', 'center', 'left', 'right'
tileset: hgf... | [
"def",
"add_track",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"new_track",
"=",
"Track",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
"self",
".",
"tracks",
"=",
"self",
".",
"tracks",
"+",
"[",
"new_track",
"]"
] | Add a track to a position.
Parameters
----------
track_type: string
The type of track to add (e.g. "heatmap", "line")
position: string
One of 'top', 'bottom', 'center', 'left', 'right'
tileset: hgflask.tilesets.Tileset
The tileset to be plotte... | [
"Add",
"a",
"track",
"to",
"a",
"position",
"."
] | 0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7 | https://github.com/higlass/higlass-python/blob/0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7/higlass/client.py#L203-L223 | train |
higlass/higlass-python | higlass/client.py | View.to_dict | def to_dict(self):
"""
Convert the existing track to a JSON representation.
"""
viewconf = json.loads(json.dumps(self.viewconf))
for track in self.tracks:
if track.position is None:
raise ValueError(
"Track has no position: {}".for... | python | def to_dict(self):
"""
Convert the existing track to a JSON representation.
"""
viewconf = json.loads(json.dumps(self.viewconf))
for track in self.tracks:
if track.position is None:
raise ValueError(
"Track has no position: {}".for... | [
"def",
"to_dict",
"(",
"self",
")",
":",
"viewconf",
"=",
"json",
".",
"loads",
"(",
"json",
".",
"dumps",
"(",
"self",
".",
"viewconf",
")",
")",
"for",
"track",
"in",
"self",
".",
"tracks",
":",
"if",
"track",
".",
"position",
"is",
"None",
":",
... | Convert the existing track to a JSON representation. | [
"Convert",
"the",
"existing",
"track",
"to",
"a",
"JSON",
"representation",
"."
] | 0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7 | https://github.com/higlass/higlass-python/blob/0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7/higlass/client.py#L225-L238 | train |
higlass/higlass-python | higlass/client.py | ViewConf.add_view | def add_view(self, *args, **kwargs):
"""
Add a new view
Parameters
----------
uid: string
The uid of new view
width: int
The width of this of view on a 12 unit grid
height: int
The height of the this view. The height is proport... | python | def add_view(self, *args, **kwargs):
"""
Add a new view
Parameters
----------
uid: string
The uid of new view
width: int
The width of this of view on a 12 unit grid
height: int
The height of the this view. The height is proport... | [
"def",
"add_view",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"new_view",
"=",
"View",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
"for",
"view",
"in",
"self",
".",
"views",
":",
"if",
"view",
".",
"uid",
"==",
"new_view",
".",... | Add a new view
Parameters
----------
uid: string
The uid of new view
width: int
The width of this of view on a 12 unit grid
height: int
The height of the this view. The height is proportional
to the height of all the views present.... | [
"Add",
"a",
"new",
"view"
] | 0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7 | https://github.com/higlass/higlass-python/blob/0a5bf2759cc0020844aefbf0df4f9e8f9137a0b7/higlass/client.py#L279-L308 | train |
classam/silly | silly/main.py | _slugify | def _slugify(string):
"""
This is not as good as a proper slugification function, but the input space is limited
>>> _slugify("beets")
'beets'
>>> _slugify("Toaster Strudel")
'toaster-strudel'
Here's why: It handles very little. It doesn't handle esoteric whitespace or symbols:
>>> _... | python | def _slugify(string):
"""
This is not as good as a proper slugification function, but the input space is limited
>>> _slugify("beets")
'beets'
>>> _slugify("Toaster Strudel")
'toaster-strudel'
Here's why: It handles very little. It doesn't handle esoteric whitespace or symbols:
>>> _... | [
"def",
"_slugify",
"(",
"string",
")",
":",
"words",
"=",
"re",
".",
"split",
"(",
"r'[\\W]'",
",",
"string",
")",
"clean_words",
"=",
"[",
"w",
"for",
"w",
"in",
"words",
"if",
"w",
"!=",
"''",
"]",
"return",
"'-'",
".",
"join",
"(",
"clean_words"... | This is not as good as a proper slugification function, but the input space is limited
>>> _slugify("beets")
'beets'
>>> _slugify("Toaster Strudel")
'toaster-strudel'
Here's why: It handles very little. It doesn't handle esoteric whitespace or symbols:
>>> _slugify("Hat\\nBasket- of justice ... | [
"This",
"is",
"not",
"as",
"good",
"as",
"a",
"proper",
"slugification",
"function",
"but",
"the",
"input",
"space",
"is",
"limited"
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L16-L34 | train |
classam/silly | silly/main.py | slugify_argument | def slugify_argument(func):
"""
Wraps a function that returns a string, adding the 'slugify' argument.
>>> slugified_fn = slugify_argument(lambda *args, **kwargs: "YOU ARE A NICE LADY")
>>> slugified_fn()
'YOU ARE A NICE LADY'
>>> slugified_fn(slugify=True)
'you-are-a-nice-lady'
"""
... | python | def slugify_argument(func):
"""
Wraps a function that returns a string, adding the 'slugify' argument.
>>> slugified_fn = slugify_argument(lambda *args, **kwargs: "YOU ARE A NICE LADY")
>>> slugified_fn()
'YOU ARE A NICE LADY'
>>> slugified_fn(slugify=True)
'you-are-a-nice-lady'
"""
... | [
"def",
"slugify_argument",
"(",
"func",
")",
":",
"@",
"six",
".",
"wraps",
"(",
"func",
")",
"def",
"wrapped",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"if",
"\"slugify\"",
"in",
"kwargs",
"and",
"kwargs",
"[",
"'slugify'",
"]",
":",
"return... | Wraps a function that returns a string, adding the 'slugify' argument.
>>> slugified_fn = slugify_argument(lambda *args, **kwargs: "YOU ARE A NICE LADY")
>>> slugified_fn()
'YOU ARE A NICE LADY'
>>> slugified_fn(slugify=True)
'you-are-a-nice-lady' | [
"Wraps",
"a",
"function",
"that",
"returns",
"a",
"string",
"adding",
"the",
"slugify",
"argument",
"."
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L651-L668 | train |
classam/silly | silly/main.py | capitalize_argument | def capitalize_argument(func):
"""
Wraps a function that returns a string, adding the 'capitalize' argument.
>>> capsified_fn = capitalize_argument(lambda *args, **kwargs: "what in the beeswax is this?")
>>> capsified_fn()
'what in the beeswax is this?'
>>> capsified_fn(capitalize=True)
'Wh... | python | def capitalize_argument(func):
"""
Wraps a function that returns a string, adding the 'capitalize' argument.
>>> capsified_fn = capitalize_argument(lambda *args, **kwargs: "what in the beeswax is this?")
>>> capsified_fn()
'what in the beeswax is this?'
>>> capsified_fn(capitalize=True)
'Wh... | [
"def",
"capitalize_argument",
"(",
"func",
")",
":",
"@",
"six",
".",
"wraps",
"(",
"func",
")",
"def",
"wrapped",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"if",
"\"capitalize\"",
"in",
"kwargs",
"and",
"kwargs",
"[",
"'capitalize'",
"]",
":",
... | Wraps a function that returns a string, adding the 'capitalize' argument.
>>> capsified_fn = capitalize_argument(lambda *args, **kwargs: "what in the beeswax is this?")
>>> capsified_fn()
'what in the beeswax is this?'
>>> capsified_fn(capitalize=True)
'What In The Beeswax Is This?' | [
"Wraps",
"a",
"function",
"that",
"returns",
"a",
"string",
"adding",
"the",
"capitalize",
"argument",
"."
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L671-L688 | train |
classam/silly | silly/main.py | datetime | def datetime(past=True, random=random):
"""
Returns a random datetime from the past... or the future!
>>> mock_random.seed(0)
>>> datetime(random=mock_random).isoformat()
'1950-02-03T03:04:05'
"""
def year():
if past:
return random.choice(range(1950,2005))
else... | python | def datetime(past=True, random=random):
"""
Returns a random datetime from the past... or the future!
>>> mock_random.seed(0)
>>> datetime(random=mock_random).isoformat()
'1950-02-03T03:04:05'
"""
def year():
if past:
return random.choice(range(1950,2005))
else... | [
"def",
"datetime",
"(",
"past",
"=",
"True",
",",
"random",
"=",
"random",
")",
":",
"def",
"year",
"(",
")",
":",
"if",
"past",
":",
"return",
"random",
".",
"choice",
"(",
"range",
"(",
"1950",
",",
"2005",
")",
")",
"else",
":",
"return",
"_da... | Returns a random datetime from the past... or the future!
>>> mock_random.seed(0)
>>> datetime(random=mock_random).isoformat()
'1950-02-03T03:04:05' | [
"Returns",
"a",
"random",
"datetime",
"from",
"the",
"past",
"...",
"or",
"the",
"future!"
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L691-L730 | train |
classam/silly | silly/main.py | a_noun | def a_noun(random=random, *args, **kwargs):
"""
Return a noun, but with an 'a' in front of it. Or an 'an', depending!
>>> mock_random.seed(0)
>>> a_noun(random=mock_random)
'an onion'
>>> a_noun(random=mock_random, capitalize=True)
'A Chimp'
>>> a_noun(random=mock_random, slugify=True)
... | python | def a_noun(random=random, *args, **kwargs):
"""
Return a noun, but with an 'a' in front of it. Or an 'an', depending!
>>> mock_random.seed(0)
>>> a_noun(random=mock_random)
'an onion'
>>> a_noun(random=mock_random, capitalize=True)
'A Chimp'
>>> a_noun(random=mock_random, slugify=True)
... | [
"def",
"a_noun",
"(",
"random",
"=",
"random",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"return",
"inflectify",
".",
"a",
"(",
"noun",
"(",
"random",
"=",
"random",
")",
")"
] | Return a noun, but with an 'a' in front of it. Or an 'an', depending!
>>> mock_random.seed(0)
>>> a_noun(random=mock_random)
'an onion'
>>> a_noun(random=mock_random, capitalize=True)
'A Chimp'
>>> a_noun(random=mock_random, slugify=True)
'a-blister' | [
"Return",
"a",
"noun",
"but",
"with",
"an",
"a",
"in",
"front",
"of",
"it",
".",
"Or",
"an",
"an",
"depending!"
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L813-L825 | train |
classam/silly | silly/main.py | plural | def plural(random=random, *args, **kwargs):
"""
Return a plural noun.
>>> mock_random.seed(0)
>>> plural(random=mock_random)
'onions'
>>> plural(random=mock_random, capitalize=True)
'Chimps'
>>> plural(random=mock_random, slugify=True)
'blisters'
"""
return inflectify.plural... | python | def plural(random=random, *args, **kwargs):
"""
Return a plural noun.
>>> mock_random.seed(0)
>>> plural(random=mock_random)
'onions'
>>> plural(random=mock_random, capitalize=True)
'Chimps'
>>> plural(random=mock_random, slugify=True)
'blisters'
"""
return inflectify.plural... | [
"def",
"plural",
"(",
"random",
"=",
"random",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"return",
"inflectify",
".",
"plural",
"(",
"random",
".",
"choice",
"(",
"nouns",
")",
")"
] | Return a plural noun.
>>> mock_random.seed(0)
>>> plural(random=mock_random)
'onions'
>>> plural(random=mock_random, capitalize=True)
'Chimps'
>>> plural(random=mock_random, slugify=True)
'blisters' | [
"Return",
"a",
"plural",
"noun",
"."
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L830-L842 | train |
classam/silly | silly/main.py | lastname | def lastname(random=random, *args, **kwargs):
"""
Return a first name!
>>> mock_random.seed(0)
>>> lastname(random=mock_random)
'chimp'
>>> mock_random.seed(1)
>>> lastname(random=mock_random, capitalize=True)
'Wonderful'
>>> mock_random.seed(2)
>>> lastname(random=mock_random, ... | python | def lastname(random=random, *args, **kwargs):
"""
Return a first name!
>>> mock_random.seed(0)
>>> lastname(random=mock_random)
'chimp'
>>> mock_random.seed(1)
>>> lastname(random=mock_random, capitalize=True)
'Wonderful'
>>> mock_random.seed(2)
>>> lastname(random=mock_random, ... | [
"def",
"lastname",
"(",
"random",
"=",
"random",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"types",
"=",
"[",
"\"{noun}\"",
",",
"\"{adjective}\"",
",",
"\"{noun}{second_noun}\"",
",",
"\"{adjective}{noun}\"",
",",
"\"{adjective}{plural}\"",
",",
"\"{noun... | Return a first name!
>>> mock_random.seed(0)
>>> lastname(random=mock_random)
'chimp'
>>> mock_random.seed(1)
>>> lastname(random=mock_random, capitalize=True)
'Wonderful'
>>> mock_random.seed(2)
>>> lastname(random=mock_random, slugify=True)
'poopbritches'
>>> [lastname(random... | [
"Return",
"a",
"first",
"name!"
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L881-L925 | train |
classam/silly | silly/main.py | numberwang | def numberwang(random=random, *args, **kwargs):
"""
Return a number that is spelled out.
>>> numberwang(random=mock_random)
'two'
>>> numberwang(random=mock_random, capitalize=True)
'Two'
>>> numberwang(random=mock_random, slugify=True)
'two'
"""
n = random.randint(2, 150)
... | python | def numberwang(random=random, *args, **kwargs):
"""
Return a number that is spelled out.
>>> numberwang(random=mock_random)
'two'
>>> numberwang(random=mock_random, capitalize=True)
'Two'
>>> numberwang(random=mock_random, slugify=True)
'two'
"""
n = random.randint(2, 150)
... | [
"def",
"numberwang",
"(",
"random",
"=",
"random",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"n",
"=",
"random",
".",
"randint",
"(",
"2",
",",
"150",
")",
"return",
"inflectify",
".",
"number_to_words",
"(",
"n",
")"
] | Return a number that is spelled out.
>>> numberwang(random=mock_random)
'two'
>>> numberwang(random=mock_random, capitalize=True)
'Two'
>>> numberwang(random=mock_random, slugify=True)
'two' | [
"Return",
"a",
"number",
"that",
"is",
"spelled",
"out",
"."
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L947-L960 | train |
classam/silly | silly/main.py | things | def things(random=random, *args, **kwargs):
"""
Return a set of things.
>>> mock_random.seed(0)
>>> things(random=mock_random)
'two secrets, two secrets, and two secrets'
>>> mock_random.seed(1)
>>> things(random=mock_random, capitalize=True)
'A Mighty Poop, A Mighty Poop, And A Mighty ... | python | def things(random=random, *args, **kwargs):
"""
Return a set of things.
>>> mock_random.seed(0)
>>> things(random=mock_random)
'two secrets, two secrets, and two secrets'
>>> mock_random.seed(1)
>>> things(random=mock_random, capitalize=True)
'A Mighty Poop, A Mighty Poop, And A Mighty ... | [
"def",
"things",
"(",
"random",
"=",
"random",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"return",
"inflectify",
".",
"join",
"(",
"[",
"a_thing",
"(",
"random",
"=",
"random",
")",
",",
"a_thing",
"(",
"random",
"=",
"random",
")",
",",
"a_... | Return a set of things.
>>> mock_random.seed(0)
>>> things(random=mock_random)
'two secrets, two secrets, and two secrets'
>>> mock_random.seed(1)
>>> things(random=mock_random, capitalize=True)
'A Mighty Poop, A Mighty Poop, And A Mighty Poop' | [
"Return",
"a",
"set",
"of",
"things",
"."
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L1092-L1104 | train |
classam/silly | silly/main.py | name | def name(random=random, *args, **kwargs):
"""
Return someone's name
>>> mock_random.seed(0)
>>> name(random=mock_random)
'carl poopbritches'
>>> mock_random.seed(7)
>>> name(random=mock_random, capitalize=True)
'Duke Testy Wonderful'
"""
if random.choice([True, True, True, Fals... | python | def name(random=random, *args, **kwargs):
"""
Return someone's name
>>> mock_random.seed(0)
>>> name(random=mock_random)
'carl poopbritches'
>>> mock_random.seed(7)
>>> name(random=mock_random, capitalize=True)
'Duke Testy Wonderful'
"""
if random.choice([True, True, True, Fals... | [
"def",
"name",
"(",
"random",
"=",
"random",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"if",
"random",
".",
"choice",
"(",
"[",
"True",
",",
"True",
",",
"True",
",",
"False",
"]",
")",
":",
"return",
"firstname",
"(",
"random",
"=",
"rand... | Return someone's name
>>> mock_random.seed(0)
>>> name(random=mock_random)
'carl poopbritches'
>>> mock_random.seed(7)
>>> name(random=mock_random, capitalize=True)
'Duke Testy Wonderful' | [
"Return",
"someone",
"s",
"name"
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L1109-L1126 | train |
classam/silly | silly/main.py | domain | def domain(random=random, *args, **kwargs):
"""
Return a domain
>>> mock_random.seed(0)
>>> domain(random=mock_random)
'onion.net'
>>> domain(random=mock_random)
'bag-of-heroic-chimps.sexy'
"""
words = random.choice([
noun(random=random),
thing(random=random),
... | python | def domain(random=random, *args, **kwargs):
"""
Return a domain
>>> mock_random.seed(0)
>>> domain(random=mock_random)
'onion.net'
>>> domain(random=mock_random)
'bag-of-heroic-chimps.sexy'
"""
words = random.choice([
noun(random=random),
thing(random=random),
... | [
"def",
"domain",
"(",
"random",
"=",
"random",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"words",
"=",
"random",
".",
"choice",
"(",
"[",
"noun",
"(",
"random",
"=",
"random",
")",
",",
"thing",
"(",
"random",
"=",
"random",
")",
",",
"adj... | Return a domain
>>> mock_random.seed(0)
>>> domain(random=mock_random)
'onion.net'
>>> domain(random=mock_random)
'bag-of-heroic-chimps.sexy' | [
"Return",
"a",
"domain"
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L1131-L1147 | train |
classam/silly | silly/main.py | email | def email(random=random, *args, **kwargs):
"""
Return an e-mail address
>>> mock_random.seed(0)
>>> email(random=mock_random)
'onion@bag-of-heroic-chimps.sexy'
>>> email(random=mock_random)
'agatha-incrediblebritches-spam@amazingbritches.click'
>>> email(random=mock_random, name="charle... | python | def email(random=random, *args, **kwargs):
"""
Return an e-mail address
>>> mock_random.seed(0)
>>> email(random=mock_random)
'onion@bag-of-heroic-chimps.sexy'
>>> email(random=mock_random)
'agatha-incrediblebritches-spam@amazingbritches.click'
>>> email(random=mock_random, name="charle... | [
"def",
"email",
"(",
"random",
"=",
"random",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"if",
"'name'",
"in",
"kwargs",
"and",
"kwargs",
"[",
"'name'",
"]",
":",
"words",
"=",
"kwargs",
"[",
"'name'",
"]",
"else",
":",
"words",
"=",
"random"... | Return an e-mail address
>>> mock_random.seed(0)
>>> email(random=mock_random)
'onion@bag-of-heroic-chimps.sexy'
>>> email(random=mock_random)
'agatha-incrediblebritches-spam@amazingbritches.click'
>>> email(random=mock_random, name="charles")
'charles@secret.xyz' | [
"Return",
"an",
"e",
"-",
"mail",
"address"
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L1150-L1171 | train |
classam/silly | silly/main.py | phone_number | def phone_number(random=random, *args, **kwargs):
"""
Return a phone number
>>> mock_random.seed(0)
>>> phone_number(random=mock_random)
'555-0000'
>>> phone_number(random=mock_random)
'1-604-555-0000'
>>> phone_number(random=mock_random)
'864-70-555-0000'
"""
return random... | python | def phone_number(random=random, *args, **kwargs):
"""
Return a phone number
>>> mock_random.seed(0)
>>> phone_number(random=mock_random)
'555-0000'
>>> phone_number(random=mock_random)
'1-604-555-0000'
>>> phone_number(random=mock_random)
'864-70-555-0000'
"""
return random... | [
"def",
"phone_number",
"(",
"random",
"=",
"random",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"return",
"random",
".",
"choice",
"(",
"[",
"'555-{number}{other_number}{number}{other_number}'",
",",
"'1-604-555-{number}{other_number}{number}{other_number}'",
",",... | Return a phone number
>>> mock_random.seed(0)
>>> phone_number(random=mock_random)
'555-0000'
>>> phone_number(random=mock_random)
'1-604-555-0000'
>>> phone_number(random=mock_random)
'864-70-555-0000' | [
"Return",
"a",
"phone",
"number"
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L1174-L1193 | train |
classam/silly | silly/main.py | sentence | def sentence(random=random, *args, **kwargs):
"""
Return a whole sentence
>>> mock_random.seed(0)
>>> sentence(random=mock_random)
"Agatha Incrediblebritches can't wait to smell two chimps in Boatbencheston."
>>> mock_random.seed(2)
>>> sentence(random=mock_random, slugify=True)
'blist... | python | def sentence(random=random, *args, **kwargs):
"""
Return a whole sentence
>>> mock_random.seed(0)
>>> sentence(random=mock_random)
"Agatha Incrediblebritches can't wait to smell two chimps in Boatbencheston."
>>> mock_random.seed(2)
>>> sentence(random=mock_random, slugify=True)
'blist... | [
"def",
"sentence",
"(",
"random",
"=",
"random",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"if",
"'name'",
"in",
"kwargs",
"and",
"kwargs",
"[",
"'name'",
"]",
":",
"nm",
"=",
"kwargs",
"(",
"name",
")",
"elif",
"random",
".",
"choice",
"(",... | Return a whole sentence
>>> mock_random.seed(0)
>>> sentence(random=mock_random)
"Agatha Incrediblebritches can't wait to smell two chimps in Boatbencheston."
>>> mock_random.seed(2)
>>> sentence(random=mock_random, slugify=True)
'blistersecret-studios-is-the-best-company-in-liveronion' | [
"Return",
"a",
"whole",
"sentence"
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L1198-L1263 | train |
classam/silly | silly/main.py | paragraph | def paragraph(random=random, length=10, *args, **kwargs):
"""
Produces a paragraph of text.
>>> mock_random.seed(0)
>>> paragraph(random=mock_random, length=2)
"Agatha Incrediblebritches can't wait to smell two chimps in Boatbencheston. Wonderfulsecretsound is in Gallifrey."
>>> mock_random.se... | python | def paragraph(random=random, length=10, *args, **kwargs):
"""
Produces a paragraph of text.
>>> mock_random.seed(0)
>>> paragraph(random=mock_random, length=2)
"Agatha Incrediblebritches can't wait to smell two chimps in Boatbencheston. Wonderfulsecretsound is in Gallifrey."
>>> mock_random.se... | [
"def",
"paragraph",
"(",
"random",
"=",
"random",
",",
"length",
"=",
"10",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"return",
"\" \"",
".",
"join",
"(",
"[",
"sentence",
"(",
"random",
"=",
"random",
")",
"for",
"x",
"in",
"range",
"(",
... | Produces a paragraph of text.
>>> mock_random.seed(0)
>>> paragraph(random=mock_random, length=2)
"Agatha Incrediblebritches can't wait to smell two chimps in Boatbencheston. Wonderfulsecretsound is in Gallifrey."
>>> mock_random.seed(2)
>>> paragraph(random=mock_random, length=2, slugify=True)
... | [
"Produces",
"a",
"paragraph",
"of",
"text",
"."
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L1268-L1281 | train |
classam/silly | silly/main.py | markdown | def markdown(random=random, length=10, *args, **kwargs):
"""
Produces a bunch of markdown text.
>>> mock_random.seed(0)
>>> markdown(random=mock_random, length=2)
'Nobody will **head** _to_ Mystery Studies Department **to** _buy_ a mighty poop.\\nNobody will **head** _to_ Mystery Studies Department... | python | def markdown(random=random, length=10, *args, **kwargs):
"""
Produces a bunch of markdown text.
>>> mock_random.seed(0)
>>> markdown(random=mock_random, length=2)
'Nobody will **head** _to_ Mystery Studies Department **to** _buy_ a mighty poop.\\nNobody will **head** _to_ Mystery Studies Department... | [
"def",
"markdown",
"(",
"random",
"=",
"random",
",",
"length",
"=",
"10",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"def",
"title_sentence",
"(",
")",
":",
"return",
"\"\\n\"",
"+",
"\"#\"",
"*",
"random",
".",
"randint",
"(",
"1",
",",
"5"... | Produces a bunch of markdown text.
>>> mock_random.seed(0)
>>> markdown(random=mock_random, length=2)
'Nobody will **head** _to_ Mystery Studies Department **to** _buy_ a mighty poop.\\nNobody will **head** _to_ Mystery Studies Department **to** _buy_ a mighty poop.' | [
"Produces",
"a",
"bunch",
"of",
"markdown",
"text",
"."
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L1284-L1311 | train |
classam/silly | silly/main.py | company | def company(random=random, *args, **kwargs):
"""
Produce a company name
>>> mock_random.seed(0)
>>> company(random=mock_random)
'faculty of applied chimp'
>>> mock_random.seed(1)
>>> company(random=mock_random)
'blistersecret studios'
>>> mock_random.seed(2)
>>> company(random=m... | python | def company(random=random, *args, **kwargs):
"""
Produce a company name
>>> mock_random.seed(0)
>>> company(random=mock_random)
'faculty of applied chimp'
>>> mock_random.seed(1)
>>> company(random=mock_random)
'blistersecret studios'
>>> mock_random.seed(2)
>>> company(random=m... | [
"def",
"company",
"(",
"random",
"=",
"random",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"return",
"random",
".",
"choice",
"(",
"[",
"\"faculty of applied {noun}\"",
",",
"\"{noun}{second_noun} studios\"",
",",
"\"{noun}{noun}{noun} studios\"",
",",
"\"{n... | Produce a company name
>>> mock_random.seed(0)
>>> company(random=mock_random)
'faculty of applied chimp'
>>> mock_random.seed(1)
>>> company(random=mock_random)
'blistersecret studios'
>>> mock_random.seed(2)
>>> company(random=mock_random)
'pooppooppoop studios'
>>> mock_rando... | [
"Produce",
"a",
"company",
"name"
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L1332-L1388 | train |
classam/silly | silly/main.py | country | def country(random=random, *args, **kwargs):
"""
Produce a country name
>>> mock_random.seed(0)
>>> country(random=mock_random)
'testasia'
>>> country(random=mock_random, capitalize=True)
'West Xanth'
>>> country(random=mock_random, slugify=True)
'westeros'
"""
return rando... | python | def country(random=random, *args, **kwargs):
"""
Produce a country name
>>> mock_random.seed(0)
>>> country(random=mock_random)
'testasia'
>>> country(random=mock_random, capitalize=True)
'West Xanth'
>>> country(random=mock_random, slugify=True)
'westeros'
"""
return rando... | [
"def",
"country",
"(",
"random",
"=",
"random",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"return",
"random",
".",
"choice",
"(",
"[",
"\"{country}\"",
",",
"\"{direction} {country}\"",
"]",
")",
".",
"format",
"(",
"country",
"=",
"random",
".",
... | Produce a country name
>>> mock_random.seed(0)
>>> country(random=mock_random)
'testasia'
>>> country(random=mock_random, capitalize=True)
'West Xanth'
>>> country(random=mock_random, slugify=True)
'westeros' | [
"Produce",
"a",
"country",
"name"
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L1393-L1410 | train |
classam/silly | silly/main.py | city | def city(random=random, *args, **kwargs):
"""
Produce a city name
>>> mock_random.seed(0)
>>> city(random=mock_random)
'east mysteryhall'
>>> city(random=mock_random, capitalize=True)
'Birmingchimp'
>>> city(random=mock_random, slugify=True)
'wonderfulsecretsound'
"""
retur... | python | def city(random=random, *args, **kwargs):
"""
Produce a city name
>>> mock_random.seed(0)
>>> city(random=mock_random)
'east mysteryhall'
>>> city(random=mock_random, capitalize=True)
'Birmingchimp'
>>> city(random=mock_random, slugify=True)
'wonderfulsecretsound'
"""
retur... | [
"def",
"city",
"(",
"random",
"=",
"random",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"return",
"random",
".",
"choice",
"(",
"[",
"\"{direction} {noun}{city_suffix}\"",
",",
"\"{noun}{city_suffix}\"",
",",
"\"{adjective}{noun}{city_suffix}\"",
",",
"\"{pl... | Produce a city name
>>> mock_random.seed(0)
>>> city(random=mock_random)
'east mysteryhall'
>>> city(random=mock_random, capitalize=True)
'Birmingchimp'
>>> city(random=mock_random, slugify=True)
'wonderfulsecretsound' | [
"Produce",
"a",
"city",
"name"
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L1415-L1441 | train |
classam/silly | silly/main.py | postal_code | def postal_code(random=random, *args, **kwargs):
"""
Produce something that vaguely resembles a postal code
>>> mock_random.seed(0)
>>> postal_code(random=mock_random)
'b0b 0c0'
>>> postal_code(random=mock_random, capitalize=True)
'E0E 0F0'
>>> postal_code(random=mock_random, slugify=Tr... | python | def postal_code(random=random, *args, **kwargs):
"""
Produce something that vaguely resembles a postal code
>>> mock_random.seed(0)
>>> postal_code(random=mock_random)
'b0b 0c0'
>>> postal_code(random=mock_random, capitalize=True)
'E0E 0F0'
>>> postal_code(random=mock_random, slugify=Tr... | [
"def",
"postal_code",
"(",
"random",
"=",
"random",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"return",
"random",
".",
"choice",
"(",
"[",
"\"{letter}{number}{letter} {other_number}{other_letter}{other_number}\"",
",",
"\"{number}{other_number}{number}{number}{othe... | Produce something that vaguely resembles a postal code
>>> mock_random.seed(0)
>>> postal_code(random=mock_random)
'b0b 0c0'
>>> postal_code(random=mock_random, capitalize=True)
'E0E 0F0'
>>> postal_code(random=mock_random, slugify=True)
'h0h-0i0' | [
"Produce",
"something",
"that",
"vaguely",
"resembles",
"a",
"postal",
"code"
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L1446-L1468 | train |
classam/silly | silly/main.py | street | def street(random=random, *args, **kwargs):
"""
Produce something that sounds like a street name
>>> mock_random.seed(0)
>>> street(random=mock_random)
'chimp place'
>>> street(random=mock_random, capitalize=True)
'Boatbench Block'
>>> mock_random.seed(3)
>>> street(random=mock_rand... | python | def street(random=random, *args, **kwargs):
"""
Produce something that sounds like a street name
>>> mock_random.seed(0)
>>> street(random=mock_random)
'chimp place'
>>> street(random=mock_random, capitalize=True)
'Boatbench Block'
>>> mock_random.seed(3)
>>> street(random=mock_rand... | [
"def",
"street",
"(",
"random",
"=",
"random",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"return",
"random",
".",
"choice",
"(",
"[",
"\"{noun} {street_type}\"",
",",
"\"{adjective}{verb} {street_type}\"",
",",
"\"{direction} {adjective}{verb} {street_type}\"",... | Produce something that sounds like a street name
>>> mock_random.seed(0)
>>> street(random=mock_random)
'chimp place'
>>> street(random=mock_random, capitalize=True)
'Boatbench Block'
>>> mock_random.seed(3)
>>> street(random=mock_random, slugify=True)
'central-britches-boulevard' | [
"Produce",
"something",
"that",
"sounds",
"like",
"a",
"street",
"name"
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L1474-L1499 | train |
classam/silly | silly/main.py | address | def address(random=random, *args, **kwargs):
"""
A street name plus a number!
>>> mock_random.seed(0)
>>> address(random=mock_random)
'0000 amazingslap boardwalk'
>>> address(random=mock_random, capitalize=True)
'0000 South Throbbingjump Boulevard'
>>> address(random=mock_random, slugif... | python | def address(random=random, *args, **kwargs):
"""
A street name plus a number!
>>> mock_random.seed(0)
>>> address(random=mock_random)
'0000 amazingslap boardwalk'
>>> address(random=mock_random, capitalize=True)
'0000 South Throbbingjump Boulevard'
>>> address(random=mock_random, slugif... | [
"def",
"address",
"(",
"random",
"=",
"random",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"return",
"random",
".",
"choice",
"(",
"[",
"\"{number}{other_number}{number}{other_number} {street}\"",
",",
"\"{number}{other_number} {street}\"",
",",
"\"{numberwang} ... | A street name plus a number!
>>> mock_random.seed(0)
>>> address(random=mock_random)
'0000 amazingslap boardwalk'
>>> address(random=mock_random, capitalize=True)
'0000 South Throbbingjump Boulevard'
>>> address(random=mock_random, slugify=True)
'two-central-britches-boulevard' | [
"A",
"street",
"name",
"plus",
"a",
"number!"
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L1504-L1527 | train |
classam/silly | silly/main.py | image | def image(random=random, width=800, height=600, https=False, *args, **kwargs):
"""
Generate the address of a placeholder image.
>>> mock_random.seed(0)
>>> image(random=mock_random)
'http://dummyimage.com/800x600/292929/e3e3e3&text=mighty poop'
>>> image(random=mock_random, width=60, height=60)... | python | def image(random=random, width=800, height=600, https=False, *args, **kwargs):
"""
Generate the address of a placeholder image.
>>> mock_random.seed(0)
>>> image(random=mock_random)
'http://dummyimage.com/800x600/292929/e3e3e3&text=mighty poop'
>>> image(random=mock_random, width=60, height=60)... | [
"def",
"image",
"(",
"random",
"=",
"random",
",",
"width",
"=",
"800",
",",
"height",
"=",
"600",
",",
"https",
"=",
"False",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"target_fn",
"=",
"noun",
"if",
"width",
"+",
"height",
">",
"300",
":... | Generate the address of a placeholder image.
>>> mock_random.seed(0)
>>> image(random=mock_random)
'http://dummyimage.com/800x600/292929/e3e3e3&text=mighty poop'
>>> image(random=mock_random, width=60, height=60)
'http://placekitten.com/60/60'
>>> image(random=mock_random, width=1920, height=10... | [
"Generate",
"the",
"address",
"of",
"a",
"placeholder",
"image",
"."
] | f3202e997d5ebc9e4f98370b08665fd1178a9556 | https://github.com/classam/silly/blob/f3202e997d5ebc9e4f98370b08665fd1178a9556/silly/main.py#L1530-L1563 | train |
andersinno/python-database-sanitizer | database_sanitizer/utils/postgres.py | decode_copy_value | def decode_copy_value(value):
"""
Decodes value received as part of Postgres `COPY` command.
:param value: Value to decode.
:type value: str
:return: Either None if the value is NULL string, or the given value where
escape sequences have been decoded from.
:rtype: str|None
"""... | python | def decode_copy_value(value):
"""
Decodes value received as part of Postgres `COPY` command.
:param value: Value to decode.
:type value: str
:return: Either None if the value is NULL string, or the given value where
escape sequences have been decoded from.
:rtype: str|None
"""... | [
"def",
"decode_copy_value",
"(",
"value",
")",
":",
"if",
"value",
"==",
"POSTGRES_COPY_NULL_VALUE",
":",
"return",
"None",
"if",
"'\\\\'",
"not",
"in",
"value",
":",
"return",
"value",
"return",
"DECODE_REGEX",
".",
"sub",
"(",
"unescape_single_character",
",",... | Decodes value received as part of Postgres `COPY` command.
:param value: Value to decode.
:type value: str
:return: Either None if the value is NULL string, or the given value where
escape sequences have been decoded from.
:rtype: str|None | [
"Decodes",
"value",
"received",
"as",
"part",
"of",
"Postgres",
"COPY",
"command",
"."
] | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/utils/postgres.py#L59-L82 | train |
andersinno/python-database-sanitizer | database_sanitizer/utils/postgres.py | unescape_single_character | def unescape_single_character(match):
"""
Unescape a single escape sequence found by regular expression.
:param match: Regular expression match object
:rtype: str
:raises: ValueError if the escape sequence is invalid
"""
try:
return DECODE_MAP[match.group(0)]
except KeyError:
... | python | def unescape_single_character(match):
"""
Unescape a single escape sequence found by regular expression.
:param match: Regular expression match object
:rtype: str
:raises: ValueError if the escape sequence is invalid
"""
try:
return DECODE_MAP[match.group(0)]
except KeyError:
... | [
"def",
"unescape_single_character",
"(",
"match",
")",
":",
"try",
":",
"return",
"DECODE_MAP",
"[",
"match",
".",
"group",
"(",
"0",
")",
"]",
"except",
"KeyError",
":",
"value",
"=",
"match",
".",
"group",
"(",
"0",
")",
"if",
"value",
"==",
"'\\\\'"... | Unescape a single escape sequence found by regular expression.
:param match: Regular expression match object
:rtype: str
:raises: ValueError if the escape sequence is invalid | [
"Unescape",
"a",
"single",
"escape",
"sequence",
"found",
"by",
"regular",
"expression",
"."
] | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/utils/postgres.py#L85-L101 | train |
andersinno/python-database-sanitizer | database_sanitizer/dump/__init__.py | run | def run(url, output, config):
"""
Extracts database dump from given database URL and outputs sanitized
copy of it into given stream.
:param url: URL to the database which is to be sanitized.
:type url: str
:param output: Stream where sanitized copy of the database dump will be
... | python | def run(url, output, config):
"""
Extracts database dump from given database URL and outputs sanitized
copy of it into given stream.
:param url: URL to the database which is to be sanitized.
:type url: str
:param output: Stream where sanitized copy of the database dump will be
... | [
"def",
"run",
"(",
"url",
",",
"output",
",",
"config",
")",
":",
"parsed_url",
"=",
"urlparse",
".",
"urlparse",
"(",
"url",
")",
"db_module_path",
"=",
"SUPPORTED_DATABASE_MODULES",
".",
"get",
"(",
"parsed_url",
".",
"scheme",
")",
"if",
"not",
"db_modu... | Extracts database dump from given database URL and outputs sanitized
copy of it into given stream.
:param url: URL to the database which is to be sanitized.
:type url: str
:param output: Stream where sanitized copy of the database dump will be
written into.
:type output: file
... | [
"Extracts",
"database",
"dump",
"from",
"given",
"database",
"URL",
"and",
"outputs",
"sanitized",
"copy",
"of",
"it",
"into",
"given",
"stream",
"."
] | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/dump/__init__.py#L24-L47 | train |
andersinno/python-database-sanitizer | database_sanitizer/dump/postgres.py | sanitize | def sanitize(url, config):
"""
Obtains dump of an Postgres database by executing `pg_dump` command and
sanitizes it's output.
:param url: URL to the database which is going to be sanitized, parsed by
Python's URL parser.
:type url: six.moves.urllib.parse.ParseResult
:param conf... | python | def sanitize(url, config):
"""
Obtains dump of an Postgres database by executing `pg_dump` command and
sanitizes it's output.
:param url: URL to the database which is going to be sanitized, parsed by
Python's URL parser.
:type url: six.moves.urllib.parse.ParseResult
:param conf... | [
"def",
"sanitize",
"(",
"url",
",",
"config",
")",
":",
"if",
"url",
".",
"scheme",
"not",
"in",
"(",
"\"postgres\"",
",",
"\"postgresql\"",
",",
"\"postgis\"",
")",
":",
"raise",
"ValueError",
"(",
"\"Unsupported database type: '%s'\"",
"%",
"(",
"url",
"."... | Obtains dump of an Postgres database by executing `pg_dump` command and
sanitizes it's output.
:param url: URL to the database which is going to be sanitized, parsed by
Python's URL parser.
:type url: six.moves.urllib.parse.ParseResult
:param config: Optional sanitizer configuration to... | [
"Obtains",
"dump",
"of",
"an",
"Postgres",
"database",
"by",
"executing",
"pg_dump",
"command",
"and",
"sanitizes",
"it",
"s",
"output",
"."
] | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/dump/postgres.py#L18-L85 | train |
andersinno/python-database-sanitizer | database_sanitizer/dump/postgres.py | parse_column_names | def parse_column_names(text):
"""
Extracts column names from a string containing quoted and comma separated
column names.
:param text: Line extracted from `COPY` statement containing quoted and
comma separated column names.
:type text: str
:return: Tuple containing just the co... | python | def parse_column_names(text):
"""
Extracts column names from a string containing quoted and comma separated
column names.
:param text: Line extracted from `COPY` statement containing quoted and
comma separated column names.
:type text: str
:return: Tuple containing just the co... | [
"def",
"parse_column_names",
"(",
"text",
")",
":",
"return",
"tuple",
"(",
"re",
".",
"sub",
"(",
"r\"^\\\"(.*)\\\"$\"",
",",
"r\"\\1\"",
",",
"column_name",
".",
"strip",
"(",
")",
")",
"for",
"column_name",
"in",
"text",
".",
"split",
"(",
"\",\"",
")... | Extracts column names from a string containing quoted and comma separated
column names.
:param text: Line extracted from `COPY` statement containing quoted and
comma separated column names.
:type text: str
:return: Tuple containing just the column names.
:rtype: tuple[str] | [
"Extracts",
"column",
"names",
"from",
"a",
"string",
"containing",
"quoted",
"and",
"comma",
"separated",
"column",
"names",
"."
] | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/dump/postgres.py#L123-L138 | train |
andersinno/python-database-sanitizer | database_sanitizer/utils/mysql.py | get_mysqldump_args_and_env_from_url | def get_mysqldump_args_and_env_from_url(url):
"""
Constructs list of command line arguments and dictionary of environment
variables that can be given to `mysqldump` executable to obtain database
dump of the database described in given URL.
:param url: Parsed database URL.
:type url: urllib.urlp... | python | def get_mysqldump_args_and_env_from_url(url):
"""
Constructs list of command line arguments and dictionary of environment
variables that can be given to `mysqldump` executable to obtain database
dump of the database described in given URL.
:param url: Parsed database URL.
:type url: urllib.urlp... | [
"def",
"get_mysqldump_args_and_env_from_url",
"(",
"url",
")",
":",
"args",
"=",
"[",
"\"--complete-insert\"",
",",
"\"--extended-insert\"",
",",
"\"--net_buffer_length=10240\"",
",",
"\"-h\"",
",",
"url",
".",
"hostname",
",",
"]",
"env",
"=",
"{",
"}",
"if",
"... | Constructs list of command line arguments and dictionary of environment
variables that can be given to `mysqldump` executable to obtain database
dump of the database described in given URL.
:param url: Parsed database URL.
:type url: urllib.urlparse.ParseResult
:return: List of command line argume... | [
"Constructs",
"list",
"of",
"command",
"line",
"arguments",
"and",
"dictionary",
"of",
"environment",
"variables",
"that",
"can",
"be",
"given",
"to",
"mysqldump",
"executable",
"to",
"obtain",
"database",
"dump",
"of",
"the",
"database",
"described",
"in",
"giv... | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/utils/mysql.py#L11-L61 | train |
andersinno/python-database-sanitizer | database_sanitizer/utils/mysql.py | decode_mysql_literal | def decode_mysql_literal(text):
"""
Attempts to decode given MySQL literal into Python value.
:param text: Value to be decoded, as MySQL literal.
:type text: str
:return: Python version of the given MySQL literal.
:rtype: any
"""
if MYSQL_NULL_PATTERN.match(text):
return None
... | python | def decode_mysql_literal(text):
"""
Attempts to decode given MySQL literal into Python value.
:param text: Value to be decoded, as MySQL literal.
:type text: str
:return: Python version of the given MySQL literal.
:rtype: any
"""
if MYSQL_NULL_PATTERN.match(text):
return None
... | [
"def",
"decode_mysql_literal",
"(",
"text",
")",
":",
"if",
"MYSQL_NULL_PATTERN",
".",
"match",
"(",
"text",
")",
":",
"return",
"None",
"if",
"MYSQL_BOOLEAN_PATTERN",
".",
"match",
"(",
"text",
")",
":",
"return",
"text",
".",
"lower",
"(",
")",
"==",
"... | Attempts to decode given MySQL literal into Python value.
:param text: Value to be decoded, as MySQL literal.
:type text: str
:return: Python version of the given MySQL literal.
:rtype: any | [
"Attempts",
"to",
"decode",
"given",
"MySQL",
"literal",
"into",
"Python",
"value",
"."
] | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/utils/mysql.py#L71-L96 | train |
andersinno/python-database-sanitizer | database_sanitizer/utils/mysql.py | decode_mysql_string_literal | def decode_mysql_string_literal(text):
"""
Removes quotes and decodes escape sequences from given MySQL string literal
returning the result.
:param text: MySQL string literal, with the quotes still included.
:type text: str
:return: Given string literal with quotes removed and escape sequences... | python | def decode_mysql_string_literal(text):
"""
Removes quotes and decodes escape sequences from given MySQL string literal
returning the result.
:param text: MySQL string literal, with the quotes still included.
:type text: str
:return: Given string literal with quotes removed and escape sequences... | [
"def",
"decode_mysql_string_literal",
"(",
"text",
")",
":",
"assert",
"text",
".",
"startswith",
"(",
"\"'\"",
")",
"assert",
"text",
".",
"endswith",
"(",
"\"'\"",
")",
"text",
"=",
"text",
"[",
"1",
":",
"-",
"1",
"]",
"return",
"MYSQL_STRING_ESCAPE_SEQ... | Removes quotes and decodes escape sequences from given MySQL string literal
returning the result.
:param text: MySQL string literal, with the quotes still included.
:type text: str
:return: Given string literal with quotes removed and escape sequences
decoded.
:rtype: str | [
"Removes",
"quotes",
"and",
"decodes",
"escape",
"sequences",
"from",
"given",
"MySQL",
"string",
"literal",
"returning",
"the",
"result",
"."
] | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/utils/mysql.py#L110-L131 | train |
safarijv/sbo-selenium | sbo_selenium/utils.py | OutputMonitor.wait_for | def wait_for(self, text, seconds):
"""
Returns True when the specified text has appeared in a line of the
output, or False when the specified number of seconds have passed
without that occurring.
"""
found = False
stream = self.stream
start_time = time.tim... | python | def wait_for(self, text, seconds):
"""
Returns True when the specified text has appeared in a line of the
output, or False when the specified number of seconds have passed
without that occurring.
"""
found = False
stream = self.stream
start_time = time.tim... | [
"def",
"wait_for",
"(",
"self",
",",
"text",
",",
"seconds",
")",
":",
"found",
"=",
"False",
"stream",
"=",
"self",
".",
"stream",
"start_time",
"=",
"time",
".",
"time",
"(",
")",
"while",
"not",
"found",
":",
"if",
"time",
".",
"time",
"(",
")",... | Returns True when the specified text has appeared in a line of the
output, or False when the specified number of seconds have passed
without that occurring. | [
"Returns",
"True",
"when",
"the",
"specified",
"text",
"has",
"appeared",
"in",
"a",
"line",
"of",
"the",
"output",
"or",
"False",
"when",
"the",
"specified",
"number",
"of",
"seconds",
"have",
"passed",
"without",
"that",
"occurring",
"."
] | 16539f1b17cda18270033db3b64ab25bc05c5664 | https://github.com/safarijv/sbo-selenium/blob/16539f1b17cda18270033db3b64ab25bc05c5664/sbo_selenium/utils.py#L176-L200 | train |
safarijv/sbo-selenium | sbo_selenium/utils.py | DockerSelenium.command_executor | def command_executor(self):
"""Get the appropriate command executor URL for the Selenium server
running in the Docker container."""
ip_address = self.ip_address if self.ip_address else '127.0.0.1'
return 'http://{}:{}/wd/hub'.format(ip_address, self.port) | python | def command_executor(self):
"""Get the appropriate command executor URL for the Selenium server
running in the Docker container."""
ip_address = self.ip_address if self.ip_address else '127.0.0.1'
return 'http://{}:{}/wd/hub'.format(ip_address, self.port) | [
"def",
"command_executor",
"(",
"self",
")",
":",
"ip_address",
"=",
"self",
".",
"ip_address",
"if",
"self",
".",
"ip_address",
"else",
"'127.0.0.1'",
"return",
"'http://{}:{}/wd/hub'",
".",
"format",
"(",
"ip_address",
",",
"self",
".",
"port",
")"
] | Get the appropriate command executor URL for the Selenium server
running in the Docker container. | [
"Get",
"the",
"appropriate",
"command",
"executor",
"URL",
"for",
"the",
"Selenium",
"server",
"running",
"in",
"the",
"Docker",
"container",
"."
] | 16539f1b17cda18270033db3b64ab25bc05c5664 | https://github.com/safarijv/sbo-selenium/blob/16539f1b17cda18270033db3b64ab25bc05c5664/sbo_selenium/utils.py#L223-L227 | train |
safarijv/sbo-selenium | sbo_selenium/utils.py | DockerSelenium.start | def start(self):
"""Start the Docker container"""
if self.container_id is not None:
msg = 'The Docker container is already running with ID {}'
raise Exception(msg.format(self.container_id))
process = Popen(['docker ps | grep ":{}"'.format(self.port)],
... | python | def start(self):
"""Start the Docker container"""
if self.container_id is not None:
msg = 'The Docker container is already running with ID {}'
raise Exception(msg.format(self.container_id))
process = Popen(['docker ps | grep ":{}"'.format(self.port)],
... | [
"def",
"start",
"(",
"self",
")",
":",
"if",
"self",
".",
"container_id",
"is",
"not",
"None",
":",
"msg",
"=",
"'The Docker container is already running with ID {}'",
"raise",
"Exception",
"(",
"msg",
".",
"format",
"(",
"self",
".",
"container_id",
")",
")",... | Start the Docker container | [
"Start",
"the",
"Docker",
"container"
] | 16539f1b17cda18270033db3b64ab25bc05c5664 | https://github.com/safarijv/sbo-selenium/blob/16539f1b17cda18270033db3b64ab25bc05c5664/sbo_selenium/utils.py#L229-L261 | train |
safarijv/sbo-selenium | sbo_selenium/utils.py | DockerSelenium.stop | def stop(self):
"""Stop the Docker container"""
if self.container_id is None:
raise Exception('No Docker Selenium container was running')
check_call(['docker', 'stop', self.container_id])
self.container_id = None | python | def stop(self):
"""Stop the Docker container"""
if self.container_id is None:
raise Exception('No Docker Selenium container was running')
check_call(['docker', 'stop', self.container_id])
self.container_id = None | [
"def",
"stop",
"(",
"self",
")",
":",
"if",
"self",
".",
"container_id",
"is",
"None",
":",
"raise",
"Exception",
"(",
"'No Docker Selenium container was running'",
")",
"check_call",
"(",
"[",
"'docker'",
",",
"'stop'",
",",
"self",
".",
"container_id",
"]",
... | Stop the Docker container | [
"Stop",
"the",
"Docker",
"container"
] | 16539f1b17cda18270033db3b64ab25bc05c5664 | https://github.com/safarijv/sbo-selenium/blob/16539f1b17cda18270033db3b64ab25bc05c5664/sbo_selenium/utils.py#L263-L268 | train |
andersinno/python-database-sanitizer | database_sanitizer/session.py | hash_text_to_ints | def hash_text_to_ints(value, bit_lengths=(16, 16, 16, 16)):
# type: (str, Sequence[int]) -> Sequence[int]
"""
Hash a text value to a sequence of integers.
Generates a sequence of integer values with given bit-lengths
similarly to `hash_text_to_int`, but allowing generating many
separate numbers... | python | def hash_text_to_ints(value, bit_lengths=(16, 16, 16, 16)):
# type: (str, Sequence[int]) -> Sequence[int]
"""
Hash a text value to a sequence of integers.
Generates a sequence of integer values with given bit-lengths
similarly to `hash_text_to_int`, but allowing generating many
separate numbers... | [
"def",
"hash_text_to_ints",
"(",
"value",
",",
"bit_lengths",
"=",
"(",
"16",
",",
"16",
",",
"16",
",",
"16",
")",
")",
":",
"hash_value",
"=",
"hash_text",
"(",
"value",
")",
"hex_lengths",
"=",
"[",
"x",
"//",
"4",
"for",
"x",
"in",
"bit_lengths",... | Hash a text value to a sequence of integers.
Generates a sequence of integer values with given bit-lengths
similarly to `hash_text_to_int`, but allowing generating many
separate numbers with a single call.
:param bit_lengths:
Tuple of bit lengths for the resulting integers. Defines also the
... | [
"Hash",
"a",
"text",
"value",
"to",
"a",
"sequence",
"of",
"integers",
"."
] | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/session.py#L50-L72 | train |
andersinno/python-database-sanitizer | database_sanitizer/session.py | hash_text | def hash_text(value, hasher=hashlib.sha256, encoding='utf-8'):
# type: (str, Callable, str) -> str
"""
Generate a hash for a text value.
The hash will be generated by encoding the text to bytes with given
encoding and then generating a hash with HMAC using the session
secret as the key and the ... | python | def hash_text(value, hasher=hashlib.sha256, encoding='utf-8'):
# type: (str, Callable, str) -> str
"""
Generate a hash for a text value.
The hash will be generated by encoding the text to bytes with given
encoding and then generating a hash with HMAC using the session
secret as the key and the ... | [
"def",
"hash_text",
"(",
"value",
",",
"hasher",
"=",
"hashlib",
".",
"sha256",
",",
"encoding",
"=",
"'utf-8'",
")",
":",
"return",
"hash_bytes",
"(",
"value",
".",
"encode",
"(",
"encoding",
")",
",",
"hasher",
")"
] | Generate a hash for a text value.
The hash will be generated by encoding the text to bytes with given
encoding and then generating a hash with HMAC using the session
secret as the key and the given hash function.
:param value: Text value to hash
:param hasher: Hash function to use, SHA256 by defau... | [
"Generate",
"a",
"hash",
"for",
"a",
"text",
"value",
"."
] | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/session.py#L75-L89 | train |
andersinno/python-database-sanitizer | database_sanitizer/session.py | hash_bytes | def hash_bytes(value, hasher=hashlib.sha256):
# type: (bytes, Callable) -> str
"""
Generate a hash for a bytes value.
The hash will be generated by generating a hash with HMAC using the
session secret as the key and the given hash function.
:param value: Bytes value to hash
:param hasher: ... | python | def hash_bytes(value, hasher=hashlib.sha256):
# type: (bytes, Callable) -> str
"""
Generate a hash for a bytes value.
The hash will be generated by generating a hash with HMAC using the
session secret as the key and the given hash function.
:param value: Bytes value to hash
:param hasher: ... | [
"def",
"hash_bytes",
"(",
"value",
",",
"hasher",
"=",
"hashlib",
".",
"sha256",
")",
":",
"return",
"hmac",
".",
"new",
"(",
"get_secret",
"(",
")",
",",
"value",
",",
"hasher",
")",
".",
"hexdigest",
"(",
")"
] | Generate a hash for a bytes value.
The hash will be generated by generating a hash with HMAC using the
session secret as the key and the given hash function.
:param value: Bytes value to hash
:param hasher: Hash function to use.
:return: Hexadecimal presentation of the hash as a string | [
"Generate",
"a",
"hash",
"for",
"a",
"bytes",
"value",
"."
] | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/session.py#L92-L104 | train |
andersinno/python-database-sanitizer | database_sanitizer/session.py | _initialize_session | def _initialize_session():
# type: () -> None
"""
Generate a new session key and store it to thread local storage.
"""
sys_random = random.SystemRandom()
_thread_local_storage.secret_key = b''.join(
int2byte(sys_random.randint(0, 255))
for _ in range(SECRET_KEY_BITS // 8)) | python | def _initialize_session():
# type: () -> None
"""
Generate a new session key and store it to thread local storage.
"""
sys_random = random.SystemRandom()
_thread_local_storage.secret_key = b''.join(
int2byte(sys_random.randint(0, 255))
for _ in range(SECRET_KEY_BITS // 8)) | [
"def",
"_initialize_session",
"(",
")",
":",
"sys_random",
"=",
"random",
".",
"SystemRandom",
"(",
")",
"_thread_local_storage",
".",
"secret_key",
"=",
"b''",
".",
"join",
"(",
"int2byte",
"(",
"sys_random",
".",
"randint",
"(",
"0",
",",
"255",
")",
")"... | Generate a new session key and store it to thread local storage. | [
"Generate",
"a",
"new",
"session",
"key",
"and",
"store",
"it",
"to",
"thread",
"local",
"storage",
"."
] | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/session.py#L138-L146 | train |
fridiculous/estimators | estimators/evaluations.py | EvaluationMixin._get_proxy_object | def _get_proxy_object(self, obj, ProxyKlass, proxy_klass_attribute):
""" Returns the proxy object for an input object
If the object is already the proxy object, return it.
Otherwise set the appropriate proxy object to the proxy object's attribute
"""
proxy_object = obj
i... | python | def _get_proxy_object(self, obj, ProxyKlass, proxy_klass_attribute):
""" Returns the proxy object for an input object
If the object is already the proxy object, return it.
Otherwise set the appropriate proxy object to the proxy object's attribute
"""
proxy_object = obj
i... | [
"def",
"_get_proxy_object",
"(",
"self",
",",
"obj",
",",
"ProxyKlass",
",",
"proxy_klass_attribute",
")",
":",
"proxy_object",
"=",
"obj",
"if",
"not",
"isinstance",
"(",
"obj",
",",
"ProxyKlass",
")",
":",
"proxy_object",
"=",
"ProxyKlass",
"(",
"**",
"{",... | Returns the proxy object for an input object
If the object is already the proxy object, return it.
Otherwise set the appropriate proxy object to the proxy object's attribute | [
"Returns",
"the",
"proxy",
"object",
"for",
"an",
"input",
"object"
] | ab5b3d70f16f8372ae1114ac7e54e7791631eb74 | https://github.com/fridiculous/estimators/blob/ab5b3d70f16f8372ae1114ac7e54e7791631eb74/estimators/evaluations.py#L13-L22 | train |
andersinno/python-database-sanitizer | database_sanitizer/config.py | Configuration.from_file | def from_file(cls, filename):
"""
Reads configuration from given path to a file in local file system and
returns parsed version of it.
:param filename: Path to the YAML file in local file system where the
configuration will be read from.
:type filename: ... | python | def from_file(cls, filename):
"""
Reads configuration from given path to a file in local file system and
returns parsed version of it.
:param filename: Path to the YAML file in local file system where the
configuration will be read from.
:type filename: ... | [
"def",
"from_file",
"(",
"cls",
",",
"filename",
")",
":",
"instance",
"=",
"cls",
"(",
")",
"with",
"open",
"(",
"filename",
",",
"\"rb\"",
")",
"as",
"file_stream",
":",
"config_data",
"=",
"yaml",
".",
"load",
"(",
"file_stream",
")",
"instance",
".... | Reads configuration from given path to a file in local file system and
returns parsed version of it.
:param filename: Path to the YAML file in local file system where the
configuration will be read from.
:type filename: str
:return: Configuration instance parse... | [
"Reads",
"configuration",
"from",
"given",
"path",
"to",
"a",
"file",
"in",
"local",
"file",
"system",
"and",
"returns",
"parsed",
"version",
"of",
"it",
"."
] | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/config.py#L29-L48 | train |
andersinno/python-database-sanitizer | database_sanitizer/config.py | Configuration.load | def load(self, config_data):
"""
Loads sanitizers according to rulesets defined in given already parsed
configuration file.
:param config_data: Already parsed configuration data, as dictionary.
:type config_data: dict[str,any]
"""
if not isinstance(config_data, d... | python | def load(self, config_data):
"""
Loads sanitizers according to rulesets defined in given already parsed
configuration file.
:param config_data: Already parsed configuration data, as dictionary.
:type config_data: dict[str,any]
"""
if not isinstance(config_data, d... | [
"def",
"load",
"(",
"self",
",",
"config_data",
")",
":",
"if",
"not",
"isinstance",
"(",
"config_data",
",",
"dict",
")",
":",
"raise",
"ConfigurationError",
"(",
"\"Configuration data is %s instead of dict.\"",
"%",
"(",
"type",
"(",
"config_data",
")",
",",
... | Loads sanitizers according to rulesets defined in given already parsed
configuration file.
:param config_data: Already parsed configuration data, as dictionary.
:type config_data: dict[str,any] | [
"Loads",
"sanitizers",
"according",
"to",
"rulesets",
"defined",
"in",
"given",
"already",
"parsed",
"configuration",
"file",
"."
] | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/config.py#L50-L66 | train |
andersinno/python-database-sanitizer | database_sanitizer/config.py | Configuration.load_addon_packages | def load_addon_packages(self, config_data):
"""
Loads the module paths from which the configuration will attempt to
load sanitizers from. These must be stored as a list of strings under
"config.addons" section of the configuration data.
:param config_data: Already parsed configu... | python | def load_addon_packages(self, config_data):
"""
Loads the module paths from which the configuration will attempt to
load sanitizers from. These must be stored as a list of strings under
"config.addons" section of the configuration data.
:param config_data: Already parsed configu... | [
"def",
"load_addon_packages",
"(",
"self",
",",
"config_data",
")",
":",
"section_config",
"=",
"config_data",
".",
"get",
"(",
"\"config\"",
")",
"if",
"not",
"isinstance",
"(",
"section_config",
",",
"dict",
")",
":",
"if",
"section_config",
"is",
"None",
... | Loads the module paths from which the configuration will attempt to
load sanitizers from. These must be stored as a list of strings under
"config.addons" section of the configuration data.
:param config_data: Already parsed configuration data, as dictionary.
:type config_data: dict[str,... | [
"Loads",
"the",
"module",
"paths",
"from",
"which",
"the",
"configuration",
"will",
"attempt",
"to",
"load",
"sanitizers",
"from",
".",
"These",
"must",
"be",
"stored",
"as",
"a",
"list",
"of",
"strings",
"under",
"config",
".",
"addons",
"section",
"of",
... | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/config.py#L68-L104 | train |
andersinno/python-database-sanitizer | database_sanitizer/config.py | Configuration.load_sanitizers | def load_sanitizers(self, config_data):
"""
Loads sanitizers possibly defined in the configuration under dictionary
called "strategy", which should contain mapping of database tables with
column names mapped into sanitizer function names.
:param config_data: Already parsed confi... | python | def load_sanitizers(self, config_data):
"""
Loads sanitizers possibly defined in the configuration under dictionary
called "strategy", which should contain mapping of database tables with
column names mapped into sanitizer function names.
:param config_data: Already parsed confi... | [
"def",
"load_sanitizers",
"(",
"self",
",",
"config_data",
")",
":",
"section_strategy",
"=",
"config_data",
".",
"get",
"(",
"\"strategy\"",
")",
"if",
"not",
"isinstance",
"(",
"section_strategy",
",",
"dict",
")",
":",
"if",
"section_strategy",
"is",
"None"... | Loads sanitizers possibly defined in the configuration under dictionary
called "strategy", which should contain mapping of database tables with
column names mapped into sanitizer function names.
:param config_data: Already parsed configuration data, as dictionary.
:type config_data: dic... | [
"Loads",
"sanitizers",
"possibly",
"defined",
"in",
"the",
"configuration",
"under",
"dictionary",
"called",
"strategy",
"which",
"should",
"contain",
"mapping",
"of",
"database",
"tables",
"with",
"column",
"names",
"mapped",
"into",
"sanitizer",
"function",
"names... | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/config.py#L106-L151 | train |
andersinno/python-database-sanitizer | database_sanitizer/config.py | Configuration.find_sanitizer | def find_sanitizer(self, name):
"""
Searches for a sanitizer function with given name. The name should
contain two parts separated from each other with a dot, the first
part being the module name while the second being name of the function
contained in the module, when it's being... | python | def find_sanitizer(self, name):
"""
Searches for a sanitizer function with given name. The name should
contain two parts separated from each other with a dot, the first
part being the module name while the second being name of the function
contained in the module, when it's being... | [
"def",
"find_sanitizer",
"(",
"self",
",",
"name",
")",
":",
"name_parts",
"=",
"name",
".",
"split",
"(",
"\".\"",
")",
"if",
"len",
"(",
"name_parts",
")",
"<",
"2",
":",
"raise",
"ConfigurationError",
"(",
"\"Unable to separate module name from function name ... | Searches for a sanitizer function with given name. The name should
contain two parts separated from each other with a dot, the first
part being the module name while the second being name of the function
contained in the module, when it's being prefixed with "sanitize_".
The lookup proc... | [
"Searches",
"for",
"a",
"sanitizer",
"function",
"with",
"given",
"name",
".",
"The",
"name",
"should",
"contain",
"two",
"parts",
"separated",
"from",
"each",
"other",
"with",
"a",
"dot",
"the",
"first",
"part",
"being",
"the",
"module",
"name",
"while",
... | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/config.py#L153-L229 | train |
andersinno/python-database-sanitizer | database_sanitizer/config.py | Configuration.find_sanitizer_from_module | def find_sanitizer_from_module(module_name, function_name):
"""
Attempts to find sanitizer function from given module. If the module
cannot be imported, or function with given name does not exist in it,
nothing will be returned by this method. Otherwise the found sanitizer
functi... | python | def find_sanitizer_from_module(module_name, function_name):
"""
Attempts to find sanitizer function from given module. If the module
cannot be imported, or function with given name does not exist in it,
nothing will be returned by this method. Otherwise the found sanitizer
functi... | [
"def",
"find_sanitizer_from_module",
"(",
"module_name",
",",
"function_name",
")",
":",
"try",
":",
"module",
"=",
"importlib",
".",
"import_module",
"(",
"module_name",
")",
"except",
"ImportError",
":",
"return",
"None",
"callback",
"=",
"getattr",
"(",
"modu... | Attempts to find sanitizer function from given module. If the module
cannot be imported, or function with given name does not exist in it,
nothing will be returned by this method. Otherwise the found sanitizer
function will be returned.
:param module_name: Name of the module to import t... | [
"Attempts",
"to",
"find",
"sanitizer",
"function",
"from",
"given",
"module",
".",
"If",
"the",
"module",
"cannot",
"be",
"imported",
"or",
"function",
"with",
"given",
"name",
"does",
"not",
"exist",
"in",
"it",
"nothing",
"will",
"be",
"returned",
"by",
... | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/config.py#L232-L274 | train |
andersinno/python-database-sanitizer | database_sanitizer/config.py | Configuration.get_sanitizer_for | def get_sanitizer_for(self, table_name, column_name):
"""
Get sanitizer for given table and column name.
:param table_name: Name of the database table.
:type table_name: str
:param column_name: Name of the database column.
:type column_name: str
:return: Saniti... | python | def get_sanitizer_for(self, table_name, column_name):
"""
Get sanitizer for given table and column name.
:param table_name: Name of the database table.
:type table_name: str
:param column_name: Name of the database column.
:type column_name: str
:return: Saniti... | [
"def",
"get_sanitizer_for",
"(",
"self",
",",
"table_name",
",",
"column_name",
")",
":",
"sanitizer_key",
"=",
"\"%s.%s\"",
"%",
"(",
"table_name",
",",
"column_name",
")",
"return",
"self",
".",
"sanitizers",
".",
"get",
"(",
"sanitizer_key",
")"
] | Get sanitizer for given table and column name.
:param table_name: Name of the database table.
:type table_name: str
:param column_name: Name of the database column.
:type column_name: str
:return: Sanitizer function or None if nothing is configured
:rtype: Optional[Cal... | [
"Get",
"sanitizer",
"for",
"given",
"table",
"and",
"column",
"name",
"."
] | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/config.py#L276-L290 | train |
andersinno/python-database-sanitizer | database_sanitizer/config.py | Configuration.sanitize | def sanitize(self, table_name, column_name, value):
"""
Sanitizes given value extracted from the database according to the
sanitation configuration.
TODO: Add support for dates, booleans and other types found in SQL than
string.
:param table_name: Name of the database t... | python | def sanitize(self, table_name, column_name, value):
"""
Sanitizes given value extracted from the database according to the
sanitation configuration.
TODO: Add support for dates, booleans and other types found in SQL than
string.
:param table_name: Name of the database t... | [
"def",
"sanitize",
"(",
"self",
",",
"table_name",
",",
"column_name",
",",
"value",
")",
":",
"sanitizer_callback",
"=",
"self",
".",
"get_sanitizer_for",
"(",
"table_name",
",",
"column_name",
")",
"return",
"sanitizer_callback",
"(",
"value",
")",
"if",
"sa... | Sanitizes given value extracted from the database according to the
sanitation configuration.
TODO: Add support for dates, booleans and other types found in SQL than
string.
:param table_name: Name of the database table from which the value is
from.
:t... | [
"Sanitizes",
"given",
"value",
"extracted",
"from",
"the",
"database",
"according",
"to",
"the",
"sanitation",
"configuration",
"."
] | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/config.py#L292-L316 | train |
safarijv/sbo-selenium | sbo_selenium/management/commands/selenium.py | Command.add_arguments | def add_arguments(self, parser):
"""Command line arguments for Django 1.8+"""
# Add the underlying test command arguments first
test_command = TestCommand()
test_command.add_arguments(parser)
for option in OPTIONS:
parser.add_argument(*option[0], **option[1]) | python | def add_arguments(self, parser):
"""Command line arguments for Django 1.8+"""
# Add the underlying test command arguments first
test_command = TestCommand()
test_command.add_arguments(parser)
for option in OPTIONS:
parser.add_argument(*option[0], **option[1]) | [
"def",
"add_arguments",
"(",
"self",
",",
"parser",
")",
":",
"test_command",
"=",
"TestCommand",
"(",
")",
"test_command",
".",
"add_arguments",
"(",
"parser",
")",
"for",
"option",
"in",
"OPTIONS",
":",
"parser",
".",
"add_argument",
"(",
"*",
"option",
... | Command line arguments for Django 1.8+ | [
"Command",
"line",
"arguments",
"for",
"Django",
"1",
".",
"8",
"+"
] | 16539f1b17cda18270033db3b64ab25bc05c5664 | https://github.com/safarijv/sbo-selenium/blob/16539f1b17cda18270033db3b64ab25bc05c5664/sbo_selenium/management/commands/selenium.py#L47-L54 | train |
safarijv/sbo-selenium | sbo_selenium/management/commands/selenium.py | Command.clean | def clean():
"""Clear out any old screenshots"""
screenshot_dir = settings.SELENIUM_SCREENSHOT_DIR
if screenshot_dir and os.path.isdir(screenshot_dir):
rmtree(screenshot_dir, ignore_errors=True) | python | def clean():
"""Clear out any old screenshots"""
screenshot_dir = settings.SELENIUM_SCREENSHOT_DIR
if screenshot_dir and os.path.isdir(screenshot_dir):
rmtree(screenshot_dir, ignore_errors=True) | [
"def",
"clean",
"(",
")",
":",
"screenshot_dir",
"=",
"settings",
".",
"SELENIUM_SCREENSHOT_DIR",
"if",
"screenshot_dir",
"and",
"os",
".",
"path",
".",
"isdir",
"(",
"screenshot_dir",
")",
":",
"rmtree",
"(",
"screenshot_dir",
",",
"ignore_errors",
"=",
"True... | Clear out any old screenshots | [
"Clear",
"out",
"any",
"old",
"screenshots"
] | 16539f1b17cda18270033db3b64ab25bc05c5664 | https://github.com/safarijv/sbo-selenium/blob/16539f1b17cda18270033db3b64ab25bc05c5664/sbo_selenium/management/commands/selenium.py#L67-L71 | train |
safarijv/sbo-selenium | sbo_selenium/management/commands/selenium.py | Command.verify_appium_is_running | def verify_appium_is_running(self):
"""Verify that Appium is running so it can be used for local iOS tests."""
process = Popen(['ps -e | grep "Appium"'], shell=True, stdout=PIPE)
(grep_output, _grep_error) = process.communicate()
lines = grep_output.split('\n')
for line in lines:... | python | def verify_appium_is_running(self):
"""Verify that Appium is running so it can be used for local iOS tests."""
process = Popen(['ps -e | grep "Appium"'], shell=True, stdout=PIPE)
(grep_output, _grep_error) = process.communicate()
lines = grep_output.split('\n')
for line in lines:... | [
"def",
"verify_appium_is_running",
"(",
"self",
")",
":",
"process",
"=",
"Popen",
"(",
"[",
"'ps -e | grep \"Appium\"'",
"]",
",",
"shell",
"=",
"True",
",",
"stdout",
"=",
"PIPE",
")",
"(",
"grep_output",
",",
"_grep_error",
")",
"=",
"process",
".",
"co... | Verify that Appium is running so it can be used for local iOS tests. | [
"Verify",
"that",
"Appium",
"is",
"running",
"so",
"it",
"can",
"be",
"used",
"for",
"local",
"iOS",
"tests",
"."
] | 16539f1b17cda18270033db3b64ab25bc05c5664 | https://github.com/safarijv/sbo-selenium/blob/16539f1b17cda18270033db3b64ab25bc05c5664/sbo_selenium/management/commands/selenium.py#L279-L289 | train |
fridiculous/estimators | estimators/hashing.py | NumpyHasher.save | def save(self, obj):
""" Subclass the save method, to hash ndarray subclass, rather
than pickling them. Off course, this is a total abuse of
the Pickler class.
"""
if isinstance(obj, self.np.ndarray) and not obj.dtype.hasobject:
# Compute a hash of the object
... | python | def save(self, obj):
""" Subclass the save method, to hash ndarray subclass, rather
than pickling them. Off course, this is a total abuse of
the Pickler class.
"""
if isinstance(obj, self.np.ndarray) and not obj.dtype.hasobject:
# Compute a hash of the object
... | [
"def",
"save",
"(",
"self",
",",
"obj",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"self",
".",
"np",
".",
"ndarray",
")",
"and",
"not",
"obj",
".",
"dtype",
".",
"hasobject",
":",
"if",
"obj",
".",
"shape",
"==",
"(",
")",
":",
"obj_c_contig... | Subclass the save method, to hash ndarray subclass, rather
than pickling them. Off course, this is a total abuse of
the Pickler class. | [
"Subclass",
"the",
"save",
"method",
"to",
"hash",
"ndarray",
"subclass",
"rather",
"than",
"pickling",
"them",
".",
"Off",
"course",
"this",
"is",
"a",
"total",
"abuse",
"of",
"the",
"Pickler",
"class",
"."
] | ab5b3d70f16f8372ae1114ac7e54e7791631eb74 | https://github.com/fridiculous/estimators/blob/ab5b3d70f16f8372ae1114ac7e54e7791631eb74/estimators/hashing.py#L209-L267 | train |
andersinno/python-database-sanitizer | database_sanitizer/sanitizers/string.py | sanitize_random | def sanitize_random(value):
"""
Random string of same length as the given value.
"""
if not value:
return value
return ''.join(random.choice(CHARACTERS) for _ in range(len(value))) | python | def sanitize_random(value):
"""
Random string of same length as the given value.
"""
if not value:
return value
return ''.join(random.choice(CHARACTERS) for _ in range(len(value))) | [
"def",
"sanitize_random",
"(",
"value",
")",
":",
"if",
"not",
"value",
":",
"return",
"value",
"return",
"''",
".",
"join",
"(",
"random",
".",
"choice",
"(",
"CHARACTERS",
")",
"for",
"_",
"in",
"range",
"(",
"len",
"(",
"value",
")",
")",
")"
] | Random string of same length as the given value. | [
"Random",
"string",
"of",
"same",
"length",
"as",
"the",
"given",
"value",
"."
] | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/sanitizers/string.py#L25-L31 | train |
andersinno/python-database-sanitizer | database_sanitizer/dump/mysql.py | sanitize | def sanitize(url, config):
"""
Obtains dump of MySQL database by executing `mysqldump` command and
sanitizes it output.
:param url: URL to the database which is going to be sanitized, parsed by
Python's URL parser.
:type url: urllib.urlparse.ParseResult
:param config: Optional ... | python | def sanitize(url, config):
"""
Obtains dump of MySQL database by executing `mysqldump` command and
sanitizes it output.
:param url: URL to the database which is going to be sanitized, parsed by
Python's URL parser.
:type url: urllib.urlparse.ParseResult
:param config: Optional ... | [
"def",
"sanitize",
"(",
"url",
",",
"config",
")",
":",
"if",
"url",
".",
"scheme",
"!=",
"\"mysql\"",
":",
"raise",
"ValueError",
"(",
"\"Unsupported database type: '%s'\"",
"%",
"(",
"url",
".",
"scheme",
",",
")",
")",
"args",
",",
"env",
"=",
"get_my... | Obtains dump of MySQL database by executing `mysqldump` command and
sanitizes it output.
:param url: URL to the database which is going to be sanitized, parsed by
Python's URL parser.
:type url: urllib.urlparse.ParseResult
:param config: Optional sanitizer configuration to be used for ... | [
"Obtains",
"dump",
"of",
"MySQL",
"database",
"by",
"executing",
"mysqldump",
"command",
"and",
"sanitizes",
"it",
"output",
"."
] | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/dump/mysql.py#L42-L66 | train |
andersinno/python-database-sanitizer | database_sanitizer/dump/mysql.py | sanitize_from_stream | def sanitize_from_stream(stream, config):
"""
Reads dump of MySQL database from given stream and sanitizes it.
:param stream: Stream where the database dump is expected to be available
from, such as stdout of `mysqldump` process.
:type stream: file
:param config: Optional saniti... | python | def sanitize_from_stream(stream, config):
"""
Reads dump of MySQL database from given stream and sanitizes it.
:param stream: Stream where the database dump is expected to be available
from, such as stdout of `mysqldump` process.
:type stream: file
:param config: Optional saniti... | [
"def",
"sanitize_from_stream",
"(",
"stream",
",",
"config",
")",
":",
"for",
"line",
"in",
"io",
".",
"TextIOWrapper",
"(",
"stream",
",",
"encoding",
"=",
"\"utf-8\"",
")",
":",
"line",
"=",
"line",
".",
"rstrip",
"(",
"\"\\n\"",
")",
"if",
"not",
"c... | Reads dump of MySQL database from given stream and sanitizes it.
:param stream: Stream where the database dump is expected to be available
from, such as stdout of `mysqldump` process.
:type stream: file
:param config: Optional sanitizer configuration to be used for sanitation
... | [
"Reads",
"dump",
"of",
"MySQL",
"database",
"from",
"given",
"stream",
"and",
"sanitizes",
"it",
"."
] | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/dump/mysql.py#L69-L139 | train |
andersinno/python-database-sanitizer | database_sanitizer/dump/mysql.py | parse_column_names | def parse_column_names(text):
"""
Extracts column names from a string containing quoted and comma separated
column names of a table.
:param text: Line extracted from MySQL's `INSERT INTO` statement containing
quoted and comma separated column names.
:type text: str
:return: Tu... | python | def parse_column_names(text):
"""
Extracts column names from a string containing quoted and comma separated
column names of a table.
:param text: Line extracted from MySQL's `INSERT INTO` statement containing
quoted and comma separated column names.
:type text: str
:return: Tu... | [
"def",
"parse_column_names",
"(",
"text",
")",
":",
"return",
"tuple",
"(",
"re",
".",
"sub",
"(",
"r\"^`(.*)`$\"",
",",
"r\"\\1\"",
",",
"column_data",
".",
"strip",
"(",
")",
")",
"for",
"column_data",
"in",
"text",
".",
"split",
"(",
"\",\"",
")",
"... | Extracts column names from a string containing quoted and comma separated
column names of a table.
:param text: Line extracted from MySQL's `INSERT INTO` statement containing
quoted and comma separated column names.
:type text: str
:return: Tuple containing just the column names.
... | [
"Extracts",
"column",
"names",
"from",
"a",
"string",
"containing",
"quoted",
"and",
"comma",
"separated",
"column",
"names",
"of",
"a",
"table",
"."
] | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/dump/mysql.py#L142-L157 | train |
andersinno/python-database-sanitizer | database_sanitizer/dump/mysql.py | parse_values | def parse_values(text):
"""
Parses values from a string containing values from extended format `INSERT
INTO` statement. Values will be yielded from the function as tuples, with
one tuple per row in the table.
:param text: Text extracted from MySQL's `INSERT INTO` statement containing
... | python | def parse_values(text):
"""
Parses values from a string containing values from extended format `INSERT
INTO` statement. Values will be yielded from the function as tuples, with
one tuple per row in the table.
:param text: Text extracted from MySQL's `INSERT INTO` statement containing
... | [
"def",
"parse_values",
"(",
"text",
")",
":",
"assert",
"text",
".",
"startswith",
"(",
"\"(\"",
")",
"pos",
"=",
"1",
"values",
"=",
"[",
"]",
"text_len",
"=",
"len",
"(",
"text",
")",
"while",
"pos",
"<",
"text_len",
":",
"match",
"=",
"VALUE_PATTE... | Parses values from a string containing values from extended format `INSERT
INTO` statement. Values will be yielded from the function as tuples, with
one tuple per row in the table.
:param text: Text extracted from MySQL's `INSERT INTO` statement containing
quoted and comma separated column... | [
"Parses",
"values",
"from",
"a",
"string",
"containing",
"values",
"from",
"extended",
"format",
"INSERT",
"INTO",
"statement",
".",
"Values",
"will",
"be",
"yielded",
"from",
"the",
"function",
"as",
"tuples",
"with",
"one",
"tuple",
"per",
"row",
"in",
"th... | 742bc1f43526b60f322a48f18c900f94fd446ed4 | https://github.com/andersinno/python-database-sanitizer/blob/742bc1f43526b60f322a48f18c900f94fd446ed4/database_sanitizer/dump/mysql.py#L160-L185 | train |
fridiculous/estimators | estimators/database.py | HashableFileMixin.persist | def persist(self):
"""a private method that persists an object to the filesystem"""
if self.hash:
with open(self.file_name, 'wb') as f:
pickle.dump(self.object_property, f)
return True
return False | python | def persist(self):
"""a private method that persists an object to the filesystem"""
if self.hash:
with open(self.file_name, 'wb') as f:
pickle.dump(self.object_property, f)
return True
return False | [
"def",
"persist",
"(",
"self",
")",
":",
"if",
"self",
".",
"hash",
":",
"with",
"open",
"(",
"self",
".",
"file_name",
",",
"'wb'",
")",
"as",
"f",
":",
"pickle",
".",
"dump",
"(",
"self",
".",
"object_property",
",",
"f",
")",
"return",
"True",
... | a private method that persists an object to the filesystem | [
"a",
"private",
"method",
"that",
"persists",
"an",
"object",
"to",
"the",
"filesystem"
] | ab5b3d70f16f8372ae1114ac7e54e7791631eb74 | https://github.com/fridiculous/estimators/blob/ab5b3d70f16f8372ae1114ac7e54e7791631eb74/estimators/database.py#L121-L127 | train |
fridiculous/estimators | estimators/database.py | HashableFileMixin.load | def load(self):
"""a private method that loads an object from the filesystem"""
if self.is_persisted:
with open(self.file_name, 'rb') as f:
self.object_property = pickle.load(f) | python | def load(self):
"""a private method that loads an object from the filesystem"""
if self.is_persisted:
with open(self.file_name, 'rb') as f:
self.object_property = pickle.load(f) | [
"def",
"load",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_persisted",
":",
"with",
"open",
"(",
"self",
".",
"file_name",
",",
"'rb'",
")",
"as",
"f",
":",
"self",
".",
"object_property",
"=",
"pickle",
".",
"load",
"(",
"f",
")"
] | a private method that loads an object from the filesystem | [
"a",
"private",
"method",
"that",
"loads",
"an",
"object",
"from",
"the",
"filesystem"
] | ab5b3d70f16f8372ae1114ac7e54e7791631eb74 | https://github.com/fridiculous/estimators/blob/ab5b3d70f16f8372ae1114ac7e54e7791631eb74/estimators/database.py#L129-L133 | train |
lionheart/django-pyodbc | django_pyodbc/operations.py | DatabaseOperations._switch_tz_offset_sql | def _switch_tz_offset_sql(self, field_name, tzname):
"""
Returns the SQL that will convert field_name to UTC from tzname.
"""
field_name = self.quote_name(field_name)
if settings.USE_TZ:
if pytz is None:
from django.core.exceptions import ImproperlyCon... | python | def _switch_tz_offset_sql(self, field_name, tzname):
"""
Returns the SQL that will convert field_name to UTC from tzname.
"""
field_name = self.quote_name(field_name)
if settings.USE_TZ:
if pytz is None:
from django.core.exceptions import ImproperlyCon... | [
"def",
"_switch_tz_offset_sql",
"(",
"self",
",",
"field_name",
",",
"tzname",
")",
":",
"field_name",
"=",
"self",
".",
"quote_name",
"(",
"field_name",
")",
"if",
"settings",
".",
"USE_TZ",
":",
"if",
"pytz",
"is",
"None",
":",
"from",
"django",
".",
"... | Returns the SQL that will convert field_name to UTC from tzname. | [
"Returns",
"the",
"SQL",
"that",
"will",
"convert",
"field_name",
"to",
"UTC",
"from",
"tzname",
"."
] | 46adda7b0bfabfa2640f72592c6f6f407f78b363 | https://github.com/lionheart/django-pyodbc/blob/46adda7b0bfabfa2640f72592c6f6f407f78b363/django_pyodbc/operations.py#L171-L194 | train |
lionheart/django-pyodbc | django_pyodbc/operations.py | DatabaseOperations.datetime_trunc_sql | def datetime_trunc_sql(self, lookup_type, field_name, tzname):
"""
Given a lookup_type of 'year', 'month', 'day', 'hour', 'minute' or
'second', returns the SQL that truncates the given datetime field
field_name to a datetime object with only the given specificity, and
a tuple of ... | python | def datetime_trunc_sql(self, lookup_type, field_name, tzname):
"""
Given a lookup_type of 'year', 'month', 'day', 'hour', 'minute' or
'second', returns the SQL that truncates the given datetime field
field_name to a datetime object with only the given specificity, and
a tuple of ... | [
"def",
"datetime_trunc_sql",
"(",
"self",
",",
"lookup_type",
",",
"field_name",
",",
"tzname",
")",
":",
"field_name",
"=",
"self",
".",
"_switch_tz_offset_sql",
"(",
"field_name",
",",
"tzname",
")",
"reference_date",
"=",
"'0'",
"if",
"lookup_type",
"in",
"... | Given a lookup_type of 'year', 'month', 'day', 'hour', 'minute' or
'second', returns the SQL that truncates the given datetime field
field_name to a datetime object with only the given specificity, and
a tuple of parameters. | [
"Given",
"a",
"lookup_type",
"of",
"year",
"month",
"day",
"hour",
"minute",
"or",
"second",
"returns",
"the",
"SQL",
"that",
"truncates",
"the",
"given",
"datetime",
"field",
"field_name",
"to",
"a",
"datetime",
"object",
"with",
"only",
"the",
"given",
"sp... | 46adda7b0bfabfa2640f72592c6f6f407f78b363 | https://github.com/lionheart/django-pyodbc/blob/46adda7b0bfabfa2640f72592c6f6f407f78b363/django_pyodbc/operations.py#L196-L217 | train |
lionheart/django-pyodbc | django_pyodbc/operations.py | DatabaseOperations.last_insert_id | def last_insert_id(self, cursor, table_name, pk_name):
"""
Given a cursor object that has just performed an INSERT statement into
a table that has an auto-incrementing ID, returns the newly created ID.
This method also receives the table name and the name of the primary-key
colu... | python | def last_insert_id(self, cursor, table_name, pk_name):
"""
Given a cursor object that has just performed an INSERT statement into
a table that has an auto-incrementing ID, returns the newly created ID.
This method also receives the table name and the name of the primary-key
colu... | [
"def",
"last_insert_id",
"(",
"self",
",",
"cursor",
",",
"table_name",
",",
"pk_name",
")",
":",
"table_name",
"=",
"self",
".",
"quote_name",
"(",
"table_name",
")",
"cursor",
".",
"execute",
"(",
"\"SELECT CAST(IDENT_CURRENT(%s) as bigint)\"",
",",
"[",
"tabl... | Given a cursor object that has just performed an INSERT statement into
a table that has an auto-incrementing ID, returns the newly created ID.
This method also receives the table name and the name of the primary-key
column. | [
"Given",
"a",
"cursor",
"object",
"that",
"has",
"just",
"performed",
"an",
"INSERT",
"statement",
"into",
"a",
"table",
"that",
"has",
"an",
"auto",
"-",
"incrementing",
"ID",
"returns",
"the",
"newly",
"created",
"ID",
"."
] | 46adda7b0bfabfa2640f72592c6f6f407f78b363 | https://github.com/lionheart/django-pyodbc/blob/46adda7b0bfabfa2640f72592c6f6f407f78b363/django_pyodbc/operations.py#L240-L265 | train |
lionheart/django-pyodbc | django_pyodbc/operations.py | DatabaseOperations.quote_name | def quote_name(self, name):
"""
Returns a quoted version of the given table, index or column name. Does
not quote the given name if it's already been quoted.
"""
if name.startswith(self.left_sql_quote) and name.endswith(self.right_sql_quote):
return name # Quoting onc... | python | def quote_name(self, name):
"""
Returns a quoted version of the given table, index or column name. Does
not quote the given name if it's already been quoted.
"""
if name.startswith(self.left_sql_quote) and name.endswith(self.right_sql_quote):
return name # Quoting onc... | [
"def",
"quote_name",
"(",
"self",
",",
"name",
")",
":",
"if",
"name",
".",
"startswith",
"(",
"self",
".",
"left_sql_quote",
")",
"and",
"name",
".",
"endswith",
"(",
"self",
".",
"right_sql_quote",
")",
":",
"return",
"name",
"return",
"'%s%s%s'",
"%",... | Returns a quoted version of the given table, index or column name. Does
not quote the given name if it's already been quoted. | [
"Returns",
"a",
"quoted",
"version",
"of",
"the",
"given",
"table",
"index",
"or",
"column",
"name",
".",
"Does",
"not",
"quote",
"the",
"given",
"name",
"if",
"it",
"s",
"already",
"been",
"quoted",
"."
] | 46adda7b0bfabfa2640f72592c6f6f407f78b363 | https://github.com/lionheart/django-pyodbc/blob/46adda7b0bfabfa2640f72592c6f6f407f78b363/django_pyodbc/operations.py#L283-L290 | train |
lionheart/django-pyodbc | django_pyodbc/operations.py | DatabaseOperations.last_executed_query | def last_executed_query(self, cursor, sql, params):
"""
Returns a string of the query last executed by the given cursor, with
placeholders replaced with actual values.
`sql` is the raw query containing placeholders, and `params` is the
sequence of parameters. These are used by d... | python | def last_executed_query(self, cursor, sql, params):
"""
Returns a string of the query last executed by the given cursor, with
placeholders replaced with actual values.
`sql` is the raw query containing placeholders, and `params` is the
sequence of parameters. These are used by d... | [
"def",
"last_executed_query",
"(",
"self",
",",
"cursor",
",",
"sql",
",",
"params",
")",
":",
"return",
"super",
"(",
"DatabaseOperations",
",",
"self",
")",
".",
"last_executed_query",
"(",
"cursor",
",",
"cursor",
".",
"last_sql",
",",
"cursor",
".",
"l... | Returns a string of the query last executed by the given cursor, with
placeholders replaced with actual values.
`sql` is the raw query containing placeholders, and `params` is the
sequence of parameters. These are used by default, but this method
exists for database backends to provide ... | [
"Returns",
"a",
"string",
"of",
"the",
"query",
"last",
"executed",
"by",
"the",
"given",
"cursor",
"with",
"placeholders",
"replaced",
"with",
"actual",
"values",
"."
] | 46adda7b0bfabfa2640f72592c6f6f407f78b363 | https://github.com/lionheart/django-pyodbc/blob/46adda7b0bfabfa2640f72592c6f6f407f78b363/django_pyodbc/operations.py#L298-L308 | train |
lionheart/django-pyodbc | django_pyodbc/operations.py | DatabaseOperations.adapt_datetimefield_value | def adapt_datetimefield_value(self, value):
"""
Transform a datetime value to an object compatible with what is expected
by the backend driver for datetime columns.
"""
if value is None:
return None
if self.connection._DJANGO_VERSION >= 14 and settings.USE_TZ:... | python | def adapt_datetimefield_value(self, value):
"""
Transform a datetime value to an object compatible with what is expected
by the backend driver for datetime columns.
"""
if value is None:
return None
if self.connection._DJANGO_VERSION >= 14 and settings.USE_TZ:... | [
"def",
"adapt_datetimefield_value",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"is",
"None",
":",
"return",
"None",
"if",
"self",
".",
"connection",
".",
"_DJANGO_VERSION",
">=",
"14",
"and",
"settings",
".",
"USE_TZ",
":",
"if",
"timezone",
".",
... | Transform a datetime value to an object compatible with what is expected
by the backend driver for datetime columns. | [
"Transform",
"a",
"datetime",
"value",
"to",
"an",
"object",
"compatible",
"with",
"what",
"is",
"expected",
"by",
"the",
"backend",
"driver",
"for",
"datetime",
"columns",
"."
] | 46adda7b0bfabfa2640f72592c6f6f407f78b363 | https://github.com/lionheart/django-pyodbc/blob/46adda7b0bfabfa2640f72592c6f6f407f78b363/django_pyodbc/operations.py#L431-L444 | train |
lionheart/django-pyodbc | django_pyodbc/operations.py | DatabaseOperations.adapt_timefield_value | def adapt_timefield_value(self, value):
"""
Transform a time value to an object compatible with what is expected
by the backend driver for time columns.
"""
if value is None:
return None
# SQL Server doesn't support microseconds
if isinstance(value, st... | python | def adapt_timefield_value(self, value):
"""
Transform a time value to an object compatible with what is expected
by the backend driver for time columns.
"""
if value is None:
return None
# SQL Server doesn't support microseconds
if isinstance(value, st... | [
"def",
"adapt_timefield_value",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"is",
"None",
":",
"return",
"None",
"if",
"isinstance",
"(",
"value",
",",
"string_types",
")",
":",
"return",
"datetime",
".",
"datetime",
"(",
"*",
"(",
"time",
".",
... | Transform a time value to an object compatible with what is expected
by the backend driver for time columns. | [
"Transform",
"a",
"time",
"value",
"to",
"an",
"object",
"compatible",
"with",
"what",
"is",
"expected",
"by",
"the",
"backend",
"driver",
"for",
"time",
"columns",
"."
] | 46adda7b0bfabfa2640f72592c6f6f407f78b363 | https://github.com/lionheart/django-pyodbc/blob/46adda7b0bfabfa2640f72592c6f6f407f78b363/django_pyodbc/operations.py#L446-L456 | train |
lionheart/django-pyodbc | django_pyodbc/operations.py | DatabaseOperations.convert_values | def convert_values(self, value, field):
"""
Coerce the value returned by the database backend into a consistent
type that is compatible with the field type.
In our case, cater for the fact that SQL Server < 2008 has no
separate Date and Time data types.
TODO: See how we'... | python | def convert_values(self, value, field):
"""
Coerce the value returned by the database backend into a consistent
type that is compatible with the field type.
In our case, cater for the fact that SQL Server < 2008 has no
separate Date and Time data types.
TODO: See how we'... | [
"def",
"convert_values",
"(",
"self",
",",
"value",
",",
"field",
")",
":",
"if",
"value",
"is",
"None",
":",
"return",
"None",
"if",
"field",
"and",
"field",
".",
"get_internal_type",
"(",
")",
"==",
"'DateTimeField'",
":",
"if",
"isinstance",
"(",
"val... | Coerce the value returned by the database backend into a consistent
type that is compatible with the field type.
In our case, cater for the fact that SQL Server < 2008 has no
separate Date and Time data types.
TODO: See how we'll handle this for SQL Server >= 2008 | [
"Coerce",
"the",
"value",
"returned",
"by",
"the",
"database",
"backend",
"into",
"a",
"consistent",
"type",
"that",
"is",
"compatible",
"with",
"the",
"field",
"type",
"."
] | 46adda7b0bfabfa2640f72592c6f6f407f78b363 | https://github.com/lionheart/django-pyodbc/blob/46adda7b0bfabfa2640f72592c6f6f407f78b363/django_pyodbc/operations.py#L485-L524 | train |
lionheart/django-pyodbc | django_pyodbc/introspection.py | DatabaseIntrospection._is_auto_field | def _is_auto_field(self, cursor, table_name, column_name):
"""
Checks whether column is Identity
"""
# COLUMNPROPERTY: http://msdn2.microsoft.com/en-us/library/ms174968.aspx
#from django.db import connection
#cursor.execute("SELECT COLUMNPROPERTY(OBJECT_ID(%s), %s, 'IsId... | python | def _is_auto_field(self, cursor, table_name, column_name):
"""
Checks whether column is Identity
"""
# COLUMNPROPERTY: http://msdn2.microsoft.com/en-us/library/ms174968.aspx
#from django.db import connection
#cursor.execute("SELECT COLUMNPROPERTY(OBJECT_ID(%s), %s, 'IsId... | [
"def",
"_is_auto_field",
"(",
"self",
",",
"cursor",
",",
"table_name",
",",
"column_name",
")",
":",
"cursor",
".",
"execute",
"(",
"\"SELECT COLUMNPROPERTY(OBJECT_ID(%s), %s, 'IsIdentity')\"",
",",
"(",
"self",
".",
"connection",
".",
"ops",
".",
"quote_name",
"... | Checks whether column is Identity | [
"Checks",
"whether",
"column",
"is",
"Identity"
] | 46adda7b0bfabfa2640f72592c6f6f407f78b363 | https://github.com/lionheart/django-pyodbc/blob/46adda7b0bfabfa2640f72592c6f6f407f78b363/django_pyodbc/introspection.py#L99-L110 | train |
lionheart/django-pyodbc | django_pyodbc/introspection.py | DatabaseIntrospection.get_table_description | def get_table_description(self, cursor, table_name, identity_check=True):
"""Returns a description of the table, with DB-API cursor.description interface.
The 'auto_check' parameter has been added to the function argspec.
If set to True, the function will check each of the table's fields for th... | python | def get_table_description(self, cursor, table_name, identity_check=True):
"""Returns a description of the table, with DB-API cursor.description interface.
The 'auto_check' parameter has been added to the function argspec.
If set to True, the function will check each of the table's fields for th... | [
"def",
"get_table_description",
"(",
"self",
",",
"cursor",
",",
"table_name",
",",
"identity_check",
"=",
"True",
")",
":",
"columns",
"=",
"[",
"[",
"c",
"[",
"3",
"]",
",",
"c",
"[",
"4",
"]",
",",
"None",
",",
"c",
"[",
"6",
"]",
",",
"c",
... | Returns a description of the table, with DB-API cursor.description interface.
The 'auto_check' parameter has been added to the function argspec.
If set to True, the function will check each of the table's fields for the
IDENTITY property (the IDENTITY property is the MSSQL equivalent to an Auto... | [
"Returns",
"a",
"description",
"of",
"the",
"table",
"with",
"DB",
"-",
"API",
"cursor",
".",
"description",
"interface",
"."
] | 46adda7b0bfabfa2640f72592c6f6f407f78b363 | https://github.com/lionheart/django-pyodbc/blob/46adda7b0bfabfa2640f72592c6f6f407f78b363/django_pyodbc/introspection.py#L114-L137 | train |
lionheart/django-pyodbc | django_pyodbc/compiler.py | _break | def _break(s, find):
"""Break a string s into the part before the substring to find,
and the part including and after the substring."""
i = s.find(find)
return s[:i], s[i:] | python | def _break(s, find):
"""Break a string s into the part before the substring to find,
and the part including and after the substring."""
i = s.find(find)
return s[:i], s[i:] | [
"def",
"_break",
"(",
"s",
",",
"find",
")",
":",
"i",
"=",
"s",
".",
"find",
"(",
"find",
")",
"return",
"s",
"[",
":",
"i",
"]",
",",
"s",
"[",
"i",
":",
"]"
] | Break a string s into the part before the substring to find,
and the part including and after the substring. | [
"Break",
"a",
"string",
"s",
"into",
"the",
"part",
"before",
"the",
"substring",
"to",
"find",
"and",
"the",
"part",
"including",
"and",
"after",
"the",
"substring",
"."
] | 46adda7b0bfabfa2640f72592c6f6f407f78b363 | https://github.com/lionheart/django-pyodbc/blob/46adda7b0bfabfa2640f72592c6f6f407f78b363/django_pyodbc/compiler.py#L107-L111 | train |
lionheart/django-pyodbc | django_pyodbc/compiler.py | SQLCompiler._fix_aggregates | def _fix_aggregates(self):
"""
MSSQL doesn't match the behavior of the other backends on a few of
the aggregate functions; different return type behavior, different
function names, etc.
MSSQL's implementation of AVG maintains datatype without proding. To
match behavior o... | python | def _fix_aggregates(self):
"""
MSSQL doesn't match the behavior of the other backends on a few of
the aggregate functions; different return type behavior, different
function names, etc.
MSSQL's implementation of AVG maintains datatype without proding. To
match behavior o... | [
"def",
"_fix_aggregates",
"(",
"self",
")",
":",
"try",
":",
"select",
"=",
"self",
".",
"query",
".",
"annotation_select",
"except",
"AttributeError",
":",
"select",
"=",
"self",
".",
"query",
".",
"aggregate_select",
"for",
"alias",
",",
"aggregate",
"in",... | MSSQL doesn't match the behavior of the other backends on a few of
the aggregate functions; different return type behavior, different
function names, etc.
MSSQL's implementation of AVG maintains datatype without proding. To
match behavior of other django backends, it needs to not drop r... | [
"MSSQL",
"doesn",
"t",
"match",
"the",
"behavior",
"of",
"the",
"other",
"backends",
"on",
"a",
"few",
"of",
"the",
"aggregate",
"functions",
";",
"different",
"return",
"type",
"behavior",
"different",
"function",
"names",
"etc",
"."
] | 46adda7b0bfabfa2640f72592c6f6f407f78b363 | https://github.com/lionheart/django-pyodbc/blob/46adda7b0bfabfa2640f72592c6f6f407f78b363/django_pyodbc/compiler.py#L171-L205 | train |
lionheart/django-pyodbc | django_pyodbc/compiler.py | SQLCompiler._fix_slicing_order | def _fix_slicing_order(self, outer_fields, inner_select, order, inner_table_name):
"""
Apply any necessary fixes to the outer_fields, inner_select, and order
strings due to slicing.
"""
# Using ROW_NUMBER requires an ordering
if order is None:
meta = self.quer... | python | def _fix_slicing_order(self, outer_fields, inner_select, order, inner_table_name):
"""
Apply any necessary fixes to the outer_fields, inner_select, and order
strings due to slicing.
"""
# Using ROW_NUMBER requires an ordering
if order is None:
meta = self.quer... | [
"def",
"_fix_slicing_order",
"(",
"self",
",",
"outer_fields",
",",
"inner_select",
",",
"order",
",",
"inner_table_name",
")",
":",
"if",
"order",
"is",
"None",
":",
"meta",
"=",
"self",
".",
"query",
".",
"get_meta",
"(",
")",
"column",
"=",
"meta",
".... | Apply any necessary fixes to the outer_fields, inner_select, and order
strings due to slicing. | [
"Apply",
"any",
"necessary",
"fixes",
"to",
"the",
"outer_fields",
"inner_select",
"and",
"order",
"strings",
"due",
"to",
"slicing",
"."
] | 46adda7b0bfabfa2640f72592c6f6f407f78b363 | https://github.com/lionheart/django-pyodbc/blob/46adda7b0bfabfa2640f72592c6f6f407f78b363/django_pyodbc/compiler.py#L346-L393 | train |
lionheart/django-pyodbc | django_pyodbc/compiler.py | SQLCompiler._alias_columns | def _alias_columns(self, sql):
"""Return tuple of SELECT and FROM clauses, aliasing duplicate column names."""
qn = self.connection.ops.quote_name
outer = list()
inner = list()
names_seen = list()
# replace all parens with placeholders
paren_depth, paren_buf = 0... | python | def _alias_columns(self, sql):
"""Return tuple of SELECT and FROM clauses, aliasing duplicate column names."""
qn = self.connection.ops.quote_name
outer = list()
inner = list()
names_seen = list()
# replace all parens with placeholders
paren_depth, paren_buf = 0... | [
"def",
"_alias_columns",
"(",
"self",
",",
"sql",
")",
":",
"qn",
"=",
"self",
".",
"connection",
".",
"ops",
".",
"quote_name",
"outer",
"=",
"list",
"(",
")",
"inner",
"=",
"list",
"(",
")",
"names_seen",
"=",
"list",
"(",
")",
"paren_depth",
",",
... | Return tuple of SELECT and FROM clauses, aliasing duplicate column names. | [
"Return",
"tuple",
"of",
"SELECT",
"and",
"FROM",
"clauses",
"aliasing",
"duplicate",
"column",
"names",
"."
] | 46adda7b0bfabfa2640f72592c6f6f407f78b363 | https://github.com/lionheart/django-pyodbc/blob/46adda7b0bfabfa2640f72592c6f6f407f78b363/django_pyodbc/compiler.py#L395-L468 | train |
lionheart/django-pyodbc | django_pyodbc/compiler.py | SQLInsertCompiler._fix_insert | def _fix_insert(self, sql, params):
"""
Wrap the passed SQL with IDENTITY_INSERT statements and apply
other necessary fixes.
"""
meta = self.query.get_meta()
if meta.has_auto_field:
if hasattr(self.query, 'fields'):
# django 1.4 replaced colum... | python | def _fix_insert(self, sql, params):
"""
Wrap the passed SQL with IDENTITY_INSERT statements and apply
other necessary fixes.
"""
meta = self.query.get_meta()
if meta.has_auto_field:
if hasattr(self.query, 'fields'):
# django 1.4 replaced colum... | [
"def",
"_fix_insert",
"(",
"self",
",",
"sql",
",",
"params",
")",
":",
"meta",
"=",
"self",
".",
"query",
".",
"get_meta",
"(",
")",
"if",
"meta",
".",
"has_auto_field",
":",
"if",
"hasattr",
"(",
"self",
".",
"query",
",",
"'fields'",
")",
":",
"... | Wrap the passed SQL with IDENTITY_INSERT statements and apply
other necessary fixes. | [
"Wrap",
"the",
"passed",
"SQL",
"with",
"IDENTITY_INSERT",
"statements",
"and",
"apply",
"other",
"necessary",
"fixes",
"."
] | 46adda7b0bfabfa2640f72592c6f6f407f78b363 | https://github.com/lionheart/django-pyodbc/blob/46adda7b0bfabfa2640f72592c6f6f407f78b363/django_pyodbc/compiler.py#L506-L561 | train |
shmuelamar/cbox | examples/head.py | head | def head(line, n: int):
"""returns the first `n` lines"""
global counter
counter += 1
if counter > n:
raise cbox.Stop() # can also raise StopIteration()
return line | python | def head(line, n: int):
"""returns the first `n` lines"""
global counter
counter += 1
if counter > n:
raise cbox.Stop() # can also raise StopIteration()
return line | [
"def",
"head",
"(",
"line",
",",
"n",
":",
"int",
")",
":",
"global",
"counter",
"counter",
"+=",
"1",
"if",
"counter",
">",
"n",
":",
"raise",
"cbox",
".",
"Stop",
"(",
")",
"return",
"line"
] | returns the first `n` lines | [
"returns",
"the",
"first",
"n",
"lines"
] | 2d0cda5b3f61a55e530251430bf3d460dcd3732e | https://github.com/shmuelamar/cbox/blob/2d0cda5b3f61a55e530251430bf3d460dcd3732e/examples/head.py#L8-L15 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.