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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
DistributionPath.distinfo_dirname | (cls, name, version) |
The *name* and *version* parameters are converted into their
filename-escaped form, i.e. any ``'-'`` characters are replaced
with ``'_'`` other than the one in ``'dist-info'`` and the one
separating the name from the version number.
:parameter name: is converted to a standard d... |
The *name* and *version* parameters are converted into their
filename-escaped form, i.e. any ``'-'`` characters are replaced
with ``'_'`` other than the one in ``'dist-info'`` and the one
separating the name from the version number. | def distinfo_dirname(cls, name, version):
"""
The *name* and *version* parameters are converted into their
filename-escaped form, i.e. any ``'-'`` characters are replaced
with ``'_'`` other than the one in ``'dist-info'`` and the one
separating the name from the version number.
... | [
"def",
"distinfo_dirname",
"(",
"cls",
",",
"name",
",",
"version",
")",
":",
"name",
"=",
"name",
".",
"replace",
"(",
"'-'",
",",
"'_'",
")",
"return",
"'-'",
".",
"join",
"(",
"[",
"name",
",",
"version",
"]",
")",
"+",
"DISTINFO_EXT"
] | [
178,
4
] | [
197,
55
] | python | en | ['en', 'error', 'th'] | False |
DistributionPath.get_distributions | (self) |
Provides an iterator that looks for distributions and returns
:class:`InstalledDistribution` or
:class:`EggInfoDistribution` instances for each one of them.
:rtype: iterator of :class:`InstalledDistribution` and
:class:`EggInfoDistribution` instances
|
Provides an iterator that looks for distributions and returns
:class:`InstalledDistribution` or
:class:`EggInfoDistribution` instances for each one of them. | def get_distributions(self):
"""
Provides an iterator that looks for distributions and returns
:class:`InstalledDistribution` or
:class:`EggInfoDistribution` instances for each one of them.
:rtype: iterator of :class:`InstalledDistribution` and
:class:`EggInfoDis... | [
"def",
"get_distributions",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_cache_enabled",
":",
"for",
"dist",
"in",
"self",
".",
"_yield_distributions",
"(",
")",
":",
"yield",
"dist",
"else",
":",
"self",
".",
"_generate_cache",
"(",
")",
"for",
"d... | [
199,
4
] | [
219,
30
] | python | en | ['en', 'error', 'th'] | False |
DistributionPath.get_distribution | (self, name) |
Looks for a named distribution on the path.
This function only returns the first result found, as no more than one
value is expected. If nothing is found, ``None`` is returned.
:rtype: :class:`InstalledDistribution`, :class:`EggInfoDistribution`
or ``None``
|
Looks for a named distribution on the path. | def get_distribution(self, name):
"""
Looks for a named distribution on the path.
This function only returns the first result found, as no more than one
value is expected. If nothing is found, ``None`` is returned.
:rtype: :class:`InstalledDistribution`, :class:`EggInfoDistribu... | [
"def",
"get_distribution",
"(",
"self",
",",
"name",
")",
":",
"result",
"=",
"None",
"name",
"=",
"name",
".",
"lower",
"(",
")",
"if",
"not",
"self",
".",
"_cache_enabled",
":",
"for",
"dist",
"in",
"self",
".",
"_yield_distributions",
"(",
")",
":",... | [
221,
4
] | [
245,
21
] | python | en | ['en', 'error', 'th'] | False |
DistributionPath.provides_distribution | (self, name, version=None) |
Iterates over all distributions to find which distributions provide *name*.
If a *version* is provided, it will be used to filter the results.
This function only returns the first result found, since no more than
one values are expected. If the directory is not found, returns ``None``.... |
Iterates over all distributions to find which distributions provide *name*.
If a *version* is provided, it will be used to filter the results. | def provides_distribution(self, name, version=None):
"""
Iterates over all distributions to find which distributions provide *name*.
If a *version* is provided, it will be used to filter the results.
This function only returns the first result found, since no more than
one value... | [
"def",
"provides_distribution",
"(",
"self",
",",
"name",
",",
"version",
"=",
"None",
")",
":",
"matcher",
"=",
"None",
"if",
"version",
"is",
"not",
"None",
":",
"try",
":",
"matcher",
"=",
"self",
".",
"_scheme",
".",
"matcher",
"(",
"'%s (%s)'",
"%... | [
247,
4
] | [
286,
33
] | python | en | ['en', 'error', 'th'] | False |
DistributionPath.get_file_path | (self, name, relative_path) |
Return the path to a resource file.
|
Return the path to a resource file.
| def get_file_path(self, name, relative_path):
"""
Return the path to a resource file.
"""
dist = self.get_distribution(name)
if dist is None:
raise LookupError('no distribution named %r found' % name)
return dist.get_resource_path(relative_path) | [
"def",
"get_file_path",
"(",
"self",
",",
"name",
",",
"relative_path",
")",
":",
"dist",
"=",
"self",
".",
"get_distribution",
"(",
"name",
")",
"if",
"dist",
"is",
"None",
":",
"raise",
"LookupError",
"(",
"'no distribution named %r found'",
"%",
"name",
"... | [
288,
4
] | [
295,
52
] | python | en | ['en', 'error', 'th'] | False |
DistributionPath.get_exported_entries | (self, category, name=None) |
Return all of the exported entries in a particular category.
:param category: The category to search for entries.
:param name: If specified, only entries with that name are returned.
|
Return all of the exported entries in a particular category. | def get_exported_entries(self, category, name=None):
"""
Return all of the exported entries in a particular category.
:param category: The category to search for entries.
:param name: If specified, only entries with that name are returned.
"""
for dist in self.get_distri... | [
"def",
"get_exported_entries",
"(",
"self",
",",
"category",
",",
"name",
"=",
"None",
")",
":",
"for",
"dist",
"in",
"self",
".",
"get_distributions",
"(",
")",
":",
"r",
"=",
"dist",
".",
"exports",
"if",
"category",
"in",
"r",
":",
"d",
"=",
"r",
... | [
297,
4
] | [
313,
31
] | python | en | ['en', 'error', 'th'] | False |
Distribution.__init__ | (self, metadata) |
Initialise an instance.
:param metadata: The instance of :class:`Metadata` describing this
distribution.
|
Initialise an instance.
:param metadata: The instance of :class:`Metadata` describing this
distribution.
| def __init__(self, metadata):
"""
Initialise an instance.
:param metadata: The instance of :class:`Metadata` describing this
distribution.
"""
self.metadata = metadata
self.name = metadata.name
self.key = self.name.lower() # for case-insensitive compari... | [
"def",
"__init__",
"(",
"self",
",",
"metadata",
")",
":",
"self",
".",
"metadata",
"=",
"metadata",
"self",
".",
"name",
"=",
"metadata",
".",
"name",
"self",
".",
"key",
"=",
"self",
".",
"name",
".",
"lower",
"(",
")",
"# for case-insensitive comparis... | [
334,
4
] | [
349,
25
] | python | en | ['en', 'error', 'th'] | False |
Distribution.source_url | (self) |
The source archive download URL for this distribution.
|
The source archive download URL for this distribution.
| def source_url(self):
"""
The source archive download URL for this distribution.
"""
return self.metadata.source_url | [
"def",
"source_url",
"(",
"self",
")",
":",
"return",
"self",
".",
"metadata",
".",
"source_url"
] | [
352,
4
] | [
356,
39
] | python | en | ['en', 'error', 'th'] | False |
Distribution.name_and_version | (self) |
A utility property which displays the name and version in parentheses.
|
A utility property which displays the name and version in parentheses.
| def name_and_version(self):
"""
A utility property which displays the name and version in parentheses.
"""
return '%s (%s)' % (self.name, self.version) | [
"def",
"name_and_version",
"(",
"self",
")",
":",
"return",
"'%s (%s)'",
"%",
"(",
"self",
".",
"name",
",",
"self",
".",
"version",
")"
] | [
361,
4
] | [
365,
52
] | python | en | ['en', 'error', 'th'] | False |
Distribution.provides | (self) |
A set of distribution names and versions provided by this distribution.
:return: A set of "name (version)" strings.
|
A set of distribution names and versions provided by this distribution.
:return: A set of "name (version)" strings.
| def provides(self):
"""
A set of distribution names and versions provided by this distribution.
:return: A set of "name (version)" strings.
"""
plist = self.metadata.provides
s = '%s (%s)' % (self.name, self.version)
if s not in plist:
plist.append(s)
... | [
"def",
"provides",
"(",
"self",
")",
":",
"plist",
"=",
"self",
".",
"metadata",
".",
"provides",
"s",
"=",
"'%s (%s)'",
"%",
"(",
"self",
".",
"name",
",",
"self",
".",
"version",
")",
"if",
"s",
"not",
"in",
"plist",
":",
"plist",
".",
"append",
... | [
368,
4
] | [
377,
20
] | python | en | ['en', 'error', 'th'] | False |
Distribution.matches_requirement | (self, req) |
Say if this instance matches (fulfills) a requirement.
:param req: The requirement to match.
:rtype req: str
:return: True if it matches, else False.
|
Say if this instance matches (fulfills) a requirement.
:param req: The requirement to match.
:rtype req: str
:return: True if it matches, else False.
| def matches_requirement(self, req):
"""
Say if this instance matches (fulfills) a requirement.
:param req: The requirement to match.
:rtype req: str
:return: True if it matches, else False.
"""
# Requirement may contain extras - parse to lose those
# from ... | [
"def",
"matches_requirement",
"(",
"self",
",",
"req",
")",
":",
"# Requirement may contain extras - parse to lose those",
"# from what's passed to the matcher",
"r",
"=",
"parse_requirement",
"(",
"req",
")",
"scheme",
"=",
"get_scheme",
"(",
"self",
".",
"metadata",
"... | [
406,
4
] | [
438,
21
] | python | en | ['en', 'error', 'th'] | False |
Distribution.__repr__ | (self) |
Return a textual representation of this instance,
|
Return a textual representation of this instance,
| def __repr__(self):
"""
Return a textual representation of this instance,
"""
if self.source_url:
suffix = ' [%s]' % self.source_url
else:
suffix = ''
return '<Distribution %s (%s)%s>' % (self.name, self.version, suffix) | [
"def",
"__repr__",
"(",
"self",
")",
":",
"if",
"self",
".",
"source_url",
":",
"suffix",
"=",
"' [%s]'",
"%",
"self",
".",
"source_url",
"else",
":",
"suffix",
"=",
"''",
"return",
"'<Distribution %s (%s)%s>'",
"%",
"(",
"self",
".",
"name",
",",
"self"... | [
440,
4
] | [
448,
77
] | python | en | ['en', 'error', 'th'] | False |
Distribution.__eq__ | (self, other) |
See if this distribution is the same as another.
:param other: The distribution to compare with. To be equal to one
another. distributions must have the same type, name,
version and source_url.
:return: True if it is the same, else False.
|
See if this distribution is the same as another.
:param other: The distribution to compare with. To be equal to one
another. distributions must have the same type, name,
version and source_url.
:return: True if it is the same, else False.
| def __eq__(self, other):
"""
See if this distribution is the same as another.
:param other: The distribution to compare with. To be equal to one
another. distributions must have the same type, name,
version and source_url.
:return: True if it i... | [
"def",
"__eq__",
"(",
"self",
",",
"other",
")",
":",
"if",
"type",
"(",
"other",
")",
"is",
"not",
"type",
"(",
"self",
")",
":",
"result",
"=",
"False",
"else",
":",
"result",
"=",
"(",
"self",
".",
"name",
"==",
"other",
".",
"name",
"and",
... | [
450,
4
] | [
464,
21
] | python | en | ['en', 'error', 'th'] | False |
Distribution.__hash__ | (self) |
Compute hash in a way which matches the equality test.
|
Compute hash in a way which matches the equality test.
| def __hash__(self):
"""
Compute hash in a way which matches the equality test.
"""
return hash(self.name) + hash(self.version) + hash(self.source_url) | [
"def",
"__hash__",
"(",
"self",
")",
":",
"return",
"hash",
"(",
"self",
".",
"name",
")",
"+",
"hash",
"(",
"self",
".",
"version",
")",
"+",
"hash",
"(",
"self",
".",
"source_url",
")"
] | [
466,
4
] | [
470,
75
] | python | en | ['en', 'error', 'th'] | False |
BaseInstalledDistribution.__init__ | (self, metadata, path, env=None) |
Initialise an instance.
:param metadata: An instance of :class:`Metadata` which describes the
distribution. This will normally have been initialised
from a metadata file in the ``path``.
:param path: The path of the ``.dist-info`` or ``.egg-... |
Initialise an instance.
:param metadata: An instance of :class:`Metadata` which describes the
distribution. This will normally have been initialised
from a metadata file in the ``path``.
:param path: The path of the ``.dist-info`` or ``.egg-... | def __init__(self, metadata, path, env=None):
"""
Initialise an instance.
:param metadata: An instance of :class:`Metadata` which describes the
distribution. This will normally have been initialised
from a metadata file in the ``path``.
:... | [
"def",
"__init__",
"(",
"self",
",",
"metadata",
",",
"path",
",",
"env",
"=",
"None",
")",
":",
"super",
"(",
"BaseInstalledDistribution",
",",
"self",
")",
".",
"__init__",
"(",
"metadata",
")",
"self",
".",
"path",
"=",
"path",
"self",
".",
"dist_pa... | [
481,
4
] | [
494,
28
] | python | en | ['en', 'error', 'th'] | False |
BaseInstalledDistribution.get_hash | (self, data, hasher=None) |
Get the hash of some data, using a particular hash algorithm, if
specified.
:param data: The data to be hashed.
:type data: bytes
:param hasher: The name of a hash implementation, supported by hashlib,
or ``None``. Examples of valid values are ``'sha1'``,... |
Get the hash of some data, using a particular hash algorithm, if
specified. | def get_hash(self, data, hasher=None):
"""
Get the hash of some data, using a particular hash algorithm, if
specified.
:param data: The data to be hashed.
:type data: bytes
:param hasher: The name of a hash implementation, supported by hashlib,
or ... | [
"def",
"get_hash",
"(",
"self",
",",
"data",
",",
"hasher",
"=",
"None",
")",
":",
"if",
"hasher",
"is",
"None",
":",
"hasher",
"=",
"self",
".",
"hasher",
"if",
"hasher",
"is",
"None",
":",
"hasher",
"=",
"hashlib",
".",
"md5",
"prefix",
"=",
"''"... | [
496,
4
] | [
525,
40
] | python | en | ['en', 'error', 'th'] | False |
InstalledDistribution._get_records | (self) |
Get the list of installed files for the distribution
:return: A list of tuples of path, hash and size. Note that hash and
size might be ``None`` for some entries. The path is exactly
as stored in the file (which is as in PEP 376).
|
Get the list of installed files for the distribution
:return: A list of tuples of path, hash and size. Note that hash and
size might be ``None`` for some entries. The path is exactly
as stored in the file (which is as in PEP 376).
| def _get_records(self):
"""
Get the list of installed files for the distribution
:return: A list of tuples of path, hash and size. Note that hash and
size might be ``None`` for some entries. The path is exactly
as stored in the file (which is as in PEP 376).
... | [
"def",
"_get_records",
"(",
"self",
")",
":",
"results",
"=",
"[",
"]",
"r",
"=",
"self",
".",
"get_distinfo_resource",
"(",
"'RECORD'",
")",
"with",
"contextlib",
".",
"closing",
"(",
"r",
".",
"as_stream",
"(",
")",
")",
"as",
"stream",
":",
"with",
... | [
579,
4
] | [
600,
22
] | python | en | ['en', 'error', 'th'] | False |
InstalledDistribution.exports | (self) |
Return the information exported by this distribution.
:return: A dictionary of exports, mapping an export category to a dict
of :class:`ExportEntry` instances describing the individual
export entries, and keyed by name.
|
Return the information exported by this distribution.
:return: A dictionary of exports, mapping an export category to a dict
of :class:`ExportEntry` instances describing the individual
export entries, and keyed by name.
| def exports(self):
"""
Return the information exported by this distribution.
:return: A dictionary of exports, mapping an export category to a dict
of :class:`ExportEntry` instances describing the individual
export entries, and keyed by name.
"""
... | [
"def",
"exports",
"(",
"self",
")",
":",
"result",
"=",
"{",
"}",
"r",
"=",
"self",
".",
"get_distinfo_resource",
"(",
"EXPORTS_FILENAME",
")",
"if",
"r",
":",
"result",
"=",
"self",
".",
"read_exports",
"(",
")",
"return",
"result"
] | [
603,
4
] | [
614,
21
] | python | en | ['en', 'error', 'th'] | False |
InstalledDistribution.read_exports | (self) |
Read exports data from a file in .ini format.
:return: A dictionary of exports, mapping an export category to a list
of :class:`ExportEntry` instances describing the individual
export entries.
|
Read exports data from a file in .ini format. | def read_exports(self):
"""
Read exports data from a file in .ini format.
:return: A dictionary of exports, mapping an export category to a list
of :class:`ExportEntry` instances describing the individual
export entries.
"""
result = {}
... | [
"def",
"read_exports",
"(",
"self",
")",
":",
"result",
"=",
"{",
"}",
"r",
"=",
"self",
".",
"get_distinfo_resource",
"(",
"EXPORTS_FILENAME",
")",
"if",
"r",
":",
"with",
"contextlib",
".",
"closing",
"(",
"r",
".",
"as_stream",
"(",
")",
")",
"as",
... | [
616,
4
] | [
629,
21
] | python | en | ['en', 'error', 'th'] | False |
InstalledDistribution.write_exports | (self, exports) |
Write a dictionary of exports to a file in .ini format.
:param exports: A dictionary of exports, mapping an export category to
a list of :class:`ExportEntry` instances describing the
individual export entries.
|
Write a dictionary of exports to a file in .ini format.
:param exports: A dictionary of exports, mapping an export category to
a list of :class:`ExportEntry` instances describing the
individual export entries.
| def write_exports(self, exports):
"""
Write a dictionary of exports to a file in .ini format.
:param exports: A dictionary of exports, mapping an export category to
a list of :class:`ExportEntry` instances describing the
individual export entries.
... | [
"def",
"write_exports",
"(",
"self",
",",
"exports",
")",
":",
"rf",
"=",
"self",
".",
"get_distinfo_file",
"(",
"EXPORTS_FILENAME",
")",
"with",
"open",
"(",
"rf",
",",
"'w'",
")",
"as",
"f",
":",
"write_exports",
"(",
"exports",
",",
"f",
")"
] | [
631,
4
] | [
640,
37
] | python | en | ['en', 'error', 'th'] | False |
InstalledDistribution.get_resource_path | (self, relative_path) |
NOTE: This API may change in the future.
Return the absolute path to a resource file with the given relative
path.
:param relative_path: The path, relative to .dist-info, of the resource
of interest.
:return: The absolute path where the resource i... |
NOTE: This API may change in the future. | def get_resource_path(self, relative_path):
"""
NOTE: This API may change in the future.
Return the absolute path to a resource file with the given relative
path.
:param relative_path: The path, relative to .dist-info, of the resource
of interest.
... | [
"def",
"get_resource_path",
"(",
"self",
",",
"relative_path",
")",
":",
"r",
"=",
"self",
".",
"get_distinfo_resource",
"(",
"'RESOURCES'",
")",
"with",
"contextlib",
".",
"closing",
"(",
"r",
".",
"as_stream",
"(",
")",
")",
"as",
"stream",
":",
"with",
... | [
642,
4
] | [
660,
54
] | python | en | ['en', 'error', 'th'] | False |
InstalledDistribution.list_installed_files | (self) |
Iterates over the ``RECORD`` entries and returns a tuple
``(path, hash, size)`` for each line.
:returns: iterator of (path, hash, size)
|
Iterates over the ``RECORD`` entries and returns a tuple
``(path, hash, size)`` for each line. | def list_installed_files(self):
"""
Iterates over the ``RECORD`` entries and returns a tuple
``(path, hash, size)`` for each line.
:returns: iterator of (path, hash, size)
"""
for result in self._get_records():
yield result | [
"def",
"list_installed_files",
"(",
"self",
")",
":",
"for",
"result",
"in",
"self",
".",
"_get_records",
"(",
")",
":",
"yield",
"result"
] | [
662,
4
] | [
670,
24
] | python | en | ['en', 'error', 'th'] | False |
InstalledDistribution.write_installed_files | (self, paths, prefix, dry_run=False) |
Writes the ``RECORD`` file, using the ``paths`` iterable passed in. Any
existing ``RECORD`` file is silently overwritten.
prefix is used to determine when to write absolute paths.
|
Writes the ``RECORD`` file, using the ``paths`` iterable passed in. Any
existing ``RECORD`` file is silently overwritten. | def write_installed_files(self, paths, prefix, dry_run=False):
"""
Writes the ``RECORD`` file, using the ``paths`` iterable passed in. Any
existing ``RECORD`` file is silently overwritten.
prefix is used to determine when to write absolute paths.
"""
prefix = os.path.joi... | [
"def",
"write_installed_files",
"(",
"self",
",",
"paths",
",",
"prefix",
",",
"dry_run",
"=",
"False",
")",
":",
"prefix",
"=",
"os",
".",
"path",
".",
"join",
"(",
"prefix",
",",
"''",
")",
"base",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"se... | [
672,
4
] | [
705,
26
] | python | en | ['en', 'error', 'th'] | False |
InstalledDistribution.check_installed_files | (self) |
Checks that the hashes and sizes of the files in ``RECORD`` are
matched by the files themselves. Returns a (possibly empty) list of
mismatches. Each entry in the mismatch list will be a tuple consisting
of the path, 'exists', 'size' or 'hash' according to what didn't match
(exis... |
Checks that the hashes and sizes of the files in ``RECORD`` are
matched by the files themselves. Returns a (possibly empty) list of
mismatches. Each entry in the mismatch list will be a tuple consisting
of the path, 'exists', 'size' or 'hash' according to what didn't match
(exis... | def check_installed_files(self):
"""
Checks that the hashes and sizes of the files in ``RECORD`` are
matched by the files themselves. Returns a (possibly empty) list of
mismatches. Each entry in the mismatch list will be a tuple consisting
of the path, 'exists', 'size' or 'hash' ... | [
"def",
"check_installed_files",
"(",
"self",
")",
":",
"mismatches",
"=",
"[",
"]",
"base",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"self",
".",
"path",
")",
"record_path",
"=",
"self",
".",
"get_distinfo_file",
"(",
"'RECORD'",
")",
"for",
"path",
... | [
707,
4
] | [
740,
25
] | python | en | ['en', 'error', 'th'] | False |
InstalledDistribution.shared_locations | (self) |
A dictionary of shared locations whose keys are in the set 'prefix',
'purelib', 'platlib', 'scripts', 'headers', 'data' and 'namespace'.
The corresponding value is the absolute path of that category for
this distribution, and takes into account any paths selected by the
user at ... |
A dictionary of shared locations whose keys are in the set 'prefix',
'purelib', 'platlib', 'scripts', 'headers', 'data' and 'namespace'.
The corresponding value is the absolute path of that category for
this distribution, and takes into account any paths selected by the
user at ... | def shared_locations(self):
"""
A dictionary of shared locations whose keys are in the set 'prefix',
'purelib', 'platlib', 'scripts', 'headers', 'data' and 'namespace'.
The corresponding value is the absolute path of that category for
this distribution, and takes into account any... | [
"def",
"shared_locations",
"(",
"self",
")",
":",
"result",
"=",
"{",
"}",
"shared_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"path",
",",
"'SHARED'",
")",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"shared_path",
")",
":",
"wi... | [
743,
4
] | [
767,
21
] | python | en | ['en', 'error', 'th'] | False |
InstalledDistribution.write_shared_locations | (self, paths, dry_run=False) |
Write shared location information to the SHARED file in .dist-info.
:param paths: A dictionary as described in the documentation for
:meth:`shared_locations`.
:param dry_run: If True, the action is logged but no file is actually
written.
:return: The path... |
Write shared location information to the SHARED file in .dist-info.
:param paths: A dictionary as described in the documentation for
:meth:`shared_locations`.
:param dry_run: If True, the action is logged but no file is actually
written.
:return: The path... | def write_shared_locations(self, paths, dry_run=False):
"""
Write shared location information to the SHARED file in .dist-info.
:param paths: A dictionary as described in the documentation for
:meth:`shared_locations`.
:param dry_run: If True, the action is logged but no file is ... | [
"def",
"write_shared_locations",
"(",
"self",
",",
"paths",
",",
"dry_run",
"=",
"False",
")",
":",
"shared_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"path",
",",
"'SHARED'",
")",
"logger",
".",
"info",
"(",
"'creating %s'",
",",
"s... | [
769,
4
] | [
792,
26
] | python | en | ['en', 'error', 'th'] | False |
InstalledDistribution.get_distinfo_file | (self, path) |
Returns a path located under the ``.dist-info`` directory. Returns a
string representing the path.
:parameter path: a ``'/'``-separated path relative to the
``.dist-info`` directory or an absolute path;
If *path* is an absolute path and doesn't... |
Returns a path located under the ``.dist-info`` directory. Returns a
string representing the path. | def get_distinfo_file(self, path):
"""
Returns a path located under the ``.dist-info`` directory. Returns a
string representing the path.
:parameter path: a ``'/'``-separated path relative to the
``.dist-info`` directory or an absolute path;
... | [
"def",
"get_distinfo_file",
"(",
"self",
",",
"path",
")",
":",
"# Check if it is an absolute path # XXX use relpath, add tests",
"if",
"path",
".",
"find",
"(",
"os",
".",
"sep",
")",
">=",
"0",
":",
"# it's an absolute path?",
"distinfo_dirname",
",",
"path",
"="... | [
803,
4
] | [
830,
44
] | python | en | ['en', 'error', 'th'] | False |
InstalledDistribution.list_distinfo_files | (self) |
Iterates over the ``RECORD`` entries and returns paths for each line if
the path is pointing to a file located in the ``.dist-info`` directory
or one of its subdirectories.
:returns: iterator of paths
|
Iterates over the ``RECORD`` entries and returns paths for each line if
the path is pointing to a file located in the ``.dist-info`` directory
or one of its subdirectories. | def list_distinfo_files(self):
"""
Iterates over the ``RECORD`` entries and returns paths for each line if
the path is pointing to a file located in the ``.dist-info`` directory
or one of its subdirectories.
:returns: iterator of paths
"""
base = os.path.dirname(... | [
"def",
"list_distinfo_files",
"(",
"self",
")",
":",
"base",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"self",
".",
"path",
")",
"for",
"path",
",",
"checksum",
",",
"size",
"in",
"self",
".",
"_get_records",
"(",
")",
":",
"# XXX add separator or use... | [
832,
4
] | [
846,
26
] | python | en | ['en', 'error', 'th'] | False |
EggInfoDistribution.check_installed_files | (self) |
Checks that the hashes and sizes of the files in ``RECORD`` are
matched by the files themselves. Returns a (possibly empty) list of
mismatches. Each entry in the mismatch list will be a tuple consisting
of the path, 'exists', 'size' or 'hash' according to what didn't match
(exis... |
Checks that the hashes and sizes of the files in ``RECORD`` are
matched by the files themselves. Returns a (possibly empty) list of
mismatches. Each entry in the mismatch list will be a tuple consisting
of the path, 'exists', 'size' or 'hash' according to what didn't match
(exis... | def check_installed_files(self):
"""
Checks that the hashes and sizes of the files in ``RECORD`` are
matched by the files themselves. Returns a (possibly empty) list of
mismatches. Each entry in the mismatch list will be a tuple consisting
of the path, 'exists', 'size' or 'hash' ... | [
"def",
"check_installed_files",
"(",
"self",
")",
":",
"mismatches",
"=",
"[",
"]",
"record_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"path",
",",
"'installed-files.txt'",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"record_path... | [
983,
4
] | [
1000,
25
] | python | en | ['en', 'error', 'th'] | False |
EggInfoDistribution.list_installed_files | (self) |
Iterates over the ``installed-files.txt`` entries and returns a tuple
``(path, hash, size)`` for each line.
:returns: a list of (path, hash, size)
|
Iterates over the ``installed-files.txt`` entries and returns a tuple
``(path, hash, size)`` for each line. | def list_installed_files(self):
"""
Iterates over the ``installed-files.txt`` entries and returns a tuple
``(path, hash, size)`` for each line.
:returns: a list of (path, hash, size)
"""
def _md5(path):
f = open(path, 'rb')
try:
c... | [
"def",
"list_installed_files",
"(",
"self",
")",
":",
"def",
"_md5",
"(",
"path",
")",
":",
"f",
"=",
"open",
"(",
"path",
",",
"'rb'",
")",
"try",
":",
"content",
"=",
"f",
".",
"read",
"(",
")",
"finally",
":",
"f",
".",
"close",
"(",
")",
"r... | [
1002,
4
] | [
1038,
21
] | python | en | ['en', 'error', 'th'] | False |
EggInfoDistribution.list_distinfo_files | (self, absolute=False) |
Iterates over the ``installed-files.txt`` entries and returns paths for
each line if the path is pointing to a file located in the
``.egg-info`` directory or one of its subdirectories.
:parameter absolute: If *absolute* is ``True``, each returned path is
trans... |
Iterates over the ``installed-files.txt`` entries and returns paths for
each line if the path is pointing to a file located in the
``.egg-info`` directory or one of its subdirectories. | def list_distinfo_files(self, absolute=False):
"""
Iterates over the ``installed-files.txt`` entries and returns paths for
each line if the path is pointing to a file located in the
``.egg-info`` directory or one of its subdirectories.
:parameter absolute: If *absolute* is ``Tru... | [
"def",
"list_distinfo_files",
"(",
"self",
",",
"absolute",
"=",
"False",
")",
":",
"record_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"path",
",",
"'installed-files.txt'",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"record_path... | [
1040,
4
] | [
1067,
42
] | python | en | ['en', 'error', 'th'] | False |
DependencyGraph.add_distribution | (self, distribution) | Add the *distribution* to the graph.
:type distribution: :class:`distutils2.database.InstalledDistribution`
or :class:`distutils2.database.EggInfoDistribution`
| Add the *distribution* to the graph. | def add_distribution(self, distribution):
"""Add the *distribution* to the graph.
:type distribution: :class:`distutils2.database.InstalledDistribution`
or :class:`distutils2.database.EggInfoDistribution`
"""
self.adjacency_list[distribution] = []
sel... | [
"def",
"add_distribution",
"(",
"self",
",",
"distribution",
")",
":",
"self",
".",
"adjacency_list",
"[",
"distribution",
"]",
"=",
"[",
"]",
"self",
".",
"reverse_list",
"[",
"distribution",
"]",
"=",
"[",
"]"
] | [
1101,
4
] | [
1108,
44
] | python | en | ['en', 'en', 'en'] | True |
DependencyGraph.add_edge | (self, x, y, label=None) | Add an edge from distribution *x* to distribution *y* with the given
*label*.
:type x: :class:`distutils2.database.InstalledDistribution` or
:class:`distutils2.database.EggInfoDistribution`
:type y: :class:`distutils2.database.InstalledDistribution` or
:class:`... | Add an edge from distribution *x* to distribution *y* with the given
*label*. | def add_edge(self, x, y, label=None):
"""Add an edge from distribution *x* to distribution *y* with the given
*label*.
:type x: :class:`distutils2.database.InstalledDistribution` or
:class:`distutils2.database.EggInfoDistribution`
:type y: :class:`distutils2.database.In... | [
"def",
"add_edge",
"(",
"self",
",",
"x",
",",
"y",
",",
"label",
"=",
"None",
")",
":",
"self",
".",
"adjacency_list",
"[",
"x",
"]",
".",
"append",
"(",
"(",
"y",
",",
"label",
")",
")",
"# multiple edges are allowed, so be careful",
"if",
"x",
"not"... | [
1111,
4
] | [
1124,
42
] | python | en | ['en', 'en', 'en'] | True |
DependencyGraph.add_missing | (self, distribution, requirement) |
Add a missing *requirement* for the given *distribution*.
:type distribution: :class:`distutils2.database.InstalledDistribution`
or :class:`distutils2.database.EggInfoDistribution`
:type requirement: ``str``
|
Add a missing *requirement* for the given *distribution*. | def add_missing(self, distribution, requirement):
"""
Add a missing *requirement* for the given *distribution*.
:type distribution: :class:`distutils2.database.InstalledDistribution`
or :class:`distutils2.database.EggInfoDistribution`
:type requirement: ``str... | [
"def",
"add_missing",
"(",
"self",
",",
"distribution",
",",
"requirement",
")",
":",
"logger",
".",
"debug",
"(",
"'%s missing %r'",
",",
"distribution",
",",
"requirement",
")",
"self",
".",
"missing",
".",
"setdefault",
"(",
"distribution",
",",
"[",
"]",... | [
1126,
4
] | [
1135,
69
] | python | en | ['en', 'error', 'th'] | False |
DependencyGraph.repr_node | (self, dist, level=1) | Prints only a subgraph | Prints only a subgraph | def repr_node(self, dist, level=1):
"""Prints only a subgraph"""
output = [self._repr_dist(dist)]
for other, label in self.adjacency_list[dist]:
dist = self._repr_dist(other)
if label is not None:
dist = '%s [%s]' % (dist, label)
output.append(... | [
"def",
"repr_node",
"(",
"self",
",",
"dist",
",",
"level",
"=",
"1",
")",
":",
"output",
"=",
"[",
"self",
".",
"_repr_dist",
"(",
"dist",
")",
"]",
"for",
"other",
",",
"label",
"in",
"self",
".",
"adjacency_list",
"[",
"dist",
"]",
":",
"dist",
... | [
1140,
4
] | [
1151,
32
] | python | en | ['en', 'en', 'en'] | True |
DependencyGraph.to_dot | (self, f, skip_disconnected=True) | Writes a DOT output for the graph to the provided file *f*.
If *skip_disconnected* is set to ``True``, then all distributions
that are not dependent on any other distribution are skipped.
:type f: has to support ``file``-like operations
:type skip_disconnected: ``bool``
| Writes a DOT output for the graph to the provided file *f*. | def to_dot(self, f, skip_disconnected=True):
"""Writes a DOT output for the graph to the provided file *f*.
If *skip_disconnected* is set to ``True``, then all distributions
that are not dependent on any other distribution are skipped.
:type f: has to support ``file``-like operations
... | [
"def",
"to_dot",
"(",
"self",
",",
"f",
",",
"skip_disconnected",
"=",
"True",
")",
":",
"disconnected",
"=",
"[",
"]",
"f",
".",
"write",
"(",
"\"digraph dependencies {\\n\"",
")",
"for",
"dist",
",",
"adjs",
"in",
"self",
".",
"adjacency_list",
".",
"i... | [
1153,
4
] | [
1183,
22
] | python | en | ['en', 'en', 'en'] | True |
DependencyGraph.topological_sort | (self) |
Perform a topological sort of the graph.
:return: A tuple, the first element of which is a topologically sorted
list of distributions, and the second element of which is a
list of distributions that cannot be sorted because they have
circular dependenc... |
Perform a topological sort of the graph.
:return: A tuple, the first element of which is a topologically sorted
list of distributions, and the second element of which is a
list of distributions that cannot be sorted because they have
circular dependenc... | def topological_sort(self):
"""
Perform a topological sort of the graph.
:return: A tuple, the first element of which is a topologically sorted
list of distributions, and the second element of which is a
list of distributions that cannot be sorted because they h... | [
"def",
"topological_sort",
"(",
"self",
")",
":",
"result",
"=",
"[",
"]",
"# Make a shallow copy of the adjacency list",
"alist",
"=",
"{",
"}",
"for",
"k",
",",
"v",
"in",
"self",
".",
"adjacency_list",
".",
"items",
"(",
")",
":",
"alist",
"[",
"k",
"... | [
1185,
4
] | [
1214,
41
] | python | en | ['en', 'error', 'th'] | False |
DependencyGraph.__repr__ | (self) | Representation of the graph | Representation of the graph | def __repr__(self):
"""Representation of the graph"""
output = []
for dist, adjs in self.adjacency_list.items():
output.append(self.repr_node(dist))
return '\n'.join(output) | [
"def",
"__repr__",
"(",
"self",
")",
":",
"output",
"=",
"[",
"]",
"for",
"dist",
",",
"adjs",
"in",
"self",
".",
"adjacency_list",
".",
"items",
"(",
")",
":",
"output",
".",
"append",
"(",
"self",
".",
"repr_node",
"(",
"dist",
")",
")",
"return"... | [
1216,
4
] | [
1221,
32
] | python | en | ['en', 'en', 'en'] | True |
dict_to_sequence | (d) | Returns an internal sequence dictionary update. | Returns an internal sequence dictionary update. | def dict_to_sequence(d):
"""Returns an internal sequence dictionary update."""
if hasattr(d, 'items'):
d = d.items()
return d | [
"def",
"dict_to_sequence",
"(",
"d",
")",
":",
"if",
"hasattr",
"(",
"d",
",",
"'items'",
")",
":",
"d",
"=",
"d",
".",
"items",
"(",
")",
"return",
"d"
] | [
98,
0
] | [
104,
12
] | python | en | ['en', 'lb', 'en'] | True |
get_netrc_auth | (url, raise_errors=False) | Returns the Requests tuple auth for a given url from netrc. | Returns the Requests tuple auth for a given url from netrc. | def get_netrc_auth(url, raise_errors=False):
"""Returns the Requests tuple auth for a given url from netrc."""
try:
from netrc import netrc, NetrcParseError
netrc_path = None
for f in NETRC_FILES:
try:
loc = os.path.expanduser('~/{}'.format(f))
... | [
"def",
"get_netrc_auth",
"(",
"url",
",",
"raise_errors",
"=",
"False",
")",
":",
"try",
":",
"from",
"netrc",
"import",
"netrc",
",",
"NetrcParseError",
"netrc_path",
"=",
"None",
"for",
"f",
"in",
"NETRC_FILES",
":",
"try",
":",
"loc",
"=",
"os",
".",
... | [
168,
0
] | [
216,
12
] | python | en | ['en', 'en', 'en'] | True |
guess_filename | (obj) | Tries to guess the filename of the given object. | Tries to guess the filename of the given object. | def guess_filename(obj):
"""Tries to guess the filename of the given object."""
name = getattr(obj, 'name', None)
if (name and isinstance(name, basestring) and name[0] != '<' and
name[-1] != '>'):
return os.path.basename(name) | [
"def",
"guess_filename",
"(",
"obj",
")",
":",
"name",
"=",
"getattr",
"(",
"obj",
",",
"'name'",
",",
"None",
")",
"if",
"(",
"name",
"and",
"isinstance",
"(",
"name",
",",
"basestring",
")",
"and",
"name",
"[",
"0",
"]",
"!=",
"'<'",
"and",
"name... | [
219,
0
] | [
224,
37
] | python | en | ['en', 'en', 'en'] | True |
extract_zipped_paths | (path) | Replace nonexistent paths that look like they refer to a member of a zip
archive with the location of an extracted copy of the target, or else
just return the provided path unchanged.
| Replace nonexistent paths that look like they refer to a member of a zip
archive with the location of an extracted copy of the target, or else
just return the provided path unchanged.
| def extract_zipped_paths(path):
"""Replace nonexistent paths that look like they refer to a member of a zip
archive with the location of an extracted copy of the target, or else
just return the provided path unchanged.
"""
if os.path.exists(path):
# this is already a valid path, no need to d... | [
"def",
"extract_zipped_paths",
"(",
"path",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"# this is already a valid path, no need to do anything further",
"return",
"path",
"# find the first valid part of the provided path and treat that as a zip arc... | [
227,
0
] | [
256,
25
] | python | en | ['en', 'en', 'en'] | True |
from_key_val_list | (value) | Take an object and test to see if it can be represented as a
dictionary. Unless it can not be represented as such, return an
OrderedDict, e.g.,
::
>>> from_key_val_list([('key', 'val')])
OrderedDict([('key', 'val')])
>>> from_key_val_list('string')
Traceback (most recent ca... | Take an object and test to see if it can be represented as a
dictionary. Unless it can not be represented as such, return an
OrderedDict, e.g., | def from_key_val_list(value):
"""Take an object and test to see if it can be represented as a
dictionary. Unless it can not be represented as such, return an
OrderedDict, e.g.,
::
>>> from_key_val_list([('key', 'val')])
OrderedDict([('key', 'val')])
>>> from_key_val_list('strin... | [
"def",
"from_key_val_list",
"(",
"value",
")",
":",
"if",
"value",
"is",
"None",
":",
"return",
"None",
"if",
"isinstance",
"(",
"value",
",",
"(",
"str",
",",
"bytes",
",",
"bool",
",",
"int",
")",
")",
":",
"raise",
"ValueError",
"(",
"'cannot encode... | [
259,
0
] | [
283,
29
] | python | en | ['en', 'en', 'en'] | True |
to_key_val_list | (value) | Take an object and test to see if it can be represented as a
dictionary. If it can be, return a list of tuples, e.g.,
::
>>> to_key_val_list([('key', 'val')])
[('key', 'val')]
>>> to_key_val_list({'key': 'val'})
[('key', 'val')]
>>> to_key_val_list('string')
Tra... | Take an object and test to see if it can be represented as a
dictionary. If it can be, return a list of tuples, e.g., | def to_key_val_list(value):
"""Take an object and test to see if it can be represented as a
dictionary. If it can be, return a list of tuples, e.g.,
::
>>> to_key_val_list([('key', 'val')])
[('key', 'val')]
>>> to_key_val_list({'key': 'val'})
[('key', 'val')]
>>> to... | [
"def",
"to_key_val_list",
"(",
"value",
")",
":",
"if",
"value",
"is",
"None",
":",
"return",
"None",
"if",
"isinstance",
"(",
"value",
",",
"(",
"str",
",",
"bytes",
",",
"bool",
",",
"int",
")",
")",
":",
"raise",
"ValueError",
"(",
"'cannot encode o... | [
286,
0
] | [
312,
22
] | python | en | ['en', 'en', 'en'] | True |
parse_list_header | (value) | Parse lists as described by RFC 2068 Section 2.
In particular, parse comma-separated lists where the elements of
the list may include quoted-strings. A quoted-string could
contain a comma. A non-quoted string could have quotes in the
middle. Quotes are removed automatically after parsing.
It ba... | Parse lists as described by RFC 2068 Section 2. | def parse_list_header(value):
"""Parse lists as described by RFC 2068 Section 2.
In particular, parse comma-separated lists where the elements of
the list may include quoted-strings. A quoted-string could
contain a comma. A non-quoted string could have quotes in the
middle. Quotes are removed au... | [
"def",
"parse_list_header",
"(",
"value",
")",
":",
"result",
"=",
"[",
"]",
"for",
"item",
"in",
"_parse_list_header",
"(",
"value",
")",
":",
"if",
"item",
"[",
":",
"1",
"]",
"==",
"item",
"[",
"-",
"1",
":",
"]",
"==",
"'\"'",
":",
"item",
"=... | [
316,
0
] | [
344,
17
] | python | en | ['en', 'en', 'en'] | True |
parse_dict_header | (value) | Parse lists of key, value pairs as described by RFC 2068 Section 2 and
convert them into a python dict:
>>> d = parse_dict_header('foo="is a fish", bar="as well"')
>>> type(d) is dict
True
>>> sorted(d.items())
[('bar', 'as well'), ('foo', 'is a fish')]
If there is no value for a key it wi... | Parse lists of key, value pairs as described by RFC 2068 Section 2 and
convert them into a python dict: | def parse_dict_header(value):
"""Parse lists of key, value pairs as described by RFC 2068 Section 2 and
convert them into a python dict:
>>> d = parse_dict_header('foo="is a fish", bar="as well"')
>>> type(d) is dict
True
>>> sorted(d.items())
[('bar', 'as well'), ('foo', 'is a fish')]
... | [
"def",
"parse_dict_header",
"(",
"value",
")",
":",
"result",
"=",
"{",
"}",
"for",
"item",
"in",
"_parse_list_header",
"(",
"value",
")",
":",
"if",
"'='",
"not",
"in",
"item",
":",
"result",
"[",
"item",
"]",
"=",
"None",
"continue",
"name",
",",
"... | [
348,
0
] | [
379,
17
] | python | en | ['en', 'en', 'en'] | True |
unquote_header_value | (value, is_filename=False) | r"""Unquotes a header value. (Reversal of :func:`quote_header_value`).
This does not use the real unquoting but what browsers are actually
using for quoting.
:param value: the header value to unquote.
:rtype: str
| r"""Unquotes a header value. (Reversal of :func:`quote_header_value`).
This does not use the real unquoting but what browsers are actually
using for quoting. | def unquote_header_value(value, is_filename=False):
r"""Unquotes a header value. (Reversal of :func:`quote_header_value`).
This does not use the real unquoting but what browsers are actually
using for quoting.
:param value: the header value to unquote.
:rtype: str
"""
if value and value[0]... | [
"def",
"unquote_header_value",
"(",
"value",
",",
"is_filename",
"=",
"False",
")",
":",
"if",
"value",
"and",
"value",
"[",
"0",
"]",
"==",
"value",
"[",
"-",
"1",
"]",
"==",
"'\"'",
":",
"# this is not the real unquoting, but fixing this so that the",
"# RFC i... | [
383,
0
] | [
405,
16
] | python | en | ['en', 'en', 'en'] | True |
dict_from_cookiejar | (cj) | Returns a key/value dictionary from a CookieJar.
:param cj: CookieJar object to extract cookies from.
:rtype: dict
| Returns a key/value dictionary from a CookieJar. | def dict_from_cookiejar(cj):
"""Returns a key/value dictionary from a CookieJar.
:param cj: CookieJar object to extract cookies from.
:rtype: dict
"""
cookie_dict = {}
for cookie in cj:
cookie_dict[cookie.name] = cookie.value
return cookie_dict | [
"def",
"dict_from_cookiejar",
"(",
"cj",
")",
":",
"cookie_dict",
"=",
"{",
"}",
"for",
"cookie",
"in",
"cj",
":",
"cookie_dict",
"[",
"cookie",
".",
"name",
"]",
"=",
"cookie",
".",
"value",
"return",
"cookie_dict"
] | [
408,
0
] | [
420,
22
] | python | en | ['en', 'en', 'en'] | True |
add_dict_to_cookiejar | (cj, cookie_dict) | Returns a CookieJar from a key/value dictionary.
:param cj: CookieJar to insert cookies into.
:param cookie_dict: Dict of key/values to insert into CookieJar.
:rtype: CookieJar
| Returns a CookieJar from a key/value dictionary. | def add_dict_to_cookiejar(cj, cookie_dict):
"""Returns a CookieJar from a key/value dictionary.
:param cj: CookieJar to insert cookies into.
:param cookie_dict: Dict of key/values to insert into CookieJar.
:rtype: CookieJar
"""
return cookiejar_from_dict(cookie_dict, cj) | [
"def",
"add_dict_to_cookiejar",
"(",
"cj",
",",
"cookie_dict",
")",
":",
"return",
"cookiejar_from_dict",
"(",
"cookie_dict",
",",
"cj",
")"
] | [
423,
0
] | [
431,
47
] | python | en | ['en', 'en', 'en'] | True |
get_encodings_from_content | (content) | Returns encodings from given content string.
:param content: bytestring to extract encodings from.
| Returns encodings from given content string. | def get_encodings_from_content(content):
"""Returns encodings from given content string.
:param content: bytestring to extract encodings from.
"""
warnings.warn((
'In requests 3.0, get_encodings_from_content will be removed. For '
'more information, please see the discussion on issue #2... | [
"def",
"get_encodings_from_content",
"(",
"content",
")",
":",
"warnings",
".",
"warn",
"(",
"(",
"'In requests 3.0, get_encodings_from_content will be removed. For '",
"'more information, please see the discussion on issue #2266. (This'",
"' warning should only appear once.)'",
")",
"... | [
434,
0
] | [
451,
36
] | python | en | ['en', 'en', 'en'] | True |
_parse_content_type_header | (header) | Returns content type and parameters from given header
:param header: string
:return: tuple containing content type and dictionary of
parameters
| Returns content type and parameters from given header | def _parse_content_type_header(header):
"""Returns content type and parameters from given header
:param header: string
:return: tuple containing content type and dictionary of
parameters
"""
tokens = header.split(';')
content_type, params = tokens[0].strip(), tokens[1:]
params_dic... | [
"def",
"_parse_content_type_header",
"(",
"header",
")",
":",
"tokens",
"=",
"header",
".",
"split",
"(",
"';'",
")",
"content_type",
",",
"params",
"=",
"tokens",
"[",
"0",
"]",
".",
"strip",
"(",
")",
",",
"tokens",
"[",
"1",
":",
"]",
"params_dict",... | [
454,
0
] | [
476,
36
] | python | en | ['en', 'en', 'en'] | True |
get_encoding_from_headers | (headers) | Returns encodings from given HTTP Header Dict.
:param headers: dictionary to extract encoding from.
:rtype: str
| Returns encodings from given HTTP Header Dict. | def get_encoding_from_headers(headers):
"""Returns encodings from given HTTP Header Dict.
:param headers: dictionary to extract encoding from.
:rtype: str
"""
content_type = headers.get('content-type')
if not content_type:
return None
content_type, params = _parse_content_type_he... | [
"def",
"get_encoding_from_headers",
"(",
"headers",
")",
":",
"content_type",
"=",
"headers",
".",
"get",
"(",
"'content-type'",
")",
"if",
"not",
"content_type",
":",
"return",
"None",
"content_type",
",",
"params",
"=",
"_parse_content_type_header",
"(",
"conten... | [
479,
0
] | [
497,
27
] | python | en | ['en', 'en', 'en'] | True |
stream_decode_response_unicode | (iterator, r) | Stream decodes a iterator. | Stream decodes a iterator. | def stream_decode_response_unicode(iterator, r):
"""Stream decodes a iterator."""
if r.encoding is None:
for item in iterator:
yield item
return
decoder = codecs.getincrementaldecoder(r.encoding)(errors='replace')
for chunk in iterator:
rv = decoder.decode(chunk)
... | [
"def",
"stream_decode_response_unicode",
"(",
"iterator",
",",
"r",
")",
":",
"if",
"r",
".",
"encoding",
"is",
"None",
":",
"for",
"item",
"in",
"iterator",
":",
"yield",
"item",
"return",
"decoder",
"=",
"codecs",
".",
"getincrementaldecoder",
"(",
"r",
... | [
500,
0
] | [
515,
16
] | python | en | ['en', 'zh', 'pt'] | False |
iter_slices | (string, slice_length) | Iterate over slices of a string. | Iterate over slices of a string. | def iter_slices(string, slice_length):
"""Iterate over slices of a string."""
pos = 0
if slice_length is None or slice_length <= 0:
slice_length = len(string)
while pos < len(string):
yield string[pos:pos + slice_length]
pos += slice_length | [
"def",
"iter_slices",
"(",
"string",
",",
"slice_length",
")",
":",
"pos",
"=",
"0",
"if",
"slice_length",
"is",
"None",
"or",
"slice_length",
"<=",
"0",
":",
"slice_length",
"=",
"len",
"(",
"string",
")",
"while",
"pos",
"<",
"len",
"(",
"string",
")... | [
518,
0
] | [
525,
27
] | python | en | ['en', 'en', 'en'] | True |
get_unicode_from_response | (r) | Returns the requested content back in unicode.
:param r: Response object to get unicode content from.
Tried:
1. charset from content-type
2. fall back and replace all unicode characters
:rtype: str
| Returns the requested content back in unicode. | def get_unicode_from_response(r):
"""Returns the requested content back in unicode.
:param r: Response object to get unicode content from.
Tried:
1. charset from content-type
2. fall back and replace all unicode characters
:rtype: str
"""
warnings.warn((
'In requests 3.0, get... | [
"def",
"get_unicode_from_response",
"(",
"r",
")",
":",
"warnings",
".",
"warn",
"(",
"(",
"'In requests 3.0, get_unicode_from_response will be removed. For '",
"'more information, please see the discussion on issue #2266. (This'",
"' warning should only appear once.)'",
")",
",",
"D... | [
528,
0
] | [
561,
24
] | python | en | ['en', 'en', 'en'] | True |
unquote_unreserved | (uri) | Un-escape any percent-escape sequences in a URI that are unreserved
characters. This leaves all reserved, illegal and non-ASCII bytes encoded.
:rtype: str
| Un-escape any percent-escape sequences in a URI that are unreserved
characters. This leaves all reserved, illegal and non-ASCII bytes encoded. | def unquote_unreserved(uri):
"""Un-escape any percent-escape sequences in a URI that are unreserved
characters. This leaves all reserved, illegal and non-ASCII bytes encoded.
:rtype: str
"""
parts = uri.split('%')
for i in range(1, len(parts)):
h = parts[i][0:2]
if len(h) == 2 a... | [
"def",
"unquote_unreserved",
"(",
"uri",
")",
":",
"parts",
"=",
"uri",
".",
"split",
"(",
"'%'",
")",
"for",
"i",
"in",
"range",
"(",
"1",
",",
"len",
"(",
"parts",
")",
")",
":",
"h",
"=",
"parts",
"[",
"i",
"]",
"[",
"0",
":",
"2",
"]",
... | [
569,
0
] | [
590,
25
] | python | en | ['en', 'it', 'en'] | True |
requote_uri | (uri) | Re-quote the given URI.
This function passes the given URI through an unquote/quote cycle to
ensure that it is fully and consistently quoted.
:rtype: str
| Re-quote the given URI. | def requote_uri(uri):
"""Re-quote the given URI.
This function passes the given URI through an unquote/quote cycle to
ensure that it is fully and consistently quoted.
:rtype: str
"""
safe_with_percent = "!#$%&'()*+,/:;=?@[]~"
safe_without_percent = "!#$&'()*+,/:;=?@[]~"
try:
# ... | [
"def",
"requote_uri",
"(",
"uri",
")",
":",
"safe_with_percent",
"=",
"\"!#$%&'()*+,/:;=?@[]~\"",
"safe_without_percent",
"=",
"\"!#$&'()*+,/:;=?@[]~\"",
"try",
":",
"# Unquote only the unreserved characters",
"# Then quote only illegal characters (do not quote reserved,",
"# unreser... | [
593,
0
] | [
612,
52
] | python | en | ['en', 'en', 'en'] | True |
address_in_network | (ip, net) | This function allows you to check if an IP belongs to a network subnet
Example: returns True if ip = 192.168.1.1 and net = 192.168.1.0/24
returns False if ip = 192.168.1.1 and net = 192.168.100.0/24
:rtype: bool
| This function allows you to check if an IP belongs to a network subnet | def address_in_network(ip, net):
"""This function allows you to check if an IP belongs to a network subnet
Example: returns True if ip = 192.168.1.1 and net = 192.168.1.0/24
returns False if ip = 192.168.1.1 and net = 192.168.100.0/24
:rtype: bool
"""
ipaddr = struct.unpack('=L', sock... | [
"def",
"address_in_network",
"(",
"ip",
",",
"net",
")",
":",
"ipaddr",
"=",
"struct",
".",
"unpack",
"(",
"'=L'",
",",
"socket",
".",
"inet_aton",
"(",
"ip",
")",
")",
"[",
"0",
"]",
"netaddr",
",",
"bits",
"=",
"net",
".",
"split",
"(",
"'/'",
... | [
615,
0
] | [
627,
52
] | python | en | ['en', 'en', 'en'] | True |
dotted_netmask | (mask) | Converts mask from /xx format to xxx.xxx.xxx.xxx
Example: if mask is 24 function returns 255.255.255.0
:rtype: str
| Converts mask from /xx format to xxx.xxx.xxx.xxx | def dotted_netmask(mask):
"""Converts mask from /xx format to xxx.xxx.xxx.xxx
Example: if mask is 24 function returns 255.255.255.0
:rtype: str
"""
bits = 0xffffffff ^ (1 << 32 - mask) - 1
return socket.inet_ntoa(struct.pack('>I', bits)) | [
"def",
"dotted_netmask",
"(",
"mask",
")",
":",
"bits",
"=",
"0xffffffff",
"^",
"(",
"1",
"<<",
"32",
"-",
"mask",
")",
"-",
"1",
"return",
"socket",
".",
"inet_ntoa",
"(",
"struct",
".",
"pack",
"(",
"'>I'",
",",
"bits",
")",
")"
] | [
630,
0
] | [
638,
52
] | python | en | ['en', 'pl', 'en'] | True |
is_ipv4_address | (string_ip) |
:rtype: bool
|
:rtype: bool
| def is_ipv4_address(string_ip):
"""
:rtype: bool
"""
try:
socket.inet_aton(string_ip)
except socket.error:
return False
return True | [
"def",
"is_ipv4_address",
"(",
"string_ip",
")",
":",
"try",
":",
"socket",
".",
"inet_aton",
"(",
"string_ip",
")",
"except",
"socket",
".",
"error",
":",
"return",
"False",
"return",
"True"
] | [
641,
0
] | [
649,
15
] | python | en | ['en', 'error', 'th'] | False |
is_valid_cidr | (string_network) |
Very simple check of the cidr format in no_proxy variable.
:rtype: bool
|
Very simple check of the cidr format in no_proxy variable. | def is_valid_cidr(string_network):
"""
Very simple check of the cidr format in no_proxy variable.
:rtype: bool
"""
if string_network.count('/') == 1:
try:
mask = int(string_network.split('/')[1])
except ValueError:
return False
if mask < 1 or mask > ... | [
"def",
"is_valid_cidr",
"(",
"string_network",
")",
":",
"if",
"string_network",
".",
"count",
"(",
"'/'",
")",
"==",
"1",
":",
"try",
":",
"mask",
"=",
"int",
"(",
"string_network",
".",
"split",
"(",
"'/'",
")",
"[",
"1",
"]",
")",
"except",
"Value... | [
652,
0
] | [
673,
15
] | python | en | ['en', 'error', 'th'] | False |
set_environ | (env_name, value) | Set the environment variable 'env_name' to 'value'
Save previous value, yield, and then restore the previous value stored in
the environment variable 'env_name'.
If 'value' is None, do nothing | Set the environment variable 'env_name' to 'value' | def set_environ(env_name, value):
"""Set the environment variable 'env_name' to 'value'
Save previous value, yield, and then restore the previous value stored in
the environment variable 'env_name'.
If 'value' is None, do nothing"""
value_changed = value is not None
if value_changed:
o... | [
"def",
"set_environ",
"(",
"env_name",
",",
"value",
")",
":",
"value_changed",
"=",
"value",
"is",
"not",
"None",
"if",
"value_changed",
":",
"old_value",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"env_name",
")",
"os",
".",
"environ",
"[",
"env_name"... | [
677,
0
] | [
695,
48
] | python | en | ['en', 'en', 'en'] | True |
should_bypass_proxies | (url, no_proxy) |
Returns whether we should bypass proxies or not.
:rtype: bool
|
Returns whether we should bypass proxies or not. | def should_bypass_proxies(url, no_proxy):
"""
Returns whether we should bypass proxies or not.
:rtype: bool
"""
# Prioritize lowercase environment variables over uppercase
# to keep a consistent behaviour with other http projects (curl, wget).
get_proxy = lambda k: os.environ.get(k) or os.e... | [
"def",
"should_bypass_proxies",
"(",
"url",
",",
"no_proxy",
")",
":",
"# Prioritize lowercase environment variables over uppercase",
"# to keep a consistent behaviour with other http projects (curl, wget).",
"get_proxy",
"=",
"lambda",
"k",
":",
"os",
".",
"environ",
".",
"get... | [
698,
0
] | [
756,
16
] | python | en | ['en', 'error', 'th'] | False |
get_environ_proxies | (url, no_proxy=None) |
Return a dict of environment proxies.
:rtype: dict
|
Return a dict of environment proxies. | def get_environ_proxies(url, no_proxy=None):
"""
Return a dict of environment proxies.
:rtype: dict
"""
if should_bypass_proxies(url, no_proxy=no_proxy):
return {}
else:
return getproxies() | [
"def",
"get_environ_proxies",
"(",
"url",
",",
"no_proxy",
"=",
"None",
")",
":",
"if",
"should_bypass_proxies",
"(",
"url",
",",
"no_proxy",
"=",
"no_proxy",
")",
":",
"return",
"{",
"}",
"else",
":",
"return",
"getproxies",
"(",
")"
] | [
759,
0
] | [
768,
27
] | python | en | ['en', 'error', 'th'] | False |
select_proxy | (url, proxies) | Select a proxy for the url, if applicable.
:param url: The url being for the request
:param proxies: A dictionary of schemes or schemes and hosts to proxy URLs
| Select a proxy for the url, if applicable. | def select_proxy(url, proxies):
"""Select a proxy for the url, if applicable.
:param url: The url being for the request
:param proxies: A dictionary of schemes or schemes and hosts to proxy URLs
"""
proxies = proxies or {}
urlparts = urlparse(url)
if urlparts.hostname is None:
retur... | [
"def",
"select_proxy",
"(",
"url",
",",
"proxies",
")",
":",
"proxies",
"=",
"proxies",
"or",
"{",
"}",
"urlparts",
"=",
"urlparse",
"(",
"url",
")",
"if",
"urlparts",
".",
"hostname",
"is",
"None",
":",
"return",
"proxies",
".",
"get",
"(",
"urlparts"... | [
771,
0
] | [
794,
16
] | python | en | ['en', 'en', 'en'] | True |
default_user_agent | (name="python-requests") |
Return a string representing the default user agent.
:rtype: str
|
Return a string representing the default user agent. | def default_user_agent(name="python-requests"):
"""
Return a string representing the default user agent.
:rtype: str
"""
return '%s/%s' % (name, __version__) | [
"def",
"default_user_agent",
"(",
"name",
"=",
"\"python-requests\"",
")",
":",
"return",
"'%s/%s'",
"%",
"(",
"name",
",",
"__version__",
")"
] | [
797,
0
] | [
803,
40
] | python | en | ['en', 'error', 'th'] | False |
default_headers | () |
:rtype: requests.structures.CaseInsensitiveDict
|
:rtype: requests.structures.CaseInsensitiveDict
| def default_headers():
"""
:rtype: requests.structures.CaseInsensitiveDict
"""
return CaseInsensitiveDict({
'User-Agent': default_user_agent(),
'Accept-Encoding': ', '.join(('gzip', 'deflate')),
'Accept': '*/*',
'Connection': 'keep-alive',
}) | [
"def",
"default_headers",
"(",
")",
":",
"return",
"CaseInsensitiveDict",
"(",
"{",
"'User-Agent'",
":",
"default_user_agent",
"(",
")",
",",
"'Accept-Encoding'",
":",
"', '",
".",
"join",
"(",
"(",
"'gzip'",
",",
"'deflate'",
")",
")",
",",
"'Accept'",
":",... | [
806,
0
] | [
815,
6
] | python | en | ['en', 'error', 'th'] | False |
parse_header_links | (value) | Return a list of parsed link headers proxies.
i.e. Link: <http:/.../front.jpeg>; rel=front; type="image/jpeg",<http://.../back.jpeg>; rel=back;type="image/jpeg"
:rtype: list
| Return a list of parsed link headers proxies. | def parse_header_links(value):
"""Return a list of parsed link headers proxies.
i.e. Link: <http:/.../front.jpeg>; rel=front; type="image/jpeg",<http://.../back.jpeg>; rel=back;type="image/jpeg"
:rtype: list
"""
links = []
replace_chars = ' \'"'
value = value.strip(replace_chars)
if... | [
"def",
"parse_header_links",
"(",
"value",
")",
":",
"links",
"=",
"[",
"]",
"replace_chars",
"=",
"' \\'\"'",
"value",
"=",
"value",
".",
"strip",
"(",
"replace_chars",
")",
"if",
"not",
"value",
":",
"return",
"links",
"for",
"val",
"in",
"re",
".",
... | [
818,
0
] | [
852,
16
] | python | en | ['en', 'af', 'en'] | True |
guess_json_utf | (data) |
:rtype: str
|
:rtype: str
| def guess_json_utf(data):
"""
:rtype: str
"""
# JSON always starts with two ASCII characters, so detection is as
# easy as counting the nulls and from their location and count
# determine the encoding. Also detect a BOM, if present.
sample = data[:4]
if sample in (codecs.BOM_UTF32_LE, co... | [
"def",
"guess_json_utf",
"(",
"data",
")",
":",
"# JSON always starts with two ASCII characters, so detection is as",
"# easy as counting the nulls and from their location and count",
"# determine the encoding. Also detect a BOM, if present.",
"sample",
"=",
"data",
"[",
":",
"4",
"]",... | [
861,
0
] | [
890,
15
] | python | en | ['en', 'error', 'th'] | False |
prepend_scheme_if_needed | (url, new_scheme) | Given a URL that may or may not have a scheme, prepend the given scheme.
Does not replace a present scheme with the one provided as an argument.
:rtype: str
| Given a URL that may or may not have a scheme, prepend the given scheme.
Does not replace a present scheme with the one provided as an argument. | def prepend_scheme_if_needed(url, new_scheme):
"""Given a URL that may or may not have a scheme, prepend the given scheme.
Does not replace a present scheme with the one provided as an argument.
:rtype: str
"""
scheme, netloc, path, params, query, fragment = urlparse(url, new_scheme)
# urlpars... | [
"def",
"prepend_scheme_if_needed",
"(",
"url",
",",
"new_scheme",
")",
":",
"scheme",
",",
"netloc",
",",
"path",
",",
"params",
",",
"query",
",",
"fragment",
"=",
"urlparse",
"(",
"url",
",",
"new_scheme",
")",
"# urlparse is a finicky beast, and sometimes decid... | [
893,
0
] | [
907,
70
] | python | en | ['en', 'en', 'en'] | True |
get_auth_from_url | (url) | Given a url with authentication components, extract them into a tuple of
username,password.
:rtype: (str,str)
| Given a url with authentication components, extract them into a tuple of
username,password. | def get_auth_from_url(url):
"""Given a url with authentication components, extract them into a tuple of
username,password.
:rtype: (str,str)
"""
parsed = urlparse(url)
try:
auth = (unquote(parsed.username), unquote(parsed.password))
except (AttributeError, TypeError):
auth ... | [
"def",
"get_auth_from_url",
"(",
"url",
")",
":",
"parsed",
"=",
"urlparse",
"(",
"url",
")",
"try",
":",
"auth",
"=",
"(",
"unquote",
"(",
"parsed",
".",
"username",
")",
",",
"unquote",
"(",
"parsed",
".",
"password",
")",
")",
"except",
"(",
"Attr... | [
910,
0
] | [
923,
15
] | python | en | ['en', 'en', 'en'] | True |
check_header_validity | (header) | Verifies that header value is a string which doesn't contain
leading whitespace or return characters. This prevents unintended
header injection.
:param header: tuple, in the format (name, value).
| Verifies that header value is a string which doesn't contain
leading whitespace or return characters. This prevents unintended
header injection. | def check_header_validity(header):
"""Verifies that header value is a string which doesn't contain
leading whitespace or return characters. This prevents unintended
header injection.
:param header: tuple, in the format (name, value).
"""
name, value = header
if isinstance(value, bytes):
... | [
"def",
"check_header_validity",
"(",
"header",
")",
":",
"name",
",",
"value",
"=",
"header",
"if",
"isinstance",
"(",
"value",
",",
"bytes",
")",
":",
"pat",
"=",
"_CLEAN_HEADER_REGEX_BYTE",
"else",
":",
"pat",
"=",
"_CLEAN_HEADER_REGEX_STR",
"try",
":",
"i... | [
931,
0
] | [
949,
73
] | python | en | ['en', 'en', 'en'] | True |
urldefragauth | (url) |
Given a url remove the fragment and the authentication part.
:rtype: str
|
Given a url remove the fragment and the authentication part. | def urldefragauth(url):
"""
Given a url remove the fragment and the authentication part.
:rtype: str
"""
scheme, netloc, path, params, query, fragment = urlparse(url)
# see func:`prepend_scheme_if_needed`
if not netloc:
netloc, path = path, netloc
netloc = netloc.rsplit('@', 1... | [
"def",
"urldefragauth",
"(",
"url",
")",
":",
"scheme",
",",
"netloc",
",",
"path",
",",
"params",
",",
"query",
",",
"fragment",
"=",
"urlparse",
"(",
"url",
")",
"# see func:`prepend_scheme_if_needed`",
"if",
"not",
"netloc",
":",
"netloc",
",",
"path",
... | [
952,
0
] | [
966,
64
] | python | en | ['en', 'error', 'th'] | False |
rewind_body | (prepared_request) | Move file pointer back to its recorded starting position
so it can be read again on redirect.
| Move file pointer back to its recorded starting position
so it can be read again on redirect.
| def rewind_body(prepared_request):
"""Move file pointer back to its recorded starting position
so it can be read again on redirect.
"""
body_seek = getattr(prepared_request.body, 'seek', None)
if body_seek is not None and isinstance(prepared_request._body_position, integer_types):
try:
... | [
"def",
"rewind_body",
"(",
"prepared_request",
")",
":",
"body_seek",
"=",
"getattr",
"(",
"prepared_request",
".",
"body",
",",
"'seek'",
",",
"None",
")",
"if",
"body_seek",
"is",
"not",
"None",
"and",
"isinstance",
"(",
"prepared_request",
".",
"_body_posit... | [
969,
0
] | [
981,
82
] | python | en | ['en', 'en', 'en'] | True |
constant | (image, value) | Fill a channel with a given grey level.
:rtype: :py:class:`~PIL.Image.Image`
| Fill a channel with a given grey level. | def constant(image, value):
"""Fill a channel with a given grey level.
:rtype: :py:class:`~PIL.Image.Image`
"""
return Image.new("L", image.size, value) | [
"def",
"constant",
"(",
"image",
",",
"value",
")",
":",
"return",
"Image",
".",
"new",
"(",
"\"L\"",
",",
"image",
".",
"size",
",",
"value",
")"
] | [
20,
0
] | [
26,
44
] | python | en | ['en', 'en', 'en'] | True |
duplicate | (image) | Copy a channel. Alias for :py:meth:`PIL.Image.Image.copy`.
:rtype: :py:class:`~PIL.Image.Image`
| Copy a channel. Alias for :py:meth:`PIL.Image.Image.copy`. | def duplicate(image):
"""Copy a channel. Alias for :py:meth:`PIL.Image.Image.copy`.
:rtype: :py:class:`~PIL.Image.Image`
"""
return image.copy() | [
"def",
"duplicate",
"(",
"image",
")",
":",
"return",
"image",
".",
"copy",
"(",
")"
] | [
29,
0
] | [
35,
23
] | python | en | ['en', 'fr', 'en'] | True |
invert | (image) |
Invert an image (channel).
.. code-block:: python
out = MAX - image
:rtype: :py:class:`~PIL.Image.Image`
|
Invert an image (channel). | def invert(image):
"""
Invert an image (channel).
.. code-block:: python
out = MAX - image
:rtype: :py:class:`~PIL.Image.Image`
"""
image.load()
return image._new(image.im.chop_invert()) | [
"def",
"invert",
"(",
"image",
")",
":",
"image",
".",
"load",
"(",
")",
"return",
"image",
".",
"_new",
"(",
"image",
".",
"im",
".",
"chop_invert",
"(",
")",
")"
] | [
38,
0
] | [
50,
45
] | python | en | ['en', 'error', 'th'] | False |
lighter | (image1, image2) |
Compares the two images, pixel by pixel, and returns a new image containing
the lighter values.
.. code-block:: python
out = max(image1, image2)
:rtype: :py:class:`~PIL.Image.Image`
|
Compares the two images, pixel by pixel, and returns a new image containing
the lighter values. | def lighter(image1, image2):
"""
Compares the two images, pixel by pixel, and returns a new image containing
the lighter values.
.. code-block:: python
out = max(image1, image2)
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1... | [
"def",
"lighter",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_lighter",
"(",
"image2",
".",
"im",
")",
")"
] | [
53,
0
] | [
67,
57
] | python | en | ['en', 'error', 'th'] | False |
darker | (image1, image2) |
Compares the two images, pixel by pixel, and returns a new image containing
the darker values.
.. code-block:: python
out = min(image1, image2)
:rtype: :py:class:`~PIL.Image.Image`
|
Compares the two images, pixel by pixel, and returns a new image containing
the darker values. | def darker(image1, image2):
"""
Compares the two images, pixel by pixel, and returns a new image containing
the darker values.
.. code-block:: python
out = min(image1, image2)
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1.i... | [
"def",
"darker",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_darker",
"(",
"image2",
".",
"im",
")",
")"
] | [
70,
0
] | [
84,
56
] | python | en | ['en', 'error', 'th'] | False |
difference | (image1, image2) |
Returns the absolute value of the pixel-by-pixel difference between the two
images.
.. code-block:: python
out = abs(image1 - image2)
:rtype: :py:class:`~PIL.Image.Image`
|
Returns the absolute value of the pixel-by-pixel difference between the two
images. | def difference(image1, image2):
"""
Returns the absolute value of the pixel-by-pixel difference between the two
images.
.. code-block:: python
out = abs(image1 - image2)
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1.im.chop... | [
"def",
"difference",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_difference",
"(",
"image2",
".",
"im",
")",
")"
] | [
87,
0
] | [
101,
60
] | python | en | ['en', 'error', 'th'] | False |
multiply | (image1, image2) |
Superimposes two images on top of each other.
If you multiply an image with a solid black image, the result is black. If
you multiply with a solid white image, the image is unaffected.
.. code-block:: python
out = image1 * image2 / MAX
:rtype: :py:class:`~PIL.Image.Image`
|
Superimposes two images on top of each other. | def multiply(image1, image2):
"""
Superimposes two images on top of each other.
If you multiply an image with a solid black image, the result is black. If
you multiply with a solid white image, the image is unaffected.
.. code-block:: python
out = image1 * image2 / MAX
:rtype: :py:cl... | [
"def",
"multiply",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_multiply",
"(",
"image2",
".",
"im",
")",
")"
] | [
104,
0
] | [
120,
58
] | python | en | ['en', 'error', 'th'] | False |
screen | (image1, image2) |
Superimposes two inverted images on top of each other.
.. code-block:: python
out = MAX - ((MAX - image1) * (MAX - image2) / MAX)
:rtype: :py:class:`~PIL.Image.Image`
|
Superimposes two inverted images on top of each other. | def screen(image1, image2):
"""
Superimposes two inverted images on top of each other.
.. code-block:: python
out = MAX - ((MAX - image1) * (MAX - image2) / MAX)
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1.im.chop_screen(imag... | [
"def",
"screen",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_screen",
"(",
"image2",
".",
"im",
")",
")"
] | [
123,
0
] | [
136,
56
] | python | en | ['en', 'error', 'th'] | False |
soft_light | (image1, image2) |
Superimposes two images on top of each other using the Soft Light algorithm
:rtype: :py:class:`~PIL.Image.Image`
|
Superimposes two images on top of each other using the Soft Light algorithm | def soft_light(image1, image2):
"""
Superimposes two images on top of each other using the Soft Light algorithm
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1.im.chop_soft_light(image2.im)) | [
"def",
"soft_light",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_soft_light",
"(",
"image2",
".",
"im",
")",
")"
] | [
139,
0
] | [
148,
60
] | python | en | ['en', 'error', 'th'] | False |
hard_light | (image1, image2) |
Superimposes two images on top of each other using the Hard Light algorithm
:rtype: :py:class:`~PIL.Image.Image`
|
Superimposes two images on top of each other using the Hard Light algorithm | def hard_light(image1, image2):
"""
Superimposes two images on top of each other using the Hard Light algorithm
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1.im.chop_hard_light(image2.im)) | [
"def",
"hard_light",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_hard_light",
"(",
"image2",
".",
"im",
")",
")"
] | [
151,
0
] | [
160,
60
] | python | en | ['en', 'error', 'th'] | False |
overlay | (image1, image2) |
Superimposes two images on top of each other using the Overlay algorithm
:rtype: :py:class:`~PIL.Image.Image`
|
Superimposes two images on top of each other using the Overlay algorithm | def overlay(image1, image2):
"""
Superimposes two images on top of each other using the Overlay algorithm
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1.im.chop_overlay(image2.im)) | [
"def",
"overlay",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_overlay",
"(",
"image2",
".",
"im",
")",
")"
] | [
163,
0
] | [
172,
57
] | python | en | ['en', 'error', 'th'] | False |
add | (image1, image2, scale=1.0, offset=0) |
Adds two images, dividing the result by scale and adding the
offset. If omitted, scale defaults to 1.0, and offset to 0.0.
.. code-block:: python
out = ((image1 + image2) / scale + offset)
:rtype: :py:class:`~PIL.Image.Image`
|
Adds two images, dividing the result by scale and adding the
offset. If omitted, scale defaults to 1.0, and offset to 0.0. | def add(image1, image2, scale=1.0, offset=0):
"""
Adds two images, dividing the result by scale and adding the
offset. If omitted, scale defaults to 1.0, and offset to 0.0.
.. code-block:: python
out = ((image1 + image2) / scale + offset)
:rtype: :py:class:`~PIL.Image.Image`
"""
... | [
"def",
"add",
"(",
"image1",
",",
"image2",
",",
"scale",
"=",
"1.0",
",",
"offset",
"=",
"0",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_add",... | [
175,
0
] | [
189,
68
] | python | en | ['en', 'error', 'th'] | False |
subtract | (image1, image2, scale=1.0, offset=0) |
Subtracts two images, dividing the result by scale and adding the offset.
If omitted, scale defaults to 1.0, and offset to 0.0.
.. code-block:: python
out = ((image1 - image2) / scale + offset)
:rtype: :py:class:`~PIL.Image.Image`
|
Subtracts two images, dividing the result by scale and adding the offset.
If omitted, scale defaults to 1.0, and offset to 0.0. | def subtract(image1, image2, scale=1.0, offset=0):
"""
Subtracts two images, dividing the result by scale and adding the offset.
If omitted, scale defaults to 1.0, and offset to 0.0.
.. code-block:: python
out = ((image1 - image2) / scale + offset)
:rtype: :py:class:`~PIL.Image.Image`
... | [
"def",
"subtract",
"(",
"image1",
",",
"image2",
",",
"scale",
"=",
"1.0",
",",
"offset",
"=",
"0",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_... | [
192,
0
] | [
206,
73
] | python | en | ['en', 'error', 'th'] | False |
add_modulo | (image1, image2) | Add two images, without clipping the result.
.. code-block:: python
out = ((image1 + image2) % MAX)
:rtype: :py:class:`~PIL.Image.Image`
| Add two images, without clipping the result. | def add_modulo(image1, image2):
"""Add two images, without clipping the result.
.. code-block:: python
out = ((image1 + image2) % MAX)
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1.im.chop_add_modulo(image2.im)) | [
"def",
"add_modulo",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_add_modulo",
"(",
"image2",
".",
"im",
")",
")"
] | [
209,
0
] | [
221,
60
] | python | en | ['en', 'en', 'en'] | True |
subtract_modulo | (image1, image2) | Subtract two images, without clipping the result.
.. code-block:: python
out = ((image1 - image2) % MAX)
:rtype: :py:class:`~PIL.Image.Image`
| Subtract two images, without clipping the result. | def subtract_modulo(image1, image2):
"""Subtract two images, without clipping the result.
.. code-block:: python
out = ((image1 - image2) % MAX)
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1.im.chop_subtract_modulo(image2.im)) | [
"def",
"subtract_modulo",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_subtract_modulo",
"(",
"image2",
".",
"im",
")",
... | [
224,
0
] | [
236,
65
] | python | en | ['en', 'en', 'en'] | True |
logical_and | (image1, image2) | Logical AND between two images.
Both of the images must have mode "1". If you would like to perform a
logical AND on an image with a mode other than "1", try
:py:meth:`~PIL.ImageChops.multiply` instead, using a black-and-white mask
as the second image.
.. code-block:: python
out = ((image... | Logical AND between two images. | def logical_and(image1, image2):
"""Logical AND between two images.
Both of the images must have mode "1". If you would like to perform a
logical AND on an image with a mode other than "1", try
:py:meth:`~PIL.ImageChops.multiply` instead, using a black-and-white mask
as the second image.
.. co... | [
"def",
"logical_and",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_and",
"(",
"image2",
".",
"im",
")",
")"
] | [
239,
0
] | [
256,
53
] | python | en | ['en', 'en', 'en'] | True |
logical_or | (image1, image2) | Logical OR between two images.
Both of the images must have mode "1".
.. code-block:: python
out = ((image1 or image2) % MAX)
:rtype: :py:class:`~PIL.Image.Image`
| Logical OR between two images. | def logical_or(image1, image2):
"""Logical OR between two images.
Both of the images must have mode "1".
.. code-block:: python
out = ((image1 or image2) % MAX)
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1.im.chop_or(image2.i... | [
"def",
"logical_or",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_or",
"(",
"image2",
".",
"im",
")",
")"
] | [
259,
0
] | [
273,
52
] | python | en | ['en', 'en', 'en'] | True |
logical_xor | (image1, image2) | Logical XOR between two images.
Both of the images must have mode "1".
.. code-block:: python
out = ((bool(image1) != bool(image2)) % MAX)
:rtype: :py:class:`~PIL.Image.Image`
| Logical XOR between two images. | def logical_xor(image1, image2):
"""Logical XOR between two images.
Both of the images must have mode "1".
.. code-block:: python
out = ((bool(image1) != bool(image2)) % MAX)
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1.im.ch... | [
"def",
"logical_xor",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_xor",
"(",
"image2",
".",
"im",
")",
")"
] | [
276,
0
] | [
290,
53
] | python | en | ['en', 'en', 'en'] | True |
blend | (image1, image2, alpha) | Blend images using constant transparency weight. Alias for
:py:meth:`PIL.Image.Image.blend`.
:rtype: :py:class:`~PIL.Image.Image`
| Blend images using constant transparency weight. Alias for
:py:meth:`PIL.Image.Image.blend`. | def blend(image1, image2, alpha):
"""Blend images using constant transparency weight. Alias for
:py:meth:`PIL.Image.Image.blend`.
:rtype: :py:class:`~PIL.Image.Image`
"""
return Image.blend(image1, image2, alpha) | [
"def",
"blend",
"(",
"image1",
",",
"image2",
",",
"alpha",
")",
":",
"return",
"Image",
".",
"blend",
"(",
"image1",
",",
"image2",
",",
"alpha",
")"
] | [
293,
0
] | [
300,
45
] | python | en | ['en', 'en', 'en'] | True |
composite | (image1, image2, mask) | Create composite using transparency mask. Alias for
:py:meth:`PIL.Image.Image.composite`.
:rtype: :py:class:`~PIL.Image.Image`
| Create composite using transparency mask. Alias for
:py:meth:`PIL.Image.Image.composite`. | def composite(image1, image2, mask):
"""Create composite using transparency mask. Alias for
:py:meth:`PIL.Image.Image.composite`.
:rtype: :py:class:`~PIL.Image.Image`
"""
return Image.composite(image1, image2, mask) | [
"def",
"composite",
"(",
"image1",
",",
"image2",
",",
"mask",
")",
":",
"return",
"Image",
".",
"composite",
"(",
"image1",
",",
"image2",
",",
"mask",
")"
] | [
303,
0
] | [
310,
48
] | python | en | ['en', 'en', 'en'] | True |
offset | (image, xoffset, yoffset=None) | Returns a copy of the image where data has been offset by the given
distances. Data wraps around the edges. If **yoffset** is omitted, it
is assumed to be equal to **xoffset**.
:param xoffset: The horizontal distance.
:param yoffset: The vertical distance. If omitted, both
distances are set to... | Returns a copy of the image where data has been offset by the given
distances. Data wraps around the edges. If **yoffset** is omitted, it
is assumed to be equal to **xoffset**. | def offset(image, xoffset, yoffset=None):
"""Returns a copy of the image where data has been offset by the given
distances. Data wraps around the edges. If **yoffset** is omitted, it
is assumed to be equal to **xoffset**.
:param xoffset: The horizontal distance.
:param yoffset: The vertical distanc... | [
"def",
"offset",
"(",
"image",
",",
"xoffset",
",",
"yoffset",
"=",
"None",
")",
":",
"if",
"yoffset",
"is",
"None",
":",
"yoffset",
"=",
"xoffset",
"image",
".",
"load",
"(",
")",
"return",
"image",
".",
"_new",
"(",
"image",
".",
"im",
".",
"offs... | [
313,
0
] | [
327,
56
] | python | en | ['en', 'en', 'en'] | True |
handle_reservation_save | (instance, **kwargs) |
Django signal handler for updating changed/created reservations on remote Exchanges.
:param instance: A Reservation instance
:type instance: resources.models.Reservation
:param kwargs: The rest of the signal args
:return:
|
Django signal handler for updating changed/created reservations on remote Exchanges. | def handle_reservation_save(instance, **kwargs):
"""
Django signal handler for updating changed/created reservations on remote Exchanges.
:param instance: A Reservation instance
:type instance: resources.models.Reservation
:param kwargs: The rest of the signal args
:return:
"""
if not g... | [
"def",
"handle_reservation_save",
"(",
"instance",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"getattr",
"(",
"settings",
",",
"\"RESPA_EXCHANGE_ENABLED\"",
",",
"True",
")",
":",
"return",
"if",
"getattr",
"(",
"instance",
",",
"\"_from_exchange\"",
",",... | [
7,
0
] | [
46,
50
] | python | en | ['en', 'error', 'th'] | False |
handle_reservation_delete | (instance, **kwargs) |
Django signal handler for deleting reservation-related appointments from Exchange
:param instance: A Reservation instance
:type instance: resources.models.Reservation
:param kwargs: The rest of the signal args
:return:
|
Django signal handler for deleting reservation-related appointments from Exchange | def handle_reservation_delete(instance, **kwargs):
"""
Django signal handler for deleting reservation-related appointments from Exchange
:param instance: A Reservation instance
:type instance: resources.models.Reservation
:param kwargs: The rest of the signal args
:return:
"""
if not ge... | [
"def",
"handle_reservation_delete",
"(",
"instance",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"getattr",
"(",
"settings",
",",
"\"RESPA_EXCHANGE_ENABLED\"",
",",
"True",
")",
":",
"return",
"with",
"transaction",
".",
"atomic",
"(",
")",
":",
"exchang... | [
49,
0
] | [
76,
46
] | python | en | ['en', 'error', 'th'] | False |
auth | (request) |
Return context variables required by apps that use Django's authentication
system.
If there is no 'user' attribute in the request, use AnonymousUser (from
django.contrib.auth).
|
Return context variables required by apps that use Django's authentication
system. | def auth(request):
"""
Return context variables required by apps that use Django's authentication
system.
If there is no 'user' attribute in the request, use AnonymousUser (from
django.contrib.auth).
"""
if hasattr(request, 'user'):
user = request.user
else:
from django.... | [
"def",
"auth",
"(",
"request",
")",
":",
"if",
"hasattr",
"(",
"request",
",",
"'user'",
")",
":",
"user",
"=",
"request",
".",
"user",
"else",
":",
"from",
"django",
".",
"contrib",
".",
"auth",
".",
"models",
"import",
"AnonymousUser",
"user",
"=",
... | [
45,
0
] | [
62,
5
] | python | en | ['en', 'error', 'th'] | False |
PermWrapper.__contains__ | (self, perm_name) |
Lookup by "someapp" or "someapp.someperm" in perms.
|
Lookup by "someapp" or "someapp.someperm" in perms.
| def __contains__(self, perm_name):
"""
Lookup by "someapp" or "someapp.someperm" in perms.
"""
if '.' not in perm_name:
# The name refers to module.
return bool(self[perm_name])
app_label, perm_name = perm_name.split('.', 1)
return self[app_label][... | [
"def",
"__contains__",
"(",
"self",
",",
"perm_name",
")",
":",
"if",
"'.'",
"not",
"in",
"perm_name",
":",
"# The name refers to module.",
"return",
"bool",
"(",
"self",
"[",
"perm_name",
"]",
")",
"app_label",
",",
"perm_name",
"=",
"perm_name",
".",
"spli... | [
34,
4
] | [
42,
41
] | python | en | ['en', 'error', 'th'] | False |
SpatialRefSysMixin.srs | (self) |
Return a GDAL SpatialReference object.
|
Return a GDAL SpatialReference object.
| def srs(self):
"""
Return a GDAL SpatialReference object.
"""
# TODO: Is caching really necessary here? Is complexity worth it?
if hasattr(self, '_srs'):
# Returning a clone of the cached SpatialReference object.
return self._srs.clone()
else:
... | [
"def",
"srs",
"(",
"self",
")",
":",
"# TODO: Is caching really necessary here? Is complexity worth it?",
"if",
"hasattr",
"(",
"self",
",",
"'_srs'",
")",
":",
"# Returning a clone of the cached SpatialReference object.",
"return",
"self",
".",
"_srs",
".",
"clone",
"("... | [
9,
4
] | [
33,
108
] | 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.