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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
require_auth | (view_func) | Performs user authentication check.
Similar to Django's `login_required` decorator, except that this throws
:exc:`~horizon.exceptions.NotAuthenticated` exception if the user is not
signed-in.
| Performs user authentication check. | def require_auth(view_func):
"""Performs user authentication check.
Similar to Django's `login_required` decorator, except that this throws
:exc:`~horizon.exceptions.NotAuthenticated` exception if the user is not
signed-in.
"""
from horizon.exceptions import NotAuthenticated
@functools.wra... | [
"def",
"require_auth",
"(",
"view_func",
")",
":",
"from",
"horizon",
".",
"exceptions",
"import",
"NotAuthenticated",
"@",
"functools",
".",
"wraps",
"(",
"view_func",
",",
"assigned",
"=",
"available_attrs",
"(",
"view_func",
")",
")",
"def",
"dec",
"(",
"... | [
39,
0
] | [
53,
14
] | python | en | ['en', 'en', 'en'] | True |
require_perms | (view_func, required) | Enforces permission-based access controls.
:param list required: A tuple of permission names, all of which the request
user must possess in order access the decorated view.
Example usage::
from horizon.decorators import require_perms
@require_perms(['foo.admin', 'f... | Enforces permission-based access controls. | def require_perms(view_func, required):
"""Enforces permission-based access controls.
:param list required: A tuple of permission names, all of which the request
user must possess in order access the decorated view.
Example usage::
from horizon.decorators import require_... | [
"def",
"require_perms",
"(",
"view_func",
",",
"required",
")",
":",
"from",
"horizon",
".",
"exceptions",
"import",
"NotAuthorized",
"# We only need to check each permission once for a view, so we'll use a set",
"current_perms",
"=",
"getattr",
"(",
"view_func",
",",
"'_re... | [
56,
0
] | [
91,
24
] | python | en | ['en', 'fr', 'en'] | True |
require_component_access | (view_func, component) | Perform component can_access check to access the view.
:param component containing the view (panel or dashboard).
Raises a :exc:`~horizon.exceptions.NotAuthorized` exception if the
user cannot access the component containing the view.
By example the check of component policy rules will be applied to i... | Perform component can_access check to access the view. | def require_component_access(view_func, component):
"""Perform component can_access check to access the view.
:param component containing the view (panel or dashboard).
Raises a :exc:`~horizon.exceptions.NotAuthorized` exception if the
user cannot access the component containing the view.
By examp... | [
"def",
"require_component_access",
"(",
"view_func",
",",
"component",
")",
":",
"from",
"horizon",
".",
"exceptions",
"import",
"NotAuthorized",
"@",
"functools",
".",
"wraps",
"(",
"view_func",
",",
"assigned",
"=",
"available_attrs",
"(",
"view_func",
")",
")... | [
94,
0
] | [
114,
14
] | python | en | ['en', 'en', 'en'] | True |
calc_num_logits | (action_space) | Returns the number of logits required to represent the given action space. | Returns the number of logits required to represent the given action space. | def calc_num_logits(action_space):
"""Returns the number of logits required to represent the given action space."""
if isinstance(action_space, gym.spaces.Discrete):
return action_space.n
elif isinstance(action_space, gym.spaces.Tuple):
return sum(space.n for space in action_space.spaces)
... | [
"def",
"calc_num_logits",
"(",
"action_space",
")",
":",
"if",
"isinstance",
"(",
"action_space",
",",
"gym",
".",
"spaces",
".",
"Discrete",
")",
":",
"return",
"action_space",
".",
"n",
"elif",
"isinstance",
"(",
"action_space",
",",
"gym",
".",
"spaces",
... | [
25,
0
] | [
35,
91
] | python | en | ['en', 'en', 'en'] | True |
get_action_distribution | (action_space, raw_logits) |
Create the distribution object based on provided action space and unprocessed logits.
:param action_space: Gym action space object
:param raw_logits: this function expects unprocessed raw logits (not after log-softmax!)
:return: action distribution that you can sample from
|
Create the distribution object based on provided action space and unprocessed logits.
:param action_space: Gym action space object
:param raw_logits: this function expects unprocessed raw logits (not after log-softmax!)
:return: action distribution that you can sample from
| def get_action_distribution(action_space, raw_logits):
"""
Create the distribution object based on provided action space and unprocessed logits.
:param action_space: Gym action space object
:param raw_logits: this function expects unprocessed raw logits (not after log-softmax!)
:return: action distr... | [
"def",
"get_action_distribution",
"(",
"action_space",
",",
"raw_logits",
")",
":",
"assert",
"calc_num_logits",
"(",
"action_space",
")",
"==",
"raw_logits",
".",
"shape",
"[",
"-",
"1",
"]",
"if",
"isinstance",
"(",
"action_space",
",",
"gym",
".",
"spaces",... | [
42,
0
] | [
58,
91
] | python | en | ['en', 'error', 'th'] | False |
CategoricalActionDistribution.__init__ | (self, raw_logits) |
Ctor.
:param raw_logits: unprocessed logits, typically an output of a fully-connected layer
|
Ctor.
:param raw_logits: unprocessed logits, typically an output of a fully-connected layer
| def __init__(self, raw_logits):
"""
Ctor.
:param raw_logits: unprocessed logits, typically an output of a fully-connected layer
"""
self.raw_logits = raw_logits
self.log_p = self.p = None | [
"def",
"__init__",
"(",
"self",
",",
"raw_logits",
")",
":",
"self",
".",
"raw_logits",
"=",
"raw_logits",
"self",
".",
"log_p",
"=",
"self",
".",
"p",
"=",
"None"
] | [
72,
4
] | [
79,
34
] | python | en | ['en', 'error', 'th'] | False |
check_message | (keywords, message) | Checks an exception for given keywords and raises an error if found.
It raises a new ``ActionError`` with the desired message if the
keywords are found. This allows selective
control over API error messages.
| Checks an exception for given keywords and raises an error if found. | def check_message(keywords, message):
"""Checks an exception for given keywords and raises an error if found.
It raises a new ``ActionError`` with the desired message if the
keywords are found. This allows selective
control over API error messages.
"""
exc_type, exc_value, exc_traceback = sys.e... | [
"def",
"check_message",
"(",
"keywords",
",",
"message",
")",
":",
"exc_type",
",",
"exc_value",
",",
"exc_traceback",
"=",
"sys",
".",
"exc_info",
"(",
")",
"if",
"set",
"(",
"str",
"(",
"exc_value",
")",
".",
"split",
"(",
"\" \"",
")",
")",
".",
"... | [
195,
0
] | [
207,
13
] | python | en | ['en', 'en', 'en'] | True |
handle | (request, message=None, redirect=None, ignore=False,
escalate=False, log_level=None, force_log=None) | Centralized error handling for Horizon.
Because Horizon consumes so many different APIs with completely
different ``Exception`` types, it's necessary to have a centralized
place for handling exceptions which may be raised.
Exceptions are roughly divided into 3 types:
#. ``UNAUTHORIZED``: Errors r... | Centralized error handling for Horizon. | def handle(request, message=None, redirect=None, ignore=False,
escalate=False, log_level=None, force_log=None):
"""Centralized error handling for Horizon.
Because Horizon consumes so many different APIs with completely
different ``Exception`` types, it's necessary to have a centralized
place... | [
"def",
"handle",
"(",
"request",
",",
"message",
"=",
"None",
",",
"redirect",
"=",
"None",
",",
"ignore",
"=",
"False",
",",
"escalate",
"=",
"False",
",",
"log_level",
"=",
"None",
",",
"force_log",
"=",
"None",
")",
":",
"exc_type",
",",
"exc_value"... | [
264,
0
] | [
347,
51
] | python | da | ['da', 'no', 'en'] | False |
_hash_of_file | (path, algorithm) | Return the hash digest of a file. | Return the hash digest of a file. | def _hash_of_file(path, algorithm):
# type: (str, str) -> str
"""Return the hash digest of a file."""
with open(path, 'rb') as archive:
hash = hashlib.new(algorithm)
for chunk in read_chunks(archive):
hash.update(chunk)
return hash.hexdigest() | [
"def",
"_hash_of_file",
"(",
"path",
",",
"algorithm",
")",
":",
"# type: (str, str) -> str",
"with",
"open",
"(",
"path",
",",
"'rb'",
")",
"as",
"archive",
":",
"hash",
"=",
"hashlib",
".",
"new",
"(",
"algorithm",
")",
"for",
"chunk",
"in",
"read_chunks... | [
55,
0
] | [
62,
27
] | python | en | ['en', 'en', 'en'] | True |
StudentCourse.jeeves_restrict_grade | (sc, ctxt) | Only the student can see the grade.
| Only the student can see the grade.
| def jeeves_restrict_grade(sc, ctxt):
"""Only the student can see the grade.
"""
return sc.student == ctxt or ctxt.is_instructor(sc.course) | [
"def",
"jeeves_restrict_grade",
"(",
"sc",
",",
"ctxt",
")",
":",
"return",
"sc",
".",
"student",
"==",
"ctxt",
"or",
"ctxt",
".",
"is_instructor",
"(",
"sc",
".",
"course",
")"
] | [
67,
4
] | [
70,
59
] | python | en | ['en', 'en', 'en'] | True |
fix_help_options | (options) | Convert a 4-tuple 'help_options' list as found in various command
classes to the 3-tuple form required by FancyGetopt.
| Convert a 4-tuple 'help_options' list as found in various command
classes to the 3-tuple form required by FancyGetopt.
| def fix_help_options(options):
"""Convert a 4-tuple 'help_options' list as found in various command
classes to the 3-tuple form required by FancyGetopt.
"""
new_options = []
for help_tuple in options:
new_options.append(help_tuple[0:3])
return new_options | [
"def",
"fix_help_options",
"(",
"options",
")",
":",
"new_options",
"=",
"[",
"]",
"for",
"help_tuple",
"in",
"options",
":",
"new_options",
".",
"append",
"(",
"help_tuple",
"[",
"0",
":",
"3",
"]",
")",
"return",
"new_options"
] | [
1249,
0
] | [
1256,
22
] | python | en | ['en', 'en', 'en'] | True |
Distribution.__init__ | (self, attrs=None) | Construct a new Distribution instance: initialize all the
attributes of a Distribution, and then use 'attrs' (a dictionary
mapping attribute names to values) to assign some of those
attributes their "real" values. (Any attributes not mentioned in
'attrs' will be assigned to some null va... | Construct a new Distribution instance: initialize all the
attributes of a Distribution, and then use 'attrs' (a dictionary
mapping attribute names to values) to assign some of those
attributes their "real" values. (Any attributes not mentioned in
'attrs' will be assigned to some null va... | def __init__(self, attrs=None):
"""Construct a new Distribution instance: initialize all the
attributes of a Distribution, and then use 'attrs' (a dictionary
mapping attribute names to values) to assign some of those
attributes their "real" values. (Any attributes not mentioned in
... | [
"def",
"__init__",
"(",
"self",
",",
"attrs",
"=",
"None",
")",
":",
"# Default values for our command-line options",
"self",
".",
"verbose",
"=",
"1",
"self",
".",
"dry_run",
"=",
"0",
"self",
".",
"help",
"=",
"0",
"for",
"attr",
"in",
"self",
".",
"di... | [
136,
4
] | [
292,
31
] | python | en | ['en', 'en', 'en'] | True |
Distribution.get_option_dict | (self, command) | Get the option dictionary for a given command. If that
command's option dictionary hasn't been created yet, then create it
and return the new dictionary; otherwise, return the existing
option dictionary.
| Get the option dictionary for a given command. If that
command's option dictionary hasn't been created yet, then create it
and return the new dictionary; otherwise, return the existing
option dictionary.
| def get_option_dict(self, command):
"""Get the option dictionary for a given command. If that
command's option dictionary hasn't been created yet, then create it
and return the new dictionary; otherwise, return the existing
option dictionary.
"""
dict = self.command_opti... | [
"def",
"get_option_dict",
"(",
"self",
",",
"command",
")",
":",
"dict",
"=",
"self",
".",
"command_options",
".",
"get",
"(",
"command",
")",
"if",
"dict",
"is",
"None",
":",
"dict",
"=",
"self",
".",
"command_options",
"[",
"command",
"]",
"=",
"{",
... | [
294,
4
] | [
303,
19
] | python | en | ['en', 'en', 'en'] | True |
Distribution.find_config_files | (self) | Find as many configuration files as should be processed for this
platform, and return a list of filenames in the order in which they
should be parsed. The filenames returned are guaranteed to exist
(modulo nasty race conditions).
There are three possible config files: distutils.cfg in ... | Find as many configuration files as should be processed for this
platform, and return a list of filenames in the order in which they
should be parsed. The filenames returned are guaranteed to exist
(modulo nasty race conditions). | def find_config_files(self):
"""Find as many configuration files as should be processed for this
platform, and return a list of filenames in the order in which they
should be parsed. The filenames returned are guaranteed to exist
(modulo nasty race conditions).
There are three ... | [
"def",
"find_config_files",
"(",
"self",
")",
":",
"files",
"=",
"[",
"]",
"check_environ",
"(",
")",
"# Where to look for the system-wide Distutils config file",
"sys_dir",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"sys",
".",
"modules",
"[",
"'distutils'",
... | [
333,
4
] | [
379,
20
] | python | en | ['en', 'en', 'en'] | True |
Distribution.parse_command_line | (self) | Parse the setup script's command line, taken from the
'script_args' instance attribute (which defaults to 'sys.argv[1:]'
-- see 'setup()' in core.py). This list is first processed for
"global options" -- options that set attributes of the Distribution
instance. Then, it is alternately ... | Parse the setup script's command line, taken from the
'script_args' instance attribute (which defaults to 'sys.argv[1:]'
-- see 'setup()' in core.py). This list is first processed for
"global options" -- options that set attributes of the Distribution
instance. Then, it is alternately ... | def parse_command_line(self):
"""Parse the setup script's command line, taken from the
'script_args' instance attribute (which defaults to 'sys.argv[1:]'
-- see 'setup()' in core.py). This list is first processed for
"global options" -- options that set attributes of the Distribution
... | [
"def",
"parse_command_line",
"(",
"self",
")",
":",
"#",
"# We now have enough information to show the Macintosh dialog",
"# that allows the user to interactively specify the \"command line\".",
"#",
"toplevel_options",
"=",
"self",
".",
"_get_toplevel_options",
"(",
")",
"# We hav... | [
439,
4
] | [
504,
19
] | python | en | ['en', 'en', 'en'] | True |
Distribution._get_toplevel_options | (self) | Return the non-display options recognized at the top level.
This includes options that are recognized *only* at the top
level as well as options recognized for commands.
| Return the non-display options recognized at the top level. | def _get_toplevel_options(self):
"""Return the non-display options recognized at the top level.
This includes options that are recognized *only* at the top
level as well as options recognized for commands.
"""
return self.global_options + [
("command-packages=", None... | [
"def",
"_get_toplevel_options",
"(",
"self",
")",
":",
"return",
"self",
".",
"global_options",
"+",
"[",
"(",
"\"command-packages=\"",
",",
"None",
",",
"\"list of packages that provide distutils commands\"",
")",
",",
"]"
] | [
506,
4
] | [
515,
13
] | python | en | ['en', 'en', 'en'] | True |
Distribution._parse_command_opts | (self, parser, args) | Parse the command-line options for a single command.
'parser' must be a FancyGetopt instance; 'args' must be the list
of arguments, starting with the current command (whose options
we are about to parse). Returns a new version of 'args' with
the next command at the front of the list; wi... | Parse the command-line options for a single command.
'parser' must be a FancyGetopt instance; 'args' must be the list
of arguments, starting with the current command (whose options
we are about to parse). Returns a new version of 'args' with
the next command at the front of the list; wi... | def _parse_command_opts(self, parser, args):
"""Parse the command-line options for a single command.
'parser' must be a FancyGetopt instance; 'args' must be the list
of arguments, starting with the current command (whose options
we are about to parse). Returns a new version of 'args' wi... | [
"def",
"_parse_command_opts",
"(",
"self",
",",
"parser",
",",
"args",
")",
":",
"# late import because of mutual dependence between these modules",
"from",
"distutils",
".",
"cmd",
"import",
"Command",
"# Pull the current command from the head of the command line",
"command",
... | [
517,
4
] | [
606,
19
] | python | en | ['en', 'en', 'en'] | True |
Distribution.finalize_options | (self) | Set final values for all the options on the Distribution
instance, analogous to the .finalize_options() method of Command
objects.
| Set final values for all the options on the Distribution
instance, analogous to the .finalize_options() method of Command
objects.
| def finalize_options(self):
"""Set final values for all the options on the Distribution
instance, analogous to the .finalize_options() method of Command
objects.
"""
for attr in ('keywords', 'platforms'):
value = getattr(self.metadata, attr)
if value is No... | [
"def",
"finalize_options",
"(",
"self",
")",
":",
"for",
"attr",
"in",
"(",
"'keywords'",
",",
"'platforms'",
")",
":",
"value",
"=",
"getattr",
"(",
"self",
".",
"metadata",
",",
"attr",
")",
"if",
"value",
"is",
"None",
":",
"continue",
"if",
"isinst... | [
608,
4
] | [
619,
51
] | python | en | ['en', 'en', 'en'] | True |
Distribution._show_help | (self, parser, global_options=1, display_options=1,
commands=[]) | Show help for the setup script command-line in the form of
several lists of command-line options. 'parser' should be a
FancyGetopt instance; do not expect it to be returned in the
same state, as its option table will be reset to make it
generate the correct help text.
If 'globa... | Show help for the setup script command-line in the form of
several lists of command-line options. 'parser' should be a
FancyGetopt instance; do not expect it to be returned in the
same state, as its option table will be reset to make it
generate the correct help text. | def _show_help(self, parser, global_options=1, display_options=1,
commands=[]):
"""Show help for the setup script command-line in the form of
several lists of command-line options. 'parser' should be a
FancyGetopt instance; do not expect it to be returned in the
same ... | [
"def",
"_show_help",
"(",
"self",
",",
"parser",
",",
"global_options",
"=",
"1",
",",
"display_options",
"=",
"1",
",",
"commands",
"=",
"[",
"]",
")",
":",
"# late import because of mutual dependence between these modules",
"from",
"distutils",
".",
"core",
"imp... | [
621,
4
] | [
669,
42
] | python | en | ['en', 'en', 'en'] | True |
Distribution.handle_display_options | (self, option_order) | If there were any non-global "display-only" options
(--help-commands or the metadata display options) on the command
line, display the requested info and return true; else return
false.
| If there were any non-global "display-only" options
(--help-commands or the metadata display options) on the command
line, display the requested info and return true; else return
false.
| def handle_display_options(self, option_order):
"""If there were any non-global "display-only" options
(--help-commands or the metadata display options) on the command
line, display the requested info and return true; else return
false.
"""
from distutils.core import gen_... | [
"def",
"handle_display_options",
"(",
"self",
",",
"option_order",
")",
":",
"from",
"distutils",
".",
"core",
"import",
"gen_usage",
"# User just wants a list of commands -- we'll print it out and stop",
"# processing now (ie. if they ran \"setup --help-commands foo bar\",",
"# we i... | [
671,
4
] | [
709,
34
] | python | en | ['en', 'en', 'en'] | True |
Distribution.print_command_list | (self, commands, header, max_length) | Print a subset of the list of all commands -- used by
'print_commands()'.
| Print a subset of the list of all commands -- used by
'print_commands()'.
| def print_command_list(self, commands, header, max_length):
"""Print a subset of the list of all commands -- used by
'print_commands()'.
"""
print(header + ":")
for cmd in commands:
klass = self.cmdclass.get(cmd)
if not klass:
klass = self... | [
"def",
"print_command_list",
"(",
"self",
",",
"commands",
",",
"header",
",",
"max_length",
")",
":",
"print",
"(",
"header",
"+",
"\":\"",
")",
"for",
"cmd",
"in",
"commands",
":",
"klass",
"=",
"self",
".",
"cmdclass",
".",
"get",
"(",
"cmd",
")",
... | [
711,
4
] | [
726,
64
] | python | en | ['en', 'en', 'en'] | True |
Distribution.print_commands | (self) | Print out a help message listing all available commands with a
description of each. The list is divided into "standard commands"
(listed in distutils.command.__all__) and "extra commands"
(mentioned in self.cmdclass, but not a standard command). The
descriptions come from the command c... | Print out a help message listing all available commands with a
description of each. The list is divided into "standard commands"
(listed in distutils.command.__all__) and "extra commands"
(mentioned in self.cmdclass, but not a standard command). The
descriptions come from the command c... | def print_commands(self):
"""Print out a help message listing all available commands with a
description of each. The list is divided into "standard commands"
(listed in distutils.command.__all__) and "extra commands"
(mentioned in self.cmdclass, but not a standard command). The
... | [
"def",
"print_commands",
"(",
"self",
")",
":",
"import",
"distutils",
".",
"command",
"std_commands",
"=",
"distutils",
".",
"command",
".",
"__all__",
"is_std",
"=",
"{",
"}",
"for",
"cmd",
"in",
"std_commands",
":",
"is_std",
"[",
"cmd",
"]",
"=",
"1"... | [
728,
4
] | [
759,
47
] | python | en | ['en', 'en', 'en'] | True |
Distribution.get_command_list | (self) | Get a list of (command, description) tuples.
The list is divided into "standard commands" (listed in
distutils.command.__all__) and "extra commands" (mentioned in
self.cmdclass, but not a standard command). The descriptions come
from the command class attribute 'description'.
| Get a list of (command, description) tuples.
The list is divided into "standard commands" (listed in
distutils.command.__all__) and "extra commands" (mentioned in
self.cmdclass, but not a standard command). The descriptions come
from the command class attribute 'description'.
| def get_command_list(self):
"""Get a list of (command, description) tuples.
The list is divided into "standard commands" (listed in
distutils.command.__all__) and "extra commands" (mentioned in
self.cmdclass, but not a standard command). The descriptions come
from the command cl... | [
"def",
"get_command_list",
"(",
"self",
")",
":",
"# Currently this is only used on Mac OS, for the Mac-only GUI",
"# Distutils interface (by Jack Jansen)",
"import",
"distutils",
".",
"command",
"std_commands",
"=",
"distutils",
".",
"command",
".",
"__all__",
"is_std",
"=",... | [
761,
4
] | [
791,
17
] | python | en | ['en', 'fr', 'en'] | True |
Distribution.get_command_packages | (self) | Return a list of packages from which commands are loaded. | Return a list of packages from which commands are loaded. | def get_command_packages(self):
"""Return a list of packages from which commands are loaded."""
pkgs = self.command_packages
if not isinstance(pkgs, list):
if pkgs is None:
pkgs = ''
pkgs = [pkg.strip() for pkg in pkgs.split(',') if pkg != '']
... | [
"def",
"get_command_packages",
"(",
"self",
")",
":",
"pkgs",
"=",
"self",
".",
"command_packages",
"if",
"not",
"isinstance",
"(",
"pkgs",
",",
"list",
")",
":",
"if",
"pkgs",
"is",
"None",
":",
"pkgs",
"=",
"''",
"pkgs",
"=",
"[",
"pkg",
".",
"stri... | [
795,
4
] | [
805,
19
] | python | en | ['en', 'en', 'en'] | True |
Distribution.get_command_class | (self, command) | Return the class that implements the Distutils command named by
'command'. First we check the 'cmdclass' dictionary; if the
command is mentioned there, we fetch the class object from the
dictionary and return it. Otherwise we load the command module
("distutils.command." + command) and... | Return the class that implements the Distutils command named by
'command'. First we check the 'cmdclass' dictionary; if the
command is mentioned there, we fetch the class object from the
dictionary and return it. Otherwise we load the command module
("distutils.command." + command) and... | def get_command_class(self, command):
"""Return the class that implements the Distutils command named by
'command'. First we check the 'cmdclass' dictionary; if the
command is mentioned there, we fetch the class object from the
dictionary and return it. Otherwise we load the command mo... | [
"def",
"get_command_class",
"(",
"self",
",",
"command",
")",
":",
"klass",
"=",
"self",
".",
"cmdclass",
".",
"get",
"(",
"command",
")",
"if",
"klass",
":",
"return",
"klass",
"for",
"pkgname",
"in",
"self",
".",
"get_command_packages",
"(",
")",
":",
... | [
807,
4
] | [
843,
68
] | python | en | ['en', 'en', 'en'] | True |
Distribution.get_command_obj | (self, command, create=1) | Return the command object for 'command'. Normally this object
is cached on a previous call to 'get_command_obj()'; if no command
object for 'command' is in the cache, then we either create and
return it (if 'create' is true) or return None.
| Return the command object for 'command'. Normally this object
is cached on a previous call to 'get_command_obj()'; if no command
object for 'command' is in the cache, then we either create and
return it (if 'create' is true) or return None.
| def get_command_obj(self, command, create=1):
"""Return the command object for 'command'. Normally this object
is cached on a previous call to 'get_command_obj()'; if no command
object for 'command' is in the cache, then we either create and
return it (if 'create' is true) or return Non... | [
"def",
"get_command_obj",
"(",
"self",
",",
"command",
",",
"create",
"=",
"1",
")",
":",
"cmd_obj",
"=",
"self",
".",
"command_obj",
".",
"get",
"(",
"command",
")",
"if",
"not",
"cmd_obj",
"and",
"create",
":",
"if",
"DEBUG",
":",
"self",
".",
"ann... | [
845,
4
] | [
870,
22
] | python | en | ['en', 'en', 'en'] | True |
Distribution._set_command_options | (self, command_obj, option_dict=None) | Set the options for 'command_obj' from 'option_dict'. Basically
this means copying elements of a dictionary ('option_dict') to
attributes of an instance ('command').
'command_obj' must be a Command instance. If 'option_dict' is not
supplied, uses the standard option dictionary for thi... | Set the options for 'command_obj' from 'option_dict'. Basically
this means copying elements of a dictionary ('option_dict') to
attributes of an instance ('command'). | def _set_command_options(self, command_obj, option_dict=None):
"""Set the options for 'command_obj' from 'option_dict'. Basically
this means copying elements of a dictionary ('option_dict') to
attributes of an instance ('command').
'command_obj' must be a Command instance. If 'option_... | [
"def",
"_set_command_options",
"(",
"self",
",",
"command_obj",
",",
"option_dict",
"=",
"None",
")",
":",
"command_name",
"=",
"command_obj",
".",
"get_command_name",
"(",
")",
"if",
"option_dict",
"is",
"None",
":",
"option_dict",
"=",
"self",
".",
"get_opti... | [
872,
4
] | [
914,
47
] | python | en | ['en', 'en', 'en'] | True |
Distribution.reinitialize_command | (self, command, reinit_subcommands=0) | Reinitializes a command to the state it was in when first
returned by 'get_command_obj()': ie., initialized but not yet
finalized. This provides the opportunity to sneak option
values in programmatically, overriding or supplementing
user-supplied values from the config files and command... | Reinitializes a command to the state it was in when first
returned by 'get_command_obj()': ie., initialized but not yet
finalized. This provides the opportunity to sneak option
values in programmatically, overriding or supplementing
user-supplied values from the config files and command... | def reinitialize_command(self, command, reinit_subcommands=0):
"""Reinitializes a command to the state it was in when first
returned by 'get_command_obj()': ie., initialized but not yet
finalized. This provides the opportunity to sneak option
values in programmatically, overriding or su... | [
"def",
"reinitialize_command",
"(",
"self",
",",
"command",
",",
"reinit_subcommands",
"=",
"0",
")",
":",
"from",
"distutils",
".",
"cmd",
"import",
"Command",
"if",
"not",
"isinstance",
"(",
"command",
",",
"Command",
")",
":",
"command_name",
"=",
"comman... | [
916,
4
] | [
953,
22
] | python | en | ['en', 'en', 'en'] | True |
Distribution.run_commands | (self) | Run each command that was seen on the setup script command line.
Uses the list of commands found and cache of command objects
created by 'get_command_obj()'.
| Run each command that was seen on the setup script command line.
Uses the list of commands found and cache of command objects
created by 'get_command_obj()'.
| def run_commands(self):
"""Run each command that was seen on the setup script command line.
Uses the list of commands found and cache of command objects
created by 'get_command_obj()'.
"""
for cmd in self.commands:
self.run_command(cmd) | [
"def",
"run_commands",
"(",
"self",
")",
":",
"for",
"cmd",
"in",
"self",
".",
"commands",
":",
"self",
".",
"run_command",
"(",
"cmd",
")"
] | [
960,
4
] | [
966,
33
] | python | en | ['en', 'en', 'en'] | True |
Distribution.run_command | (self, command) | Do whatever it takes to run a command (including nothing at all,
if the command has already been run). Specifically: if we have
already created and run the command named by 'command', return
silently without doing anything. If the command named by 'command'
doesn't even have a command ... | Do whatever it takes to run a command (including nothing at all,
if the command has already been run). Specifically: if we have
already created and run the command named by 'command', return
silently without doing anything. If the command named by 'command'
doesn't even have a command ... | def run_command(self, command):
"""Do whatever it takes to run a command (including nothing at all,
if the command has already been run). Specifically: if we have
already created and run the command named by 'command', return
silently without doing anything. If the command named by 'co... | [
"def",
"run_command",
"(",
"self",
",",
"command",
")",
":",
"# Already been here, done that? then return silently.",
"if",
"self",
".",
"have_run",
".",
"get",
"(",
"command",
")",
":",
"return",
"log",
".",
"info",
"(",
"\"running %s\"",
",",
"command",
")",
... | [
970,
4
] | [
986,
34
] | python | en | ['en', 'en', 'en'] | True |
DistributionMetadata.read_pkg_file | (self, file) | Reads the metadata values from a file object. | Reads the metadata values from a file object. | def read_pkg_file(self, file):
"""Reads the metadata values from a file object."""
msg = message_from_file(file)
def _read_field(name):
value = msg[name]
if value == 'UNKNOWN':
return None
return value
def _read_list(name):
... | [
"def",
"read_pkg_file",
"(",
"self",
",",
"file",
")",
":",
"msg",
"=",
"message_from_file",
"(",
"file",
")",
"def",
"_read_field",
"(",
"name",
")",
":",
"value",
"=",
"msg",
"[",
"name",
"]",
"if",
"value",
"==",
"'UNKNOWN'",
":",
"return",
"None",
... | [
1060,
4
] | [
1110,
33
] | python | en | ['en', 'en', 'en'] | True |
DistributionMetadata.write_pkg_info | (self, base_dir) | Write the PKG-INFO file into the release tree.
| Write the PKG-INFO file into the release tree.
| def write_pkg_info(self, base_dir):
"""Write the PKG-INFO file into the release tree.
"""
with open(os.path.join(base_dir, 'PKG-INFO'), 'w',
encoding='UTF-8') as pkg_info:
self.write_pkg_file(pkg_info) | [
"def",
"write_pkg_info",
"(",
"self",
",",
"base_dir",
")",
":",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"base_dir",
",",
"'PKG-INFO'",
")",
",",
"'w'",
",",
"encoding",
"=",
"'UTF-8'",
")",
"as",
"pkg_info",
":",
"self",
".",
"writ... | [
1112,
4
] | [
1117,
41
] | python | en | ['en', 'en', 'en'] | True |
DistributionMetadata.write_pkg_file | (self, file) | Write the PKG-INFO format data to a file object.
| Write the PKG-INFO format data to a file object.
| def write_pkg_file(self, file):
"""Write the PKG-INFO format data to a file object.
"""
version = '1.0'
if (self.provides or self.requires or self.obsoletes or
self.classifiers or self.download_url):
version = '1.1'
file.write('Metadata-Version: %s\n'... | [
"def",
"write_pkg_file",
"(",
"self",
",",
"file",
")",
":",
"version",
"=",
"'1.0'",
"if",
"(",
"self",
".",
"provides",
"or",
"self",
".",
"requires",
"or",
"self",
".",
"obsoletes",
"or",
"self",
".",
"classifiers",
"or",
"self",
".",
"download_url",
... | [
1119,
4
] | [
1151,
65
] | python | en | ['en', 'en', 'en'] | True |
format_command_result | (
command_args, # type: List[str]
command_output, # type: Text
) | Format command information for logging. | Format command information for logging. | def format_command_result(
command_args, # type: List[str]
command_output, # type: Text
):
# type: (...) -> str
"""Format command information for logging."""
command_desc = format_command_args(command_args)
text = 'Command arguments: {}\n'.format(command_desc)
if not command_output:
... | [
"def",
"format_command_result",
"(",
"command_args",
",",
"# type: List[str]",
"command_output",
",",
"# type: Text",
")",
":",
"# type: (...) -> str",
"command_desc",
"=",
"format_command_args",
"(",
"command_args",
")",
"text",
"=",
"'Command arguments: {}\\n'",
".",
"f... | [
20,
0
] | [
38,
15
] | python | en | ['en', 'da', 'en'] | True |
get_legacy_build_wheel_path | (
names, # type: List[str]
temp_dir, # type: str
name, # type: str
command_args, # type: List[str]
command_output, # type: Text
) | Return the path to the wheel in the temporary build directory. | Return the path to the wheel in the temporary build directory. | def get_legacy_build_wheel_path(
names, # type: List[str]
temp_dir, # type: str
name, # type: str
command_args, # type: List[str]
command_output, # type: Text
):
# type: (...) -> Optional[str]
"""Return the path to the wheel in the temporary build directory."""
# Sort for determinis... | [
"def",
"get_legacy_build_wheel_path",
"(",
"names",
",",
"# type: List[str]",
"temp_dir",
",",
"# type: str",
"name",
",",
"# type: str",
"command_args",
",",
"# type: List[str]",
"command_output",
",",
"# type: Text",
")",
":",
"# type: (...) -> Optional[str]",
"# Sort for... | [
41,
0
] | [
68,
43
] | python | en | ['en', 'en', 'en'] | True |
build_wheel_legacy | (
name, # type: str
setup_py_path, # type: str
source_dir, # type: str
global_options, # type: List[str]
build_options, # type: List[str]
tempd, # type: str
) | Build one unpacked package using the "legacy" build process.
Returns path to wheel if successfully built. Otherwise, returns None.
| Build one unpacked package using the "legacy" build process. | def build_wheel_legacy(
name, # type: str
setup_py_path, # type: str
source_dir, # type: str
global_options, # type: List[str]
build_options, # type: List[str]
tempd, # type: str
):
# type: (...) -> Optional[str]
"""Build one unpacked package using the "legacy" build process.
... | [
"def",
"build_wheel_legacy",
"(",
"name",
",",
"# type: str",
"setup_py_path",
",",
"# type: str",
"source_dir",
",",
"# type: str",
"global_options",
",",
"# type: List[str]",
"build_options",
",",
"# type: List[str]",
"tempd",
",",
"# type: str",
")",
":",
"# type: (.... | [
71,
0
] | [
114,
25
] | python | en | ['en', 'en', 'en'] | True |
requires_to_requires_dist | (requirement) | Return the version specifier for a requirement in PEP 345/566 fashion. | Return the version specifier for a requirement in PEP 345/566 fashion. | def requires_to_requires_dist(requirement):
"""Return the version specifier for a requirement in PEP 345/566 fashion."""
if getattr(requirement, 'url', None):
return " @ " + requirement.url
requires_dist = []
for op, ver in requirement.specs:
requires_dist.append(op + ver)
if not re... | [
"def",
"requires_to_requires_dist",
"(",
"requirement",
")",
":",
"if",
"getattr",
"(",
"requirement",
",",
"'url'",
",",
"None",
")",
":",
"return",
"\" @ \"",
"+",
"requirement",
".",
"url",
"requires_dist",
"=",
"[",
"]",
"for",
"op",
",",
"ver",
"in",
... | [
12,
0
] | [
22,
52
] | python | en | ['en', 'en', 'en'] | True |
convert_requirements | (requirements) | Yield Requires-Dist: strings for parsed requirements strings. | Yield Requires-Dist: strings for parsed requirements strings. | def convert_requirements(requirements):
"""Yield Requires-Dist: strings for parsed requirements strings."""
for req in requirements:
parsed_requirement = pkg_resources.Requirement.parse(req)
spec = requires_to_requires_dist(parsed_requirement)
extras = ",".join(sorted(parsed_requirement.... | [
"def",
"convert_requirements",
"(",
"requirements",
")",
":",
"for",
"req",
"in",
"requirements",
":",
"parsed_requirement",
"=",
"pkg_resources",
".",
"Requirement",
".",
"parse",
"(",
"req",
")",
"spec",
"=",
"requires_to_requires_dist",
"(",
"parsed_requirement",... | [
25,
0
] | [
33,
63
] | python | en | ['en', 'en', 'en'] | True |
generate_requirements | (extras_require) |
Convert requirements from a setup()-style dictionary to ('Requires-Dist', 'requirement')
and ('Provides-Extra', 'extra') tuples.
extras_require is a dictionary of {extra: [requirements]} as passed to setup(),
using the empty extra {'': [requirements]} to hold install_requires.
|
Convert requirements from a setup()-style dictionary to ('Requires-Dist', 'requirement')
and ('Provides-Extra', 'extra') tuples. | def generate_requirements(extras_require):
"""
Convert requirements from a setup()-style dictionary to ('Requires-Dist', 'requirement')
and ('Provides-Extra', 'extra') tuples.
extras_require is a dictionary of {extra: [requirements]} as passed to setup(),
using the empty extra {'': [requirements]} ... | [
"def",
"generate_requirements",
"(",
"extras_require",
")",
":",
"for",
"extra",
",",
"depends",
"in",
"extras_require",
".",
"items",
"(",
")",
":",
"condition",
"=",
"''",
"extra",
"=",
"extra",
"or",
"''",
"if",
"':'",
"in",
"extra",
":",
"# setuptools ... | [
36,
0
] | [
61,
54
] | python | en | ['en', 'error', 'th'] | False |
pkginfo_to_metadata | (egg_info_path, pkginfo_path) |
Convert .egg-info directory with PKG-INFO to the Metadata 2.1 format
|
Convert .egg-info directory with PKG-INFO to the Metadata 2.1 format
| def pkginfo_to_metadata(egg_info_path, pkginfo_path):
"""
Convert .egg-info directory with PKG-INFO to the Metadata 2.1 format
"""
pkg_info = read_pkg_info(pkginfo_path)
pkg_info.replace_header('Metadata-Version', '2.1')
# Those will be regenerated from `requires.txt`.
del pkg_info['Provides... | [
"def",
"pkginfo_to_metadata",
"(",
"egg_info_path",
",",
"pkginfo_path",
")",
":",
"pkg_info",
"=",
"read_pkg_info",
"(",
"pkginfo_path",
")",
"pkg_info",
".",
"replace_header",
"(",
"'Metadata-Version'",
",",
"'2.1'",
")",
"# Those will be regenerated from `requires.txt`... | [
64,
0
] | [
90,
19
] | python | en | ['en', 'error', 'th'] | False |
pkginfo_unicode | (pkg_info, field) | Hack to coax Unicode out of an email Message() - Python 3.3+ | Hack to coax Unicode out of an email Message() - Python 3.3+ | def pkginfo_unicode(pkg_info, field):
"""Hack to coax Unicode out of an email Message() - Python 3.3+"""
text = pkg_info[field]
field = field.lower()
if not isinstance(text, str):
for item in pkg_info.raw_items():
if item[0].lower() == field:
text = item[1].encode('as... | [
"def",
"pkginfo_unicode",
"(",
"pkg_info",
",",
"field",
")",
":",
"text",
"=",
"pkg_info",
"[",
"field",
"]",
"field",
"=",
"field",
".",
"lower",
"(",
")",
"if",
"not",
"isinstance",
"(",
"text",
",",
"str",
")",
":",
"for",
"item",
"in",
"pkg_info... | [
93,
0
] | [
104,
15
] | python | en | ['en', 'en', 'en'] | True |
dedent_description | (pkg_info) |
Dedent and convert pkg_info['Description'] to Unicode.
|
Dedent and convert pkg_info['Description'] to Unicode.
| def dedent_description(pkg_info):
"""
Dedent and convert pkg_info['Description'] to Unicode.
"""
description = pkg_info['Description']
# Python 3 Unicode handling, sorta.
surrogates = False
if not isinstance(description, str):
surrogates = True
description = pkginfo_unicode(... | [
"def",
"dedent_description",
"(",
"pkg_info",
")",
":",
"description",
"=",
"pkg_info",
"[",
"'Description'",
"]",
"# Python 3 Unicode handling, sorta.",
"surrogates",
"=",
"False",
"if",
"not",
"isinstance",
"(",
"description",
",",
"str",
")",
":",
"surrogates",
... | [
107,
0
] | [
132,
29
] | python | en | ['en', 'error', 'th'] | False |
search_packages_info | (query) |
Gather details from installed distributions. Print distribution name,
version, location, and installed files. Installed files requires a
pip generated 'installed-files.txt' in the distributions '.egg-info'
directory.
|
Gather details from installed distributions. Print distribution name,
version, location, and installed files. Installed files requires a
pip generated 'installed-files.txt' in the distributions '.egg-info'
directory.
| def search_packages_info(query):
# type: (List[str]) -> Iterator[Dict[str, str]]
"""
Gather details from installed distributions. Print distribution name,
version, location, and installed files. Installed files requires a
pip generated 'installed-files.txt' in the distributions '.egg-info'
direc... | [
"def",
"search_packages_info",
"(",
"query",
")",
":",
"# type: (List[str]) -> Iterator[Dict[str, str]]",
"installed",
"=",
"{",
"}",
"for",
"p",
"in",
"pkg_resources",
".",
"working_set",
":",
"installed",
"[",
"canonicalize_name",
"(",
"p",
".",
"project_name",
")... | [
57,
0
] | [
144,
21
] | python | en | ['en', 'error', 'th'] | False |
print_results | (distributions, list_files=False, verbose=False) |
Print the information from installed distributions found.
|
Print the information from installed distributions found.
| def print_results(distributions, list_files=False, verbose=False):
# type: (Iterator[Dict[str, str]], bool, bool) -> bool
"""
Print the information from installed distributions found.
"""
results_printed = False
for i, dist in enumerate(distributions):
results_printed = True
if i... | [
"def",
"print_results",
"(",
"distributions",
",",
"list_files",
"=",
"False",
",",
"verbose",
"=",
"False",
")",
":",
"# type: (Iterator[Dict[str, str]], bool, bool) -> bool",
"results_printed",
"=",
"False",
"for",
"i",
",",
"dist",
"in",
"enumerate",
"(",
"distri... | [
147,
0
] | [
185,
26
] | python | en | ['en', 'error', 'th'] | False |
test_invalid_options_show_extra_information | (testdir) | display extra information when pytest exits due to unrecognized
options in the command-line | display extra information when pytest exits due to unrecognized
options in the command-line | def test_invalid_options_show_extra_information(testdir):
"""display extra information when pytest exits due to unrecognized
options in the command-line"""
testdir.makeini("""
[pytest]
addopts = --invalid-option
""")
result = testdir.runpytest()
result.stderr.fnmatch_lines([
... | [
"def",
"test_invalid_options_show_extra_information",
"(",
"testdir",
")",
":",
"testdir",
".",
"makeini",
"(",
"\"\"\"\n [pytest]\n addopts = --invalid-option\n \"\"\"",
")",
"result",
"=",
"testdir",
".",
"runpytest",
"(",
")",
"result",
".",
"stderr",
... | [
517,
0
] | [
529,
6
] | python | en | ['en', 'en', 'en'] | True |
test_consider_args_after_options_for_rootdir_and_inifile | (testdir, args) |
Consider all arguments in the command-line for rootdir and inifile
discovery, even if they happen to occur after an option. #949
|
Consider all arguments in the command-line for rootdir and inifile
discovery, even if they happen to occur after an option. #949
| def test_consider_args_after_options_for_rootdir_and_inifile(testdir, args):
"""
Consider all arguments in the command-line for rootdir and inifile
discovery, even if they happen to occur after an option. #949
"""
# replace "dir1" and "dir2" from "args" into their real directory
root = testdir.t... | [
"def",
"test_consider_args_after_options_for_rootdir_and_inifile",
"(",
"testdir",
",",
"args",
")",
":",
"# replace \"dir1\" and \"dir2\" from \"args\" into their real directory",
"root",
"=",
"testdir",
".",
"tmpdir",
".",
"mkdir",
"(",
"'myroot'",
")",
"d1",
"=",
"root",... | [
538,
0
] | [
554,
64
] | python | en | ['en', 'error', 'th'] | False |
TestParseIni.test_getcfg_empty_path | (self) | correctly handle zero length arguments (a la pytest '') | correctly handle zero length arguments (a la pytest '') | def test_getcfg_empty_path(self):
"""correctly handle zero length arguments (a la pytest '')"""
getcfg(['']) | [
"def",
"test_getcfg_empty_path",
"(",
"self",
")",
":",
"getcfg",
"(",
"[",
"''",
"]",
")"
] | [
26,
4
] | [
28,
20
] | python | en | ['en', 'fr', 'en'] | True |
TestConfigAPI.test_confcutdir_check_isdir | (self, testdir) | Give an error if --confcutdir is not a valid directory (#2078) | Give an error if --confcutdir is not a valid directory (#2078) | def test_confcutdir_check_isdir(self, testdir):
"""Give an error if --confcutdir is not a valid directory (#2078)"""
with pytest.raises(pytest.UsageError):
testdir.parseconfig('--confcutdir', testdir.tmpdir.join('file').ensure(file=1))
with pytest.raises(pytest.UsageError):
... | [
"def",
"test_confcutdir_check_isdir",
"(",
"self",
",",
"testdir",
")",
":",
"with",
"pytest",
".",
"raises",
"(",
"pytest",
".",
"UsageError",
")",
":",
"testdir",
".",
"parseconfig",
"(",
"'--confcutdir'",
",",
"testdir",
".",
"tmpdir",
".",
"join",
"(",
... | [
309,
4
] | [
316,
80
] | python | en | ['en', 'en', 'en'] | True |
TestConfigFromdictargs.test_origargs | (self) | Show that fromdictargs can handle args in their "orig" format | Show that fromdictargs can handle args in their "orig" format | def test_origargs(self):
"""Show that fromdictargs can handle args in their "orig" format"""
from _pytest.config import Config
option_dict = {}
args = ['-vvvv', '-s', 'a', 'b']
config = Config.fromdictargs(option_dict, args)
assert config.args == ['a', 'b']
asser... | [
"def",
"test_origargs",
"(",
"self",
")",
":",
"from",
"_pytest",
".",
"config",
"import",
"Config",
"option_dict",
"=",
"{",
"}",
"args",
"=",
"[",
"'-vvvv'",
",",
"'-s'",
",",
"'a'",
",",
"'b'",
"]",
"config",
"=",
"Config",
".",
"fromdictargs",
"(",... | [
347,
4
] | [
357,
44
] | python | en | ['en', 'en', 'en'] | True |
TestOverrideIniArgs.test_override_ini_handled_asap | (self, testdir, with_ini) | -o should be handled as soon as possible and always override what's in ini files (#2238) | -o should be handled as soon as possible and always override what's in ini files (#2238) | def test_override_ini_handled_asap(self, testdir, with_ini):
"""-o should be handled as soon as possible and always override what's in ini files (#2238)"""
if with_ini:
testdir.makeini("""
[pytest]
python_files=test_*.py
""")
testdir.makepy... | [
"def",
"test_override_ini_handled_asap",
"(",
"self",
",",
"testdir",
",",
"with_ini",
")",
":",
"if",
"with_ini",
":",
"testdir",
".",
"makeini",
"(",
"\"\"\"\n [pytest]\n python_files=test_*.py\n \"\"\"",
")",
"testdir",
".",
"make... | [
818,
4
] | [
830,
54
] | python | en | ['en', 'en', 'en'] | True |
TestOverrideIniArgs.test_override_ini_does_not_contain_paths | (self) | Check that -o no longer swallows all options after it (#3103) | Check that -o no longer swallows all options after it (#3103) | def test_override_ini_does_not_contain_paths(self):
"""Check that -o no longer swallows all options after it (#3103)"""
from _pytest.config import get_config
config = get_config()
config._preparse(['-o', 'cache_dir=/cache', '/some/test/path'])
assert config._override_ini == ['cac... | [
"def",
"test_override_ini_does_not_contain_paths",
"(",
"self",
")",
":",
"from",
"_pytest",
".",
"config",
"import",
"get_config",
"config",
"=",
"get_config",
"(",
")",
"config",
".",
"_preparse",
"(",
"[",
"'-o'",
",",
"'cache_dir=/cache'",
",",
"'/some/test/pa... | [
872,
4
] | [
877,
59
] | python | en | ['en', 'en', 'en'] | True |
TestOverrideIniArgs.test_multiple_override_ini_options | (self, testdir, request) | Ensure a file path following a '-o' option does not generate an error (#3103) | Ensure a file path following a '-o' option does not generate an error (#3103) | def test_multiple_override_ini_options(self, testdir, request):
"""Ensure a file path following a '-o' option does not generate an error (#3103)"""
testdir.makepyfile(**{
"conftest.py": """
def pytest_addoption(parser):
parser.addini('foo', default=None, h... | [
"def",
"test_multiple_override_ini_options",
"(",
"self",
",",
"testdir",
",",
"request",
")",
":",
"testdir",
".",
"makepyfile",
"(",
"*",
"*",
"{",
"\"conftest.py\"",
":",
"\"\"\"\n def pytest_addoption(parser):\n parser.addini('foo', default... | [
879,
4
] | [
902,
10
] | python | en | ['en', 'en', 'en'] | True |
TestRuleList.test_paths_in_rules | (self) | Verifies that the paths mentioned in linter rules actually exist | Verifies that the paths mentioned in linter rules actually exist | def test_paths_in_rules(self) -> None:
"""Verifies that the paths mentioned in linter rules actually exist"""
for rule in self.all_rules:
for path in rule.get("exclude", {}):
abs_path = os.path.abspath(os.path.join(ROOT_DIR, path))
self.assertTrue(
... | [
"def",
"test_paths_in_rules",
"(",
"self",
")",
"->",
"None",
":",
"for",
"rule",
"in",
"self",
".",
"all_rules",
":",
"for",
"path",
"in",
"rule",
".",
"get",
"(",
"\"exclude\"",
",",
"{",
"}",
")",
":",
"abs_path",
"=",
"os",
".",
"path",
".",
"a... | [
19,
4
] | [
41,
21
] | python | en | ['en', 'en', 'en'] | True |
TestRuleList.test_rule_patterns | (self) | Verifies that the search regex specified in a custom rule actually matches
the expectation and doesn't throw false positives. | Verifies that the search regex specified in a custom rule actually matches
the expectation and doesn't throw false positives. | def test_rule_patterns(self) -> None:
"""Verifies that the search regex specified in a custom rule actually matches
the expectation and doesn't throw false positives."""
for rule in self.all_rules:
pattern = rule["pattern"]
for line in rule.get("good_lines", []):
... | [
"def",
"test_rule_patterns",
"(",
"self",
")",
"->",
"None",
":",
"for",
"rule",
"in",
"self",
".",
"all_rules",
":",
"pattern",
"=",
"rule",
"[",
"\"pattern\"",
"]",
"for",
"line",
"in",
"rule",
".",
"get",
"(",
"\"good_lines\"",
",",
"[",
"]",
")",
... | [
43,
4
] | [
73,
21
] | python | en | ['en', 'en', 'en'] | True |
stn | (s, length, encoding, errors) | Convert a string to a null-terminated bytes object.
| Convert a string to a null-terminated bytes object.
| def stn(s, length, encoding, errors):
"""Convert a string to a null-terminated bytes object.
"""
s = s.encode(encoding, errors)
return s[:length] + (length - len(s)) * NUL | [
"def",
"stn",
"(",
"s",
",",
"length",
",",
"encoding",
",",
"errors",
")",
":",
"s",
"=",
"s",
".",
"encode",
"(",
"encoding",
",",
"errors",
")",
"return",
"s",
"[",
":",
"length",
"]",
"+",
"(",
"length",
"-",
"len",
"(",
"s",
")",
")",
"*... | [
159,
0
] | [
163,
47
] | python | en | ['en', 'en', 'en'] | True |
nts | (s, encoding, errors) | Convert a null-terminated bytes object to a string.
| Convert a null-terminated bytes object to a string.
| def nts(s, encoding, errors):
"""Convert a null-terminated bytes object to a string.
"""
p = s.find(b"\0")
if p != -1:
s = s[:p]
return s.decode(encoding, errors) | [
"def",
"nts",
"(",
"s",
",",
"encoding",
",",
"errors",
")",
":",
"p",
"=",
"s",
".",
"find",
"(",
"b\"\\0\"",
")",
"if",
"p",
"!=",
"-",
"1",
":",
"s",
"=",
"s",
"[",
":",
"p",
"]",
"return",
"s",
".",
"decode",
"(",
"encoding",
",",
"erro... | [
165,
0
] | [
171,
37
] | python | en | ['en', 'en', 'en'] | True |
nti | (s) | Convert a number field to a python number.
| Convert a number field to a python number.
| def nti(s):
"""Convert a number field to a python number.
"""
# There are two possible encodings for a number field, see
# itn() below.
if s[0] in (0o200, 0o377):
n = 0
for i in range(len(s) - 1):
n <<= 8
n += s[i + 1]
if s[0] == 0o377:
n =... | [
"def",
"nti",
"(",
"s",
")",
":",
"# There are two possible encodings for a number field, see",
"# itn() below.",
"if",
"s",
"[",
"0",
"]",
"in",
"(",
"0o200",
",",
"0o377",
")",
":",
"n",
"=",
"0",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"s",
")",
... | [
173,
0
] | [
191,
12
] | python | en | ['en', 'en', 'en'] | True |
itn | (n, digits=8, format=DEFAULT_FORMAT) | Convert a python number to a number field.
| Convert a python number to a number field.
| def itn(n, digits=8, format=DEFAULT_FORMAT):
"""Convert a python number to a number field.
"""
# POSIX 1003.1-1988 requires numbers to be encoded as a string of
# octal digits followed by a null-byte, this allows values up to
# (8**(digits-1))-1. GNU tar allows storing numbers greater than
# tha... | [
"def",
"itn",
"(",
"n",
",",
"digits",
"=",
"8",
",",
"format",
"=",
"DEFAULT_FORMAT",
")",
":",
"# POSIX 1003.1-1988 requires numbers to be encoded as a string of",
"# octal digits followed by a null-byte, this allows values up to",
"# (8**(digits-1))-1. GNU tar allows storing numbe... | [
193,
0
] | [
220,
12
] | python | en | ['en', 'en', 'en'] | True |
calc_chksums | (buf) | Calculate the checksum for a member's header by summing up all
characters except for the chksum field which is treated as if
it was filled with spaces. According to the GNU tar sources,
some tars (Sun and NeXT) calculate chksum with signed char,
which will be different if there are chars in ... | Calculate the checksum for a member's header by summing up all
characters except for the chksum field which is treated as if
it was filled with spaces. According to the GNU tar sources,
some tars (Sun and NeXT) calculate chksum with signed char,
which will be different if there are chars in ... | def calc_chksums(buf):
"""Calculate the checksum for a member's header by summing up all
characters except for the chksum field which is treated as if
it was filled with spaces. According to the GNU tar sources,
some tars (Sun and NeXT) calculate chksum with signed char,
which will be di... | [
"def",
"calc_chksums",
"(",
"buf",
")",
":",
"unsigned_chksum",
"=",
"256",
"+",
"sum",
"(",
"struct",
".",
"unpack_from",
"(",
"\"148B8x356B\"",
",",
"buf",
")",
")",
"signed_chksum",
"=",
"256",
"+",
"sum",
"(",
"struct",
".",
"unpack_from",
"(",
"\"14... | [
222,
0
] | [
233,
41
] | python | en | ['en', 'en', 'en'] | True |
copyfileobj | (src, dst, length=None, exception=OSError, bufsize=None) | Copy length bytes from fileobj src to fileobj dst.
If length is None, copy the entire content.
| Copy length bytes from fileobj src to fileobj dst.
If length is None, copy the entire content.
| def copyfileobj(src, dst, length=None, exception=OSError, bufsize=None):
"""Copy length bytes from fileobj src to fileobj dst.
If length is None, copy the entire content.
"""
bufsize = bufsize or 16 * 1024
if length == 0:
return
if length is None:
shutil.copyfileobj(src, dst, ... | [
"def",
"copyfileobj",
"(",
"src",
",",
"dst",
",",
"length",
"=",
"None",
",",
"exception",
"=",
"OSError",
",",
"bufsize",
"=",
"None",
")",
":",
"bufsize",
"=",
"bufsize",
"or",
"16",
"*",
"1024",
"if",
"length",
"==",
"0",
":",
"return",
"if",
"... | [
235,
0
] | [
258,
10
] | python | en | ['en', 'pt', 'en'] | True |
filemode | (mode) | Deprecated in this location; use stat.filemode. | Deprecated in this location; use stat.filemode. | def filemode(mode):
"""Deprecated in this location; use stat.filemode."""
import warnings
warnings.warn("deprecated in favor of stat.filemode",
DeprecationWarning, 2)
return stat.filemode(mode) | [
"def",
"filemode",
"(",
"mode",
")",
":",
"import",
"warnings",
"warnings",
".",
"warn",
"(",
"\"deprecated in favor of stat.filemode\"",
",",
"DeprecationWarning",
",",
"2",
")",
"return",
"stat",
".",
"filemode",
"(",
"mode",
")"
] | [
260,
0
] | [
265,
30
] | python | en | ['en', 'en', 'en'] | True |
is_tarfile | (name) | Return True if name points to a tar archive that we
are able to handle, else return False.
| Return True if name points to a tar archive that we
are able to handle, else return False.
| def is_tarfile(name):
"""Return True if name points to a tar archive that we
are able to handle, else return False.
"""
try:
t = open(name)
t.close()
return True
except TarError:
return False | [
"def",
"is_tarfile",
"(",
"name",
")",
":",
"try",
":",
"t",
"=",
"open",
"(",
"name",
")",
"t",
".",
"close",
"(",
")",
"return",
"True",
"except",
"TarError",
":",
"return",
"False"
] | [
2442,
0
] | [
2451,
20
] | python | en | ['en', 'en', 'en'] | True |
_Stream.__init__ | (self, name, mode, comptype, fileobj, bufsize) | Construct a _Stream object.
| Construct a _Stream object.
| def __init__(self, name, mode, comptype, fileobj, bufsize):
"""Construct a _Stream object.
"""
self._extfileobj = True
if fileobj is None:
fileobj = _LowLevelFile(name, mode)
self._extfileobj = False
if comptype == '*':
# Enable transparent co... | [
"def",
"__init__",
"(",
"self",
",",
"name",
",",
"mode",
",",
"comptype",
",",
"fileobj",
",",
"bufsize",
")",
":",
"self",
".",
"_extfileobj",
"=",
"True",
"if",
"fileobj",
"is",
"None",
":",
"fileobj",
"=",
"_LowLevelFile",
"(",
"name",
",",
"mode",... | [
346,
4
] | [
414,
17
] | python | en | ['en', 'en', 'en'] | True |
_Stream._init_write_gz | (self) | Initialize for writing with gzip compression.
| Initialize for writing with gzip compression.
| def _init_write_gz(self):
"""Initialize for writing with gzip compression.
"""
self.cmp = self.zlib.compressobj(9, self.zlib.DEFLATED,
-self.zlib.MAX_WBITS,
self.zlib.DEF_MEM_LEVEL,
... | [
"def",
"_init_write_gz",
"(",
"self",
")",
":",
"self",
".",
"cmp",
"=",
"self",
".",
"zlib",
".",
"compressobj",
"(",
"9",
",",
"self",
".",
"zlib",
".",
"DEFLATED",
",",
"-",
"self",
".",
"zlib",
".",
"MAX_WBITS",
",",
"self",
".",
"zlib",
".",
... | [
420,
4
] | [
432,
69
] | python | en | ['en', 'en', 'en'] | True |
_Stream.write | (self, s) | Write string s to the stream.
| Write string s to the stream.
| def write(self, s):
"""Write string s to the stream.
"""
if self.comptype == "gz":
self.crc = self.zlib.crc32(s, self.crc)
self.pos += len(s)
if self.comptype != "tar":
s = self.cmp.compress(s)
self.__write(s) | [
"def",
"write",
"(",
"self",
",",
"s",
")",
":",
"if",
"self",
".",
"comptype",
"==",
"\"gz\"",
":",
"self",
".",
"crc",
"=",
"self",
".",
"zlib",
".",
"crc32",
"(",
"s",
",",
"self",
".",
"crc",
")",
"self",
".",
"pos",
"+=",
"len",
"(",
"s"... | [
434,
4
] | [
442,
23
] | python | en | ['en', 'en', 'en'] | True |
_Stream.__write | (self, s) | Write string s to the stream if a whole new block
is ready to be written.
| Write string s to the stream if a whole new block
is ready to be written.
| def __write(self, s):
"""Write string s to the stream if a whole new block
is ready to be written.
"""
self.buf += s
while len(self.buf) > self.bufsize:
self.fileobj.write(self.buf[:self.bufsize])
self.buf = self.buf[self.bufsize:] | [
"def",
"__write",
"(",
"self",
",",
"s",
")",
":",
"self",
".",
"buf",
"+=",
"s",
"while",
"len",
"(",
"self",
".",
"buf",
")",
">",
"self",
".",
"bufsize",
":",
"self",
".",
"fileobj",
".",
"write",
"(",
"self",
".",
"buf",
"[",
":",
"self",
... | [
444,
4
] | [
451,
46
] | python | en | ['en', 'en', 'en'] | True |
_Stream.close | (self) | Close the _Stream object. No operation should be
done on it afterwards.
| Close the _Stream object. No operation should be
done on it afterwards.
| def close(self):
"""Close the _Stream object. No operation should be
done on it afterwards.
"""
if self.closed:
return
self.closed = True
try:
if self.mode == "w" and self.comptype != "tar":
self.buf += self.cmp.flush()
... | [
"def",
"close",
"(",
"self",
")",
":",
"if",
"self",
".",
"closed",
":",
"return",
"self",
".",
"closed",
"=",
"True",
"try",
":",
"if",
"self",
".",
"mode",
"==",
"\"w\"",
"and",
"self",
".",
"comptype",
"!=",
"\"tar\"",
":",
"self",
".",
"buf",
... | [
453,
4
] | [
473,
36
] | python | en | ['en', 'en', 'en'] | True |
_Stream._init_read_gz | (self) | Initialize for reading a gzip compressed fileobj.
| Initialize for reading a gzip compressed fileobj.
| def _init_read_gz(self):
"""Initialize for reading a gzip compressed fileobj.
"""
self.cmp = self.zlib.decompressobj(-self.zlib.MAX_WBITS)
self.dbuf = b""
# taken from gzip.GzipFile with some alterations
if self.__read(2) != b"\037\213":
raise ReadError("not ... | [
"def",
"_init_read_gz",
"(",
"self",
")",
":",
"self",
".",
"cmp",
"=",
"self",
".",
"zlib",
".",
"decompressobj",
"(",
"-",
"self",
".",
"zlib",
".",
"MAX_WBITS",
")",
"self",
".",
"dbuf",
"=",
"b\"\"",
"# taken from gzip.GzipFile with some alterations",
"i... | [
475,
4
] | [
504,
26
] | python | en | ['en', 'en', 'pt'] | True |
_Stream.tell | (self) | Return the stream's file pointer position.
| Return the stream's file pointer position.
| def tell(self):
"""Return the stream's file pointer position.
"""
return self.pos | [
"def",
"tell",
"(",
"self",
")",
":",
"return",
"self",
".",
"pos"
] | [
506,
4
] | [
509,
23
] | python | en | ['en', 'en', 'en'] | True |
_Stream.seek | (self, pos=0) | Set the stream's file pointer to pos. Negative seeking
is forbidden.
| Set the stream's file pointer to pos. Negative seeking
is forbidden.
| def seek(self, pos=0):
"""Set the stream's file pointer to pos. Negative seeking
is forbidden.
"""
if pos - self.pos >= 0:
blocks, remainder = divmod(pos - self.pos, self.bufsize)
for i in range(blocks):
self.read(self.bufsize)
self.... | [
"def",
"seek",
"(",
"self",
",",
"pos",
"=",
"0",
")",
":",
"if",
"pos",
"-",
"self",
".",
"pos",
">=",
"0",
":",
"blocks",
",",
"remainder",
"=",
"divmod",
"(",
"pos",
"-",
"self",
".",
"pos",
",",
"self",
".",
"bufsize",
")",
"for",
"i",
"i... | [
511,
4
] | [
522,
23
] | python | en | ['en', 'en', 'en'] | True |
_Stream.read | (self, size=None) | Return the next size number of bytes from the stream.
If size is not defined, return all bytes of the stream
up to EOF.
| Return the next size number of bytes from the stream.
If size is not defined, return all bytes of the stream
up to EOF.
| def read(self, size=None):
"""Return the next size number of bytes from the stream.
If size is not defined, return all bytes of the stream
up to EOF.
"""
if size is None:
t = []
while True:
buf = self._read(self.bufsize)
... | [
"def",
"read",
"(",
"self",
",",
"size",
"=",
"None",
")",
":",
"if",
"size",
"is",
"None",
":",
"t",
"=",
"[",
"]",
"while",
"True",
":",
"buf",
"=",
"self",
".",
"_read",
"(",
"self",
".",
"bufsize",
")",
"if",
"not",
"buf",
":",
"break",
"... | [
524,
4
] | [
540,
18
] | python | en | ['en', 'en', 'en'] | True |
_Stream._read | (self, size) | Return size bytes from the stream.
| Return size bytes from the stream.
| def _read(self, size):
"""Return size bytes from the stream.
"""
if self.comptype == "tar":
return self.__read(size)
c = len(self.dbuf)
while c < size:
buf = self.__read(self.bufsize)
if not buf:
break
try:
... | [
"def",
"_read",
"(",
"self",
",",
"size",
")",
":",
"if",
"self",
".",
"comptype",
"==",
"\"tar\"",
":",
"return",
"self",
".",
"__read",
"(",
"size",
")",
"c",
"=",
"len",
"(",
"self",
".",
"dbuf",
")",
"while",
"c",
"<",
"size",
":",
"buf",
"... | [
542,
4
] | [
561,
18
] | python | en | ['en', 'en', 'en'] | True |
_Stream.__read | (self, size) | Return size bytes from stream. If internal buffer is empty,
read another block from the stream.
| Return size bytes from stream. If internal buffer is empty,
read another block from the stream.
| def __read(self, size):
"""Return size bytes from stream. If internal buffer is empty,
read another block from the stream.
"""
c = len(self.buf)
while c < size:
buf = self.fileobj.read(self.bufsize)
if not buf:
break
self.buf... | [
"def",
"__read",
"(",
"self",
",",
"size",
")",
":",
"c",
"=",
"len",
"(",
"self",
".",
"buf",
")",
"while",
"c",
"<",
"size",
":",
"buf",
"=",
"self",
".",
"fileobj",
".",
"read",
"(",
"self",
".",
"bufsize",
")",
"if",
"not",
"buf",
":",
"b... | [
563,
4
] | [
576,
18
] | python | en | ['en', 'fy', 'en'] | True |
_FileInFile.tell | (self) | Return the current file position.
| Return the current file position.
| def tell(self):
"""Return the current file position.
"""
return self.position | [
"def",
"tell",
"(",
"self",
")",
":",
"return",
"self",
".",
"position"
] | [
652,
4
] | [
655,
28
] | python | en | ['en', 'en', 'en'] | True |
_FileInFile.seek | (self, position, whence=io.SEEK_SET) | Seek to a position in the file.
| Seek to a position in the file.
| def seek(self, position, whence=io.SEEK_SET):
"""Seek to a position in the file.
"""
if whence == io.SEEK_SET:
self.position = min(max(position, 0), self.size)
elif whence == io.SEEK_CUR:
if position < 0:
self.position = max(self.position + positio... | [
"def",
"seek",
"(",
"self",
",",
"position",
",",
"whence",
"=",
"io",
".",
"SEEK_SET",
")",
":",
"if",
"whence",
"==",
"io",
".",
"SEEK_SET",
":",
"self",
".",
"position",
"=",
"min",
"(",
"max",
"(",
"position",
",",
"0",
")",
",",
"self",
".",... | [
657,
4
] | [
671,
28
] | python | en | ['en', 'en', 'en'] | True |
_FileInFile.read | (self, size=None) | Read data from the file.
| Read data from the file.
| def read(self, size=None):
"""Read data from the file.
"""
if size is None:
size = self.size - self.position
else:
size = min(size, self.size - self.position)
buf = b""
while size > 0:
while True:
data, start, stop, off... | [
"def",
"read",
"(",
"self",
",",
"size",
"=",
"None",
")",
":",
"if",
"size",
"is",
"None",
":",
"size",
"=",
"self",
".",
"size",
"-",
"self",
".",
"position",
"else",
":",
"size",
"=",
"min",
"(",
"size",
",",
"self",
".",
"size",
"-",
"self"... | [
673,
4
] | [
702,
18
] | python | en | ['en', 'en', 'en'] | True |
TarInfo.__init__ | (self, name="") | Construct a TarInfo object. name is the optional name
of the member.
| Construct a TarInfo object. name is the optional name
of the member.
| def __init__(self, name=""):
"""Construct a TarInfo object. name is the optional name
of the member.
"""
self.name = name # member name
self.mode = 0o644 # file permissions
self.uid = 0 # user id
self.gid = 0 # group id
... | [
"def",
"__init__",
"(",
"self",
",",
"name",
"=",
"\"\"",
")",
":",
"self",
".",
"name",
"=",
"name",
"# member name",
"self",
".",
"mode",
"=",
"0o644",
"# file permissions",
"self",
".",
"uid",
"=",
"0",
"# user id",
"self",
".",
"gid",
"=",
"0",
"... | [
738,
4
] | [
760,
29
] | python | en | ['en', 'en', 'en'] | True |
TarInfo.get_info | (self) | Return the TarInfo's attributes as a dictionary.
| Return the TarInfo's attributes as a dictionary.
| def get_info(self):
"""Return the TarInfo's attributes as a dictionary.
"""
info = {
"name": self.name,
"mode": self.mode & 0o7777,
"uid": self.uid,
"gid": self.gid,
"size": self.size,
"mtime": self.... | [
"def",
"get_info",
"(",
"self",
")",
":",
"info",
"=",
"{",
"\"name\"",
":",
"self",
".",
"name",
",",
"\"mode\"",
":",
"self",
".",
"mode",
"&",
"0o7777",
",",
"\"uid\"",
":",
"self",
".",
"uid",
",",
"\"gid\"",
":",
"self",
".",
"gid",
",",
"\"... | [
779,
4
] | [
801,
19
] | python | en | ['en', 'en', 'en'] | True |
TarInfo.tobuf | (self, format=DEFAULT_FORMAT, encoding=ENCODING, errors="surrogateescape") | Return a tar header as a string of 512 byte blocks.
| Return a tar header as a string of 512 byte blocks.
| def tobuf(self, format=DEFAULT_FORMAT, encoding=ENCODING, errors="surrogateescape"):
"""Return a tar header as a string of 512 byte blocks.
"""
info = self.get_info()
if format == USTAR_FORMAT:
return self.create_ustar_header(info, encoding, errors)
elif format == GN... | [
"def",
"tobuf",
"(",
"self",
",",
"format",
"=",
"DEFAULT_FORMAT",
",",
"encoding",
"=",
"ENCODING",
",",
"errors",
"=",
"\"surrogateescape\"",
")",
":",
"info",
"=",
"self",
".",
"get_info",
"(",
")",
"if",
"format",
"==",
"USTAR_FORMAT",
":",
"return",
... | [
803,
4
] | [
815,
46
] | python | en | ['en', 'cy', 'en'] | True |
TarInfo.create_ustar_header | (self, info, encoding, errors) | Return the object as a ustar header block.
| Return the object as a ustar header block.
| def create_ustar_header(self, info, encoding, errors):
"""Return the object as a ustar header block.
"""
info["magic"] = POSIX_MAGIC
if len(info["linkname"].encode(encoding, errors)) > LENGTH_LINK:
raise ValueError("linkname is too long")
if len(info["name"].encode(... | [
"def",
"create_ustar_header",
"(",
"self",
",",
"info",
",",
"encoding",
",",
"errors",
")",
":",
"info",
"[",
"\"magic\"",
"]",
"=",
"POSIX_MAGIC",
"if",
"len",
"(",
"info",
"[",
"\"linkname\"",
"]",
".",
"encode",
"(",
"encoding",
",",
"errors",
")",
... | [
817,
4
] | [
828,
72
] | python | en | ['en', 'ga', 'en'] | True |
TarInfo.create_gnu_header | (self, info, encoding, errors) | Return the object as a GNU header block sequence.
| Return the object as a GNU header block sequence.
| def create_gnu_header(self, info, encoding, errors):
"""Return the object as a GNU header block sequence.
"""
info["magic"] = GNU_MAGIC
buf = b""
if len(info["linkname"].encode(encoding, errors)) > LENGTH_LINK:
buf += self._create_gnu_long_header(info["linkname"], GN... | [
"def",
"create_gnu_header",
"(",
"self",
",",
"info",
",",
"encoding",
",",
"errors",
")",
":",
"info",
"[",
"\"magic\"",
"]",
"=",
"GNU_MAGIC",
"buf",
"=",
"b\"\"",
"if",
"len",
"(",
"info",
"[",
"\"linkname\"",
"]",
".",
"encode",
"(",
"encoding",
",... | [
830,
4
] | [
842,
76
] | python | en | ['en', 'en', 'en'] | True |
TarInfo.create_pax_header | (self, info, encoding) | Return the object as a ustar header block. If it cannot be
represented this way, prepend a pax extended header sequence
with supplement information.
| Return the object as a ustar header block. If it cannot be
represented this way, prepend a pax extended header sequence
with supplement information.
| def create_pax_header(self, info, encoding):
"""Return the object as a ustar header block. If it cannot be
represented this way, prepend a pax extended header sequence
with supplement information.
"""
info["magic"] = POSIX_MAGIC
pax_headers = self.pax_headers.copy()... | [
"def",
"create_pax_header",
"(",
"self",
",",
"info",
",",
"encoding",
")",
":",
"info",
"[",
"\"magic\"",
"]",
"=",
"POSIX_MAGIC",
"pax_headers",
"=",
"self",
".",
"pax_headers",
".",
"copy",
"(",
")",
"# Test string fields for values that exceed the field length o... | [
844,
4
] | [
891,
80
] | python | en | ['en', 'en', 'en'] | True |
TarInfo.create_pax_global_header | (cls, pax_headers) | Return the object as a pax global header block sequence.
| Return the object as a pax global header block sequence.
| def create_pax_global_header(cls, pax_headers):
"""Return the object as a pax global header block sequence.
"""
return cls._create_pax_generic_header(pax_headers, XGLTYPE, "utf-8") | [
"def",
"create_pax_global_header",
"(",
"cls",
",",
"pax_headers",
")",
":",
"return",
"cls",
".",
"_create_pax_generic_header",
"(",
"pax_headers",
",",
"XGLTYPE",
",",
"\"utf-8\"",
")"
] | [
894,
4
] | [
897,
76
] | python | en | ['en', 'en', 'en'] | True |
TarInfo._posix_split_name | (self, name, encoding, errors) | Split a name longer than 100 chars into a prefix
and a name part.
| Split a name longer than 100 chars into a prefix
and a name part.
| def _posix_split_name(self, name, encoding, errors):
"""Split a name longer than 100 chars into a prefix
and a name part.
"""
components = name.split("/")
for i in range(1, len(components)):
prefix = "/".join(components[:i])
name = "/".join(components[i... | [
"def",
"_posix_split_name",
"(",
"self",
",",
"name",
",",
"encoding",
",",
"errors",
")",
":",
"components",
"=",
"name",
".",
"split",
"(",
"\"/\"",
")",
"for",
"i",
"in",
"range",
"(",
"1",
",",
"len",
"(",
"components",
")",
")",
":",
"prefix",
... | [
899,
4
] | [
913,
27
] | python | en | ['en', 'ht', 'en'] | True |
TarInfo._create_header | (info, format, encoding, errors) | Return a header block. info is a dictionary with file
information, format must be one of the *_FORMAT constants.
| Return a header block. info is a dictionary with file
information, format must be one of the *_FORMAT constants.
| def _create_header(info, format, encoding, errors):
"""Return a header block. info is a dictionary with file
information, format must be one of the *_FORMAT constants.
"""
parts = [
stn(info.get("name", ""), 100, encoding, errors),
itn(info.get("mode", 0) & 0o7... | [
"def",
"_create_header",
"(",
"info",
",",
"format",
",",
"encoding",
",",
"errors",
")",
":",
"parts",
"=",
"[",
"stn",
"(",
"info",
".",
"get",
"(",
"\"name\"",
",",
"\"\"",
")",
",",
"100",
",",
"encoding",
",",
"errors",
")",
",",
"itn",
"(",
... | [
916,
4
] | [
941,
18
] | python | en | ['en', 'en', 'en'] | True |
TarInfo._create_payload | (payload) | Return the string payload filled with zero bytes
up to the next 512 byte border.
| Return the string payload filled with zero bytes
up to the next 512 byte border.
| def _create_payload(payload):
"""Return the string payload filled with zero bytes
up to the next 512 byte border.
"""
blocks, remainder = divmod(len(payload), BLOCKSIZE)
if remainder > 0:
payload += (BLOCKSIZE - remainder) * NUL
return payload | [
"def",
"_create_payload",
"(",
"payload",
")",
":",
"blocks",
",",
"remainder",
"=",
"divmod",
"(",
"len",
"(",
"payload",
")",
",",
"BLOCKSIZE",
")",
"if",
"remainder",
">",
"0",
":",
"payload",
"+=",
"(",
"BLOCKSIZE",
"-",
"remainder",
")",
"*",
"NUL... | [
944,
4
] | [
951,
22
] | python | en | ['en', 'en', 'en'] | True |
TarInfo._create_gnu_long_header | (cls, name, type, encoding, errors) | Return a GNUTYPE_LONGNAME or GNUTYPE_LONGLINK sequence
for name.
| Return a GNUTYPE_LONGNAME or GNUTYPE_LONGLINK sequence
for name.
| def _create_gnu_long_header(cls, name, type, encoding, errors):
"""Return a GNUTYPE_LONGNAME or GNUTYPE_LONGLINK sequence
for name.
"""
name = name.encode(encoding, errors) + NUL
info = {}
info["name"] = "././@LongLink"
info["type"] = type
info["size"]... | [
"def",
"_create_gnu_long_header",
"(",
"cls",
",",
"name",
",",
"type",
",",
"encoding",
",",
"errors",
")",
":",
"name",
"=",
"name",
".",
"encode",
"(",
"encoding",
",",
"errors",
")",
"+",
"NUL",
"info",
"=",
"{",
"}",
"info",
"[",
"\"name\"",
"]"... | [
954,
4
] | [
968,
41
] | python | en | ['en', 'en', 'en'] | True |
TarInfo._create_pax_generic_header | (cls, pax_headers, type, encoding) | Return a POSIX.1-2008 extended or global header sequence
that contains a list of keyword, value pairs. The values
must be strings.
| Return a POSIX.1-2008 extended or global header sequence
that contains a list of keyword, value pairs. The values
must be strings.
| def _create_pax_generic_header(cls, pax_headers, type, encoding):
"""Return a POSIX.1-2008 extended or global header sequence
that contains a list of keyword, value pairs. The values
must be strings.
"""
# Check if one of the fields contains surrogate characters and thereby... | [
"def",
"_create_pax_generic_header",
"(",
"cls",
",",
"pax_headers",
",",
"type",
",",
"encoding",
")",
":",
"# Check if one of the fields contains surrogate characters and thereby",
"# forces hdrcharset=BINARY, see _proc_pax() for more information.",
"binary",
"=",
"False",
"for",... | [
971,
4
] | [
1019,
44
] | python | en | ['en', 'en', 'en'] | True |
TarInfo.frombuf | (cls, buf, encoding, errors) | Construct a TarInfo object from a 512 byte bytes object.
| Construct a TarInfo object from a 512 byte bytes object.
| def frombuf(cls, buf, encoding, errors):
"""Construct a TarInfo object from a 512 byte bytes object.
"""
if len(buf) == 0:
raise EmptyHeaderError("empty header")
if len(buf) != BLOCKSIZE:
raise TruncatedHeaderError("truncated header")
if buf.count(NUL) == ... | [
"def",
"frombuf",
"(",
"cls",
",",
"buf",
",",
"encoding",
",",
"errors",
")",
":",
"if",
"len",
"(",
"buf",
")",
"==",
"0",
":",
"raise",
"EmptyHeaderError",
"(",
"\"empty header\"",
")",
"if",
"len",
"(",
"buf",
")",
"!=",
"BLOCKSIZE",
":",
"raise"... | [
1022,
4
] | [
1082,
18
] | python | en | ['en', 'en', 'en'] | True |
TarInfo.fromtarfile | (cls, tarfile) | Return the next TarInfo object from TarFile object
tarfile.
| Return the next TarInfo object from TarFile object
tarfile.
| def fromtarfile(cls, tarfile):
"""Return the next TarInfo object from TarFile object
tarfile.
"""
buf = tarfile.fileobj.read(BLOCKSIZE)
obj = cls.frombuf(buf, tarfile.encoding, tarfile.errors)
obj.offset = tarfile.fileobj.tell() - BLOCKSIZE
return obj._proc_mem... | [
"def",
"fromtarfile",
"(",
"cls",
",",
"tarfile",
")",
":",
"buf",
"=",
"tarfile",
".",
"fileobj",
".",
"read",
"(",
"BLOCKSIZE",
")",
"obj",
"=",
"cls",
".",
"frombuf",
"(",
"buf",
",",
"tarfile",
".",
"encoding",
",",
"tarfile",
".",
"errors",
")",... | [
1085,
4
] | [
1092,
40
] | python | en | ['en', 'en', 'en'] | True |
TarInfo._proc_member | (self, tarfile) | Choose the right processing method depending on
the type and call it.
| Choose the right processing method depending on
the type and call it.
| def _proc_member(self, tarfile):
"""Choose the right processing method depending on
the type and call it.
"""
if self.type in (GNUTYPE_LONGNAME, GNUTYPE_LONGLINK):
return self._proc_gnulong(tarfile)
elif self.type == GNUTYPE_SPARSE:
return self._proc_sp... | [
"def",
"_proc_member",
"(",
"self",
",",
"tarfile",
")",
":",
"if",
"self",
".",
"type",
"in",
"(",
"GNUTYPE_LONGNAME",
",",
"GNUTYPE_LONGLINK",
")",
":",
"return",
"self",
".",
"_proc_gnulong",
"(",
"tarfile",
")",
"elif",
"self",
".",
"type",
"==",
"GN... | [
1105,
4
] | [
1116,
46
] | python | en | ['en', 'en', 'en'] | True |
TarInfo._proc_builtin | (self, tarfile) | Process a builtin type or an unknown type which
will be treated as a regular file.
| Process a builtin type or an unknown type which
will be treated as a regular file.
| def _proc_builtin(self, tarfile):
"""Process a builtin type or an unknown type which
will be treated as a regular file.
"""
self.offset_data = tarfile.fileobj.tell()
offset = self.offset_data
if self.isreg() or self.type not in SUPPORTED_TYPES:
# Skip the f... | [
"def",
"_proc_builtin",
"(",
"self",
",",
"tarfile",
")",
":",
"self",
".",
"offset_data",
"=",
"tarfile",
".",
"fileobj",
".",
"tell",
"(",
")",
"offset",
"=",
"self",
".",
"offset_data",
"if",
"self",
".",
"isreg",
"(",
")",
"or",
"self",
".",
"typ... | [
1118,
4
] | [
1133,
19
] | python | en | ['en', 'en', 'en'] | True |
TarInfo._proc_gnulong | (self, tarfile) | Process the blocks that hold a GNU longname
or longlink member.
| Process the blocks that hold a GNU longname
or longlink member.
| def _proc_gnulong(self, tarfile):
"""Process the blocks that hold a GNU longname
or longlink member.
"""
buf = tarfile.fileobj.read(self._block(self.size))
# Fetch the next header and process it.
try:
next = self.fromtarfile(tarfile)
except HeaderE... | [
"def",
"_proc_gnulong",
"(",
"self",
",",
"tarfile",
")",
":",
"buf",
"=",
"tarfile",
".",
"fileobj",
".",
"read",
"(",
"self",
".",
"_block",
"(",
"self",
".",
"size",
")",
")",
"# Fetch the next header and process it.",
"try",
":",
"next",
"=",
"self",
... | [
1135,
4
] | [
1155,
19
] | python | en | ['en', 'en', 'en'] | True |
TarInfo._proc_sparse | (self, tarfile) | Process a GNU sparse header plus extra headers.
| Process a GNU sparse header plus extra headers.
| def _proc_sparse(self, tarfile):
"""Process a GNU sparse header plus extra headers.
"""
# We already collected some sparse structures in frombuf().
structs, isextended, origsize = self._sparse_structs
del self._sparse_structs
# Collect sparse structures from extended hea... | [
"def",
"_proc_sparse",
"(",
"self",
",",
"tarfile",
")",
":",
"# We already collected some sparse structures in frombuf().",
"structs",
",",
"isextended",
",",
"origsize",
"=",
"self",
".",
"_sparse_structs",
"del",
"self",
".",
"_sparse_structs",
"# Collect sparse struct... | [
1157,
4
] | [
1183,
19
] | python | en | ['en', 'en', 'en'] | True |
TarInfo._proc_pax | (self, tarfile) | Process an extended or global header as described in
POSIX.1-2008.
| Process an extended or global header as described in
POSIX.1-2008.
| def _proc_pax(self, tarfile):
"""Process an extended or global header as described in
POSIX.1-2008.
"""
# Read the header information.
buf = tarfile.fileobj.read(self._block(self.size))
# A pax header stores supplemental information for either
# the following ... | [
"def",
"_proc_pax",
"(",
"self",
",",
"tarfile",
")",
":",
"# Read the header information.",
"buf",
"=",
"tarfile",
".",
"fileobj",
".",
"read",
"(",
"self",
".",
"_block",
"(",
"self",
".",
"size",
")",
")",
"# A pax header stores supplemental information for eit... | [
1185,
4
] | [
1285,
19
] | python | en | ['en', 'en', 'en'] | True |
TarInfo._proc_gnusparse_00 | (self, next, pax_headers, buf) | Process a GNU tar extended sparse header, version 0.0.
| Process a GNU tar extended sparse header, version 0.0.
| def _proc_gnusparse_00(self, next, pax_headers, buf):
"""Process a GNU tar extended sparse header, version 0.0.
"""
offsets = []
for match in re.finditer(br"\d+ GNU.sparse.offset=(\d+)\n", buf):
offsets.append(int(match.group(1)))
numbytes = []
for match in re... | [
"def",
"_proc_gnusparse_00",
"(",
"self",
",",
"next",
",",
"pax_headers",
",",
"buf",
")",
":",
"offsets",
"=",
"[",
"]",
"for",
"match",
"in",
"re",
".",
"finditer",
"(",
"br\"\\d+ GNU.sparse.offset=(\\d+)\\n\"",
",",
"buf",
")",
":",
"offsets",
".",
"ap... | [
1287,
4
] | [
1296,
50
] | python | en | ['en', 'en', 'en'] | True |
TarInfo._proc_gnusparse_01 | (self, next, pax_headers) | Process a GNU tar extended sparse header, version 0.1.
| Process a GNU tar extended sparse header, version 0.1.
| def _proc_gnusparse_01(self, next, pax_headers):
"""Process a GNU tar extended sparse header, version 0.1.
"""
sparse = [int(x) for x in pax_headers["GNU.sparse.map"].split(",")]
next.sparse = list(zip(sparse[::2], sparse[1::2])) | [
"def",
"_proc_gnusparse_01",
"(",
"self",
",",
"next",
",",
"pax_headers",
")",
":",
"sparse",
"=",
"[",
"int",
"(",
"x",
")",
"for",
"x",
"in",
"pax_headers",
"[",
"\"GNU.sparse.map\"",
"]",
".",
"split",
"(",
"\",\"",
")",
"]",
"next",
".",
"sparse",... | [
1298,
4
] | [
1302,
58
] | python | en | ['en', 'en', 'en'] | True |
TarInfo._proc_gnusparse_10 | (self, next, pax_headers, tarfile) | Process a GNU tar extended sparse header, version 1.0.
| Process a GNU tar extended sparse header, version 1.0.
| def _proc_gnusparse_10(self, next, pax_headers, tarfile):
"""Process a GNU tar extended sparse header, version 1.0.
"""
fields = None
sparse = []
buf = tarfile.fileobj.read(BLOCKSIZE)
fields, buf = buf.split(b"\n", 1)
fields = int(fields)
while len(sparse)... | [
"def",
"_proc_gnusparse_10",
"(",
"self",
",",
"next",
",",
"pax_headers",
",",
"tarfile",
")",
":",
"fields",
"=",
"None",
"sparse",
"=",
"[",
"]",
"buf",
"=",
"tarfile",
".",
"fileobj",
".",
"read",
"(",
"BLOCKSIZE",
")",
"fields",
",",
"buf",
"=",
... | [
1304,
4
] | [
1318,
58
] | python | en | ['en', 'en', 'en'] | True |
TarInfo._apply_pax_info | (self, pax_headers, encoding, errors) | Replace fields with supplemental information from a previous
pax extended or global header.
| Replace fields with supplemental information from a previous
pax extended or global header.
| def _apply_pax_info(self, pax_headers, encoding, errors):
"""Replace fields with supplemental information from a previous
pax extended or global header.
"""
for keyword, value in pax_headers.items():
if keyword == "GNU.sparse.name":
setattr(self, "path", va... | [
"def",
"_apply_pax_info",
"(",
"self",
",",
"pax_headers",
",",
"encoding",
",",
"errors",
")",
":",
"for",
"keyword",
",",
"value",
"in",
"pax_headers",
".",
"items",
"(",
")",
":",
"if",
"keyword",
"==",
"\"GNU.sparse.name\"",
":",
"setattr",
"(",
"self"... | [
1320,
4
] | [
1341,
45
] | python | en | ['en', 'en', 'en'] | True |
TarInfo._decode_pax_field | (self, value, encoding, fallback_encoding, fallback_errors) | Decode a single field from a pax record.
| Decode a single field from a pax record.
| def _decode_pax_field(self, value, encoding, fallback_encoding, fallback_errors):
"""Decode a single field from a pax record.
"""
try:
return value.decode(encoding, "strict")
except UnicodeDecodeError:
return value.decode(fallback_encoding, fallback_errors) | [
"def",
"_decode_pax_field",
"(",
"self",
",",
"value",
",",
"encoding",
",",
"fallback_encoding",
",",
"fallback_errors",
")",
":",
"try",
":",
"return",
"value",
".",
"decode",
"(",
"encoding",
",",
"\"strict\"",
")",
"except",
"UnicodeDecodeError",
":",
"ret... | [
1343,
4
] | [
1349,
67
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.