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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
SpatiaLiteCreation._create_test_db_pre_migrate_sql | (self) |
Creates the spatial metadata tables.
|
Creates the spatial metadata tables.
| def _create_test_db_pre_migrate_sql(self):
"""
Creates the spatial metadata tables.
"""
cur = self.connection._cursor()
cur.execute("SELECT InitSpatialMetaData()") | [
"def",
"_create_test_db_pre_migrate_sql",
"(",
"self",
")",
":",
"cur",
"=",
"self",
".",
"connection",
".",
"_cursor",
"(",
")",
"cur",
".",
"execute",
"(",
"\"SELECT InitSpatialMetaData()\"",
")"
] | [
33,
4
] | [
38,
51
] | python | en | ['en', 'error', 'th'] | False |
copyfileobj | (fsrc, fdst, length=16*1024) | copy data from file-like object fsrc to file-like object fdst | copy data from file-like object fsrc to file-like object fdst | def copyfileobj(fsrc, fdst, length=16*1024):
"""copy data from file-like object fsrc to file-like object fdst"""
while 1:
buf = fsrc.read(length)
if not buf:
break
fdst.write(buf) | [
"def",
"copyfileobj",
"(",
"fsrc",
",",
"fdst",
",",
"length",
"=",
"16",
"*",
"1024",
")",
":",
"while",
"1",
":",
"buf",
"=",
"fsrc",
".",
"read",
"(",
"length",
")",
"if",
"not",
"buf",
":",
"break",
"fdst",
".",
"write",
"(",
"buf",
")"
] | [
66,
0
] | [
72,
23
] | python | en | ['en', 'en', 'en'] | True |
copyfile | (src, dst) | Copy data from src to dst | Copy data from src to dst | def copyfile(src, dst):
"""Copy data from src to dst"""
if _samefile(src, dst):
raise Error("`%s` and `%s` are the same file" % (src, dst))
for fn in [src, dst]:
try:
st = os.stat(fn)
except OSError:
# File most likely does not exist
pass
... | [
"def",
"copyfile",
"(",
"src",
",",
"dst",
")",
":",
"if",
"_samefile",
"(",
"src",
",",
"dst",
")",
":",
"raise",
"Error",
"(",
"\"`%s` and `%s` are the same file\"",
"%",
"(",
"src",
",",
"dst",
")",
")",
"for",
"fn",
"in",
"[",
"src",
",",
"dst",
... | [
86,
0
] | [
104,
35
] | python | en | ['en', 'en', 'en'] | True |
copymode | (src, dst) | Copy mode bits from src to dst | Copy mode bits from src to dst | def copymode(src, dst):
"""Copy mode bits from src to dst"""
if hasattr(os, 'chmod'):
st = os.stat(src)
mode = stat.S_IMODE(st.st_mode)
os.chmod(dst, mode) | [
"def",
"copymode",
"(",
"src",
",",
"dst",
")",
":",
"if",
"hasattr",
"(",
"os",
",",
"'chmod'",
")",
":",
"st",
"=",
"os",
".",
"stat",
"(",
"src",
")",
"mode",
"=",
"stat",
".",
"S_IMODE",
"(",
"st",
".",
"st_mode",
")",
"os",
".",
"chmod",
... | [
106,
0
] | [
111,
27
] | python | en | ['en', 'en', 'en'] | True |
copystat | (src, dst) | Copy all stat info (mode bits, atime, mtime, flags) from src to dst | Copy all stat info (mode bits, atime, mtime, flags) from src to dst | def copystat(src, dst):
"""Copy all stat info (mode bits, atime, mtime, flags) from src to dst"""
st = os.stat(src)
mode = stat.S_IMODE(st.st_mode)
if hasattr(os, 'utime'):
os.utime(dst, (st.st_atime, st.st_mtime))
if hasattr(os, 'chmod'):
os.chmod(dst, mode)
if hasattr(os, 'chfl... | [
"def",
"copystat",
"(",
"src",
",",
"dst",
")",
":",
"st",
"=",
"os",
".",
"stat",
"(",
"src",
")",
"mode",
"=",
"stat",
".",
"S_IMODE",
"(",
"st",
".",
"st_mode",
")",
"if",
"hasattr",
"(",
"os",
",",
"'utime'",
")",
":",
"os",
".",
"utime",
... | [
113,
0
] | [
127,
21
] | python | en | ['en', 'en', 'en'] | True |
copy | (src, dst) | Copy data and mode bits ("cp src dst").
The destination may be a directory.
| Copy data and mode bits ("cp src dst"). | def copy(src, dst):
"""Copy data and mode bits ("cp src dst").
The destination may be a directory.
"""
if os.path.isdir(dst):
dst = os.path.join(dst, os.path.basename(src))
copyfile(src, dst)
copymode(src, dst) | [
"def",
"copy",
"(",
"src",
",",
"dst",
")",
":",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"dst",
")",
":",
"dst",
"=",
"os",
".",
"path",
".",
"join",
"(",
"dst",
",",
"os",
".",
"path",
".",
"basename",
"(",
"src",
")",
")",
"copyfile",
... | [
129,
0
] | [
138,
22
] | python | en | ['en', 'en', 'en'] | True |
copy2 | (src, dst) | Copy data and all stat info ("cp -p src dst").
The destination may be a directory.
| Copy data and all stat info ("cp -p src dst"). | def copy2(src, dst):
"""Copy data and all stat info ("cp -p src dst").
The destination may be a directory.
"""
if os.path.isdir(dst):
dst = os.path.join(dst, os.path.basename(src))
copyfile(src, dst)
copystat(src, dst) | [
"def",
"copy2",
"(",
"src",
",",
"dst",
")",
":",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"dst",
")",
":",
"dst",
"=",
"os",
".",
"path",
".",
"join",
"(",
"dst",
",",
"os",
".",
"path",
".",
"basename",
"(",
"src",
")",
")",
"copyfile",
... | [
140,
0
] | [
149,
22
] | python | en | ['en', 'en', 'en'] | True |
ignore_patterns | (*patterns) | Function that can be used as copytree() ignore parameter.
Patterns is a sequence of glob-style patterns
that are used to exclude files | Function that can be used as copytree() ignore parameter. | def ignore_patterns(*patterns):
"""Function that can be used as copytree() ignore parameter.
Patterns is a sequence of glob-style patterns
that are used to exclude files"""
def _ignore_patterns(path, names):
ignored_names = []
for pattern in patterns:
ignored_names.extend(fn... | [
"def",
"ignore_patterns",
"(",
"*",
"patterns",
")",
":",
"def",
"_ignore_patterns",
"(",
"path",
",",
"names",
")",
":",
"ignored_names",
"=",
"[",
"]",
"for",
"pattern",
"in",
"patterns",
":",
"ignored_names",
".",
"extend",
"(",
"fnmatch",
".",
"filter"... | [
151,
0
] | [
161,
27
] | python | en | ['en', 'en', 'en'] | True |
copytree | (src, dst, symlinks=False, ignore=None, copy_function=copy2,
ignore_dangling_symlinks=False) | Recursively copy a directory tree.
The destination directory must not already exist.
If exception(s) occur, an Error is raised with a list of reasons.
If the optional symlinks flag is true, symbolic links in the
source tree result in symbolic links in the destination tree; if
it is false, the cont... | Recursively copy a directory tree. | def copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2,
ignore_dangling_symlinks=False):
"""Recursively copy a directory tree.
The destination directory must not already exist.
If exception(s) occur, an Error is raised with a list of reasons.
If the optional symlinks flag... | [
"def",
"copytree",
"(",
"src",
",",
"dst",
",",
"symlinks",
"=",
"False",
",",
"ignore",
"=",
"None",
",",
"copy_function",
"=",
"copy2",
",",
"ignore_dangling_symlinks",
"=",
"False",
")",
":",
"names",
"=",
"os",
".",
"listdir",
"(",
"src",
")",
"if"... | [
163,
0
] | [
243,
27
] | python | en | ['en', 'en', 'en'] | True |
rmtree | (path, ignore_errors=False, onerror=None) | Recursively delete a directory tree.
If ignore_errors is set, errors are ignored; otherwise, if onerror
is set, it is called to handle the error with arguments (func,
path, exc_info) where func is os.listdir, os.remove, or os.rmdir;
path is the argument to that function that caused it to fail; and
... | Recursively delete a directory tree. | def rmtree(path, ignore_errors=False, onerror=None):
"""Recursively delete a directory tree.
If ignore_errors is set, errors are ignored; otherwise, if onerror
is set, it is called to handle the error with arguments (func,
path, exc_info) where func is os.listdir, os.remove, or os.rmdir;
path is th... | [
"def",
"rmtree",
"(",
"path",
",",
"ignore_errors",
"=",
"False",
",",
"onerror",
"=",
"None",
")",
":",
"if",
"ignore_errors",
":",
"def",
"onerror",
"(",
"*",
"args",
")",
":",
"pass",
"elif",
"onerror",
"is",
"None",
":",
"def",
"onerror",
"(",
"*... | [
245,
0
] | [
291,
47
] | python | en | ['en', 'en', 'en'] | True |
move | (src, dst) | Recursively move a file or directory to another location. This is
similar to the Unix "mv" command.
If the destination is a directory or a symlink to a directory, the source
is moved inside the directory. The destination path must not already
exist.
If the destination already exists but is not a d... | Recursively move a file or directory to another location. This is
similar to the Unix "mv" command. | def move(src, dst):
"""Recursively move a file or directory to another location. This is
similar to the Unix "mv" command.
If the destination is a directory or a symlink to a directory, the source
is moved inside the directory. The destination path must not already
exist.
If the destination al... | [
"def",
"move",
"(",
"src",
",",
"dst",
")",
":",
"real_dst",
"=",
"dst",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"dst",
")",
":",
"if",
"_samefile",
"(",
"src",
",",
"dst",
")",
":",
"# We might be on a case insensitive filesystem,",
"# perform the ren... | [
299,
0
] | [
337,
26
] | python | en | ['en', 'en', 'en'] | True |
_get_gid | (name) | Returns a gid, given a group name. | Returns a gid, given a group name. | def _get_gid(name):
"""Returns a gid, given a group name."""
if getgrnam is None or name is None:
return None
try:
result = getgrnam(name)
except KeyError:
result = None
if result is not None:
return result[2]
return None | [
"def",
"_get_gid",
"(",
"name",
")",
":",
"if",
"getgrnam",
"is",
"None",
"or",
"name",
"is",
"None",
":",
"return",
"None",
"try",
":",
"result",
"=",
"getgrnam",
"(",
"name",
")",
"except",
"KeyError",
":",
"result",
"=",
"None",
"if",
"result",
"i... | [
348,
0
] | [
358,
15
] | python | en | ['en', 'en', 'en'] | True |
_get_uid | (name) | Returns an uid, given a user name. | Returns an uid, given a user name. | def _get_uid(name):
"""Returns an uid, given a user name."""
if getpwnam is None or name is None:
return None
try:
result = getpwnam(name)
except KeyError:
result = None
if result is not None:
return result[2]
return None | [
"def",
"_get_uid",
"(",
"name",
")",
":",
"if",
"getpwnam",
"is",
"None",
"or",
"name",
"is",
"None",
":",
"return",
"None",
"try",
":",
"result",
"=",
"getpwnam",
"(",
"name",
")",
"except",
"KeyError",
":",
"result",
"=",
"None",
"if",
"result",
"i... | [
360,
0
] | [
370,
15
] | python | en | ['en', 'en', 'en'] | True |
_make_tarball | (base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
owner=None, group=None, logger=None) | Create a (possibly compressed) tar file from all the files under
'base_dir'.
'compress' must be "gzip" (the default), "bzip2", or None.
'owner' and 'group' can be used to define an owner and a group for the
archive that is being built. If not provided, the current owner and group
will be used.
... | Create a (possibly compressed) tar file from all the files under
'base_dir'. | def _make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
owner=None, group=None, logger=None):
"""Create a (possibly compressed) tar file from all the files under
'base_dir'.
'compress' must be "gzip" (the default), "bzip2", or None.
'owner' and 'group' can be us... | [
"def",
"_make_tarball",
"(",
"base_name",
",",
"base_dir",
",",
"compress",
"=",
"\"gzip\"",
",",
"verbose",
"=",
"0",
",",
"dry_run",
"=",
"0",
",",
"owner",
"=",
"None",
",",
"group",
"=",
"None",
",",
"logger",
"=",
"None",
")",
":",
"tar_compressio... | [
372,
0
] | [
432,
23
] | python | en | ['en', 'en', 'en'] | True |
_make_zipfile | (base_name, base_dir, verbose=0, dry_run=0, logger=None) | Create a zip file from all the files under 'base_dir'.
The output zip file will be named 'base_name' + ".zip". Uses either the
"zipfile" Python module (if available) or the InfoZIP "zip" utility
(if installed and found on the default search path). If neither tool is
available, raises ExecError. Retu... | Create a zip file from all the files under 'base_dir'. | def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0, logger=None):
"""Create a zip file from all the files under 'base_dir'.
The output zip file will be named 'base_name' + ".zip". Uses either the
"zipfile" Python module (if available) or the InfoZIP "zip" utility
(if installed and found on th... | [
"def",
"_make_zipfile",
"(",
"base_name",
",",
"base_dir",
",",
"verbose",
"=",
"0",
",",
"dry_run",
"=",
"0",
",",
"logger",
"=",
"None",
")",
":",
"zip_filename",
"=",
"base_name",
"+",
"\".zip\"",
"archive_dir",
"=",
"os",
".",
"path",
".",
"dirname",... | [
451,
0
] | [
496,
23
] | python | en | ['en', 'en', 'en'] | True |
get_archive_formats | () | Returns a list of supported formats for archiving and unarchiving.
Each element of the returned sequence is a tuple (name, description)
| Returns a list of supported formats for archiving and unarchiving. | def get_archive_formats():
"""Returns a list of supported formats for archiving and unarchiving.
Each element of the returned sequence is a tuple (name, description)
"""
formats = [(name, registry[2]) for name, registry in
_ARCHIVE_FORMATS.items()]
formats.sort()
return formats | [
"def",
"get_archive_formats",
"(",
")",
":",
"formats",
"=",
"[",
"(",
"name",
",",
"registry",
"[",
"2",
"]",
")",
"for",
"name",
",",
"registry",
"in",
"_ARCHIVE_FORMATS",
".",
"items",
"(",
")",
"]",
"formats",
".",
"sort",
"(",
")",
"return",
"fo... | [
509,
0
] | [
517,
18
] | python | en | ['en', 'en', 'en'] | True |
register_archive_format | (name, function, extra_args=None, description='') | Registers an archive format.
name is the name of the format. function is the callable that will be
used to create archives. If provided, extra_args is a sequence of
(name, value) tuples that will be passed as arguments to the callable.
description can be provided to describe the format, and will be ret... | Registers an archive format. | def register_archive_format(name, function, extra_args=None, description=''):
"""Registers an archive format.
name is the name of the format. function is the callable that will be
used to create archives. If provided, extra_args is a sequence of
(name, value) tuples that will be passed as arguments to ... | [
"def",
"register_archive_format",
"(",
"name",
",",
"function",
",",
"extra_args",
"=",
"None",
",",
"description",
"=",
"''",
")",
":",
"if",
"extra_args",
"is",
"None",
":",
"extra_args",
"=",
"[",
"]",
"if",
"not",
"isinstance",
"(",
"function",
",",
... | [
519,
0
] | [
538,
64
] | python | en | ['en', 'en', 'en'] | True |
make_archive | (base_name, format, root_dir=None, base_dir=None, verbose=0,
dry_run=0, owner=None, group=None, logger=None) | Create an archive file (eg. zip or tar).
'base_name' is the name of the file to create, minus any format-specific
extension; 'format' is the archive format: one of "zip", "tar", "bztar"
or "gztar".
'root_dir' is a directory that will be the root directory of the
archive; ie. we typically chdir int... | Create an archive file (eg. zip or tar). | def make_archive(base_name, format, root_dir=None, base_dir=None, verbose=0,
dry_run=0, owner=None, group=None, logger=None):
"""Create an archive file (eg. zip or tar).
'base_name' is the name of the file to create, minus any format-specific
extension; 'format' is the archive format: one ... | [
"def",
"make_archive",
"(",
"base_name",
",",
"format",
",",
"root_dir",
"=",
"None",
",",
"base_dir",
"=",
"None",
",",
"verbose",
"=",
"0",
",",
"dry_run",
"=",
"0",
",",
"owner",
"=",
"None",
",",
"group",
"=",
"None",
",",
"logger",
"=",
"None",
... | [
543,
0
] | [
595,
19
] | python | en | ['en', 'gd', 'en'] | True |
get_unpack_formats | () | Returns a list of supported formats for unpacking.
Each element of the returned sequence is a tuple
(name, extensions, description)
| Returns a list of supported formats for unpacking. | def get_unpack_formats():
"""Returns a list of supported formats for unpacking.
Each element of the returned sequence is a tuple
(name, extensions, description)
"""
formats = [(name, info[0], info[3]) for name, info in
_UNPACK_FORMATS.items()]
formats.sort()
return formats | [
"def",
"get_unpack_formats",
"(",
")",
":",
"formats",
"=",
"[",
"(",
"name",
",",
"info",
"[",
"0",
"]",
",",
"info",
"[",
"3",
"]",
")",
"for",
"name",
",",
"info",
"in",
"_UNPACK_FORMATS",
".",
"items",
"(",
")",
"]",
"formats",
".",
"sort",
"... | [
598,
0
] | [
607,
18
] | python | en | ['en', 'en', 'en'] | True |
_check_unpack_options | (extensions, function, extra_args) | Checks what gets registered as an unpacker. | Checks what gets registered as an unpacker. | def _check_unpack_options(extensions, function, extra_args):
"""Checks what gets registered as an unpacker."""
# first make sure no other unpacker is registered for this extension
existing_extensions = {}
for name, info in _UNPACK_FORMATS.items():
for ext in info[0]:
existing_extensi... | [
"def",
"_check_unpack_options",
"(",
"extensions",
",",
"function",
",",
"extra_args",
")",
":",
"# first make sure no other unpacker is registered for this extension",
"existing_extensions",
"=",
"{",
"}",
"for",
"name",
",",
"info",
"in",
"_UNPACK_FORMATS",
".",
"items"... | [
609,
0
] | [
624,
69
] | python | en | ['en', 'en', 'en'] | True |
register_unpack_format | (name, extensions, function, extra_args=None,
description='') | Registers an unpack format.
`name` is the name of the format. `extensions` is a list of extensions
corresponding to the format.
`function` is the callable that will be
used to unpack archives. The callable will receive archives to unpack.
If it's unable to handle an archive, it needs to raise a Re... | Registers an unpack format. | def register_unpack_format(name, extensions, function, extra_args=None,
description=''):
"""Registers an unpack format.
`name` is the name of the format. `extensions` is a list of extensions
corresponding to the format.
`function` is the callable that will be
used to unp... | [
"def",
"register_unpack_format",
"(",
"name",
",",
"extensions",
",",
"function",
",",
"extra_args",
"=",
"None",
",",
"description",
"=",
"''",
")",
":",
"if",
"extra_args",
"is",
"None",
":",
"extra_args",
"=",
"[",
"]",
"_check_unpack_options",
"(",
"exte... | [
627,
0
] | [
647,
73
] | python | en | ['en', 'fr', 'en'] | True |
unregister_unpack_format | (name) | Removes the pack format from the registry. | Removes the pack format from the registry. | def unregister_unpack_format(name):
"""Removes the pack format from the registry."""
del _UNPACK_FORMATS[name] | [
"def",
"unregister_unpack_format",
"(",
"name",
")",
":",
"del",
"_UNPACK_FORMATS",
"[",
"name",
"]"
] | [
649,
0
] | [
651,
29
] | python | en | ['en', 'en', 'en'] | True |
_ensure_directory | (path) | Ensure that the parent directory of `path` exists | Ensure that the parent directory of `path` exists | def _ensure_directory(path):
"""Ensure that the parent directory of `path` exists"""
dirname = os.path.dirname(path)
if not os.path.isdir(dirname):
os.makedirs(dirname) | [
"def",
"_ensure_directory",
"(",
"path",
")",
":",
"dirname",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"path",
")",
"if",
"not",
"os",
".",
"path",
".",
"isdir",
"(",
"dirname",
")",
":",
"os",
".",
"makedirs",
"(",
"dirname",
")"
] | [
653,
0
] | [
657,
28
] | python | en | ['en', 'en', 'en'] | True |
_unpack_zipfile | (filename, extract_dir) | Unpack zip `filename` to `extract_dir`
| Unpack zip `filename` to `extract_dir`
| def _unpack_zipfile(filename, extract_dir):
"""Unpack zip `filename` to `extract_dir`
"""
try:
import zipfile
except ImportError:
raise ReadError('zlib not supported, cannot unpack this archive.')
if not zipfile.is_zipfile(filename):
raise ReadError("%s is not a zip file" % ... | [
"def",
"_unpack_zipfile",
"(",
"filename",
",",
"extract_dir",
")",
":",
"try",
":",
"import",
"zipfile",
"except",
"ImportError",
":",
"raise",
"ReadError",
"(",
"'zlib not supported, cannot unpack this archive.'",
")",
"if",
"not",
"zipfile",
".",
"is_zipfile",
"(... | [
659,
0
] | [
694,
19
] | python | en | ['en', 'nl', 'ur'] | False |
_unpack_tarfile | (filename, extract_dir) | Unpack tar/tar.gz/tar.bz2 `filename` to `extract_dir`
| Unpack tar/tar.gz/tar.bz2 `filename` to `extract_dir`
| def _unpack_tarfile(filename, extract_dir):
"""Unpack tar/tar.gz/tar.bz2 `filename` to `extract_dir`
"""
try:
tarobj = tarfile.open(filename)
except tarfile.TarError:
raise ReadError(
"%s is not a compressed or uncompressed tar file" % filename)
try:
tarobj.extrac... | [
"def",
"_unpack_tarfile",
"(",
"filename",
",",
"extract_dir",
")",
":",
"try",
":",
"tarobj",
"=",
"tarfile",
".",
"open",
"(",
"filename",
")",
"except",
"tarfile",
".",
"TarError",
":",
"raise",
"ReadError",
"(",
"\"%s is not a compressed or uncompressed tar fi... | [
696,
0
] | [
707,
22
] | python | en | ['en', 'id', 'hi'] | False |
unpack_archive | (filename, extract_dir=None, format=None) | Unpack an archive.
`filename` is the name of the archive.
`extract_dir` is the name of the target directory, where the archive
is unpacked. If not provided, the current working directory is used.
`format` is the archive format: one of "zip", "tar", or "gztar". Or any
other registered format. If n... | Unpack an archive. | def unpack_archive(filename, extract_dir=None, format=None):
"""Unpack an archive.
`filename` is the name of the archive.
`extract_dir` is the name of the target directory, where the archive
is unpacked. If not provided, the current working directory is used.
`format` is the archive format: one o... | [
"def",
"unpack_archive",
"(",
"filename",
",",
"extract_dir",
"=",
"None",
",",
"format",
"=",
"None",
")",
":",
"if",
"extract_dir",
"is",
"None",
":",
"extract_dir",
"=",
"os",
".",
"getcwd",
"(",
")",
"if",
"format",
"is",
"not",
"None",
":",
"try",... | [
726,
0
] | [
760,
45
] | python | de | ['en', 'fr', 'de'] | False |
lookup_needs_distinct | (opts, lookup_path) |
Return True if 'distinct()' should be used to query the given lookup path.
|
Return True if 'distinct()' should be used to query the given lookup path.
| def lookup_needs_distinct(opts, lookup_path):
"""
Return True if 'distinct()' should be used to query the given lookup path.
"""
lookup_fields = lookup_path.split(LOOKUP_SEP)
# Go through the fields (following all relations) and look for an m2m.
for field_name in lookup_fields:
if field_... | [
"def",
"lookup_needs_distinct",
"(",
"opts",
",",
"lookup_path",
")",
":",
"lookup_fields",
"=",
"lookup_path",
".",
"split",
"(",
"LOOKUP_SEP",
")",
"# Go through the fields (following all relations) and look for an m2m.",
"for",
"field_name",
"in",
"lookup_fields",
":",
... | [
26,
0
] | [
48,
16
] | python | en | ['en', 'error', 'th'] | False |
prepare_lookup_value | (key, value) |
Return a lookup value prepared to be used in queryset filtering.
|
Return a lookup value prepared to be used in queryset filtering.
| def prepare_lookup_value(key, value):
"""
Return a lookup value prepared to be used in queryset filtering.
"""
# if key ends with __in, split parameter into separate values
if key.endswith('__in'):
value = value.split(',')
# if key ends with __isnull, special case '' and the string liter... | [
"def",
"prepare_lookup_value",
"(",
"key",
",",
"value",
")",
":",
"# if key ends with __in, split parameter into separate values",
"if",
"key",
".",
"endswith",
"(",
"'__in'",
")",
":",
"value",
"=",
"value",
".",
"split",
"(",
"','",
")",
"# if key ends with __isn... | [
51,
0
] | [
61,
16
] | python | en | ['en', 'error', 'th'] | False |
quote | (s) |
Ensure that primary key values do not confuse the admin URLs by escaping
any '/', '_' and ':' and similarly problematic characters.
Similar to urllib.parse.quote(), except that the quoting is slightly
different so that it doesn't get automatically unquoted by the Web browser.
|
Ensure that primary key values do not confuse the admin URLs by escaping
any '/', '_' and ':' and similarly problematic characters.
Similar to urllib.parse.quote(), except that the quoting is slightly
different so that it doesn't get automatically unquoted by the Web browser.
| def quote(s):
"""
Ensure that primary key values do not confuse the admin URLs by escaping
any '/', '_' and ':' and similarly problematic characters.
Similar to urllib.parse.quote(), except that the quoting is slightly
different so that it doesn't get automatically unquoted by the Web browser.
"... | [
"def",
"quote",
"(",
"s",
")",
":",
"return",
"s",
".",
"translate",
"(",
"QUOTE_MAP",
")",
"if",
"isinstance",
"(",
"s",
",",
"str",
")",
"else",
"s"
] | [
64,
0
] | [
71,
62
] | python | en | ['en', 'error', 'th'] | False |
unquote | (s) | Undo the effects of quote(). | Undo the effects of quote(). | def unquote(s):
"""Undo the effects of quote()."""
return UNQUOTE_RE.sub(lambda m: UNQUOTE_MAP[m.group(0)], s) | [
"def",
"unquote",
"(",
"s",
")",
":",
"return",
"UNQUOTE_RE",
".",
"sub",
"(",
"lambda",
"m",
":",
"UNQUOTE_MAP",
"[",
"m",
".",
"group",
"(",
"0",
")",
"]",
",",
"s",
")"
] | [
74,
0
] | [
76,
63
] | python | en | ['en', 'en', 'en'] | True |
flatten | (fields) |
Return a list which is a single level of flattening of the original list.
|
Return a list which is a single level of flattening of the original list.
| def flatten(fields):
"""
Return a list which is a single level of flattening of the original list.
"""
flat = []
for field in fields:
if isinstance(field, (list, tuple)):
flat.extend(field)
else:
flat.append(field)
return flat | [
"def",
"flatten",
"(",
"fields",
")",
":",
"flat",
"=",
"[",
"]",
"for",
"field",
"in",
"fields",
":",
"if",
"isinstance",
"(",
"field",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"flat",
".",
"extend",
"(",
"field",
")",
"else",
":",
"flat",... | [
79,
0
] | [
89,
15
] | python | en | ['en', 'error', 'th'] | False |
flatten_fieldsets | (fieldsets) | Return a list of field names from an admin fieldsets structure. | Return a list of field names from an admin fieldsets structure. | def flatten_fieldsets(fieldsets):
"""Return a list of field names from an admin fieldsets structure."""
field_names = []
for name, opts in fieldsets:
field_names.extend(
flatten(opts['fields'])
)
return field_names | [
"def",
"flatten_fieldsets",
"(",
"fieldsets",
")",
":",
"field_names",
"=",
"[",
"]",
"for",
"name",
",",
"opts",
"in",
"fieldsets",
":",
"field_names",
".",
"extend",
"(",
"flatten",
"(",
"opts",
"[",
"'fields'",
"]",
")",
")",
"return",
"field_names"
] | [
92,
0
] | [
99,
22
] | python | en | ['en', 'en', 'en'] | True |
get_deleted_objects | (objs, request, admin_site) |
Find all objects related to ``objs`` that should also be deleted. ``objs``
must be a homogeneous iterable of objects (e.g. a QuerySet).
Return a nested list of strings suitable for display in the
template with the ``unordered_list`` filter.
|
Find all objects related to ``objs`` that should also be deleted. ``objs``
must be a homogeneous iterable of objects (e.g. a QuerySet). | def get_deleted_objects(objs, request, admin_site):
"""
Find all objects related to ``objs`` that should also be deleted. ``objs``
must be a homogeneous iterable of objects (e.g. a QuerySet).
Return a nested list of strings suitable for display in the
template with the ``unordered_list`` filter.
... | [
"def",
"get_deleted_objects",
"(",
"objs",
",",
"request",
",",
"admin_site",
")",
":",
"try",
":",
"obj",
"=",
"objs",
"[",
"0",
"]",
"except",
"IndexError",
":",
"return",
"[",
"]",
",",
"{",
"}",
",",
"set",
"(",
")",
",",
"[",
"]",
"else",
":... | [
102,
0
] | [
155,
58
] | python | en | ['en', 'error', 'th'] | False |
model_format_dict | (obj) |
Return a `dict` with keys 'verbose_name' and 'verbose_name_plural',
typically for use with string formatting.
`obj` may be a `Model` instance, `Model` subclass, or `QuerySet` instance.
|
Return a `dict` with keys 'verbose_name' and 'verbose_name_plural',
typically for use with string formatting. | def model_format_dict(obj):
"""
Return a `dict` with keys 'verbose_name' and 'verbose_name_plural',
typically for use with string formatting.
`obj` may be a `Model` instance, `Model` subclass, or `QuerySet` instance.
"""
if isinstance(obj, (models.Model, models.base.ModelBase)):
opts = ... | [
"def",
"model_format_dict",
"(",
"obj",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"(",
"models",
".",
"Model",
",",
"models",
".",
"base",
".",
"ModelBase",
")",
")",
":",
"opts",
"=",
"obj",
".",
"_meta",
"elif",
"isinstance",
"(",
"obj",
",",
... | [
221,
0
] | [
237,
5
] | python | en | ['en', 'error', 'th'] | False |
model_ngettext | (obj, n=None) |
Return the appropriate `verbose_name` or `verbose_name_plural` value for
`obj` depending on the count `n`.
`obj` may be a `Model` instance, `Model` subclass, or `QuerySet` instance.
If `obj` is a `QuerySet` instance, `n` is optional and the length of the
`QuerySet` is used.
|
Return the appropriate `verbose_name` or `verbose_name_plural` value for
`obj` depending on the count `n`. | def model_ngettext(obj, n=None):
"""
Return the appropriate `verbose_name` or `verbose_name_plural` value for
`obj` depending on the count `n`.
`obj` may be a `Model` instance, `Model` subclass, or `QuerySet` instance.
If `obj` is a `QuerySet` instance, `n` is optional and the length of the
`Qu... | [
"def",
"model_ngettext",
"(",
"obj",
",",
"n",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"models",
".",
"query",
".",
"QuerySet",
")",
":",
"if",
"n",
"is",
"None",
":",
"n",
"=",
"obj",
".",
"count",
"(",
")",
"obj",
"=",
"ob... | [
240,
0
] | [
255,
45
] | python | en | ['en', 'error', 'th'] | False |
_get_non_gfk_field | (opts, name) |
For historical reasons, the admin app relies on GenericForeignKeys as being
"not found" by get_field(). This could likely be cleaned up.
Reverse relations should also be excluded as these aren't attributes of the
model (rather something like `foo_set`).
|
For historical reasons, the admin app relies on GenericForeignKeys as being
"not found" by get_field(). This could likely be cleaned up. | def _get_non_gfk_field(opts, name):
"""
For historical reasons, the admin app relies on GenericForeignKeys as being
"not found" by get_field(). This could likely be cleaned up.
Reverse relations should also be excluded as these aren't attributes of the
model (rather something like `foo_set`).
"... | [
"def",
"_get_non_gfk_field",
"(",
"opts",
",",
"name",
")",
":",
"field",
"=",
"opts",
".",
"get_field",
"(",
"name",
")",
"if",
"(",
"field",
".",
"is_relation",
"and",
"# Generic foreign keys OR reverse relations",
"(",
"(",
"field",
".",
"many_to_one",
"and... | [
284,
0
] | [
302,
16
] | python | en | ['en', 'error', 'th'] | False |
label_for_field | (name, model, model_admin=None, return_attr=False, form=None) |
Return a sensible label for a field name. The name can be a callable,
property (but not created with @property decorator), or the name of an
object's attribute, as well as a model field. If return_attr is True, also
return the resolved attribute (which could be a callable). This will be
None if (an... |
Return a sensible label for a field name. The name can be a callable,
property (but not created with | def label_for_field(name, model, model_admin=None, return_attr=False, form=None):
"""
Return a sensible label for a field name. The name can be a callable,
property (but not created with @property decorator), or the name of an
object's attribute, as well as a model field. If return_attr is True, also
... | [
"def",
"label_for_field",
"(",
"name",
",",
"model",
",",
"model_admin",
"=",
"None",
",",
"return_attr",
"=",
"False",
",",
"form",
"=",
"None",
")",
":",
"attr",
"=",
"None",
"try",
":",
"field",
"=",
"_get_non_gfk_field",
"(",
"model",
".",
"_meta",
... | [
305,
0
] | [
362,
20
] | python | en | ['en', 'error', 'th'] | False |
reverse_field_path | (model, path) | Create a reversed field path.
E.g. Given (Order, "user__groups"),
return (Group, "user__order").
Final field must be a related model, not a data field.
| Create a reversed field path. | def reverse_field_path(model, path):
""" Create a reversed field path.
E.g. Given (Order, "user__groups"),
return (Group, "user__order").
Final field must be a related model, not a data field.
"""
reversed_path = []
parent = model
pieces = path.split(LOOKUP_SEP)
for piece in pieces... | [
"def",
"reverse_field_path",
"(",
"model",
",",
"path",
")",
":",
"reversed_path",
"=",
"[",
"]",
"parent",
"=",
"model",
"pieces",
"=",
"path",
".",
"split",
"(",
"LOOKUP_SEP",
")",
"for",
"piece",
"in",
"pieces",
":",
"field",
"=",
"parent",
".",
"_m... | [
434,
0
] | [
462,
51
] | python | en | ['en', 'co', 'en'] | True |
get_fields_from_path | (model, path) | Return list of Fields given path relative to model.
e.g. (ModelX, "user__groups__name") -> [
<django.db.models.fields.related.ForeignKey object at 0x...>,
<django.db.models.fields.related.ManyToManyField object at 0x...>,
<django.db.models.fields.CharField object at 0x...>,
]
| Return list of Fields given path relative to model. | def get_fields_from_path(model, path):
""" Return list of Fields given path relative to model.
e.g. (ModelX, "user__groups__name") -> [
<django.db.models.fields.related.ForeignKey object at 0x...>,
<django.db.models.fields.related.ManyToManyField object at 0x...>,
<django.db.models.fiel... | [
"def",
"get_fields_from_path",
"(",
"model",
",",
"path",
")",
":",
"pieces",
"=",
"path",
".",
"split",
"(",
"LOOKUP_SEP",
")",
"fields",
"=",
"[",
"]",
"for",
"piece",
"in",
"pieces",
":",
"if",
"fields",
":",
"parent",
"=",
"get_model_from_relation",
... | [
465,
0
] | [
482,
17
] | python | en | ['en', 'en', 'en'] | True |
construct_change_message | (form, formsets, add) |
Construct a JSON structure describing changes from a changed object.
Translations are deactivated so that strings are stored untranslated.
Translation happens later on LogEntry access.
|
Construct a JSON structure describing changes from a changed object.
Translations are deactivated so that strings are stored untranslated.
Translation happens later on LogEntry access.
| def construct_change_message(form, formsets, add):
"""
Construct a JSON structure describing changes from a changed object.
Translations are deactivated so that strings are stored untranslated.
Translation happens later on LogEntry access.
"""
# Evaluating `form.changed_data` prior to disabling ... | [
"def",
"construct_change_message",
"(",
"form",
",",
"formsets",
",",
"add",
")",
":",
"# Evaluating `form.changed_data` prior to disabling translations is required",
"# to avoid fields affected by localization from being included incorrectly,",
"# e.g. where date formats differ such as MM/D... | [
485,
0
] | [
531,
25
] | python | en | ['en', 'error', 'th'] | False |
NestedObjects.nested | (self, format_callback=None) |
Return the graph as a nested list.
|
Return the graph as a nested list.
| def nested(self, format_callback=None):
"""
Return the graph as a nested list.
"""
seen = set()
roots = []
for root in self.edges.get(None, ()):
roots.extend(self._nested(root, seen, format_callback))
return roots | [
"def",
"nested",
"(",
"self",
",",
"format_callback",
"=",
"None",
")",
":",
"seen",
"=",
"set",
"(",
")",
"roots",
"=",
"[",
"]",
"for",
"root",
"in",
"self",
".",
"edges",
".",
"get",
"(",
"None",
",",
"(",
")",
")",
":",
"roots",
".",
"exten... | [
203,
4
] | [
211,
20
] | python | en | ['en', 'error', 'th'] | False |
NestedObjects.can_fast_delete | (self, *args, **kwargs) |
We always want to load the objects into memory so that we can display
them to the user in confirm page.
|
We always want to load the objects into memory so that we can display
them to the user in confirm page.
| def can_fast_delete(self, *args, **kwargs):
"""
We always want to load the objects into memory so that we can display
them to the user in confirm page.
"""
return False | [
"def",
"can_fast_delete",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"False"
] | [
213,
4
] | [
218,
20
] | python | en | ['en', 'error', 'th'] | False |
_build_subject | (res) |
Build a subject line for the given Reservation, to be sent to Exchange
:type res: resources.models.Reservation
:return: str
|
Build a subject line for the given Reservation, to be sent to Exchange | def _build_subject(res):
"""
Build a subject line for the given Reservation, to be sent to Exchange
:type res: resources.models.Reservation
:return: str
"""
if res.event_subject:
return res.event_subject
bits = ["Respa"]
if res.reserver_name:
bits.append(res.reserver_na... | [
"def",
"_build_subject",
"(",
"res",
")",
":",
"if",
"res",
".",
"event_subject",
":",
"return",
"res",
".",
"event_subject",
"bits",
"=",
"[",
"\"Respa\"",
"]",
"if",
"res",
".",
"reserver_name",
":",
"bits",
".",
"append",
"(",
"res",
".",
"reserver_na... | [
13,
0
] | [
28,
54
] | python | en | ['en', 'error', 'th'] | False |
_build_body | (res) |
Build the body of the Exchange appointment for a given Reservation.
:type res: resources.models.Reservation
:return: str
|
Build the body of the Exchange appointment for a given Reservation. | def _build_body(res):
"""
Build the body of the Exchange appointment for a given Reservation.
:type res: resources.models.Reservation
:return: str
"""
return res.event_description or '' | [
"def",
"_build_body",
"(",
"res",
")",
":",
"return",
"res",
".",
"event_description",
"or",
"''"
] | [
31,
0
] | [
38,
38
] | python | en | ['en', 'error', 'th'] | False |
create_on_remote | (exres) |
Create and link up an appointment for an ExchangeReservation.
:param exres: Exchange Reservation
:type exres: respa_exchange.models.ExchangeReservation
|
Create and link up an appointment for an ExchangeReservation. | def create_on_remote(exres):
"""
Create and link up an appointment for an ExchangeReservation.
:param exres: Exchange Reservation
:type exres: respa_exchange.models.ExchangeReservation
"""
res = exres.reservation
if res.state != Reservation.CONFIRMED:
return
assert isinstance(re... | [
"def",
"create_on_remote",
"(",
"exres",
")",
":",
"res",
"=",
"exres",
".",
"reservation",
"if",
"res",
".",
"state",
"!=",
"Reservation",
".",
"CONFIRMED",
":",
"return",
"assert",
"isinstance",
"(",
"res",
",",
"Reservation",
")",
"send_notifications",
"=... | [
65,
0
] | [
88,
51
] | python | en | ['en', 'error', 'th'] | False |
update_on_remote | (exres) |
Update (or delete) the Exchange appointment for an ExchangeReservation.
:param exres: Exchange Reservation
:type exres: respa_exchange.models.ExchangeReservation
|
Update (or delete) the Exchange appointment for an ExchangeReservation. | def update_on_remote(exres):
"""
Update (or delete) the Exchange appointment for an ExchangeReservation.
:param exres: Exchange Reservation
:type exres: respa_exchange.models.ExchangeReservation
"""
res = exres.reservation
if res.state in (Reservation.DENIED, Reservation.CANCELLED):
... | [
"def",
"update_on_remote",
"(",
"exres",
")",
":",
"res",
"=",
"exres",
".",
"reservation",
"if",
"res",
".",
"state",
"in",
"(",
"Reservation",
".",
"DENIED",
",",
"Reservation",
".",
"CANCELLED",
")",
":",
"return",
"delete_on_remote",
"(",
"exres",
")",... | [
91,
0
] | [
116,
51
] | python | en | ['en', 'error', 'th'] | False |
delete_on_remote | (exres) |
Delete the Exchange appointment for an ExchangeReservation.
:param exres: Exchange Reservation
:type exres: respa_exchange.models.ExchangeReservation
|
Delete the Exchange appointment for an ExchangeReservation. | def delete_on_remote(exres):
"""
Delete the Exchange appointment for an ExchangeReservation.
:param exres: Exchange Reservation
:type exres: respa_exchange.models.ExchangeReservation
"""
send_notifications = True
if getattr(exres.reservation, '_skip_notifications', False):
send_noti... | [
"def",
"delete_on_remote",
"(",
"exres",
")",
":",
"send_notifications",
"=",
"True",
"if",
"getattr",
"(",
"exres",
".",
"reservation",
",",
"'_skip_notifications'",
",",
"False",
")",
":",
"send_notifications",
"=",
"False",
"dcir",
"=",
"DeleteCalendarItemReque... | [
119,
0
] | [
136,
18
] | python | en | ['en', 'error', 'th'] | False |
get_dtype | (arg) |
Get numpy dtypes from strings in a python 2 and 3 compatible way
|
Get numpy dtypes from strings in a python 2 and 3 compatible way
| def get_dtype(arg):
"""
Get numpy dtypes from strings in a python 2 and 3 compatible way
"""
if arg == "string":
arg = "str"
return np.dtype(arg) | [
"def",
"get_dtype",
"(",
"arg",
")",
":",
"if",
"arg",
"==",
"\"string\"",
":",
"arg",
"=",
"\"str\"",
"return",
"np",
".",
"dtype",
"(",
"arg",
")"
] | [
18,
0
] | [
25,
24
] | python | en | ['en', 'error', 'th'] | False |
momentum_iterative_method | (
model_fn,
x,
eps=0.3,
eps_iter=0.06,
nb_iter=10,
norm=np.inf,
clip_min=None,
clip_max=None,
y=None,
targeted=False,
decay_factor=1.0,
sanity_checks=True,
) |
Tensorflow 2.0 implementation of Momentum Iterative Method (Dong et al. 2017).
This method won the first places in NIPS 2017 Non-targeted Adversarial Attacks
and Targeted Adversarial Attacks. The original paper used hard labels
for this attack; no label smoothing.
Paper link: https://arxiv.org/pdf/... |
Tensorflow 2.0 implementation of Momentum Iterative Method (Dong et al. 2017).
This method won the first places in NIPS 2017 Non-targeted Adversarial Attacks
and Targeted Adversarial Attacks. The original paper used hard labels
for this attack; no label smoothing.
Paper link: https://arxiv.org/pdf/... | def momentum_iterative_method(
model_fn,
x,
eps=0.3,
eps_iter=0.06,
nb_iter=10,
norm=np.inf,
clip_min=None,
clip_max=None,
y=None,
targeted=False,
decay_factor=1.0,
sanity_checks=True,
):
"""
Tensorflow 2.0 implementation of Momentum Iterative Method (Dong et al. ... | [
"def",
"momentum_iterative_method",
"(",
"model_fn",
",",
"x",
",",
"eps",
"=",
"0.3",
",",
"eps_iter",
"=",
"0.06",
",",
"nb_iter",
"=",
"10",
",",
"norm",
"=",
"np",
".",
"inf",
",",
"clip_min",
"=",
"None",
",",
"clip_max",
"=",
"None",
",",
"y",
... | [
9,
0
] | [
108,
16
] | python | en | ['en', 'error', 'th'] | False |
loss_fn | (labels, logits) |
Added softmax cross entropy loss for MIM as in the original MI-FGSM paper.
|
Added softmax cross entropy loss for MIM as in the original MI-FGSM paper.
| def loss_fn(labels, logits):
"""
Added softmax cross entropy loss for MIM as in the original MI-FGSM paper.
"""
return tf.nn.sparse_softmax_cross_entropy_with_logits(labels, logits, name=None) | [
"def",
"loss_fn",
"(",
"labels",
",",
"logits",
")",
":",
"return",
"tf",
".",
"nn",
".",
"sparse_softmax_cross_entropy_with_logits",
"(",
"labels",
",",
"logits",
",",
"name",
"=",
"None",
")"
] | [
111,
0
] | [
116,
84
] | python | en | ['en', 'error', 'th'] | False |
create_generic_related_manager | (superclass, rel) |
Factory function to create a manager that subclasses another manager
(generally the default manager of a given model) and adds behaviors
specific to generic relations.
|
Factory function to create a manager that subclasses another manager
(generally the default manager of a given model) and adds behaviors
specific to generic relations.
| def create_generic_related_manager(superclass, rel):
"""
Factory function to create a manager that subclasses another manager
(generally the default manager of a given model) and adds behaviors
specific to generic relations.
"""
class GenericRelatedObjectManager(superclass):
def __init_... | [
"def",
"create_generic_related_manager",
"(",
"superclass",
",",
"rel",
")",
":",
"class",
"GenericRelatedObjectManager",
"(",
"superclass",
")",
":",
"def",
"__init__",
"(",
"self",
",",
"instance",
"=",
"None",
")",
":",
"super",
"(",
")",
".",
"__init__",
... | [
506,
0
] | [
701,
38
] | python | en | ['en', 'error', 'th'] | False |
GenericForeignKey.get_filter_kwargs_for_object | (self, obj) | See corresponding method on Field | See corresponding method on Field | def get_filter_kwargs_for_object(self, obj):
"""See corresponding method on Field"""
return {
self.fk_field: getattr(obj, self.fk_field),
self.ct_field: getattr(obj, self.ct_field),
} | [
"def",
"get_filter_kwargs_for_object",
"(",
"self",
",",
"obj",
")",
":",
"return",
"{",
"self",
".",
"fk_field",
":",
"getattr",
"(",
"obj",
",",
"self",
".",
"fk_field",
")",
",",
"self",
".",
"ct_field",
":",
"getattr",
"(",
"obj",
",",
"self",
".",... | [
57,
4
] | [
62,
9
] | python | en | ['en', 'af', 'en'] | True |
GenericForeignKey.get_forward_related_filter | (self, obj) | See corresponding method on RelatedField | See corresponding method on RelatedField | def get_forward_related_filter(self, obj):
"""See corresponding method on RelatedField"""
return {
self.fk_field: obj.pk,
self.ct_field: ContentType.objects.get_for_model(obj).pk,
} | [
"def",
"get_forward_related_filter",
"(",
"self",
",",
"obj",
")",
":",
"return",
"{",
"self",
".",
"fk_field",
":",
"obj",
".",
"pk",
",",
"self",
".",
"ct_field",
":",
"ContentType",
".",
"objects",
".",
"get_for_model",
"(",
"obj",
")",
".",
"pk",
"... | [
64,
4
] | [
69,
9
] | python | en | ['en', 'sr', 'en'] | True |
GenericForeignKey._check_content_type_field | (self) |
Check if field named `field_name` in model `model` exists and is a
valid content_type field (is a ForeignKey to ContentType).
|
Check if field named `field_name` in model `model` exists and is a
valid content_type field (is a ForeignKey to ContentType).
| def _check_content_type_field(self):
"""
Check if field named `field_name` in model `model` exists and is a
valid content_type field (is a ForeignKey to ContentType).
"""
try:
field = self.model._meta.get_field(self.ct_field)
except FieldDoesNotExist:
... | [
"def",
"_check_content_type_field",
"(",
"self",
")",
":",
"try",
":",
"field",
"=",
"self",
".",
"model",
".",
"_meta",
".",
"get_field",
"(",
"self",
".",
"ct_field",
")",
"except",
"FieldDoesNotExist",
":",
"return",
"[",
"checks",
".",
"Error",
"(",
... | [
110,
4
] | [
158,
25
] | python | en | ['en', 'error', 'th'] | False |
GenericRelation._is_matching_generic_foreign_key | (self, field) |
Return True if field is a GenericForeignKey whose content type and
object id fields correspond to the equivalent attributes on this
GenericRelation.
|
Return True if field is a GenericForeignKey whose content type and
object id fields correspond to the equivalent attributes on this
GenericRelation.
| def _is_matching_generic_foreign_key(self, field):
"""
Return True if field is a GenericForeignKey whose content type and
object id fields correspond to the equivalent attributes on this
GenericRelation.
"""
return (
isinstance(field, GenericForeignKey) and
... | [
"def",
"_is_matching_generic_foreign_key",
"(",
"self",
",",
"field",
")",
":",
"return",
"(",
"isinstance",
"(",
"field",
",",
"GenericForeignKey",
")",
"and",
"field",
".",
"ct_field",
"==",
"self",
".",
"content_type_field_name",
"and",
"field",
".",
"fk_fiel... | [
320,
4
] | [
330,
9
] | python | en | ['en', 'error', 'th'] | False |
GenericRelation._get_path_info_with_parent | (self, filtered_relation) |
Return the path that joins the current model through any parent models.
The idea is that if you have a GFK defined on a parent model then we
need to join the parent model first, then the child model.
|
Return the path that joins the current model through any parent models.
The idea is that if you have a GFK defined on a parent model then we
need to join the parent model first, then the child model.
| def _get_path_info_with_parent(self, filtered_relation):
"""
Return the path that joins the current model through any parent models.
The idea is that if you have a GFK defined on a parent model then we
need to join the parent model first, then the child model.
"""
# With ... | [
"def",
"_get_path_info_with_parent",
"(",
"self",
",",
"filtered_relation",
")",
":",
"# With an inheritance chain ChildTag -> Tag and Tag defines the",
"# GenericForeignKey, and a TaggedItem model has a GenericRelation to",
"# ChildTag, then we need to generate a join from TaggedItem to Tag",
... | [
356,
4
] | [
394,
19
] | python | en | ['en', 'error', 'th'] | False |
GenericRelation.get_content_type | (self) |
Return the content type associated with this field's model.
|
Return the content type associated with this field's model.
| def get_content_type(self):
"""
Return the content type associated with this field's model.
"""
return ContentType.objects.get_for_model(self.model,
for_concrete_model=self.for_concrete_model) | [
"def",
"get_content_type",
"(",
"self",
")",
":",
"return",
"ContentType",
".",
"objects",
".",
"get_for_model",
"(",
"self",
".",
"model",
",",
"for_concrete_model",
"=",
"self",
".",
"for_concrete_model",
")"
] | [
459,
4
] | [
464,
92
] | python | en | ['en', 'error', 'th'] | False |
GenericRelation.bulk_related_objects | (self, objs, using=DEFAULT_DB_ALIAS) |
Return all objects related to ``objs`` via this ``GenericRelation``.
|
Return all objects related to ``objs`` via this ``GenericRelation``.
| def bulk_related_objects(self, objs, using=DEFAULT_DB_ALIAS):
"""
Return all objects related to ``objs`` via this ``GenericRelation``.
"""
return self.remote_field.model._base_manager.db_manager(using).filter(**{
"%s__pk" % self.content_type_field_name: ContentType.objects.db... | [
"def",
"bulk_related_objects",
"(",
"self",
",",
"objs",
",",
"using",
"=",
"DEFAULT_DB_ALIAS",
")",
":",
"return",
"self",
".",
"remote_field",
".",
"model",
".",
"_base_manager",
".",
"db_manager",
"(",
"using",
")",
".",
"filter",
"(",
"*",
"*",
"{",
... | [
474,
4
] | [
482,
10
] | python | en | ['en', 'error', 'th'] | False |
format | (value, format_string) | Convenience function | Convenience function | def format(value, format_string):
"Convenience function"
df = DateFormat(value)
return df.format(format_string) | [
"def",
"format",
"(",
"value",
",",
"format_string",
")",
":",
"df",
"=",
"DateFormat",
"(",
"value",
")",
"return",
"df",
".",
"format",
"(",
"format_string",
")"
] | [
339,
0
] | [
342,
35
] | python | en | ['en', 'en', 'en'] | False |
time_format | (value, format_string) | Convenience function | Convenience function | def time_format(value, format_string):
"Convenience function"
tf = TimeFormat(value)
return tf.format(format_string) | [
"def",
"time_format",
"(",
"value",
",",
"format_string",
")",
":",
"tf",
"=",
"TimeFormat",
"(",
"value",
")",
"return",
"tf",
".",
"format",
"(",
"format_string",
")"
] | [
345,
0
] | [
348,
35
] | python | en | ['en', 'en', 'en'] | False |
TimeFormat.a | (self) | a.m.' or 'p.m. | a.m.' or 'p.m. | def a(self):
"'a.m.' or 'p.m.'"
if self.data.hour > 11:
return _('p.m.')
return _('a.m.') | [
"def",
"a",
"(",
"self",
")",
":",
"if",
"self",
".",
"data",
".",
"hour",
">",
"11",
":",
"return",
"_",
"(",
"'p.m.'",
")",
"return",
"_",
"(",
"'a.m.'",
")"
] | [
55,
4
] | [
59,
24
] | python | en | ['en', 'en', 'en'] | True |
TimeFormat.B | (self) | Swatch Internet time | Swatch Internet time | def B(self):
"Swatch Internet time"
raise NotImplementedError('may be implemented in a future release') | [
"def",
"B",
"(",
"self",
")",
":",
"raise",
"NotImplementedError",
"(",
"'may be implemented in a future release'",
")"
] | [
67,
4
] | [
69,
75
] | python | en | ['en', 'en', 'en'] | True |
TimeFormat.e | (self) |
Timezone name.
If timezone information is not available, this method returns
an empty string.
|
Timezone name. | def e(self):
"""
Timezone name.
If timezone information is not available, this method returns
an empty string.
"""
if not self.timezone:
return ""
try:
if hasattr(self.data, 'tzinfo') and self.data.tzinfo:
# Have to use tz... | [
"def",
"e",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"timezone",
":",
"return",
"\"\"",
"try",
":",
"if",
"hasattr",
"(",
"self",
".",
"data",
",",
"'tzinfo'",
")",
"and",
"self",
".",
"data",
".",
"tzinfo",
":",
"# Have to use tzinfo.tzname an... | [
71,
4
] | [
88,
17
] | python | en | ['en', 'error', 'th'] | False |
TimeFormat.f | (self) |
Time, in 12-hour hours and minutes, with minutes left off if they're
zero.
Examples: '1', '1:30', '2:05', '2'
Proprietary extension.
|
Time, in 12-hour hours and minutes, with minutes left off if they're
zero.
Examples: '1', '1:30', '2:05', '2'
Proprietary extension.
| def f(self):
"""
Time, in 12-hour hours and minutes, with minutes left off if they're
zero.
Examples: '1', '1:30', '2:05', '2'
Proprietary extension.
"""
if self.data.minute == 0:
return self.g()
return '%s:%s' % (self.g(), self.i()) | [
"def",
"f",
"(",
"self",
")",
":",
"if",
"self",
".",
"data",
".",
"minute",
"==",
"0",
":",
"return",
"self",
".",
"g",
"(",
")",
"return",
"'%s:%s'",
"%",
"(",
"self",
".",
"g",
"(",
")",
",",
"self",
".",
"i",
"(",
")",
")"
] | [
90,
4
] | [
99,
45
] | python | en | ['en', 'error', 'th'] | False |
TimeFormat.g | (self) | Hour, 12-hour format without leading zeros; i.e. '1' to '12 | Hour, 12-hour format without leading zeros; i.e. '1' to '12 | def g(self):
"Hour, 12-hour format without leading zeros; i.e. '1' to '12'"
if self.data.hour == 0:
return 12
if self.data.hour > 12:
return self.data.hour - 12
return self.data.hour | [
"def",
"g",
"(",
"self",
")",
":",
"if",
"self",
".",
"data",
".",
"hour",
"==",
"0",
":",
"return",
"12",
"if",
"self",
".",
"data",
".",
"hour",
">",
"12",
":",
"return",
"self",
".",
"data",
".",
"hour",
"-",
"12",
"return",
"self",
".",
"... | [
101,
4
] | [
107,
29
] | python | en | ['en', 'en', 'en'] | True |
TimeFormat.G | (self) | Hour, 24-hour format without leading zeros; i.e. '0' to '23 | Hour, 24-hour format without leading zeros; i.e. '0' to '23 | def G(self):
"Hour, 24-hour format without leading zeros; i.e. '0' to '23'"
return self.data.hour | [
"def",
"G",
"(",
"self",
")",
":",
"return",
"self",
".",
"data",
".",
"hour"
] | [
109,
4
] | [
111,
29
] | python | en | ['en', 'en', 'en'] | True |
TimeFormat.h | (self) | Hour, 12-hour format; i.e. '01' to '12 | Hour, 12-hour format; i.e. '01' to '12 | def h(self):
"Hour, 12-hour format; i.e. '01' to '12'"
return '%02d' % self.g() | [
"def",
"h",
"(",
"self",
")",
":",
"return",
"'%02d'",
"%",
"self",
".",
"g",
"(",
")"
] | [
113,
4
] | [
115,
32
] | python | en | ['en', 'pt', 'it'] | False |
TimeFormat.H | (self) | Hour, 24-hour format; i.e. '00' to '23 | Hour, 24-hour format; i.e. '00' to '23 | def H(self):
"Hour, 24-hour format; i.e. '00' to '23'"
return '%02d' % self.G() | [
"def",
"H",
"(",
"self",
")",
":",
"return",
"'%02d'",
"%",
"self",
".",
"G",
"(",
")"
] | [
117,
4
] | [
119,
32
] | python | en | ['en', 'pt', 'it'] | False |
TimeFormat.i | (self) | Minutes; i.e. '00' to '59 | Minutes; i.e. '00' to '59 | def i(self):
"Minutes; i.e. '00' to '59'"
return '%02d' % self.data.minute | [
"def",
"i",
"(",
"self",
")",
":",
"return",
"'%02d'",
"%",
"self",
".",
"data",
".",
"minute"
] | [
121,
4
] | [
123,
40
] | python | en | ['en', 'mi', 'it'] | False |
TimeFormat.O | (self) |
Difference to Greenwich time in hours; e.g. '+0200', '-0430'.
If timezone information is not available, this method returns
an empty string.
|
Difference to Greenwich time in hours; e.g. '+0200', '-0430'. | def O(self):
"""
Difference to Greenwich time in hours; e.g. '+0200', '-0430'.
If timezone information is not available, this method returns
an empty string.
"""
if not self.timezone:
return ""
seconds = self.Z()
sign = '-' if seconds < 0 els... | [
"def",
"O",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"timezone",
":",
"return",
"\"\"",
"seconds",
"=",
"self",
".",
"Z",
"(",
")",
"sign",
"=",
"'-'",
"if",
"seconds",
"<",
"0",
"else",
"'+'",
"seconds",
"=",
"abs",
"(",
"seconds",
")",
... | [
125,
4
] | [
138,
75
] | python | en | ['en', 'error', 'th'] | False |
TimeFormat.P | (self) |
Time, in 12-hour hours, minutes and 'a.m.'/'p.m.', with minutes left off
if they're zero and the strings 'midnight' and 'noon' if appropriate.
Examples: '1 a.m.', '1:30 p.m.', 'midnight', 'noon', '12:30 p.m.'
Proprietary extension.
|
Time, in 12-hour hours, minutes and 'a.m.'/'p.m.', with minutes left off
if they're zero and the strings 'midnight' and 'noon' if appropriate.
Examples: '1 a.m.', '1:30 p.m.', 'midnight', 'noon', '12:30 p.m.'
Proprietary extension.
| def P(self):
"""
Time, in 12-hour hours, minutes and 'a.m.'/'p.m.', with minutes left off
if they're zero and the strings 'midnight' and 'noon' if appropriate.
Examples: '1 a.m.', '1:30 p.m.', 'midnight', 'noon', '12:30 p.m.'
Proprietary extension.
"""
if self.dat... | [
"def",
"P",
"(",
"self",
")",
":",
"if",
"self",
".",
"data",
".",
"minute",
"==",
"0",
"and",
"self",
".",
"data",
".",
"hour",
"==",
"0",
":",
"return",
"_",
"(",
"'midnight'",
")",
"if",
"self",
".",
"data",
".",
"minute",
"==",
"0",
"and",
... | [
140,
4
] | [
151,
45
] | python | en | ['en', 'error', 'th'] | False |
TimeFormat.s | (self) | Seconds; i.e. '00' to '59 | Seconds; i.e. '00' to '59 | def s(self):
"Seconds; i.e. '00' to '59'"
return '%02d' % self.data.second | [
"def",
"s",
"(",
"self",
")",
":",
"return",
"'%02d'",
"%",
"self",
".",
"data",
".",
"second"
] | [
153,
4
] | [
155,
40
] | python | en | ['en', 'pt', 'it'] | False |
TimeFormat.T | (self) |
Time zone of this machine; e.g. 'EST' or 'MDT'.
If timezone information is not available, this method returns
an empty string.
|
Time zone of this machine; e.g. 'EST' or 'MDT'. | def T(self):
"""
Time zone of this machine; e.g. 'EST' or 'MDT'.
If timezone information is not available, this method returns
an empty string.
"""
if not self.timezone:
return ""
name = self.timezone.tzname(self.data) if self.timezone else None
... | [
"def",
"T",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"timezone",
":",
"return",
"\"\"",
"name",
"=",
"self",
".",
"timezone",
".",
"tzname",
"(",
"self",
".",
"data",
")",
"if",
"self",
".",
"timezone",
"else",
"None",
"if",
"name",
"is",
... | [
157,
4
] | [
170,
34
] | python | en | ['en', 'error', 'th'] | False |
TimeFormat.u | (self) | Microseconds; i.e. '000000' to '999999 | Microseconds; i.e. '000000' to '999999 | def u(self):
"Microseconds; i.e. '000000' to '999999'"
return '%06d' % self.data.microsecond | [
"def",
"u",
"(",
"self",
")",
":",
"return",
"'%06d'",
"%",
"self",
".",
"data",
".",
"microsecond"
] | [
172,
4
] | [
174,
45
] | python | en | ['en', 'mk', 'en'] | True |
TimeFormat.Z | (self) |
Time zone offset in seconds (i.e. '-43200' to '43200'). The offset for
timezones west of UTC is always negative, and for those east of UTC is
always positive.
If timezone information is not available, this method returns
an empty string.
|
Time zone offset in seconds (i.e. '-43200' to '43200'). The offset for
timezones west of UTC is always negative, and for those east of UTC is
always positive. | def Z(self):
"""
Time zone offset in seconds (i.e. '-43200' to '43200'). The offset for
timezones west of UTC is always negative, and for those east of UTC is
always positive.
If timezone information is not available, this method returns
an empty string.
"""
... | [
"def",
"Z",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"timezone",
":",
"return",
"\"\"",
"offset",
"=",
"self",
".",
"timezone",
".",
"utcoffset",
"(",
"self",
".",
"data",
")",
"# `offset` is a datetime.timedelta. For negative values (to the west of",
"#... | [
176,
4
] | [
193,
51
] | python | en | ['en', 'error', 'th'] | False |
DateFormat.b | (self) | Month, textual, 3 letters, lowercase; e.g. 'jan | Month, textual, 3 letters, lowercase; e.g. 'jan | def b(self):
"Month, textual, 3 letters, lowercase; e.g. 'jan'"
return MONTHS_3[self.data.month] | [
"def",
"b",
"(",
"self",
")",
":",
"return",
"MONTHS_3",
"[",
"self",
".",
"data",
".",
"month",
"]"
] | [
199,
4
] | [
201,
40
] | python | en | ['en', 'en', 'en'] | True |
DateFormat.c | (self) |
ISO 8601 Format
Example : '2008-01-02T10:30:00.000123'
|
ISO 8601 Format
Example : '2008-01-02T10:30:00.000123'
| def c(self):
"""
ISO 8601 Format
Example : '2008-01-02T10:30:00.000123'
"""
return self.data.isoformat() | [
"def",
"c",
"(",
"self",
")",
":",
"return",
"self",
".",
"data",
".",
"isoformat",
"(",
")"
] | [
203,
4
] | [
208,
36
] | python | en | ['en', 'error', 'th'] | False |
DateFormat.d | (self) | Day of the month, 2 digits with leading zeros; i.e. '01' to '31 | Day of the month, 2 digits with leading zeros; i.e. '01' to '31 | def d(self):
"Day of the month, 2 digits with leading zeros; i.e. '01' to '31'"
return '%02d' % self.data.day | [
"def",
"d",
"(",
"self",
")",
":",
"return",
"'%02d'",
"%",
"self",
".",
"data",
".",
"day"
] | [
210,
4
] | [
212,
37
] | python | en | ['en', 'en', 'en'] | True |
DateFormat.D | (self) | Day of the week, textual, 3 letters; e.g. 'Fri | Day of the week, textual, 3 letters; e.g. 'Fri | def D(self):
"Day of the week, textual, 3 letters; e.g. 'Fri'"
return WEEKDAYS_ABBR[self.data.weekday()] | [
"def",
"D",
"(",
"self",
")",
":",
"return",
"WEEKDAYS_ABBR",
"[",
"self",
".",
"data",
".",
"weekday",
"(",
")",
"]"
] | [
214,
4
] | [
216,
49
] | python | en | ['en', 'en', 'en'] | True |
DateFormat.E | (self) | Alternative month names as required by some locales. Proprietary extension. | Alternative month names as required by some locales. Proprietary extension. | def E(self):
"Alternative month names as required by some locales. Proprietary extension."
return MONTHS_ALT[self.data.month] | [
"def",
"E",
"(",
"self",
")",
":",
"return",
"MONTHS_ALT",
"[",
"self",
".",
"data",
".",
"month",
"]"
] | [
218,
4
] | [
220,
42
] | python | en | ['en', 'en', 'en'] | True |
DateFormat.F | (self) | Month, textual, long; e.g. 'January | Month, textual, long; e.g. 'January | def F(self):
"Month, textual, long; e.g. 'January'"
return MONTHS[self.data.month] | [
"def",
"F",
"(",
"self",
")",
":",
"return",
"MONTHS",
"[",
"self",
".",
"data",
".",
"month",
"]"
] | [
222,
4
] | [
224,
38
] | python | en | ['en', 'en', 'pt'] | True |
DateFormat.I | (self) | 1' if Daylight Savings Time, '0' otherwise. | 1' if Daylight Savings Time, '0' otherwise. | def I(self):
"'1' if Daylight Savings Time, '0' otherwise."
if self.timezone and self.timezone.dst(self.data):
return '1'
else:
return '0' | [
"def",
"I",
"(",
"self",
")",
":",
"if",
"self",
".",
"timezone",
"and",
"self",
".",
"timezone",
".",
"dst",
"(",
"self",
".",
"data",
")",
":",
"return",
"'1'",
"else",
":",
"return",
"'0'"
] | [
226,
4
] | [
231,
22
] | python | en | ['en', 'en', 'en'] | True |
DateFormat.j | (self) | Day of the month without leading zeros; i.e. '1' to '31 | Day of the month without leading zeros; i.e. '1' to '31 | def j(self):
"Day of the month without leading zeros; i.e. '1' to '31'"
return self.data.day | [
"def",
"j",
"(",
"self",
")",
":",
"return",
"self",
".",
"data",
".",
"day"
] | [
233,
4
] | [
235,
28
] | python | en | ['en', 'en', 'en'] | True |
DateFormat.l | (self) | Day of the week, textual, long; e.g. 'Friday | Day of the week, textual, long; e.g. 'Friday | def l(self):
"Day of the week, textual, long; e.g. 'Friday'"
return WEEKDAYS[self.data.weekday()] | [
"def",
"l",
"(",
"self",
")",
":",
"return",
"WEEKDAYS",
"[",
"self",
".",
"data",
".",
"weekday",
"(",
")",
"]"
] | [
237,
4
] | [
239,
44
] | python | en | ['en', 'en', 'en'] | True |
DateFormat.L | (self) | Boolean for whether it is a leap year; i.e. True or False | Boolean for whether it is a leap year; i.e. True or False | def L(self):
"Boolean for whether it is a leap year; i.e. True or False"
return calendar.isleap(self.data.year) | [
"def",
"L",
"(",
"self",
")",
":",
"return",
"calendar",
".",
"isleap",
"(",
"self",
".",
"data",
".",
"year",
")"
] | [
241,
4
] | [
243,
46
] | python | en | ['en', 'en', 'en'] | True |
DateFormat.m | (self) | Month; i.e. '01' to '12 | Month; i.e. '01' to '12 | def m(self):
"Month; i.e. '01' to '12'"
return '%02d' % self.data.month | [
"def",
"m",
"(",
"self",
")",
":",
"return",
"'%02d'",
"%",
"self",
".",
"data",
".",
"month"
] | [
245,
4
] | [
247,
39
] | python | en | ['en', 'pt', 'it'] | False |
DateFormat.M | (self) | Month, textual, 3 letters; e.g. 'Jan | Month, textual, 3 letters; e.g. 'Jan | def M(self):
"Month, textual, 3 letters; e.g. 'Jan'"
return MONTHS_3[self.data.month].title() | [
"def",
"M",
"(",
"self",
")",
":",
"return",
"MONTHS_3",
"[",
"self",
".",
"data",
".",
"month",
"]",
".",
"title",
"(",
")"
] | [
249,
4
] | [
251,
48
] | python | en | ['en', 'fr', 'pt'] | False |
DateFormat.n | (self) | Month without leading zeros; i.e. '1' to '12 | Month without leading zeros; i.e. '1' to '12 | def n(self):
"Month without leading zeros; i.e. '1' to '12'"
return self.data.month | [
"def",
"n",
"(",
"self",
")",
":",
"return",
"self",
".",
"data",
".",
"month"
] | [
253,
4
] | [
255,
30
] | python | en | ['en', 'en', 'en'] | True |
DateFormat.N | (self) | Month abbreviation in Associated Press style. Proprietary extension. | Month abbreviation in Associated Press style. Proprietary extension. | def N(self):
"Month abbreviation in Associated Press style. Proprietary extension."
return MONTHS_AP[self.data.month] | [
"def",
"N",
"(",
"self",
")",
":",
"return",
"MONTHS_AP",
"[",
"self",
".",
"data",
".",
"month",
"]"
] | [
257,
4
] | [
259,
41
] | python | en | ['en', 'en', 'en'] | True |
DateFormat.o | (self) | ISO 8601 year number matching the ISO week number (W) | ISO 8601 year number matching the ISO week number (W) | def o(self):
"ISO 8601 year number matching the ISO week number (W)"
return self.data.isocalendar()[0] | [
"def",
"o",
"(",
"self",
")",
":",
"return",
"self",
".",
"data",
".",
"isocalendar",
"(",
")",
"[",
"0",
"]"
] | [
261,
4
] | [
263,
41
] | python | en | ['en', 'en', 'en'] | True |
DateFormat.r | (self) | RFC 2822 formatted date; e.g. 'Thu, 21 Dec 2000 16:01:07 +0200 | RFC 2822 formatted date; e.g. 'Thu, 21 Dec 2000 16:01:07 +0200 | def r(self):
"RFC 2822 formatted date; e.g. 'Thu, 21 Dec 2000 16:01:07 +0200'"
return self.format('D, j M Y H:i:s O') | [
"def",
"r",
"(",
"self",
")",
":",
"return",
"self",
".",
"format",
"(",
"'D, j M Y H:i:s O'",
")"
] | [
265,
4
] | [
267,
46
] | python | co | ['fr', 'co', 'it'] | False |
DateFormat.S | (self) | English ordinal suffix for the day of the month, 2 characters; i.e. 'st', 'nd', 'rd' or 'th | English ordinal suffix for the day of the month, 2 characters; i.e. 'st', 'nd', 'rd' or 'th | def S(self):
"English ordinal suffix for the day of the month, 2 characters; i.e. 'st', 'nd', 'rd' or 'th'"
if self.data.day in (11, 12, 13): # Special case
return 'th'
last = self.data.day % 10
if last == 1:
return 'st'
if last == 2:
return '... | [
"def",
"S",
"(",
"self",
")",
":",
"if",
"self",
".",
"data",
".",
"day",
"in",
"(",
"11",
",",
"12",
",",
"13",
")",
":",
"# Special case",
"return",
"'th'",
"last",
"=",
"self",
".",
"data",
".",
"day",
"%",
"10",
"if",
"last",
"==",
"1",
"... | [
269,
4
] | [
280,
19
] | python | en | ['en', 'en', 'en'] | True |
DateFormat.t | (self) | Number of days in the given month; i.e. '28' to '31 | Number of days in the given month; i.e. '28' to '31 | def t(self):
"Number of days in the given month; i.e. '28' to '31'"
return '%02d' % calendar.monthrange(self.data.year, self.data.month)[1] | [
"def",
"t",
"(",
"self",
")",
":",
"return",
"'%02d'",
"%",
"calendar",
".",
"monthrange",
"(",
"self",
".",
"data",
".",
"year",
",",
"self",
".",
"data",
".",
"month",
")",
"[",
"1",
"]"
] | [
282,
4
] | [
284,
79
] | python | en | ['en', 'en', 'en'] | True |
DateFormat.U | (self) | Seconds since the Unix epoch (January 1 1970 00:00:00 GMT) | Seconds since the Unix epoch (January 1 1970 00:00:00 GMT) | def U(self):
"Seconds since the Unix epoch (January 1 1970 00:00:00 GMT)"
if isinstance(self.data, datetime.datetime) and is_aware(self.data):
return int(calendar.timegm(self.data.utctimetuple()))
else:
return int(time.mktime(self.data.timetuple())) | [
"def",
"U",
"(",
"self",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"data",
",",
"datetime",
".",
"datetime",
")",
"and",
"is_aware",
"(",
"self",
".",
"data",
")",
":",
"return",
"int",
"(",
"calendar",
".",
"timegm",
"(",
"self",
".",
"data"... | [
286,
4
] | [
291,
58
] | python | en | ['en', 'cs', 'en'] | True |
DateFormat.w | (self) | Day of the week, numeric, i.e. '0' (Sunday) to '6' (Saturday) | Day of the week, numeric, i.e. '0' (Sunday) to '6' (Saturday) | def w(self):
"Day of the week, numeric, i.e. '0' (Sunday) to '6' (Saturday)"
return (self.data.weekday() + 1) % 7 | [
"def",
"w",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"data",
".",
"weekday",
"(",
")",
"+",
"1",
")",
"%",
"7"
] | [
293,
4
] | [
295,
44
] | python | en | ['en', 'en', 'en'] | True |
DateFormat.W | (self) | ISO-8601 week number of year, weeks starting on Monday | ISO-8601 week number of year, weeks starting on Monday | def W(self):
"ISO-8601 week number of year, weeks starting on Monday"
# Algorithm from http://www.personal.ecu.edu/mccartyr/ISOwdALG.txt
week_number = None
jan1_weekday = self.data.replace(month=1, day=1).weekday() + 1
weekday = self.data.weekday() + 1
day_of_year = self.... | [
"def",
"W",
"(",
"self",
")",
":",
"# Algorithm from http://www.personal.ecu.edu/mccartyr/ISOwdALG.txt",
"week_number",
"=",
"None",
"jan1_weekday",
"=",
"self",
".",
"data",
".",
"replace",
"(",
"month",
"=",
"1",
",",
"day",
"=",
"1",
")",
".",
"weekday",
"(... | [
297,
4
] | [
321,
26
] | python | en | ['en', 'en', 'en'] | True |
DateFormat.y | (self) | Year, 2 digits; e.g. '99 | Year, 2 digits; e.g. '99 | def y(self):
"Year, 2 digits; e.g. '99'"
return six.text_type(self.data.year)[2:] | [
"def",
"y",
"(",
"self",
")",
":",
"return",
"six",
".",
"text_type",
"(",
"self",
".",
"data",
".",
"year",
")",
"[",
"2",
":",
"]"
] | [
323,
4
] | [
325,
48
] | python | da | ['da', 'ny', 'en'] | False |
DateFormat.Y | (self) | Year, 4 digits; e.g. '1999 | Year, 4 digits; e.g. '1999 | def Y(self):
"Year, 4 digits; e.g. '1999'"
return self.data.year | [
"def",
"Y",
"(",
"self",
")",
":",
"return",
"self",
".",
"data",
".",
"year"
] | [
327,
4
] | [
329,
29
] | python | da | ['da', 'ny', 'en'] | False |
DateFormat.z | (self) | Day of the year; i.e. '0' to '365 | Day of the year; i.e. '0' to '365 | def z(self):
"Day of the year; i.e. '0' to '365'"
doy = self.year_days[self.data.month] + self.data.day
if self.L() and self.data.month > 2:
doy += 1
return doy | [
"def",
"z",
"(",
"self",
")",
":",
"doy",
"=",
"self",
".",
"year_days",
"[",
"self",
".",
"data",
".",
"month",
"]",
"+",
"self",
".",
"data",
".",
"day",
"if",
"self",
".",
"L",
"(",
")",
"and",
"self",
".",
"data",
".",
"month",
">",
"2",
... | [
331,
4
] | [
336,
18
] | python | en | ['en', 'en', 'en'] | True |
serve | (request, path, insecure=False, **kwargs) |
Serve static files below a given point in the directory structure or
from locations inferred from the staticfiles finders.
To use, put a URL pattern such as::
from django.contrib.staticfiles import views
url(r'^(?P<path>.*)$', views.serve)
in your URLconf.
It uses the django.vi... |
Serve static files below a given point in the directory structure or
from locations inferred from the staticfiles finders. | def serve(request, path, insecure=False, **kwargs):
"""
Serve static files below a given point in the directory structure or
from locations inferred from the staticfiles finders.
To use, put a URL pattern such as::
from django.contrib.staticfiles import views
url(r'^(?P<path>.*)$', vi... | [
"def",
"serve",
"(",
"request",
",",
"path",
",",
"insecure",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"settings",
".",
"DEBUG",
"and",
"not",
"insecure",
":",
"raise",
"Http404",
"normalized_path",
"=",
"posixpath",
".",
"normpath",... | [
16,
0
] | [
40,
77
] | 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.