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
logical_and
(image1, image2)
Logical AND between two images. Both of the images must have mode "1". If you would like to perform a logical AND on an image with a mode other than "1", try :py:meth:`~PIL.ImageChops.multiply` instead, using a black-and-white mask as the second image. .. code-block:: python out = ((image...
Logical AND between two images.
def logical_and(image1, image2): """Logical AND between two images. Both of the images must have mode "1". If you would like to perform a logical AND on an image with a mode other than "1", try :py:meth:`~PIL.ImageChops.multiply` instead, using a black-and-white mask as the second image. .. co...
[ "def", "logical_and", "(", "image1", ",", "image2", ")", ":", "image1", ".", "load", "(", ")", "image2", ".", "load", "(", ")", "return", "image1", ".", "_new", "(", "image1", ".", "im", ".", "chop_and", "(", "image2", ".", "im", ")", ")" ]
[ 239, 0 ]
[ 256, 53 ]
python
en
['en', 'en', 'en']
True
logical_or
(image1, image2)
Logical OR between two images. Both of the images must have mode "1". .. code-block:: python out = ((image1 or image2) % MAX) :rtype: :py:class:`~PIL.Image.Image`
Logical OR between two images.
def logical_or(image1, image2): """Logical OR between two images. Both of the images must have mode "1". .. code-block:: python out = ((image1 or image2) % MAX) :rtype: :py:class:`~PIL.Image.Image` """ image1.load() image2.load() return image1._new(image1.im.chop_or(image2.i...
[ "def", "logical_or", "(", "image1", ",", "image2", ")", ":", "image1", ".", "load", "(", ")", "image2", ".", "load", "(", ")", "return", "image1", ".", "_new", "(", "image1", ".", "im", ".", "chop_or", "(", "image2", ".", "im", ")", ")" ]
[ 259, 0 ]
[ 273, 52 ]
python
en
['en', 'en', 'en']
True
logical_xor
(image1, image2)
Logical XOR between two images. Both of the images must have mode "1". .. code-block:: python out = ((bool(image1) != bool(image2)) % MAX) :rtype: :py:class:`~PIL.Image.Image`
Logical XOR between two images.
def logical_xor(image1, image2): """Logical XOR between two images. Both of the images must have mode "1". .. code-block:: python out = ((bool(image1) != bool(image2)) % MAX) :rtype: :py:class:`~PIL.Image.Image` """ image1.load() image2.load() return image1._new(image1.im.ch...
[ "def", "logical_xor", "(", "image1", ",", "image2", ")", ":", "image1", ".", "load", "(", ")", "image2", ".", "load", "(", ")", "return", "image1", ".", "_new", "(", "image1", ".", "im", ".", "chop_xor", "(", "image2", ".", "im", ")", ")" ]
[ 276, 0 ]
[ 290, 53 ]
python
en
['en', 'en', 'en']
True
blend
(image1, image2, alpha)
Blend images using constant transparency weight. Alias for :py:func:`PIL.Image.blend`. :rtype: :py:class:`~PIL.Image.Image`
Blend images using constant transparency weight. Alias for :py:func:`PIL.Image.blend`.
def blend(image1, image2, alpha): """Blend images using constant transparency weight. Alias for :py:func:`PIL.Image.blend`. :rtype: :py:class:`~PIL.Image.Image` """ return Image.blend(image1, image2, alpha)
[ "def", "blend", "(", "image1", ",", "image2", ",", "alpha", ")", ":", "return", "Image", ".", "blend", "(", "image1", ",", "image2", ",", "alpha", ")" ]
[ 293, 0 ]
[ 300, 45 ]
python
en
['en', 'en', 'en']
True
composite
(image1, image2, mask)
Create composite using transparency mask. Alias for :py:func:`PIL.Image.composite`. :rtype: :py:class:`~PIL.Image.Image`
Create composite using transparency mask. Alias for :py:func:`PIL.Image.composite`.
def composite(image1, image2, mask): """Create composite using transparency mask. Alias for :py:func:`PIL.Image.composite`. :rtype: :py:class:`~PIL.Image.Image` """ return Image.composite(image1, image2, mask)
[ "def", "composite", "(", "image1", ",", "image2", ",", "mask", ")", ":", "return", "Image", ".", "composite", "(", "image1", ",", "image2", ",", "mask", ")" ]
[ 303, 0 ]
[ 310, 48 ]
python
en
['en', 'en', 'en']
True
offset
(image, xoffset, yoffset=None)
Returns a copy of the image where data has been offset by the given distances. Data wraps around the edges. If ``yoffset`` is omitted, it is assumed to be equal to ``xoffset``. :param xoffset: The horizontal distance. :param yoffset: The vertical distance. If omitted, both distances are set to...
Returns a copy of the image where data has been offset by the given distances. Data wraps around the edges. If ``yoffset`` is omitted, it is assumed to be equal to ``xoffset``.
def offset(image, xoffset, yoffset=None): """Returns a copy of the image where data has been offset by the given distances. Data wraps around the edges. If ``yoffset`` is omitted, it is assumed to be equal to ``xoffset``. :param xoffset: The horizontal distance. :param yoffset: The vertical distanc...
[ "def", "offset", "(", "image", ",", "xoffset", ",", "yoffset", "=", "None", ")", ":", "if", "yoffset", "is", "None", ":", "yoffset", "=", "xoffset", "image", ".", "load", "(", ")", "return", "image", ".", "_new", "(", "image", ".", "im", ".", "offs...
[ 313, 0 ]
[ 327, 56 ]
python
en
['en', 'en', 'en']
True
to_genshi
(walker)
Convert a tree to a genshi tree :arg walker: the treewalker to use to walk the tree to convert it :returns: generator of genshi nodes
Convert a tree to a genshi tree
def to_genshi(walker): """Convert a tree to a genshi tree :arg walker: the treewalker to use to walk the tree to convert it :returns: generator of genshi nodes """ text = [] for token in walker: type = token["type"] if type in ("Characters", "SpaceCharacters"): tex...
[ "def", "to_genshi", "(", "walker", ")", ":", "text", "=", "[", "]", "for", "token", "in", "walker", ":", "type", "=", "token", "[", "\"type\"", "]", "if", "type", "in", "(", "\"Characters\"", ",", "\"SpaceCharacters\"", ")", ":", "text", ".", "append",...
[ 6, 0 ]
[ 53, 49 ]
python
en
['en', 'mk', 'en']
True
urlquote
(url, safe='/')
A legacy compatibility wrapper to Python's urllib.parse.quote() function. (was used for unicode handling on Python 2)
A legacy compatibility wrapper to Python's urllib.parse.quote() function. (was used for unicode handling on Python 2)
def urlquote(url, safe='/'): """ A legacy compatibility wrapper to Python's urllib.parse.quote() function. (was used for unicode handling on Python 2) """ warnings.warn( 'django.utils.http.urlquote() is deprecated in favor of ' 'urllib.parse.quote().', RemovedInDjango40Warnin...
[ "def", "urlquote", "(", "url", ",", "safe", "=", "'/'", ")", ":", "warnings", ".", "warn", "(", "'django.utils.http.urlquote() is deprecated in favor of '", "'urllib.parse.quote().'", ",", "RemovedInDjango40Warning", ",", "stacklevel", "=", "2", ",", ")", "return", ...
[ 45, 0 ]
[ 55, 27 ]
python
en
['en', 'error', 'th']
False
urlquote_plus
(url, safe='')
A legacy compatibility wrapper to Python's urllib.parse.quote_plus() function. (was used for unicode handling on Python 2)
A legacy compatibility wrapper to Python's urllib.parse.quote_plus() function. (was used for unicode handling on Python 2)
def urlquote_plus(url, safe=''): """ A legacy compatibility wrapper to Python's urllib.parse.quote_plus() function. (was used for unicode handling on Python 2) """ warnings.warn( 'django.utils.http.urlquote_plus() is deprecated in favor of ' 'urllib.parse.quote_plus(),', Remo...
[ "def", "urlquote_plus", "(", "url", ",", "safe", "=", "''", ")", ":", "warnings", ".", "warn", "(", "'django.utils.http.urlquote_plus() is deprecated in favor of '", "'urllib.parse.quote_plus(),'", ",", "RemovedInDjango40Warning", ",", "stacklevel", "=", "2", ",", ")", ...
[ 59, 0 ]
[ 69, 32 ]
python
en
['en', 'error', 'th']
False
urlunquote
(quoted_url)
A legacy compatibility wrapper to Python's urllib.parse.unquote() function. (was used for unicode handling on Python 2)
A legacy compatibility wrapper to Python's urllib.parse.unquote() function. (was used for unicode handling on Python 2)
def urlunquote(quoted_url): """ A legacy compatibility wrapper to Python's urllib.parse.unquote() function. (was used for unicode handling on Python 2) """ warnings.warn( 'django.utils.http.urlunquote() is deprecated in favor of ' 'urllib.parse.unquote().', RemovedInDjango40W...
[ "def", "urlunquote", "(", "quoted_url", ")", ":", "warnings", ".", "warn", "(", "'django.utils.http.urlunquote() is deprecated in favor of '", "'urllib.parse.unquote().'", ",", "RemovedInDjango40Warning", ",", "stacklevel", "=", "2", ",", ")", "return", "unquote", "(", ...
[ 73, 0 ]
[ 83, 30 ]
python
en
['en', 'error', 'th']
False
urlunquote_plus
(quoted_url)
A legacy compatibility wrapper to Python's urllib.parse.unquote_plus() function. (was used for unicode handling on Python 2)
A legacy compatibility wrapper to Python's urllib.parse.unquote_plus() function. (was used for unicode handling on Python 2)
def urlunquote_plus(quoted_url): """ A legacy compatibility wrapper to Python's urllib.parse.unquote_plus() function. (was used for unicode handling on Python 2) """ warnings.warn( 'django.utils.http.urlunquote_plus() is deprecated in favor of ' 'urllib.parse.unquote_plus().', ...
[ "def", "urlunquote_plus", "(", "quoted_url", ")", ":", "warnings", ".", "warn", "(", "'django.utils.http.urlunquote_plus() is deprecated in favor of '", "'urllib.parse.unquote_plus().'", ",", "RemovedInDjango40Warning", ",", "stacklevel", "=", "2", ",", ")", "return", "unqu...
[ 87, 0 ]
[ 97, 35 ]
python
en
['en', 'error', 'th']
False
urlencode
(query, doseq=False)
A version of Python's urllib.parse.urlencode() function that can operate on MultiValueDict and non-string values.
A version of Python's urllib.parse.urlencode() function that can operate on MultiValueDict and non-string values.
def urlencode(query, doseq=False): """ A version of Python's urllib.parse.urlencode() function that can operate on MultiValueDict and non-string values. """ if isinstance(query, MultiValueDict): query = query.lists() elif hasattr(query, 'items'): query = query.items() query_p...
[ "def", "urlencode", "(", "query", ",", "doseq", "=", "False", ")", ":", "if", "isinstance", "(", "query", ",", "MultiValueDict", ")", ":", "query", "=", "query", ".", "lists", "(", ")", "elif", "hasattr", "(", "query", ",", "'items'", ")", ":", "quer...
[ 100, 0 ]
[ 138, 50 ]
python
en
['en', 'error', 'th']
False
http_date
(epoch_seconds=None)
Format the time to match the RFC1123 date format as specified by HTTP RFC7231 section 7.1.1.1. `epoch_seconds` is a floating point number expressed in seconds since the epoch, in UTC - such as that outputted by time.time(). If set to None, it defaults to the current time. Output a string in t...
Format the time to match the RFC1123 date format as specified by HTTP RFC7231 section 7.1.1.1.
def http_date(epoch_seconds=None): """ Format the time to match the RFC1123 date format as specified by HTTP RFC7231 section 7.1.1.1. `epoch_seconds` is a floating point number expressed in seconds since the epoch, in UTC - such as that outputted by time.time(). If set to None, it defaults to t...
[ "def", "http_date", "(", "epoch_seconds", "=", "None", ")", ":", "return", "formatdate", "(", "epoch_seconds", ",", "usegmt", "=", "True", ")" ]
[ 141, 0 ]
[ 152, 49 ]
python
en
['en', 'error', 'th']
False
parse_http_date
(date)
Parse 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. Return an integer expressed in seconds since the epoch, in UTC.
Parse a date format as specified by HTTP RFC7231 section 7.1.1.1.
def parse_http_date(date): """ Parse 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. Return an integer expressed in seconds since the epoch, in UTC. """ # email.utils.parse...
[ "def", "parse_http_date", "(", "date", ")", ":", "# email.utils.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"...
[ 155, 0 ]
[ 192, 66 ]
python
en
['en', 'error', 'th']
False
parse_http_date_safe
(date)
Same as parse_http_date, but return None if the input is invalid.
Same as parse_http_date, but return None if the input is invalid.
def parse_http_date_safe(date): """ Same as parse_http_date, but return 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" ]
[ 195, 0 ]
[ 202, 12 ]
python
en
['en', 'error', 'th']
False
base36_to_int
(s)
Convert a base 36 string to an int. Raise ValueError if the input won't fit into an int.
Convert a base 36 string to an int. Raise ValueError if the input won't fit into an int.
def base36_to_int(s): """ Convert a base 36 string to an int. Raise 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-bit inte...
[ "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"...
[ 207, 0 ]
[ 217, 21 ]
python
en
['en', 'error', 'th']
False
int_to_base36
(i)
Convert an integer to a base36 string.
Convert an integer to a base36 string.
def int_to_base36(i): """Convert an integer to a base36 string.""" char_set = '0123456789abcdefghijklmnopqrstuvwxyz' if i < 0: raise ValueError("Negative base36 conversion input.") if i < 36: return char_set[i] b36 = '' while i != 0: i, n = divmod(i, 36) b36 = cha...
[ "def", "int_to_base36", "(", "i", ")", ":", "char_set", "=", "'0123456789abcdefghijklmnopqrstuvwxyz'", "if", "i", "<", "0", ":", "raise", "ValueError", "(", "\"Negative base36 conversion input.\"", ")", "if", "i", "<", "36", ":", "return", "char_set", "[", "i", ...
[ 220, 0 ]
[ 231, 14 ]
python
en
['en', 'lb', 'en']
True
urlsafe_base64_encode
(s)
Encode a bytestring to a base64 string for use in URLs. Strip any trailing equal signs.
Encode a bytestring to a base64 string for use in URLs. Strip any trailing equal signs.
def urlsafe_base64_encode(s): """ Encode a bytestring to a base64 string for use in URLs. Strip any trailing equal signs. """ return base64.urlsafe_b64encode(s).rstrip(b'\n=').decode('ascii')
[ "def", "urlsafe_base64_encode", "(", "s", ")", ":", "return", "base64", ".", "urlsafe_b64encode", "(", "s", ")", ".", "rstrip", "(", "b'\\n='", ")", ".", "decode", "(", "'ascii'", ")" ]
[ 234, 0 ]
[ 239, 69 ]
python
en
['en', 'error', 'th']
False
urlsafe_base64_decode
(s)
Decode a base64 encoded string. Add back any trailing equal signs that might have been stripped.
Decode a base64 encoded string. Add back any trailing equal signs that might have been stripped.
def urlsafe_base64_decode(s): """ Decode a base64 encoded string. Add back any trailing equal signs that might have been stripped. """ s = s.encode() try: return base64.urlsafe_b64decode(s.ljust(len(s) + len(s) % 4, b'=')) except (LookupError, BinasciiError) as e: raise Value...
[ "def", "urlsafe_base64_decode", "(", "s", ")", ":", "s", "=", "s", ".", "encode", "(", ")", "try", ":", "return", "base64", ".", "urlsafe_b64decode", "(", "s", ".", "ljust", "(", "len", "(", "s", ")", "+", "len", "(", "s", ")", "%", "4", ",", "...
[ 242, 0 ]
[ 251, 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...
[ 254, 0 ]
[ 265, 60 ]
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" ]
[ 268, 0 ]
[ 276, 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...
[ 279, 0 ]
[ 295, 5 ]
python
en
['en', 'error', 'th']
False
url_has_allowed_host_and_scheme
(url, allowed_hosts, require_https=False)
Return ``True`` if the url uses an allowed host and a safe scheme. Always return ``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, ``False``. Note: "True" doesn't entail that a URL is "s...
Return ``True`` if the url uses an allowed host and a safe scheme.
def url_has_allowed_host_and_scheme(url, allowed_hosts, require_https=False): """ Return ``True`` if the url uses an allowed host and a safe scheme. Always return ``False`` on an empty url. If ``require_https`` is ``True``, only 'https' will be considered a valid scheme, as opposed to 'http' and '...
[ "def", "url_has_allowed_host_and_scheme", "(", "url", ",", "allowed_hosts", ",", "require_https", "=", "False", ")", ":", "if", "url", "is", "not", "None", ":", "url", "=", "url", ".", "strip", "(", ")", "if", "not", "url", ":", "return", "False", "if", ...
[ 298, 0 ]
[ 324, 5 ]
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", ")", ":", "url", ",", "scheme", ",", "_coerce_result", "=", "_coerce_args", "(", "url", ",", "scheme", ")", "splitresult", "=", "_urlsplit", "(", "url", ",", ...
[ 337, 0 ]
[ 351, 33 ]
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", ")", ":", "url", ",", "scheme", ",", "_coerce_result", "=", "_coerce_args", "(", "url", ",", "scheme", ")", "netloc", "=", "query", "=", "fragment", "=", "''...
[ 356, 0 ]
[ 382, 28 ]
python
en
['en', 'en', 'en']
True
parse_qsl
( qs, keep_blank_values=False, strict_parsing=False, encoding='utf-8', errors='replace', max_num_fields=None, separator='&', )
Return a list of key/value tuples parsed from query string. Backport of urllib.parse.parse_qsl() from Python 3.8.8. Copyright (C) 2021 Python Software Foundation (see LICENSE.python). ---- Parse a query given as a string argument. Arguments: qs: percent-encoded query string to be parse...
Return a list of key/value tuples parsed from query string.
def parse_qsl( qs, keep_blank_values=False, strict_parsing=False, encoding='utf-8', errors='replace', max_num_fields=None, separator='&', ): """ Return a list of key/value tuples parsed from query string. Backport of urllib.parse.parse_qsl() from Python 3.8.8. Copyright (C) 2021 Python Software...
[ "def", "parse_qsl", "(", "qs", ",", "keep_blank_values", "=", "False", ",", "strict_parsing", "=", "False", ",", "encoding", "=", "'utf-8'", ",", "errors", "=", "'replace'", ",", "max_num_fields", "=", "None", ",", "separator", "=", "'&'", ",", ")", ":", ...
[ 415, 0 ]
[ 489, 12 ]
python
en
['en', 'error', 'th']
False
escape_leading_slashes
(url)
If redirecting to an absolute path (two leading slashes), a slash must be escaped to prevent browsers from handling the path as schemaless and redirecting to another host.
If redirecting to an absolute path (two leading slashes), a slash must be escaped to prevent browsers from handling the path as schemaless and redirecting to another host.
def escape_leading_slashes(url): """ If redirecting to an absolute path (two leading slashes), a slash must be escaped to prevent browsers from handling the path as schemaless and redirecting to another host. """ if url.startswith('//'): url = '/%2F{}'.format(url[2:]) return url
[ "def", "escape_leading_slashes", "(", "url", ")", ":", "if", "url", ".", "startswith", "(", "'//'", ")", ":", "url", "=", "'/%2F{}'", ".", "format", "(", "url", "[", "2", ":", "]", ")", "return", "url" ]
[ 492, 0 ]
[ 500, 14 ]
python
en
['en', 'error', 'th']
False
ForeignObjectRel.target_field
(self)
When filtering against this relation, return the field on the remote model against which the filtering should happen.
When filtering against this relation, return the field on the remote model against which the filtering should happen.
def target_field(self): """ When filtering against this relation, return the field on the remote model against which the filtering should happen. """ target_fields = self.get_path_info()[-1].target_fields if len(target_fields) > 1: raise exceptions.FieldError(...
[ "def", "target_field", "(", "self", ")", ":", "target_fields", "=", "self", ".", "get_path_info", "(", ")", "[", "-", "1", "]", ".", "target_fields", "if", "len", "(", "target_fields", ")", ">", "1", ":", "raise", "exceptions", ".", "FieldError", "(", ...
[ 68, 4 ]
[ 76, 31 ]
python
en
['en', 'error', 'th']
False
ForeignObjectRel.get_choices
( self, include_blank=True, blank_choice=BLANK_CHOICE_DASH, limit_choices_to=None, ordering=(), )
Return choices with a default blank choices included, for use as <select> choices for this field. Analog of django.db.models.fields.Field.get_choices(), provided initially for utilization by RelatedFieldListFilter.
Return choices with a default blank choices included, for use as <select> choices for this field.
def get_choices( self, include_blank=True, blank_choice=BLANK_CHOICE_DASH, limit_choices_to=None, ordering=(), ): """ Return choices with a default blank choices included, for use as <select> choices for this field. Analog of django.db.models.fields.Field.get_choices...
[ "def", "get_choices", "(", "self", ",", "include_blank", "=", "True", ",", "blank_choice", "=", "BLANK_CHOICE_DASH", ",", "limit_choices_to", "=", "None", ",", "ordering", "=", "(", ")", ",", ")", ":", "limit_choices_to", "=", "limit_choices_to", "or", "self",...
[ 140, 4 ]
[ 157, 9 ]
python
en
['en', 'error', 'th']
False
ForeignObjectRel.is_hidden
(self)
Should the related object be hidden?
Should the related object be hidden?
def is_hidden(self): """Should the related object be hidden?""" return bool(self.related_name) and self.related_name[-1] == '+'
[ "def", "is_hidden", "(", "self", ")", ":", "return", "bool", "(", "self", ".", "related_name", ")", "and", "self", ".", "related_name", "[", "-", "1", "]", "==", "'+'" ]
[ 159, 4 ]
[ 161, 71 ]
python
en
['en', 'en', 'en']
True
ForeignObjectRel.set_field_name
(self)
Set the related field's name, this is not available until later stages of app loading, so set_field_name is called from set_attributes_from_rel()
Set the related field's name, this is not available until later stages of app loading, so set_field_name is called from set_attributes_from_rel()
def set_field_name(self): """ Set the related field's name, this is not available until later stages of app loading, so set_field_name is called from set_attributes_from_rel() """ # By default foreign object doesn't relate to any remote field (for # example custom...
[ "def", "set_field_name", "(", "self", ")", ":", "# By default foreign object doesn't relate to any remote field (for", "# example custom multicolumn joins currently have no remote field).", "self", ".", "field_name", "=", "None" ]
[ 169, 4 ]
[ 177, 30 ]
python
en
['en', 'error', 'th']
False
ForeignObjectRel.get_cache_name
(self)
Return the name of the cache key to use for storing an instance of the forward model on the reverse model.
Return the name of the cache key to use for storing an instance of the forward model on the reverse model.
def get_cache_name(self): """ Return the name of the cache key to use for storing an instance of the forward model on the reverse model. """ return self.get_accessor_name()
[ "def", "get_cache_name", "(", "self", ")", ":", "return", "self", ".", "get_accessor_name", "(", ")" ]
[ 199, 4 ]
[ 204, 39 ]
python
en
['en', 'error', 'th']
False
ManyToOneRel.get_related_field
(self)
Return the Field in the 'to' object to which this relationship is tied.
Return the Field in the 'to' object to which this relationship is tied.
def get_related_field(self): """ Return the Field in the 'to' object to which this relationship is tied. """ field = self.model._meta.get_field(self.field_name) if not field.concrete: raise exceptions.FieldDoesNotExist("No related field named '%s'" % self.field_name) ...
[ "def", "get_related_field", "(", "self", ")", ":", "field", "=", "self", ".", "model", ".", "_meta", ".", "get_field", "(", "self", ".", "field_name", ")", "if", "not", "field", ".", "concrete", ":", "raise", "exceptions", ".", "FieldDoesNotExist", "(", ...
[ 244, 4 ]
[ 251, 20 ]
python
en
['en', 'error', 'th']
False
ManyToManyRel.get_related_field
(self)
Return the field in the 'to' object to which this relationship is tied. Provided for symmetry with ManyToOneRel.
Return the field in the 'to' object to which this relationship is tied. Provided for symmetry with ManyToOneRel.
def get_related_field(self): """ Return the field in the 'to' object to which this relationship is tied. Provided for symmetry with ManyToOneRel. """ opts = self.through._meta if self.through_fields: field = opts.get_field(self.through_fields[0]) else:...
[ "def", "get_related_field", "(", "self", ")", ":", "opts", "=", "self", ".", "through", ".", "_meta", "if", "self", ".", "through_fields", ":", "field", "=", "opts", ".", "get_field", "(", "self", ".", "through_fields", "[", "0", "]", ")", "else", ":",...
[ 316, 4 ]
[ 329, 46 ]
python
en
['en', 'error', 'th']
False
_verify_python3_env
()
Ensures that the environment is good for unicode on Python 3.
Ensures that the environment is good for unicode on Python 3.
def _verify_python3_env(): """Ensures that the environment is good for unicode on Python 3.""" if PY2: return try: import locale fs_enc = codecs.lookup(locale.getpreferredencoding()).name except Exception: fs_enc = 'ascii' if fs_enc != 'ascii': return ext...
[ "def", "_verify_python3_env", "(", ")", ":", "if", "PY2", ":", "return", "try", ":", "import", "locale", "fs_enc", "=", "codecs", ".", "lookup", "(", "locale", ".", "getpreferredencoding", "(", ")", ")", ".", "name", "except", "Exception", ":", "fs_enc", ...
[ 49, 0 ]
[ 124, 5 ]
python
en
['en', 'en', 'en']
True
pre_sql_setup
(self)
Do any necessary class setup immediately prior to producing SQL. This is for things that can't necessarily be done in __init__ because we might not have all the pieces in place at that time.
Do any necessary class setup immediately prior to producing SQL. This is for things that can't necessarily be done in __init__ because we might not have all the pieces in place at that time.
def pre_sql_setup(self): """ Do any necessary class setup immediately prior to producing SQL. This is for things that can't necessarily be done in __init__ because we might not have all the pieces in place at that time. """ self.setup_query() order_by = self.get_o...
[ "def", "pre_sql_setup", "(", "self", ")", ":", "self", ".", "setup_query", "(", ")", "order_by", "=", "self", ".", "get_order_by", "(", ")", "self", ".", "where", ",", "self", ".", "having", "=", "self", ".", "query", ".", "where", ".", "split_having",...
[ 48, 4 ]
[ 60, 47 ]
python
en
['en', 'error', 'th']
False
get_group_by
(self, select, order_by)
Return a list of 2-tuples of form (sql, params). The logic of what exactly the GROUP BY clause contains is hard to describe in other words than "if it passes the test suite, then it is correct".
Return a list of 2-tuples of form (sql, params).
def get_group_by(self, select, order_by): """ Return a list of 2-tuples of form (sql, params). The logic of what exactly the GROUP BY clause contains is hard to describe in other words than "if it passes the test suite, then it is correct". """ # Some examples: ...
[ "def", "get_group_by", "(", "self", ",", "select", ",", "order_by", ")", ":", "# Some examples:", "# SomeModel.objects.annotate(Count('somecol'))", "# GROUP BY: all fields of the model", "#", "# SomeModel.objects.values('name').annotate(Count('somecol'))", "# GROUP BY: na...
[ 62, 4 ]
[ 146, 21 ]
python
en
['en', 'error', 'th']
False
get_select
(self)
Return three values: - a list of 3-tuples of (expression, (sql, params), alias) - a klass_info structure, - a dictionary of annotations The (sql, params) is what the expression will produce, and alias is the "AS alias" for the column (possibly None). The klass_...
Return three values: - a list of 3-tuples of (expression, (sql, params), alias) - a klass_info structure, - a dictionary of annotations
def get_select(self): """ Return three values: - a list of 3-tuples of (expression, (sql, params), alias) - a klass_info structure, - a dictionary of annotations The (sql, params) is what the expression will produce, and alias is the "AS alias" for the column (po...
[ "def", "get_select", "(", "self", ")", ":", "select", "=", "[", "]", "klass_info", "=", "None", "annotations", "=", "{", "}", "select_idx", "=", "0", "for", "alias", ",", "(", "sql", ",", "params", ")", "in", "self", ".", "query", ".", "extra_select"...
[ 198, 4 ]
[ 268, 43 ]
python
en
['en', 'error', 'th']
False
get_order_by
(self)
Return a list of 2-tuples of form (expr, (sql, params, is_ref)) for the ORDER BY clause. The order_by clause can alter the select clause (for example it can add aliases to clauses that do not yet have one, or it can add totally new select clauses).
Return a list of 2-tuples of form (expr, (sql, params, is_ref)) for the ORDER BY clause.
def get_order_by(self): """ Return a list of 2-tuples of form (expr, (sql, params, is_ref)) for the ORDER BY clause. The order_by clause can alter the select clause (for example it can add aliases to clauses that do not yet have one, or it can add totally new select clau...
[ "def", "get_order_by", "(", "self", ")", ":", "if", "self", ".", "query", ".", "extra_order_by", ":", "ordering", "=", "self", ".", "query", ".", "extra_order_by", "elif", "not", "self", ".", "query", ".", "default_ordering", ":", "ordering", "=", "self", ...
[ 270, 4 ]
[ 410, 21 ]
python
en
['en', 'error', 'th']
False
quote_name_unless_alias
(self, name)
A wrapper around connection.ops.quote_name that doesn't quote aliases for table names. This avoids problems with some SQL dialects that treat quoted strings specially (e.g. PostgreSQL).
A wrapper around connection.ops.quote_name that doesn't quote aliases for table names. This avoids problems with some SQL dialects that treat quoted strings specially (e.g. PostgreSQL).
def quote_name_unless_alias(self, name): """ A wrapper around connection.ops.quote_name that doesn't quote aliases for table names. This avoids problems with some SQL dialects that treat quoted strings specially (e.g. PostgreSQL). """ if name in self.quote_cache: ...
[ "def", "quote_name_unless_alias", "(", "self", ",", "name", ")", ":", "if", "name", "in", "self", ".", "quote_cache", ":", "return", "self", ".", "quote_cache", "[", "name", "]", "if", "(", "(", "name", "in", "self", ".", "query", ".", "alias_map", "an...
[ 422, 4 ]
[ 437, 16 ]
python
en
['en', 'error', 'th']
False
pixelwise_weighted_loss
(original_loss_func, y_true_channels=None, weight_channels=None, sum_channels=True, reshape_axis=None)
This function implements pixel-wise weighted loss if y_true has 2n channels, weight maps are the Weight map are [n, 2n) channels; otherwise y_true channels and weight channels can be specified as lists of length 2
This function implements pixel-wise weighted loss if y_true has 2n channels, weight maps are the Weight map are [n, 2n) channels; otherwise y_true channels and weight channels can be specified as lists of length 2
def pixelwise_weighted_loss(original_loss_func, y_true_channels=None, weight_channels=None, sum_channels=True, reshape_axis=None): ''' This function implements pixel-wise weighted loss if y_true has 2n channels, weight maps are the Weight map are [n, 2n) channels; otherwise y_true channels and weight channe...
[ "def", "pixelwise_weighted_loss", "(", "original_loss_func", ",", "y_true_channels", "=", "None", ",", "weight_channels", "=", "None", ",", "sum_channels", "=", "True", ",", "reshape_axis", "=", "None", ")", ":", "#@tf.function", "if", "y_true_channels", "is", "No...
[ 101, 0 ]
[ 130, 20 ]
python
en
['en', 'error', 'th']
False
soft_generalized_dice_loss
(batch_mean = False, square_weights = True, sparse = True, exclude_background=False, spatial_dim_axes=[1, 2])
Generalised Dice Loss function defined in Sudre, C. et. al. (2017) Generalised Dice overlap as a deep learning loss function for highly unbalanced segmentations. DLMIA 2017 TF1x implementation : https://github.com/NifTK/NiftyNet/blob/dev/niftynet/layer/loss_segmentation.py Assumes clas...
Generalised Dice Loss function defined in Sudre, C. et. al. (2017) Generalised Dice overlap as a deep learning loss function for highly unbalanced segmentations. DLMIA 2017
def soft_generalized_dice_loss(batch_mean = False, square_weights = True, sparse = True, exclude_background=False, spatial_dim_axes=[1, 2]): """ Generalised Dice Loss function defined in Sudre, C. et. al. (2017) Generalised Dice overlap as a deep learning loss function for highly unbalanced segmenta...
[ "def", "soft_generalized_dice_loss", "(", "batch_mean", "=", "False", ",", "square_weights", "=", "True", ",", "sparse", "=", "True", ",", "exclude_background", "=", "False", ",", "spatial_dim_axes", "=", "[", "1", ",", "2", "]", ")", ":", "def", "loss_fun",...
[ 187, 0 ]
[ 229, 19 ]
python
en
['en', 'en', 'en']
True
binary_tversky_loss
(alpha=0.3, beta=0.7, smooth=1e-7, batch_mean=False)
Return the Tversky loss for imbalanced data Sadegh et al. (2017) Tversky loss function for image segmentation using 3D fully convolutional deep networks Parameters ---------- alpha : type weight of false positives (penalize false positives) beta : type weight of false neg...
Return the Tversky loss for imbalanced data Sadegh et al. (2017) Tversky loss function for image segmentation using 3D fully convolutional deep networks Parameters ---------- alpha : type weight of false positives (penalize false positives) beta : type weight of false neg...
def binary_tversky_loss(alpha=0.3, beta=0.7, smooth=1e-7, batch_mean=False): """Return the Tversky loss for imbalanced data Sadegh et al. (2017) Tversky loss function for image segmentation using 3D fully convolutional deep networks Parameters ---------- alpha : type weight of fa...
[ "def", "binary_tversky_loss", "(", "alpha", "=", "0.3", ",", "beta", "=", "0.7", ",", "smooth", "=", "1e-7", ",", "batch_mean", "=", "False", ")", ":", "def", "loss_fun", "(", "y_true", ",", "y_pred", ")", ":", "batchSize", "=", "K", ".", "shape", "(...
[ 231, 0 ]
[ 267, 19 ]
python
en
['en', 'ceb', 'en']
True
boundary_regional_loss
(alpha, regional_loss, mul_coeff=1, y_true_channels=None, levelset_channels=None)
Mixed boundary loss with regional loss function as in https://arxiv.org/abs/1812.07032 Parameters ---------- alpha : type number / Keras variable in range [0,1] importance given to regional loss over boundary loss regional_loss : function. returns a tensor with shape (batch_size, ) mul_coe...
Mixed boundary loss with regional loss function as in https://arxiv.org/abs/1812.07032
def boundary_regional_loss(alpha, regional_loss, mul_coeff=1, y_true_channels=None, levelset_channels=None): """Mixed boundary loss with regional loss function as in https://arxiv.org/abs/1812.07032 Parameters ---------- alpha : type number / Keras variable in range [0,1] importance given to r...
[ "def", "boundary_regional_loss", "(", "alpha", ",", "regional_loss", ",", "mul_coeff", "=", "1", ",", "y_true_channels", "=", "None", ",", "levelset_channels", "=", "None", ")", ":", "def", "loss_fun", "(", "y_true", ",", "y_pred", ")", ":", "if", "y_true_ch...
[ 269, 0 ]
[ 303, 19 ]
python
en
['en', 'en', 'en']
True
Apps.populate
(self, installed_apps=None)
Load application configurations and models. Import each application module and then each model module. It is thread-safe and idempotent, but not reentrant.
Load application configurations and models.
def populate(self, installed_apps=None): """ Load application configurations and models. Import each application module and then each model module. It is thread-safe and idempotent, but not reentrant. """ if self.ready: return # populate() might be ...
[ "def", "populate", "(", "self", ",", "installed_apps", "=", "None", ")", ":", "if", "self", ".", "ready", ":", "return", "# populate() might be called by two threads in parallel on servers", "# that create threads before initializing the WSGI callable.", "with", "self", ".", ...
[ 60, 4 ]
[ 124, 34 ]
python
en
['en', 'error', 'th']
False
Apps.check_apps_ready
(self)
Raise an exception if all apps haven't been imported yet.
Raise an exception if all apps haven't been imported yet.
def check_apps_ready(self): """Raise an exception if all apps haven't been imported yet.""" if not self.apps_ready: from django.conf import settings # If "not ready" is due to unconfigured settings, accessing # INSTALLED_APPS raises a more helpful ImproperlyConfigure...
[ "def", "check_apps_ready", "(", "self", ")", ":", "if", "not", "self", ".", "apps_ready", ":", "from", "django", ".", "conf", "import", "settings", "# If \"not ready\" is due to unconfigured settings, accessing", "# INSTALLED_APPS raises a more helpful ImproperlyConfigured", ...
[ 126, 4 ]
[ 135, 64 ]
python
en
['en', 'en', 'en']
True
Apps.check_models_ready
(self)
Raise an exception if all models haven't been imported yet.
Raise an exception if all models haven't been imported yet.
def check_models_ready(self): """Raise an exception if all models haven't been imported yet.""" if not self.models_ready: raise AppRegistryNotReady("Models aren't loaded yet.")
[ "def", "check_models_ready", "(", "self", ")", ":", "if", "not", "self", ".", "models_ready", ":", "raise", "AppRegistryNotReady", "(", "\"Models aren't loaded yet.\"", ")" ]
[ 137, 4 ]
[ 140, 66 ]
python
en
['en', 'en', 'en']
True
Apps.get_app_configs
(self)
Import applications and return an iterable of app configs.
Import applications and return an iterable of app configs.
def get_app_configs(self): """Import applications and return an iterable of app configs.""" self.check_apps_ready() return self.app_configs.values()
[ "def", "get_app_configs", "(", "self", ")", ":", "self", ".", "check_apps_ready", "(", ")", "return", "self", ".", "app_configs", ".", "values", "(", ")" ]
[ 142, 4 ]
[ 145, 40 ]
python
en
['en', 'en', 'en']
True
Apps.get_app_config
(self, app_label)
Import applications and returns an app config for the given label. Raise LookupError if no application exists with this label.
Import applications and returns an app config for the given label.
def get_app_config(self, app_label): """ Import applications and returns an app config for the given label. Raise LookupError if no application exists with this label. """ self.check_apps_ready() try: return self.app_configs[app_label] except KeyError...
[ "def", "get_app_config", "(", "self", ",", "app_label", ")", ":", "self", ".", "check_apps_ready", "(", ")", "try", ":", "return", "self", ".", "app_configs", "[", "app_label", "]", "except", "KeyError", ":", "message", "=", "\"No installed app with label '%s'.\...
[ 147, 4 ]
[ 162, 38 ]
python
en
['en', 'error', 'th']
False
Apps.get_models
(self, include_auto_created=False, include_swapped=False)
Return a list of all installed models. By default, the following models aren't included: - auto-created models for many-to-many relations without an explicit intermediate table, - models that have been swapped out. Set the corresponding keyword argument to True to i...
Return a list of all installed models.
def get_models(self, include_auto_created=False, include_swapped=False): """ Return a list of all installed models. By default, the following models aren't included: - auto-created models for many-to-many relations without an explicit intermediate table, - models that...
[ "def", "get_models", "(", "self", ",", "include_auto_created", "=", "False", ",", "include_swapped", "=", "False", ")", ":", "self", ".", "check_models_ready", "(", ")", "result", "=", "[", "]", "for", "app_config", "in", "self", ".", "app_configs", ".", "...
[ 166, 4 ]
[ 183, 21 ]
python
en
['en', 'error', 'th']
False
Apps.get_model
(self, app_label, model_name=None, require_ready=True)
Return the model matching the given app_label and model_name. As a shortcut, app_label may be in the form <app_label>.<model_name>. model_name is case-insensitive. Raise LookupError if no application exists with this label, or no model exists with this name in the application...
Return the model matching the given app_label and model_name.
def get_model(self, app_label, model_name=None, require_ready=True): """ Return the model matching the given app_label and model_name. As a shortcut, app_label may be in the form <app_label>.<model_name>. model_name is case-insensitive. Raise LookupError if no application exis...
[ "def", "get_model", "(", "self", ",", "app_label", ",", "model_name", "=", "None", ",", "require_ready", "=", "True", ")", ":", "if", "require_ready", ":", "self", ".", "check_models_ready", "(", ")", "else", ":", "self", ".", "check_apps_ready", "(", ")",...
[ 185, 4 ]
[ 210, 76 ]
python
en
['en', 'error', 'th']
False
Apps.is_installed
(self, app_name)
Check whether an application with this name exists in the registry. app_name is the full name of the app e.g. 'django.contrib.admin'.
Check whether an application with this name exists in the registry.
def is_installed(self, app_name): """ Check whether an application with this name exists in the registry. app_name is the full name of the app e.g. 'django.contrib.admin'. """ self.check_apps_ready() return any(ac.name == app_name for ac in self.app_configs.values())
[ "def", "is_installed", "(", "self", ",", "app_name", ")", ":", "self", ".", "check_apps_ready", "(", ")", "return", "any", "(", "ac", ".", "name", "==", "app_name", "for", "ac", "in", "self", ".", "app_configs", ".", "values", "(", ")", ")" ]
[ 234, 4 ]
[ 241, 75 ]
python
en
['en', 'error', 'th']
False
Apps.get_containing_app_config
(self, object_name)
Look for an app config containing a given object. object_name is the dotted Python path to the object. Return the app config for the inner application in case of nesting. Return None if the object isn't in any registered app config.
Look for an app config containing a given object.
def get_containing_app_config(self, object_name): """ Look for an app config containing a given object. object_name is the dotted Python path to the object. Return the app config for the inner application in case of nesting. Return None if the object isn't in any registered app...
[ "def", "get_containing_app_config", "(", "self", ",", "object_name", ")", ":", "self", ".", "check_apps_ready", "(", ")", "candidates", "=", "[", "]", "for", "app_config", "in", "self", ".", "app_configs", ".", "values", "(", ")", ":", "if", "object_name", ...
[ 243, 4 ]
[ 260, 70 ]
python
en
['en', 'error', 'th']
False
Apps.get_registered_model
(self, app_label, model_name)
Similar to get_model(), but doesn't require that an app exists with the given app_label. It's safe to call this method at import time, even while the registry is being populated.
Similar to get_model(), but doesn't require that an app exists with the given app_label.
def get_registered_model(self, app_label, model_name): """ Similar to get_model(), but doesn't require that an app exists with the given app_label. It's safe to call this method at import time, even while the registry is being populated. """ model = self.all_mode...
[ "def", "get_registered_model", "(", "self", ",", "app_label", ",", "model_name", ")", ":", "model", "=", "self", ".", "all_models", "[", "app_label", "]", ".", "get", "(", "model_name", ".", "lower", "(", ")", ")", "if", "model", "is", "None", ":", "ra...
[ 262, 4 ]
[ 274, 20 ]
python
en
['en', 'error', 'th']
False
Apps.get_swappable_settings_name
(self, to_string)
For a given model string (e.g. "auth.User"), return the name of the corresponding settings name if it refers to a swappable model. If the referred model is not swappable, return None. This method is decorated with lru_cache because it's performance critical when it comes to mig...
For a given model string (e.g. "auth.User"), return the name of the corresponding settings name if it refers to a swappable model. If the referred model is not swappable, return None.
def get_swappable_settings_name(self, to_string): """ For a given model string (e.g. "auth.User"), return the name of the corresponding settings name if it refers to a swappable model. If the referred model is not swappable, return None. This method is decorated with lru_cache b...
[ "def", "get_swappable_settings_name", "(", "self", ",", "to_string", ")", ":", "for", "model", "in", "self", ".", "get_models", "(", "include_swapped", "=", "True", ")", ":", "swapped", "=", "model", ".", "_meta", ".", "swapped", "# Is this model swapped out for...
[ 277, 4 ]
[ 296, 19 ]
python
en
['en', 'error', 'th']
False
Apps.set_available_apps
(self, available)
Restrict the set of installed apps used by get_app_config[s]. available must be an iterable of application names. set_available_apps() must be balanced with unset_available_apps(). Primarily used for performance optimization in TransactionTestCase. This method is safe in the...
Restrict the set of installed apps used by get_app_config[s].
def set_available_apps(self, available): """ Restrict the set of installed apps used by get_app_config[s]. available must be an iterable of application names. set_available_apps() must be balanced with unset_available_apps(). Primarily used for performance optimization in Tran...
[ "def", "set_available_apps", "(", "self", ",", "available", ")", ":", "available", "=", "set", "(", "available", ")", "installed", "=", "{", "app_config", ".", "name", "for", "app_config", "in", "self", ".", "get_app_configs", "(", ")", "}", "if", "not", ...
[ 298, 4 ]
[ 324, 26 ]
python
en
['en', 'error', 'th']
False
Apps.unset_available_apps
(self)
Cancel a previous call to set_available_apps().
Cancel a previous call to set_available_apps().
def unset_available_apps(self): """Cancel a previous call to set_available_apps().""" self.app_configs = self.stored_app_configs.pop() self.clear_cache()
[ "def", "unset_available_apps", "(", "self", ")", ":", "self", ".", "app_configs", "=", "self", ".", "stored_app_configs", ".", "pop", "(", ")", "self", ".", "clear_cache", "(", ")" ]
[ 326, 4 ]
[ 329, 26 ]
python
en
['en', 'en', 'en']
True
Apps.set_installed_apps
(self, installed)
Enable a different set of installed apps for get_app_config[s]. installed must be an iterable in the same format as INSTALLED_APPS. set_installed_apps() must be balanced with unset_installed_apps(), even if it exits with an exception. Primarily used as a receiver of the setti...
Enable a different set of installed apps for get_app_config[s].
def set_installed_apps(self, installed): """ Enable a different set of installed apps for get_app_config[s]. installed must be an iterable in the same format as INSTALLED_APPS. set_installed_apps() must be balanced with unset_installed_apps(), even if it exits with an exception...
[ "def", "set_installed_apps", "(", "self", ",", "installed", ")", ":", "if", "not", "self", ".", "ready", ":", "raise", "AppRegistryNotReady", "(", "\"App registry isn't ready yet.\"", ")", "self", ".", "stored_app_configs", ".", "append", "(", "self", ".", "app_...
[ 331, 4 ]
[ 354, 32 ]
python
en
['en', 'error', 'th']
False
Apps.unset_installed_apps
(self)
Cancel a previous call to set_installed_apps().
Cancel a previous call to set_installed_apps().
def unset_installed_apps(self): """Cancel a previous call to set_installed_apps().""" self.app_configs = self.stored_app_configs.pop() self.apps_ready = self.models_ready = self.ready = True self.clear_cache()
[ "def", "unset_installed_apps", "(", "self", ")", ":", "self", ".", "app_configs", "=", "self", ".", "stored_app_configs", ".", "pop", "(", ")", "self", ".", "apps_ready", "=", "self", ".", "models_ready", "=", "self", ".", "ready", "=", "True", "self", "...
[ 356, 4 ]
[ 360, 26 ]
python
en
['en', 'en', 'en']
True
Apps.clear_cache
(self)
Clear all internal caches, for methods that alter the app registry. This is mostly used in tests.
Clear all internal caches, for methods that alter the app registry.
def clear_cache(self): """ Clear all internal caches, for methods that alter the app registry. This is mostly used in tests. """ # Call expire cache on each model. This will purge # the relation tree and the fields cache. self.get_models.cache_clear() if ...
[ "def", "clear_cache", "(", "self", ")", ":", "# Call expire cache on each model. This will purge", "# the relation tree and the fields cache.", "self", ".", "get_models", ".", "cache_clear", "(", ")", "if", "self", ".", "ready", ":", "# Circumvent self.get_models() to prevent...
[ 362, 4 ]
[ 376, 47 ]
python
en
['en', 'error', 'th']
False
Apps.lazy_model_operation
(self, function, *model_keys)
Take a function and a number of ("app_label", "modelname") tuples, and when all the corresponding models have been imported and registered, call the function with the model classes as its arguments. The function passed to this method must accept exactly n models as arguments, w...
Take a function and a number of ("app_label", "modelname") tuples, and when all the corresponding models have been imported and registered, call the function with the model classes as its arguments.
def lazy_model_operation(self, function, *model_keys): """ Take a function and a number of ("app_label", "modelname") tuples, and when all the corresponding models have been imported and registered, call the function with the model classes as its arguments. The function passed t...
[ "def", "lazy_model_operation", "(", "self", ",", "function", ",", "*", "model_keys", ")", ":", "# Base case: no arguments, just execute the function.", "if", "not", "model_keys", ":", "function", "(", ")", "# Recursive case: take the head of model_keys, wait for the", "# corr...
[ 378, 4 ]
[ 415, 45 ]
python
en
['en', 'error', 'th']
False
Apps.do_pending_operations
(self, model)
Take a newly-prepared model and pass it to each function waiting for it. This is called at the very end of Apps.register_model().
Take a newly-prepared model and pass it to each function waiting for it. This is called at the very end of Apps.register_model().
def do_pending_operations(self, model): """ Take a newly-prepared model and pass it to each function waiting for it. This is called at the very end of Apps.register_model(). """ key = model._meta.app_label, model._meta.model_name for function in self._pending_operations.p...
[ "def", "do_pending_operations", "(", "self", ",", "model", ")", ":", "key", "=", "model", ".", "_meta", ".", "app_label", ",", "model", ".", "_meta", ".", "model_name", "for", "function", "in", "self", ".", "_pending_operations", ".", "pop", "(", "key", ...
[ 417, 4 ]
[ 424, 27 ]
python
en
['en', 'error', 'th']
False
staticfiles_urlpatterns
(prefix=None)
Helper function to return a URL pattern for serving static files.
Helper function to return a URL pattern for serving static files.
def staticfiles_urlpatterns(prefix=None): """ Helper function to return a URL pattern for serving static files. """ if prefix is None: prefix = settings.STATIC_URL return static(prefix, view=serve)
[ "def", "staticfiles_urlpatterns", "(", "prefix", "=", "None", ")", ":", "if", "prefix", "is", "None", ":", "prefix", "=", "settings", ".", "STATIC_URL", "return", "static", "(", "prefix", ",", "view", "=", "serve", ")" ]
[ 7, 0 ]
[ 13, 37 ]
python
en
['en', 'error', 'th']
False
bytes2int
(raw_bytes)
r"""Converts a list of bytes or an 8-bit string to an integer. When using unicode strings, encode it to some encoding like UTF8 first. >>> (((128 * 256) + 64) * 256) + 15 8405007 >>> bytes2int(b'\x80@\x0f') 8405007
r"""Converts a list of bytes or an 8-bit string to an integer.
def bytes2int(raw_bytes): r"""Converts a list of bytes or an 8-bit string to an integer. When using unicode strings, encode it to some encoding like UTF8 first. >>> (((128 * 256) + 64) * 256) + 15 8405007 >>> bytes2int(b'\x80@\x0f') 8405007 """ return int(binascii.hexlify(raw_bytes),...
[ "def", "bytes2int", "(", "raw_bytes", ")", ":", "return", "int", "(", "binascii", ".", "hexlify", "(", "raw_bytes", ")", ",", "16", ")" ]
[ 30, 0 ]
[ 42, 47 ]
python
en
['en', 'en', 'en']
True
_int2bytes
(number, block_size=None)
r"""Converts a number to a string of bytes. Usage:: >>> _int2bytes(123456789) b'\x07[\xcd\x15' >>> bytes2int(_int2bytes(123456789)) 123456789 >>> _int2bytes(123456789, 6) b'\x00\x00\x07[\xcd\x15' >>> bytes2int(_int2bytes(123456789, 128)) 123456789 ...
r"""Converts a number to a string of bytes.
def _int2bytes(number, block_size=None): r"""Converts a number to a string of bytes. Usage:: >>> _int2bytes(123456789) b'\x07[\xcd\x15' >>> bytes2int(_int2bytes(123456789)) 123456789 >>> _int2bytes(123456789, 6) b'\x00\x00\x07[\xcd\x15' >>> bytes2int(_i...
[ "def", "_int2bytes", "(", "number", ",", "block_size", "=", "None", ")", ":", "# Type checking", "if", "not", "is_integer", "(", "number", ")", ":", "raise", "TypeError", "(", "\"You must pass an integer for 'number', not %s\"", "%", "number", ".", "__class__", ")...
[ 45, 0 ]
[ 107, 40 ]
python
en
['en', 'en', 'en']
True
bytes_leading
(raw_bytes, needle=b'\x00')
Finds the number of prefixed byte occurrences in the haystack. Useful when you want to deal with padding. :param raw_bytes: Raw bytes. :param needle: The byte to count. Default \x00. :returns: The number of leading needle bytes.
Finds the number of prefixed byte occurrences in the haystack.
def bytes_leading(raw_bytes, needle=b'\x00'): """ Finds the number of prefixed byte occurrences in the haystack. Useful when you want to deal with padding. :param raw_bytes: Raw bytes. :param needle: The byte to count. Default \x00. :returns: The number of leading needl...
[ "def", "bytes_leading", "(", "raw_bytes", ",", "needle", "=", "b'\\x00'", ")", ":", "leading", "=", "0", "# Indexing keeps compatibility between Python 2.x and Python 3.x", "_byte", "=", "needle", "[", "0", "]", "for", "x", "in", "raw_bytes", ":", "if", "x", "==...
[ 110, 0 ]
[ 132, 18 ]
python
en
['en', 'error', 'th']
False
int2bytes
(number, fill_size=None, chunk_size=None, overflow=False)
Convert an unsigned integer to bytes (base-256 representation):: Does not preserve leading zeros if you don't specify a chunk size or fill size. .. NOTE: You must not specify both fill_size and chunk_size. Only one of them is allowed. :param number: Integer value :par...
Convert an unsigned integer to bytes (base-256 representation)::
def int2bytes(number, fill_size=None, chunk_size=None, overflow=False): """ Convert an unsigned integer to bytes (base-256 representation):: Does not preserve leading zeros if you don't specify a chunk size or fill size. .. NOTE: You must not specify both fill_size and chunk_size. Only one...
[ "def", "int2bytes", "(", "number", ",", "fill_size", "=", "None", ",", "chunk_size", "=", "None", ",", "overflow", "=", "False", ")", ":", "if", "number", "<", "0", ":", "raise", "ValueError", "(", "\"Number must be an unsigned integer: %d\"", "%", "number", ...
[ 135, 0 ]
[ 208, 20 ]
python
en
['en', 'error', 'th']
False
getimage
(photo)
Copies the contents of a PhotoImage to a PIL image memory.
Copies the contents of a PhotoImage to a PIL image memory.
def getimage(photo): """Copies the contents of a PhotoImage to a PIL image memory.""" im = Image.new("RGBA", (photo.width(), photo.height())) block = im.im photo.tk.call("PyImagingPhotoGet", photo, block.id) return im
[ "def", "getimage", "(", "photo", ")", ":", "im", "=", "Image", ".", "new", "(", "\"RGBA\"", ",", "(", "photo", ".", "width", "(", ")", ",", "photo", ".", "height", "(", ")", ")", ")", "block", "=", "im", ".", "im", "photo", ".", "tk", ".", "c...
[ 273, 0 ]
[ 280, 13 ]
python
en
['en', 'en', 'en']
True
_show
(image, title)
Helper for the Image.show method.
Helper for the Image.show method.
def _show(image, title): """Helper for the Image.show method.""" class UI(tkinter.Label): def __init__(self, master, im): if im.mode == "1": self.image = BitmapImage(im, foreground="white", master=master) else: self.image = PhotoImage(im, master=m...
[ "def", "_show", "(", "image", ",", "title", ")", ":", "class", "UI", "(", "tkinter", ".", "Label", ")", ":", "def", "__init__", "(", "self", ",", "master", ",", "im", ")", ":", "if", "im", ".", "mode", "==", "\"1\"", ":", "self", ".", "image", ...
[ 283, 0 ]
[ 299, 25 ]
python
en
['en', 'en', 'en']
True
PhotoImage.__str__
(self)
Get the Tkinter photo image identifier. This method is automatically called by Tkinter whenever a PhotoImage object is passed to a Tkinter method. :return: A Tkinter photo image identifier (a string).
Get the Tkinter photo image identifier. This method is automatically called by Tkinter whenever a PhotoImage object is passed to a Tkinter method.
def __str__(self): """ Get the Tkinter photo image identifier. This method is automatically called by Tkinter whenever a PhotoImage object is passed to a Tkinter method. :return: A Tkinter photo image identifier (a string). """ return str(self.__photo)
[ "def", "__str__", "(", "self", ")", ":", "return", "str", "(", "self", ".", "__photo", ")" ]
[ 124, 4 ]
[ 132, 32 ]
python
en
['en', 'error', 'th']
False
PhotoImage.width
(self)
Get the width of the image. :return: The width, in pixels.
Get the width of the image.
def width(self): """ Get the width of the image. :return: The width, in pixels. """ return self.__size[0]
[ "def", "width", "(", "self", ")", ":", "return", "self", ".", "__size", "[", "0", "]" ]
[ 134, 4 ]
[ 140, 29 ]
python
en
['en', 'error', 'th']
False
PhotoImage.height
(self)
Get the height of the image. :return: The height, in pixels.
Get the height of the image.
def height(self): """ Get the height of the image. :return: The height, in pixels. """ return self.__size[1]
[ "def", "height", "(", "self", ")", ":", "return", "self", ".", "__size", "[", "1", "]" ]
[ 142, 4 ]
[ 148, 29 ]
python
en
['en', 'error', 'th']
False
PhotoImage.paste
(self, im, box=None)
Paste a PIL image into the photo image. Note that this can be very slow if the photo image is displayed. :param im: A PIL image. The size must match the target region. If the mode does not match, the image is converted to the mode of the bitmap image. ...
Paste a PIL image into the photo image. Note that this can be very slow if the photo image is displayed.
def paste(self, im, box=None): """ Paste a PIL image into the photo image. Note that this can be very slow if the photo image is displayed. :param im: A PIL image. The size must match the target region. If the mode does not match, the image is converted to the mode ...
[ "def", "paste", "(", "self", ",", "im", ",", "box", "=", "None", ")", ":", "# convert to blittable", "im", ".", "load", "(", ")", "image", "=", "im", ".", "im", "if", "image", ".", "isblock", "(", ")", "and", "im", ".", "mode", "==", "self", ".",...
[ 150, 4 ]
[ 198, 21 ]
python
en
['en', 'error', 'th']
False
BitmapImage.width
(self)
Get the width of the image. :return: The width, in pixels.
Get the width of the image.
def width(self): """ Get the width of the image. :return: The width, in pixels. """ return self.__size[0]
[ "def", "width", "(", "self", ")", ":", "return", "self", ".", "__size", "[", "0", "]" ]
[ 246, 4 ]
[ 252, 29 ]
python
en
['en', 'error', 'th']
False
BitmapImage.height
(self)
Get the height of the image. :return: The height, in pixels.
Get the height of the image.
def height(self): """ Get the height of the image. :return: The height, in pixels. """ return self.__size[1]
[ "def", "height", "(", "self", ")", ":", "return", "self", ".", "__size", "[", "1", "]" ]
[ 254, 4 ]
[ 260, 29 ]
python
en
['en', 'error', 'th']
False
BitmapImage.__str__
(self)
Get the Tkinter bitmap image identifier. This method is automatically called by Tkinter whenever a BitmapImage object is passed to a Tkinter method. :return: A Tkinter bitmap image identifier (a string).
Get the Tkinter bitmap image identifier. This method is automatically called by Tkinter whenever a BitmapImage object is passed to a Tkinter method.
def __str__(self): """ Get the Tkinter bitmap image identifier. This method is automatically called by Tkinter whenever a BitmapImage object is passed to a Tkinter method. :return: A Tkinter bitmap image identifier (a string). """ return str(self.__photo)
[ "def", "__str__", "(", "self", ")", ":", "return", "str", "(", "self", ".", "__photo", ")" ]
[ 262, 4 ]
[ 270, 32 ]
python
en
['en', 'error', 'th']
False
_date_from_string
(year, year_format, month='', month_format='', day='', day_format='', delim='__')
Get a datetime.date object given a format string and a year, month, and day (only year is mandatory). Raise a 404 for an invalid date.
Get a datetime.date object given a format string and a year, month, and day (only year is mandatory). Raise a 404 for an invalid date.
def _date_from_string(year, year_format, month='', month_format='', day='', day_format='', delim='__'): """ Get a datetime.date object given a format string and a year, month, and day (only year is mandatory). Raise a 404 for an invalid date. """ format = year_format + delim + month_format + delim +...
[ "def", "_date_from_string", "(", "year", ",", "year_format", ",", "month", "=", "''", ",", "month_format", "=", "''", ",", "day", "=", "''", ",", "day_format", "=", "''", ",", "delim", "=", "'__'", ")", ":", "format", "=", "year_format", "+", "delim", ...
[ 617, 0 ]
[ 630, 10 ]
python
en
['en', 'error', 'th']
False
_get_next_prev
(generic_view, date, is_previous, period)
Get the next or the previous valid date. The idea is to allow links on month/day views to never be 404s by never providing a date that'll be invalid for the given view. This is a bit complicated since it handles different intervals of time, hence the coupling to generic_view. However in essen...
Get the next or the previous valid date. The idea is to allow links on month/day views to never be 404s by never providing a date that'll be invalid for the given view.
def _get_next_prev(generic_view, date, is_previous, period): """ Get the next or the previous valid date. The idea is to allow links on month/day views to never be 404s by never providing a date that'll be invalid for the given view. This is a bit complicated since it handles different intervals of...
[ "def", "_get_next_prev", "(", "generic_view", ",", "date", ",", "is_previous", ",", "period", ")", ":", "date_field", "=", "generic_view", ".", "get_date_field", "(", ")", "allow_empty", "=", "generic_view", ".", "get_allow_empty", "(", ")", "allow_future", "=",...
[ 633, 0 ]
[ 720, 34 ]
python
en
['en', 'error', 'th']
False
timezone_today
()
Return the current date in the current time zone.
Return the current date in the current time zone.
def timezone_today(): """Return the current date in the current time zone.""" if settings.USE_TZ: return timezone.localdate() else: return datetime.date.today()
[ "def", "timezone_today", "(", ")", ":", "if", "settings", ".", "USE_TZ", ":", "return", "timezone", ".", "localdate", "(", ")", "else", ":", "return", "datetime", ".", "date", ".", "today", "(", ")" ]
[ 723, 0 ]
[ 728, 36 ]
python
en
['en', 'en', 'en']
True
YearMixin.get_year_format
(self)
Get a year format string in strptime syntax to be used to parse the year from url variables.
Get a year format string in strptime syntax to be used to parse the year from url variables.
def get_year_format(self): """ Get a year format string in strptime syntax to be used to parse the year from url variables. """ return self.year_format
[ "def", "get_year_format", "(", "self", ")", ":", "return", "self", ".", "year_format" ]
[ 23, 4 ]
[ 28, 31 ]
python
en
['en', 'error', 'th']
False
YearMixin.get_year
(self)
Return the year for which this view should display data.
Return the year for which this view should display data.
def get_year(self): """Return the year for which this view should display data.""" year = self.year if year is None: try: year = self.kwargs['year'] except KeyError: try: year = self.request.GET['year'] e...
[ "def", "get_year", "(", "self", ")", ":", "year", "=", "self", ".", "year", "if", "year", "is", "None", ":", "try", ":", "year", "=", "self", ".", "kwargs", "[", "'year'", "]", "except", "KeyError", ":", "try", ":", "year", "=", "self", ".", "req...
[ 30, 4 ]
[ 41, 19 ]
python
en
['en', 'en', 'en']
True
YearMixin.get_next_year
(self, date)
Get the next valid year.
Get the next valid year.
def get_next_year(self, date): """Get the next valid year.""" return _get_next_prev(self, date, is_previous=False, period='year')
[ "def", "get_next_year", "(", "self", ",", "date", ")", ":", "return", "_get_next_prev", "(", "self", ",", "date", ",", "is_previous", "=", "False", ",", "period", "=", "'year'", ")" ]
[ 43, 4 ]
[ 45, 75 ]
python
en
['en', 'en', 'en']
True
YearMixin.get_previous_year
(self, date)
Get the previous valid year.
Get the previous valid year.
def get_previous_year(self, date): """Get the previous valid year.""" return _get_next_prev(self, date, is_previous=True, period='year')
[ "def", "get_previous_year", "(", "self", ",", "date", ")", ":", "return", "_get_next_prev", "(", "self", ",", "date", ",", "is_previous", "=", "True", ",", "period", "=", "'year'", ")" ]
[ 47, 4 ]
[ 49, 74 ]
python
en
['en', 'en', 'en']
True
YearMixin._get_next_year
(self, date)
Return the start date of the next interval. The interval is defined by start date <= item date < next start date.
Return the start date of the next interval.
def _get_next_year(self, date): """ Return the start date of the next interval. The interval is defined by start date <= item date < next start date. """ try: return date.replace(year=date.year + 1, month=1, day=1) except ValueError: raise Http404...
[ "def", "_get_next_year", "(", "self", ",", "date", ")", ":", "try", ":", "return", "date", ".", "replace", "(", "year", "=", "date", ".", "year", "+", "1", ",", "month", "=", "1", ",", "day", "=", "1", ")", "except", "ValueError", ":", "raise", "...
[ 51, 4 ]
[ 60, 49 ]
python
en
['en', 'error', 'th']
False
YearMixin._get_current_year
(self, date)
Return the start date of the current interval.
Return the start date of the current interval.
def _get_current_year(self, date): """Return the start date of the current interval.""" return date.replace(month=1, day=1)
[ "def", "_get_current_year", "(", "self", ",", "date", ")", ":", "return", "date", ".", "replace", "(", "month", "=", "1", ",", "day", "=", "1", ")" ]
[ 62, 4 ]
[ 64, 43 ]
python
en
['en', 'en', 'en']
True
MonthMixin.get_month_format
(self)
Get a month format string in strptime syntax to be used to parse the month from url variables.
Get a month format string in strptime syntax to be used to parse the month from url variables.
def get_month_format(self): """ Get a month format string in strptime syntax to be used to parse the month from url variables. """ return self.month_format
[ "def", "get_month_format", "(", "self", ")", ":", "return", "self", ".", "month_format" ]
[ 72, 4 ]
[ 77, 32 ]
python
en
['en', 'error', 'th']
False
MonthMixin.get_month
(self)
Return the month for which this view should display data.
Return the month for which this view should display data.
def get_month(self): """Return the month for which this view should display data.""" month = self.month if month is None: try: month = self.kwargs['month'] except KeyError: try: month = self.request.GET['month'] ...
[ "def", "get_month", "(", "self", ")", ":", "month", "=", "self", ".", "month", "if", "month", "is", "None", ":", "try", ":", "month", "=", "self", ".", "kwargs", "[", "'month'", "]", "except", "KeyError", ":", "try", ":", "month", "=", "self", ".",...
[ 79, 4 ]
[ 90, 20 ]
python
en
['en', 'en', 'en']
True
MonthMixin.get_next_month
(self, date)
Get the next valid month.
Get the next valid month.
def get_next_month(self, date): """Get the next valid month.""" return _get_next_prev(self, date, is_previous=False, period='month')
[ "def", "get_next_month", "(", "self", ",", "date", ")", ":", "return", "_get_next_prev", "(", "self", ",", "date", ",", "is_previous", "=", "False", ",", "period", "=", "'month'", ")" ]
[ 92, 4 ]
[ 94, 76 ]
python
en
['en', 'en', 'en']
True
MonthMixin.get_previous_month
(self, date)
Get the previous valid month.
Get the previous valid month.
def get_previous_month(self, date): """Get the previous valid month.""" return _get_next_prev(self, date, is_previous=True, period='month')
[ "def", "get_previous_month", "(", "self", ",", "date", ")", ":", "return", "_get_next_prev", "(", "self", ",", "date", ",", "is_previous", "=", "True", ",", "period", "=", "'month'", ")" ]
[ 96, 4 ]
[ 98, 75 ]
python
en
['en', 'en', 'en']
True
MonthMixin._get_next_month
(self, date)
Return the start date of the next interval. The interval is defined by start date <= item date < next start date.
Return the start date of the next interval.
def _get_next_month(self, date): """ Return the start date of the next interval. The interval is defined by start date <= item date < next start date. """ if date.month == 12: try: return date.replace(year=date.year + 1, month=1, day=1) ex...
[ "def", "_get_next_month", "(", "self", ",", "date", ")", ":", "if", "date", ".", "month", "==", "12", ":", "try", ":", "return", "date", ".", "replace", "(", "year", "=", "date", ".", "year", "+", "1", ",", "month", "=", "1", ",", "day", "=", "...
[ 100, 4 ]
[ 112, 60 ]
python
en
['en', 'error', 'th']
False
MonthMixin._get_current_month
(self, date)
Return the start date of the previous interval.
Return the start date of the previous interval.
def _get_current_month(self, date): """Return the start date of the previous interval.""" return date.replace(day=1)
[ "def", "_get_current_month", "(", "self", ",", "date", ")", ":", "return", "date", ".", "replace", "(", "day", "=", "1", ")" ]
[ 114, 4 ]
[ 116, 34 ]
python
en
['en', 'en', 'en']
True
DayMixin.get_day_format
(self)
Get a day format string in strptime syntax to be used to parse the day from url variables.
Get a day format string in strptime syntax to be used to parse the day from url variables.
def get_day_format(self): """ Get a day format string in strptime syntax to be used to parse the day from url variables. """ return self.day_format
[ "def", "get_day_format", "(", "self", ")", ":", "return", "self", ".", "day_format" ]
[ 124, 4 ]
[ 129, 30 ]
python
en
['en', 'error', 'th']
False
DayMixin.get_day
(self)
Return the day for which this view should display data.
Return the day for which this view should display data.
def get_day(self): """Return the day for which this view should display data.""" day = self.day if day is None: try: day = self.kwargs['day'] except KeyError: try: day = self.request.GET['day'] except Key...
[ "def", "get_day", "(", "self", ")", ":", "day", "=", "self", ".", "day", "if", "day", "is", "None", ":", "try", ":", "day", "=", "self", ".", "kwargs", "[", "'day'", "]", "except", "KeyError", ":", "try", ":", "day", "=", "self", ".", "request", ...
[ 131, 4 ]
[ 142, 18 ]
python
en
['en', 'en', 'en']
True
DayMixin.get_next_day
(self, date)
Get the next valid day.
Get the next valid day.
def get_next_day(self, date): """Get the next valid day.""" return _get_next_prev(self, date, is_previous=False, period='day')
[ "def", "get_next_day", "(", "self", ",", "date", ")", ":", "return", "_get_next_prev", "(", "self", ",", "date", ",", "is_previous", "=", "False", ",", "period", "=", "'day'", ")" ]
[ 144, 4 ]
[ 146, 74 ]
python
en
['en', 'en', 'en']
True
DayMixin.get_previous_day
(self, date)
Get the previous valid day.
Get the previous valid day.
def get_previous_day(self, date): """Get the previous valid day.""" return _get_next_prev(self, date, is_previous=True, period='day')
[ "def", "get_previous_day", "(", "self", ",", "date", ")", ":", "return", "_get_next_prev", "(", "self", ",", "date", ",", "is_previous", "=", "True", ",", "period", "=", "'day'", ")" ]
[ 148, 4 ]
[ 150, 73 ]
python
en
['en', 'en', 'en']
True
DayMixin._get_next_day
(self, date)
Return the start date of the next interval. The interval is defined by start date <= item date < next start date.
Return the start date of the next interval.
def _get_next_day(self, date): """ Return the start date of the next interval. The interval is defined by start date <= item date < next start date. """ return date + datetime.timedelta(days=1)
[ "def", "_get_next_day", "(", "self", ",", "date", ")", ":", "return", "date", "+", "datetime", ".", "timedelta", "(", "days", "=", "1", ")" ]
[ 152, 4 ]
[ 158, 48 ]
python
en
['en', 'error', 'th']
False
DayMixin._get_current_day
(self, date)
Return the start date of the current interval.
Return the start date of the current interval.
def _get_current_day(self, date): """Return the start date of the current interval.""" return date
[ "def", "_get_current_day", "(", "self", ",", "date", ")", ":", "return", "date" ]
[ 160, 4 ]
[ 162, 19 ]
python
en
['en', 'en', 'en']
True
WeekMixin.get_week_format
(self)
Get a week format string in strptime syntax to be used to parse the week from url variables.
Get a week format string in strptime syntax to be used to parse the week from url variables.
def get_week_format(self): """ Get a week format string in strptime syntax to be used to parse the week from url variables. """ return self.week_format
[ "def", "get_week_format", "(", "self", ")", ":", "return", "self", ".", "week_format" ]
[ 170, 4 ]
[ 175, 31 ]
python
en
['en', 'error', 'th']
False
WeekMixin.get_week
(self)
Return the week for which this view should display data.
Return the week for which this view should display data.
def get_week(self): """Return the week for which this view should display data.""" week = self.week if week is None: try: week = self.kwargs['week'] except KeyError: try: week = self.request.GET['week'] e...
[ "def", "get_week", "(", "self", ")", ":", "week", "=", "self", ".", "week", "if", "week", "is", "None", ":", "try", ":", "week", "=", "self", ".", "kwargs", "[", "'week'", "]", "except", "KeyError", ":", "try", ":", "week", "=", "self", ".", "req...
[ 177, 4 ]
[ 188, 19 ]
python
en
['en', 'en', 'en']
True
WeekMixin.get_next_week
(self, date)
Get the next valid week.
Get the next valid week.
def get_next_week(self, date): """Get the next valid week.""" return _get_next_prev(self, date, is_previous=False, period='week')
[ "def", "get_next_week", "(", "self", ",", "date", ")", ":", "return", "_get_next_prev", "(", "self", ",", "date", ",", "is_previous", "=", "False", ",", "period", "=", "'week'", ")" ]
[ 190, 4 ]
[ 192, 75 ]
python
en
['en', 'af', 'en']
True