Search is not available for this dataset
identifier stringlengths 1 155 | parameters stringlengths 2 6.09k | docstring stringlengths 11 63.4k | docstring_summary stringlengths 0 63.4k | function stringlengths 29 99.8k | function_tokens list | start_point list | end_point list | language stringclasses 1
value | docstring_language stringlengths 2 7 | docstring_language_predictions stringlengths 18 23 | is_langid_reliable stringclasses 2
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
env_func | (f, argtypes) | For getting OGREnvelopes. | For getting OGREnvelopes. | def env_func(f, argtypes):
"For getting OGREnvelopes."
f.argtypes = argtypes
f.restype = None
f.errcheck = check_envelope
return f | [
"def",
"env_func",
"(",
"f",
",",
"argtypes",
")",
":",
"f",
".",
"argtypes",
"=",
"argtypes",
"f",
".",
"restype",
"=",
"None",
"f",
".",
"errcheck",
"=",
"check_envelope",
"return",
"f"
] | [
12,
0
] | [
17,
12
] | python | de | ['de', 'no', 'en'] | False |
pnt_func | (f) | For accessing point information. | For accessing point information. | def pnt_func(f):
"For accessing point information."
return double_output(f, [c_void_p, c_int]) | [
"def",
"pnt_func",
"(",
"f",
")",
":",
"return",
"double_output",
"(",
"f",
",",
"[",
"c_void_p",
",",
"c_int",
"]",
")"
] | [
20,
0
] | [
22,
46
] | python | en | ['en', 'en', 'en'] | True |
topological_sort_as_sets | (dependency_graph) |
Variation of Kahn's algorithm (1962) that returns sets.
Take a dependency graph as a dictionary of node => dependencies.
Yield sets of items in topological order, where the first set contains
all nodes without dependencies, and each following set contains all
nodes that may depend on the nodes on... |
Variation of Kahn's algorithm (1962) that returns sets. | def topological_sort_as_sets(dependency_graph):
"""
Variation of Kahn's algorithm (1962) that returns sets.
Take a dependency graph as a dictionary of node => dependencies.
Yield sets of items in topological order, where the first set contains
all nodes without dependencies, and each following set... | [
"def",
"topological_sort_as_sets",
"(",
"dependency_graph",
")",
":",
"todo",
"=",
"dependency_graph",
".",
"copy",
"(",
")",
"while",
"todo",
":",
"current",
"=",
"{",
"node",
"for",
"node",
",",
"deps",
"in",
"todo",
".",
"items",
"(",
")",
"if",
"not"... | [
4,
0
] | [
26,
52
] | python | en | ['en', 'error', 'th'] | False |
_const_compare_digest_backport | (a, b) |
Compare two digests of equal length in constant time.
The digests must be of type str/bytes.
Returns True if the digests match, and False otherwise.
|
Compare two digests of equal length in constant time. | def _const_compare_digest_backport(a, b):
"""
Compare two digests of equal length in constant time.
The digests must be of type str/bytes.
Returns True if the digests match, and False otherwise.
"""
result = abs(len(a) - len(b))
for l, r in zip(bytearray(a), bytearray(b)):
result |=... | [
"def",
"_const_compare_digest_backport",
"(",
"a",
",",
"b",
")",
":",
"result",
"=",
"abs",
"(",
"len",
"(",
"a",
")",
"-",
"len",
"(",
"b",
")",
")",
"for",
"l",
",",
"r",
"in",
"zip",
"(",
"bytearray",
"(",
"a",
")",
",",
"bytearray",
"(",
"... | [
23,
0
] | [
33,
22
] | python | en | ['en', 'error', 'th'] | False |
assert_fingerprint | (cert, fingerprint) |
Checks if given fingerprint matches the supplied certificate.
:param cert:
Certificate as bytes object.
:param fingerprint:
Fingerprint as string of hexdigits, can be interspersed by colons.
|
Checks if given fingerprint matches the supplied certificate. | def assert_fingerprint(cert, fingerprint):
"""
Checks if given fingerprint matches the supplied certificate.
:param cert:
Certificate as bytes object.
:param fingerprint:
Fingerprint as string of hexdigits, can be interspersed by colons.
"""
fingerprint = fingerprint.replace(":... | [
"def",
"assert_fingerprint",
"(",
"cert",
",",
"fingerprint",
")",
":",
"fingerprint",
"=",
"fingerprint",
".",
"replace",
"(",
"\":\"",
",",
"\"\"",
")",
".",
"lower",
"(",
")",
"digest_length",
"=",
"len",
"(",
"fingerprint",
")",
"hashfunc",
"=",
"HASHF... | [
154,
0
] | [
180,
9
] | python | en | ['en', 'error', 'th'] | False |
resolve_cert_reqs | (candidate) |
Resolves the argument to a numeric constant, which can be passed to
the wrap_socket function/method from the ssl module.
Defaults to :data:`ssl.CERT_REQUIRED`.
If given a string it is assumed to be the name of the constant in the
:mod:`ssl` module or its abbreviation.
(So you can specify `REQUI... |
Resolves the argument to a numeric constant, which can be passed to
the wrap_socket function/method from the ssl module.
Defaults to :data:`ssl.CERT_REQUIRED`.
If given a string it is assumed to be the name of the constant in the
:mod:`ssl` module or its abbreviation.
(So you can specify `REQUI... | def resolve_cert_reqs(candidate):
"""
Resolves the argument to a numeric constant, which can be passed to
the wrap_socket function/method from the ssl module.
Defaults to :data:`ssl.CERT_REQUIRED`.
If given a string it is assumed to be the name of the constant in the
:mod:`ssl` module or its abb... | [
"def",
"resolve_cert_reqs",
"(",
"candidate",
")",
":",
"if",
"candidate",
"is",
"None",
":",
"return",
"CERT_REQUIRED",
"if",
"isinstance",
"(",
"candidate",
",",
"str",
")",
":",
"res",
"=",
"getattr",
"(",
"ssl",
",",
"candidate",
",",
"None",
")",
"i... | [
183,
0
] | [
203,
20
] | python | en | ['en', 'error', 'th'] | False |
resolve_ssl_version | (candidate) |
like resolve_cert_reqs
|
like resolve_cert_reqs
| def resolve_ssl_version(candidate):
"""
like resolve_cert_reqs
"""
if candidate is None:
return PROTOCOL_TLS
if isinstance(candidate, str):
res = getattr(ssl, candidate, None)
if res is None:
res = getattr(ssl, "PROTOCOL_" + candidate)
return res
ret... | [
"def",
"resolve_ssl_version",
"(",
"candidate",
")",
":",
"if",
"candidate",
"is",
"None",
":",
"return",
"PROTOCOL_TLS",
"if",
"isinstance",
"(",
"candidate",
",",
"str",
")",
":",
"res",
"=",
"getattr",
"(",
"ssl",
",",
"candidate",
",",
"None",
")",
"... | [
206,
0
] | [
219,
20
] | python | en | ['en', 'error', 'th'] | False |
create_urllib3_context | (
ssl_version=None, cert_reqs=None, options=None, ciphers=None
) | All arguments have the same meaning as ``ssl_wrap_socket``.
By default, this function does a lot of the same work that
``ssl.create_default_context`` does on Python 3.4+. It:
- Disables SSLv2, SSLv3, and compression
- Sets a restricted set of server ciphers
If you wish to enable SSLv3, you can do... | All arguments have the same meaning as ``ssl_wrap_socket``. | def create_urllib3_context(
ssl_version=None, cert_reqs=None, options=None, ciphers=None
):
"""All arguments have the same meaning as ``ssl_wrap_socket``.
By default, this function does a lot of the same work that
``ssl.create_default_context`` does on Python 3.4+. It:
- Disables SSLv2, SSLv3, and... | [
"def",
"create_urllib3_context",
"(",
"ssl_version",
"=",
"None",
",",
"cert_reqs",
"=",
"None",
",",
"options",
"=",
"None",
",",
"ciphers",
"=",
"None",
")",
":",
"context",
"=",
"SSLContext",
"(",
"ssl_version",
"or",
"PROTOCOL_TLS",
")",
"context",
".",
... | [
222,
0
] | [
295,
18
] | python | en | ['en', 'en', 'en'] | True |
ssl_wrap_socket | (
sock,
keyfile=None,
certfile=None,
cert_reqs=None,
ca_certs=None,
server_hostname=None,
ssl_version=None,
ciphers=None,
ssl_context=None,
ca_cert_dir=None,
key_password=None,
ca_cert_data=None,
) |
All arguments except for server_hostname, ssl_context, and ca_cert_dir have
the same meaning as they do when using :func:`ssl.wrap_socket`.
:param server_hostname:
When SNI is supported, the expected hostname of the certificate
:param ssl_context:
A pre-made :class:`SSLContext` object.... |
All arguments except for server_hostname, ssl_context, and ca_cert_dir have
the same meaning as they do when using :func:`ssl.wrap_socket`. | def ssl_wrap_socket(
sock,
keyfile=None,
certfile=None,
cert_reqs=None,
ca_certs=None,
server_hostname=None,
ssl_version=None,
ciphers=None,
ssl_context=None,
ca_cert_dir=None,
key_password=None,
ca_cert_data=None,
):
"""
All arguments except for server_hostname, ... | [
"def",
"ssl_wrap_socket",
"(",
"sock",
",",
"keyfile",
"=",
"None",
",",
"certfile",
"=",
"None",
",",
"cert_reqs",
"=",
"None",
",",
"ca_certs",
"=",
"None",
",",
"server_hostname",
"=",
"None",
",",
"ssl_version",
"=",
"None",
",",
"ciphers",
"=",
"Non... | [
298,
0
] | [
389,
36
] | python | en | ['en', 'error', 'th'] | False |
is_ipaddress | (hostname) | Detects whether the hostname given is an IPv4 or IPv6 address.
Also detects IPv6 addresses with Zone IDs.
:param str hostname: Hostname to examine.
:return: True if the hostname is an IP address, False otherwise.
| Detects whether the hostname given is an IPv4 or IPv6 address.
Also detects IPv6 addresses with Zone IDs. | def is_ipaddress(hostname):
"""Detects whether the hostname given is an IPv4 or IPv6 address.
Also detects IPv6 addresses with Zone IDs.
:param str hostname: Hostname to examine.
:return: True if the hostname is an IP address, False otherwise.
"""
if not six.PY2 and isinstance(hostname, bytes):... | [
"def",
"is_ipaddress",
"(",
"hostname",
")",
":",
"if",
"not",
"six",
".",
"PY2",
"and",
"isinstance",
"(",
"hostname",
",",
"bytes",
")",
":",
"# IDN A-label bytes are ASCII compatible.",
"hostname",
"=",
"hostname",
".",
"decode",
"(",
"\"ascii\"",
")",
"ret... | [
392,
0
] | [
402,
83
] | python | en | ['en', 'en', 'en'] | True |
_is_key_file_encrypted | (key_file) | Detects if a key file is encrypted or not. | Detects if a key file is encrypted or not. | def _is_key_file_encrypted(key_file):
"""Detects if a key file is encrypted or not."""
with open(key_file, "r") as f:
for line in f:
# Look for Proc-Type: 4,ENCRYPTED
if "ENCRYPTED" in line:
return True
return False | [
"def",
"_is_key_file_encrypted",
"(",
"key_file",
")",
":",
"with",
"open",
"(",
"key_file",
",",
"\"r\"",
")",
"as",
"f",
":",
"for",
"line",
"in",
"f",
":",
"# Look for Proc-Type: 4,ENCRYPTED",
"if",
"\"ENCRYPTED\"",
"in",
"line",
":",
"return",
"True",
"r... | [
405,
0
] | [
413,
16
] | python | en | ['en', 'en', 'en'] | True |
parse | (sql, encoding=None) | Parse sql and return a list of statements.
:param sql: A string containing one or more SQL statements.
:param encoding: The encoding of the statement (optional).
:returns: A tuple of :class:`~sqlparse.sql.Statement` instances.
| Parse sql and return a list of statements. | def parse(sql, encoding=None):
"""Parse sql and return a list of statements.
:param sql: A string containing one or more SQL statements.
:param encoding: The encoding of the statement (optional).
:returns: A tuple of :class:`~sqlparse.sql.Statement` instances.
"""
return tuple(parsestream(sql, ... | [
"def",
"parse",
"(",
"sql",
",",
"encoding",
"=",
"None",
")",
":",
"return",
"tuple",
"(",
"parsestream",
"(",
"sql",
",",
"encoding",
")",
")"
] | [
24,
0
] | [
31,
44
] | python | en | ['en', 'en', 'en'] | True |
parsestream | (stream, encoding=None) | Parses sql statements from file-like object.
:param stream: A file-like object.
:param encoding: The encoding of the stream contents (optional).
:returns: A generator of :class:`~sqlparse.sql.Statement` instances.
| Parses sql statements from file-like object. | def parsestream(stream, encoding=None):
"""Parses sql statements from file-like object.
:param stream: A file-like object.
:param encoding: The encoding of the stream contents (optional).
:returns: A generator of :class:`~sqlparse.sql.Statement` instances.
"""
stack = engine.FilterStack()
s... | [
"def",
"parsestream",
"(",
"stream",
",",
"encoding",
"=",
"None",
")",
":",
"stack",
"=",
"engine",
".",
"FilterStack",
"(",
")",
"stack",
".",
"enable_grouping",
"(",
")",
"return",
"stack",
".",
"run",
"(",
"stream",
",",
"encoding",
")"
] | [
34,
0
] | [
43,
38
] | python | en | ['en', 'en', 'en'] | True |
format | (sql, encoding=None, **options) | Format *sql* according to *options*.
Available options are documented in :ref:`formatting`.
In addition to the formatting options this function accepts the
keyword "encoding" which determines the encoding of the statement.
:returns: The formatted SQL statement as string.
| Format *sql* according to *options*. | def format(sql, encoding=None, **options):
"""Format *sql* according to *options*.
Available options are documented in :ref:`formatting`.
In addition to the formatting options this function accepts the
keyword "encoding" which determines the encoding of the statement.
:returns: The formatted SQL ... | [
"def",
"format",
"(",
"sql",
",",
"encoding",
"=",
"None",
",",
"*",
"*",
"options",
")",
":",
"stack",
"=",
"engine",
".",
"FilterStack",
"(",
")",
"options",
"=",
"formatter",
".",
"validate_options",
"(",
"options",
")",
"stack",
"=",
"formatter",
"... | [
46,
0
] | [
60,
45
] | python | en | ['en', 'en', 'en'] | True |
split | (sql, encoding=None) | Split *sql* into single statements.
:param sql: A string containing one or more SQL statements.
:param encoding: The encoding of the statement (optional).
:returns: A list of strings.
| Split *sql* into single statements. | def split(sql, encoding=None):
"""Split *sql* into single statements.
:param sql: A string containing one or more SQL statements.
:param encoding: The encoding of the statement (optional).
:returns: A list of strings.
"""
stack = engine.FilterStack()
return [text_type(stmt).strip() for stmt... | [
"def",
"split",
"(",
"sql",
",",
"encoding",
"=",
"None",
")",
":",
"stack",
"=",
"engine",
".",
"FilterStack",
"(",
")",
"return",
"[",
"text_type",
"(",
"stmt",
")",
".",
"strip",
"(",
")",
"for",
"stmt",
"in",
"stack",
".",
"run",
"(",
"sql",
... | [
63,
0
] | [
71,
73
] | python | en | ['it', 'sl', 'en'] | False |
TestUtilsHashPass.test_unspecified_password | (self) |
Makes sure specifying no plain password with a valid encoded password
returns `False`.
|
Makes sure specifying no plain password with a valid encoded password
returns `False`.
| def test_unspecified_password(self):
"""
Makes sure specifying no plain password with a valid encoded password
returns `False`.
"""
self.assertFalse(check_password(None, make_password('lètmein'))) | [
"def",
"test_unspecified_password",
"(",
"self",
")",
":",
"self",
".",
"assertFalse",
"(",
"check_password",
"(",
"None",
",",
"make_password",
"(",
"'lètmein')",
")",
")",
""
] | [
193,
4
] | [
198,
73
] | python | en | ['en', 'error', 'th'] | False |
_InstallRequirementBackedCandidate.name | (self) | The normalised name of the project the candidate refers to | The normalised name of the project the candidate refers to | def name(self):
# type: () -> str
"""The normalised name of the project the candidate refers to"""
if self._name is None:
self._name = canonicalize_name(self.dist.project_name)
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"# type: () -> str",
"if",
"self",
".",
"_name",
"is",
"None",
":",
"self",
".",
"_name",
"=",
"canonicalize_name",
"(",
"self",
".",
"dist",
".",
"project_name",
")",
"return",
"self",
".",
"_name"
] | [
131,
4
] | [
136,
25
] | python | en | ['en', 'en', 'en'] | True |
ExtrasCandidate.name | (self) | The normalised name of the project the candidate refers to | The normalised name of the project the candidate refers to | def name(self):
# type: () -> str
"""The normalised name of the project the candidate refers to"""
return format_name(self.base.name, self.extras) | [
"def",
"name",
"(",
"self",
")",
":",
"# type: () -> str",
"return",
"format_name",
"(",
"self",
".",
"base",
".",
"name",
",",
"self",
".",
"extras",
")"
] | [
376,
4
] | [
379,
55
] | python | en | ['en', 'en', 'en'] | True |
Util.fileExists | (path) | determines if a file exists
Arguments:
path -- path to file on disk
Returns:
bool
| determines if a file exists | def fileExists(path):
"""determines if a file exists
Arguments:
path -- path to file on disk
Returns:
bool
"""
return os.path.isfile(path) | [
"def",
"fileExists",
"(",
"path",
")",
":",
"return",
"os",
".",
"path",
".",
"isfile",
"(",
"path",
")"
] | [
20,
4
] | [
30,
35
] | python | en | ['en', 'en', 'en'] | True |
Util.isDir | (path) | determines if a path is a directory
Arguments:
path -- path on disk
Returns:
bool
| determines if a path is a directory | def isDir(path):
"""determines if a path is a directory
Arguments:
path -- path on disk
Returns:
bool
"""
return os.path.isdir(path) | [
"def",
"isDir",
"(",
"path",
")",
":",
"return",
"os",
".",
"path",
".",
"isdir",
"(",
"path",
")"
] | [
33,
4
] | [
43,
34
] | python | en | ['en', 'en', 'en'] | True |
Util.dump | (obj) | displays an object as a string for debugging
Arguments:
obj -- object
Returns:
string
| displays an object as a string for debugging | def dump(obj):
"""displays an object as a string for debugging
Arguments:
obj -- object
Returns:
string
"""
for attr in dir(obj):
print "obj.%s = %s" % (attr, getattr(obj, attr)) | [
"def",
"dump",
"(",
"obj",
")",
":",
"for",
"attr",
"in",
"dir",
"(",
"obj",
")",
":",
"print",
"\"obj.%s = %s\"",
"%",
"(",
"attr",
",",
"getattr",
"(",
"obj",
",",
"attr",
")",
")"
] | [
55,
4
] | [
66,
60
] | python | en | ['en', 'en', 'en'] | True |
Util.getExtension | (path) | gets the extension from a file
Arguments:
path -- string of the file name
Returns:
string
| gets the extension from a file | def getExtension(path):
"""gets the extension from a file
Arguments:
path -- string of the file name
Returns:
string
"""
return path.split(".").pop() | [
"def",
"getExtension",
"(",
"path",
")",
":",
"return",
"path",
".",
"split",
"(",
"\".\"",
")",
".",
"pop",
"(",
")"
] | [
69,
4
] | [
79,
36
] | python | en | ['en', 'en', 'en'] | True |
Util.getBasePath | (path) | gets the base directory one level up from the current path
Arguments:
path -- path to file or directory
Returns:
string
| gets the base directory one level up from the current path | def getBasePath(path):
"""gets the base directory one level up from the current path
Arguments:
path -- path to file or directory
Returns:
string
"""
bits = path.split("/")
last_bit = bits.pop()
return "/".join(bits) | [
"def",
"getBasePath",
"(",
"path",
")",
":",
"bits",
"=",
"path",
".",
"split",
"(",
"\"/\"",
")",
"last_bit",
"=",
"bits",
".",
"pop",
"(",
")",
"return",
"\"/\"",
".",
"join",
"(",
"bits",
")"
] | [
87,
4
] | [
99,
29
] | python | en | ['en', 'en', 'en'] | True |
Util.unlink | (path) | deletes a file on disk
Arguments:
path -- path to file on disk
Returns:
void
| deletes a file on disk | def unlink(path):
"""deletes a file on disk
Arguments:
path -- path to file on disk
Returns:
void
"""
if Util.fileExists(path):
os.unlink(path) | [
"def",
"unlink",
"(",
"path",
")",
":",
"if",
"Util",
".",
"fileExists",
"(",
"path",
")",
":",
"os",
".",
"unlink",
"(",
"path",
")"
] | [
107,
4
] | [
118,
27
] | python | en | ['en', 'en', 'pt'] | True |
Util.unlinkDir | (path) | removes an entire directory on disk
Arguments:
path -- path to directory to remove
Returns:
void
| removes an entire directory on disk | def unlinkDir(path):
"""removes an entire directory on disk
Arguments:
path -- path to directory to remove
Returns:
void
"""
try:
shutil.rmtree(path)
except:
pass | [
"def",
"unlinkDir",
"(",
"path",
")",
":",
"try",
":",
"shutil",
".",
"rmtree",
"(",
"path",
")",
"except",
":",
"pass"
] | [
121,
4
] | [
134,
16
] | python | en | ['en', 'en', 'en'] | True |
Util.fileGetContents | (path) | gets the contents of a file
Arguments:
path -- path to file on disk
Returns:
string
| gets the contents of a file | def fileGetContents(path):
"""gets the contents of a file
Arguments:
path -- path to file on disk
Returns:
string
"""
if not Util.fileExists(path):
print "file does not exist at path " + path
print "skipping"
file = open(path, "r... | [
"def",
"fileGetContents",
"(",
"path",
")",
":",
"if",
"not",
"Util",
".",
"fileExists",
"(",
"path",
")",
":",
"print",
"\"file does not exist at path \"",
"+",
"path",
"print",
"\"skipping\"",
"file",
"=",
"open",
"(",
"path",
",",
"\"r\"",
")",
"contents"... | [
137,
4
] | [
153,
23
] | python | en | ['en', 'en', 'en'] | True |
Util.filePutContents | (path, contents) | puts contents into a file
Arguments:
path -- path to file to write to
contents -- contents to put into file
Returns:
void
| puts contents into a file | def filePutContents(path, contents):
"""puts contents into a file
Arguments:
path -- path to file to write to
contents -- contents to put into file
Returns:
void
"""
file = open(path, "w")
file.write(contents)
file.close() | [
"def",
"filePutContents",
"(",
"path",
",",
"contents",
")",
":",
"file",
"=",
"open",
"(",
"path",
",",
"\"w\"",
")",
"file",
".",
"write",
"(",
"contents",
")",
"file",
".",
"close",
"(",
")"
] | [
156,
4
] | [
169,
20
] | python | en | ['en', 'en', 'en'] | True |
Util.keyInTupleList | (key, tuple_list) | checks a list of tuples for the given key | checks a list of tuples for the given key | def keyInTupleList(key, tuple_list):
"""checks a list of tuples for the given key"""
for tuple in tuple_list:
if tuple[0] == key:
return True
return False | [
"def",
"keyInTupleList",
"(",
"key",
",",
"tuple_list",
")",
":",
"for",
"tuple",
"in",
"tuple_list",
":",
"if",
"tuple",
"[",
"0",
"]",
"==",
"key",
":",
"return",
"True",
"return",
"False"
] | [
172,
4
] | [
177,
20
] | python | en | ['en', 'en', 'en'] | True |
xframe_options_deny | (view_func) |
Modify a view function so its response has the X-Frame-Options HTTP
header set to 'DENY' as long as the response doesn't already have that
header set. Usage:
@xframe_options_deny
def some_view(request):
...
|
Modify a view function so its response has the X-Frame-Options HTTP
header set to 'DENY' as long as the response doesn't already have that
header set. Usage: | def xframe_options_deny(view_func):
"""
Modify a view function so its response has the X-Frame-Options HTTP
header set to 'DENY' as long as the response doesn't already have that
header set. Usage:
@xframe_options_deny
def some_view(request):
...
"""
def wrapped_view(*args, **kw... | [
"def",
"xframe_options_deny",
"(",
"view_func",
")",
":",
"def",
"wrapped_view",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"resp",
"=",
"view_func",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"if",
"resp",
".",
"get",
"(",
"'X-Frame-O... | [
3,
0
] | [
18,
41
] | python | en | ['en', 'error', 'th'] | False |
xframe_options_sameorigin | (view_func) |
Modify a view function so its response has the X-Frame-Options HTTP
header set to 'SAMEORIGIN' as long as the response doesn't already have
that header set. Usage:
@xframe_options_sameorigin
def some_view(request):
...
|
Modify a view function so its response has the X-Frame-Options HTTP
header set to 'SAMEORIGIN' as long as the response doesn't already have
that header set. Usage: | def xframe_options_sameorigin(view_func):
"""
Modify a view function so its response has the X-Frame-Options HTTP
header set to 'SAMEORIGIN' as long as the response doesn't already have
that header set. Usage:
@xframe_options_sameorigin
def some_view(request):
...
"""
def wrappe... | [
"def",
"xframe_options_sameorigin",
"(",
"view_func",
")",
":",
"def",
"wrapped_view",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"resp",
"=",
"view_func",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"if",
"resp",
".",
"get",
"(",
"'X-F... | [
21,
0
] | [
36,
41
] | python | en | ['en', 'error', 'th'] | False |
xframe_options_exempt | (view_func) |
Modify a view function by setting a response variable that instructs
XFrameOptionsMiddleware to NOT set the X-Frame-Options HTTP header. Usage:
@xframe_options_exempt
def some_view(request):
...
|
Modify a view function by setting a response variable that instructs
XFrameOptionsMiddleware to NOT set the X-Frame-Options HTTP header. Usage: | def xframe_options_exempt(view_func):
"""
Modify a view function by setting a response variable that instructs
XFrameOptionsMiddleware to NOT set the X-Frame-Options HTTP header. Usage:
@xframe_options_exempt
def some_view(request):
...
"""
def wrapped_view(*args, **kwargs):
... | [
"def",
"xframe_options_exempt",
"(",
"view_func",
")",
":",
"def",
"wrapped_view",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"resp",
"=",
"view_func",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"resp",
".",
"xframe_options_exempt",
"=",
... | [
39,
0
] | [
52,
41
] | python | en | ['en', 'error', 'th'] | False |
parse_date | (value) | Parse a string and return a datetime.date.
Raise ValueError if the input is well formatted but not a valid date.
Return None if the input isn't well formatted.
| Parse a string and return a datetime.date. | def parse_date(value):
"""Parse a string and return a datetime.date.
Raise ValueError if the input is well formatted but not a valid date.
Return None if the input isn't well formatted.
"""
match = date_re.match(value)
if match:
kw = {k: int(v) for k, v in match.groupdict().items()}
... | [
"def",
"parse_date",
"(",
"value",
")",
":",
"match",
"=",
"date_re",
".",
"match",
"(",
"value",
")",
"if",
"match",
":",
"kw",
"=",
"{",
"k",
":",
"int",
"(",
"v",
")",
"for",
"k",
",",
"v",
"in",
"match",
".",
"groupdict",
"(",
")",
".",
"... | [
68,
0
] | [
77,
34
] | python | en | ['en', 'en', 'en'] | True |
parse_time | (value) | Parse a string and return a datetime.time.
This function doesn't support time zone offsets.
Raise ValueError if the input is well formatted but not a valid time.
Return None if the input isn't well formatted, in particular if it
contains an offset.
| Parse a string and return a datetime.time. | def parse_time(value):
"""Parse a string and return a datetime.time.
This function doesn't support time zone offsets.
Raise ValueError if the input is well formatted but not a valid time.
Return None if the input isn't well formatted, in particular if it
contains an offset.
"""
match = tim... | [
"def",
"parse_time",
"(",
"value",
")",
":",
"match",
"=",
"time_re",
".",
"match",
"(",
"value",
")",
"if",
"match",
":",
"kw",
"=",
"match",
".",
"groupdict",
"(",
")",
"kw",
"[",
"'microsecond'",
"]",
"=",
"kw",
"[",
"'microsecond'",
"]",
"and",
... | [
80,
0
] | [
94,
34
] | python | en | ['en', 'en', 'en'] | True |
parse_datetime | (value) | Parse a string and return a datetime.datetime.
This function supports time zone offsets. When the input contains one,
the output uses a timezone with a fixed offset from UTC.
Raise ValueError if the input is well formatted but not a valid datetime.
Return None if the input isn't well formatted.
| Parse a string and return a datetime.datetime. | def parse_datetime(value):
"""Parse a string and return a datetime.datetime.
This function supports time zone offsets. When the input contains one,
the output uses a timezone with a fixed offset from UTC.
Raise ValueError if the input is well formatted but not a valid datetime.
Return None if the ... | [
"def",
"parse_datetime",
"(",
"value",
")",
":",
"match",
"=",
"datetime_re",
".",
"match",
"(",
"value",
")",
"if",
"match",
":",
"kw",
"=",
"match",
".",
"groupdict",
"(",
")",
"kw",
"[",
"'microsecond'",
"]",
"=",
"kw",
"[",
"'microsecond'",
"]",
... | [
97,
0
] | [
121,
38
] | python | en | ['en', 'en', 'en'] | True |
parse_duration | (value) | Parse a duration string and return a datetime.timedelta.
The preferred format for durations in Django is '%d %H:%M:%S.%f'.
Also supports ISO 8601 representation and PostgreSQL's day-time interval
format.
| Parse a duration string and return a datetime.timedelta. | def parse_duration(value):
"""Parse a duration string and return a datetime.timedelta.
The preferred format for durations in Django is '%d %H:%M:%S.%f'.
Also supports ISO 8601 representation and PostgreSQL's day-time interval
format.
"""
match = (
standard_duration_re.match(value) or
... | [
"def",
"parse_duration",
"(",
"value",
")",
":",
"match",
"=",
"(",
"standard_duration_re",
".",
"match",
"(",
"value",
")",
"or",
"iso8601_duration_re",
".",
"match",
"(",
"value",
")",
"or",
"postgres_interval_re",
".",
"match",
"(",
"value",
")",
")",
"... | [
124,
0
] | [
146,
53
] | python | en | ['en', 'en', 'en'] | True |
SimpleTimeFormatTests.test_timeField | (self) | TimeFields can parse dates in the default format | TimeFields can parse dates in the default format | def test_timeField(self):
"TimeFields can parse dates in the default format"
f = forms.TimeField()
# Parse a time in an unaccepted format; get an error
self.assertRaises(forms.ValidationError, f.clean, '1:30:05 PM')
# Parse a time in a valid format, get a parsed result
r... | [
"def",
"test_timeField",
"(",
"self",
")",
":",
"f",
"=",
"forms",
".",
"TimeField",
"(",
")",
"# Parse a time in an unaccepted format; get an error",
"self",
".",
"assertRaises",
"(",
"forms",
".",
"ValidationError",
",",
"f",
".",
"clean",
",",
"'1:30:05 PM'",
... | [
207,
4
] | [
227,
42
] | python | en | ['en', 'en', 'en'] | True |
SimpleTimeFormatTests.test_localized_timeField | (self) | Localized TimeFields in a non-localized environment act as unlocalized widgets | Localized TimeFields in a non-localized environment act as unlocalized widgets | def test_localized_timeField(self):
"Localized TimeFields in a non-localized environment act as unlocalized widgets"
f = forms.TimeField()
# Parse a time in an unaccepted format; get an error
self.assertRaises(forms.ValidationError, f.clean, '1:30:05 PM')
# Parse a time in a val... | [
"def",
"test_localized_timeField",
"(",
"self",
")",
":",
"f",
"=",
"forms",
".",
"TimeField",
"(",
")",
"# Parse a time in an unaccepted format; get an error",
"self",
".",
"assertRaises",
"(",
"forms",
".",
"ValidationError",
",",
"f",
".",
"clean",
",",
"'1:30:... | [
229,
4
] | [
249,
42
] | python | en | ['en', 'en', 'en'] | True |
SimpleTimeFormatTests.test_timeField_with_inputformat | (self) | TimeFields with manually specified input formats can accept those formats | TimeFields with manually specified input formats can accept those formats | def test_timeField_with_inputformat(self):
"TimeFields with manually specified input formats can accept those formats"
f = forms.TimeField(input_formats=["%I:%M:%S %p", "%I:%M %p"])
# Parse a time in an unaccepted format; get an error
self.assertRaises(forms.ValidationError, f.clean, '13... | [
"def",
"test_timeField_with_inputformat",
"(",
"self",
")",
":",
"f",
"=",
"forms",
".",
"TimeField",
"(",
"input_formats",
"=",
"[",
"\"%I:%M:%S %p\"",
",",
"\"%I:%M %p\"",
"]",
")",
"# Parse a time in an unaccepted format; get an error",
"self",
".",
"assertRaises",
... | [
251,
4
] | [
271,
42
] | python | en | ['en', 'en', 'en'] | True |
SimpleTimeFormatTests.test_localized_timeField_with_inputformat | (self) | Localized TimeFields with manually specified input formats can accept those formats | Localized TimeFields with manually specified input formats can accept those formats | def test_localized_timeField_with_inputformat(self):
"Localized TimeFields with manually specified input formats can accept those formats"
f = forms.TimeField(input_formats=["%I:%M:%S %p", "%I:%M %p"], localize=True)
# Parse a time in an unaccepted format; get an error
self.assertRaises(... | [
"def",
"test_localized_timeField_with_inputformat",
"(",
"self",
")",
":",
"f",
"=",
"forms",
".",
"TimeField",
"(",
"input_formats",
"=",
"[",
"\"%I:%M:%S %p\"",
",",
"\"%I:%M %p\"",
"]",
",",
"localize",
"=",
"True",
")",
"# Parse a time in an unaccepted format; get... | [
273,
4
] | [
293,
42
] | python | en | ['en', 'en', 'en'] | True |
SimpleDateFormatTests.test_dateField | (self) | DateFields can parse dates in the default format | DateFields can parse dates in the default format | def test_dateField(self):
"DateFields can parse dates in the default format"
f = forms.DateField()
# Parse a date in an unaccepted format; get an error
self.assertRaises(forms.ValidationError, f.clean, '21.12.2010')
# Parse a date in a valid format, get a parsed result
r... | [
"def",
"test_dateField",
"(",
"self",
")",
":",
"f",
"=",
"forms",
".",
"DateField",
"(",
")",
"# Parse a date in an unaccepted format; get an error",
"self",
".",
"assertRaises",
"(",
"forms",
".",
"ValidationError",
",",
"f",
".",
"clean",
",",
"'21.12.2010'",
... | [
494,
4
] | [
514,
44
] | python | en | ['en', 'en', 'en'] | True |
SimpleDateFormatTests.test_localized_dateField | (self) | Localized DateFields in a non-localized environment act as unlocalized widgets | Localized DateFields in a non-localized environment act as unlocalized widgets | def test_localized_dateField(self):
"Localized DateFields in a non-localized environment act as unlocalized widgets"
f = forms.DateField()
# Parse a date in an unaccepted format; get an error
self.assertRaises(forms.ValidationError, f.clean, '21.12.2010')
# Parse a date in a val... | [
"def",
"test_localized_dateField",
"(",
"self",
")",
":",
"f",
"=",
"forms",
".",
"DateField",
"(",
")",
"# Parse a date in an unaccepted format; get an error",
"self",
".",
"assertRaises",
"(",
"forms",
".",
"ValidationError",
",",
"f",
".",
"clean",
",",
"'21.12... | [
516,
4
] | [
536,
44
] | python | en | ['en', 'en', 'en'] | True |
SimpleDateFormatTests.test_dateField_with_inputformat | (self) | DateFields with manually specified input formats can accept those formats | DateFields with manually specified input formats can accept those formats | def test_dateField_with_inputformat(self):
"DateFields with manually specified input formats can accept those formats"
f = forms.DateField(input_formats=["%d.%m.%Y", "%d-%m-%Y"])
# Parse a date in an unaccepted format; get an error
self.assertRaises(forms.ValidationError, f.clean, '2010-... | [
"def",
"test_dateField_with_inputformat",
"(",
"self",
")",
":",
"f",
"=",
"forms",
".",
"DateField",
"(",
"input_formats",
"=",
"[",
"\"%d.%m.%Y\"",
",",
"\"%d-%m-%Y\"",
"]",
")",
"# Parse a date in an unaccepted format; get an error",
"self",
".",
"assertRaises",
"(... | [
538,
4
] | [
558,
44
] | python | en | ['en', 'en', 'en'] | True |
SimpleDateFormatTests.test_localized_dateField_with_inputformat | (self) | Localized DateFields with manually specified input formats can accept those formats | Localized DateFields with manually specified input formats can accept those formats | def test_localized_dateField_with_inputformat(self):
"Localized DateFields with manually specified input formats can accept those formats"
f = forms.DateField(input_formats=["%d.%m.%Y", "%d-%m-%Y"], localize=True)
# Parse a date in an unaccepted format; get an error
self.assertRaises(for... | [
"def",
"test_localized_dateField_with_inputformat",
"(",
"self",
")",
":",
"f",
"=",
"forms",
".",
"DateField",
"(",
"input_formats",
"=",
"[",
"\"%d.%m.%Y\"",
",",
"\"%d-%m-%Y\"",
"]",
",",
"localize",
"=",
"True",
")",
"# Parse a date in an unaccepted format; get an... | [
560,
4
] | [
580,
44
] | python | en | ['en', 'en', 'en'] | True |
SimpleDateTimeFormatTests.test_dateTimeField | (self) | DateTimeFields can parse dates in the default format | DateTimeFields can parse dates in the default format | def test_dateTimeField(self):
"DateTimeFields can parse dates in the default format"
f = forms.DateTimeField()
# Parse a date in an unaccepted format; get an error
self.assertRaises(forms.ValidationError, f.clean, '13:30:05 21.12.2010')
# Parse a date in a valid format, get a pa... | [
"def",
"test_dateTimeField",
"(",
"self",
")",
":",
"f",
"=",
"forms",
".",
"DateTimeField",
"(",
")",
"# Parse a date in an unaccepted format; get an error",
"self",
".",
"assertRaises",
"(",
"forms",
".",
"ValidationError",
",",
"f",
".",
"clean",
",",
"'13:30:0... | [
781,
4
] | [
801,
53
] | python | en | ['en', 'en', 'en'] | True |
SimpleDateTimeFormatTests.test_localized_dateTimeField | (self) | Localized DateTimeFields in a non-localized environment act as unlocalized widgets | Localized DateTimeFields in a non-localized environment act as unlocalized widgets | def test_localized_dateTimeField(self):
"Localized DateTimeFields in a non-localized environment act as unlocalized widgets"
f = forms.DateTimeField()
# Parse a date in an unaccepted format; get an error
self.assertRaises(forms.ValidationError, f.clean, '13:30:05 21.12.2010')
# ... | [
"def",
"test_localized_dateTimeField",
"(",
"self",
")",
":",
"f",
"=",
"forms",
".",
"DateTimeField",
"(",
")",
"# Parse a date in an unaccepted format; get an error",
"self",
".",
"assertRaises",
"(",
"forms",
".",
"ValidationError",
",",
"f",
".",
"clean",
",",
... | [
803,
4
] | [
823,
53
] | python | en | ['en', 'en', 'en'] | True |
SimpleDateTimeFormatTests.test_dateTimeField_with_inputformat | (self) | DateTimeFields with manually specified input formats can accept those formats | DateTimeFields with manually specified input formats can accept those formats | def test_dateTimeField_with_inputformat(self):
"DateTimeFields with manually specified input formats can accept those formats"
f = forms.DateTimeField(input_formats=["%I:%M:%S %p %d.%m.%Y", "%I:%M %p %d-%m-%Y"])
# Parse a date in an unaccepted format; get an error
self.assertRaises(forms... | [
"def",
"test_dateTimeField_with_inputformat",
"(",
"self",
")",
":",
"f",
"=",
"forms",
".",
"DateTimeField",
"(",
"input_formats",
"=",
"[",
"\"%I:%M:%S %p %d.%m.%Y\"",
",",
"\"%I:%M %p %d-%m-%Y\"",
"]",
")",
"# Parse a date in an unaccepted format; get an error",
"self",
... | [
825,
4
] | [
845,
53
] | python | en | ['en', 'en', 'en'] | True |
SimpleDateTimeFormatTests.test_localized_dateTimeField_with_inputformat | (self) | Localized DateTimeFields with manually specified input formats can accept those formats | Localized DateTimeFields with manually specified input formats can accept those formats | def test_localized_dateTimeField_with_inputformat(self):
"Localized DateTimeFields with manually specified input formats can accept those formats"
f = forms.DateTimeField(input_formats=["%I:%M:%S %p %d.%m.%Y", "%I:%M %p %d-%m-%Y"], localize=True)
# Parse a date in an unaccepted format; get an er... | [
"def",
"test_localized_dateTimeField_with_inputformat",
"(",
"self",
")",
":",
"f",
"=",
"forms",
".",
"DateTimeField",
"(",
"input_formats",
"=",
"[",
"\"%I:%M:%S %p %d.%m.%Y\"",
",",
"\"%I:%M %p %d-%m-%Y\"",
"]",
",",
"localize",
"=",
"True",
")",
"# Parse a date in... | [
847,
4
] | [
867,
53
] | python | en | ['en', 'en', 'en'] | True |
WriterTests.test_serialize | (self) |
Tests various different forms of the serializer.
This does not care about formatting, just that the parsed result is
correct, so we always exec() the result and check that.
|
Tests various different forms of the serializer.
This does not care about formatting, just that the parsed result is
correct, so we always exec() the result and check that.
| def test_serialize(self):
"""
Tests various different forms of the serializer.
This does not care about formatting, just that the parsed result is
correct, so we always exec() the result and check that.
"""
# Basic values
self.assertSerializedEqual(1)
self... | [
"def",
"test_serialize",
"(",
"self",
")",
":",
"# Basic values",
"self",
".",
"assertSerializedEqual",
"(",
"1",
")",
"self",
".",
"assertSerializedEqual",
"(",
"None",
")",
"self",
".",
"assertSerializedEqual",
"(",
"b\"foobar\"",
")",
"string",
",",
"imports"... | [
63,
4
] | [
135,
9
] | python | en | ['en', 'error', 'th'] | False |
WriterTests.test_serialize_compiled_regex | (self) |
Make sure compiled regex can be serialized.
|
Make sure compiled regex can be serialized.
| def test_serialize_compiled_regex(self):
"""
Make sure compiled regex can be serialized.
"""
regex = re.compile(r'^\w+$', re.U)
self.assertSerializedEqual(regex) | [
"def",
"test_serialize_compiled_regex",
"(",
"self",
")",
":",
"regex",
"=",
"re",
".",
"compile",
"(",
"r'^\\w+$'",
",",
"re",
".",
"U",
")",
"self",
".",
"assertSerializedEqual",
"(",
"regex",
")"
] | [
137,
4
] | [
142,
41
] | python | en | ['en', 'error', 'th'] | False |
WriterTests.test_serialize_class_based_validators | (self) |
Ticket #22943: Test serialization of class-based validators, including
compiled regexes.
|
Ticket #22943: Test serialization of class-based validators, including
compiled regexes.
| def test_serialize_class_based_validators(self):
"""
Ticket #22943: Test serialization of class-based validators, including
compiled regexes.
"""
validator = RegexValidator(message="hello")
string = MigrationWriter.serialize(validator)[0]
self.assertEqual(string, ... | [
"def",
"test_serialize_class_based_validators",
"(",
"self",
")",
":",
"validator",
"=",
"RegexValidator",
"(",
"message",
"=",
"\"hello\"",
")",
"string",
"=",
"MigrationWriter",
".",
"serialize",
"(",
"validator",
")",
"[",
"0",
"]",
"self",
".",
"assertEqual"... | [
144,
4
] | [
188,
48
] | python | en | ['en', 'error', 'th'] | False |
WriterTests.test_serialize_empty_nonempty_tuple | (self) |
Ticket #22679: makemigrations generates invalid code for (an empty
tuple) default_permissions = ()
|
Ticket #22679: makemigrations generates invalid code for (an empty
tuple) default_permissions = ()
| def test_serialize_empty_nonempty_tuple(self):
"""
Ticket #22679: makemigrations generates invalid code for (an empty
tuple) default_permissions = ()
"""
empty_tuple = ()
one_item_tuple = ('a',)
many_items_tuple = ('a', 'b', 'c')
self.assertSerializedEqual... | [
"def",
"test_serialize_empty_nonempty_tuple",
"(",
"self",
")",
":",
"empty_tuple",
"=",
"(",
")",
"one_item_tuple",
"=",
"(",
"'a'",
",",
")",
"many_items_tuple",
"=",
"(",
"'a'",
",",
"'b'",
",",
"'c'",
")",
"self",
".",
"assertSerializedEqual",
"(",
"empt... | [
190,
4
] | [
200,
52
] | python | en | ['en', 'error', 'th'] | False |
WriterTests.test_serialize_direct_function_reference | (self) |
Ticket #22436: You cannot use a function straight from its body
(e.g. define the method and use it in the same body)
|
Ticket #22436: You cannot use a function straight from its body
(e.g. define the method and use it in the same body)
| def test_serialize_direct_function_reference(self):
"""
Ticket #22436: You cannot use a function straight from its body
(e.g. define the method and use it in the same body)
"""
with self.assertRaises(ValueError):
self.serialize_round_trip(TestModel1.thing) | [
"def",
"test_serialize_direct_function_reference",
"(",
"self",
")",
":",
"with",
"self",
".",
"assertRaises",
"(",
"ValueError",
")",
":",
"self",
".",
"serialize_round_trip",
"(",
"TestModel1",
".",
"thing",
")"
] | [
203,
4
] | [
209,
55
] | python | en | ['en', 'error', 'th'] | False |
WriterTests.test_serialize_local_function_reference | (self) |
Neither py2 or py3 can serialize a reference in a local scope.
|
Neither py2 or py3 can serialize a reference in a local scope.
| def test_serialize_local_function_reference(self):
"""
Neither py2 or py3 can serialize a reference in a local scope.
"""
class TestModel2(object):
def upload_to(self):
return "somewhere dynamic"
thing = models.FileField(upload_to=upload_to)
... | [
"def",
"test_serialize_local_function_reference",
"(",
"self",
")",
":",
"class",
"TestModel2",
"(",
"object",
")",
":",
"def",
"upload_to",
"(",
"self",
")",
":",
"return",
"\"somewhere dynamic\"",
"thing",
"=",
"models",
".",
"FileField",
"(",
"upload_to",
"="... | [
211,
4
] | [
220,
55
] | python | en | ['en', 'error', 'th'] | False |
WriterTests.test_serialize_local_function_reference_message | (self) |
Make sure user is seeing which module/function is the issue
|
Make sure user is seeing which module/function is the issue
| def test_serialize_local_function_reference_message(self):
"""
Make sure user is seeing which module/function is the issue
"""
class TestModel2(object):
def upload_to(self):
return "somewhere dynamic"
thing = models.FileField(upload_to=upload_to)
... | [
"def",
"test_serialize_local_function_reference_message",
"(",
"self",
")",
":",
"class",
"TestModel2",
"(",
"object",
")",
":",
"def",
"upload_to",
"(",
"self",
")",
":",
"return",
"\"somewhere dynamic\"",
"thing",
"=",
"models",
".",
"FileField",
"(",
"upload_to... | [
222,
4
] | [
233,
55
] | python | en | ['en', 'error', 'th'] | False |
WriterTests.test_simple_migration | (self) |
Tests serializing a simple migration.
|
Tests serializing a simple migration.
| def test_simple_migration(self):
"""
Tests serializing a simple migration.
"""
fields = {
'charfield': models.DateTimeField(default=datetime.datetime.utcnow),
'datetimefield': models.DateTimeField(default=datetime.datetime.utcnow),
}
options = {
... | [
"def",
"test_simple_migration",
"(",
"self",
")",
":",
"fields",
"=",
"{",
"'charfield'",
":",
"models",
".",
"DateTimeField",
"(",
"default",
"=",
"datetime",
".",
"datetime",
".",
"utcnow",
")",
",",
"'datetimefield'",
":",
"models",
".",
"DateTimeField",
... | [
235,
4
] | [
277,
17
] | python | en | ['en', 'error', 'th'] | False |
WriterTests.test_serialize_datetime | (self) |
#23365 -- Timezone-aware datetimes should be allowed.
|
#23365 -- Timezone-aware datetimes should be allowed.
| def test_serialize_datetime(self):
"""
#23365 -- Timezone-aware datetimes should be allowed.
"""
# naive datetime
naive_datetime = datetime.datetime(2014, 1, 1, 1, 1)
self.assertEqual(MigrationWriter.serialize_datetime(naive_datetime),
"datetime.d... | [
"def",
"test_serialize_datetime",
"(",
"self",
")",
":",
"# naive datetime",
"naive_datetime",
"=",
"datetime",
".",
"datetime",
"(",
"2014",
",",
"1",
",",
"1",
",",
"1",
",",
"1",
")",
"self",
".",
"assertEqual",
"(",
"MigrationWriter",
".",
"serialize_dat... | [
319,
4
] | [
336,
78
] | python | en | ['en', 'error', 'th'] | False |
popen_wrapper | (args, os_err_exc_type=CommandError) |
Friendly wrapper around Popen.
Returns stdout output, stderr output and OS status code.
|
Friendly wrapper around Popen. | def popen_wrapper(args, os_err_exc_type=CommandError):
"""
Friendly wrapper around Popen.
Returns stdout output, stderr output and OS status code.
"""
try:
p = Popen(args, shell=False, stdout=PIPE, stderr=PIPE,
close_fds=os.name != 'nt', universal_newlines=True)
except O... | [
"def",
"popen_wrapper",
"(",
"args",
",",
"os_err_exc_type",
"=",
"CommandError",
")",
":",
"try",
":",
"p",
"=",
"Popen",
"(",
"args",
",",
"shell",
"=",
"False",
",",
"stdout",
"=",
"PIPE",
",",
"stderr",
"=",
"PIPE",
",",
"close_fds",
"=",
"os",
"... | [
12,
0
] | [
31,
5
] | python | en | ['en', 'error', 'th'] | False |
handle_extensions | (extensions=('html',), ignored=('py',)) |
Organizes multiple extensions that are separated with commas or passed by
using --extension/-e multiple times. Note that the .py extension is ignored
here because of the way non-*.py files are handled in make_messages() (they
are copied to file.ext.py files to trick xgettext to parse them as Python
... |
Organizes multiple extensions that are separated with commas or passed by
using --extension/-e multiple times. Note that the .py extension is ignored
here because of the way non-*.py files are handled in make_messages() (they
are copied to file.ext.py files to trick xgettext to parse them as Python
... | def handle_extensions(extensions=('html',), ignored=('py',)):
"""
Organizes multiple extensions that are separated with commas or passed by
using --extension/-e multiple times. Note that the .py extension is ignored
here because of the way non-*.py files are handled in make_messages() (they
are copi... | [
"def",
"handle_extensions",
"(",
"extensions",
"=",
"(",
"'html'",
",",
")",
",",
"ignored",
"=",
"(",
"'py'",
",",
")",
")",
":",
"ext_list",
"=",
"[",
"]",
"for",
"ext",
"in",
"extensions",
":",
"ext_list",
".",
"extend",
"(",
"ext",
".",
"replace"... | [
34,
0
] | [
56,
66
] | python | en | ['en', 'error', 'th'] | False |
BaseAdapter.send | (self, request, stream=False, timeout=None, verify=True,
cert=None, proxies=None) | Sends PreparedRequest object. Returns Response object.
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
:param stream: (optional) Whether to stream the request content.
:param timeout: (optional) How long to wait for the server to send
data before giving up... | Sends PreparedRequest object. Returns Response object. | def send(self, request, stream=False, timeout=None, verify=True,
cert=None, proxies=None):
"""Sends PreparedRequest object. Returns Response object.
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
:param stream: (optional) Whether to stream the request co... | [
"def",
"send",
"(",
"self",
",",
"request",
",",
"stream",
"=",
"False",
",",
"timeout",
"=",
"None",
",",
"verify",
"=",
"True",
",",
"cert",
"=",
"None",
",",
"proxies",
"=",
"None",
")",
":",
"raise",
"NotImplementedError"
] | [
60,
4
] | [
76,
33
] | python | en | ['en', 'lb', 'en'] | True |
BaseAdapter.close | (self) | Cleans up adapter specific items. | Cleans up adapter specific items. | def close(self):
"""Cleans up adapter specific items."""
raise NotImplementedError | [
"def",
"close",
"(",
"self",
")",
":",
"raise",
"NotImplementedError"
] | [
78,
4
] | [
80,
33
] | python | en | ['en', 'en', 'en'] | True |
HTTPAdapter.init_poolmanager | (self, connections, maxsize, block=DEFAULT_POOLBLOCK, **pool_kwargs) | Initializes a urllib3 PoolManager.
This method should not be called from user code, and is only
exposed for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
:param connections: The number of urllib3 connection pools to cache.
:param maxsize: The ma... | Initializes a urllib3 PoolManager. | def init_poolmanager(self, connections, maxsize, block=DEFAULT_POOLBLOCK, **pool_kwargs):
"""Initializes a urllib3 PoolManager.
This method should not be called from user code, and is only
exposed for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
... | [
"def",
"init_poolmanager",
"(",
"self",
",",
"connections",
",",
"maxsize",
",",
"block",
"=",
"DEFAULT_POOLBLOCK",
",",
"*",
"*",
"pool_kwargs",
")",
":",
"# save these values for pickling",
"self",
".",
"_pool_connections",
"=",
"connections",
"self",
".",
"_poo... | [
145,
4
] | [
163,
79
] | python | en | ['en', 'en', 'it'] | True |
HTTPAdapter.proxy_manager_for | (self, proxy, **proxy_kwargs) | Return urllib3 ProxyManager for the given proxy.
This method should not be called from user code, and is only
exposed for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
:param proxy: The proxy to return a urllib3 ProxyManager for.
:param proxy_kw... | Return urllib3 ProxyManager for the given proxy. | def proxy_manager_for(self, proxy, **proxy_kwargs):
"""Return urllib3 ProxyManager for the given proxy.
This method should not be called from user code, and is only
exposed for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
:param proxy: The prox... | [
"def",
"proxy_manager_for",
"(",
"self",
",",
"proxy",
",",
"*",
"*",
"proxy_kwargs",
")",
":",
"if",
"proxy",
"in",
"self",
".",
"proxy_manager",
":",
"manager",
"=",
"self",
".",
"proxy_manager",
"[",
"proxy",
"]",
"elif",
"proxy",
".",
"lower",
"(",
... | [
165,
4
] | [
200,
22
] | python | en | ['en', 'en', 'en'] | True |
HTTPAdapter.cert_verify | (self, conn, url, verify, cert) | Verify a SSL certificate. This method should not be called from user
code, and is only exposed for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
:param conn: The urllib3 connection object associated with the cert.
:param url: The requested URL.
:... | Verify a SSL certificate. This method should not be called from user
code, and is only exposed for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`. | def cert_verify(self, conn, url, verify, cert):
"""Verify a SSL certificate. This method should not be called from user
code, and is only exposed for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
:param conn: The urllib3 connection object associated with... | [
"def",
"cert_verify",
"(",
"self",
",",
"conn",
",",
"url",
",",
"verify",
",",
"cert",
")",
":",
"if",
"url",
".",
"lower",
"(",
")",
".",
"startswith",
"(",
"'https'",
")",
"and",
"verify",
":",
"cert_loc",
"=",
"None",
"# Allow self-specified cert loc... | [
202,
4
] | [
252,
71
] | python | en | ['en', 'en', 'en'] | True |
HTTPAdapter.build_response | (self, req, resp) | Builds a :class:`Response <requests.Response>` object from a urllib3
response. This should not be called from user code, and is only exposed
for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`
:param req: The :class:`PreparedRequest <PreparedRequest>` used ... | Builds a :class:`Response <requests.Response>` object from a urllib3
response. This should not be called from user code, and is only exposed
for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>` | def build_response(self, req, resp):
"""Builds a :class:`Response <requests.Response>` object from a urllib3
response. This should not be called from user code, and is only exposed
for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`
:param req: The ... | [
"def",
"build_response",
"(",
"self",
",",
"req",
",",
"resp",
")",
":",
"response",
"=",
"Response",
"(",
")",
"# Fallback to None if there's no status_code, for whatever reason.",
"response",
".",
"status_code",
"=",
"getattr",
"(",
"resp",
",",
"'status'",
",",
... | [
254,
4
] | [
289,
23
] | python | en | ['en', 'en', 'en'] | True |
HTTPAdapter.get_connection | (self, url, proxies=None) | Returns a urllib3 connection for the given URL. This should not be
called from user code, and is only exposed for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
:param url: The URL to connect to.
:param proxies: (optional) A Requests-style dictionary of p... | Returns a urllib3 connection for the given URL. This should not be
called from user code, and is only exposed for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`. | def get_connection(self, url, proxies=None):
"""Returns a urllib3 connection for the given URL. This should not be
called from user code, and is only exposed for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
:param url: The URL to connect to.
:pa... | [
"def",
"get_connection",
"(",
"self",
",",
"url",
",",
"proxies",
"=",
"None",
")",
":",
"proxy",
"=",
"select_proxy",
"(",
"url",
",",
"proxies",
")",
"if",
"proxy",
":",
"proxy",
"=",
"prepend_scheme_if_needed",
"(",
"proxy",
",",
"'http'",
")",
"proxy... | [
291,
4
] | [
316,
19
] | python | en | ['en', 'en', 'en'] | True |
HTTPAdapter.close | (self) | Disposes of any internal state.
Currently, this closes the PoolManager and any active ProxyManager,
which closes any pooled connections.
| Disposes of any internal state. | def close(self):
"""Disposes of any internal state.
Currently, this closes the PoolManager and any active ProxyManager,
which closes any pooled connections.
"""
self.poolmanager.clear()
for proxy in self.proxy_manager.values():
proxy.clear() | [
"def",
"close",
"(",
"self",
")",
":",
"self",
".",
"poolmanager",
".",
"clear",
"(",
")",
"for",
"proxy",
"in",
"self",
".",
"proxy_manager",
".",
"values",
"(",
")",
":",
"proxy",
".",
"clear",
"(",
")"
] | [
318,
4
] | [
326,
25
] | python | en | ['en', 'en', 'en'] | True |
HTTPAdapter.request_url | (self, request, proxies) | Obtain the url to use when making the final request.
If the message is being sent through a HTTP proxy, the full URL has to
be used. Otherwise, we should only use the path portion of the URL.
This should not be called from user code, and is only exposed for use
when subclassing the
... | Obtain the url to use when making the final request. | def request_url(self, request, proxies):
"""Obtain the url to use when making the final request.
If the message is being sent through a HTTP proxy, the full URL has to
be used. Otherwise, we should only use the path portion of the URL.
This should not be called from user code, and is o... | [
"def",
"request_url",
"(",
"self",
",",
"request",
",",
"proxies",
")",
":",
"proxy",
"=",
"select_proxy",
"(",
"request",
".",
"url",
",",
"proxies",
")",
"scheme",
"=",
"urlparse",
"(",
"request",
".",
"url",
")",
".",
"scheme",
"is_proxied_http_request"... | [
328,
4
] | [
355,
18
] | python | en | ['en', 'en', 'en'] | True |
HTTPAdapter.add_headers | (self, request, **kwargs) | Add any headers needed by the connection. As of v2.0 this does
nothing by default, but is left for overriding by users that subclass
the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
This should not be called from user code, and is only exposed for use
when subclassing the
... | Add any headers needed by the connection. As of v2.0 this does
nothing by default, but is left for overriding by users that subclass
the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`. | def add_headers(self, request, **kwargs):
"""Add any headers needed by the connection. As of v2.0 this does
nothing by default, but is left for overriding by users that subclass
the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
This should not be called from user code, and is on... | [
"def",
"add_headers",
"(",
"self",
",",
"request",
",",
"*",
"*",
"kwargs",
")",
":",
"pass"
] | [
357,
4
] | [
369,
12
] | python | en | ['en', 'en', 'en'] | True |
HTTPAdapter.proxy_headers | (self, proxy) | Returns a dictionary of the headers to add to any request sent
through a proxy. This works with urllib3 magic to ensure that they are
correctly sent to the proxy, rather than in a tunnelled request if
CONNECT is being used.
This should not be called from user code, and is only exposed f... | Returns a dictionary of the headers to add to any request sent
through a proxy. This works with urllib3 magic to ensure that they are
correctly sent to the proxy, rather than in a tunnelled request if
CONNECT is being used. | def proxy_headers(self, proxy):
"""Returns a dictionary of the headers to add to any request sent
through a proxy. This works with urllib3 magic to ensure that they are
correctly sent to the proxy, rather than in a tunnelled request if
CONNECT is being used.
This should not be c... | [
"def",
"proxy_headers",
"(",
"self",
",",
"proxy",
")",
":",
"headers",
"=",
"{",
"}",
"username",
",",
"password",
"=",
"get_auth_from_url",
"(",
"proxy",
")",
"if",
"username",
":",
"headers",
"[",
"'Proxy-Authorization'",
"]",
"=",
"_basic_auth_str",
"(",... | [
371,
4
] | [
391,
22
] | python | en | ['en', 'en', 'en'] | True |
HTTPAdapter.send | (self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None) | Sends PreparedRequest object. Returns Response object.
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
:param stream: (optional) Whether to stream the request content.
:param timeout: (optional) How long to wait for the server to send
data before giving up... | Sends PreparedRequest object. Returns Response object. | def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None):
"""Sends PreparedRequest object. Returns Response object.
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
:param stream: (optional) Whether to stream the request content.
... | [
"def",
"send",
"(",
"self",
",",
"request",
",",
"stream",
"=",
"False",
",",
"timeout",
"=",
"None",
",",
"verify",
"=",
"True",
",",
"cert",
"=",
"None",
",",
"proxies",
"=",
"None",
")",
":",
"try",
":",
"conn",
"=",
"self",
".",
"get_connection... | [
393,
4
] | [
532,
49
] | python | en | ['en', 'lb', 'en'] | True |
static | (prefix, view=serve, **kwargs) |
Return a URL pattern for serving files in debug mode.
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
Return a URL pattern for serving files in debug mode. | def static(prefix, view=serve, **kwargs):
"""
Return a URL pattern for serving files in debug mode.
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.MEDIA_URL, document_root=sett... | [
"def",
"static",
"(",
"prefix",
",",
"view",
"=",
"serve",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"prefix",
":",
"raise",
"ImproperlyConfigured",
"(",
"\"Empty static prefix not permitted\"",
")",
"elif",
"not",
"settings",
".",
"DEBUG",
"or",
"urls... | [
9,
0
] | [
27,
5
] | python | en | ['en', 'error', 'th'] | False |
intranges_from_list | (list_) | Represent a list of integers as a sequence of ranges:
((start_0, end_0), (start_1, end_1), ...), such that the original
integers are exactly those x such that start_i <= x < end_i for some i.
Ranges are encoded as single integers (start << 32 | end), not as tuples.
| Represent a list of integers as a sequence of ranges:
((start_0, end_0), (start_1, end_1), ...), such that the original
integers are exactly those x such that start_i <= x < end_i for some i. | def intranges_from_list(list_):
"""Represent a list of integers as a sequence of ranges:
((start_0, end_0), (start_1, end_1), ...), such that the original
integers are exactly those x such that start_i <= x < end_i for some i.
Ranges are encoded as single integers (start << 32 | end), not as tuples.
... | [
"def",
"intranges_from_list",
"(",
"list_",
")",
":",
"sorted_list",
"=",
"sorted",
"(",
"list_",
")",
"ranges",
"=",
"[",
"]",
"last_write",
"=",
"-",
"1",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"sorted_list",
")",
")",
":",
"if",
"i",
"+",
"... | [
9,
0
] | [
28,
24
] | python | en | ['en', 'en', 'en'] | True |
intranges_contain | (int_, ranges) | Determine if `int_` falls into one of the ranges in `ranges`. | Determine if `int_` falls into one of the ranges in `ranges`. | def intranges_contain(int_, ranges):
"""Determine if `int_` falls into one of the ranges in `ranges`."""
tuple_ = _encode_range(int_, 0)
pos = bisect.bisect_left(ranges, tuple_)
# we could be immediately ahead of a tuple (start, end)
# with start < int_ <= end
if pos > 0:
left, right = _... | [
"def",
"intranges_contain",
"(",
"int_",
",",
"ranges",
")",
":",
"tuple_",
"=",
"_encode_range",
"(",
"int_",
",",
"0",
")",
"pos",
"=",
"bisect",
".",
"bisect_left",
"(",
"ranges",
",",
"tuple_",
")",
"# we could be immediately ahead of a tuple (start, end)",
... | [
37,
0
] | [
52,
16
] | python | en | ['en', 'en', 'en'] | True |
AccessControlDriver.get_resource_identifier | (self, resource: AccessControlResource) | Get a driver-specific, human-readable resource identifier to display in UI
Should be overridden by the driver implementation if needed.
| Get a driver-specific, human-readable resource identifier to display in UI | def get_resource_identifier(self, resource: AccessControlResource):
"""Get a driver-specific, human-readable resource identifier to display in UI
Should be overridden by the driver implementation if needed.
"""
return '' | [
"def",
"get_resource_identifier",
"(",
"self",
",",
"resource",
":",
"AccessControlResource",
")",
":",
"return",
"''"
] | [
74,
4
] | [
79,
17
] | python | en | ['en', 'en', 'en'] | True |
AccessControlDriver.save_respa_resource | (self, resource: AccessControlResource, respa_resource: Resource) | Notify driver about saving a Respa resource
Allows for driver-specific customization of the Respa resource or the
corresponding access control resource. Called when the Respa resource object is saved.
NOTE: The driver must not call `respa_resource.save()`. Saving the resource
is handled... | Notify driver about saving a Respa resource | def save_respa_resource(self, resource: AccessControlResource, respa_resource: Resource):
"""Notify driver about saving a Respa resource
Allows for driver-specific customization of the Respa resource or the
corresponding access control resource. Called when the Respa resource object is saved.
... | [
"def",
"save_respa_resource",
"(",
"self",
",",
"resource",
":",
"AccessControlResource",
",",
"respa_resource",
":",
"Resource",
")",
":",
"pass"
] | [
81,
4
] | [
89,
12
] | python | en | ['en', 'en', 'en'] | True |
AccessControlDriver.save_resource | (self, resource: AccessControlResource) | Notify driver about saving an access control resource
Allows for driver-specific customization of the access control resource or the
corresponding Respa resource. Called when the access control resource is saved.
Should be overridden by the driver implementation if needed
| Notify driver about saving an access control resource | def save_resource(self, resource: AccessControlResource):
"""Notify driver about saving an access control resource
Allows for driver-specific customization of the access control resource or the
corresponding Respa resource. Called when the access control resource is saved.
Should be ov... | [
"def",
"save_resource",
"(",
"self",
",",
"resource",
":",
"AccessControlResource",
")",
":",
"pass"
] | [
91,
4
] | [
99,
12
] | python | en | ['en', 'en', 'en'] | True |
main_handler_entrypoint | (event, context) |
Parameters
----------
event: dict, required
context: object, required
Lambda Context runtime methods and attributes
Context doc: https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html
Returns
------
| def main_handler_entrypoint(event, context):
"""
Parameters
----------
event: dict, required
context: object, required
Lambda Context runtime methods and attributes
Context doc: https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html
Returns
------
""... | [
"def",
"main_handler_entrypoint",
"(",
"event",
",",
"context",
")",
":",
"ctx",
"[",
"\"now\"",
"]",
"=",
"misc",
".",
"utc_now",
"(",
")",
"ctx",
"[",
"\"FunctionName\"",
"]",
"=",
"\"Main\"",
"init",
"(",
")",
"if",
"Cfg",
".",
"get_int",
"(",
"\"ap... | [
147,
0
] | [
240,
27
] | python | en | ['en', 'error', 'th'] | False | |
sns_handler | (event, context) |
Parameters
----------
event: dict, required
context: object, required
Lambda Context runtime methods and attributes
Context doc: https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html
Returns
------
| def sns_handler(event, context):
"""
Parameters
----------
event: dict, required
context: object, required
Lambda Context runtime methods and attributes
Context doc: https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html
Returns
------
"""
global... | [
"def",
"sns_handler",
"(",
"event",
",",
"context",
")",
":",
"global",
"ctx",
"ctx",
"[",
"\"now\"",
"]",
"=",
"misc",
".",
"utc_now",
"(",
")",
"log",
".",
"log",
"(",
"log",
".",
"NOTICE",
",",
"\"Handler start.\"",
")",
"ctx",
"[",
"\"FunctionName\... | [
252,
0
] | [
289,
12
] | python | en | ['en', 'error', 'th'] | False | |
discovery_handler | (event, context) |
Parameters
----------
event: dict, required
context: object, required
Lambda Context runtime methods and attributes
Context doc: https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html
Returns
------
| def discovery_handler(event, context):
"""
Parameters
----------
event: dict, required
context: object, required
Lambda Context runtime methods and attributes
Context doc: https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html
Returns
------
"""
... | [
"def",
"discovery_handler",
"(",
"event",
",",
"context",
")",
":",
"global",
"ctx",
"ctx",
"[",
"\"now\"",
"]",
"=",
"misc",
".",
"utc_now",
"(",
")",
"ctx",
"[",
"\"FunctionName\"",
"]",
"=",
"\"Discovery\"",
"log",
".",
"info",
"(",
"\"Processing start ... | [
291,
0
] | [
314,
20
] | python | en | ['en', 'error', 'th'] | False | |
interact_handler_entrypoint | (event, context) |
Parameters
----------
event: dict, required
context: object, required
Lambda Context runtime methods and attributes
Context doc: https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html
Returns
------
| def interact_handler_entrypoint(event, context):
"""
Parameters
----------
event: dict, required
context: object, required
Lambda Context runtime methods and attributes
Context doc: https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html
Returns
------
... | [
"def",
"interact_handler_entrypoint",
"(",
"event",
",",
"context",
")",
":",
"global",
"ctx",
"ctx",
"[",
"\"now\"",
"]",
"=",
"misc",
".",
"utc_now",
"(",
")",
"ctx",
"[",
"\"FunctionName\"",
"]",
"=",
"\"Interact\"",
"log",
".",
"info",
"(",
"\"Processi... | [
324,
0
] | [
359,
19
] | python | en | ['en', 'error', 'th'] | False | |
debug_main_handler | (event, context) | Used for debugging purpose.
As it is looping for ever on the main_handler(), it simulates well an initialized Lambda node with Python
context re-use.
| Used for debugging purpose.
As it is looping for ever on the main_handler(), it simulates well an initialized Lambda node with Python
context re-use.
| def debug_main_handler(event, context):
""" Used for debugging purpose.
As it is looping for ever on the main_handler(), it simulates well an initialized Lambda node with Python
context re-use.
"""
while True:
try:
main_handler(event, context)
time.sleep(10)
e... | [
"def",
"debug_main_handler",
"(",
"event",
",",
"context",
")",
":",
"while",
"True",
":",
"try",
":",
"main_handler",
"(",
"event",
",",
"context",
")",
"time",
".",
"sleep",
"(",
"10",
")",
"except",
":",
"log",
".",
"exception",
"(",
"\"Go Exception:\... | [
375,
0
] | [
386,
27
] | python | en | ['en', 'en', 'en'] | True |
check_finders | (app_configs=None, **kwargs) | Check all registered staticfiles finders. | Check all registered staticfiles finders. | def check_finders(app_configs=None, **kwargs):
"""Check all registered staticfiles finders."""
errors = []
for finder in get_finders():
try:
finder_errors = finder.check()
except NotImplementedError:
pass
else:
errors.extend(finder_errors)
retu... | [
"def",
"check_finders",
"(",
"app_configs",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"errors",
"=",
"[",
"]",
"for",
"finder",
"in",
"get_finders",
"(",
")",
":",
"try",
":",
"finder_errors",
"=",
"finder",
".",
"check",
"(",
")",
"except",
"N... | [
3,
0
] | [
13,
17
] | python | en | ['en', 'en', 'en'] | True |
Command.load_label | (self, fixture_label) | Load fixtures files for a given label. | Load fixtures files for a given label. | def load_label(self, fixture_label):
"""Load fixtures files for a given label."""
show_progress = self.verbosity >= 3
for fixture_file, fixture_dir, fixture_name in self.find_fixtures(fixture_label):
_, ser_fmt, cmp_fmt = self.parse_name(os.path.basename(fixture_file))
op... | [
"def",
"load_label",
"(",
"self",
",",
"fixture_label",
")",
":",
"show_progress",
"=",
"self",
".",
"verbosity",
">=",
"3",
"for",
"fixture_file",
",",
"fixture_dir",
",",
"fixture_name",
"in",
"self",
".",
"find_fixtures",
"(",
"fixture_label",
")",
":",
"... | [
149,
4
] | [
214,
17
] | python | en | ['en', 'en', 'en'] | True |
Command.find_fixtures | (self, fixture_label) | Find fixture files for a given label. | Find fixture files for a given label. | def find_fixtures(self, fixture_label):
"""Find fixture files for a given label."""
if fixture_label == READ_STDIN:
return [(READ_STDIN, None, READ_STDIN)]
fixture_name, ser_fmt, cmp_fmt = self.parse_name(fixture_label)
databases = [self.using, None]
cmp_fmts = list(... | [
"def",
"find_fixtures",
"(",
"self",
",",
"fixture_label",
")",
":",
"if",
"fixture_label",
"==",
"READ_STDIN",
":",
"return",
"[",
"(",
"READ_STDIN",
",",
"None",
",",
"READ_STDIN",
")",
"]",
"fixture_name",
",",
"ser_fmt",
",",
"cmp_fmt",
"=",
"self",
".... | [
217,
4
] | [
272,
28
] | python | en | ['en', 'en', 'en'] | True |
Command.fixture_dirs | (self) |
Return a list of fixture directories.
The list contains the 'fixtures' subdirectory of each installed
application, if it exists, the directories in FIXTURE_DIRS, and the
current directory.
|
Return a list of fixture directories. | def fixture_dirs(self):
"""
Return a list of fixture directories.
The list contains the 'fixtures' subdirectory of each installed
application, if it exists, the directories in FIXTURE_DIRS, and the
current directory.
"""
dirs = []
fixture_dirs = settings.... | [
"def",
"fixture_dirs",
"(",
"self",
")",
":",
"dirs",
"=",
"[",
"]",
"fixture_dirs",
"=",
"settings",
".",
"FIXTURE_DIRS",
"if",
"len",
"(",
"fixture_dirs",
")",
"!=",
"len",
"(",
"set",
"(",
"fixture_dirs",
")",
")",
":",
"raise",
"ImproperlyConfigured",
... | [
275,
4
] | [
302,
50
] | python | en | ['en', 'error', 'th'] | False |
Command.parse_name | (self, fixture_name) |
Split fixture name in name, serialization format, compression format.
|
Split fixture name in name, serialization format, compression format.
| def parse_name(self, fixture_name):
"""
Split fixture name in name, serialization format, compression format.
"""
if fixture_name == READ_STDIN:
if not self.format:
raise CommandError('--format must be specified when reading from stdin.')
return RE... | [
"def",
"parse_name",
"(",
"self",
",",
"fixture_name",
")",
":",
"if",
"fixture_name",
"==",
"READ_STDIN",
":",
"if",
"not",
"self",
".",
"format",
":",
"raise",
"CommandError",
"(",
"'--format must be specified when reading from stdin.'",
")",
"return",
"READ_STDIN... | [
304,
4
] | [
334,
37
] | python | en | ['en', 'error', 'th'] | False |
DeleteQuery.delete_batch | (self, pk_list, using) |
Set up and execute delete queries for all the objects in pk_list.
More than one physical query may be executed if there are a
lot of values in pk_list.
|
Set up and execute delete queries for all the objects in pk_list. | def delete_batch(self, pk_list, using):
"""
Set up and execute delete queries for all the objects in pk_list.
More than one physical query may be executed if there are a
lot of values in pk_list.
"""
# number of objects deleted
num_deleted = 0
field = sel... | [
"def",
"delete_batch",
"(",
"self",
",",
"pk_list",
",",
"using",
")",
":",
"# number of objects deleted",
"num_deleted",
"=",
"0",
"field",
"=",
"self",
".",
"get_meta",
"(",
")",
".",
"pk",
"for",
"offset",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"... | [
26,
4
] | [
41,
26
] | python | en | ['en', 'error', 'th'] | False |
DeleteQuery.delete_qs | (self, query, using) |
Delete the queryset in one SQL query (if possible). For simple queries
this is done by copying the query.query.where to self.query, for
complex queries by using subquery.
|
Delete the queryset in one SQL query (if possible). For simple queries
this is done by copying the query.query.where to self.query, for
complex queries by using subquery.
| def delete_qs(self, query, using):
"""
Delete the queryset in one SQL query (if possible). For simple queries
this is done by copying the query.query.where to self.query, for
complex queries by using subquery.
"""
innerq = query.query
# Make sure the inner query h... | [
"def",
"delete_qs",
"(",
"self",
",",
"query",
",",
"using",
")",
":",
"innerq",
"=",
"query",
".",
"query",
"# Make sure the inner query has at least one table in use.",
"innerq",
".",
"get_initial_alias",
"(",
")",
"# The same for our new query.",
"self",
".",
"get_... | [
43,
4
] | [
75,
47
] | python | en | ['en', 'error', 'th'] | False |
UpdateQuery._setup_query | (self) |
Run on initialization and at the end of chaining. Any attributes that
would normally be set in __init__() should go here instead.
|
Run on initialization and at the end of chaining. Any attributes that
would normally be set in __init__() should go here instead.
| def _setup_query(self):
"""
Run on initialization and at the end of chaining. Any attributes that
would normally be set in __init__() should go here instead.
"""
self.values = []
self.related_ids = None
self.related_updates = {} | [
"def",
"_setup_query",
"(",
"self",
")",
":",
"self",
".",
"values",
"=",
"[",
"]",
"self",
".",
"related_ids",
"=",
"None",
"self",
".",
"related_updates",
"=",
"{",
"}"
] | [
87,
4
] | [
94,
33
] | python | en | ['en', 'error', 'th'] | False |
UpdateQuery.add_update_values | (self, values) |
Convert a dictionary of field name to value mappings into an update
query. This is the entry point for the public update() method on
querysets.
|
Convert a dictionary of field name to value mappings into an update
query. This is the entry point for the public update() method on
querysets.
| def add_update_values(self, values):
"""
Convert a dictionary of field name to value mappings into an update
query. This is the entry point for the public update() method on
querysets.
"""
values_seq = []
for name, val in values.items():
field = self.g... | [
"def",
"add_update_values",
"(",
"self",
",",
"values",
")",
":",
"values_seq",
"=",
"[",
"]",
"for",
"name",
",",
"val",
"in",
"values",
".",
"items",
"(",
")",
":",
"field",
"=",
"self",
".",
"get_meta",
"(",
")",
".",
"get_field",
"(",
"name",
"... | [
108,
4
] | [
128,
49
] | python | en | ['en', 'error', 'th'] | False |
UpdateQuery.add_update_fields | (self, values_seq) |
Append a sequence of (field, model, value) triples to the internal list
that will be used to generate the UPDATE query. Might be more usefully
called add_update_targets() to hint at the extra information here.
|
Append a sequence of (field, model, value) triples to the internal list
that will be used to generate the UPDATE query. Might be more usefully
called add_update_targets() to hint at the extra information here.
| def add_update_fields(self, values_seq):
"""
Append a sequence of (field, model, value) triples to the internal list
that will be used to generate the UPDATE query. Might be more usefully
called add_update_targets() to hint at the extra information here.
"""
for field, mo... | [
"def",
"add_update_fields",
"(",
"self",
",",
"values_seq",
")",
":",
"for",
"field",
",",
"model",
",",
"val",
"in",
"values_seq",
":",
"if",
"hasattr",
"(",
"val",
",",
"'resolve_expression'",
")",
":",
"# Resolve expressions here so that annotations are no longer... | [
130,
4
] | [
140,
51
] | python | en | ['en', 'error', 'th'] | False |
UpdateQuery.add_related_update | (self, model, field, value) |
Add (name, value) to an update query for an ancestor model.
Update are coalesced so that only one update query per ancestor is run.
|
Add (name, value) to an update query for an ancestor model. | def add_related_update(self, model, field, value):
"""
Add (name, value) to an update query for an ancestor model.
Update are coalesced so that only one update query per ancestor is run.
"""
self.related_updates.setdefault(model, []).append((field, None, value)) | [
"def",
"add_related_update",
"(",
"self",
",",
"model",
",",
"field",
",",
"value",
")",
":",
"self",
".",
"related_updates",
".",
"setdefault",
"(",
"model",
",",
"[",
"]",
")",
".",
"append",
"(",
"(",
"field",
",",
"None",
",",
"value",
")",
")"
] | [
142,
4
] | [
148,
79
] | python | en | ['en', 'error', 'th'] | False |
UpdateQuery.get_related_updates | (self) |
Return a list of query objects: one for each update required to an
ancestor model. Each query will have the same filtering conditions as
the current query but will only update a single table.
|
Return a list of query objects: one for each update required to an
ancestor model. Each query will have the same filtering conditions as
the current query but will only update a single table.
| def get_related_updates(self):
"""
Return a list of query objects: one for each update required to an
ancestor model. Each query will have the same filtering conditions as
the current query but will only update a single table.
"""
if not self.related_updates:
... | [
"def",
"get_related_updates",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"related_updates",
":",
"return",
"[",
"]",
"result",
"=",
"[",
"]",
"for",
"model",
",",
"values",
"in",
"self",
".",
"related_updates",
".",
"items",
"(",
")",
":",
"query... | [
150,
4
] | [
165,
21
] | python | en | ['en', 'error', 'th'] | False |
MessagePOSTTest.test_message_to_stream_by_name | (self) |
Sending a message to a stream to which you are subscribed is
successful.
|
Sending a message to a stream to which you are subscribed is
successful.
| def test_message_to_stream_by_name(self) -> None:
"""
Sending a message to a stream to which you are subscribed is
successful.
"""
self.login("hamlet")
result = self.client_post(
"/json/messages",
{
"type": "stream",
... | [
"def",
"test_message_to_stream_by_name",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"hamlet\"",
")",
"result",
"=",
"self",
".",
"client_post",
"(",
"\"/json/messages\"",
",",
"{",
"\"type\"",
":",
"\"stream\"",
",",
"\"to\"",
":",
"\"... | [
82,
4
] | [
98,
40
] | python | en | ['en', 'error', 'th'] | False |
MessagePOSTTest.test_api_message_to_stream_by_name | (self) |
Same as above, but for the API view
|
Same as above, but for the API view
| def test_api_message_to_stream_by_name(self) -> None:
"""
Same as above, but for the API view
"""
user = self.example_user("hamlet")
result = self.api_post(
user,
"/api/v1/messages",
{
"type": "stream",
"to": "Ve... | [
"def",
"test_api_message_to_stream_by_name",
"(",
"self",
")",
"->",
"None",
":",
"user",
"=",
"self",
".",
"example_user",
"(",
"\"hamlet\"",
")",
"result",
"=",
"self",
".",
"api_post",
"(",
"user",
",",
"\"/api/v1/messages\"",
",",
"{",
"\"type\"",
":",
"... | [
100,
4
] | [
116,
40
] | python | en | ['en', 'error', 'th'] | False |
MessagePOSTTest.test_message_to_stream_by_id | (self) |
Sending a message to a stream (by stream ID) to which you are
subscribed is successful.
|
Sending a message to a stream (by stream ID) to which you are
subscribed is successful.
| def test_message_to_stream_by_id(self) -> None:
"""
Sending a message to a stream (by stream ID) to which you are
subscribed is successful.
"""
self.login("hamlet")
realm = get_realm("zulip")
stream = get_stream("Verona", realm)
result = self.client_post(
... | [
"def",
"test_message_to_stream_by_id",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"hamlet\"",
")",
"realm",
"=",
"get_realm",
"(",
"\"zulip\"",
")",
"stream",
"=",
"get_stream",
"(",
"\"Verona\"",
",",
"realm",
")",
"result",
"=",
"s... | [
144,
4
] | [
164,
71
] | python | en | ['en', 'error', 'th'] | False |
MessagePOSTTest.test_sending_message_as_stream_post_policy_admins | (self) |
Sending messages to streams which only the admins can post to.
|
Sending messages to streams which only the admins can post to.
| def test_sending_message_as_stream_post_policy_admins(self) -> None:
"""
Sending messages to streams which only the admins can post to.
"""
admin_profile = self.example_user("iago")
self.login_user(admin_profile)
stream_name = "Verona"
stream = get_stream(stream_... | [
"def",
"test_sending_message_as_stream_post_policy_admins",
"(",
"self",
")",
"->",
"None",
":",
"admin_profile",
"=",
"self",
".",
"example_user",
"(",
"\"iago\"",
")",
"self",
".",
"login_user",
"(",
"admin_profile",
")",
"stream_name",
"=",
"\"Verona\"",
"stream"... | [
166,
4
] | [
252,
9
] | python | en | ['en', 'error', 'th'] | False |
MessagePOSTTest.test_sending_message_as_stream_post_policy_moderators | (self) |
Sending messages to streams which only the moderators can post to.
|
Sending messages to streams which only the moderators can post to.
| def test_sending_message_as_stream_post_policy_moderators(self) -> None:
"""
Sending messages to streams which only the moderators can post to.
"""
admin_profile = self.example_user("iago")
self.login_user(admin_profile)
stream_name = "Verona"
stream = get_stream... | [
"def",
"test_sending_message_as_stream_post_policy_moderators",
"(",
"self",
")",
"->",
"None",
":",
"admin_profile",
"=",
"self",
".",
"example_user",
"(",
"\"iago\"",
")",
"self",
".",
"login_user",
"(",
"admin_profile",
")",
"stream_name",
"=",
"\"Verona\"",
"str... | [
254,
4
] | [
334,
9
] | python | en | ['en', 'error', 'th'] | False |
MessagePOSTTest.test_sending_message_as_stream_post_policy_restrict_new_members | (self) |
Sending messages to streams which new members cannot post to.
|
Sending messages to streams which new members cannot post to.
| def test_sending_message_as_stream_post_policy_restrict_new_members(self) -> None:
"""
Sending messages to streams which new members cannot post to.
"""
admin_profile = self.example_user("iago")
self.login_user(admin_profile)
do_set_realm_property(admin_profile.realm, "w... | [
"def",
"test_sending_message_as_stream_post_policy_restrict_new_members",
"(",
"self",
")",
"->",
"None",
":",
"admin_profile",
"=",
"self",
".",
"example_user",
"(",
"\"iago\"",
")",
"self",
".",
"login_user",
"(",
"admin_profile",
")",
"do_set_realm_property",
"(",
... | [
336,
4
] | [
438,
9
] | python | en | ['en', 'error', 'th'] | False |
MessagePOSTTest.test_api_message_with_default_to | (self) |
Sending messages without a to field should be sent to the default
stream for the user_profile.
|
Sending messages without a to field should be sent to the default
stream for the user_profile.
| def test_api_message_with_default_to(self) -> None:
"""
Sending messages without a to field should be sent to the default
stream for the user_profile.
"""
user = self.example_user("hamlet")
user.default_sending_stream_id = get_stream("Verona", user.realm).id
user.... | [
"def",
"test_api_message_with_default_to",
"(",
"self",
")",
"->",
"None",
":",
"user",
"=",
"self",
".",
"example_user",
"(",
"\"hamlet\"",
")",
"user",
".",
"default_sending_stream_id",
"=",
"get_stream",
"(",
"\"Verona\"",
",",
"user",
".",
"realm",
")",
".... | [
440,
4
] | [
463,
68
] | python | en | ['en', 'error', 'th'] | False |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.