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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
file_move_safe | (old_file_name, new_file_name, chunk_size=1024 * 64, allow_overwrite=False) |
Moves a file from one location to another in the safest way possible.
First, tries ``os.rename``, which is simple but will break across filesystems.
If that fails, streams manually from one file to another in pure Python.
If the destination file exists and ``allow_overwrite`` is ``False``, this
f... |
Moves a file from one location to another in the safest way possible. | def file_move_safe(old_file_name, new_file_name, chunk_size=1024 * 64, allow_overwrite=False):
"""
Moves a file from one location to another in the safest way possible.
First, tries ``os.rename``, which is simple but will break across filesystems.
If that fails, streams manually from one file to anothe... | [
"def",
"file_move_safe",
"(",
"old_file_name",
",",
"new_file_name",
",",
"chunk_size",
"=",
"1024",
"*",
"64",
",",
"allow_overwrite",
"=",
"False",
")",
":",
"# There's no reason to move if we don't have to.",
"if",
"_samefile",
"(",
"old_file_name",
",",
"new_file_... | [
28,
0
] | [
79,
17
] | python | en | ['en', 'error', 'th'] | False |
aryl_amination | (aryl_halide='ohe', additive='ohe', base='ohe', ligand='ohe', subset=1) |
Load aryl amination data with different features.
|
Load aryl amination data with different features.
| def aryl_amination(aryl_halide='ohe', additive='ohe', base='ohe', ligand='ohe', subset=1):
"""
Load aryl amination data with different features.
"""
# SMILES index
index = pd.read_csv('data/aryl_amination/experiment_index.csv')
# Choose supset:
ar123 = ['FC(F)(F)c1ccc(Cl)... | [
"def",
"aryl_amination",
"(",
"aryl_halide",
"=",
"'ohe'",
",",
"additive",
"=",
"'ohe'",
",",
"base",
"=",
"'ohe'",
",",
"ligand",
"=",
"'ohe'",
",",
"subset",
"=",
"1",
")",
":",
"# SMILES index",
"index",
"=",
"pd",
".",
"read_csv",
"(",
"'data/aryl_a... | [
12,
0
] | [
106,
27
] | python | en | ['en', 'error', 'th'] | False |
suzuki | (electrophile='ohe', nucleophile='ohe', base='ohe', ligand='ohe', solvent='ohe') |
Load Suzuki data with different features.
|
Load Suzuki data with different features.
| def suzuki(electrophile='ohe', nucleophile='ohe', base='ohe', ligand='ohe', solvent='ohe'):
"""
Load Suzuki data with different features.
"""
# SMILES index
index = pd.read_csv('data/suzuki/experiment_index.csv')
# Electrophile features
if electrophile == 'dft':
e... | [
"def",
"suzuki",
"(",
"electrophile",
"=",
"'ohe'",
",",
"nucleophile",
"=",
"'ohe'",
",",
"base",
"=",
"'ohe'",
",",
"ligand",
"=",
"'ohe'",
",",
"solvent",
"=",
"'ohe'",
")",
":",
"# SMILES index",
"index",
"=",
"pd",
".",
"read_csv",
"(",
"'data/suzuk... | [
108,
0
] | [
191,
27
] | python | en | ['en', 'error', 'th'] | False |
direct_arylation | (base='ohe', ligand='ohe', solvent='ohe') |
Load direct arylation data with different features.
|
Load direct arylation data with different features.
| def direct_arylation(base='ohe', ligand='ohe', solvent='ohe'):
"""
Load direct arylation data with different features.
"""
# SMILES index
index = pd.read_csv('data/direct_arylation/experiment_index.csv')
# Base features
if base == 'dft':
base_features = pd.read_csv... | [
"def",
"direct_arylation",
"(",
"base",
"=",
"'ohe'",
",",
"ligand",
"=",
"'ohe'",
",",
"solvent",
"=",
"'ohe'",
")",
":",
"# SMILES index",
"index",
"=",
"pd",
".",
"read_csv",
"(",
"'data/direct_arylation/experiment_index.csv'",
")",
"# Base features",
"if",
"... | [
193,
0
] | [
253,
27
] | python | en | ['en', 'error', 'th'] | False |
direct_arylation_extended | (base='ohe', ligand='ohe', solvent='ohe') |
Load direct arylation data for extended ligand set with
different features.
|
Load direct arylation data for extended ligand set with
different features.
| def direct_arylation_extended(base='ohe', ligand='ohe', solvent='ohe'):
"""
Load direct arylation data for extended ligand set with
different features.
"""
# SMILES index
index = pd.read_csv('data/direct_arylation_extended/experiment_index.csv')
# Base features
if base ==... | [
"def",
"direct_arylation_extended",
"(",
"base",
"=",
"'ohe'",
",",
"ligand",
"=",
"'ohe'",
",",
"solvent",
"=",
"'ohe'",
")",
":",
"# SMILES index",
"index",
"=",
"pd",
".",
"read_csv",
"(",
"'data/direct_arylation_extended/experiment_index.csv'",
")",
"# Base feat... | [
256,
0
] | [
317,
27
] | python | en | ['en', 'error', 'th'] | False |
getiptcinfo | (im) |
Get IPTC information from TIFF, JPEG, or IPTC file.
:param im: An image containing IPTC data.
:returns: A dictionary containing IPTC information, or None if
no IPTC information block was found.
|
Get IPTC information from TIFF, JPEG, or IPTC file. | def getiptcinfo(im):
"""
Get IPTC information from TIFF, JPEG, or IPTC file.
:param im: An image containing IPTC data.
:returns: A dictionary containing IPTC information, or None if
no IPTC information block was found.
"""
import io
from . import JpegImagePlugin, TiffImagePlugin
... | [
"def",
"getiptcinfo",
"(",
"im",
")",
":",
"import",
"io",
"from",
".",
"import",
"JpegImagePlugin",
",",
"TiffImagePlugin",
"data",
"=",
"None",
"if",
"isinstance",
"(",
"im",
",",
"IptcImageFile",
")",
":",
"# return info dictionary right away",
"return",
"im"... | [
178,
0
] | [
229,
18
] | python | en | ['en', 'error', 'th'] | False |
ConditionalKernelDensityEstimation.fit | (self, X, Y, **kwargs) | Since CKDE is a lazy learner, fit just stores the provided training data (X,Y)
Args:
X: numpy array to be conditioned on - shape: (n_samples, n_dim_x)
Y: numpy array of y targets - shape: (n_samples, n_dim_y)
| Since CKDE is a lazy learner, fit just stores the provided training data (X,Y) | def fit(self, X, Y, **kwargs):
""" Since CKDE is a lazy learner, fit just stores the provided training data (X,Y)
Args:
X: numpy array to be conditioned on - shape: (n_samples, n_dim_x)
Y: numpy array of y targets - shape: (n_samples, n_dim_y)
"""
X, Y = self._handle_input_dimensiona... | [
"def",
"fit",
"(",
"self",
",",
"X",
",",
"Y",
",",
"*",
"*",
"kwargs",
")",
":",
"X",
",",
"Y",
"=",
"self",
".",
"_handle_input_dimensionality",
"(",
"X",
",",
"Y",
",",
"fitting",
"=",
"True",
")",
"self",
".",
"y_mean",
",",
"self",
".",
"y... | [
50,
2
] | [
67,
23
] | python | en | ['en', 'en', 'en'] | True |
ConditionalKernelDensityEstimation.pdf | (self, X, Y) | Predicts the conditional likelihood p(y|x). Requires the model to be fitted.
Args:
X: numpy array to be conditioned on - shape: (n_samples, n_dim_x)
Y: numpy array of y targets - shape: (n_samples, n_dim_y)
Returns:
conditional likelihood p(y|x) - numpy array of shape (n_que... | Predicts the conditional likelihood p(y|x). Requires the model to be fitted. | def pdf(self, X, Y):
""" Predicts the conditional likelihood p(y|x). Requires the model to be fitted.
Args:
X: numpy array to be conditioned on - shape: (n_samples, n_dim_x)
Y: numpy array of y targets - shape: (n_samples, n_dim_y)
Returns:
conditional likelihood p(y|x) -... | [
"def",
"pdf",
"(",
"self",
",",
"X",
",",
"Y",
")",
":",
"X",
",",
"Y",
"=",
"self",
".",
"_handle_input_dimensionality",
"(",
"X",
",",
"Y",
")",
"n_samples",
"=",
"X",
".",
"shape",
"[",
"0",
"]",
"if",
"n_samples",
">=",
"MULTIPROC_THRESHOLD",
"... | [
69,
2
] | [
86,
61
] | python | en | ['en', 'en', 'en'] | True |
ConditionalKernelDensityEstimation.cdf | (self, X, Y) | Predicts the conditional cumulative probability p(Y<=y|X=x). Requires the model to be fitted.
Args:
X: numpy array to be conditioned on - shape: (n_samples, n_dim_x)
Y: numpy array of y targets - shape: (n_samples, n_dim_y)
Returns:
conditional cumulative probability p(Y<=y|X=x) - numpy arr... | Predicts the conditional cumulative probability p(Y<=y|X=x). Requires the model to be fitted. | def cdf(self, X, Y):
""" Predicts the conditional cumulative probability p(Y<=y|X=x). Requires the model to be fitted.
Args:
X: numpy array to be conditioned on - shape: (n_samples, n_dim_x)
Y: numpy array of y targets - shape: (n_samples, n_dim_y)
Returns:
conditional cumulative probabi... | [
"def",
"cdf",
"(",
"self",
",",
"X",
",",
"Y",
")",
":",
"assert",
"self",
".",
"fitted",
",",
"\"model must be fitted to compute likelihood score\"",
"X",
",",
"Y",
"=",
"self",
".",
"_handle_input_dimensionality",
"(",
"X",
",",
"Y",
")",
"n_samples",
"=",... | [
88,
2
] | [
105,
61
] | python | en | ['en', 'en', 'en'] | True |
Distance.distance | (self, x, y) |
Computes distance measure between vectors x and y. Returns float.
|
Computes distance measure between vectors x and y. Returns float.
| def distance(self, x, y):
"""
Computes distance measure between vectors x and y. Returns float.
"""
raise NotImplementedError | [
"def",
"distance",
"(",
"self",
",",
"x",
",",
"y",
")",
":",
"raise",
"NotImplementedError"
] | [
26,
4
] | [
30,
33
] | python | en | ['en', 'error', 'th'] | False |
urlquote | (url, safe='/') |
A version of Python's urllib.quote() function that can operate on unicode
strings. The url is first UTF-8 encoded before quoting. The returned string
can safely be used as part of an argument to a subsequent iri_to_uri() call
without double-quoting occurring.
|
A version of Python's urllib.quote() function that can operate on unicode
strings. The url is first UTF-8 encoded before quoting. The returned string
can safely be used as part of an argument to a subsequent iri_to_uri() call
without double-quoting occurring.
| def urlquote(url, safe='/'):
"""
A version of Python's urllib.quote() function that can operate on unicode
strings. The url is first UTF-8 encoded before quoting. The returned string
can safely be used as part of an argument to a subsequent iri_to_uri() call
without double-quoting occurring.
"""... | [
"def",
"urlquote",
"(",
"url",
",",
"safe",
"=",
"'/'",
")",
":",
"return",
"force_text",
"(",
"quote",
"(",
"force_str",
"(",
"url",
")",
",",
"force_str",
"(",
"safe",
")",
")",
")"
] | [
62,
0
] | [
69,
61
] | python | en | ['en', 'error', 'th'] | False |
urlquote_plus | (url, safe='') |
A version of Python's urllib.quote_plus() function that can operate on
unicode strings. The url is first UTF-8 encoded before quoting. The
returned string can safely be used as part of an argument to a subsequent
iri_to_uri() call without double-quoting occurring.
|
A version of Python's urllib.quote_plus() function that can operate on
unicode strings. The url is first UTF-8 encoded before quoting. The
returned string can safely be used as part of an argument to a subsequent
iri_to_uri() call without double-quoting occurring.
| def urlquote_plus(url, safe=''):
"""
A version of Python's urllib.quote_plus() function that can operate on
unicode strings. The url is first UTF-8 encoded before quoting. The
returned string can safely be used as part of an argument to a subsequent
iri_to_uri() call without double-quoting occurring... | [
"def",
"urlquote_plus",
"(",
"url",
",",
"safe",
"=",
"''",
")",
":",
"return",
"force_text",
"(",
"quote_plus",
"(",
"force_str",
"(",
"url",
")",
",",
"force_str",
"(",
"safe",
")",
")",
")"
] | [
73,
0
] | [
80,
66
] | python | en | ['en', 'error', 'th'] | False |
urlunquote | (quoted_url) |
A wrapper for Python's urllib.unquote() function that can operate on
the result of django.utils.http.urlquote().
|
A wrapper for Python's urllib.unquote() function that can operate on
the result of django.utils.http.urlquote().
| def urlunquote(quoted_url):
"""
A wrapper for Python's urllib.unquote() function that can operate on
the result of django.utils.http.urlquote().
"""
return force_text(unquote(force_str(quoted_url))) | [
"def",
"urlunquote",
"(",
"quoted_url",
")",
":",
"return",
"force_text",
"(",
"unquote",
"(",
"force_str",
"(",
"quoted_url",
")",
")",
")"
] | [
84,
0
] | [
89,
53
] | python | en | ['en', 'error', 'th'] | False |
urlunquote_plus | (quoted_url) |
A wrapper for Python's urllib.unquote_plus() function that can operate on
the result of django.utils.http.urlquote_plus().
|
A wrapper for Python's urllib.unquote_plus() function that can operate on
the result of django.utils.http.urlquote_plus().
| def urlunquote_plus(quoted_url):
"""
A wrapper for Python's urllib.unquote_plus() function that can operate on
the result of django.utils.http.urlquote_plus().
"""
return force_text(unquote_plus(force_str(quoted_url))) | [
"def",
"urlunquote_plus",
"(",
"quoted_url",
")",
":",
"return",
"force_text",
"(",
"unquote_plus",
"(",
"force_str",
"(",
"quoted_url",
")",
")",
")"
] | [
93,
0
] | [
98,
58
] | python | en | ['en', 'error', 'th'] | False |
urlencode | (query, doseq=0) |
A version of Python's urllib.urlencode() function that can operate on
unicode strings. The parameters are first cast to UTF-8 encoded strings and
then encoded as per normal.
|
A version of Python's urllib.urlencode() function that can operate on
unicode strings. The parameters are first cast to UTF-8 encoded strings and
then encoded as per normal.
| def urlencode(query, doseq=0):
"""
A version of Python's urllib.urlencode() function that can operate on
unicode strings. The parameters are first cast to UTF-8 encoded strings and
then encoded as per normal.
"""
if isinstance(query, MultiValueDict):
query = query.lists()
elif hasatt... | [
"def",
"urlencode",
"(",
"query",
",",
"doseq",
"=",
"0",
")",
":",
"if",
"isinstance",
"(",
"query",
",",
"MultiValueDict",
")",
":",
"query",
"=",
"query",
".",
"lists",
"(",
")",
"elif",
"hasattr",
"(",
"query",
",",
"'items'",
")",
":",
"query",
... | [
101,
0
] | [
115,
14
] | python | en | ['en', 'error', 'th'] | False |
cookie_date | (epoch_seconds=None) |
Formats the time to ensure compatibility with Netscape's cookie standard.
Accepts a floating point number expressed in seconds since the epoch, in
UTC - such as that outputted by time.time(). If set to None, defaults to
the current time.
Outputs a string in the format 'Wdy, DD-Mon-YYYY HH:MM:SS G... |
Formats the time to ensure compatibility with Netscape's cookie standard. | def cookie_date(epoch_seconds=None):
"""
Formats the time to ensure compatibility with Netscape's cookie standard.
Accepts a floating point number expressed in seconds since the epoch, in
UTC - such as that outputted by time.time(). If set to None, defaults to
the current time.
Outputs a strin... | [
"def",
"cookie_date",
"(",
"epoch_seconds",
"=",
"None",
")",
":",
"rfcdate",
"=",
"formatdate",
"(",
"epoch_seconds",
")",
"return",
"'%s-%s-%s GMT'",
"%",
"(",
"rfcdate",
"[",
":",
"7",
"]",
",",
"rfcdate",
"[",
"8",
":",
"11",
"]",
",",
"rfcdate",
"... | [
118,
0
] | [
129,
72
] | python | en | ['en', 'error', 'th'] | False |
http_date | (epoch_seconds=None) |
Formats the time to match the RFC1123 date format as specified by HTTP
RFC7231 section 7.1.1.1.
Accepts a floating point number expressed in seconds since the epoch, in
UTC - such as that outputted by time.time(). If set to None, defaults to
the current time.
Outputs a string in the format 'W... |
Formats the time to match the RFC1123 date format as specified by HTTP
RFC7231 section 7.1.1.1. | def http_date(epoch_seconds=None):
"""
Formats the time to match the RFC1123 date format as specified by HTTP
RFC7231 section 7.1.1.1.
Accepts a floating point number expressed in seconds since the epoch, in
UTC - such as that outputted by time.time(). If set to None, defaults to
the current ti... | [
"def",
"http_date",
"(",
"epoch_seconds",
"=",
"None",
")",
":",
"return",
"formatdate",
"(",
"epoch_seconds",
",",
"usegmt",
"=",
"True",
")"
] | [
132,
0
] | [
143,
49
] | python | en | ['en', 'error', 'th'] | False |
parse_http_date | (date) |
Parses a date format as specified by HTTP RFC7231 section 7.1.1.1.
The three formats allowed by the RFC are accepted, even if only the first
one is still in widespread use.
Returns an integer expressed in seconds since the epoch, in UTC.
|
Parses a date format as specified by HTTP RFC7231 section 7.1.1.1. | def parse_http_date(date):
"""
Parses a date format as specified by HTTP RFC7231 section 7.1.1.1.
The three formats allowed by the RFC are accepted, even if only the first
one is still in widespread use.
Returns an integer expressed in seconds since the epoch, in UTC.
"""
# emails.Util.par... | [
"def",
"parse_http_date",
"(",
"date",
")",
":",
"# emails.Util.parsedate does the job for RFC1123 dates; unfortunately",
"# RFC7231 makes it mandatory to support RFC850 dates too. So we roll",
"# our own RFC-compliant parsing.",
"for",
"regex",
"in",
"RFC1123_DATE",
",",
"RFC850_DATE",
... | [
146,
0
] | [
179,
95
] | python | en | ['en', 'error', 'th'] | False |
parse_http_date_safe | (date) |
Same as parse_http_date, but returns None if the input is invalid.
|
Same as parse_http_date, but returns None if the input is invalid.
| def parse_http_date_safe(date):
"""
Same as parse_http_date, but returns None if the input is invalid.
"""
try:
return parse_http_date(date)
except Exception:
pass | [
"def",
"parse_http_date_safe",
"(",
"date",
")",
":",
"try",
":",
"return",
"parse_http_date",
"(",
"date",
")",
"except",
"Exception",
":",
"pass"
] | [
182,
0
] | [
189,
12
] | python | en | ['en', 'error', 'th'] | False |
base36_to_int | (s) |
Converts a base 36 string to an ``int``. Raises ``ValueError` if the
input won't fit into an int.
|
Converts a base 36 string to an ``int``. Raises ``ValueError` if the
input won't fit into an int.
| def base36_to_int(s):
"""
Converts a base 36 string to an ``int``. Raises ``ValueError` if the
input won't fit into an int.
"""
# To prevent overconsumption of server resources, reject any
# base36 string that is longer than 13 base36 digits (13 digits
# is sufficient to base36-encode any 64... | [
"def",
"base36_to_int",
"(",
"s",
")",
":",
"# To prevent overconsumption of server resources, reject any",
"# base36 string that is longer than 13 base36 digits (13 digits",
"# is sufficient to base36-encode any 64-bit integer)",
"if",
"len",
"(",
"s",
")",
">",
"13",
":",
"raise"... | [
194,
0
] | [
209,
16
] | python | en | ['en', 'error', 'th'] | False |
int_to_base36 | (i) |
Converts an integer to a base36 string
|
Converts an integer to a base36 string
| def int_to_base36(i):
"""
Converts an integer to a base36 string
"""
char_set = '0123456789abcdefghijklmnopqrstuvwxyz'
if i < 0:
raise ValueError("Negative base36 conversion input.")
if six.PY2:
if not isinstance(i, six.integer_types):
raise TypeError("Non-integer bas... | [
"def",
"int_to_base36",
"(",
"i",
")",
":",
"char_set",
"=",
"'0123456789abcdefghijklmnopqrstuvwxyz'",
"if",
"i",
"<",
"0",
":",
"raise",
"ValueError",
"(",
"\"Negative base36 conversion input.\"",
")",
"if",
"six",
".",
"PY2",
":",
"if",
"not",
"isinstance",
"(... | [
212,
0
] | [
230,
14
] | python | en | ['en', 'error', 'th'] | False |
urlsafe_base64_encode | (s) |
Encodes a bytestring in base64 for use in URLs, stripping any trailing
equal signs.
|
Encodes a bytestring in base64 for use in URLs, stripping any trailing
equal signs.
| def urlsafe_base64_encode(s):
"""
Encodes a bytestring in base64 for use in URLs, stripping any trailing
equal signs.
"""
return base64.urlsafe_b64encode(s).rstrip(b'\n=') | [
"def",
"urlsafe_base64_encode",
"(",
"s",
")",
":",
"return",
"base64",
".",
"urlsafe_b64encode",
"(",
"s",
")",
".",
"rstrip",
"(",
"b'\\n='",
")"
] | [
233,
0
] | [
238,
53
] | python | en | ['en', 'error', 'th'] | False |
urlsafe_base64_decode | (s) |
Decodes a base64 encoded string, adding back any trailing equal signs that
might have been stripped.
|
Decodes a base64 encoded string, adding back any trailing equal signs that
might have been stripped.
| def urlsafe_base64_decode(s):
"""
Decodes a base64 encoded string, adding back any trailing equal signs that
might have been stripped.
"""
s = force_bytes(s)
try:
return base64.urlsafe_b64decode(s.ljust(len(s) + len(s) % 4, b'='))
except (LookupError, BinasciiError) as e:
rai... | [
"def",
"urlsafe_base64_decode",
"(",
"s",
")",
":",
"s",
"=",
"force_bytes",
"(",
"s",
")",
"try",
":",
"return",
"base64",
".",
"urlsafe_b64decode",
"(",
"s",
".",
"ljust",
"(",
"len",
"(",
"s",
")",
"+",
"len",
"(",
"s",
")",
"%",
"4",
",",
"b'... | [
241,
0
] | [
250,
27
] | python | en | ['en', 'error', 'th'] | False |
parse_etags | (etag_str) |
Parse a string of ETags given in an If-None-Match or If-Match header as
defined by RFC 7232. Return a list of quoted ETags, or ['*'] if all ETags
should be matched.
|
Parse a string of ETags given in an If-None-Match or If-Match header as
defined by RFC 7232. Return a list of quoted ETags, or ['*'] if all ETags
should be matched.
| def parse_etags(etag_str):
"""
Parse a string of ETags given in an If-None-Match or If-Match header as
defined by RFC 7232. Return a list of quoted ETags, or ['*'] if all ETags
should be matched.
"""
if etag_str.strip() == '*':
return ['*']
else:
# Parse each ETag individuall... | [
"def",
"parse_etags",
"(",
"etag_str",
")",
":",
"if",
"etag_str",
".",
"strip",
"(",
")",
"==",
"'*'",
":",
"return",
"[",
"'*'",
"]",
"else",
":",
"# Parse each ETag individually, and return any that are valid.",
"etag_matches",
"=",
"(",
"ETAG_MATCH",
".",
"m... | [
253,
0
] | [
264,
66
] | python | en | ['en', 'error', 'th'] | False |
quote_etag | (etag_str) |
If the provided string is already a quoted ETag, return it. Otherwise, wrap
the string in quotes, making it a strong ETag.
|
If the provided string is already a quoted ETag, return it. Otherwise, wrap
the string in quotes, making it a strong ETag.
| def quote_etag(etag_str):
"""
If the provided string is already a quoted ETag, return it. Otherwise, wrap
the string in quotes, making it a strong ETag.
"""
if ETAG_MATCH.match(etag_str):
return etag_str
else:
return '"%s"' % etag_str | [
"def",
"quote_etag",
"(",
"etag_str",
")",
":",
"if",
"ETAG_MATCH",
".",
"match",
"(",
"etag_str",
")",
":",
"return",
"etag_str",
"else",
":",
"return",
"'\"%s\"'",
"%",
"etag_str"
] | [
267,
0
] | [
275,
32
] | python | en | ['en', 'error', 'th'] | False |
is_same_domain | (host, pattern) |
Return ``True`` if the host is either an exact match or a match
to the wildcard pattern.
Any pattern beginning with a period matches a domain and all of its
subdomains. (e.g. ``.example.com`` matches ``example.com`` and
``foo.example.com``). Anything else is an exact string match.
|
Return ``True`` if the host is either an exact match or a match
to the wildcard pattern. | def is_same_domain(host, pattern):
"""
Return ``True`` if the host is either an exact match or a match
to the wildcard pattern.
Any pattern beginning with a period matches a domain and all of its
subdomains. (e.g. ``.example.com`` matches ``example.com`` and
``foo.example.com``). Anything else ... | [
"def",
"is_same_domain",
"(",
"host",
",",
"pattern",
")",
":",
"if",
"not",
"pattern",
":",
"return",
"False",
"pattern",
"=",
"pattern",
".",
"lower",
"(",
")",
"return",
"(",
"pattern",
"[",
"0",
"]",
"==",
"'.'",
"and",
"(",
"host",
".",
"endswit... | [
278,
0
] | [
294,
5
] | python | en | ['en', 'error', 'th'] | False |
is_safe_url | (url, host=None, allowed_hosts=None, require_https=False) |
Return ``True`` if the url is a safe redirection (i.e. it doesn't point to
a different host and uses a safe scheme).
Always returns ``False`` on an empty url.
If ``require_https`` is ``True``, only 'https' will be considered a valid
scheme, as opposed to 'http' and 'https' with the default, ``Fal... |
Return ``True`` if the url is a safe redirection (i.e. it doesn't point to
a different host and uses a safe scheme). | def is_safe_url(url, host=None, allowed_hosts=None, require_https=False):
"""
Return ``True`` if the url is a safe redirection (i.e. it doesn't point to
a different host and uses a safe scheme).
Always returns ``False`` on an empty url.
If ``require_https`` is ``True``, only 'https' will be consid... | [
"def",
"is_safe_url",
"(",
"url",
",",
"host",
"=",
"None",
",",
"allowed_hosts",
"=",
"None",
",",
"require_https",
"=",
"False",
")",
":",
"if",
"url",
"is",
"not",
"None",
":",
"url",
"=",
"url",
".",
"strip",
"(",
")",
"if",
"not",
"url",
":",
... | [
297,
0
] | [
329,
93
] | python | en | ['en', 'error', 'th'] | False |
_urlparse | (url, scheme='', allow_fragments=True) | Parse a URL into 6 components:
<scheme>://<netloc>/<path>;<params>?<query>#<fragment>
Return a 6-tuple: (scheme, netloc, path, params, query, fragment).
Note that we don't break the components up in smaller bits
(e.g. netloc is a single string) and we don't expand % escapes. | Parse a URL into 6 components:
<scheme>://<netloc>/<path>;<params>?<query>#<fragment>
Return a 6-tuple: (scheme, netloc, path, params, query, fragment).
Note that we don't break the components up in smaller bits
(e.g. netloc is a single string) and we don't expand % escapes. | def _urlparse(url, scheme='', allow_fragments=True):
"""Parse a URL into 6 components:
<scheme>://<netloc>/<path>;<params>?<query>#<fragment>
Return a 6-tuple: (scheme, netloc, path, params, query, fragment).
Note that we don't break the components up in smaller bits
(e.g. netloc is a single string)... | [
"def",
"_urlparse",
"(",
"url",
",",
"scheme",
"=",
"''",
",",
"allow_fragments",
"=",
"True",
")",
":",
"if",
"_coerce_args",
":",
"url",
",",
"scheme",
",",
"_coerce_result",
"=",
"_coerce_args",
"(",
"url",
",",
"scheme",
")",
"splitresult",
"=",
"_ur... | [
333,
0
] | [
348,
61
] | python | en | ['en', 'en', 'en'] | True |
_urlsplit | (url, scheme='', allow_fragments=True) | Parse a URL into 5 components:
<scheme>://<netloc>/<path>?<query>#<fragment>
Return a 5-tuple: (scheme, netloc, path, query, fragment).
Note that we don't break the components up in smaller bits
(e.g. netloc is a single string) and we don't expand % escapes. | Parse a URL into 5 components:
<scheme>://<netloc>/<path>?<query>#<fragment>
Return a 5-tuple: (scheme, netloc, path, query, fragment).
Note that we don't break the components up in smaller bits
(e.g. netloc is a single string) and we don't expand % escapes. | def _urlsplit(url, scheme='', allow_fragments=True):
"""Parse a URL into 5 components:
<scheme>://<netloc>/<path>?<query>#<fragment>
Return a 5-tuple: (scheme, netloc, path, query, fragment).
Note that we don't break the components up in smaller bits
(e.g. netloc is a single string) and we don't exp... | [
"def",
"_urlsplit",
"(",
"url",
",",
"scheme",
"=",
"''",
",",
"allow_fragments",
"=",
"True",
")",
":",
"if",
"_coerce_args",
":",
"url",
",",
"scheme",
",",
"_coerce_result",
"=",
"_coerce_args",
"(",
"url",
",",
"scheme",
")",
"allow_fragments",
"=",
... | [
353,
0
] | [
381,
51
] | python | en | ['en', 'en', 'en'] | True |
limited_parse_qsl | (qs, keep_blank_values=False, encoding='utf-8',
errors='replace', fields_limit=None) |
Return a list of key/value tuples parsed from query string.
Copied from urlparse with an additional "fields_limit" argument.
Copyright (C) 2013 Python Software Foundation (see LICENSE.python).
Arguments:
qs: percent-encoded query string to be parsed
keep_blank_values: flag indicating whethe... |
Return a list of key/value tuples parsed from query string. | def limited_parse_qsl(qs, keep_blank_values=False, encoding='utf-8',
errors='replace', fields_limit=None):
"""
Return a list of key/value tuples parsed from query string.
Copied from urlparse with an additional "fields_limit" argument.
Copyright (C) 2013 Python Software Foundation... | [
"def",
"limited_parse_qsl",
"(",
"qs",
",",
"keep_blank_values",
"=",
"False",
",",
"encoding",
"=",
"'utf-8'",
",",
"errors",
"=",
"'replace'",
",",
"fields_limit",
"=",
"None",
")",
":",
"if",
"fields_limit",
":",
"pairs",
"=",
"FIELDS_MATCH",
".",
"split"... | [
410,
0
] | [
464,
12
] | python | en | ['en', 'error', 'th'] | False |
get_openapi_fixture | (endpoint: str, method: str, status_code: str = "200") | Fetch a fixture from the full spec object. | Fetch a fixture from the full spec object. | def get_openapi_fixture(endpoint: str, method: str, status_code: str = "200") -> Dict[str, Any]:
"""Fetch a fixture from the full spec object."""
return get_schema(endpoint, method, status_code)["example"] | [
"def",
"get_openapi_fixture",
"(",
"endpoint",
":",
"str",
",",
"method",
":",
"str",
",",
"status_code",
":",
"str",
"=",
"\"200\"",
")",
"->",
"Dict",
"[",
"str",
",",
"Any",
"]",
":",
"return",
"get_schema",
"(",
"endpoint",
",",
"method",
",",
"sta... | [
206,
0
] | [
208,
63
] | python | en | ['en', 'en', 'en'] | True |
get_openapi_fixture_description | (endpoint: str, method: str, status_code: str = "200") | Fetch a fixture from the full spec object. | Fetch a fixture from the full spec object. | def get_openapi_fixture_description(endpoint: str, method: str, status_code: str = "200") -> str:
"""Fetch a fixture from the full spec object."""
return get_schema(endpoint, method, status_code)["description"] | [
"def",
"get_openapi_fixture_description",
"(",
"endpoint",
":",
"str",
",",
"method",
":",
"str",
",",
"status_code",
":",
"str",
"=",
"\"200\"",
")",
"->",
"str",
":",
"return",
"get_schema",
"(",
"endpoint",
",",
"method",
",",
"status_code",
")",
"[",
"... | [
211,
0
] | [
213,
67
] | python | en | ['en', 'en', 'en'] | True |
check_requires_administrator | (endpoint: str, method: str) | Fetch if the endpoint requires admin config. | Fetch if the endpoint requires admin config. | def check_requires_administrator(endpoint: str, method: str) -> bool:
"""Fetch if the endpoint requires admin config."""
return openapi_spec.openapi()["paths"][endpoint][method.lower()].get(
"x-requires-administrator", False
) | [
"def",
"check_requires_administrator",
"(",
"endpoint",
":",
"str",
",",
"method",
":",
"str",
")",
"->",
"bool",
":",
"return",
"openapi_spec",
".",
"openapi",
"(",
")",
"[",
"\"paths\"",
"]",
"[",
"endpoint",
"]",
"[",
"method",
".",
"lower",
"(",
")",... | [
216,
0
] | [
220,
5
] | python | en | ['en', 'en', 'en'] | True |
generate_openapi_fixture | (endpoint: str, method: str, status_code: str = "200") | Generate fixture to be rendered | Generate fixture to be rendered | def generate_openapi_fixture(endpoint: str, method: str, status_code: str = "200") -> List[str]:
"""Generate fixture to be rendered"""
fixture = []
if status_code not in openapi_spec.openapi()["paths"][endpoint][method.lower()]["responses"]:
subschema_count = 0
elif (
"oneOf"
in ... | [
"def",
"generate_openapi_fixture",
"(",
"endpoint",
":",
"str",
",",
"method",
":",
"str",
",",
"status_code",
":",
"str",
"=",
"\"200\"",
")",
"->",
"List",
"[",
"str",
"]",
":",
"fixture",
"=",
"[",
"]",
"if",
"status_code",
"not",
"in",
"openapi_spec"... | [
223,
0
] | [
256,
18
] | python | en | ['en', 'en', 'en'] | True |
get_openapi_description | (endpoint: str, method: str) | Fetch a description from the full spec object. | Fetch a description from the full spec object. | def get_openapi_description(endpoint: str, method: str) -> str:
"""Fetch a description from the full spec object."""
return openapi_spec.openapi()["paths"][endpoint][method.lower()]["description"] | [
"def",
"get_openapi_description",
"(",
"endpoint",
":",
"str",
",",
"method",
":",
"str",
")",
"->",
"str",
":",
"return",
"openapi_spec",
".",
"openapi",
"(",
")",
"[",
"\"paths\"",
"]",
"[",
"endpoint",
"]",
"[",
"method",
".",
"lower",
"(",
")",
"]"... | [
259,
0
] | [
261,
83
] | python | en | ['en', 'en', 'en'] | True |
get_openapi_summary | (endpoint: str, method: str) | Fetch a summary from the full spec object. | Fetch a summary from the full spec object. | def get_openapi_summary(endpoint: str, method: str) -> str:
"""Fetch a summary from the full spec object."""
return openapi_spec.openapi()["paths"][endpoint][method.lower()]["summary"] | [
"def",
"get_openapi_summary",
"(",
"endpoint",
":",
"str",
",",
"method",
":",
"str",
")",
"->",
"str",
":",
"return",
"openapi_spec",
".",
"openapi",
"(",
")",
"[",
"\"paths\"",
"]",
"[",
"endpoint",
"]",
"[",
"method",
".",
"lower",
"(",
")",
"]",
... | [
264,
0
] | [
266,
79
] | python | en | ['en', 'en', 'en'] | True |
fix_events | (content: Dict[str, Any]) | Remove undocumented events from events array. This is a makeshift
function so that further documentation of `/events` can happen with
only zulip.yaml changes and minimal other changes. It should be removed
as soon as `/events` documentation is complete.
| Remove undocumented events from events array. This is a makeshift
function so that further documentation of `/events` can happen with
only zulip.yaml changes and minimal other changes. It should be removed
as soon as `/events` documentation is complete.
| def fix_events(content: Dict[str, Any]) -> None:
"""Remove undocumented events from events array. This is a makeshift
function so that further documentation of `/events` can happen with
only zulip.yaml changes and minimal other changes. It should be removed
as soon as `/events` documentation is complete... | [
"def",
"fix_events",
"(",
"content",
":",
"Dict",
"[",
"str",
",",
"Any",
"]",
")",
"->",
"None",
":",
"# 'user' is deprecated so remove its occurrences from the events array",
"for",
"event",
"in",
"content",
"[",
"\"events\"",
"]",
":",
"event",
".",
"pop",
"(... | [
318,
0
] | [
326,
31
] | python | en | ['en', 'en', 'en'] | True |
validate_against_openapi_schema | (
content: Dict[str, Any],
path: str,
method: str,
status_code: str,
display_brief_error: bool = False,
) | Compare a "content" dict with the defined schema for a specific method
in an endpoint. Return true if validated and false if skipped.
| Compare a "content" dict with the defined schema for a specific method
in an endpoint. Return true if validated and false if skipped.
| def validate_against_openapi_schema(
content: Dict[str, Any],
path: str,
method: str,
status_code: str,
display_brief_error: bool = False,
) -> bool:
"""Compare a "content" dict with the defined schema for a specific method
in an endpoint. Return true if validated and false if skipped.
"... | [
"def",
"validate_against_openapi_schema",
"(",
"content",
":",
"Dict",
"[",
"str",
",",
"Any",
"]",
",",
"path",
":",
"str",
",",
"method",
":",
"str",
",",
"status_code",
":",
"str",
",",
"display_brief_error",
":",
"bool",
"=",
"False",
",",
")",
"->",... | [
329,
0
] | [
416,
15
] | python | en | ['en', 'en', 'en'] | True |
validate_schema | (schema: Dict[str, Any]) | Check if opaque objects are present in the OpenAPI spec; this is an
important part of our policy for ensuring every detail of Zulip's
API responses is correct.
This is done by checking for the presence of the
`additionalProperties` attribute for all objects (dictionaries).
| Check if opaque objects are present in the OpenAPI spec; this is an
important part of our policy for ensuring every detail of Zulip's
API responses is correct. | def validate_schema(schema: Dict[str, Any]) -> None:
"""Check if opaque objects are present in the OpenAPI spec; this is an
important part of our policy for ensuring every detail of Zulip's
API responses is correct.
This is done by checking for the presence of the
`additionalProperties` attribute f... | [
"def",
"validate_schema",
"(",
"schema",
":",
"Dict",
"[",
"str",
",",
"Any",
"]",
")",
"->",
"None",
":",
"if",
"\"oneOf\"",
"in",
"schema",
":",
"for",
"subschema",
"in",
"schema",
"[",
"\"oneOf\"",
"]",
":",
"validate_schema",
"(",
"subschema",
")",
... | [
419,
0
] | [
441,
59
] | python | en | ['en', 'en', 'en'] | True |
to_python_type | (py_type: str) | Transform an OpenAPI-like type to a Python one.
https://swagger.io/docs/specification/data-models/data-types
| Transform an OpenAPI-like type to a Python one.
https://swagger.io/docs/specification/data-models/data-types
| def to_python_type(py_type: str) -> type:
"""Transform an OpenAPI-like type to a Python one.
https://swagger.io/docs/specification/data-models/data-types
"""
TYPES = {
"string": str,
"number": float,
"integer": int,
"boolean": bool,
"array": list,
"object"... | [
"def",
"to_python_type",
"(",
"py_type",
":",
"str",
")",
"->",
"type",
":",
"TYPES",
"=",
"{",
"\"string\"",
":",
"str",
",",
"\"number\"",
":",
"float",
",",
"\"integer\"",
":",
"int",
",",
"\"boolean\"",
":",
"bool",
",",
"\"array\"",
":",
"list",
"... | [
444,
0
] | [
457,
25
] | python | en | ['en', 'haw', 'en'] | True |
OpenAPISpec.openapi | (self) | Reload the OpenAPI file if it has been modified after the last time
it was read, and then return the parsed data.
| Reload the OpenAPI file if it has been modified after the last time
it was read, and then return the parsed data.
| def openapi(self) -> Dict[str, Any]:
"""Reload the OpenAPI file if it has been modified after the last time
it was read, and then return the parsed data.
"""
self.check_reload()
assert len(self._openapi) > 0
return self._openapi | [
"def",
"openapi",
"(",
"self",
")",
"->",
"Dict",
"[",
"str",
",",
"Any",
"]",
":",
"self",
".",
"check_reload",
"(",
")",
"assert",
"len",
"(",
"self",
".",
"_openapi",
")",
">",
"0",
"return",
"self",
".",
"_openapi"
] | [
149,
4
] | [
155,
28
] | python | en | ['en', 'en', 'en'] | True |
OpenAPISpec.endpoints_dict | (self) | Reload the OpenAPI file if it has been modified after the last time
it was read, and then return the parsed data.
| Reload the OpenAPI file if it has been modified after the last time
it was read, and then return the parsed data.
| def endpoints_dict(self) -> Dict[str, str]:
"""Reload the OpenAPI file if it has been modified after the last time
it was read, and then return the parsed data.
"""
self.check_reload()
assert len(self._endpoints_dict) > 0
return self._endpoints_dict | [
"def",
"endpoints_dict",
"(",
"self",
")",
"->",
"Dict",
"[",
"str",
",",
"str",
"]",
":",
"self",
".",
"check_reload",
"(",
")",
"assert",
"len",
"(",
"self",
".",
"_endpoints_dict",
")",
">",
"0",
"return",
"self",
".",
"_endpoints_dict"
] | [
157,
4
] | [
163,
35
] | python | en | ['en', 'en', 'en'] | True |
OpenAPISpec.request_validator | (self) | Reload the OpenAPI file if it has been modified after the last time
it was read, and then return the openapi_core validator object. Similar
to preceding functions. Used for proper access to OpenAPI objects.
| Reload the OpenAPI file if it has been modified after the last time
it was read, and then return the openapi_core validator object. Similar
to preceding functions. Used for proper access to OpenAPI objects.
| def request_validator(self) -> RequestValidator:
"""Reload the OpenAPI file if it has been modified after the last time
it was read, and then return the openapi_core validator object. Similar
to preceding functions. Used for proper access to OpenAPI objects.
"""
self.check_reload... | [
"def",
"request_validator",
"(",
"self",
")",
"->",
"RequestValidator",
":",
"self",
".",
"check_reload",
"(",
")",
"assert",
"self",
".",
"_request_validator",
"is",
"not",
"None",
"return",
"self",
".",
"_request_validator"
] | [
165,
4
] | [
172,
38
] | python | en | ['en', 'en', 'en'] | True |
AddView.get_edit_object_form_context_data | (self) |
Return the context data necessary for rendering the HTML form for editing
an object that has been successfully uploaded
|
Return the context data necessary for rendering the HTML form for editing
an object that has been successfully uploaded
| def get_edit_object_form_context_data(self):
"""
Return the context data necessary for rendering the HTML form for editing
an object that has been successfully uploaded
"""
edit_form_class = self.get_edit_form_class()
return {
self.context_object_name: self.ob... | [
"def",
"get_edit_object_form_context_data",
"(",
"self",
")",
":",
"edit_form_class",
"=",
"self",
".",
"get_edit_form_class",
"(",
")",
"return",
"{",
"self",
".",
"context_object_name",
":",
"self",
".",
"object",
",",
"'edit_action'",
":",
"reverse",
"(",
"se... | [
48,
4
] | [
63,
9
] | python | en | ['en', 'error', 'th'] | False |
AddView.get_edit_object_response_data | (self) |
Return the JSON response data for an object that has been successfully uploaded
|
Return the JSON response data for an object that has been successfully uploaded
| def get_edit_object_response_data(self):
"""
Return the JSON response data for an object that has been successfully uploaded
"""
return {
'success': True,
self.context_object_id_name: int(self.object.id),
'form': render_to_string(
self.... | [
"def",
"get_edit_object_response_data",
"(",
"self",
")",
":",
"return",
"{",
"'success'",
":",
"True",
",",
"self",
".",
"context_object_id_name",
":",
"int",
"(",
"self",
".",
"object",
".",
"id",
")",
",",
"'form'",
":",
"render_to_string",
"(",
"self",
... | [
65,
4
] | [
77,
9
] | python | en | ['en', 'error', 'th'] | False |
AddView.get_edit_upload_form_context_data | (self) |
Return the context data necessary for rendering the HTML form for supplying the
metadata to turn an upload object into a final object
|
Return the context data necessary for rendering the HTML form for supplying the
metadata to turn an upload object into a final object
| def get_edit_upload_form_context_data(self):
"""
Return the context data necessary for rendering the HTML form for supplying the
metadata to turn an upload object into a final object
"""
edit_form_class = self.get_edit_form_class()
return {
self.context_upload... | [
"def",
"get_edit_upload_form_context_data",
"(",
"self",
")",
":",
"edit_form_class",
"=",
"self",
".",
"get_edit_form_class",
"(",
")",
"return",
"{",
"self",
".",
"context_upload_name",
":",
"self",
".",
"upload_object",
",",
"'edit_action'",
":",
"reverse",
"("... | [
79,
4
] | [
94,
9
] | python | en | ['en', 'error', 'th'] | False |
AddView.get_edit_upload_response_data | (self) |
Return the JSON response data for an object that has been uploaded to an
upload object and now needs extra metadata to become a final object
|
Return the JSON response data for an object that has been uploaded to an
upload object and now needs extra metadata to become a final object
| def get_edit_upload_response_data(self):
"""
Return the JSON response data for an object that has been uploaded to an
upload object and now needs extra metadata to become a final object
"""
return {
'success': True,
self.context_upload_id_name: self.upload... | [
"def",
"get_edit_upload_response_data",
"(",
"self",
")",
":",
"return",
"{",
"'success'",
":",
"True",
",",
"self",
".",
"context_upload_id_name",
":",
"self",
".",
"upload_object",
".",
"id",
",",
"'form'",
":",
"render_to_string",
"(",
"self",
".",
"edit_fo... | [
96,
4
] | [
109,
9
] | python | en | ['en', 'error', 'th'] | False |
AddView.get_invalid_response_data | (self, form) |
Return the JSON response data for an invalid form submission
|
Return the JSON response data for an invalid form submission
| def get_invalid_response_data(self, form):
"""
Return the JSON response data for an invalid form submission
"""
return {
'success': False,
'error_message': '\n'.join(form.errors['file']),
} | [
"def",
"get_invalid_response_data",
"(",
"self",
",",
"form",
")",
":",
"return",
"{",
"'success'",
":",
"False",
",",
"'error_message'",
":",
"'\\n'",
".",
"join",
"(",
"form",
".",
"errors",
"[",
"'file'",
"]",
")",
",",
"}"
] | [
111,
4
] | [
118,
9
] | python | en | ['en', 'error', 'th'] | False |
SessionStore.load | (self) |
We load the data from the key itself instead of fetching from
some external data store. Opposite of _get_session_key(),
raises BadSignature if signature fails.
|
We load the data from the key itself instead of fetching from
some external data store. Opposite of _get_session_key(),
raises BadSignature if signature fails.
| def load(self):
"""
We load the data from the key itself instead of fetching from
some external data store. Opposite of _get_session_key(),
raises BadSignature if signature fails.
"""
try:
return signing.loads(
self.session_key,
... | [
"def",
"load",
"(",
"self",
")",
":",
"try",
":",
"return",
"signing",
".",
"loads",
"(",
"self",
".",
"session_key",
",",
"serializer",
"=",
"self",
".",
"serializer",
",",
"# This doesn't handle non-default expiry dates, see #19201",
"max_age",
"=",
"settings",
... | [
7,
4
] | [
25,
17
] | python | en | ['en', 'error', 'th'] | False |
SessionStore.create | (self) |
To create a new key, we simply make sure that the modified flag is set
so that the cookie is set on the client for the current request.
|
To create a new key, we simply make sure that the modified flag is set
so that the cookie is set on the client for the current request.
| def create(self):
"""
To create a new key, we simply make sure that the modified flag is set
so that the cookie is set on the client for the current request.
"""
self.modified = True | [
"def",
"create",
"(",
"self",
")",
":",
"self",
".",
"modified",
"=",
"True"
] | [
27,
4
] | [
32,
28
] | python | en | ['en', 'error', 'th'] | False |
SessionStore.save | (self, must_create=False) |
To save, we get the session key as a securely signed string and then
set the modified flag so that the cookie is set on the client for the
current request.
|
To save, we get the session key as a securely signed string and then
set the modified flag so that the cookie is set on the client for the
current request.
| def save(self, must_create=False):
"""
To save, we get the session key as a securely signed string and then
set the modified flag so that the cookie is set on the client for the
current request.
"""
self._session_key = self._get_session_key()
self.modified = True | [
"def",
"save",
"(",
"self",
",",
"must_create",
"=",
"False",
")",
":",
"self",
".",
"_session_key",
"=",
"self",
".",
"_get_session_key",
"(",
")",
"self",
".",
"modified",
"=",
"True"
] | [
34,
4
] | [
41,
28
] | python | en | ['en', 'error', 'th'] | False |
SessionStore.exists | (self, session_key=None) |
This method makes sense when you're talking to a shared resource, but
it doesn't matter when you're storing the information in the client's
cookie.
|
This method makes sense when you're talking to a shared resource, but
it doesn't matter when you're storing the information in the client's
cookie.
| def exists(self, session_key=None):
"""
This method makes sense when you're talking to a shared resource, but
it doesn't matter when you're storing the information in the client's
cookie.
"""
return False | [
"def",
"exists",
"(",
"self",
",",
"session_key",
"=",
"None",
")",
":",
"return",
"False"
] | [
43,
4
] | [
49,
20
] | python | en | ['en', 'error', 'th'] | False |
SessionStore.delete | (self, session_key=None) |
To delete, we clear the session key and the underlying data structure
and set the modified flag so that the cookie is set on the client for
the current request.
|
To delete, we clear the session key and the underlying data structure
and set the modified flag so that the cookie is set on the client for
the current request.
| def delete(self, session_key=None):
"""
To delete, we clear the session key and the underlying data structure
and set the modified flag so that the cookie is set on the client for
the current request.
"""
self._session_key = ''
self._session_cache = {}
sel... | [
"def",
"delete",
"(",
"self",
",",
"session_key",
"=",
"None",
")",
":",
"self",
".",
"_session_key",
"=",
"''",
"self",
".",
"_session_cache",
"=",
"{",
"}",
"self",
".",
"modified",
"=",
"True"
] | [
51,
4
] | [
59,
28
] | python | en | ['en', 'error', 'th'] | False |
SessionStore.cycle_key | (self) |
Keeps the same data but with a new key. To do this, we just have to
call ``save()`` and it will automatically save a cookie with a new key
at the end of the request.
|
Keeps the same data but with a new key. To do this, we just have to
call ``save()`` and it will automatically save a cookie with a new key
at the end of the request.
| def cycle_key(self):
"""
Keeps the same data but with a new key. To do this, we just have to
call ``save()`` and it will automatically save a cookie with a new key
at the end of the request.
"""
self.save() | [
"def",
"cycle_key",
"(",
"self",
")",
":",
"self",
".",
"save",
"(",
")"
] | [
61,
4
] | [
67,
19
] | python | en | ['en', 'error', 'th'] | False |
SessionStore._get_session_key | (self) |
Most session backends don't need to override this method, but we do,
because instead of generating a random string, we want to actually
generate a secure url-safe Base64-encoded string of data as our
session key.
|
Most session backends don't need to override this method, but we do,
because instead of generating a random string, we want to actually
generate a secure url-safe Base64-encoded string of data as our
session key.
| def _get_session_key(self):
"""
Most session backends don't need to override this method, but we do,
because instead of generating a random string, we want to actually
generate a secure url-safe Base64-encoded string of data as our
session key.
"""
session_cache =... | [
"def",
"_get_session_key",
"(",
"self",
")",
":",
"session_cache",
"=",
"getattr",
"(",
"self",
",",
"'_session_cache'",
",",
"{",
"}",
")",
"return",
"signing",
".",
"dumps",
"(",
"session_cache",
",",
"compress",
"=",
"True",
",",
"salt",
"=",
"'django.c... | [
69,
4
] | [
81,
9
] | python | en | ['en', 'error', 'th'] | False |
dataclass_from_dict | (klass, d) |
Converts a dictionary based on a dataclass, into an instance of that dataclass.
Recursively goes through lists, optionals, and dictionaries.
|
Converts a dictionary based on a dataclass, into an instance of that dataclass.
Recursively goes through lists, optionals, and dictionaries.
| def dataclass_from_dict(klass, d):
"""
Converts a dictionary based on a dataclass, into an instance of that dataclass.
Recursively goes through lists, optionals, and dictionaries.
"""
if is_type_SpecificOptional(klass):
# Type is optional, data is either None, or Any
if not d:
... | [
"def",
"dataclass_from_dict",
"(",
"klass",
",",
"d",
")",
":",
"if",
"is_type_SpecificOptional",
"(",
"klass",
")",
":",
"# Type is optional, data is either None, or Any",
"if",
"not",
"d",
":",
"return",
"None",
"return",
"dataclass_from_dict",
"(",
"get_args",
"(... | [
51,
0
] | [
84,
23
] | python | en | ['en', 'error', 'th'] | False |
recurse_jsonify | (d) |
Makes bytes objects and unhashable types into strings with 0x, and makes large ints into
strings.
|
Makes bytes objects and unhashable types into strings with 0x, and makes large ints into
strings.
| def recurse_jsonify(d):
"""
Makes bytes objects and unhashable types into strings with 0x, and makes large ints into
strings.
"""
if isinstance(d, list) or isinstance(d, tuple):
new_list = []
for item in d:
if type(item) in unhashable_types or issubclass(type(item), bytes... | [
"def",
"recurse_jsonify",
"(",
"d",
")",
":",
"if",
"isinstance",
"(",
"d",
",",
"list",
")",
"or",
"isinstance",
"(",
"d",
",",
"tuple",
")",
":",
"new_list",
"=",
"[",
"]",
"for",
"item",
"in",
"d",
":",
"if",
"type",
"(",
"item",
")",
"in",
... | [
87,
0
] | [
124,
12
] | python | en | ['en', 'error', 'th'] | False |
streamable | (cls: Any) |
This is a decorator for class definitions. It applies the strictdataclass decorator,
which checks all types at construction. It also defines a simple serialization format,
and adds parse, from bytes, stream, and __bytes__ methods.
Serialization format:
- Each field is serialized in order, by calli... |
This is a decorator for class definitions. It applies the strictdataclass decorator,
which checks all types at construction. It also defines a simple serialization format,
and adds parse, from bytes, stream, and __bytes__ methods. | def streamable(cls: Any):
"""
This is a decorator for class definitions. It applies the strictdataclass decorator,
which checks all types at construction. It also defines a simple serialization format,
and adds parse, from bytes, stream, and __bytes__ methods.
Serialization format:
- Each field... | [
"def",
"streamable",
"(",
"cls",
":",
"Any",
")",
":",
"cls1",
"=",
"strictdataclass",
"(",
"cls",
")",
"t",
"=",
"type",
"(",
"cls",
".",
"__name__",
",",
"(",
"cls1",
",",
"Streamable",
")",
",",
"{",
"}",
")",
"parse_functions",
"=",
"[",
"]",
... | [
130,
0
] | [
169,
12
] | python | en | ['en', 'error', 'th'] | False |
Streamable.function_to_parse_one_item | (cls: Type[cls.__name__], f_type: Type) |
This function returns a function taking one argument `f: BinaryIO` that parses
and returns a value of the given type.
|
This function returns a function taking one argument `f: BinaryIO` that parses
and returns a value of the given type.
| def function_to_parse_one_item(cls: Type[cls.__name__], f_type: Type): # type: ignore
"""
This function returns a function taking one argument `f: BinaryIO` that parses
and returns a value of the given type.
"""
inner_type: Type
if f_type is bool:
return pars... | [
"def",
"function_to_parse_one_item",
"(",
"cls",
":",
"Type",
"[",
"cls",
".",
"__name__",
"]",
",",
"f_type",
":",
"Type",
")",
":",
"# type: ignore",
"inner_type",
":",
"Type",
"if",
"f_type",
"is",
"bool",
":",
"return",
"parse_bool",
"if",
"is_type_Speci... | [
238,
4
] | [
267,
71
] | python | en | ['en', 'error', 'th'] | False |
to_sax | (walker, handler) | Call SAX-like content handler based on treewalker walker
:arg walker: the treewalker to use to walk the tree to convert it
:arg handler: SAX handler to use
| Call SAX-like content handler based on treewalker walker | def to_sax(walker, handler):
"""Call SAX-like content handler based on treewalker walker
:arg walker: the treewalker to use to walk the tree to convert it
:arg handler: SAX handler to use
"""
handler.startDocument()
for prefix, namespace in prefix_mapping.items():
handler.startPrefixM... | [
"def",
"to_sax",
"(",
"walker",
",",
"handler",
")",
":",
"handler",
".",
"startDocument",
"(",
")",
"for",
"prefix",
",",
"namespace",
"in",
"prefix_mapping",
".",
"items",
"(",
")",
":",
"handler",
".",
"startPrefixMapping",
"(",
"prefix",
",",
"namespac... | [
12,
0
] | [
49,
25
] | python | en | ['en', 'no', 'en'] | True |
get_document_model_string | () |
Get the dotted ``app.Model`` name for the document model as a string.
Useful for developers making Wagtail plugins that need to refer to the
document model, such as in foreign keys, but the model itself is not required.
|
Get the dotted ``app.Model`` name for the document model as a string.
Useful for developers making Wagtail plugins that need to refer to the
document model, such as in foreign keys, but the model itself is not required.
| def get_document_model_string():
"""
Get the dotted ``app.Model`` name for the document model as a string.
Useful for developers making Wagtail plugins that need to refer to the
document model, such as in foreign keys, but the model itself is not required.
"""
return getattr(settings, 'WAGTAILDO... | [
"def",
"get_document_model_string",
"(",
")",
":",
"return",
"getattr",
"(",
"settings",
",",
"'WAGTAILDOCS_DOCUMENT_MODEL'",
",",
"'wagtaildocs.Document'",
")"
] | [
7,
0
] | [
13,
82
] | python | en | ['en', 'error', 'th'] | False |
get_document_model | () |
Get the document model from the ``WAGTAILDOCS_DOCUMENT_MODEL`` setting.
Defaults to the standard :class:`~wagtail.documents.models.Document` model
if no custom model is defined.
|
Get the document model from the ``WAGTAILDOCS_DOCUMENT_MODEL`` setting.
Defaults to the standard :class:`~wagtail.documents.models.Document` model
if no custom model is defined.
| def get_document_model():
"""
Get the document model from the ``WAGTAILDOCS_DOCUMENT_MODEL`` setting.
Defaults to the standard :class:`~wagtail.documents.models.Document` model
if no custom model is defined.
"""
from django.apps import apps
model_string = get_document_model_string()
try:... | [
"def",
"get_document_model",
"(",
")",
":",
"from",
"django",
".",
"apps",
"import",
"apps",
"model_string",
"=",
"get_document_model_string",
"(",
")",
"try",
":",
"return",
"apps",
".",
"get_model",
"(",
"model_string",
")",
"except",
"ValueError",
":",
"rai... | [
16,
0
] | [
31,
9
] | python | en | ['en', 'error', 'th'] | False |
Notification.is_successful | (self) | Return whether the notification was created successfully. This means that:
* self.status == 'successful'
* self.error == False
| Return whether the notification was created successfully. This means that:
* self.status == 'successful'
* self.error == False
| def is_successful(self):
"""Return whether the notification was created successfully. This means that:
* self.status == 'successful'
* self.error == False
"""
return super(Notification, self).is_successful and not self.error | [
"def",
"is_successful",
"(",
"self",
")",
":",
"return",
"super",
"(",
"Notification",
",",
"self",
")",
".",
"is_successful",
"and",
"not",
"self",
".",
"error"
] | [
17,
4
] | [
22,
73
] | python | en | ['en', 'en', 'en'] | True |
Notification.wait_until_completed | (self, interval=5, timeout=240) | Notifications need a longer timeout, since the backend often has
to wait for the request (sending the notification) to timeout itself
| Notifications need a longer timeout, since the backend often has
to wait for the request (sending the notification) to timeout itself
| def wait_until_completed(self, interval=5, timeout=240):
"""Notifications need a longer timeout, since the backend often has
to wait for the request (sending the notification) to timeout itself
"""
adjusted_timeout = timeout - seconds_since_date_string(self.created)
return super(... | [
"def",
"wait_until_completed",
"(",
"self",
",",
"interval",
"=",
"5",
",",
"timeout",
"=",
"240",
")",
":",
"adjusted_timeout",
"=",
"timeout",
"-",
"seconds_since_date_string",
"(",
"self",
".",
"created",
")",
"return",
"super",
"(",
"Notification",
",",
... | [
28,
4
] | [
33,
89
] | python | en | ['en', 'en', 'en'] | True |
Notifications.wait_until_count | (self, count, interval=10, timeout=60, **kw) | Poll notifications page until it is populated with `count` number of notifications. | Poll notifications page until it is populated with `count` number of notifications. | def wait_until_count(self, count, interval=10, timeout=60, **kw):
"""Poll notifications page until it is populated with `count` number of notifications."""
poll_until(lambda: getattr(self.get(), 'count') == count, interval=interval, timeout=timeout, **kw)
return self | [
"def",
"wait_until_count",
"(",
"self",
",",
"count",
",",
"interval",
"=",
"10",
",",
"timeout",
"=",
"60",
",",
"*",
"*",
"kw",
")",
":",
"poll_until",
"(",
"lambda",
":",
"getattr",
"(",
"self",
".",
"get",
"(",
")",
",",
"'count'",
")",
"==",
... | [
40,
4
] | [
43,
19
] | python | en | ['en', 'en', 'en'] | True |
render_to_response | (template_name, context=None, content_type=None, status=None, using=None) |
Returns a HttpResponse whose content is filled with the result of calling
django.template.loader.render_to_string() with the passed arguments.
|
Returns a HttpResponse whose content is filled with the result of calling
django.template.loader.render_to_string() with the passed arguments.
| def render_to_response(template_name, context=None, content_type=None, status=None, using=None):
"""
Returns a HttpResponse whose content is filled with the result of calling
django.template.loader.render_to_string() with the passed arguments.
"""
content = loader.render_to_string(template_name, con... | [
"def",
"render_to_response",
"(",
"template_name",
",",
"context",
"=",
"None",
",",
"content_type",
"=",
"None",
",",
"status",
"=",
"None",
",",
"using",
"=",
"None",
")",
":",
"content",
"=",
"loader",
".",
"render_to_string",
"(",
"template_name",
",",
... | [
15,
0
] | [
21,
54
] | python | en | ['en', 'error', 'th'] | False |
render | (request, template_name, context=None, content_type=None, status=None, using=None) |
Returns a HttpResponse whose content is filled with the result of calling
django.template.loader.render_to_string() with the passed arguments.
|
Returns a HttpResponse whose content is filled with the result of calling
django.template.loader.render_to_string() with the passed arguments.
| def render(request, template_name, context=None, content_type=None, status=None, using=None):
"""
Returns a HttpResponse whose content is filled with the result of calling
django.template.loader.render_to_string() with the passed arguments.
"""
content = loader.render_to_string(template_name, contex... | [
"def",
"render",
"(",
"request",
",",
"template_name",
",",
"context",
"=",
"None",
",",
"content_type",
"=",
"None",
",",
"status",
"=",
"None",
",",
"using",
"=",
"None",
")",
":",
"content",
"=",
"loader",
".",
"render_to_string",
"(",
"template_name",
... | [
24,
0
] | [
30,
54
] | python | en | ['en', 'error', 'th'] | False |
redirect | (to, *args, **kwargs) |
Returns an HttpResponseRedirect to the appropriate URL for the arguments
passed.
The arguments could be:
* A model: the model's `get_absolute_url()` function will be called.
* A view name, possibly with arguments: `urls.reverse()` will be used
to reverse-resolve the name.
... |
Returns an HttpResponseRedirect to the appropriate URL for the arguments
passed. | def redirect(to, *args, **kwargs):
"""
Returns an HttpResponseRedirect to the appropriate URL for the arguments
passed.
The arguments could be:
* A model: the model's `get_absolute_url()` function will be called.
* A view name, possibly with arguments: `urls.reverse()` will be used
... | [
"def",
"redirect",
"(",
"to",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"kwargs",
".",
"pop",
"(",
"'permanent'",
",",
"False",
")",
":",
"redirect_class",
"=",
"HttpResponsePermanentRedirect",
"else",
":",
"redirect_class",
"=",
"HttpResp... | [
33,
0
] | [
55,
59
] | python | en | ['en', 'error', 'th'] | False |
_get_queryset | (klass) |
Return a QuerySet or a Manager.
Duck typing in action: any class with a `get()` method (for
get_object_or_404) or a `filter()` method (for get_list_or_404) might do
the job.
|
Return a QuerySet or a Manager.
Duck typing in action: any class with a `get()` method (for
get_object_or_404) or a `filter()` method (for get_list_or_404) might do
the job.
| def _get_queryset(klass):
"""
Return a QuerySet or a Manager.
Duck typing in action: any class with a `get()` method (for
get_object_or_404) or a `filter()` method (for get_list_or_404) might do
the job.
"""
# If it is a model class or anything else with ._default_manager
if hasattr(klas... | [
"def",
"_get_queryset",
"(",
"klass",
")",
":",
"# If it is a model class or anything else with ._default_manager",
"if",
"hasattr",
"(",
"klass",
",",
"'_default_manager'",
")",
":",
"return",
"klass",
".",
"_default_manager",
".",
"all",
"(",
")",
"return",
"klass"
... | [
58,
0
] | [
68,
16
] | python | en | ['en', 'error', 'th'] | False |
get_object_or_404 | (klass, *args, **kwargs) |
Uses get() to return an object, or raises a Http404 exception if the object
does not exist.
klass may be a Model, Manager, or QuerySet object. All other passed
arguments and keyword arguments are used in the get() query.
Note: Like with get(), an MultipleObjectsReturned will be raised if more tha... |
Uses get() to return an object, or raises a Http404 exception if the object
does not exist. | def get_object_or_404(klass, *args, **kwargs):
"""
Uses get() to return an object, or raises a Http404 exception if the object
does not exist.
klass may be a Model, Manager, or QuerySet object. All other passed
arguments and keyword arguments are used in the get() query.
Note: Like with get(),... | [
"def",
"get_object_or_404",
"(",
"klass",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"queryset",
"=",
"_get_queryset",
"(",
"klass",
")",
"try",
":",
"return",
"queryset",
".",
"get",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"except"... | [
71,
0
] | [
92,
90
] | python | en | ['en', 'error', 'th'] | False |
get_list_or_404 | (klass, *args, **kwargs) |
Uses filter() to return a list of objects, or raise a Http404 exception if
the list is empty.
klass may be a Model, Manager, or QuerySet object. All other passed
arguments and keyword arguments are used in the filter() query.
|
Uses filter() to return a list of objects, or raise a Http404 exception if
the list is empty. | def get_list_or_404(klass, *args, **kwargs):
"""
Uses filter() to return a list of objects, or raise a Http404 exception if
the list is empty.
klass may be a Model, Manager, or QuerySet object. All other passed
arguments and keyword arguments are used in the filter() query.
"""
queryset = _... | [
"def",
"get_list_or_404",
"(",
"klass",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"queryset",
"=",
"_get_queryset",
"(",
"klass",
")",
"try",
":",
"obj_list",
"=",
"list",
"(",
"queryset",
".",
"filter",
"(",
"*",
"args",
",",
"*",
"*",
... | [
95,
0
] | [
114,
19
] | python | en | ['en', 'error', 'th'] | False |
resolve_url | (to, *args, **kwargs) |
Return a URL appropriate for the arguments passed.
The arguments could be:
* A model: the model's `get_absolute_url()` function will be called.
* A view name, possibly with arguments: `urls.reverse()` will be used
to reverse-resolve the name.
* A URL, which will be returne... |
Return a URL appropriate for the arguments passed. | def resolve_url(to, *args, **kwargs):
"""
Return a URL appropriate for the arguments passed.
The arguments could be:
* A model: the model's `get_absolute_url()` function will be called.
* A view name, possibly with arguments: `urls.reverse()` will be used
to reverse-resolve the ... | [
"def",
"resolve_url",
"(",
"to",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# If it's a model, use get_absolute_url()",
"if",
"hasattr",
"(",
"to",
",",
"'get_absolute_url'",
")",
":",
"return",
"to",
".",
"get_absolute_url",
"(",
")",
"if",
"isin... | [
117,
0
] | [
156,
13
] | python | en | ['en', 'error', 'th'] | False |
connect | (dsn=None, connection_factory=None, cursor_factory=None, **kwargs) |
Create a new database connection.
The connection parameters can be specified as a string:
conn = psycopg2.connect("dbname=test user=postgres password=secret")
or using a set of keyword arguments:
conn = psycopg2.connect(database="test", user="postgres", password="secret")
Or as a m... |
Create a new database connection. | def connect(dsn=None, connection_factory=None, cursor_factory=None, **kwargs):
"""
Create a new database connection.
The connection parameters can be specified as a string:
conn = psycopg2.connect("dbname=test user=postgres password=secret")
or using a set of keyword arguments:
conn ... | [
"def",
"connect",
"(",
"dsn",
"=",
"None",
",",
"connection_factory",
"=",
"None",
",",
"cursor_factory",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"kwasync",
"=",
"{",
"}",
"if",
"'async'",
"in",
"kwargs",
":",
"kwasync",
"[",
"'async'",
"]",
... | [
84,
0
] | [
133,
15
] | python | en | ['en', 'error', 'th'] | False |
srs_double | (f) |
Creates a function prototype for the OSR routines that take
the OSRSpatialReference object and
|
Creates a function prototype for the OSR routines that take
the OSRSpatialReference object and
| def srs_double(f):
"""
Creates a function prototype for the OSR routines that take
the OSRSpatialReference object and
"""
return double_output(f, [c_void_p, POINTER(c_int)], errcheck=True) | [
"def",
"srs_double",
"(",
"f",
")",
":",
"return",
"double_output",
"(",
"f",
",",
"[",
"c_void_p",
",",
"POINTER",
"(",
"c_int",
")",
"]",
",",
"errcheck",
"=",
"True",
")"
] | [
10,
0
] | [
15,
70
] | python | en | ['en', 'error', 'th'] | False |
units_func | (f) |
Creates a ctypes function prototype for OSR units functions, e.g.,
OSRGetAngularUnits, OSRGetLinearUnits.
|
Creates a ctypes function prototype for OSR units functions, e.g.,
OSRGetAngularUnits, OSRGetLinearUnits.
| def units_func(f):
"""
Creates a ctypes function prototype for OSR units functions, e.g.,
OSRGetAngularUnits, OSRGetLinearUnits.
"""
return double_output(f, [c_void_p, POINTER(c_char_p)], strarg=True) | [
"def",
"units_func",
"(",
"f",
")",
":",
"return",
"double_output",
"(",
"f",
",",
"[",
"c_void_p",
",",
"POINTER",
"(",
"c_char_p",
")",
"]",
",",
"strarg",
"=",
"True",
")"
] | [
18,
0
] | [
23,
71
] | python | en | ['en', 'error', 'th'] | False |
mempool_assert_announcement | (condition: ConditionWithArgs, announcements: Set[bytes32]) |
Check if an announcement is included in the list of announcements
|
Check if an announcement is included in the list of announcements
| def mempool_assert_announcement(condition: ConditionWithArgs, announcements: Set[bytes32]) -> Optional[Err]:
"""
Check if an announcement is included in the list of announcements
"""
announcement_hash = bytes32(condition.vars[0])
if announcement_hash not in announcements:
return Err.ASSERT_A... | [
"def",
"mempool_assert_announcement",
"(",
"condition",
":",
"ConditionWithArgs",
",",
"announcements",
":",
"Set",
"[",
"bytes32",
"]",
")",
"->",
"Optional",
"[",
"Err",
"]",
":",
"announcement_hash",
"=",
"bytes32",
"(",
"condition",
".",
"vars",
"[",
"0",
... | [
22,
0
] | [
30,
15
] | python | en | ['en', 'error', 'th'] | False |
mempool_assert_my_coin_id | (condition: ConditionWithArgs, unspent: CoinRecord) |
Checks if CoinID matches the id from the condition
|
Checks if CoinID matches the id from the condition
| def mempool_assert_my_coin_id(condition: ConditionWithArgs, unspent: CoinRecord) -> Optional[Err]:
"""
Checks if CoinID matches the id from the condition
"""
if unspent.coin.name() != condition.vars[0]:
return Err.ASSERT_MY_COIN_ID_FAILED
return None | [
"def",
"mempool_assert_my_coin_id",
"(",
"condition",
":",
"ConditionWithArgs",
",",
"unspent",
":",
"CoinRecord",
")",
"->",
"Optional",
"[",
"Err",
"]",
":",
"if",
"unspent",
".",
"coin",
".",
"name",
"(",
")",
"!=",
"condition",
".",
"vars",
"[",
"0",
... | [
33,
0
] | [
39,
15
] | python | en | ['en', 'error', 'th'] | False |
mempool_assert_absolute_block_height_exceeds | (
condition: ConditionWithArgs, prev_transaction_block_height: uint32
) |
Checks if the next block index exceeds the block index from the condition
|
Checks if the next block index exceeds the block index from the condition
| def mempool_assert_absolute_block_height_exceeds(
condition: ConditionWithArgs, prev_transaction_block_height: uint32
) -> Optional[Err]:
"""
Checks if the next block index exceeds the block index from the condition
"""
try:
block_index_exceeds_this = int_from_bytes(condition.vars[0])
ex... | [
"def",
"mempool_assert_absolute_block_height_exceeds",
"(",
"condition",
":",
"ConditionWithArgs",
",",
"prev_transaction_block_height",
":",
"uint32",
")",
"->",
"Optional",
"[",
"Err",
"]",
":",
"try",
":",
"block_index_exceeds_this",
"=",
"int_from_bytes",
"(",
"cond... | [
42,
0
] | [
54,
15
] | python | en | ['en', 'error', 'th'] | False |
mempool_assert_relative_block_height_exceeds | (
condition: ConditionWithArgs, unspent: CoinRecord, prev_transaction_block_height: uint32
) |
Checks if the coin age exceeds the age from the condition
|
Checks if the coin age exceeds the age from the condition
| def mempool_assert_relative_block_height_exceeds(
condition: ConditionWithArgs, unspent: CoinRecord, prev_transaction_block_height: uint32
) -> Optional[Err]:
"""
Checks if the coin age exceeds the age from the condition
"""
try:
expected_block_age = int_from_bytes(condition.vars[0])
... | [
"def",
"mempool_assert_relative_block_height_exceeds",
"(",
"condition",
":",
"ConditionWithArgs",
",",
"unspent",
":",
"CoinRecord",
",",
"prev_transaction_block_height",
":",
"uint32",
")",
"->",
"Optional",
"[",
"Err",
"]",
":",
"try",
":",
"expected_block_age",
"=... | [
57,
0
] | [
70,
15
] | python | en | ['en', 'error', 'th'] | False |
mempool_assert_absolute_time_exceeds | (condition: ConditionWithArgs, timestamp: uint64) |
Check if the current time in seconds exceeds the time specified by condition
|
Check if the current time in seconds exceeds the time specified by condition
| def mempool_assert_absolute_time_exceeds(condition: ConditionWithArgs, timestamp: uint64) -> Optional[Err]:
"""
Check if the current time in seconds exceeds the time specified by condition
"""
try:
expected_seconds = int_from_bytes(condition.vars[0])
except ValueError:
return Err.INV... | [
"def",
"mempool_assert_absolute_time_exceeds",
"(",
"condition",
":",
"ConditionWithArgs",
",",
"timestamp",
":",
"uint64",
")",
"->",
"Optional",
"[",
"Err",
"]",
":",
"try",
":",
"expected_seconds",
"=",
"int_from_bytes",
"(",
"condition",
".",
"vars",
"[",
"0... | [
73,
0
] | [
86,
15
] | python | en | ['en', 'error', 'th'] | False |
mempool_assert_relative_time_exceeds | (
condition: ConditionWithArgs, unspent: CoinRecord, timestamp: uint64
) |
Check if the current time in seconds exceeds the time specified by condition
|
Check if the current time in seconds exceeds the time specified by condition
| def mempool_assert_relative_time_exceeds(
condition: ConditionWithArgs, unspent: CoinRecord, timestamp: uint64
) -> Optional[Err]:
"""
Check if the current time in seconds exceeds the time specified by condition
"""
try:
expected_seconds = int_from_bytes(condition.vars[0])
except ValueEr... | [
"def",
"mempool_assert_relative_time_exceeds",
"(",
"condition",
":",
"ConditionWithArgs",
",",
"unspent",
":",
"CoinRecord",
",",
"timestamp",
":",
"uint64",
")",
"->",
"Optional",
"[",
"Err",
"]",
":",
"try",
":",
"expected_seconds",
"=",
"int_from_bytes",
"(",
... | [
89,
0
] | [
104,
15
] | python | en | ['en', 'error', 'th'] | False |
mempool_assert_my_parent_id | (condition: ConditionWithArgs, unspent: CoinRecord) |
Checks if coin's parent ID matches the ID from the condition
|
Checks if coin's parent ID matches the ID from the condition
| def mempool_assert_my_parent_id(condition: ConditionWithArgs, unspent: CoinRecord) -> Optional[Err]:
"""
Checks if coin's parent ID matches the ID from the condition
"""
if unspent.coin.parent_coin_info != condition.vars[0]:
return Err.ASSERT_MY_PARENT_ID_FAILED
return None | [
"def",
"mempool_assert_my_parent_id",
"(",
"condition",
":",
"ConditionWithArgs",
",",
"unspent",
":",
"CoinRecord",
")",
"->",
"Optional",
"[",
"Err",
"]",
":",
"if",
"unspent",
".",
"coin",
".",
"parent_coin_info",
"!=",
"condition",
".",
"vars",
"[",
"0",
... | [
107,
0
] | [
113,
15
] | python | en | ['en', 'error', 'th'] | False |
mempool_assert_my_puzzlehash | (condition: ConditionWithArgs, unspent: CoinRecord) |
Checks if coin's puzzlehash matches the puzzlehash from the condition
|
Checks if coin's puzzlehash matches the puzzlehash from the condition
| def mempool_assert_my_puzzlehash(condition: ConditionWithArgs, unspent: CoinRecord) -> Optional[Err]:
"""
Checks if coin's puzzlehash matches the puzzlehash from the condition
"""
if unspent.coin.puzzle_hash != condition.vars[0]:
return Err.ASSERT_MY_PUZZLEHASH_FAILED
return None | [
"def",
"mempool_assert_my_puzzlehash",
"(",
"condition",
":",
"ConditionWithArgs",
",",
"unspent",
":",
"CoinRecord",
")",
"->",
"Optional",
"[",
"Err",
"]",
":",
"if",
"unspent",
".",
"coin",
".",
"puzzle_hash",
"!=",
"condition",
".",
"vars",
"[",
"0",
"]"... | [
116,
0
] | [
122,
15
] | python | en | ['en', 'error', 'th'] | False |
mempool_assert_my_amount | (condition: ConditionWithArgs, unspent: CoinRecord) |
Checks if coin's amount matches the amount from the condition
|
Checks if coin's amount matches the amount from the condition
| def mempool_assert_my_amount(condition: ConditionWithArgs, unspent: CoinRecord) -> Optional[Err]:
"""
Checks if coin's amount matches the amount from the condition
"""
if unspent.coin.amount != int_from_bytes(condition.vars[0]):
return Err.ASSERT_MY_AMOUNT_FAILED
return None | [
"def",
"mempool_assert_my_amount",
"(",
"condition",
":",
"ConditionWithArgs",
",",
"unspent",
":",
"CoinRecord",
")",
"->",
"Optional",
"[",
"Err",
"]",
":",
"if",
"unspent",
".",
"coin",
".",
"amount",
"!=",
"int_from_bytes",
"(",
"condition",
".",
"vars",
... | [
125,
0
] | [
131,
15
] | python | en | ['en', 'error', 'th'] | False |
mempool_check_conditions_dict | (
unspent: CoinRecord,
coin_announcement_names: Set[bytes32],
puzzle_announcement_names: Set[bytes32],
conditions_dict: Dict[ConditionOpcode, List[ConditionWithArgs]],
prev_transaction_block_height: uint32,
timestamp: uint64,
) |
Check all conditions against current state.
|
Check all conditions against current state.
| def mempool_check_conditions_dict(
unspent: CoinRecord,
coin_announcement_names: Set[bytes32],
puzzle_announcement_names: Set[bytes32],
conditions_dict: Dict[ConditionOpcode, List[ConditionWithArgs]],
prev_transaction_block_height: uint32,
timestamp: uint64,
) -> Optional[Err]:
"""
Check... | [
"def",
"mempool_check_conditions_dict",
"(",
"unspent",
":",
"CoinRecord",
",",
"coin_announcement_names",
":",
"Set",
"[",
"bytes32",
"]",
",",
"puzzle_announcement_names",
":",
"Set",
"[",
"bytes32",
"]",
",",
"conditions_dict",
":",
"Dict",
"[",
"ConditionOpcode"... | [
190,
0
] | [
228,
15
] | python | en | ['en', 'error', 'th'] | False |
test_initialisation_with_mixins | (self) |
The order of child blocks of a ``StreamBlock`` with multiple parent
classes is slightly surprising at first. Child blocks are inherited in
a bottom-up order, by traversing the MRO in reverse. In the example
below, ``ArticleWithIntroBlock`` will have an MRO of::
[ArticleWith... |
The order of child blocks of a ``StreamBlock`` with multiple parent
classes is slightly surprising at first. Child blocks are inherited in
a bottom-up order, by traversing the MRO in reverse. In the example
below, ``ArticleWithIntroBlock`` will have an MRO of:: | def test_initialisation_with_mixins(self):
"""
The order of child blocks of a ``StreamBlock`` with multiple parent
classes is slightly surprising at first. Child blocks are inherited in
a bottom-up order, by traversing the MRO in reverse. In the example
below, ``ArticleWithIntroB... | [
"def",
"test_initialisation_with_mixins",
"(",
"self",
")",
":",
"class",
"ArticleBlock",
"(",
"blocks",
".",
"StreamBlock",
")",
":",
"heading",
"=",
"blocks",
".",
"CharBlock",
"(",
")",
"paragraph",
"=",
"blocks",
".",
"CharBlock",
"(",
")",
"class",
"Int... | [
2465,
4
] | [
2491,
70
] | python | en | ['en', 'error', 'th'] | False |
test_get_api_representation_calls_same_method_on_children_with_context | (self) |
The get_api_representation method of a StreamBlock should invoke
the block's get_api_representation method on each child and
the context should be passed on.
|
The get_api_representation method of a StreamBlock should invoke
the block's get_api_representation method on each child and
the context should be passed on.
| def test_get_api_representation_calls_same_method_on_children_with_context(self):
"""
The get_api_representation method of a StreamBlock should invoke
the block's get_api_representation method on each child and
the context should be passed on.
"""
class ContextBlock(block... | [
"def",
"test_get_api_representation_calls_same_method_on_children_with_context",
"(",
"self",
")",
":",
"class",
"ContextBlock",
"(",
"blocks",
".",
"CharBlock",
")",
":",
"def",
"get_api_representation",
"(",
"self",
",",
"value",
",",
"context",
"=",
"None",
")",
... | [
2551,
4
] | [
2581,
9
] | python | en | ['en', 'error', 'th'] | False |
test_render_calls_block_render_on_children | (self) |
The default rendering of a StreamBlock should invoke the block's render method
on each child, rather than just outputting the child value as a string.
|
The default rendering of a StreamBlock should invoke the block's render method
on each child, rather than just outputting the child value as a string.
| def test_render_calls_block_render_on_children(self):
"""
The default rendering of a StreamBlock should invoke the block's render method
on each child, rather than just outputting the child value as a string.
"""
block = blocks.StreamBlock([
('heading', blocks.CharBlo... | [
"def",
"test_render_calls_block_render_on_children",
"(",
"self",
")",
":",
"block",
"=",
"blocks",
".",
"StreamBlock",
"(",
"[",
"(",
"'heading'",
",",
"blocks",
".",
"CharBlock",
"(",
"template",
"=",
"'tests/blocks/heading_block.html'",
")",
")",
",",
"(",
"'... | [
2619,
4
] | [
2637,
78
] | python | en | ['en', 'error', 'th'] | False |
test_render_on_stream_child_uses_child_template | (self) |
Accessing a child element of the stream (giving a StreamChild object) and rendering it
should use the block template, not just render the value's string representation
|
Accessing a child element of the stream (giving a StreamChild object) and rendering it
should use the block template, not just render the value's string representation
| def test_render_on_stream_child_uses_child_template(self):
"""
Accessing a child element of the stream (giving a StreamChild object) and rendering it
should use the block template, not just render the value's string representation
"""
block = blocks.StreamBlock([
('he... | [
"def",
"test_render_on_stream_child_uses_child_template",
"(",
"self",
")",
":",
"block",
"=",
"blocks",
".",
"StreamBlock",
"(",
"[",
"(",
"'heading'",
",",
"blocks",
".",
"CharBlock",
"(",
"template",
"=",
"'tests/blocks/heading_block.html'",
")",
")",
",",
"(",... | [
2659,
4
] | [
2680,
48
] | python | en | ['en', 'error', 'th'] | False |
TestFieldBlock.test_charblock_adapter_form_classname | (self) |
Meta data test for FormField; this checks if both the meta values
form_classname and classname are accepted and are rendered
in the form
|
Meta data test for FormField; this checks if both the meta values
form_classname and classname are accepted and are rendered
in the form
| def test_charblock_adapter_form_classname(self):
"""
Meta data test for FormField; this checks if both the meta values
form_classname and classname are accepted and are rendered
in the form
"""
block = blocks.CharBlock(
form_classname='special-char-formclassna... | [
"def",
"test_charblock_adapter_form_classname",
"(",
"self",
")",
":",
"block",
"=",
"blocks",
".",
"CharBlock",
"(",
"form_classname",
"=",
"'special-char-formclassname'",
")",
"block",
".",
"set_name",
"(",
"'test_block'",
")",
"js_args",
"=",
"FieldBlockAdapter",
... | [
79,
4
] | [
99,
73
] | python | en | ['en', 'error', 'th'] | False |
TestFieldBlock.test_searchable_content | (self) |
FieldBlock should not return anything for `get_searchable_content` by
default. Subclasses are free to override it and provide relevant
content.
|
FieldBlock should not return anything for `get_searchable_content` by
default. Subclasses are free to override it and provide relevant
content.
| def test_searchable_content(self):
"""
FieldBlock should not return anything for `get_searchable_content` by
default. Subclasses are free to override it and provide relevant
content.
"""
class CustomBlock(blocks.FieldBlock):
field = forms.CharField(required=Tr... | [
"def",
"test_searchable_content",
"(",
"self",
")",
":",
"class",
"CustomBlock",
"(",
"blocks",
".",
"FieldBlock",
")",
":",
"field",
"=",
"forms",
".",
"CharField",
"(",
"required",
"=",
"True",
")",
"block",
"=",
"CustomBlock",
"(",
")",
"self",
".",
"... | [
170,
4
] | [
179,
69
] | python | en | ['en', 'error', 'th'] | False |
TestFieldBlock.test_prepare_value_called | (self) |
Check that Field.prepare_value is called before sending the value to
the widget for rendering.
Actual real-world use case: A Youtube field that produces YoutubeVideo
instances from IDs, but videos are entered using their full URLs.
|
Check that Field.prepare_value is called before sending the value to
the widget for rendering. | def test_prepare_value_called(self):
"""
Check that Field.prepare_value is called before sending the value to
the widget for rendering.
Actual real-world use case: A Youtube field that produces YoutubeVideo
instances from IDs, but videos are entered using their full URLs.
... | [
"def",
"test_prepare_value_called",
"(",
"self",
")",
":",
"class",
"PrefixWrapper",
":",
"prefix",
"=",
"'http://example.com/'",
"def",
"__init__",
"(",
"self",
",",
"value",
")",
":",
"self",
".",
"value",
"=",
"value",
"def",
"with_prefix",
"(",
"self",
"... | [
198,
4
] | [
248,
57
] | python | en | ['en', 'error', 'th'] | False |
TestMeta.test_meta_nested_inheritance | (self) |
Check that having a multi-level inheritance chain works
|
Check that having a multi-level inheritance chain works
| def test_meta_nested_inheritance(self):
"""
Check that having a multi-level inheritance chain works
"""
class HeadingBlock(blocks.CharBlock):
class Meta:
template = 'heading.html'
test = 'Foo'
class SubHeadingBlock(HeadingBlock):
... | [
"def",
"test_meta_nested_inheritance",
"(",
"self",
")",
":",
"class",
"HeadingBlock",
"(",
"blocks",
".",
"CharBlock",
")",
":",
"class",
"Meta",
":",
"template",
"=",
"'heading.html'",
"test",
"=",
"'Foo'",
"class",
"SubHeadingBlock",
"(",
"HeadingBlock",
")",... | [
1373,
4
] | [
1388,
48
] | python | en | ['en', 'error', 'th'] | False |
TestMeta.test_meta_multi_inheritance | (self) |
Check that multi-inheritance and Meta classes work together
|
Check that multi-inheritance and Meta classes work together
| def test_meta_multi_inheritance(self):
"""
Check that multi-inheritance and Meta classes work together
"""
class LeftBlock(blocks.CharBlock):
class Meta:
template = 'template.html'
clash = 'the band'
label = 'Left block'
... | [
"def",
"test_meta_multi_inheritance",
"(",
"self",
")",
":",
"class",
"LeftBlock",
"(",
"blocks",
".",
"CharBlock",
")",
":",
"class",
"Meta",
":",
"template",
"=",
"'template.html'",
"clash",
"=",
"'the band'",
"label",
"=",
"'Left block'",
"class",
"RightBlock... | [
1390,
4
] | [
1421,
57
] | python | en | ['en', 'error', 'th'] | False |
TestStructBlock.test_initialisation_with_mixins | (self) |
The order of fields of classes with multiple parent classes is slightly
surprising at first. Child fields are inherited in a bottom-up order,
by traversing the MRO in reverse. In the example below,
``StyledLinkBlock`` will have an MRO of::
[StyledLinkBlock, StylingMixin, Li... |
The order of fields of classes with multiple parent classes is slightly
surprising at first. Child fields are inherited in a bottom-up order,
by traversing the MRO in reverse. In the example below,
``StyledLinkBlock`` will have an MRO of:: | def test_initialisation_with_mixins(self):
"""
The order of fields of classes with multiple parent classes is slightly
surprising at first. Child fields are inherited in a bottom-up order,
by traversing the MRO in reverse. In the example below,
``StyledLinkBlock`` will have an MR... | [
"def",
"test_initialisation_with_mixins",
"(",
"self",
")",
":",
"class",
"LinkBlock",
"(",
"blocks",
".",
"StructBlock",
")",
":",
"title",
"=",
"blocks",
".",
"CharBlock",
"(",
")",
"link",
"=",
"blocks",
".",
"URLBlock",
"(",
")",
"class",
"StylingMixin",... | [
1465,
4
] | [
1491,
66
] | python | en | ['en', 'error', 'th'] | False |
TestStructBlock.test_get_api_representation_calls_same_method_on_fields_with_context | (self) |
The get_api_representation method of a StructBlock should invoke
the block's get_api_representation method on each field and the
context should be passed on.
|
The get_api_representation method of a StructBlock should invoke
the block's get_api_representation method on each field and the
context should be passed on.
| def test_get_api_representation_calls_same_method_on_fields_with_context(self):
"""
The get_api_representation method of a StructBlock should invoke
the block's get_api_representation method on each field and the
context should be passed on.
"""
class ContextBlock(blocks.... | [
"def",
"test_get_api_representation_calls_same_method_on_fields_with_context",
"(",
"self",
")",
":",
"class",
"ContextBlock",
"(",
"blocks",
".",
"CharBlock",
")",
":",
"def",
"get_api_representation",
"(",
"self",
",",
"value",
",",
"context",
"=",
"None",
")",
":... | [
1514,
4
] | [
1545,
9
] | python | en | ['en', 'error', 'th'] | False |
TestStructBlock.test_default_is_returned_as_structvalue | (self) | When returning the default value of a StructBlock (e.g. because it's
a child of another StructBlock, and the outer value is missing that key)
we should receive it as a StructValue, not just a plain dict | When returning the default value of a StructBlock (e.g. because it's
a child of another StructBlock, and the outer value is missing that key)
we should receive it as a StructValue, not just a plain dict | def test_default_is_returned_as_structvalue(self):
"""When returning the default value of a StructBlock (e.g. because it's
a child of another StructBlock, and the outer value is missing that key)
we should receive it as a StructValue, not just a plain dict"""
class PersonBlock(blocks.Str... | [
"def",
"test_default_is_returned_as_structvalue",
"(",
"self",
")",
":",
"class",
"PersonBlock",
"(",
"blocks",
".",
"StructBlock",
")",
":",
"first_name",
"=",
"blocks",
".",
"CharBlock",
"(",
")",
"surname",
"=",
"blocks",
".",
"CharBlock",
"(",
")",
"class"... | [
1764,
4
] | [
1781,
79
] | python | en | ['en', 'en', 'en'] | True |
TestStructBlock.test_default_value_is_distinct_instance | (self) |
Whenever the default value of a StructBlock is invoked, it should be a distinct
instance of the dict so that modifying it doesn't modify other places where the
default value appears.
|
Whenever the default value of a StructBlock is invoked, it should be a distinct
instance of the dict so that modifying it doesn't modify other places where the
default value appears.
| def test_default_value_is_distinct_instance(self):
"""
Whenever the default value of a StructBlock is invoked, it should be a distinct
instance of the dict so that modifying it doesn't modify other places where the
default value appears.
"""
class PersonBlock(blocks.Struc... | [
"def",
"test_default_value_is_distinct_instance",
"(",
"self",
")",
":",
"class",
"PersonBlock",
"(",
"blocks",
".",
"StructBlock",
")",
":",
"first_name",
"=",
"blocks",
".",
"CharBlock",
"(",
")",
"surname",
"=",
"blocks",
".",
"CharBlock",
"(",
")",
"class"... | [
1783,
4
] | [
1805,
69
] | python | en | ['en', 'error', 'th'] | False |
TestStructBlock.test_bulk_to_python_returns_distinct_default_instances | (self) |
Whenever StructBlock.bulk_to_python invokes a child block's get_default method to
fill in missing fields, it should use a separate invocation for each record so that
we don't end up with the same instance of a mutable value on multiple records
|
Whenever StructBlock.bulk_to_python invokes a child block's get_default method to
fill in missing fields, it should use a separate invocation for each record so that
we don't end up with the same instance of a mutable value on multiple records
| def test_bulk_to_python_returns_distinct_default_instances(self):
"""
Whenever StructBlock.bulk_to_python invokes a child block's get_default method to
fill in missing fields, it should use a separate invocation for each record so that
we don't end up with the same instance of a mutable ... | [
"def",
"test_bulk_to_python_returns_distinct_default_instances",
"(",
"self",
")",
":",
"class",
"ShoppingListBlock",
"(",
"blocks",
".",
"StructBlock",
")",
":",
"shop",
"=",
"blocks",
".",
"CharBlock",
"(",
")",
"items",
"=",
"blocks",
".",
"ListBlock",
"(",
"... | [
1807,
4
] | [
1827,
67
] | python | en | ['en', 'error', 'th'] | False |
TestStructBlock.test_bound_blocks_are_available_on_template | (self) |
Test that we are able to use value.bound_blocks within templates
to access a child block's own HTML rendering
|
Test that we are able to use value.bound_blocks within templates
to access a child block's own HTML rendering
| def test_bound_blocks_are_available_on_template(self):
"""
Test that we are able to use value.bound_blocks within templates
to access a child block's own HTML rendering
"""
block = SectionBlock()
value = block.to_python({'title': 'Hello', 'body': '<i>italic</i> world'})
... | [
"def",
"test_bound_blocks_are_available_on_template",
"(",
"self",
")",
":",
"block",
"=",
"SectionBlock",
"(",
")",
"value",
"=",
"block",
".",
"to_python",
"(",
"{",
"'title'",
":",
"'Hello'",
",",
"'body'",
":",
"'<i>italic</i> world'",
"}",
")",
"result",
... | [
1844,
4
] | [
1852,
73
] | 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.