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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
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",
... | [
89,
0
] | [
107,
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",
... | [
109,
0
] | [
114,
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",
... | [
116,
0
] | [
130,
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",
... | [
132,
0
] | [
141,
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",
... | [
143,
0
] | [
152,
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"... | [
154,
0
] | [
164,
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"... | [
166,
0
] | [
246,
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",
"(",
"*... | [
248,
0
] | [
294,
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... | [
302,
0
] | [
340,
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... | [
351,
0
] | [
361,
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... | [
363,
0
] | [
373,
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... | [
375,
0
] | [
435,
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",... | [
454,
0
] | [
499,
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... | [
512,
0
] | [
520,
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",
",",
... | [
522,
0
] | [
541,
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",
... | [
546,
0
] | [
598,
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",
"... | [
601,
0
] | [
610,
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"... | [
612,
0
] | [
627,
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... | [
630,
0
] | [
650,
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",
"]"
] | [
652,
0
] | [
654,
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",
")"
] | [
656,
0
] | [
660,
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",
"(... | [
662,
0
] | [
697,
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... | [
699,
0
] | [
710,
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",... | [
729,
0
] | [
763,
45
] | python | de | ['en', 'fr', 'de'] | False |
_is_descriptor | (obj) | Returns True if obj is a descriptor, False otherwise. | Returns True if obj is a descriptor, False otherwise. | def _is_descriptor(obj):
"""Returns True if obj is a descriptor, False otherwise."""
return (
hasattr(obj, '__get__') or
hasattr(obj, '__set__') or
hasattr(obj, '__delete__')) | [
"def",
"_is_descriptor",
"(",
"obj",
")",
":",
"return",
"(",
"hasattr",
"(",
"obj",
",",
"'__get__'",
")",
"or",
"hasattr",
"(",
"obj",
",",
"'__set__'",
")",
"or",
"hasattr",
"(",
"obj",
",",
"'__delete__'",
")",
")"
] | [
19,
0
] | [
24,
39
] | python | en | ['en', 'lb', 'en'] | True |
_is_dunder | (name) | Returns True if a __dunder__ name, False otherwise. | Returns True if a __dunder__ name, False otherwise. | def _is_dunder(name):
"""Returns True if a __dunder__ name, False otherwise."""
return (name[:2] == name[-2:] == '__' and
name[2:3] != '_' and
name[-3:-2] != '_' and
len(name) > 4) | [
"def",
"_is_dunder",
"(",
"name",
")",
":",
"return",
"(",
"name",
"[",
":",
"2",
"]",
"==",
"name",
"[",
"-",
"2",
":",
"]",
"==",
"'__'",
"and",
"name",
"[",
"2",
":",
"3",
"]",
"!=",
"'_'",
"and",
"name",
"[",
"-",
"3",
":",
"-",
"2",
... | [
27,
0
] | [
32,
26
] | python | en | ['en', 'en', 'en'] | True |
_is_sunder | (name) | Returns True if a _sunder_ name, False otherwise. | Returns True if a _sunder_ name, False otherwise. | def _is_sunder(name):
"""Returns True if a _sunder_ name, False otherwise."""
return (name[0] == name[-1] == '_' and
name[1:2] != '_' and
name[-2:-1] != '_' and
len(name) > 2) | [
"def",
"_is_sunder",
"(",
"name",
")",
":",
"return",
"(",
"name",
"[",
"0",
"]",
"==",
"name",
"[",
"-",
"1",
"]",
"==",
"'_'",
"and",
"name",
"[",
"1",
":",
"2",
"]",
"!=",
"'_'",
"and",
"name",
"[",
"-",
"2",
":",
"-",
"1",
"]",
"!=",
... | [
35,
0
] | [
40,
26
] | python | en | ['en', 'en', 'en'] | True |
_make_class_unpicklable | (cls) | Make the given class un-picklable. | Make the given class un-picklable. | def _make_class_unpicklable(cls):
"""Make the given class un-picklable."""
def _break_on_call_reduce(self, proto):
raise TypeError('%r cannot be pickled' % self)
cls.__reduce_ex__ = _break_on_call_reduce
cls.__module__ = '<unknown>' | [
"def",
"_make_class_unpicklable",
"(",
"cls",
")",
":",
"def",
"_break_on_call_reduce",
"(",
"self",
",",
"proto",
")",
":",
"raise",
"TypeError",
"(",
"'%r cannot be pickled'",
"%",
"self",
")",
"cls",
".",
"__reduce_ex__",
"=",
"_break_on_call_reduce",
"cls",
... | [
42,
0
] | [
47,
32
] | python | en | ['en', 'en', 'en'] | True |
_high_bit | (value) | returns index of highest bit, or -1 if value is zero or negative | returns index of highest bit, or -1 if value is zero or negative | def _high_bit(value):
"""returns index of highest bit, or -1 if value is zero or negative"""
return value.bit_length() - 1 | [
"def",
"_high_bit",
"(",
"value",
")",
":",
"return",
"value",
".",
"bit_length",
"(",
")",
"-",
"1"
] | [
819,
0
] | [
821,
33
] | python | en | ['en', 'en', 'en'] | True |
unique | (enumeration) | Class decorator for enumerations ensuring unique member values. | Class decorator for enumerations ensuring unique member values. | def unique(enumeration):
"""Class decorator for enumerations ensuring unique member values."""
duplicates = []
for name, member in enumeration.__members__.items():
if name != member.name:
duplicates.append((name, member.name))
if duplicates:
alias_details = ', '.join(
... | [
"def",
"unique",
"(",
"enumeration",
")",
":",
"duplicates",
"=",
"[",
"]",
"for",
"name",
",",
"member",
"in",
"enumeration",
".",
"__members__",
".",
"items",
"(",
")",
":",
"if",
"name",
"!=",
"member",
".",
"name",
":",
"duplicates",
".",
"append",... | [
823,
0
] | [
834,
22
] | python | en | ['fr', 'la', 'en'] | False |
_decompose | (flag, value) | Extract all members from the value. | Extract all members from the value. | def _decompose(flag, value):
"""Extract all members from the value."""
# _decompose is only called if the value is not named
not_covered = value
negative = value < 0
# issue29167: wrap accesses to _value2member_map_ in a list to avoid race
# conditions between iterating over it and h... | [
"def",
"_decompose",
"(",
"flag",
",",
"value",
")",
":",
"# _decompose is only called if the value is not named",
"not_covered",
"=",
"value",
"negative",
"=",
"value",
"<",
"0",
"# issue29167: wrap accesses to _value2member_map_ in a list to avoid race",
"# conditio... | [
836,
0
] | [
869,
31
] | python | en | ['en', 'en', 'en'] | True |
_EnumDict.__setitem__ | (self, key, value) | Changes anything not dundered or not a descriptor.
If an enum member name is used twice, an error is raised; duplicate
values are not checked for.
Single underscore (sunder) names are reserved.
| Changes anything not dundered or not a descriptor. | def __setitem__(self, key, value):
"""Changes anything not dundered or not a descriptor.
If an enum member name is used twice, an error is raised; duplicate
values are not checked for.
Single underscore (sunder) names are reserved.
"""
if _is_sunder(key):
i... | [
"def",
"__setitem__",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"if",
"_is_sunder",
"(",
"key",
")",
":",
"if",
"key",
"not",
"in",
"(",
"'_order_'",
",",
"'_create_pseudo_member_'",
",",
"'_generate_next_value_'",
",",
"'_missing_'",
",",
")",
":",... | [
69,
4
] | [
102,
39
] | python | en | ['en', 'en', 'en'] | True |
EnumMeta.__bool__ | (self) |
classes/types should always be True.
|
classes/types should always be True.
| def __bool__(self):
"""
classes/types should always be True.
"""
return True | [
"def",
"__bool__",
"(",
"self",
")",
":",
"return",
"True"
] | [
258,
4
] | [
262,
19
] | python | en | ['en', 'error', 'th'] | False |
EnumMeta.__call__ | (cls, value, names=None, *, module=None, qualname=None, type=None, start=1) | Either returns an existing member, or creates a new enum class.
This method is used both when an enum class is given a value to match
to an enumeration member (i.e. Color(3)) and for the functional API
(i.e. Color = Enum('Color', names='RED GREEN BLUE')).
When used for the functional A... | Either returns an existing member, or creates a new enum class. | def __call__(cls, value, names=None, *, module=None, qualname=None, type=None, start=1):
"""Either returns an existing member, or creates a new enum class.
This method is used both when an enum class is given a value to match
to an enumeration member (i.e. Color(3)) and for the functional API
... | [
"def",
"__call__",
"(",
"cls",
",",
"value",
",",
"names",
"=",
"None",
",",
"*",
",",
"module",
"=",
"None",
",",
"qualname",
"=",
"None",
",",
"type",
"=",
"None",
",",
"start",
"=",
"1",
")",
":",
"if",
"names",
"is",
"None",
":",
"# simple va... | [
264,
4
] | [
292,
99
] | python | en | ['en', 'en', 'en'] | True |
EnumMeta.__getattr__ | (cls, name) | Return the enum member matching `name`
We use __getattr__ instead of descriptors or inserting into the enum
class' __dict__ in order to support `name` and `value` being both
properties for enum members (which live in the class' __dict__) and
enum members themselves.
| Return the enum member matching `name` | def __getattr__(cls, name):
"""Return the enum member matching `name`
We use __getattr__ instead of descriptors or inserting into the enum
class' __dict__ in order to support `name` and `value` being both
properties for enum members (which live in the class' __dict__) and
enum m... | [
"def",
"__getattr__",
"(",
"cls",
",",
"name",
")",
":",
"if",
"_is_dunder",
"(",
"name",
")",
":",
"raise",
"AttributeError",
"(",
"name",
")",
"try",
":",
"return",
"cls",
".",
"_member_map_",
"[",
"name",
"]",
"except",
"KeyError",
":",
"raise",
"At... | [
309,
4
] | [
323,
48
] | python | en | ['en', 'id', 'en'] | True |
EnumMeta.__members__ | (cls) | Returns a mapping of member name->value.
This mapping lists all enum members, including aliases. Note that this
is a read-only view of the internal mapping.
| Returns a mapping of member name->value. | def __members__(cls):
"""Returns a mapping of member name->value.
This mapping lists all enum members, including aliases. Note that this
is a read-only view of the internal mapping.
"""
return MappingProxyType(cls._member_map_) | [
"def",
"__members__",
"(",
"cls",
")",
":",
"return",
"MappingProxyType",
"(",
"cls",
".",
"_member_map_",
")"
] | [
335,
4
] | [
342,
49
] | python | en | ['en', 'en', 'en'] | True |
EnumMeta.__setattr__ | (cls, name, value) | Block attempts to reassign Enum members.
A simple assignment to the class namespace only changes one of the
several possible ways to get an Enum member from the Enum class,
resulting in an inconsistent Enumeration.
| Block attempts to reassign Enum members. | def __setattr__(cls, name, value):
"""Block attempts to reassign Enum members.
A simple assignment to the class namespace only changes one of the
several possible ways to get an Enum member from the Enum class,
resulting in an inconsistent Enumeration.
"""
member_map = ... | [
"def",
"__setattr__",
"(",
"cls",
",",
"name",
",",
"value",
")",
":",
"member_map",
"=",
"cls",
".",
"__dict__",
".",
"get",
"(",
"'_member_map_'",
",",
"{",
"}",
")",
"if",
"name",
"in",
"member_map",
":",
"raise",
"AttributeError",
"(",
"'Cannot reass... | [
350,
4
] | [
361,
40
] | python | en | ['en', 'en', 'en'] | True |
EnumMeta._create_ | (cls, class_name, names, *, module=None, qualname=None, type=None, start=1) | Convenience method to create a new Enum class.
`names` can be:
* A string containing member names, separated either with spaces or
commas. Values are incremented by 1 from `start`.
* An iterable of member names. Values are incremented by 1 from `start`.
* An iterable of (me... | Convenience method to create a new Enum class. | def _create_(cls, class_name, names, *, module=None, qualname=None, type=None, start=1):
"""Convenience method to create a new Enum class.
`names` can be:
* A string containing member names, separated either with spaces or
commas. Values are incremented by 1 from `start`.
* ... | [
"def",
"_create_",
"(",
"cls",
",",
"class_name",
",",
"names",
",",
"*",
",",
"module",
"=",
"None",
",",
"qualname",
"=",
"None",
",",
"type",
"=",
"None",
",",
"start",
"=",
"1",
")",
":",
"metacls",
"=",
"cls",
".",
"__class__",
"bases",
"=",
... | [
363,
4
] | [
414,
25
] | python | en | ['en', 'en', 'en'] | True |
EnumMeta._get_mixins_ | (bases) | Returns the type for creating enum members, and the first inherited
enum class.
bases: the tuple of bases that was given to __new__
| Returns the type for creating enum members, and the first inherited
enum class. | def _get_mixins_(bases):
"""Returns the type for creating enum members, and the first inherited
enum class.
bases: the tuple of bases that was given to __new__
"""
if not bases:
return object, Enum
# double check that we are not subclassing a class with exi... | [
"def",
"_get_mixins_",
"(",
"bases",
")",
":",
"if",
"not",
"bases",
":",
"return",
"object",
",",
"Enum",
"# double check that we are not subclassing a class with existing",
"# enumeration members; while we're at it, see if any other data",
"# type has been mixed in so we can use th... | [
417,
4
] | [
459,
38
] | python | en | ['en', 'en', 'en'] | True |
EnumMeta._find_new_ | (classdict, member_type, first_enum) | Returns the __new__ to be used for creating the enum members.
classdict: the class dictionary given to __new__
member_type: the data type whose __new__ will be used by default
first_enum: enumeration to check for an overriding __new__
| Returns the __new__ to be used for creating the enum members. | def _find_new_(classdict, member_type, first_enum):
"""Returns the __new__ to be used for creating the enum members.
classdict: the class dictionary given to __new__
member_type: the data type whose __new__ will be used by default
first_enum: enumeration to check for an overriding __new... | [
"def",
"_find_new_",
"(",
"classdict",
",",
"member_type",
",",
"first_enum",
")",
":",
"# now find the correct __new__, checking to see of one was defined",
"# by the user; also check earlier enum classes in case a __new__ was",
"# saved as __new_member__",
"__new__",
"=",
"classdict"... | [
462,
4
] | [
505,
42
] | python | en | ['en', 'en', 'en'] | True |
Enum.name | (self) | The name of the Enum member. | The name of the Enum member. | def name(self):
"""The name of the Enum member."""
return self._name_ | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name_"
] | [
592,
4
] | [
594,
26
] | python | en | ['en', 'id', 'en'] | True |
Enum.value | (self) | The value of the Enum member. | The value of the Enum member. | def value(self):
"""The value of the Enum member."""
return self._value_ | [
"def",
"value",
"(",
"self",
")",
":",
"return",
"self",
".",
"_value_"
] | [
597,
4
] | [
599,
27
] | python | en | ['en', 'en', 'en'] | True |
Enum._convert | (cls, name, module, filter, source=None) |
Create a new Enum subclass that replaces a collection of global constants
|
Create a new Enum subclass that replaces a collection of global constants
| def _convert(cls, name, module, filter, source=None):
"""
Create a new Enum subclass that replaces a collection of global constants
"""
# convert all constants from source (or module) that pass filter() to
# a new Enum called name, and export the enum and its members back to
... | [
"def",
"_convert",
"(",
"cls",
",",
"name",
",",
"module",
",",
"filter",
",",
"source",
"=",
"None",
")",
":",
"# convert all constants from source (or module) that pass filter() to",
"# a new Enum called name, and export the enum and its members back to",
"# module;",
"# also... | [
602,
4
] | [
635,
18
] | python | en | ['en', 'error', 'th'] | False |
Flag._generate_next_value_ | (name, start, count, last_values) |
Generate the next value when not given.
name: the name of the member
start: the initital start value or None
count: the number of existing members
last_value: the last value assigned or None
|
Generate the next value when not given. | def _generate_next_value_(name, start, count, last_values):
"""
Generate the next value when not given.
name: the name of the member
start: the initital start value or None
count: the number of existing members
last_value: the last value assigned or None
"""
... | [
"def",
"_generate_next_value_",
"(",
"name",
",",
"start",
",",
"count",
",",
"last_values",
")",
":",
"if",
"not",
"count",
":",
"return",
"start",
"if",
"start",
"is",
"not",
"None",
"else",
"1",
"for",
"last_value",
"in",
"reversed",
"(",
"last_values",... | [
648,
4
] | [
665,
32
] | python | en | ['en', 'error', 'th'] | False |
Flag._create_pseudo_member_ | (cls, value) |
Create a composite member iff value contains only members.
|
Create a composite member iff value contains only members.
| def _create_pseudo_member_(cls, value):
"""
Create a composite member iff value contains only members.
"""
pseudo_member = cls._value2member_map_.get(value, None)
if pseudo_member is None:
# verify all bits are accounted for
_, extra_flags = _decompose(cls... | [
"def",
"_create_pseudo_member_",
"(",
"cls",
",",
"value",
")",
":",
"pseudo_member",
"=",
"cls",
".",
"_value2member_map_",
".",
"get",
"(",
"value",
",",
"None",
")",
"if",
"pseudo_member",
"is",
"None",
":",
"# verify all bits are accounted for",
"_",
",",
... | [
678,
4
] | [
695,
28
] | python | en | ['en', 'error', 'th'] | False |
Reader.__init__ | (self, options) |
@param options: An options object.
@type options: I{Options}
| def __init__(self, options):
"""
@param options: An options object.
@type options: I{Options}
"""
self.options = options
self.plugins = PluginContainer(options.plugins) | [
"def",
"__init__",
"(",
"self",
",",
"options",
")",
":",
"self",
".",
"options",
"=",
"options",
"self",
".",
"plugins",
"=",
"PluginContainer",
"(",
"options",
".",
"plugins",
")"
] | [
39,
4
] | [
45,
55
] | python | en | ['en', 'error', 'th'] | False | |
Reader.mangle | (self, name, x) |
Mangle the name by hashing the I{name} and appending I{x}.
@return: the mangled name.
|
Mangle the name by hashing the I{name} and appending I{x}.
| def mangle(self, name, x):
"""
Mangle the name by hashing the I{name} and appending I{x}.
@return: the mangled name.
"""
h = abs(hash(name))
return '%s-%s' % (h, x) | [
"def",
"mangle",
"(",
"self",
",",
"name",
",",
"x",
")",
":",
"h",
"=",
"abs",
"(",
"hash",
"(",
"name",
")",
")",
"return",
"'%s-%s'",
"%",
"(",
"h",
",",
"x",
")"
] | [
47,
4
] | [
53,
31
] | python | en | ['en', 'error', 'th'] | False |
DocumentReader.open | (self, url) |
Open an XML document at the specified I{url}.
First, the document attempted to be retrieved from
the I{object cache}. If not found, it is downloaded and
parsed using the SAX parser. The result is added to the
cache for the next open().
@param url: A document url.
... |
Open an XML document at the specified I{url}.
First, the document attempted to be retrieved from
the I{object cache}. If not found, it is downloaded and
parsed using the SAX parser. The result is added to the
cache for the next open().
| def open(self, url):
"""
Open an XML document at the specified I{url}.
First, the document attempted to be retrieved from
the I{object cache}. If not found, it is downloaded and
parsed using the SAX parser. The result is added to the
cache for the next open().
@... | [
"def",
"open",
"(",
"self",
",",
"url",
")",
":",
"cache",
"=",
"self",
".",
"cache",
"(",
")",
"id",
"=",
"self",
".",
"mangle",
"(",
"url",
",",
"'document'",
")",
"d",
"=",
"cache",
".",
"get",
"(",
"id",
")",
"if",
"d",
"is",
"None",
":",... | [
62,
4
] | [
81,
16
] | python | en | ['en', 'error', 'th'] | False |
DocumentReader.download | (self, url) |
Download the docuemnt.
@param url: A document url.
@type url: str.
@return: A file pointer to the docuemnt.
@rtype: file-like
|
Download the docuemnt.
| def download(self, url):
"""
Download the docuemnt.
@param url: A document url.
@type url: str.
@return: A file pointer to the docuemnt.
@rtype: file-like
"""
store = DocumentStore()
fp = store.open(url)
if fp is None:
fp = self... | [
"def",
"download",
"(",
"self",
",",
"url",
")",
":",
"store",
"=",
"DocumentStore",
"(",
")",
"fp",
"=",
"store",
".",
"open",
"(",
"url",
")",
"if",
"fp",
"is",
"None",
":",
"fp",
"=",
"self",
".",
"options",
".",
"transport",
".",
"open",
"(",... | [
83,
4
] | [
100,
40
] | python | en | ['en', 'error', 'th'] | False |
DocumentReader.cache | (self) |
Get the cache.
@return: The I{options} when I{cachingpolicy} = B{0}.
@rtype: L{Cache}
|
Get the cache.
| def cache(self):
"""
Get the cache.
@return: The I{options} when I{cachingpolicy} = B{0}.
@rtype: L{Cache}
"""
if self.options.cachingpolicy == 0:
return self.options.cache
else:
return NoCache() | [
"def",
"cache",
"(",
"self",
")",
":",
"if",
"self",
".",
"options",
".",
"cachingpolicy",
"==",
"0",
":",
"return",
"self",
".",
"options",
".",
"cache",
"else",
":",
"return",
"NoCache",
"(",
")"
] | [
102,
4
] | [
111,
28
] | python | en | ['en', 'error', 'th'] | False |
DefinitionsReader.__init__ | (self, options, fn) |
@param options: An options object.
@type options: I{Options}
@param fn: A factory function (constructor) used to
create the object not found in the cache.
@type fn: I{Constructor}
| def __init__(self, options, fn):
"""
@param options: An options object.
@type options: I{Options}
@param fn: A factory function (constructor) used to
create the object not found in the cache.
@type fn: I{Constructor}
"""
Reader.__init__(self, options)
... | [
"def",
"__init__",
"(",
"self",
",",
"options",
",",
"fn",
")",
":",
"Reader",
".",
"__init__",
"(",
"self",
",",
"options",
")",
"self",
".",
"fn",
"=",
"fn"
] | [
123,
4
] | [
132,
20
] | python | en | ['en', 'error', 'th'] | False | |
DefinitionsReader.open | (self, url) |
Open a WSDL at the specified I{url}.
First, the WSDL attempted to be retrieved from
the I{object cache}. After unpickled from the cache, the
I{options} attribute is restored.
If not found, it is downloaded and instantiated using the
I{fn} constructor and added to the c... |
Open a WSDL at the specified I{url}.
First, the WSDL attempted to be retrieved from
the I{object cache}. After unpickled from the cache, the
I{options} attribute is restored.
If not found, it is downloaded and instantiated using the
I{fn} constructor and added to the c... | def open(self, url):
"""
Open a WSDL at the specified I{url}.
First, the WSDL attempted to be retrieved from
the I{object cache}. After unpickled from the cache, the
I{options} attribute is restored.
If not found, it is downloaded and instantiated using the
I{fn... | [
"def",
"open",
"(",
"self",
",",
"url",
")",
":",
"cache",
"=",
"self",
".",
"cache",
"(",
")",
"id",
"=",
"self",
".",
"mangle",
"(",
"url",
",",
"'wsdl'",
")",
"d",
"=",
"cache",
".",
"get",
"(",
"id",
")",
"if",
"d",
"is",
"None",
":",
"... | [
134,
4
] | [
157,
16
] | python | en | ['en', 'error', 'th'] | False |
DefinitionsReader.cache | (self) |
Get the cache.
@return: The I{options} when I{cachingpolicy} = B{1}.
@rtype: L{Cache}
|
Get the cache.
| def cache(self):
"""
Get the cache.
@return: The I{options} when I{cachingpolicy} = B{1}.
@rtype: L{Cache}
"""
if self.options.cachingpolicy == 1:
return self.options.cache
else:
return NoCache() | [
"def",
"cache",
"(",
"self",
")",
":",
"if",
"self",
".",
"options",
".",
"cachingpolicy",
"==",
"1",
":",
"return",
"self",
".",
"options",
".",
"cache",
"else",
":",
"return",
"NoCache",
"(",
")"
] | [
159,
4
] | [
168,
28
] | python | en | ['en', 'error', 'th'] | False |
new | (key, msg = None, digestmod = None) | Create a new hashing object and return it.
key: The starting key for the hash.
msg: if available, will immediately be hashed into the object's starting
state.
You can now feed arbitrary strings into the object using its update()
method, and can ask for the hash value at any time by calling its dig... | Create a new hashing object and return it. | def new(key, msg = None, digestmod = None):
"""Create a new hashing object and return it.
key: The starting key for the hash.
msg: if available, will immediately be hashed into the object's starting
state.
You can now feed arbitrary strings into the object using its update()
method, and can as... | [
"def",
"new",
"(",
"key",
",",
"msg",
"=",
"None",
",",
"digestmod",
"=",
"None",
")",
":",
"return",
"HMAC",
"(",
"key",
",",
"msg",
",",
"digestmod",
")"
] | [
132,
0
] | [
143,
36
] | python | en | ['en', 'en', 'en'] | True |
HMAC.__init__ | (self, key, msg = None, digestmod = None) | Create a new HMAC object.
key: key for the keyed hash object.
msg: Initial input for the hash, if provided.
digestmod: A module supporting PEP 247. *OR*
A hashlib constructor returning a new hash object. *OR*
A hash name suitable for hashlib.ne... | Create a new HMAC object. | def __init__(self, key, msg = None, digestmod = None):
"""Create a new HMAC object.
key: key for the keyed hash object.
msg: Initial input for the hash, if provided.
digestmod: A module supporting PEP 247. *OR*
A hashlib constructor returning a new hash o... | [
"def",
"__init__",
"(",
"self",
",",
"key",
",",
"msg",
"=",
"None",
",",
"digestmod",
"=",
"None",
")",
":",
"if",
"not",
"isinstance",
"(",
"key",
",",
"(",
"bytes",
",",
"bytearray",
")",
")",
":",
"raise",
"TypeError",
"(",
"\"key: expected bytes o... | [
25,
4
] | [
83,
28
] | python | en | ['en', 'en', 'en'] | True |
HMAC.update | (self, msg) | Update this hashing object with the string msg.
| Update this hashing object with the string msg.
| def update(self, msg):
"""Update this hashing object with the string msg.
"""
self.inner.update(msg) | [
"def",
"update",
"(",
"self",
",",
"msg",
")",
":",
"self",
".",
"inner",
".",
"update",
"(",
"msg",
")"
] | [
89,
4
] | [
92,
30
] | python | en | ['en', 'en', 'en'] | True |
HMAC.copy | (self) | Return a separate copy of this hashing object.
An update to this copy won't affect the original object.
| Return a separate copy of this hashing object. | def copy(self):
"""Return a separate copy of this hashing object.
An update to this copy won't affect the original object.
"""
# Call __new__ directly to avoid the expensive __init__.
other = self.__class__.__new__(self.__class__)
other.digest_cons = self.digest_cons
... | [
"def",
"copy",
"(",
"self",
")",
":",
"# Call __new__ directly to avoid the expensive __init__.",
"other",
"=",
"self",
".",
"__class__",
".",
"__new__",
"(",
"self",
".",
"__class__",
")",
"other",
".",
"digest_cons",
"=",
"self",
".",
"digest_cons",
"other",
"... | [
94,
4
] | [
105,
20
] | python | en | ['en', 'en', 'en'] | True |
HMAC._current | (self) | Return a hash object for the current state.
To be used only internally with digest() and hexdigest().
| Return a hash object for the current state. | def _current(self):
"""Return a hash object for the current state.
To be used only internally with digest() and hexdigest().
"""
h = self.outer.copy()
h.update(self.inner.digest())
return h | [
"def",
"_current",
"(",
"self",
")",
":",
"h",
"=",
"self",
".",
"outer",
".",
"copy",
"(",
")",
"h",
".",
"update",
"(",
"self",
".",
"inner",
".",
"digest",
"(",
")",
")",
"return",
"h"
] | [
107,
4
] | [
114,
16
] | python | en | ['en', 'en', 'en'] | True |
HMAC.digest | (self) | Return the hash value of this hashing object.
This returns a string containing 8-bit data. The object is
not altered in any way by this function; you can continue
updating the object after calling this function.
| Return the hash value of this hashing object. | def digest(self):
"""Return the hash value of this hashing object.
This returns a string containing 8-bit data. The object is
not altered in any way by this function; you can continue
updating the object after calling this function.
"""
h = self._current()
retur... | [
"def",
"digest",
"(",
"self",
")",
":",
"h",
"=",
"self",
".",
"_current",
"(",
")",
"return",
"h",
".",
"digest",
"(",
")"
] | [
116,
4
] | [
124,
25
] | python | en | ['en', 'en', 'en'] | True |
HMAC.hexdigest | (self) | Like digest(), but returns a string of hexadecimal digits instead.
| Like digest(), but returns a string of hexadecimal digits instead.
| def hexdigest(self):
"""Like digest(), but returns a string of hexadecimal digits instead.
"""
h = self._current()
return h.hexdigest() | [
"def",
"hexdigest",
"(",
"self",
")",
":",
"h",
"=",
"self",
".",
"_current",
"(",
")",
"return",
"h",
".",
"hexdigest",
"(",
")"
] | [
126,
4
] | [
130,
28
] | python | en | ['en', 'en', 'en'] | True |
midi_file_to_drum_track | (midi_file, steps_per_quarter=4) | Loads a drum track from a MIDI file.
Args:
midi_file: Absolute path to MIDI file.
steps_per_quarter: Quantization of DrumTrack. For example, 4 = 16th notes.
Returns:
A DrumTrack object extracted from the MIDI file.
| Loads a drum track from a MIDI file. | def midi_file_to_drum_track(midi_file, steps_per_quarter=4):
"""Loads a drum track from a MIDI file.
Args:
midi_file: Absolute path to MIDI file.
steps_per_quarter: Quantization of DrumTrack. For example, 4 = 16th notes.
Returns:
A DrumTrack object extracted from the MIDI file.
"""
sequence = mi... | [
"def",
"midi_file_to_drum_track",
"(",
"midi_file",
",",
"steps_per_quarter",
"=",
"4",
")",
":",
"sequence",
"=",
"midi_io",
".",
"midi_file_to_sequence_proto",
"(",
"midi_file",
")",
"quantized_sequence",
"=",
"sequences_lib",
".",
"quantize_note_sequence",
"(",
"se... | [
268,
0
] | [
283,
19
] | python | en | ['en', 'en', 'en'] | True |
DrumTrack.__init__ | (self, events=None, **kwargs) | Construct a DrumTrack. | Construct a DrumTrack. | def __init__(self, events=None, **kwargs):
"""Construct a DrumTrack."""
if 'pad_event' in kwargs:
del kwargs['pad_event']
super(DrumTrack, self).__init__(pad_event=frozenset(),
events=events, **kwargs) | [
"def",
"__init__",
"(",
"self",
",",
"events",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"'pad_event'",
"in",
"kwargs",
":",
"del",
"kwargs",
"[",
"'pad_event'",
"]",
"super",
"(",
"DrumTrack",
",",
"self",
")",
".",
"__init__",
"(",
"pad... | [
69,
2
] | [
74,
60
] | python | en | ['en', 'en', 'en'] | True |
DrumTrack._from_event_list | (self, events, start_step=0,
steps_per_bar=DEFAULT_STEPS_PER_BAR,
steps_per_quarter=DEFAULT_STEPS_PER_QUARTER) | Initializes with a list of event values and sets attributes.
Args:
events: List of drum events to set drum track to.
start_step: The integer starting step offset.
steps_per_bar: The number of steps in a bar.
steps_per_quarter: The number of steps in a quarter note.
Raises:
ValueE... | Initializes with a list of event values and sets attributes. | def _from_event_list(self, events, start_step=0,
steps_per_bar=DEFAULT_STEPS_PER_BAR,
steps_per_quarter=DEFAULT_STEPS_PER_QUARTER):
"""Initializes with a list of event values and sets attributes.
Args:
events: List of drum events to set drum track to.
s... | [
"def",
"_from_event_list",
"(",
"self",
",",
"events",
",",
"start_step",
"=",
"0",
",",
"steps_per_bar",
"=",
"DEFAULT_STEPS_PER_BAR",
",",
"steps_per_quarter",
"=",
"DEFAULT_STEPS_PER_QUARTER",
")",
":",
"for",
"event",
"in",
"events",
":",
"if",
"not",
"isins... | [
76,
2
] | [
97,
44
] | python | en | ['en', 'en', 'en'] | True |
DrumTrack.append | (self, event) | Appends the event to the end of the drums and increments the end step.
Args:
event: The drum event to append to the end.
Raises:
ValueError: If `event` is not a valid drum event.
| Appends the event to the end of the drums and increments the end step. | def append(self, event):
"""Appends the event to the end of the drums and increments the end step.
Args:
event: The drum event to append to the end.
Raises:
ValueError: If `event` is not a valid drum event.
"""
if not isinstance(event, frozenset):
raise ValueError('Invalid drum ev... | [
"def",
"append",
"(",
"self",
",",
"event",
")",
":",
"if",
"not",
"isinstance",
"(",
"event",
",",
"frozenset",
")",
":",
"raise",
"ValueError",
"(",
"'Invalid drum event: %s'",
"%",
"event",
")",
"if",
"not",
"all",
"(",
"MIN_MIDI_PITCH",
"<=",
"drum",
... | [
99,
2
] | [
111,
40
] | python | en | ['en', 'en', 'en'] | True |
DrumTrack.from_quantized_sequence | (self,
quantized_sequence,
search_start_step=0,
gap_bars=1,
pad_end=False,
ignore_is_drum=False) | Populate self with drums from the given quantized NoteSequence object.
A drum track is extracted from the given quantized sequence starting at time
step `start_step`. `start_step` can be used to drive extraction of multiple
drum tracks from the same quantized sequence. The end step of the extracted
dru... | Populate self with drums from the given quantized NoteSequence object. | def from_quantized_sequence(self,
quantized_sequence,
search_start_step=0,
gap_bars=1,
pad_end=False,
ignore_is_drum=False):
"""Populate self with drums from the give... | [
"def",
"from_quantized_sequence",
"(",
"self",
",",
"quantized_sequence",
",",
"search_start_step",
"=",
"0",
",",
"gap_bars",
"=",
"1",
",",
"pad_end",
"=",
"False",
",",
"ignore_is_drum",
"=",
"False",
")",
":",
"sequences_lib",
".",
"assert_is_relative_quantize... | [
113,
2
] | [
209,
27
] | python | en | ['en', 'en', 'en'] | True |
DrumTrack.to_sequence | (self,
velocity=100,
instrument=9,
program=0,
sequence_start_time=0.0,
qpm=120.0) | Converts the DrumTrack to NoteSequence proto.
Args:
velocity: Midi velocity to give each note. Between 1 and 127 (inclusive).
instrument: Midi instrument to give each note.
program: Midi program to give each note.
sequence_start_time: A time in seconds (float) that the first event in the
... | Converts the DrumTrack to NoteSequence proto. | def to_sequence(self,
velocity=100,
instrument=9,
program=0,
sequence_start_time=0.0,
qpm=120.0):
"""Converts the DrumTrack to NoteSequence proto.
Args:
velocity: Midi velocity to give each note. Between 1 and 127 (... | [
"def",
"to_sequence",
"(",
"self",
",",
"velocity",
"=",
"100",
",",
"instrument",
"=",
"9",
",",
"program",
"=",
"0",
",",
"sequence_start_time",
"=",
"0.0",
",",
"qpm",
"=",
"120.0",
")",
":",
"seconds_per_step",
"=",
"60.0",
"/",
"qpm",
"/",
"self",... | [
211,
2
] | [
252,
19
] | python | en | ['en', 'en', 'en'] | True |
DrumTrack.increase_resolution | (self, k) | Increase the resolution of a DrumTrack.
Increases the resolution of a DrumTrack object by a factor of `k`. This uses
empty events to extend each event in the drum track to be `k` steps long.
Args:
k: An integer, the factor by which to increase the resolution of the
drum track.
| Increase the resolution of a DrumTrack. | def increase_resolution(self, k):
"""Increase the resolution of a DrumTrack.
Increases the resolution of a DrumTrack object by a factor of `k`. This uses
empty events to extend each event in the drum track to be `k` steps long.
Args:
k: An integer, the factor by which to increase the resolution ... | [
"def",
"increase_resolution",
"(",
"self",
",",
"k",
")",
":",
"super",
"(",
"DrumTrack",
",",
"self",
")",
".",
"increase_resolution",
"(",
"k",
",",
"fill_event",
"=",
"frozenset",
"(",
")",
")"
] | [
254,
2
] | [
265,
34
] | python | en | ['en', 'en', 'en'] | True |
get_all_distribution_names | (url=None) |
Return all distribution names known by an index.
:param url: The URL of the index.
:return: A list of all known distribution names.
|
Return all distribution names known by an index.
:param url: The URL of the index.
:return: A list of all known distribution names.
| def get_all_distribution_names(url=None):
"""
Return all distribution names known by an index.
:param url: The URL of the index.
:return: A list of all known distribution names.
"""
if url is None:
url = DEFAULT_INDEX
client = ServerProxy(url, timeout=3.0)
try:
return cli... | [
"def",
"get_all_distribution_names",
"(",
"url",
"=",
"None",
")",
":",
"if",
"url",
"is",
"None",
":",
"url",
"=",
"DEFAULT_INDEX",
"client",
"=",
"ServerProxy",
"(",
"url",
",",
"timeout",
"=",
"3.0",
")",
"try",
":",
"return",
"client",
".",
"list_pac... | [
40,
0
] | [
52,
25
] | python | en | ['en', 'error', 'th'] | False |
Locator.__init__ | (self, scheme='default') |
Initialise an instance.
:param scheme: Because locators look for most recent versions, they
need to know the version scheme to use. This specifies
the current PEP-recommended scheme - use ``'legacy'``
if you need to support existing d... |
Initialise an instance.
:param scheme: Because locators look for most recent versions, they
need to know the version scheme to use. This specifies
the current PEP-recommended scheme - use ``'legacy'``
if you need to support existing d... | def __init__(self, scheme='default'):
"""
Initialise an instance.
:param scheme: Because locators look for most recent versions, they
need to know the version scheme to use. This specifies
the current PEP-recommended scheme - use ``'legacy'``
... | [
"def",
"__init__",
"(",
"self",
",",
"scheme",
"=",
"'default'",
")",
":",
"self",
".",
"_cache",
"=",
"{",
"}",
"self",
".",
"scheme",
"=",
"scheme",
"# Because of bugs in some of the handlers on some of the platforms,",
"# we use our own opener rather than just using ur... | [
101,
4
] | [
118,
35
] | python | en | ['en', 'error', 'th'] | False |
Locator.get_errors | (self) |
Return any errors which have occurred.
|
Return any errors which have occurred.
| def get_errors(self):
"""
Return any errors which have occurred.
"""
result = []
while not self.errors.empty(): # pragma: no cover
try:
e = self.errors.get(False)
result.append(e)
except self.errors.Empty:
c... | [
"def",
"get_errors",
"(",
"self",
")",
":",
"result",
"=",
"[",
"]",
"while",
"not",
"self",
".",
"errors",
".",
"empty",
"(",
")",
":",
"# pragma: no cover",
"try",
":",
"e",
"=",
"self",
".",
"errors",
".",
"get",
"(",
"False",
")",
"result",
"."... | [
120,
4
] | [
132,
21
] | python | en | ['en', 'error', 'th'] | False |
Locator.clear_errors | (self) |
Clear any errors which may have been logged.
|
Clear any errors which may have been logged.
| def clear_errors(self):
"""
Clear any errors which may have been logged.
"""
# Just get the errors and throw them away
self.get_errors() | [
"def",
"clear_errors",
"(",
"self",
")",
":",
"# Just get the errors and throw them away",
"self",
".",
"get_errors",
"(",
")"
] | [
134,
4
] | [
139,
25
] | python | en | ['en', 'error', 'th'] | False |
Locator._get_project | (self, name) |
For a given project, get a dictionary mapping available versions to Distribution
instances.
This should be implemented in subclasses.
If called from a locate() request, self.matcher will be set to a
matcher for the requirement to satisfy, otherwise it will be None.
|
For a given project, get a dictionary mapping available versions to Distribution
instances. | def _get_project(self, name):
"""
For a given project, get a dictionary mapping available versions to Distribution
instances.
This should be implemented in subclasses.
If called from a locate() request, self.matcher will be set to a
matcher for the requirement to satisf... | [
"def",
"_get_project",
"(",
"self",
",",
"name",
")",
":",
"raise",
"NotImplementedError",
"(",
"'Please implement in the subclass'",
")"
] | [
152,
4
] | [
162,
69
] | python | en | ['en', 'error', 'th'] | False |
Locator.get_distribution_names | (self) |
Return all the distribution names known to this locator.
|
Return all the distribution names known to this locator.
| def get_distribution_names(self):
"""
Return all the distribution names known to this locator.
"""
raise NotImplementedError('Please implement in the subclass') | [
"def",
"get_distribution_names",
"(",
"self",
")",
":",
"raise",
"NotImplementedError",
"(",
"'Please implement in the subclass'",
")"
] | [
164,
4
] | [
168,
69
] | python | en | ['en', 'error', 'th'] | False |
Locator.get_project | (self, name) |
For a given project, get a dictionary mapping available versions to Distribution
instances.
This calls _get_project to do all the work, and just implements a caching layer on top.
|
For a given project, get a dictionary mapping available versions to Distribution
instances. | def get_project(self, name):
"""
For a given project, get a dictionary mapping available versions to Distribution
instances.
This calls _get_project to do all the work, and just implements a caching layer on top.
"""
if self._cache is None: # pragma: no cover
... | [
"def",
"get_project",
"(",
"self",
",",
"name",
")",
":",
"if",
"self",
".",
"_cache",
"is",
"None",
":",
"# pragma: no cover",
"result",
"=",
"self",
".",
"_get_project",
"(",
"name",
")",
"elif",
"name",
"in",
"self",
".",
"_cache",
":",
"result",
"=... | [
170,
4
] | [
185,
21
] | python | en | ['en', 'error', 'th'] | False |
Locator.score_url | (self, url) |
Give an url a score which can be used to choose preferred URLs
for a given project release.
|
Give an url a score which can be used to choose preferred URLs
for a given project release.
| def score_url(self, url):
"""
Give an url a score which can be used to choose preferred URLs
for a given project release.
"""
t = urlparse(url)
basename = posixpath.basename(t.path)
compatible = True
is_wheel = basename.endswith('.whl')
is_download... | [
"def",
"score_url",
"(",
"self",
",",
"url",
")",
":",
"t",
"=",
"urlparse",
"(",
"url",
")",
"basename",
"=",
"posixpath",
".",
"basename",
"(",
"t",
".",
"path",
")",
"compatible",
"=",
"True",
"is_wheel",
"=",
"basename",
".",
"endswith",
"(",
"'.... | [
187,
4
] | [
200,
64
] | python | en | ['en', 'error', 'th'] | False |
Locator.prefer_url | (self, url1, url2) |
Choose one of two URLs where both are candidates for distribution
archives for the same version of a distribution (for example,
.tar.gz vs. zip).
The current implementation favours https:// URLs over http://, archives
from PyPI over those from other locations, wheel compatibili... |
Choose one of two URLs where both are candidates for distribution
archives for the same version of a distribution (for example,
.tar.gz vs. zip). | def prefer_url(self, url1, url2):
"""
Choose one of two URLs where both are candidates for distribution
archives for the same version of a distribution (for example,
.tar.gz vs. zip).
The current implementation favours https:// URLs over http://, archives
from PyPI over ... | [
"def",
"prefer_url",
"(",
"self",
",",
"url1",
",",
"url2",
")",
":",
"result",
"=",
"url2",
"if",
"url1",
":",
"s1",
"=",
"self",
".",
"score_url",
"(",
"url1",
")",
"s2",
"=",
"self",
".",
"score_url",
"(",
"url2",
")",
"if",
"s1",
">",
"s2",
... | [
202,
4
] | [
222,
21
] | python | en | ['en', 'error', 'th'] | False |
Locator.split_filename | (self, filename, project_name) |
Attempt to split a filename in project name, version and Python version.
|
Attempt to split a filename in project name, version and Python version.
| def split_filename(self, filename, project_name):
"""
Attempt to split a filename in project name, version and Python version.
"""
return split_filename(filename, project_name) | [
"def",
"split_filename",
"(",
"self",
",",
"filename",
",",
"project_name",
")",
":",
"return",
"split_filename",
"(",
"filename",
",",
"project_name",
")"
] | [
224,
4
] | [
228,
53
] | python | en | ['en', 'error', 'th'] | False |
Locator.convert_url_to_download_info | (self, url, project_name) |
See if a URL is a candidate for a download URL for a project (the URL
has typically been scraped from an HTML page).
If it is, a dictionary is returned with keys "name", "version",
"filename" and "url"; otherwise, None is returned.
|
See if a URL is a candidate for a download URL for a project (the URL
has typically been scraped from an HTML page). | def convert_url_to_download_info(self, url, project_name):
"""
See if a URL is a candidate for a download URL for a project (the URL
has typically been scraped from an HTML page).
If it is, a dictionary is returned with keys "name", "version",
"filename" and "url"; otherwise, No... | [
"def",
"convert_url_to_download_info",
"(",
"self",
",",
"url",
",",
"project_name",
")",
":",
"def",
"same_project",
"(",
"name1",
",",
"name2",
")",
":",
"return",
"normalize_name",
"(",
"name1",
")",
"==",
"normalize_name",
"(",
"name2",
")",
"result",
"=... | [
230,
4
] | [
302,
21
] | python | en | ['en', 'error', 'th'] | False |
Locator._get_digest | (self, info) |
Get a digest from a dictionary by looking at a "digests" dictionary
or keys of the form 'algo_digest'.
Returns a 2-tuple (algo, digest) if found, else None. Currently
looks only for SHA256, then MD5.
|
Get a digest from a dictionary by looking at a "digests" dictionary
or keys of the form 'algo_digest'. | def _get_digest(self, info):
"""
Get a digest from a dictionary by looking at a "digests" dictionary
or keys of the form 'algo_digest'.
Returns a 2-tuple (algo, digest) if found, else None. Currently
looks only for SHA256, then MD5.
"""
result = None
if '... | [
"def",
"_get_digest",
"(",
"self",
",",
"info",
")",
":",
"result",
"=",
"None",
"if",
"'digests'",
"in",
"info",
":",
"digests",
"=",
"info",
"[",
"'digests'",
"]",
"for",
"algo",
"in",
"(",
"'sha256'",
",",
"'md5'",
")",
":",
"if",
"algo",
"in",
... | [
304,
4
] | [
325,
21
] | python | en | ['en', 'error', 'th'] | False |
Locator._update_version_data | (self, result, info) |
Update a result dictionary (the final result from _get_project) with a
dictionary for a specific version, which typically holds information
gleaned from a filename or URL for an archive for the distribution.
|
Update a result dictionary (the final result from _get_project) with a
dictionary for a specific version, which typically holds information
gleaned from a filename or URL for an archive for the distribution.
| def _update_version_data(self, result, info):
"""
Update a result dictionary (the final result from _get_project) with a
dictionary for a specific version, which typically holds information
gleaned from a filename or URL for an archive for the distribution.
"""
name = inf... | [
"def",
"_update_version_data",
"(",
"self",
",",
"result",
",",
"info",
")",
":",
"name",
"=",
"info",
".",
"pop",
"(",
"'name'",
")",
"version",
"=",
"info",
".",
"pop",
"(",
"'version'",
")",
"if",
"version",
"in",
"result",
":",
"dist",
"=",
"resu... | [
327,
4
] | [
348,
30
] | python | en | ['en', 'error', 'th'] | False |
Locator.locate | (self, requirement, prereleases=False) |
Find the most recent distribution which matches the given
requirement.
:param requirement: A requirement of the form 'foo (1.0)' or perhaps
'foo (>= 1.0, < 2.0, != 1.3)'
:param prereleases: If ``True``, allow pre-release versions
... |
Find the most recent distribution which matches the given
requirement. | def locate(self, requirement, prereleases=False):
"""
Find the most recent distribution which matches the given
requirement.
:param requirement: A requirement of the form 'foo (1.0)' or perhaps
'foo (>= 1.0, < 2.0, != 1.3)'
:param prereleases: If ``Tr... | [
"def",
"locate",
"(",
"self",
",",
"requirement",
",",
"prereleases",
"=",
"False",
")",
":",
"result",
"=",
"None",
"r",
"=",
"parse_requirement",
"(",
"requirement",
")",
"if",
"r",
"is",
"None",
":",
"# pragma: no cover",
"raise",
"DistlibException",
"(",... | [
350,
4
] | [
407,
21
] | python | en | ['en', 'error', 'th'] | False |
PyPIRPCLocator.__init__ | (self, url, **kwargs) |
Initialise an instance.
:param url: The URL to use for XML-RPC.
:param kwargs: Passed to the superclass constructor.
|
Initialise an instance. | def __init__(self, url, **kwargs):
"""
Initialise an instance.
:param url: The URL to use for XML-RPC.
:param kwargs: Passed to the superclass constructor.
"""
super(PyPIRPCLocator, self).__init__(**kwargs)
self.base_url = url
self.client = ServerProxy(ur... | [
"def",
"__init__",
"(",
"self",
",",
"url",
",",
"*",
"*",
"kwargs",
")",
":",
"super",
"(",
"PyPIRPCLocator",
",",
"self",
")",
".",
"__init__",
"(",
"*",
"*",
"kwargs",
")",
"self",
".",
"base_url",
"=",
"url",
"self",
".",
"client",
"=",
"Server... | [
415,
4
] | [
424,
51
] | python | en | ['en', 'error', 'th'] | False |
PyPIRPCLocator.get_distribution_names | (self) |
Return all the distribution names known to this locator.
|
Return all the distribution names known to this locator.
| def get_distribution_names(self):
"""
Return all the distribution names known to this locator.
"""
return set(self.client.list_packages()) | [
"def",
"get_distribution_names",
"(",
"self",
")",
":",
"return",
"set",
"(",
"self",
".",
"client",
".",
"list_packages",
"(",
")",
")"
] | [
426,
4
] | [
430,
47
] | python | en | ['en', 'error', 'th'] | False |
PyPIJSONLocator.get_distribution_names | (self) |
Return all the distribution names known to this locator.
|
Return all the distribution names known to this locator.
| def get_distribution_names(self):
"""
Return all the distribution names known to this locator.
"""
raise NotImplementedError('Not available from this locator') | [
"def",
"get_distribution_names",
"(",
"self",
")",
":",
"raise",
"NotImplementedError",
"(",
"'Not available from this locator'",
")"
] | [
467,
4
] | [
471,
68
] | python | en | ['en', 'error', 'th'] | False |
Page.__init__ | (self, data, url) |
Initialise an instance with the Unicode page contents and the URL they
came from.
|
Initialise an instance with the Unicode page contents and the URL they
came from.
| def __init__(self, data, url):
"""
Initialise an instance with the Unicode page contents and the URL they
came from.
"""
self.data = data
self.base_url = self.url = url
m = self._base.search(self.data)
if m:
self.base_url = m.group(1) | [
"def",
"__init__",
"(",
"self",
",",
"data",
",",
"url",
")",
":",
"self",
".",
"data",
"=",
"data",
"self",
".",
"base_url",
"=",
"self",
".",
"url",
"=",
"url",
"m",
"=",
"self",
".",
"_base",
".",
"search",
"(",
"self",
".",
"data",
")",
"if... | [
543,
4
] | [
552,
38
] | python | en | ['en', 'error', 'th'] | False |
Page.links | (self) |
Return the URLs of all the links on a page together with information
about their "rel" attribute, for determining which ones to treat as
downloads and which ones to queue for further scraping.
|
Return the URLs of all the links on a page together with information
about their "rel" attribute, for determining which ones to treat as
downloads and which ones to queue for further scraping.
| def links(self):
"""
Return the URLs of all the links on a page together with information
about their "rel" attribute, for determining which ones to treat as
downloads and which ones to queue for further scraping.
"""
def clean(url):
"Tidy up an URL."
... | [
"def",
"links",
"(",
"self",
")",
":",
"def",
"clean",
"(",
"url",
")",
":",
"\"Tidy up an URL.\"",
"scheme",
",",
"netloc",
",",
"path",
",",
"params",
",",
"query",
",",
"frag",
"=",
"urlparse",
"(",
"url",
")",
"return",
"urlunparse",
"(",
"(",
"s... | [
557,
4
] | [
582,
21
] | python | en | ['en', 'error', 'th'] | False |
SimpleScrapingLocator.__init__ | (self, url, timeout=None, num_workers=10, **kwargs) |
Initialise an instance.
:param url: The root URL to use for scraping.
:param timeout: The timeout, in seconds, to be applied to requests.
This defaults to ``None`` (no timeout specified).
:param num_workers: The number of worker threads you want to do I/O,
... |
Initialise an instance.
:param url: The root URL to use for scraping.
:param timeout: The timeout, in seconds, to be applied to requests.
This defaults to ``None`` (no timeout specified).
:param num_workers: The number of worker threads you want to do I/O,
... | def __init__(self, url, timeout=None, num_workers=10, **kwargs):
"""
Initialise an instance.
:param url: The root URL to use for scraping.
:param timeout: The timeout, in seconds, to be applied to requests.
This defaults to ``None`` (no timeout specified).
... | [
"def",
"__init__",
"(",
"self",
",",
"url",
",",
"timeout",
"=",
"None",
",",
"num_workers",
"=",
"10",
",",
"*",
"*",
"kwargs",
")",
":",
"super",
"(",
"SimpleScrapingLocator",
",",
"self",
")",
".",
"__init__",
"(",
"*",
"*",
"kwargs",
")",
"self",... | [
599,
4
] | [
624,
35
] | python | en | ['en', 'error', 'th'] | False |
SimpleScrapingLocator._prepare_threads | (self) |
Threads are created only when get_project is called, and terminate
before it returns. They are there primarily to parallelise I/O (i.e.
fetching web pages).
|
Threads are created only when get_project is called, and terminate
before it returns. They are there primarily to parallelise I/O (i.e.
fetching web pages).
| def _prepare_threads(self):
"""
Threads are created only when get_project is called, and terminate
before it returns. They are there primarily to parallelise I/O (i.e.
fetching web pages).
"""
self._threads = []
for i in range(self.num_workers):
t = th... | [
"def",
"_prepare_threads",
"(",
"self",
")",
":",
"self",
".",
"_threads",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"num_workers",
")",
":",
"t",
"=",
"threading",
".",
"Thread",
"(",
"target",
"=",
"self",
".",
"_fetch",
")",
"t... | [
626,
4
] | [
637,
35
] | python | en | ['en', 'error', 'th'] | False |
SimpleScrapingLocator._wait_threads | (self) |
Tell all the threads to terminate (by sending a sentinel value) and
wait for them to do so.
|
Tell all the threads to terminate (by sending a sentinel value) and
wait for them to do so.
| def _wait_threads(self):
"""
Tell all the threads to terminate (by sending a sentinel value) and
wait for them to do so.
"""
# Note that you need two loops, since you can't say which
# thread will get each sentinel
for t in self._threads:
self._to_fetc... | [
"def",
"_wait_threads",
"(",
"self",
")",
":",
"# Note that you need two loops, since you can't say which",
"# thread will get each sentinel",
"for",
"t",
"in",
"self",
".",
"_threads",
":",
"self",
".",
"_to_fetch",
".",
"put",
"(",
"None",
")",
"# sentinel",
"for",
... | [
639,
4
] | [
650,
26
] | python | en | ['en', 'error', 'th'] | False |
SimpleScrapingLocator._is_platform_dependent | (self, url) |
Does an URL refer to a platform-specific download?
|
Does an URL refer to a platform-specific download?
| def _is_platform_dependent(self, url):
"""
Does an URL refer to a platform-specific download?
"""
return self.platform_dependent.search(url) | [
"def",
"_is_platform_dependent",
"(",
"self",
",",
"url",
")",
":",
"return",
"self",
".",
"platform_dependent",
".",
"search",
"(",
"url",
")"
] | [
673,
4
] | [
677,
50
] | python | en | ['en', 'error', 'th'] | False |
SimpleScrapingLocator._process_download | (self, url) |
See if an URL is a suitable download for a project.
If it is, register information in the result dictionary (for
_get_project) about the specific version it's for.
Note that the return value isn't actually used other than as a boolean
value.
|
See if an URL is a suitable download for a project. | def _process_download(self, url):
"""
See if an URL is a suitable download for a project.
If it is, register information in the result dictionary (for
_get_project) about the specific version it's for.
Note that the return value isn't actually used other than as a boolean
... | [
"def",
"_process_download",
"(",
"self",
",",
"url",
")",
":",
"if",
"self",
".",
"platform_check",
"and",
"self",
".",
"_is_platform_dependent",
"(",
"url",
")",
":",
"info",
"=",
"None",
"else",
":",
"info",
"=",
"self",
".",
"convert_url_to_download_info"... | [
679,
4
] | [
697,
19
] | python | en | ['en', 'error', 'th'] | False |
SimpleScrapingLocator._should_queue | (self, link, referrer, rel) |
Determine whether a link URL from a referring page and with a
particular "rel" attribute should be queued for scraping.
|
Determine whether a link URL from a referring page and with a
particular "rel" attribute should be queued for scraping.
| def _should_queue(self, link, referrer, rel):
"""
Determine whether a link URL from a referring page and with a
particular "rel" attribute should be queued for scraping.
"""
scheme, netloc, path, _, _, _ = urlparse(link)
if path.endswith(self.source_extensions + self.bina... | [
"def",
"_should_queue",
"(",
"self",
",",
"link",
",",
"referrer",
",",
"rel",
")",
":",
"scheme",
",",
"netloc",
",",
"path",
",",
"_",
",",
"_",
",",
"_",
"=",
"urlparse",
"(",
"link",
")",
"if",
"path",
".",
"endswith",
"(",
"self",
".",
"sour... | [
699,
4
] | [
726,
21
] | python | en | ['en', 'error', 'th'] | False |
SimpleScrapingLocator._fetch | (self) |
Get a URL to fetch from the work queue, get the HTML page, examine its
links for download candidates and candidates for further scraping.
This is a handy method to run in a thread.
|
Get a URL to fetch from the work queue, get the HTML page, examine its
links for download candidates and candidates for further scraping. | def _fetch(self):
"""
Get a URL to fetch from the work queue, get the HTML page, examine its
links for download candidates and candidates for further scraping.
This is a handy method to run in a thread.
"""
while True:
url = self._to_fetch.get()
t... | [
"def",
"_fetch",
"(",
"self",
")",
":",
"while",
"True",
":",
"url",
"=",
"self",
".",
"_to_fetch",
".",
"get",
"(",
")",
"try",
":",
"if",
"url",
":",
"page",
"=",
"self",
".",
"get_page",
"(",
"url",
")",
"if",
"page",
"is",
"None",
":",
"# e... | [
728,
4
] | [
759,
21
] | python | en | ['en', 'error', 'th'] | False |
SimpleScrapingLocator.get_page | (self, url) |
Get the HTML for an URL, possibly from an in-memory cache.
XXX TODO Note: this cache is never actually cleared. It's assumed that
the data won't get stale over the lifetime of a locator instance (not
necessarily true for the default_locator).
|
Get the HTML for an URL, possibly from an in-memory cache. | def get_page(self, url):
"""
Get the HTML for an URL, possibly from an in-memory cache.
XXX TODO Note: this cache is never actually cleared. It's assumed that
the data won't get stale over the lifetime of a locator instance (not
necessarily true for the default_locator).
... | [
"def",
"get_page",
"(",
"self",
",",
"url",
")",
":",
"# http://peak.telecommunity.com/DevCenter/EasyInstall#package-index-api",
"scheme",
",",
"netloc",
",",
"path",
",",
"_",
",",
"_",
",",
"_",
"=",
"urlparse",
"(",
"url",
")",
"if",
"scheme",
"==",
"'file'... | [
761,
4
] | [
818,
21
] | python | en | ['en', 'error', 'th'] | False |
SimpleScrapingLocator.get_distribution_names | (self) |
Return all the distribution names known to this locator.
|
Return all the distribution names known to this locator.
| def get_distribution_names(self):
"""
Return all the distribution names known to this locator.
"""
result = set()
page = self.get_page(self.base_url)
if not page:
raise DistlibException('Unable to get %s' % self.base_url)
for match in self._distname_re... | [
"def",
"get_distribution_names",
"(",
"self",
")",
":",
"result",
"=",
"set",
"(",
")",
"page",
"=",
"self",
".",
"get_page",
"(",
"self",
".",
"base_url",
")",
"if",
"not",
"page",
":",
"raise",
"DistlibException",
"(",
"'Unable to get %s'",
"%",
"self",
... | [
822,
4
] | [
832,
21
] | python | en | ['en', 'error', 'th'] | False |
DirectoryLocator.__init__ | (self, path, **kwargs) |
Initialise an instance.
:param path: The root of the directory tree to search.
:param kwargs: Passed to the superclass constructor,
except for:
* recursive - if True (the default), subdirectories are
recursed into. If False,... |
Initialise an instance.
:param path: The root of the directory tree to search.
:param kwargs: Passed to the superclass constructor,
except for:
* recursive - if True (the default), subdirectories are
recursed into. If False,... | def __init__(self, path, **kwargs):
"""
Initialise an instance.
:param path: The root of the directory tree to search.
:param kwargs: Passed to the superclass constructor,
except for:
* recursive - if True (the default), subdirectories are
... | [
"def",
"__init__",
"(",
"self",
",",
"path",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"recursive",
"=",
"kwargs",
".",
"pop",
"(",
"'recursive'",
",",
"True",
")",
"super",
"(",
"DirectoryLocator",
",",
"self",
")",
".",
"__init__",
"(",
"*",
... | [
839,
4
] | [
854,
28
] | python | en | ['en', 'error', 'th'] | False |
DirectoryLocator.should_include | (self, filename, parent) |
Should a filename be considered as a candidate for a distribution
archive? As well as the filename, the directory which contains it
is provided, though not used by the current implementation.
|
Should a filename be considered as a candidate for a distribution
archive? As well as the filename, the directory which contains it
is provided, though not used by the current implementation.
| def should_include(self, filename, parent):
"""
Should a filename be considered as a candidate for a distribution
archive? As well as the filename, the directory which contains it
is provided, though not used by the current implementation.
"""
return filename.endswith(sel... | [
"def",
"should_include",
"(",
"self",
",",
"filename",
",",
"parent",
")",
":",
"return",
"filename",
".",
"endswith",
"(",
"self",
".",
"downloadable_extensions",
")"
] | [
856,
4
] | [
862,
62
] | python | en | ['en', 'error', 'th'] | False |
DirectoryLocator.get_distribution_names | (self) |
Return all the distribution names known to this locator.
|
Return all the distribution names known to this locator.
| def get_distribution_names(self):
"""
Return all the distribution names known to this locator.
"""
result = set()
for root, dirs, files in os.walk(self.base_dir):
for fn in files:
if self.should_include(fn, root):
fn = os.path.join(... | [
"def",
"get_distribution_names",
"(",
"self",
")",
":",
"result",
"=",
"set",
"(",
")",
"for",
"root",
",",
"dirs",
",",
"files",
"in",
"os",
".",
"walk",
"(",
"self",
".",
"base_dir",
")",
":",
"for",
"fn",
"in",
"files",
":",
"if",
"self",
".",
... | [
880,
4
] | [
897,
21
] | python | en | ['en', 'error', 'th'] | False |
JSONLocator.get_distribution_names | (self) |
Return all the distribution names known to this locator.
|
Return all the distribution names known to this locator.
| def get_distribution_names(self):
"""
Return all the distribution names known to this locator.
"""
raise NotImplementedError('Not available from this locator') | [
"def",
"get_distribution_names",
"(",
"self",
")",
":",
"raise",
"NotImplementedError",
"(",
"'Not available from this locator'",
")"
] | [
906,
4
] | [
910,
68
] | python | en | ['en', 'error', 'th'] | False |
DistPathLocator.__init__ | (self, distpath, **kwargs) |
Initialise an instance.
:param distpath: A :class:`DistributionPath` instance to search.
|
Initialise an instance. | def __init__(self, distpath, **kwargs):
"""
Initialise an instance.
:param distpath: A :class:`DistributionPath` instance to search.
"""
super(DistPathLocator, self).__init__(**kwargs)
assert isinstance(distpath, DistributionPath)
self.distpath = distpath | [
"def",
"__init__",
"(",
"self",
",",
"distpath",
",",
"*",
"*",
"kwargs",
")",
":",
"super",
"(",
"DistPathLocator",
",",
"self",
")",
".",
"__init__",
"(",
"*",
"*",
"kwargs",
")",
"assert",
"isinstance",
"(",
"distpath",
",",
"DistributionPath",
")",
... | [
942,
4
] | [
950,
32
] | 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.