partition
stringclasses
3 values
func_name
stringlengths
1
134
docstring
stringlengths
1
46.9k
path
stringlengths
4
223
original_string
stringlengths
75
104k
code
stringlengths
75
104k
docstring_tokens
listlengths
1
1.97k
repo
stringlengths
7
55
language
stringclasses
1 value
url
stringlengths
87
315
code_tokens
listlengths
19
28.4k
sha
stringlengths
40
40
train
Lexer.tokenize
Calls tokeniter + tokenize and wraps it in a token stream.
pipenv/vendor/jinja2/lexer.py
def tokenize(self, source, name=None, filename=None, state=None): """Calls tokeniter + tokenize and wraps it in a token stream. """ stream = self.tokeniter(source, name, filename, state) return TokenStream(self.wrap(stream, name, filename), name, filename)
def tokenize(self, source, name=None, filename=None, state=None): """Calls tokeniter + tokenize and wraps it in a token stream. """ stream = self.tokeniter(source, name, filename, state) return TokenStream(self.wrap(stream, name, filename), name, filename)
[ "Calls", "tokeniter", "+", "tokenize", "and", "wraps", "it", "in", "a", "token", "stream", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/lexer.py#L552-L556
[ "def", "tokenize", "(", "self", ",", "source", ",", "name", "=", "None", ",", "filename", "=", "None", ",", "state", "=", "None", ")", ":", "stream", "=", "self", ".", "tokeniter", "(", "source", ",", "name", ",", "filename", ",", "state", ")", "re...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Lexer.wrap
This is called with the stream as returned by `tokenize` and wraps every token in a :class:`Token` and converts the value.
pipenv/vendor/jinja2/lexer.py
def wrap(self, stream, name=None, filename=None): """This is called with the stream as returned by `tokenize` and wraps every token in a :class:`Token` and converts the value. """ for lineno, token, value in stream: if token in ignored_tokens: continue elif token == 'linestatement_begin': token = 'block_begin' elif token == 'linestatement_end': token = 'block_end' # we are not interested in those tokens in the parser elif token in ('raw_begin', 'raw_end'): continue elif token == 'data': value = self._normalize_newlines(value) elif token == 'keyword': token = value elif token == 'name': value = str(value) if check_ident and not value.isidentifier(): raise TemplateSyntaxError( 'Invalid character in identifier', lineno, name, filename) elif token == 'string': # try to unescape string try: value = self._normalize_newlines(value[1:-1]) \ .encode('ascii', 'backslashreplace') \ .decode('unicode-escape') except Exception as e: msg = str(e).split(':')[-1].strip() raise TemplateSyntaxError(msg, lineno, name, filename) elif token == 'integer': value = int(value) elif token == 'float': value = float(value) elif token == 'operator': token = operators[value] yield Token(lineno, token, value)
def wrap(self, stream, name=None, filename=None): """This is called with the stream as returned by `tokenize` and wraps every token in a :class:`Token` and converts the value. """ for lineno, token, value in stream: if token in ignored_tokens: continue elif token == 'linestatement_begin': token = 'block_begin' elif token == 'linestatement_end': token = 'block_end' # we are not interested in those tokens in the parser elif token in ('raw_begin', 'raw_end'): continue elif token == 'data': value = self._normalize_newlines(value) elif token == 'keyword': token = value elif token == 'name': value = str(value) if check_ident and not value.isidentifier(): raise TemplateSyntaxError( 'Invalid character in identifier', lineno, name, filename) elif token == 'string': # try to unescape string try: value = self._normalize_newlines(value[1:-1]) \ .encode('ascii', 'backslashreplace') \ .decode('unicode-escape') except Exception as e: msg = str(e).split(':')[-1].strip() raise TemplateSyntaxError(msg, lineno, name, filename) elif token == 'integer': value = int(value) elif token == 'float': value = float(value) elif token == 'operator': token = operators[value] yield Token(lineno, token, value)
[ "This", "is", "called", "with", "the", "stream", "as", "returned", "by", "tokenize", "and", "wraps", "every", "token", "in", "a", ":", "class", ":", "Token", "and", "converts", "the", "value", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/lexer.py#L558-L597
[ "def", "wrap", "(", "self", ",", "stream", ",", "name", "=", "None", ",", "filename", "=", "None", ")", ":", "for", "lineno", ",", "token", ",", "value", "in", "stream", ":", "if", "token", "in", "ignored_tokens", ":", "continue", "elif", "token", "=...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
load_pyproject_toml
Load the pyproject.toml file. Parameters: use_pep517 - Has the user requested PEP 517 processing? None means the user hasn't explicitly specified. pyproject_toml - Location of the project's pyproject.toml file setup_py - Location of the project's setup.py file req_name - The name of the requirement we're processing (for error reporting) Returns: None if we should use the legacy code path, otherwise a tuple ( requirements from pyproject.toml, name of PEP 517 backend, requirements we should check are installed after setting up the build environment )
pipenv/patched/notpip/_internal/pyproject.py
def load_pyproject_toml( use_pep517, # type: Optional[bool] pyproject_toml, # type: str setup_py, # type: str req_name # type: str ): # type: (...) -> Optional[Tuple[List[str], str, List[str]]] """Load the pyproject.toml file. Parameters: use_pep517 - Has the user requested PEP 517 processing? None means the user hasn't explicitly specified. pyproject_toml - Location of the project's pyproject.toml file setup_py - Location of the project's setup.py file req_name - The name of the requirement we're processing (for error reporting) Returns: None if we should use the legacy code path, otherwise a tuple ( requirements from pyproject.toml, name of PEP 517 backend, requirements we should check are installed after setting up the build environment ) """ has_pyproject = os.path.isfile(pyproject_toml) has_setup = os.path.isfile(setup_py) if has_pyproject: with io.open(pyproject_toml, encoding="utf-8") as f: pp_toml = pytoml.load(f) build_system = pp_toml.get("build-system") else: build_system = None # The following cases must use PEP 517 # We check for use_pep517 being non-None and falsey because that means # the user explicitly requested --no-use-pep517. The value 0 as # opposed to False can occur when the value is provided via an # environment variable or config file option (due to the quirk of # strtobool() returning an integer in pip's configuration code). if has_pyproject and not has_setup: if use_pep517 is not None and not use_pep517: raise InstallationError( "Disabling PEP 517 processing is invalid: " "project does not have a setup.py" ) use_pep517 = True elif build_system and "build-backend" in build_system: if use_pep517 is not None and not use_pep517: raise InstallationError( "Disabling PEP 517 processing is invalid: " "project specifies a build backend of {} " "in pyproject.toml".format( build_system["build-backend"] ) ) use_pep517 = True # If we haven't worked out whether to use PEP 517 yet, # and the user hasn't explicitly stated a preference, # we do so if the project has a pyproject.toml file. elif use_pep517 is None: use_pep517 = has_pyproject # At this point, we know whether we're going to use PEP 517. assert use_pep517 is not None # If we're using the legacy code path, there is nothing further # for us to do here. if not use_pep517: return None if build_system is None: # Either the user has a pyproject.toml with no build-system # section, or the user has no pyproject.toml, but has opted in # explicitly via --use-pep517. # In the absence of any explicit backend specification, we # assume the setuptools backend that most closely emulates the # traditional direct setup.py execution, and require wheel and # a version of setuptools that supports that backend. build_system = { "requires": ["setuptools>=40.8.0", "wheel"], "build-backend": "setuptools.build_meta:__legacy__", } # If we're using PEP 517, we have build system information (either # from pyproject.toml, or defaulted by the code above). # Note that at this point, we do not know if the user has actually # specified a backend, though. assert build_system is not None # Ensure that the build-system section in pyproject.toml conforms # to PEP 518. error_template = ( "{package} has a pyproject.toml file that does not comply " "with PEP 518: {reason}" ) # Specifying the build-system table but not the requires key is invalid if "requires" not in build_system: raise InstallationError( error_template.format(package=req_name, reason=( "it has a 'build-system' table but not " "'build-system.requires' which is mandatory in the table" )) ) # Error out if requires is not a list of strings requires = build_system["requires"] if not _is_list_of_str(requires): raise InstallationError(error_template.format( package=req_name, reason="'build-system.requires' is not a list of strings.", )) backend = build_system.get("build-backend") check = [] # type: List[str] if backend is None: # If the user didn't specify a backend, we assume they want to use # the setuptools backend. But we can't be sure they have included # a version of setuptools which supplies the backend, or wheel # (which is needed by the backend) in their requirements. So we # make a note to check that those requirements are present once # we have set up the environment. # This is quite a lot of work to check for a very specific case. But # the problem is, that case is potentially quite common - projects that # adopted PEP 518 early for the ability to specify requirements to # execute setup.py, but never considered needing to mention the build # tools themselves. The original PEP 518 code had a similar check (but # implemented in a different way). backend = "setuptools.build_meta:__legacy__" check = ["setuptools>=40.8.0", "wheel"] return (requires, backend, check)
def load_pyproject_toml( use_pep517, # type: Optional[bool] pyproject_toml, # type: str setup_py, # type: str req_name # type: str ): # type: (...) -> Optional[Tuple[List[str], str, List[str]]] """Load the pyproject.toml file. Parameters: use_pep517 - Has the user requested PEP 517 processing? None means the user hasn't explicitly specified. pyproject_toml - Location of the project's pyproject.toml file setup_py - Location of the project's setup.py file req_name - The name of the requirement we're processing (for error reporting) Returns: None if we should use the legacy code path, otherwise a tuple ( requirements from pyproject.toml, name of PEP 517 backend, requirements we should check are installed after setting up the build environment ) """ has_pyproject = os.path.isfile(pyproject_toml) has_setup = os.path.isfile(setup_py) if has_pyproject: with io.open(pyproject_toml, encoding="utf-8") as f: pp_toml = pytoml.load(f) build_system = pp_toml.get("build-system") else: build_system = None # The following cases must use PEP 517 # We check for use_pep517 being non-None and falsey because that means # the user explicitly requested --no-use-pep517. The value 0 as # opposed to False can occur when the value is provided via an # environment variable or config file option (due to the quirk of # strtobool() returning an integer in pip's configuration code). if has_pyproject and not has_setup: if use_pep517 is not None and not use_pep517: raise InstallationError( "Disabling PEP 517 processing is invalid: " "project does not have a setup.py" ) use_pep517 = True elif build_system and "build-backend" in build_system: if use_pep517 is not None and not use_pep517: raise InstallationError( "Disabling PEP 517 processing is invalid: " "project specifies a build backend of {} " "in pyproject.toml".format( build_system["build-backend"] ) ) use_pep517 = True # If we haven't worked out whether to use PEP 517 yet, # and the user hasn't explicitly stated a preference, # we do so if the project has a pyproject.toml file. elif use_pep517 is None: use_pep517 = has_pyproject # At this point, we know whether we're going to use PEP 517. assert use_pep517 is not None # If we're using the legacy code path, there is nothing further # for us to do here. if not use_pep517: return None if build_system is None: # Either the user has a pyproject.toml with no build-system # section, or the user has no pyproject.toml, but has opted in # explicitly via --use-pep517. # In the absence of any explicit backend specification, we # assume the setuptools backend that most closely emulates the # traditional direct setup.py execution, and require wheel and # a version of setuptools that supports that backend. build_system = { "requires": ["setuptools>=40.8.0", "wheel"], "build-backend": "setuptools.build_meta:__legacy__", } # If we're using PEP 517, we have build system information (either # from pyproject.toml, or defaulted by the code above). # Note that at this point, we do not know if the user has actually # specified a backend, though. assert build_system is not None # Ensure that the build-system section in pyproject.toml conforms # to PEP 518. error_template = ( "{package} has a pyproject.toml file that does not comply " "with PEP 518: {reason}" ) # Specifying the build-system table but not the requires key is invalid if "requires" not in build_system: raise InstallationError( error_template.format(package=req_name, reason=( "it has a 'build-system' table but not " "'build-system.requires' which is mandatory in the table" )) ) # Error out if requires is not a list of strings requires = build_system["requires"] if not _is_list_of_str(requires): raise InstallationError(error_template.format( package=req_name, reason="'build-system.requires' is not a list of strings.", )) backend = build_system.get("build-backend") check = [] # type: List[str] if backend is None: # If the user didn't specify a backend, we assume they want to use # the setuptools backend. But we can't be sure they have included # a version of setuptools which supplies the backend, or wheel # (which is needed by the backend) in their requirements. So we # make a note to check that those requirements are present once # we have set up the environment. # This is quite a lot of work to check for a very specific case. But # the problem is, that case is potentially quite common - projects that # adopted PEP 518 early for the ability to specify requirements to # execute setup.py, but never considered needing to mention the build # tools themselves. The original PEP 518 code had a similar check (but # implemented in a different way). backend = "setuptools.build_meta:__legacy__" check = ["setuptools>=40.8.0", "wheel"] return (requires, backend, check)
[ "Load", "the", "pyproject", ".", "toml", "file", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_internal/pyproject.py#L35-L171
[ "def", "load_pyproject_toml", "(", "use_pep517", ",", "# type: Optional[bool]", "pyproject_toml", ",", "# type: str", "setup_py", ",", "# type: str", "req_name", "# type: str", ")", ":", "# type: (...) -> Optional[Tuple[List[str], str, List[str]]]", "has_pyproject", "=", "os", ...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Runner.iter_installable_versions
Iterate through CPython versions available for Pipenv to install.
pipenv/pyenv.py
def iter_installable_versions(self): """Iterate through CPython versions available for Pipenv to install. """ for name in self._pyenv('install', '--list').out.splitlines(): try: version = Version.parse(name.strip()) except ValueError: continue yield version
def iter_installable_versions(self): """Iterate through CPython versions available for Pipenv to install. """ for name in self._pyenv('install', '--list').out.splitlines(): try: version = Version.parse(name.strip()) except ValueError: continue yield version
[ "Iterate", "through", "CPython", "versions", "available", "for", "Pipenv", "to", "install", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/pyenv.py#L75-L83
[ "def", "iter_installable_versions", "(", "self", ")", ":", "for", "name", "in", "self", ".", "_pyenv", "(", "'install'", ",", "'--list'", ")", ".", "out", ".", "splitlines", "(", ")", ":", "try", ":", "version", "=", "Version", ".", "parse", "(", "name...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Runner.find_version_to_install
Find a version in pyenv from the version supplied. A ValueError is raised if a matching version cannot be found.
pipenv/pyenv.py
def find_version_to_install(self, name): """Find a version in pyenv from the version supplied. A ValueError is raised if a matching version cannot be found. """ version = Version.parse(name) if version.patch is not None: return name try: best_match = max(( inst_version for inst_version in self.iter_installable_versions() if inst_version.matches_minor(version) ), key=operator.attrgetter('cmpkey')) except ValueError: raise ValueError( 'no installable version found for {0!r}'.format(name), ) return best_match
def find_version_to_install(self, name): """Find a version in pyenv from the version supplied. A ValueError is raised if a matching version cannot be found. """ version = Version.parse(name) if version.patch is not None: return name try: best_match = max(( inst_version for inst_version in self.iter_installable_versions() if inst_version.matches_minor(version) ), key=operator.attrgetter('cmpkey')) except ValueError: raise ValueError( 'no installable version found for {0!r}'.format(name), ) return best_match
[ "Find", "a", "version", "in", "pyenv", "from", "the", "version", "supplied", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/pyenv.py#L85-L103
[ "def", "find_version_to_install", "(", "self", ",", "name", ")", ":", "version", "=", "Version", ".", "parse", "(", "name", ")", "if", "version", ".", "patch", "is", "not", "None", ":", "return", "name", "try", ":", "best_match", "=", "max", "(", "(", ...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Runner.install
Install the given version with pyenv. The version must be a ``Version`` instance representing a version found in pyenv. A ValueError is raised if the given version does not have a match in pyenv. A PyenvError is raised if the pyenv command fails.
pipenv/pyenv.py
def install(self, version): """Install the given version with pyenv. The version must be a ``Version`` instance representing a version found in pyenv. A ValueError is raised if the given version does not have a match in pyenv. A PyenvError is raised if the pyenv command fails. """ c = self._pyenv( 'install', '-s', str(version), timeout=PIPENV_INSTALL_TIMEOUT, ) return c
def install(self, version): """Install the given version with pyenv. The version must be a ``Version`` instance representing a version found in pyenv. A ValueError is raised if the given version does not have a match in pyenv. A PyenvError is raised if the pyenv command fails. """ c = self._pyenv( 'install', '-s', str(version), timeout=PIPENV_INSTALL_TIMEOUT, ) return c
[ "Install", "the", "given", "version", "with", "pyenv", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/pyenv.py#L105-L118
[ "def", "install", "(", "self", ",", "version", ")", ":", "c", "=", "self", ".", "_pyenv", "(", "'install'", ",", "'-s'", ",", "str", "(", "version", ")", ",", "timeout", "=", "PIPENV_INSTALL_TIMEOUT", ",", ")", "return", "c" ]
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
parse_editable
Parses an editable requirement into: - a requirement name - an URL - extras - editable options Accepted requirements: svn+http://blahblah@rev#egg=Foobar[baz]&subdirectory=version_subdir .[some_extra]
pipenv/patched/notpip/_internal/req/constructors.py
def parse_editable(editable_req): # type: (str) -> Tuple[Optional[str], str, Optional[Set[str]]] """Parses an editable requirement into: - a requirement name - an URL - extras - editable options Accepted requirements: svn+http://blahblah@rev#egg=Foobar[baz]&subdirectory=version_subdir .[some_extra] """ url = editable_req # If a file path is specified with extras, strip off the extras. url_no_extras, extras = _strip_extras(url) if os.path.isdir(url_no_extras): if not os.path.exists(os.path.join(url_no_extras, 'setup.py')): msg = ( 'File "setup.py" not found. Directory cannot be installed ' 'in editable mode: {}'.format(os.path.abspath(url_no_extras)) ) pyproject_path = make_pyproject_path(url_no_extras) if os.path.isfile(pyproject_path): msg += ( '\n(A "pyproject.toml" file was found, but editable ' 'mode currently requires a setup.py based build.)' ) raise InstallationError(msg) # Treating it as code that has already been checked out url_no_extras = path_to_url(url_no_extras) if url_no_extras.lower().startswith('file:'): package_name = Link(url_no_extras).egg_fragment if extras: return ( package_name, url_no_extras, Requirement("placeholder" + extras.lower()).extras, ) else: return package_name, url_no_extras, None for version_control in vcs: if url.lower().startswith('%s:' % version_control): url = '%s+%s' % (version_control, url) break if '+' not in url: raise InstallationError( '%s should either be a path to a local project or a VCS url ' 'beginning with svn+, git+, hg+, or bzr+' % editable_req ) vc_type = url.split('+', 1)[0].lower() if not vcs.get_backend(vc_type): error_message = 'For --editable=%s only ' % editable_req + \ ', '.join([backend.name + '+URL' for backend in vcs.backends]) + \ ' is currently supported' raise InstallationError(error_message) package_name = Link(url).egg_fragment if not package_name: raise InstallationError( "Could not detect requirement name for '%s', please specify one " "with #egg=your_package_name" % editable_req ) return package_name, url, None
def parse_editable(editable_req): # type: (str) -> Tuple[Optional[str], str, Optional[Set[str]]] """Parses an editable requirement into: - a requirement name - an URL - extras - editable options Accepted requirements: svn+http://blahblah@rev#egg=Foobar[baz]&subdirectory=version_subdir .[some_extra] """ url = editable_req # If a file path is specified with extras, strip off the extras. url_no_extras, extras = _strip_extras(url) if os.path.isdir(url_no_extras): if not os.path.exists(os.path.join(url_no_extras, 'setup.py')): msg = ( 'File "setup.py" not found. Directory cannot be installed ' 'in editable mode: {}'.format(os.path.abspath(url_no_extras)) ) pyproject_path = make_pyproject_path(url_no_extras) if os.path.isfile(pyproject_path): msg += ( '\n(A "pyproject.toml" file was found, but editable ' 'mode currently requires a setup.py based build.)' ) raise InstallationError(msg) # Treating it as code that has already been checked out url_no_extras = path_to_url(url_no_extras) if url_no_extras.lower().startswith('file:'): package_name = Link(url_no_extras).egg_fragment if extras: return ( package_name, url_no_extras, Requirement("placeholder" + extras.lower()).extras, ) else: return package_name, url_no_extras, None for version_control in vcs: if url.lower().startswith('%s:' % version_control): url = '%s+%s' % (version_control, url) break if '+' not in url: raise InstallationError( '%s should either be a path to a local project or a VCS url ' 'beginning with svn+, git+, hg+, or bzr+' % editable_req ) vc_type = url.split('+', 1)[0].lower() if not vcs.get_backend(vc_type): error_message = 'For --editable=%s only ' % editable_req + \ ', '.join([backend.name + '+URL' for backend in vcs.backends]) + \ ' is currently supported' raise InstallationError(error_message) package_name = Link(url).egg_fragment if not package_name: raise InstallationError( "Could not detect requirement name for '%s', please specify one " "with #egg=your_package_name" % editable_req ) return package_name, url, None
[ "Parses", "an", "editable", "requirement", "into", ":", "-", "a", "requirement", "name", "-", "an", "URL", "-", "extras", "-", "editable", "options", "Accepted", "requirements", ":", "svn", "+", "http", ":", "//", "blahblah" ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_internal/req/constructors.py#L62-L133
[ "def", "parse_editable", "(", "editable_req", ")", ":", "# type: (str) -> Tuple[Optional[str], str, Optional[Set[str]]]", "url", "=", "editable_req", "# If a file path is specified with extras, strip off the extras.", "url_no_extras", ",", "extras", "=", "_strip_extras", "(", "url"...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
deduce_helpful_msg
Returns helpful msg in case requirements file does not exist, or cannot be parsed. :params req: Requirements file path
pipenv/patched/notpip/_internal/req/constructors.py
def deduce_helpful_msg(req): # type: (str) -> str """Returns helpful msg in case requirements file does not exist, or cannot be parsed. :params req: Requirements file path """ msg = "" if os.path.exists(req): msg = " It does exist." # Try to parse and check if it is a requirements file. try: with open(req, 'r') as fp: # parse first line only next(parse_requirements(fp.read())) msg += " The argument you provided " + \ "(%s) appears to be a" % (req) + \ " requirements file. If that is the" + \ " case, use the '-r' flag to install" + \ " the packages specified within it." except RequirementParseError: logger.debug("Cannot parse '%s' as requirements \ file" % (req), exc_info=True) else: msg += " File '%s' does not exist." % (req) return msg
def deduce_helpful_msg(req): # type: (str) -> str """Returns helpful msg in case requirements file does not exist, or cannot be parsed. :params req: Requirements file path """ msg = "" if os.path.exists(req): msg = " It does exist." # Try to parse and check if it is a requirements file. try: with open(req, 'r') as fp: # parse first line only next(parse_requirements(fp.read())) msg += " The argument you provided " + \ "(%s) appears to be a" % (req) + \ " requirements file. If that is the" + \ " case, use the '-r' flag to install" + \ " the packages specified within it." except RequirementParseError: logger.debug("Cannot parse '%s' as requirements \ file" % (req), exc_info=True) else: msg += " File '%s' does not exist." % (req) return msg
[ "Returns", "helpful", "msg", "in", "case", "requirements", "file", "does", "not", "exist", "or", "cannot", "be", "parsed", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_internal/req/constructors.py#L136-L161
[ "def", "deduce_helpful_msg", "(", "req", ")", ":", "# type: (str) -> str", "msg", "=", "\"\"", "if", "os", ".", "path", ".", "exists", "(", "req", ")", ":", "msg", "=", "\" It does exist.\"", "# Try to parse and check if it is a requirements file.", "try", ":", "w...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
install_req_from_line
Creates an InstallRequirement from a name, which might be a requirement, directory containing 'setup.py', filename, or URL.
pipenv/patched/notpip/_internal/req/constructors.py
def install_req_from_line( name, # type: str comes_from=None, # type: Optional[Union[str, InstallRequirement]] use_pep517=None, # type: Optional[bool] isolated=False, # type: bool options=None, # type: Optional[Dict[str, Any]] wheel_cache=None, # type: Optional[WheelCache] constraint=False # type: bool ): # type: (...) -> InstallRequirement """Creates an InstallRequirement from a name, which might be a requirement, directory containing 'setup.py', filename, or URL. """ if is_url(name): marker_sep = '; ' else: marker_sep = ';' if marker_sep in name: name, markers_as_string = name.split(marker_sep, 1) markers_as_string = markers_as_string.strip() if not markers_as_string: markers = None else: markers = Marker(markers_as_string) else: markers = None name = name.strip() req_as_string = None path = os.path.normpath(os.path.abspath(name)) link = None extras_as_string = None if is_url(name): link = Link(name) else: p, extras_as_string = _strip_extras(path) looks_like_dir = os.path.isdir(p) and ( os.path.sep in name or (os.path.altsep is not None and os.path.altsep in name) or name.startswith('.') ) if looks_like_dir: if not is_installable_dir(p): raise InstallationError( "Directory %r is not installable. Neither 'setup.py' " "nor 'pyproject.toml' found." % name ) link = Link(path_to_url(p)) elif is_archive_file(p): if not os.path.isfile(p): logger.warning( 'Requirement %r looks like a filename, but the ' 'file does not exist', name ) link = Link(path_to_url(p)) # it's a local file, dir, or url if link: # Handle relative file URLs if link.scheme == 'file' and re.search(r'\.\./', link.url): link = Link( path_to_url(os.path.normpath(os.path.abspath(link.path)))) # wheel file if link.is_wheel: wheel = Wheel(link.filename) # can raise InvalidWheelFilename req_as_string = "%s==%s" % (wheel.name, wheel.version) else: # set the req to the egg fragment. when it's not there, this # will become an 'unnamed' requirement req_as_string = link.egg_fragment # a requirement specifier else: req_as_string = name if extras_as_string: extras = Requirement("placeholder" + extras_as_string.lower()).extras else: extras = () if req_as_string is not None: try: req = Requirement(req_as_string) except InvalidRequirement: if os.path.sep in req_as_string: add_msg = "It looks like a path." add_msg += deduce_helpful_msg(req_as_string) elif ('=' in req_as_string and not any(op in req_as_string for op in operators)): add_msg = "= is not a valid operator. Did you mean == ?" else: add_msg = "" raise InstallationError( "Invalid requirement: '%s'\n%s" % (req_as_string, add_msg) ) else: req = None return InstallRequirement( req, comes_from, link=link, markers=markers, use_pep517=use_pep517, isolated=isolated, options=options if options else {}, wheel_cache=wheel_cache, constraint=constraint, extras=extras, )
def install_req_from_line( name, # type: str comes_from=None, # type: Optional[Union[str, InstallRequirement]] use_pep517=None, # type: Optional[bool] isolated=False, # type: bool options=None, # type: Optional[Dict[str, Any]] wheel_cache=None, # type: Optional[WheelCache] constraint=False # type: bool ): # type: (...) -> InstallRequirement """Creates an InstallRequirement from a name, which might be a requirement, directory containing 'setup.py', filename, or URL. """ if is_url(name): marker_sep = '; ' else: marker_sep = ';' if marker_sep in name: name, markers_as_string = name.split(marker_sep, 1) markers_as_string = markers_as_string.strip() if not markers_as_string: markers = None else: markers = Marker(markers_as_string) else: markers = None name = name.strip() req_as_string = None path = os.path.normpath(os.path.abspath(name)) link = None extras_as_string = None if is_url(name): link = Link(name) else: p, extras_as_string = _strip_extras(path) looks_like_dir = os.path.isdir(p) and ( os.path.sep in name or (os.path.altsep is not None and os.path.altsep in name) or name.startswith('.') ) if looks_like_dir: if not is_installable_dir(p): raise InstallationError( "Directory %r is not installable. Neither 'setup.py' " "nor 'pyproject.toml' found." % name ) link = Link(path_to_url(p)) elif is_archive_file(p): if not os.path.isfile(p): logger.warning( 'Requirement %r looks like a filename, but the ' 'file does not exist', name ) link = Link(path_to_url(p)) # it's a local file, dir, or url if link: # Handle relative file URLs if link.scheme == 'file' and re.search(r'\.\./', link.url): link = Link( path_to_url(os.path.normpath(os.path.abspath(link.path)))) # wheel file if link.is_wheel: wheel = Wheel(link.filename) # can raise InvalidWheelFilename req_as_string = "%s==%s" % (wheel.name, wheel.version) else: # set the req to the egg fragment. when it's not there, this # will become an 'unnamed' requirement req_as_string = link.egg_fragment # a requirement specifier else: req_as_string = name if extras_as_string: extras = Requirement("placeholder" + extras_as_string.lower()).extras else: extras = () if req_as_string is not None: try: req = Requirement(req_as_string) except InvalidRequirement: if os.path.sep in req_as_string: add_msg = "It looks like a path." add_msg += deduce_helpful_msg(req_as_string) elif ('=' in req_as_string and not any(op in req_as_string for op in operators)): add_msg = "= is not a valid operator. Did you mean == ?" else: add_msg = "" raise InstallationError( "Invalid requirement: '%s'\n%s" % (req_as_string, add_msg) ) else: req = None return InstallRequirement( req, comes_from, link=link, markers=markers, use_pep517=use_pep517, isolated=isolated, options=options if options else {}, wheel_cache=wheel_cache, constraint=constraint, extras=extras, )
[ "Creates", "an", "InstallRequirement", "from", "a", "name", "which", "might", "be", "a", "requirement", "directory", "containing", "setup", ".", "py", "filename", "or", "URL", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_internal/req/constructors.py#L203-L308
[ "def", "install_req_from_line", "(", "name", ",", "# type: str", "comes_from", "=", "None", ",", "# type: Optional[Union[str, InstallRequirement]]", "use_pep517", "=", "None", ",", "# type: Optional[bool]", "isolated", "=", "False", ",", "# type: bool", "options", "=", ...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
url_to_file_path
Return the file cache path based on the URL. This does not ensure the file exists!
pipenv/patched/notpip/_vendor/cachecontrol/caches/file_cache.py
def url_to_file_path(url, filecache): """Return the file cache path based on the URL. This does not ensure the file exists! """ key = CacheController.cache_url(url) return filecache._fn(key)
def url_to_file_path(url, filecache): """Return the file cache path based on the URL. This does not ensure the file exists! """ key = CacheController.cache_url(url) return filecache._fn(key)
[ "Return", "the", "file", "cache", "path", "based", "on", "the", "URL", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/cachecontrol/caches/file_cache.py#L140-L146
[ "def", "url_to_file_path", "(", "url", ",", "filecache", ")", ":", "key", "=", "CacheController", ".", "cache_url", "(", "url", ")", "return", "filecache", ".", "_fn", "(", "key", ")" ]
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
write_pid_to_pidfile
Write the PID in the named PID file. Get the numeric process ID (“PID”) of the current process and write it to the named file as a line of text.
pipenv/patched/notpip/_vendor/lockfile/pidlockfile.py
def write_pid_to_pidfile(pidfile_path): """ Write the PID in the named PID file. Get the numeric process ID (“PID”) of the current process and write it to the named file as a line of text. """ open_flags = (os.O_CREAT | os.O_EXCL | os.O_WRONLY) open_mode = 0o644 pidfile_fd = os.open(pidfile_path, open_flags, open_mode) pidfile = os.fdopen(pidfile_fd, 'w') # According to the FHS 2.3 section on PID files in /var/run: # # The file must consist of the process identifier in # ASCII-encoded decimal, followed by a newline character. For # example, if crond was process number 25, /var/run/crond.pid # would contain three characters: two, five, and newline. pid = os.getpid() pidfile.write("%s\n" % pid) pidfile.close()
def write_pid_to_pidfile(pidfile_path): """ Write the PID in the named PID file. Get the numeric process ID (“PID”) of the current process and write it to the named file as a line of text. """ open_flags = (os.O_CREAT | os.O_EXCL | os.O_WRONLY) open_mode = 0o644 pidfile_fd = os.open(pidfile_path, open_flags, open_mode) pidfile = os.fdopen(pidfile_fd, 'w') # According to the FHS 2.3 section on PID files in /var/run: # # The file must consist of the process identifier in # ASCII-encoded decimal, followed by a newline character. For # example, if crond was process number 25, /var/run/crond.pid # would contain three characters: two, five, and newline. pid = os.getpid() pidfile.write("%s\n" % pid) pidfile.close()
[ "Write", "the", "PID", "in", "the", "named", "PID", "file", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/lockfile/pidlockfile.py#L152-L173
[ "def", "write_pid_to_pidfile", "(", "pidfile_path", ")", ":", "open_flags", "=", "(", "os", ".", "O_CREAT", "|", "os", ".", "O_EXCL", "|", "os", ".", "O_WRONLY", ")", "open_mode", "=", "0o644", "pidfile_fd", "=", "os", ".", "open", "(", "pidfile_path", "...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
remove_existing_pidfile
Remove the named PID file if it exists. Removing a PID file that doesn't already exist puts us in the desired state, so we ignore the condition if the file does not exist.
pipenv/patched/notpip/_vendor/lockfile/pidlockfile.py
def remove_existing_pidfile(pidfile_path): """ Remove the named PID file if it exists. Removing a PID file that doesn't already exist puts us in the desired state, so we ignore the condition if the file does not exist. """ try: os.remove(pidfile_path) except OSError as exc: if exc.errno == errno.ENOENT: pass else: raise
def remove_existing_pidfile(pidfile_path): """ Remove the named PID file if it exists. Removing a PID file that doesn't already exist puts us in the desired state, so we ignore the condition if the file does not exist. """ try: os.remove(pidfile_path) except OSError as exc: if exc.errno == errno.ENOENT: pass else: raise
[ "Remove", "the", "named", "PID", "file", "if", "it", "exists", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/lockfile/pidlockfile.py#L176-L190
[ "def", "remove_existing_pidfile", "(", "pidfile_path", ")", ":", "try", ":", "os", ".", "remove", "(", "pidfile_path", ")", "except", "OSError", "as", "exc", ":", "if", "exc", ".", "errno", "==", "errno", ".", "ENOENT", ":", "pass", "else", ":", "raise" ...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
PIDLockFile.release
Release the lock. Removes the PID file to release the lock, or raises an error if the current process does not hold the lock.
pipenv/patched/notpip/_vendor/lockfile/pidlockfile.py
def release(self): """ Release the lock. Removes the PID file to release the lock, or raises an error if the current process does not hold the lock. """ if not self.is_locked(): raise NotLocked("%s is not locked" % self.path) if not self.i_am_locking(): raise NotMyLock("%s is locked, but not by me" % self.path) remove_existing_pidfile(self.path)
def release(self): """ Release the lock. Removes the PID file to release the lock, or raises an error if the current process does not hold the lock. """ if not self.is_locked(): raise NotLocked("%s is not locked" % self.path) if not self.i_am_locking(): raise NotMyLock("%s is locked, but not by me" % self.path) remove_existing_pidfile(self.path)
[ "Release", "the", "lock", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/lockfile/pidlockfile.py#L95-L106
[ "def", "release", "(", "self", ")", ":", "if", "not", "self", ".", "is_locked", "(", ")", ":", "raise", "NotLocked", "(", "\"%s is not locked\"", "%", "self", ".", "path", ")", "if", "not", "self", ".", "i_am_locking", "(", ")", ":", "raise", "NotMyLoc...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Bazaar.export
Export the Bazaar repository at the url to the destination location
pipenv/patched/notpip/_internal/vcs/bazaar.py
def export(self, location): """ Export the Bazaar repository at the url to the destination location """ # Remove the location to make sure Bazaar can export it correctly if os.path.exists(location): rmtree(location) with TempDirectory(kind="export") as temp_dir: self.unpack(temp_dir.path) self.run_command( ['export', location], cwd=temp_dir.path, show_stdout=False, )
def export(self, location): """ Export the Bazaar repository at the url to the destination location """ # Remove the location to make sure Bazaar can export it correctly if os.path.exists(location): rmtree(location) with TempDirectory(kind="export") as temp_dir: self.unpack(temp_dir.path) self.run_command( ['export', location], cwd=temp_dir.path, show_stdout=False, )
[ "Export", "the", "Bazaar", "repository", "at", "the", "url", "to", "the", "destination", "location" ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_internal/vcs/bazaar.py#L37-L51
[ "def", "export", "(", "self", ",", "location", ")", ":", "# Remove the location to make sure Bazaar can export it correctly", "if", "os", ".", "path", ".", "exists", "(", "location", ")", ":", "rmtree", "(", "location", ")", "with", "TempDirectory", "(", "kind", ...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
search_packages_info
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.
pipenv/patched/notpip/_internal/commands/show.py
def 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. """ installed = {} for p in pkg_resources.working_set: installed[canonicalize_name(p.project_name)] = p query_names = [canonicalize_name(name) for name in query] for dist in [installed[pkg] for pkg in query_names if pkg in installed]: package = { 'name': dist.project_name, 'version': dist.version, 'location': dist.location, 'requires': [dep.project_name for dep in dist.requires()], } file_list = None metadata = None if isinstance(dist, pkg_resources.DistInfoDistribution): # RECORDs should be part of .dist-info metadatas if dist.has_metadata('RECORD'): lines = dist.get_metadata_lines('RECORD') paths = [l.split(',')[0] for l in lines] paths = [os.path.join(dist.location, p) for p in paths] file_list = [os.path.relpath(p, dist.location) for p in paths] if dist.has_metadata('METADATA'): metadata = dist.get_metadata('METADATA') else: # Otherwise use pip's log for .egg-info's if dist.has_metadata('installed-files.txt'): paths = dist.get_metadata_lines('installed-files.txt') paths = [os.path.join(dist.egg_info, p) for p in paths] file_list = [os.path.relpath(p, dist.location) for p in paths] if dist.has_metadata('PKG-INFO'): metadata = dist.get_metadata('PKG-INFO') if dist.has_metadata('entry_points.txt'): entry_points = dist.get_metadata_lines('entry_points.txt') package['entry_points'] = entry_points if dist.has_metadata('INSTALLER'): for line in dist.get_metadata_lines('INSTALLER'): if line.strip(): package['installer'] = line.strip() break # @todo: Should pkg_resources.Distribution have a # `get_pkg_info` method? feed_parser = FeedParser() feed_parser.feed(metadata) pkg_info_dict = feed_parser.close() for key in ('metadata-version', 'summary', 'home-page', 'author', 'author-email', 'license'): package[key] = pkg_info_dict.get(key) # It looks like FeedParser cannot deal with repeated headers classifiers = [] for line in metadata.splitlines(): if line.startswith('Classifier: '): classifiers.append(line[len('Classifier: '):]) package['classifiers'] = classifiers if file_list: package['files'] = sorted(file_list) yield package
def 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. """ installed = {} for p in pkg_resources.working_set: installed[canonicalize_name(p.project_name)] = p query_names = [canonicalize_name(name) for name in query] for dist in [installed[pkg] for pkg in query_names if pkg in installed]: package = { 'name': dist.project_name, 'version': dist.version, 'location': dist.location, 'requires': [dep.project_name for dep in dist.requires()], } file_list = None metadata = None if isinstance(dist, pkg_resources.DistInfoDistribution): # RECORDs should be part of .dist-info metadatas if dist.has_metadata('RECORD'): lines = dist.get_metadata_lines('RECORD') paths = [l.split(',')[0] for l in lines] paths = [os.path.join(dist.location, p) for p in paths] file_list = [os.path.relpath(p, dist.location) for p in paths] if dist.has_metadata('METADATA'): metadata = dist.get_metadata('METADATA') else: # Otherwise use pip's log for .egg-info's if dist.has_metadata('installed-files.txt'): paths = dist.get_metadata_lines('installed-files.txt') paths = [os.path.join(dist.egg_info, p) for p in paths] file_list = [os.path.relpath(p, dist.location) for p in paths] if dist.has_metadata('PKG-INFO'): metadata = dist.get_metadata('PKG-INFO') if dist.has_metadata('entry_points.txt'): entry_points = dist.get_metadata_lines('entry_points.txt') package['entry_points'] = entry_points if dist.has_metadata('INSTALLER'): for line in dist.get_metadata_lines('INSTALLER'): if line.strip(): package['installer'] = line.strip() break # @todo: Should pkg_resources.Distribution have a # `get_pkg_info` method? feed_parser = FeedParser() feed_parser.feed(metadata) pkg_info_dict = feed_parser.close() for key in ('metadata-version', 'summary', 'home-page', 'author', 'author-email', 'license'): package[key] = pkg_info_dict.get(key) # It looks like FeedParser cannot deal with repeated headers classifiers = [] for line in metadata.splitlines(): if line.startswith('Classifier: '): classifiers.append(line[len('Classifier: '):]) package['classifiers'] = classifiers if file_list: package['files'] = sorted(file_list) yield package
[ "Gather", "details", "from", "installed", "distributions", ".", "Print", "distribution", "name", "version", "location", "and", "installed", "files", ".", "Installed", "files", "requires", "a", "pip", "generated", "installed", "-", "files", ".", "txt", "in", "the...
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_internal/commands/show.py#L52-L122
[ "def", "search_packages_info", "(", "query", ")", ":", "installed", "=", "{", "}", "for", "p", "in", "pkg_resources", ".", "working_set", ":", "installed", "[", "canonicalize_name", "(", "p", ".", "project_name", ")", "]", "=", "p", "query_names", "=", "["...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
print_results
Print the informations from installed distributions found.
pipenv/patched/notpip/_internal/commands/show.py
def print_results(distributions, list_files=False, verbose=False): """ Print the informations from installed distributions found. """ results_printed = False for i, dist in enumerate(distributions): results_printed = True if i > 0: logger.info("---") name = dist.get('name', '') required_by = [ pkg.project_name for pkg in pkg_resources.working_set if name in [required.name for required in pkg.requires()] ] logger.info("Name: %s", name) logger.info("Version: %s", dist.get('version', '')) logger.info("Summary: %s", dist.get('summary', '')) logger.info("Home-page: %s", dist.get('home-page', '')) logger.info("Author: %s", dist.get('author', '')) logger.info("Author-email: %s", dist.get('author-email', '')) logger.info("License: %s", dist.get('license', '')) logger.info("Location: %s", dist.get('location', '')) logger.info("Requires: %s", ', '.join(dist.get('requires', []))) logger.info("Required-by: %s", ', '.join(required_by)) if verbose: logger.info("Metadata-Version: %s", dist.get('metadata-version', '')) logger.info("Installer: %s", dist.get('installer', '')) logger.info("Classifiers:") for classifier in dist.get('classifiers', []): logger.info(" %s", classifier) logger.info("Entry-points:") for entry in dist.get('entry_points', []): logger.info(" %s", entry.strip()) if list_files: logger.info("Files:") for line in dist.get('files', []): logger.info(" %s", line.strip()) if "files" not in dist: logger.info("Cannot locate installed-files.txt") return results_printed
def print_results(distributions, list_files=False, verbose=False): """ Print the informations from installed distributions found. """ results_printed = False for i, dist in enumerate(distributions): results_printed = True if i > 0: logger.info("---") name = dist.get('name', '') required_by = [ pkg.project_name for pkg in pkg_resources.working_set if name in [required.name for required in pkg.requires()] ] logger.info("Name: %s", name) logger.info("Version: %s", dist.get('version', '')) logger.info("Summary: %s", dist.get('summary', '')) logger.info("Home-page: %s", dist.get('home-page', '')) logger.info("Author: %s", dist.get('author', '')) logger.info("Author-email: %s", dist.get('author-email', '')) logger.info("License: %s", dist.get('license', '')) logger.info("Location: %s", dist.get('location', '')) logger.info("Requires: %s", ', '.join(dist.get('requires', []))) logger.info("Required-by: %s", ', '.join(required_by)) if verbose: logger.info("Metadata-Version: %s", dist.get('metadata-version', '')) logger.info("Installer: %s", dist.get('installer', '')) logger.info("Classifiers:") for classifier in dist.get('classifiers', []): logger.info(" %s", classifier) logger.info("Entry-points:") for entry in dist.get('entry_points', []): logger.info(" %s", entry.strip()) if list_files: logger.info("Files:") for line in dist.get('files', []): logger.info(" %s", line.strip()) if "files" not in dist: logger.info("Cannot locate installed-files.txt") return results_printed
[ "Print", "the", "informations", "from", "installed", "distributions", "found", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_internal/commands/show.py#L125-L168
[ "def", "print_results", "(", "distributions", ",", "list_files", "=", "False", ",", "verbose", "=", "False", ")", ":", "results_printed", "=", "False", "for", "i", ",", "dist", "in", "enumerate", "(", "distributions", ")", ":", "results_printed", "=", "True"...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Parser.fail
Convenience method that raises `exc` with the message, passed line number or last line number as well as the current name and filename.
pipenv/vendor/jinja2/parser.py
def fail(self, msg, lineno=None, exc=TemplateSyntaxError): """Convenience method that raises `exc` with the message, passed line number or last line number as well as the current name and filename. """ if lineno is None: lineno = self.stream.current.lineno raise exc(msg, lineno, self.name, self.filename)
def fail(self, msg, lineno=None, exc=TemplateSyntaxError): """Convenience method that raises `exc` with the message, passed line number or last line number as well as the current name and filename. """ if lineno is None: lineno = self.stream.current.lineno raise exc(msg, lineno, self.name, self.filename)
[ "Convenience", "method", "that", "raises", "exc", "with", "the", "message", "passed", "line", "number", "or", "last", "line", "number", "as", "well", "as", "the", "current", "name", "and", "filename", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/parser.py#L52-L59
[ "def", "fail", "(", "self", ",", "msg", ",", "lineno", "=", "None", ",", "exc", "=", "TemplateSyntaxError", ")", ":", "if", "lineno", "is", "None", ":", "lineno", "=", "self", ".", "stream", ".", "current", ".", "lineno", "raise", "exc", "(", "msg", ...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Parser.fail_unknown_tag
Called if the parser encounters an unknown tag. Tries to fail with a human readable error message that could help to identify the problem.
pipenv/vendor/jinja2/parser.py
def fail_unknown_tag(self, name, lineno=None): """Called if the parser encounters an unknown tag. Tries to fail with a human readable error message that could help to identify the problem. """ return self._fail_ut_eof(name, self._end_token_stack, lineno)
def fail_unknown_tag(self, name, lineno=None): """Called if the parser encounters an unknown tag. Tries to fail with a human readable error message that could help to identify the problem. """ return self._fail_ut_eof(name, self._end_token_stack, lineno)
[ "Called", "if", "the", "parser", "encounters", "an", "unknown", "tag", ".", "Tries", "to", "fail", "with", "a", "human", "readable", "error", "message", "that", "could", "help", "to", "identify", "the", "problem", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/parser.py#L92-L97
[ "def", "fail_unknown_tag", "(", "self", ",", "name", ",", "lineno", "=", "None", ")", ":", "return", "self", ".", "_fail_ut_eof", "(", "name", ",", "self", ".", "_end_token_stack", ",", "lineno", ")" ]
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Parser.fail_eof
Like fail_unknown_tag but for end of template situations.
pipenv/vendor/jinja2/parser.py
def fail_eof(self, end_tokens=None, lineno=None): """Like fail_unknown_tag but for end of template situations.""" stack = list(self._end_token_stack) if end_tokens is not None: stack.append(end_tokens) return self._fail_ut_eof(None, stack, lineno)
def fail_eof(self, end_tokens=None, lineno=None): """Like fail_unknown_tag but for end of template situations.""" stack = list(self._end_token_stack) if end_tokens is not None: stack.append(end_tokens) return self._fail_ut_eof(None, stack, lineno)
[ "Like", "fail_unknown_tag", "but", "for", "end", "of", "template", "situations", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/parser.py#L99-L104
[ "def", "fail_eof", "(", "self", ",", "end_tokens", "=", "None", ",", "lineno", "=", "None", ")", ":", "stack", "=", "list", "(", "self", ".", "_end_token_stack", ")", "if", "end_tokens", "is", "not", "None", ":", "stack", ".", "append", "(", "end_token...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Parser.is_tuple_end
Are we at the end of a tuple?
pipenv/vendor/jinja2/parser.py
def is_tuple_end(self, extra_end_rules=None): """Are we at the end of a tuple?""" if self.stream.current.type in ('variable_end', 'block_end', 'rparen'): return True elif extra_end_rules is not None: return self.stream.current.test_any(extra_end_rules) return False
def is_tuple_end(self, extra_end_rules=None): """Are we at the end of a tuple?""" if self.stream.current.type in ('variable_end', 'block_end', 'rparen'): return True elif extra_end_rules is not None: return self.stream.current.test_any(extra_end_rules) return False
[ "Are", "we", "at", "the", "end", "of", "a", "tuple?" ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/parser.py#L106-L112
[ "def", "is_tuple_end", "(", "self", ",", "extra_end_rules", "=", "None", ")", ":", "if", "self", ".", "stream", ".", "current", ".", "type", "in", "(", "'variable_end'", ",", "'block_end'", ",", "'rparen'", ")", ":", "return", "True", "elif", "extra_end_ru...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Parser.free_identifier
Return a new free identifier as :class:`~jinja2.nodes.InternalName`.
pipenv/vendor/jinja2/parser.py
def free_identifier(self, lineno=None): """Return a new free identifier as :class:`~jinja2.nodes.InternalName`.""" self._last_identifier += 1 rv = object.__new__(nodes.InternalName) nodes.Node.__init__(rv, 'fi%d' % self._last_identifier, lineno=lineno) return rv
def free_identifier(self, lineno=None): """Return a new free identifier as :class:`~jinja2.nodes.InternalName`.""" self._last_identifier += 1 rv = object.__new__(nodes.InternalName) nodes.Node.__init__(rv, 'fi%d' % self._last_identifier, lineno=lineno) return rv
[ "Return", "a", "new", "free", "identifier", "as", ":", "class", ":", "~jinja2", ".", "nodes", ".", "InternalName", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/parser.py#L114-L119
[ "def", "free_identifier", "(", "self", ",", "lineno", "=", "None", ")", ":", "self", ".", "_last_identifier", "+=", "1", "rv", "=", "object", ".", "__new__", "(", "nodes", ".", "InternalName", ")", "nodes", ".", "Node", ".", "__init__", "(", "rv", ",",...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Parser.parse_statement
Parse a single statement.
pipenv/vendor/jinja2/parser.py
def parse_statement(self): """Parse a single statement.""" token = self.stream.current if token.type != 'name': self.fail('tag name expected', token.lineno) self._tag_stack.append(token.value) pop_tag = True try: if token.value in _statement_keywords: return getattr(self, 'parse_' + self.stream.current.value)() if token.value == 'call': return self.parse_call_block() if token.value == 'filter': return self.parse_filter_block() ext = self.extensions.get(token.value) if ext is not None: return ext(self) # did not work out, remove the token we pushed by accident # from the stack so that the unknown tag fail function can # produce a proper error message. self._tag_stack.pop() pop_tag = False self.fail_unknown_tag(token.value, token.lineno) finally: if pop_tag: self._tag_stack.pop()
def parse_statement(self): """Parse a single statement.""" token = self.stream.current if token.type != 'name': self.fail('tag name expected', token.lineno) self._tag_stack.append(token.value) pop_tag = True try: if token.value in _statement_keywords: return getattr(self, 'parse_' + self.stream.current.value)() if token.value == 'call': return self.parse_call_block() if token.value == 'filter': return self.parse_filter_block() ext = self.extensions.get(token.value) if ext is not None: return ext(self) # did not work out, remove the token we pushed by accident # from the stack so that the unknown tag fail function can # produce a proper error message. self._tag_stack.pop() pop_tag = False self.fail_unknown_tag(token.value, token.lineno) finally: if pop_tag: self._tag_stack.pop()
[ "Parse", "a", "single", "statement", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/parser.py#L121-L147
[ "def", "parse_statement", "(", "self", ")", ":", "token", "=", "self", ".", "stream", ".", "current", "if", "token", ".", "type", "!=", "'name'", ":", "self", ".", "fail", "(", "'tag name expected'", ",", "token", ".", "lineno", ")", "self", ".", "_tag...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Parser.parse_statements
Parse multiple statements into a list until one of the end tokens is reached. This is used to parse the body of statements as it also parses template data if appropriate. The parser checks first if the current token is a colon and skips it if there is one. Then it checks for the block end and parses until if one of the `end_tokens` is reached. Per default the active token in the stream at the end of the call is the matched end token. If this is not wanted `drop_needle` can be set to `True` and the end token is removed.
pipenv/vendor/jinja2/parser.py
def parse_statements(self, end_tokens, drop_needle=False): """Parse multiple statements into a list until one of the end tokens is reached. This is used to parse the body of statements as it also parses template data if appropriate. The parser checks first if the current token is a colon and skips it if there is one. Then it checks for the block end and parses until if one of the `end_tokens` is reached. Per default the active token in the stream at the end of the call is the matched end token. If this is not wanted `drop_needle` can be set to `True` and the end token is removed. """ # the first token may be a colon for python compatibility self.stream.skip_if('colon') # in the future it would be possible to add whole code sections # by adding some sort of end of statement token and parsing those here. self.stream.expect('block_end') result = self.subparse(end_tokens) # we reached the end of the template too early, the subparser # does not check for this, so we do that now if self.stream.current.type == 'eof': self.fail_eof(end_tokens) if drop_needle: next(self.stream) return result
def parse_statements(self, end_tokens, drop_needle=False): """Parse multiple statements into a list until one of the end tokens is reached. This is used to parse the body of statements as it also parses template data if appropriate. The parser checks first if the current token is a colon and skips it if there is one. Then it checks for the block end and parses until if one of the `end_tokens` is reached. Per default the active token in the stream at the end of the call is the matched end token. If this is not wanted `drop_needle` can be set to `True` and the end token is removed. """ # the first token may be a colon for python compatibility self.stream.skip_if('colon') # in the future it would be possible to add whole code sections # by adding some sort of end of statement token and parsing those here. self.stream.expect('block_end') result = self.subparse(end_tokens) # we reached the end of the template too early, the subparser # does not check for this, so we do that now if self.stream.current.type == 'eof': self.fail_eof(end_tokens) if drop_needle: next(self.stream) return result
[ "Parse", "multiple", "statements", "into", "a", "list", "until", "one", "of", "the", "end", "tokens", "is", "reached", ".", "This", "is", "used", "to", "parse", "the", "body", "of", "statements", "as", "it", "also", "parses", "template", "data", "if", "a...
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/parser.py#L149-L174
[ "def", "parse_statements", "(", "self", ",", "end_tokens", ",", "drop_needle", "=", "False", ")", ":", "# the first token may be a colon for python compatibility", "self", ".", "stream", ".", "skip_if", "(", "'colon'", ")", "# in the future it would be possible to add whole...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Parser.parse_set
Parse an assign statement.
pipenv/vendor/jinja2/parser.py
def parse_set(self): """Parse an assign statement.""" lineno = next(self.stream).lineno target = self.parse_assign_target(with_namespace=True) if self.stream.skip_if('assign'): expr = self.parse_tuple() return nodes.Assign(target, expr, lineno=lineno) filter_node = self.parse_filter(None) body = self.parse_statements(('name:endset',), drop_needle=True) return nodes.AssignBlock(target, filter_node, body, lineno=lineno)
def parse_set(self): """Parse an assign statement.""" lineno = next(self.stream).lineno target = self.parse_assign_target(with_namespace=True) if self.stream.skip_if('assign'): expr = self.parse_tuple() return nodes.Assign(target, expr, lineno=lineno) filter_node = self.parse_filter(None) body = self.parse_statements(('name:endset',), drop_needle=True) return nodes.AssignBlock(target, filter_node, body, lineno=lineno)
[ "Parse", "an", "assign", "statement", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/parser.py#L176-L186
[ "def", "parse_set", "(", "self", ")", ":", "lineno", "=", "next", "(", "self", ".", "stream", ")", ".", "lineno", "target", "=", "self", ".", "parse_assign_target", "(", "with_namespace", "=", "True", ")", "if", "self", ".", "stream", ".", "skip_if", "...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Parser.parse_for
Parse a for loop.
pipenv/vendor/jinja2/parser.py
def parse_for(self): """Parse a for loop.""" lineno = self.stream.expect('name:for').lineno target = self.parse_assign_target(extra_end_rules=('name:in',)) self.stream.expect('name:in') iter = self.parse_tuple(with_condexpr=False, extra_end_rules=('name:recursive',)) test = None if self.stream.skip_if('name:if'): test = self.parse_expression() recursive = self.stream.skip_if('name:recursive') body = self.parse_statements(('name:endfor', 'name:else')) if next(self.stream).value == 'endfor': else_ = [] else: else_ = self.parse_statements(('name:endfor',), drop_needle=True) return nodes.For(target, iter, body, else_, test, recursive, lineno=lineno)
def parse_for(self): """Parse a for loop.""" lineno = self.stream.expect('name:for').lineno target = self.parse_assign_target(extra_end_rules=('name:in',)) self.stream.expect('name:in') iter = self.parse_tuple(with_condexpr=False, extra_end_rules=('name:recursive',)) test = None if self.stream.skip_if('name:if'): test = self.parse_expression() recursive = self.stream.skip_if('name:recursive') body = self.parse_statements(('name:endfor', 'name:else')) if next(self.stream).value == 'endfor': else_ = [] else: else_ = self.parse_statements(('name:endfor',), drop_needle=True) return nodes.For(target, iter, body, else_, test, recursive, lineno=lineno)
[ "Parse", "a", "for", "loop", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/parser.py#L188-L205
[ "def", "parse_for", "(", "self", ")", ":", "lineno", "=", "self", ".", "stream", ".", "expect", "(", "'name:for'", ")", ".", "lineno", "target", "=", "self", ".", "parse_assign_target", "(", "extra_end_rules", "=", "(", "'name:in'", ",", ")", ")", "self"...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Parser.parse_if
Parse an if construct.
pipenv/vendor/jinja2/parser.py
def parse_if(self): """Parse an if construct.""" node = result = nodes.If(lineno=self.stream.expect('name:if').lineno) while 1: node.test = self.parse_tuple(with_condexpr=False) node.body = self.parse_statements(('name:elif', 'name:else', 'name:endif')) node.elif_ = [] node.else_ = [] token = next(self.stream) if token.test('name:elif'): node = nodes.If(lineno=self.stream.current.lineno) result.elif_.append(node) continue elif token.test('name:else'): result.else_ = self.parse_statements(('name:endif',), drop_needle=True) break return result
def parse_if(self): """Parse an if construct.""" node = result = nodes.If(lineno=self.stream.expect('name:if').lineno) while 1: node.test = self.parse_tuple(with_condexpr=False) node.body = self.parse_statements(('name:elif', 'name:else', 'name:endif')) node.elif_ = [] node.else_ = [] token = next(self.stream) if token.test('name:elif'): node = nodes.If(lineno=self.stream.current.lineno) result.elif_.append(node) continue elif token.test('name:else'): result.else_ = self.parse_statements(('name:endif',), drop_needle=True) break return result
[ "Parse", "an", "if", "construct", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/parser.py#L207-L225
[ "def", "parse_if", "(", "self", ")", ":", "node", "=", "result", "=", "nodes", ".", "If", "(", "lineno", "=", "self", ".", "stream", ".", "expect", "(", "'name:if'", ")", ".", "lineno", ")", "while", "1", ":", "node", ".", "test", "=", "self", "....
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Parser.parse_assign_target
Parse an assignment target. As Jinja2 allows assignments to tuples, this function can parse all allowed assignment targets. Per default assignments to tuples are parsed, that can be disable however by setting `with_tuple` to `False`. If only assignments to names are wanted `name_only` can be set to `True`. The `extra_end_rules` parameter is forwarded to the tuple parsing function. If `with_namespace` is enabled, a namespace assignment may be parsed.
pipenv/vendor/jinja2/parser.py
def parse_assign_target(self, with_tuple=True, name_only=False, extra_end_rules=None, with_namespace=False): """Parse an assignment target. As Jinja2 allows assignments to tuples, this function can parse all allowed assignment targets. Per default assignments to tuples are parsed, that can be disable however by setting `with_tuple` to `False`. If only assignments to names are wanted `name_only` can be set to `True`. The `extra_end_rules` parameter is forwarded to the tuple parsing function. If `with_namespace` is enabled, a namespace assignment may be parsed. """ if with_namespace and self.stream.look().type == 'dot': token = self.stream.expect('name') next(self.stream) # dot attr = self.stream.expect('name') target = nodes.NSRef(token.value, attr.value, lineno=token.lineno) elif name_only: token = self.stream.expect('name') target = nodes.Name(token.value, 'store', lineno=token.lineno) else: if with_tuple: target = self.parse_tuple(simplified=True, extra_end_rules=extra_end_rules) else: target = self.parse_primary() target.set_ctx('store') if not target.can_assign(): self.fail('can\'t assign to %r' % target.__class__. __name__.lower(), target.lineno) return target
def parse_assign_target(self, with_tuple=True, name_only=False, extra_end_rules=None, with_namespace=False): """Parse an assignment target. As Jinja2 allows assignments to tuples, this function can parse all allowed assignment targets. Per default assignments to tuples are parsed, that can be disable however by setting `with_tuple` to `False`. If only assignments to names are wanted `name_only` can be set to `True`. The `extra_end_rules` parameter is forwarded to the tuple parsing function. If `with_namespace` is enabled, a namespace assignment may be parsed. """ if with_namespace and self.stream.look().type == 'dot': token = self.stream.expect('name') next(self.stream) # dot attr = self.stream.expect('name') target = nodes.NSRef(token.value, attr.value, lineno=token.lineno) elif name_only: token = self.stream.expect('name') target = nodes.Name(token.value, 'store', lineno=token.lineno) else: if with_tuple: target = self.parse_tuple(simplified=True, extra_end_rules=extra_end_rules) else: target = self.parse_primary() target.set_ctx('store') if not target.can_assign(): self.fail('can\'t assign to %r' % target.__class__. __name__.lower(), target.lineno) return target
[ "Parse", "an", "assignment", "target", ".", "As", "Jinja2", "allows", "assignments", "to", "tuples", "this", "function", "can", "parse", "all", "allowed", "assignment", "targets", ".", "Per", "default", "assignments", "to", "tuples", "are", "parsed", "that", "...
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/parser.py#L396-L424
[ "def", "parse_assign_target", "(", "self", ",", "with_tuple", "=", "True", ",", "name_only", "=", "False", ",", "extra_end_rules", "=", "None", ",", "with_namespace", "=", "False", ")", ":", "if", "with_namespace", "and", "self", ".", "stream", ".", "look", ...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Parser.parse
Parse the whole template into a `Template` node.
pipenv/vendor/jinja2/parser.py
def parse(self): """Parse the whole template into a `Template` node.""" result = nodes.Template(self.subparse(), lineno=1) result.set_environment(self.environment) return result
def parse(self): """Parse the whole template into a `Template` node.""" result = nodes.Template(self.subparse(), lineno=1) result.set_environment(self.environment) return result
[ "Parse", "the", "whole", "template", "into", "a", "Template", "node", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/parser.py#L899-L903
[ "def", "parse", "(", "self", ")", ":", "result", "=", "nodes", ".", "Template", "(", "self", ".", "subparse", "(", ")", ",", "lineno", "=", "1", ")", "result", ".", "set_environment", "(", "self", ".", "environment", ")", "return", "result" ]
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
ExceptionPexpect.get_trace
This returns an abbreviated stack trace with lines that only concern the caller. In other words, the stack trace inside the Pexpect module is not included.
pipenv/vendor/pexpect/exceptions.py
def get_trace(self): '''This returns an abbreviated stack trace with lines that only concern the caller. In other words, the stack trace inside the Pexpect module is not included. ''' tblist = traceback.extract_tb(sys.exc_info()[2]) tblist = [item for item in tblist if ('pexpect/__init__' not in item[0]) and ('pexpect/expect' not in item[0])] tblist = traceback.format_list(tblist) return ''.join(tblist)
def get_trace(self): '''This returns an abbreviated stack trace with lines that only concern the caller. In other words, the stack trace inside the Pexpect module is not included. ''' tblist = traceback.extract_tb(sys.exc_info()[2]) tblist = [item for item in tblist if ('pexpect/__init__' not in item[0]) and ('pexpect/expect' not in item[0])] tblist = traceback.format_list(tblist) return ''.join(tblist)
[ "This", "returns", "an", "abbreviated", "stack", "trace", "with", "lines", "that", "only", "concern", "the", "caller", ".", "In", "other", "words", "the", "stack", "trace", "inside", "the", "Pexpect", "module", "is", "not", "included", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pexpect/exceptions.py#L17-L26
[ "def", "get_trace", "(", "self", ")", ":", "tblist", "=", "traceback", ".", "extract_tb", "(", "sys", ".", "exc_info", "(", ")", "[", "2", "]", ")", "tblist", "=", "[", "item", "for", "item", "in", "tblist", "if", "(", "'pexpect/__init__'", "not", "i...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
parse_uri
Parses a URI using the regex given in Appendix B of RFC 3986. (scheme, authority, path, query, fragment) = parse_uri(uri)
pipenv/patched/notpip/_vendor/cachecontrol/controller.py
def parse_uri(uri): """Parses a URI using the regex given in Appendix B of RFC 3986. (scheme, authority, path, query, fragment) = parse_uri(uri) """ groups = URI.match(uri).groups() return (groups[1], groups[3], groups[4], groups[6], groups[8])
def parse_uri(uri): """Parses a URI using the regex given in Appendix B of RFC 3986. (scheme, authority, path, query, fragment) = parse_uri(uri) """ groups = URI.match(uri).groups() return (groups[1], groups[3], groups[4], groups[6], groups[8])
[ "Parses", "a", "URI", "using", "the", "regex", "given", "in", "Appendix", "B", "of", "RFC", "3986", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/cachecontrol/controller.py#L21-L27
[ "def", "parse_uri", "(", "uri", ")", ":", "groups", "=", "URI", ".", "match", "(", "uri", ")", ".", "groups", "(", ")", "return", "(", "groups", "[", "1", "]", ",", "groups", "[", "3", "]", ",", "groups", "[", "4", "]", ",", "groups", "[", "6...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
CacheController._urlnorm
Normalize the URL to create a safe key for the cache
pipenv/patched/notpip/_vendor/cachecontrol/controller.py
def _urlnorm(cls, uri): """Normalize the URL to create a safe key for the cache""" (scheme, authority, path, query, fragment) = parse_uri(uri) if not scheme or not authority: raise Exception("Only absolute URIs are allowed. uri = %s" % uri) scheme = scheme.lower() authority = authority.lower() if not path: path = "/" # Could do syntax based normalization of the URI before # computing the digest. See Section 6.2.2 of Std 66. request_uri = query and "?".join([path, query]) or path defrag_uri = scheme + "://" + authority + request_uri return defrag_uri
def _urlnorm(cls, uri): """Normalize the URL to create a safe key for the cache""" (scheme, authority, path, query, fragment) = parse_uri(uri) if not scheme or not authority: raise Exception("Only absolute URIs are allowed. uri = %s" % uri) scheme = scheme.lower() authority = authority.lower() if not path: path = "/" # Could do syntax based normalization of the URI before # computing the digest. See Section 6.2.2 of Std 66. request_uri = query and "?".join([path, query]) or path defrag_uri = scheme + "://" + authority + request_uri return defrag_uri
[ "Normalize", "the", "URL", "to", "create", "a", "safe", "key", "for", "the", "cache" ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/cachecontrol/controller.py#L43-L60
[ "def", "_urlnorm", "(", "cls", ",", "uri", ")", ":", "(", "scheme", ",", "authority", ",", "path", ",", "query", ",", "fragment", ")", "=", "parse_uri", "(", "uri", ")", "if", "not", "scheme", "or", "not", "authority", ":", "raise", "Exception", "(",...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
CacheController.cached_request
Return a cached response if it exists in the cache, otherwise return False.
pipenv/patched/notpip/_vendor/cachecontrol/controller.py
def cached_request(self, request): """ Return a cached response if it exists in the cache, otherwise return False. """ cache_url = self.cache_url(request.url) logger.debug('Looking up "%s" in the cache', cache_url) cc = self.parse_cache_control(request.headers) # Bail out if the request insists on fresh data if "no-cache" in cc: logger.debug('Request header has "no-cache", cache bypassed') return False if "max-age" in cc and cc["max-age"] == 0: logger.debug('Request header has "max_age" as 0, cache bypassed') return False # Request allows serving from the cache, let's see if we find something cache_data = self.cache.get(cache_url) if cache_data is None: logger.debug("No cache entry available") return False # Check whether it can be deserialized resp = self.serializer.loads(request, cache_data) if not resp: logger.warning("Cache entry deserialization failed, entry ignored") return False # If we have a cached 301, return it immediately. We don't # need to test our response for other headers b/c it is # intrinsically "cacheable" as it is Permanent. # See: # https://tools.ietf.org/html/rfc7231#section-6.4.2 # # Client can try to refresh the value by repeating the request # with cache busting headers as usual (ie no-cache). if resp.status == 301: msg = ( 'Returning cached "301 Moved Permanently" response ' "(ignoring date and etag information)" ) logger.debug(msg) return resp headers = CaseInsensitiveDict(resp.headers) if not headers or "date" not in headers: if "etag" not in headers: # Without date or etag, the cached response can never be used # and should be deleted. logger.debug("Purging cached response: no date or etag") self.cache.delete(cache_url) logger.debug("Ignoring cached response: no date") return False now = time.time() date = calendar.timegm(parsedate_tz(headers["date"])) current_age = max(0, now - date) logger.debug("Current age based on date: %i", current_age) # TODO: There is an assumption that the result will be a # urllib3 response object. This may not be best since we # could probably avoid instantiating or constructing the # response until we know we need it. resp_cc = self.parse_cache_control(headers) # determine freshness freshness_lifetime = 0 # Check the max-age pragma in the cache control header if "max-age" in resp_cc: freshness_lifetime = resp_cc["max-age"] logger.debug("Freshness lifetime from max-age: %i", freshness_lifetime) # If there isn't a max-age, check for an expires header elif "expires" in headers: expires = parsedate_tz(headers["expires"]) if expires is not None: expire_time = calendar.timegm(expires) - date freshness_lifetime = max(0, expire_time) logger.debug("Freshness lifetime from expires: %i", freshness_lifetime) # Determine if we are setting freshness limit in the # request. Note, this overrides what was in the response. if "max-age" in cc: freshness_lifetime = cc["max-age"] logger.debug( "Freshness lifetime from request max-age: %i", freshness_lifetime ) if "min-fresh" in cc: min_fresh = cc["min-fresh"] # adjust our current age by our min fresh current_age += min_fresh logger.debug("Adjusted current age from min-fresh: %i", current_age) # Return entry if it is fresh enough if freshness_lifetime > current_age: logger.debug('The response is "fresh", returning cached response') logger.debug("%i > %i", freshness_lifetime, current_age) return resp # we're not fresh. If we don't have an Etag, clear it out if "etag" not in headers: logger.debug('The cached response is "stale" with no etag, purging') self.cache.delete(cache_url) # return the original handler return False
def cached_request(self, request): """ Return a cached response if it exists in the cache, otherwise return False. """ cache_url = self.cache_url(request.url) logger.debug('Looking up "%s" in the cache', cache_url) cc = self.parse_cache_control(request.headers) # Bail out if the request insists on fresh data if "no-cache" in cc: logger.debug('Request header has "no-cache", cache bypassed') return False if "max-age" in cc and cc["max-age"] == 0: logger.debug('Request header has "max_age" as 0, cache bypassed') return False # Request allows serving from the cache, let's see if we find something cache_data = self.cache.get(cache_url) if cache_data is None: logger.debug("No cache entry available") return False # Check whether it can be deserialized resp = self.serializer.loads(request, cache_data) if not resp: logger.warning("Cache entry deserialization failed, entry ignored") return False # If we have a cached 301, return it immediately. We don't # need to test our response for other headers b/c it is # intrinsically "cacheable" as it is Permanent. # See: # https://tools.ietf.org/html/rfc7231#section-6.4.2 # # Client can try to refresh the value by repeating the request # with cache busting headers as usual (ie no-cache). if resp.status == 301: msg = ( 'Returning cached "301 Moved Permanently" response ' "(ignoring date and etag information)" ) logger.debug(msg) return resp headers = CaseInsensitiveDict(resp.headers) if not headers or "date" not in headers: if "etag" not in headers: # Without date or etag, the cached response can never be used # and should be deleted. logger.debug("Purging cached response: no date or etag") self.cache.delete(cache_url) logger.debug("Ignoring cached response: no date") return False now = time.time() date = calendar.timegm(parsedate_tz(headers["date"])) current_age = max(0, now - date) logger.debug("Current age based on date: %i", current_age) # TODO: There is an assumption that the result will be a # urllib3 response object. This may not be best since we # could probably avoid instantiating or constructing the # response until we know we need it. resp_cc = self.parse_cache_control(headers) # determine freshness freshness_lifetime = 0 # Check the max-age pragma in the cache control header if "max-age" in resp_cc: freshness_lifetime = resp_cc["max-age"] logger.debug("Freshness lifetime from max-age: %i", freshness_lifetime) # If there isn't a max-age, check for an expires header elif "expires" in headers: expires = parsedate_tz(headers["expires"]) if expires is not None: expire_time = calendar.timegm(expires) - date freshness_lifetime = max(0, expire_time) logger.debug("Freshness lifetime from expires: %i", freshness_lifetime) # Determine if we are setting freshness limit in the # request. Note, this overrides what was in the response. if "max-age" in cc: freshness_lifetime = cc["max-age"] logger.debug( "Freshness lifetime from request max-age: %i", freshness_lifetime ) if "min-fresh" in cc: min_fresh = cc["min-fresh"] # adjust our current age by our min fresh current_age += min_fresh logger.debug("Adjusted current age from min-fresh: %i", current_age) # Return entry if it is fresh enough if freshness_lifetime > current_age: logger.debug('The response is "fresh", returning cached response') logger.debug("%i > %i", freshness_lifetime, current_age) return resp # we're not fresh. If we don't have an Etag, clear it out if "etag" not in headers: logger.debug('The cached response is "stale" with no etag, purging') self.cache.delete(cache_url) # return the original handler return False
[ "Return", "a", "cached", "response", "if", "it", "exists", "in", "the", "cache", "otherwise", "return", "False", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/cachecontrol/controller.py#L120-L229
[ "def", "cached_request", "(", "self", ",", "request", ")", ":", "cache_url", "=", "self", ".", "cache_url", "(", "request", ".", "url", ")", "logger", ".", "debug", "(", "'Looking up \"%s\" in the cache'", ",", "cache_url", ")", "cc", "=", "self", ".", "pa...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
CacheController.cache_response
Algorithm for caching requests. This assumes a requests Response object.
pipenv/patched/notpip/_vendor/cachecontrol/controller.py
def cache_response(self, request, response, body=None, status_codes=None): """ Algorithm for caching requests. This assumes a requests Response object. """ # From httplib2: Don't cache 206's since we aren't going to # handle byte range requests cacheable_status_codes = status_codes or self.cacheable_status_codes if response.status not in cacheable_status_codes: logger.debug( "Status code %s not in %s", response.status, cacheable_status_codes ) return response_headers = CaseInsensitiveDict(response.headers) # If we've been given a body, our response has a Content-Length, that # Content-Length is valid then we can check to see if the body we've # been given matches the expected size, and if it doesn't we'll just # skip trying to cache it. if ( body is not None and "content-length" in response_headers and response_headers["content-length"].isdigit() and int(response_headers["content-length"]) != len(body) ): return cc_req = self.parse_cache_control(request.headers) cc = self.parse_cache_control(response_headers) cache_url = self.cache_url(request.url) logger.debug('Updating cache with response from "%s"', cache_url) # Delete it from the cache if we happen to have it stored there no_store = False if "no-store" in cc: no_store = True logger.debug('Response header has "no-store"') if "no-store" in cc_req: no_store = True logger.debug('Request header has "no-store"') if no_store and self.cache.get(cache_url): logger.debug('Purging existing cache entry to honor "no-store"') self.cache.delete(cache_url) if no_store: return # If we've been given an etag, then keep the response if self.cache_etags and "etag" in response_headers: logger.debug("Caching due to etag") self.cache.set( cache_url, self.serializer.dumps(request, response, body=body) ) # Add to the cache any 301s. We do this before looking that # the Date headers. elif response.status == 301: logger.debug("Caching permanant redirect") self.cache.set(cache_url, self.serializer.dumps(request, response)) # Add to the cache if the response headers demand it. If there # is no date header then we can't do anything about expiring # the cache. elif "date" in response_headers: # cache when there is a max-age > 0 if "max-age" in cc and cc["max-age"] > 0: logger.debug("Caching b/c date exists and max-age > 0") self.cache.set( cache_url, self.serializer.dumps(request, response, body=body) ) # If the request can expire, it means we should cache it # in the meantime. elif "expires" in response_headers: if response_headers["expires"]: logger.debug("Caching b/c of expires header") self.cache.set( cache_url, self.serializer.dumps(request, response, body=body) )
def cache_response(self, request, response, body=None, status_codes=None): """ Algorithm for caching requests. This assumes a requests Response object. """ # From httplib2: Don't cache 206's since we aren't going to # handle byte range requests cacheable_status_codes = status_codes or self.cacheable_status_codes if response.status not in cacheable_status_codes: logger.debug( "Status code %s not in %s", response.status, cacheable_status_codes ) return response_headers = CaseInsensitiveDict(response.headers) # If we've been given a body, our response has a Content-Length, that # Content-Length is valid then we can check to see if the body we've # been given matches the expected size, and if it doesn't we'll just # skip trying to cache it. if ( body is not None and "content-length" in response_headers and response_headers["content-length"].isdigit() and int(response_headers["content-length"]) != len(body) ): return cc_req = self.parse_cache_control(request.headers) cc = self.parse_cache_control(response_headers) cache_url = self.cache_url(request.url) logger.debug('Updating cache with response from "%s"', cache_url) # Delete it from the cache if we happen to have it stored there no_store = False if "no-store" in cc: no_store = True logger.debug('Response header has "no-store"') if "no-store" in cc_req: no_store = True logger.debug('Request header has "no-store"') if no_store and self.cache.get(cache_url): logger.debug('Purging existing cache entry to honor "no-store"') self.cache.delete(cache_url) if no_store: return # If we've been given an etag, then keep the response if self.cache_etags and "etag" in response_headers: logger.debug("Caching due to etag") self.cache.set( cache_url, self.serializer.dumps(request, response, body=body) ) # Add to the cache any 301s. We do this before looking that # the Date headers. elif response.status == 301: logger.debug("Caching permanant redirect") self.cache.set(cache_url, self.serializer.dumps(request, response)) # Add to the cache if the response headers demand it. If there # is no date header then we can't do anything about expiring # the cache. elif "date" in response_headers: # cache when there is a max-age > 0 if "max-age" in cc and cc["max-age"] > 0: logger.debug("Caching b/c date exists and max-age > 0") self.cache.set( cache_url, self.serializer.dumps(request, response, body=body) ) # If the request can expire, it means we should cache it # in the meantime. elif "expires" in response_headers: if response_headers["expires"]: logger.debug("Caching b/c of expires header") self.cache.set( cache_url, self.serializer.dumps(request, response, body=body) )
[ "Algorithm", "for", "caching", "requests", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/cachecontrol/controller.py#L247-L327
[ "def", "cache_response", "(", "self", ",", "request", ",", "response", ",", "body", "=", "None", ",", "status_codes", "=", "None", ")", ":", "# From httplib2: Don't cache 206's since we aren't going to", "# handle byte range requests", "cacheable_status_codes",...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
CacheController.update_cached_response
On a 304 we will get a new set of headers that we want to update our cached value with, assuming we have one. This should only ever be called when we've sent an ETag and gotten a 304 as the response.
pipenv/patched/notpip/_vendor/cachecontrol/controller.py
def update_cached_response(self, request, response): """On a 304 we will get a new set of headers that we want to update our cached value with, assuming we have one. This should only ever be called when we've sent an ETag and gotten a 304 as the response. """ cache_url = self.cache_url(request.url) cached_response = self.serializer.loads(request, self.cache.get(cache_url)) if not cached_response: # we didn't have a cached response return response # Lets update our headers with the headers from the new request: # http://tools.ietf.org/html/draft-ietf-httpbis-p4-conditional-26#section-4.1 # # The server isn't supposed to send headers that would make # the cached body invalid. But... just in case, we'll be sure # to strip out ones we know that might be problmatic due to # typical assumptions. excluded_headers = ["content-length"] cached_response.headers.update( dict( (k, v) for k, v in response.headers.items() if k.lower() not in excluded_headers ) ) # we want a 200 b/c we have content via the cache cached_response.status = 200 # update our cache self.cache.set(cache_url, self.serializer.dumps(request, cached_response)) return cached_response
def update_cached_response(self, request, response): """On a 304 we will get a new set of headers that we want to update our cached value with, assuming we have one. This should only ever be called when we've sent an ETag and gotten a 304 as the response. """ cache_url = self.cache_url(request.url) cached_response = self.serializer.loads(request, self.cache.get(cache_url)) if not cached_response: # we didn't have a cached response return response # Lets update our headers with the headers from the new request: # http://tools.ietf.org/html/draft-ietf-httpbis-p4-conditional-26#section-4.1 # # The server isn't supposed to send headers that would make # the cached body invalid. But... just in case, we'll be sure # to strip out ones we know that might be problmatic due to # typical assumptions. excluded_headers = ["content-length"] cached_response.headers.update( dict( (k, v) for k, v in response.headers.items() if k.lower() not in excluded_headers ) ) # we want a 200 b/c we have content via the cache cached_response.status = 200 # update our cache self.cache.set(cache_url, self.serializer.dumps(request, cached_response)) return cached_response
[ "On", "a", "304", "we", "will", "get", "a", "new", "set", "of", "headers", "that", "we", "want", "to", "update", "our", "cached", "value", "with", "assuming", "we", "have", "one", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/cachecontrol/controller.py#L329-L367
[ "def", "update_cached_response", "(", "self", ",", "request", ",", "response", ")", ":", "cache_url", "=", "self", ".", "cache_url", "(", "request", ".", "url", ")", "cached_response", "=", "self", ".", "serializer", ".", "loads", "(", "request", ",", "sel...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
fdspawn.close
Close the file descriptor. Calling this method a second time does nothing, but if the file descriptor was closed elsewhere, :class:`OSError` will be raised.
pipenv/vendor/pexpect/fdpexpect.py
def close (self): """Close the file descriptor. Calling this method a second time does nothing, but if the file descriptor was closed elsewhere, :class:`OSError` will be raised. """ if self.child_fd == -1: return self.flush() os.close(self.child_fd) self.child_fd = -1 self.closed = True
def close (self): """Close the file descriptor. Calling this method a second time does nothing, but if the file descriptor was closed elsewhere, :class:`OSError` will be raised. """ if self.child_fd == -1: return self.flush() os.close(self.child_fd) self.child_fd = -1 self.closed = True
[ "Close", "the", "file", "descriptor", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pexpect/fdpexpect.py#L63-L75
[ "def", "close", "(", "self", ")", ":", "if", "self", ".", "child_fd", "==", "-", "1", ":", "return", "self", ".", "flush", "(", ")", "os", ".", "close", "(", "self", ".", "child_fd", ")", "self", ".", "child_fd", "=", "-", "1", "self", ".", "cl...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
fdspawn.isalive
This checks if the file descriptor is still valid. If :func:`os.fstat` does not raise an exception then we assume it is alive.
pipenv/vendor/pexpect/fdpexpect.py
def isalive (self): '''This checks if the file descriptor is still valid. If :func:`os.fstat` does not raise an exception then we assume it is alive. ''' if self.child_fd == -1: return False try: os.fstat(self.child_fd) return True except: return False
def isalive (self): '''This checks if the file descriptor is still valid. If :func:`os.fstat` does not raise an exception then we assume it is alive. ''' if self.child_fd == -1: return False try: os.fstat(self.child_fd) return True except: return False
[ "This", "checks", "if", "the", "file", "descriptor", "is", "still", "valid", ".", "If", ":", "func", ":", "os", ".", "fstat", "does", "not", "raise", "an", "exception", "then", "we", "assume", "it", "is", "alive", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pexpect/fdpexpect.py#L77-L87
[ "def", "isalive", "(", "self", ")", ":", "if", "self", ".", "child_fd", "==", "-", "1", ":", "return", "False", "try", ":", "os", ".", "fstat", "(", "self", ".", "child_fd", ")", "return", "True", "except", ":", "return", "False" ]
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
fdspawn.read_nonblocking
Read from the file descriptor and return the result as a string. The read_nonblocking method of :class:`SpawnBase` assumes that a call to os.read will not block (timeout parameter is ignored). This is not the case for POSIX file-like objects such as sockets and serial ports. Use :func:`select.select`, timeout is implemented conditionally for POSIX systems. :param int size: Read at most *size* bytes. :param int timeout: Wait timeout seconds for file descriptor to be ready to read. When -1 (default), use self.timeout. When 0, poll. :return: String containing the bytes read
pipenv/vendor/pexpect/fdpexpect.py
def read_nonblocking(self, size=1, timeout=-1): """ Read from the file descriptor and return the result as a string. The read_nonblocking method of :class:`SpawnBase` assumes that a call to os.read will not block (timeout parameter is ignored). This is not the case for POSIX file-like objects such as sockets and serial ports. Use :func:`select.select`, timeout is implemented conditionally for POSIX systems. :param int size: Read at most *size* bytes. :param int timeout: Wait timeout seconds for file descriptor to be ready to read. When -1 (default), use self.timeout. When 0, poll. :return: String containing the bytes read """ if os.name == 'posix': if timeout == -1: timeout = self.timeout rlist = [self.child_fd] wlist = [] xlist = [] if self.use_poll: rlist = poll_ignore_interrupts(rlist, timeout) else: rlist, wlist, xlist = select_ignore_interrupts( rlist, wlist, xlist, timeout ) if self.child_fd not in rlist: raise TIMEOUT('Timeout exceeded.') return super(fdspawn, self).read_nonblocking(size)
def read_nonblocking(self, size=1, timeout=-1): """ Read from the file descriptor and return the result as a string. The read_nonblocking method of :class:`SpawnBase` assumes that a call to os.read will not block (timeout parameter is ignored). This is not the case for POSIX file-like objects such as sockets and serial ports. Use :func:`select.select`, timeout is implemented conditionally for POSIX systems. :param int size: Read at most *size* bytes. :param int timeout: Wait timeout seconds for file descriptor to be ready to read. When -1 (default), use self.timeout. When 0, poll. :return: String containing the bytes read """ if os.name == 'posix': if timeout == -1: timeout = self.timeout rlist = [self.child_fd] wlist = [] xlist = [] if self.use_poll: rlist = poll_ignore_interrupts(rlist, timeout) else: rlist, wlist, xlist = select_ignore_interrupts( rlist, wlist, xlist, timeout ) if self.child_fd not in rlist: raise TIMEOUT('Timeout exceeded.') return super(fdspawn, self).read_nonblocking(size)
[ "Read", "from", "the", "file", "descriptor", "and", "return", "the", "result", "as", "a", "string", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pexpect/fdpexpect.py#L118-L148
[ "def", "read_nonblocking", "(", "self", ",", "size", "=", "1", ",", "timeout", "=", "-", "1", ")", ":", "if", "os", ".", "name", "==", "'posix'", ":", "if", "timeout", "==", "-", "1", ":", "timeout", "=", "self", ".", "timeout", "rlist", "=", "["...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
clear_caches
Jinja2 keeps internal caches for environments and lexers. These are used so that Jinja2 doesn't have to recreate environments and lexers all the time. Normally you don't have to care about that but if you are measuring memory consumption you may want to clean the caches.
pipenv/vendor/jinja2/utils.py
def clear_caches(): """Jinja2 keeps internal caches for environments and lexers. These are used so that Jinja2 doesn't have to recreate environments and lexers all the time. Normally you don't have to care about that but if you are measuring memory consumption you may want to clean the caches. """ from jinja2.environment import _spontaneous_environments from jinja2.lexer import _lexer_cache _spontaneous_environments.clear() _lexer_cache.clear()
def clear_caches(): """Jinja2 keeps internal caches for environments and lexers. These are used so that Jinja2 doesn't have to recreate environments and lexers all the time. Normally you don't have to care about that but if you are measuring memory consumption you may want to clean the caches. """ from jinja2.environment import _spontaneous_environments from jinja2.lexer import _lexer_cache _spontaneous_environments.clear() _lexer_cache.clear()
[ "Jinja2", "keeps", "internal", "caches", "for", "environments", "and", "lexers", ".", "These", "are", "used", "so", "that", "Jinja2", "doesn", "t", "have", "to", "recreate", "environments", "and", "lexers", "all", "the", "time", ".", "Normally", "you", "don"...
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/utils.py#L111-L120
[ "def", "clear_caches", "(", ")", ":", "from", "jinja2", ".", "environment", "import", "_spontaneous_environments", "from", "jinja2", ".", "lexer", "import", "_lexer_cache", "_spontaneous_environments", ".", "clear", "(", ")", "_lexer_cache", ".", "clear", "(", ")"...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
import_string
Imports an object based on a string. This is useful if you want to use import paths as endpoints or something similar. An import path can be specified either in dotted notation (``xml.sax.saxutils.escape``) or with a colon as object delimiter (``xml.sax.saxutils:escape``). If the `silent` is True the return value will be `None` if the import fails. :return: imported object
pipenv/vendor/jinja2/utils.py
def import_string(import_name, silent=False): """Imports an object based on a string. This is useful if you want to use import paths as endpoints or something similar. An import path can be specified either in dotted notation (``xml.sax.saxutils.escape``) or with a colon as object delimiter (``xml.sax.saxutils:escape``). If the `silent` is True the return value will be `None` if the import fails. :return: imported object """ try: if ':' in import_name: module, obj = import_name.split(':', 1) elif '.' in import_name: items = import_name.split('.') module = '.'.join(items[:-1]) obj = items[-1] else: return __import__(import_name) return getattr(__import__(module, None, None, [obj]), obj) except (ImportError, AttributeError): if not silent: raise
def import_string(import_name, silent=False): """Imports an object based on a string. This is useful if you want to use import paths as endpoints or something similar. An import path can be specified either in dotted notation (``xml.sax.saxutils.escape``) or with a colon as object delimiter (``xml.sax.saxutils:escape``). If the `silent` is True the return value will be `None` if the import fails. :return: imported object """ try: if ':' in import_name: module, obj = import_name.split(':', 1) elif '.' in import_name: items = import_name.split('.') module = '.'.join(items[:-1]) obj = items[-1] else: return __import__(import_name) return getattr(__import__(module, None, None, [obj]), obj) except (ImportError, AttributeError): if not silent: raise
[ "Imports", "an", "object", "based", "on", "a", "string", ".", "This", "is", "useful", "if", "you", "want", "to", "use", "import", "paths", "as", "endpoints", "or", "something", "similar", ".", "An", "import", "path", "can", "be", "specified", "either", "...
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/utils.py#L123-L146
[ "def", "import_string", "(", "import_name", ",", "silent", "=", "False", ")", ":", "try", ":", "if", "':'", "in", "import_name", ":", "module", ",", "obj", "=", "import_name", ".", "split", "(", "':'", ",", "1", ")", "elif", "'.'", "in", "import_name",...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
pformat
Prettyprint an object. Either use the `pretty` library or the builtin `pprint`.
pipenv/vendor/jinja2/utils.py
def pformat(obj, verbose=False): """Prettyprint an object. Either use the `pretty` library or the builtin `pprint`. """ try: from pretty import pretty return pretty(obj, verbose=verbose) except ImportError: from pprint import pformat return pformat(obj)
def pformat(obj, verbose=False): """Prettyprint an object. Either use the `pretty` library or the builtin `pprint`. """ try: from pretty import pretty return pretty(obj, verbose=verbose) except ImportError: from pprint import pformat return pformat(obj)
[ "Prettyprint", "an", "object", ".", "Either", "use", "the", "pretty", "library", "or", "the", "builtin", "pprint", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/utils.py#L177-L186
[ "def", "pformat", "(", "obj", ",", "verbose", "=", "False", ")", ":", "try", ":", "from", "pretty", "import", "pretty", "return", "pretty", "(", "obj", ",", "verbose", "=", "verbose", ")", "except", "ImportError", ":", "from", "pprint", "import", "pforma...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
unicode_urlencode
URL escapes a single bytestring or unicode string with the given charset if applicable to URL safe quoting under all rules that need to be considered under all supported Python versions. If non strings are provided they are converted to their unicode representation first.
pipenv/vendor/jinja2/utils.py
def unicode_urlencode(obj, charset='utf-8', for_qs=False): """URL escapes a single bytestring or unicode string with the given charset if applicable to URL safe quoting under all rules that need to be considered under all supported Python versions. If non strings are provided they are converted to their unicode representation first. """ if not isinstance(obj, string_types): obj = text_type(obj) if isinstance(obj, text_type): obj = obj.encode(charset) safe = not for_qs and b'/' or b'' rv = text_type(url_quote(obj, safe)) if for_qs: rv = rv.replace('%20', '+') return rv
def unicode_urlencode(obj, charset='utf-8', for_qs=False): """URL escapes a single bytestring or unicode string with the given charset if applicable to URL safe quoting under all rules that need to be considered under all supported Python versions. If non strings are provided they are converted to their unicode representation first. """ if not isinstance(obj, string_types): obj = text_type(obj) if isinstance(obj, text_type): obj = obj.encode(charset) safe = not for_qs and b'/' or b'' rv = text_type(url_quote(obj, safe)) if for_qs: rv = rv.replace('%20', '+') return rv
[ "URL", "escapes", "a", "single", "bytestring", "or", "unicode", "string", "with", "the", "given", "charset", "if", "applicable", "to", "URL", "safe", "quoting", "under", "all", "rules", "that", "need", "to", "be", "considered", "under", "all", "supported", "...
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/utils.py#L287-L303
[ "def", "unicode_urlencode", "(", "obj", ",", "charset", "=", "'utf-8'", ",", "for_qs", "=", "False", ")", ":", "if", "not", "isinstance", "(", "obj", ",", "string_types", ")", ":", "obj", "=", "text_type", "(", "obj", ")", "if", "isinstance", "(", "obj...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
select_autoescape
Intelligently sets the initial value of autoescaping based on the filename of the template. This is the recommended way to configure autoescaping if you do not want to write a custom function yourself. If you want to enable it for all templates created from strings or for all templates with `.html` and `.xml` extensions:: from jinja2 import Environment, select_autoescape env = Environment(autoescape=select_autoescape( enabled_extensions=('html', 'xml'), default_for_string=True, )) Example configuration to turn it on at all times except if the template ends with `.txt`:: from jinja2 import Environment, select_autoescape env = Environment(autoescape=select_autoescape( disabled_extensions=('txt',), default_for_string=True, default=True, )) The `enabled_extensions` is an iterable of all the extensions that autoescaping should be enabled for. Likewise `disabled_extensions` is a list of all templates it should be disabled for. If a template is loaded from a string then the default from `default_for_string` is used. If nothing matches then the initial value of autoescaping is set to the value of `default`. For security reasons this function operates case insensitive. .. versionadded:: 2.9
pipenv/vendor/jinja2/utils.py
def select_autoescape(enabled_extensions=('html', 'htm', 'xml'), disabled_extensions=(), default_for_string=True, default=False): """Intelligently sets the initial value of autoescaping based on the filename of the template. This is the recommended way to configure autoescaping if you do not want to write a custom function yourself. If you want to enable it for all templates created from strings or for all templates with `.html` and `.xml` extensions:: from jinja2 import Environment, select_autoescape env = Environment(autoescape=select_autoescape( enabled_extensions=('html', 'xml'), default_for_string=True, )) Example configuration to turn it on at all times except if the template ends with `.txt`:: from jinja2 import Environment, select_autoescape env = Environment(autoescape=select_autoescape( disabled_extensions=('txt',), default_for_string=True, default=True, )) The `enabled_extensions` is an iterable of all the extensions that autoescaping should be enabled for. Likewise `disabled_extensions` is a list of all templates it should be disabled for. If a template is loaded from a string then the default from `default_for_string` is used. If nothing matches then the initial value of autoescaping is set to the value of `default`. For security reasons this function operates case insensitive. .. versionadded:: 2.9 """ enabled_patterns = tuple('.' + x.lstrip('.').lower() for x in enabled_extensions) disabled_patterns = tuple('.' + x.lstrip('.').lower() for x in disabled_extensions) def autoescape(template_name): if template_name is None: return default_for_string template_name = template_name.lower() if template_name.endswith(enabled_patterns): return True if template_name.endswith(disabled_patterns): return False return default return autoescape
def select_autoescape(enabled_extensions=('html', 'htm', 'xml'), disabled_extensions=(), default_for_string=True, default=False): """Intelligently sets the initial value of autoescaping based on the filename of the template. This is the recommended way to configure autoescaping if you do not want to write a custom function yourself. If you want to enable it for all templates created from strings or for all templates with `.html` and `.xml` extensions:: from jinja2 import Environment, select_autoescape env = Environment(autoescape=select_autoescape( enabled_extensions=('html', 'xml'), default_for_string=True, )) Example configuration to turn it on at all times except if the template ends with `.txt`:: from jinja2 import Environment, select_autoescape env = Environment(autoescape=select_autoescape( disabled_extensions=('txt',), default_for_string=True, default=True, )) The `enabled_extensions` is an iterable of all the extensions that autoescaping should be enabled for. Likewise `disabled_extensions` is a list of all templates it should be disabled for. If a template is loaded from a string then the default from `default_for_string` is used. If nothing matches then the initial value of autoescaping is set to the value of `default`. For security reasons this function operates case insensitive. .. versionadded:: 2.9 """ enabled_patterns = tuple('.' + x.lstrip('.').lower() for x in enabled_extensions) disabled_patterns = tuple('.' + x.lstrip('.').lower() for x in disabled_extensions) def autoescape(template_name): if template_name is None: return default_for_string template_name = template_name.lower() if template_name.endswith(enabled_patterns): return True if template_name.endswith(disabled_patterns): return False return default return autoescape
[ "Intelligently", "sets", "the", "initial", "value", "of", "autoescaping", "based", "on", "the", "filename", "of", "the", "template", ".", "This", "is", "the", "recommended", "way", "to", "configure", "autoescaping", "if", "you", "do", "not", "want", "to", "w...
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/utils.py#L491-L542
[ "def", "select_autoescape", "(", "enabled_extensions", "=", "(", "'html'", ",", "'htm'", ",", "'xml'", ")", ",", "disabled_extensions", "=", "(", ")", ",", "default_for_string", "=", "True", ",", "default", "=", "False", ")", ":", "enabled_patterns", "=", "t...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
htmlsafe_json_dumps
Works exactly like :func:`dumps` but is safe for use in ``<script>`` tags. It accepts the same arguments and returns a JSON string. Note that this is available in templates through the ``|tojson`` filter which will also mark the result as safe. Due to how this function escapes certain characters this is safe even if used outside of ``<script>`` tags. The following characters are escaped in strings: - ``<`` - ``>`` - ``&`` - ``'`` This makes it safe to embed such strings in any place in HTML with the notable exception of double quoted attributes. In that case single quote your attributes or HTML escape it in addition.
pipenv/vendor/jinja2/utils.py
def htmlsafe_json_dumps(obj, dumper=None, **kwargs): """Works exactly like :func:`dumps` but is safe for use in ``<script>`` tags. It accepts the same arguments and returns a JSON string. Note that this is available in templates through the ``|tojson`` filter which will also mark the result as safe. Due to how this function escapes certain characters this is safe even if used outside of ``<script>`` tags. The following characters are escaped in strings: - ``<`` - ``>`` - ``&`` - ``'`` This makes it safe to embed such strings in any place in HTML with the notable exception of double quoted attributes. In that case single quote your attributes or HTML escape it in addition. """ if dumper is None: dumper = json.dumps rv = dumper(obj, **kwargs) \ .replace(u'<', u'\\u003c') \ .replace(u'>', u'\\u003e') \ .replace(u'&', u'\\u0026') \ .replace(u"'", u'\\u0027') return Markup(rv)
def htmlsafe_json_dumps(obj, dumper=None, **kwargs): """Works exactly like :func:`dumps` but is safe for use in ``<script>`` tags. It accepts the same arguments and returns a JSON string. Note that this is available in templates through the ``|tojson`` filter which will also mark the result as safe. Due to how this function escapes certain characters this is safe even if used outside of ``<script>`` tags. The following characters are escaped in strings: - ``<`` - ``>`` - ``&`` - ``'`` This makes it safe to embed such strings in any place in HTML with the notable exception of double quoted attributes. In that case single quote your attributes or HTML escape it in addition. """ if dumper is None: dumper = json.dumps rv = dumper(obj, **kwargs) \ .replace(u'<', u'\\u003c') \ .replace(u'>', u'\\u003e') \ .replace(u'&', u'\\u0026') \ .replace(u"'", u'\\u0027') return Markup(rv)
[ "Works", "exactly", "like", ":", "func", ":", "dumps", "but", "is", "safe", "for", "use", "in", "<script", ">", "tags", ".", "It", "accepts", "the", "same", "arguments", "and", "returns", "a", "JSON", "string", ".", "Note", "that", "this", "is", "avail...
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/utils.py#L545-L570
[ "def", "htmlsafe_json_dumps", "(", "obj", ",", "dumper", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "dumper", "is", "None", ":", "dumper", "=", "json", ".", "dumps", "rv", "=", "dumper", "(", "obj", ",", "*", "*", "kwargs", ")", ".", "...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
LRUCache.copy
Return a shallow copy of the instance.
pipenv/vendor/jinja2/utils.py
def copy(self): """Return a shallow copy of the instance.""" rv = self.__class__(self.capacity) rv._mapping.update(self._mapping) rv._queue = deque(self._queue) return rv
def copy(self): """Return a shallow copy of the instance.""" rv = self.__class__(self.capacity) rv._mapping.update(self._mapping) rv._queue = deque(self._queue) return rv
[ "Return", "a", "shallow", "copy", "of", "the", "instance", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/utils.py#L341-L346
[ "def", "copy", "(", "self", ")", ":", "rv", "=", "self", ".", "__class__", "(", "self", ".", "capacity", ")", "rv", ".", "_mapping", ".", "update", "(", "self", ".", "_mapping", ")", "rv", ".", "_queue", "=", "deque", "(", "self", ".", "_queue", ...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
LRUCache.setdefault
Set `default` if the key is not in the cache otherwise leave unchanged. Return the value of this key.
pipenv/vendor/jinja2/utils.py
def setdefault(self, key, default=None): """Set `default` if the key is not in the cache otherwise leave unchanged. Return the value of this key. """ self._wlock.acquire() try: try: return self[key] except KeyError: self[key] = default return default finally: self._wlock.release()
def setdefault(self, key, default=None): """Set `default` if the key is not in the cache otherwise leave unchanged. Return the value of this key. """ self._wlock.acquire() try: try: return self[key] except KeyError: self[key] = default return default finally: self._wlock.release()
[ "Set", "default", "if", "the", "key", "is", "not", "in", "the", "cache", "otherwise", "leave", "unchanged", ".", "Return", "the", "value", "of", "this", "key", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/utils.py#L355-L367
[ "def", "setdefault", "(", "self", ",", "key", ",", "default", "=", "None", ")", ":", "self", ".", "_wlock", ".", "acquire", "(", ")", "try", ":", "try", ":", "return", "self", "[", "key", "]", "except", "KeyError", ":", "self", "[", "key", "]", "...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
LRUCache.clear
Clear the cache.
pipenv/vendor/jinja2/utils.py
def clear(self): """Clear the cache.""" self._wlock.acquire() try: self._mapping.clear() self._queue.clear() finally: self._wlock.release()
def clear(self): """Clear the cache.""" self._wlock.acquire() try: self._mapping.clear() self._queue.clear() finally: self._wlock.release()
[ "Clear", "the", "cache", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/utils.py#L369-L376
[ "def", "clear", "(", "self", ")", ":", "self", ".", "_wlock", ".", "acquire", "(", ")", "try", ":", "self", ".", "_mapping", ".", "clear", "(", ")", "self", ".", "_queue", ".", "clear", "(", ")", "finally", ":", "self", ".", "_wlock", ".", "relea...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
LRUCache.items
Return a list of items.
pipenv/vendor/jinja2/utils.py
def items(self): """Return a list of items.""" result = [(key, self._mapping[key]) for key in list(self._queue)] result.reverse() return result
def items(self): """Return a list of items.""" result = [(key, self._mapping[key]) for key in list(self._queue)] result.reverse() return result
[ "Return", "a", "list", "of", "items", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/utils.py#L444-L448
[ "def", "items", "(", "self", ")", ":", "result", "=", "[", "(", "key", ",", "self", ".", "_mapping", "[", "key", "]", ")", "for", "key", "in", "list", "(", "self", ".", "_queue", ")", "]", "result", ".", "reverse", "(", ")", "return", "result" ]
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
license_fallback
Hardcoded license URLs. Check when updating if those are still needed
tasks/vendoring/__init__.py
def license_fallback(vendor_dir, sdist_name): """Hardcoded license URLs. Check when updating if those are still needed""" libname = libname_from_dir(sdist_name) if libname not in HARDCODED_LICENSE_URLS: raise ValueError('No hardcoded URL for {} license'.format(libname)) url = HARDCODED_LICENSE_URLS[libname] _, _, name = url.rpartition('/') dest = license_destination(vendor_dir, libname, name) r = requests.get(url, allow_redirects=True) log('Downloading {}'.format(url)) r.raise_for_status() dest.write_bytes(r.content)
def license_fallback(vendor_dir, sdist_name): """Hardcoded license URLs. Check when updating if those are still needed""" libname = libname_from_dir(sdist_name) if libname not in HARDCODED_LICENSE_URLS: raise ValueError('No hardcoded URL for {} license'.format(libname)) url = HARDCODED_LICENSE_URLS[libname] _, _, name = url.rpartition('/') dest = license_destination(vendor_dir, libname, name) r = requests.get(url, allow_redirects=True) log('Downloading {}'.format(url)) r.raise_for_status() dest.write_bytes(r.content)
[ "Hardcoded", "license", "URLs", ".", "Check", "when", "updating", "if", "those", "are", "still", "needed" ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/tasks/vendoring/__init__.py#L588-L600
[ "def", "license_fallback", "(", "vendor_dir", ",", "sdist_name", ")", ":", "libname", "=", "libname_from_dir", "(", "sdist_name", ")", "if", "libname", "not", "in", "HARDCODED_LICENSE_URLS", ":", "raise", "ValueError", "(", "'No hardcoded URL for {} license'", ".", ...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
libname_from_dir
Reconstruct the library name without it's version
tasks/vendoring/__init__.py
def libname_from_dir(dirname): """Reconstruct the library name without it's version""" parts = [] for part in dirname.split('-'): if part[0].isdigit(): break parts.append(part) return '-'.join(parts)
def libname_from_dir(dirname): """Reconstruct the library name without it's version""" parts = [] for part in dirname.split('-'): if part[0].isdigit(): break parts.append(part) return '-'.join(parts)
[ "Reconstruct", "the", "library", "name", "without", "it", "s", "version" ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/tasks/vendoring/__init__.py#L603-L610
[ "def", "libname_from_dir", "(", "dirname", ")", ":", "parts", "=", "[", "]", "for", "part", "in", "dirname", ".", "split", "(", "'-'", ")", ":", "if", "part", "[", "0", "]", ".", "isdigit", "(", ")", ":", "break", "parts", ".", "append", "(", "pa...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
license_destination
Given the (reconstructed) library name, find appropriate destination
tasks/vendoring/__init__.py
def license_destination(vendor_dir, libname, filename): """Given the (reconstructed) library name, find appropriate destination""" normal = vendor_dir / libname if normal.is_dir(): return normal / filename lowercase = vendor_dir / libname.lower().replace('-', '_') if lowercase.is_dir(): return lowercase / filename rename_dict = LIBRARY_RENAMES if vendor_dir.name != 'patched' else PATCHED_RENAMES # Short circuit all logic if we are renaming the whole library if libname in rename_dict: return vendor_dir / rename_dict[libname] / filename if libname in LIBRARY_DIRNAMES: override = vendor_dir / LIBRARY_DIRNAMES[libname] if not override.exists() and override.parent.exists(): # for flattened subdeps, specifically backports/weakref.py return ( vendor_dir / override.parent ) / '{0}.{1}'.format(override.name, filename) return vendor_dir / LIBRARY_DIRNAMES[libname] / filename # fallback to libname.LICENSE (used for nondirs) return vendor_dir / '{}.{}'.format(libname, filename)
def license_destination(vendor_dir, libname, filename): """Given the (reconstructed) library name, find appropriate destination""" normal = vendor_dir / libname if normal.is_dir(): return normal / filename lowercase = vendor_dir / libname.lower().replace('-', '_') if lowercase.is_dir(): return lowercase / filename rename_dict = LIBRARY_RENAMES if vendor_dir.name != 'patched' else PATCHED_RENAMES # Short circuit all logic if we are renaming the whole library if libname in rename_dict: return vendor_dir / rename_dict[libname] / filename if libname in LIBRARY_DIRNAMES: override = vendor_dir / LIBRARY_DIRNAMES[libname] if not override.exists() and override.parent.exists(): # for flattened subdeps, specifically backports/weakref.py return ( vendor_dir / override.parent ) / '{0}.{1}'.format(override.name, filename) return vendor_dir / LIBRARY_DIRNAMES[libname] / filename # fallback to libname.LICENSE (used for nondirs) return vendor_dir / '{}.{}'.format(libname, filename)
[ "Given", "the", "(", "reconstructed", ")", "library", "name", "find", "appropriate", "destination" ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/tasks/vendoring/__init__.py#L613-L634
[ "def", "license_destination", "(", "vendor_dir", ",", "libname", ",", "filename", ")", ":", "normal", "=", "vendor_dir", "/", "libname", "if", "normal", ".", "is_dir", "(", ")", ":", "return", "normal", "/", "filename", "lowercase", "=", "vendor_dir", "/", ...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
_convert_hashes
Convert Pipfile.lock hash lines into InstallRequirement option format. The option format uses a str-list mapping. Keys are hash algorithms, and the list contains all values of that algorithm.
pipenv/vendor/passa/internals/_pip.py
def _convert_hashes(values): """Convert Pipfile.lock hash lines into InstallRequirement option format. The option format uses a str-list mapping. Keys are hash algorithms, and the list contains all values of that algorithm. """ hashes = {} if not values: return hashes for value in values: try: name, value = value.split(":", 1) except ValueError: name = "sha256" if name not in hashes: hashes[name] = [] hashes[name].append(value) return hashes
def _convert_hashes(values): """Convert Pipfile.lock hash lines into InstallRequirement option format. The option format uses a str-list mapping. Keys are hash algorithms, and the list contains all values of that algorithm. """ hashes = {} if not values: return hashes for value in values: try: name, value = value.split(":", 1) except ValueError: name = "sha256" if name not in hashes: hashes[name] = [] hashes[name].append(value) return hashes
[ "Convert", "Pipfile", ".", "lock", "hash", "lines", "into", "InstallRequirement", "option", "format", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/passa/internals/_pip.py#L113-L130
[ "def", "_convert_hashes", "(", "values", ")", ":", "hashes", "=", "{", "}", "if", "not", "values", ":", "return", "hashes", "for", "value", "in", "values", ":", "try", ":", "name", ",", "value", "=", "value", ".", "split", "(", "\":\"", ",", "1", "...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
_suppress_distutils_logs
Hack to hide noise generated by `setup.py develop`. There isn't a good way to suppress them now, so let's monky-patch. See https://bugs.python.org/issue25392.
pipenv/vendor/passa/internals/_pip.py
def _suppress_distutils_logs(): """Hack to hide noise generated by `setup.py develop`. There isn't a good way to suppress them now, so let's monky-patch. See https://bugs.python.org/issue25392. """ f = distutils.log.Log._log def _log(log, level, msg, args): if level >= distutils.log.ERROR: f(log, level, msg, args) distutils.log.Log._log = _log yield distutils.log.Log._log = f
def _suppress_distutils_logs(): """Hack to hide noise generated by `setup.py develop`. There isn't a good way to suppress them now, so let's monky-patch. See https://bugs.python.org/issue25392. """ f = distutils.log.Log._log def _log(log, level, msg, args): if level >= distutils.log.ERROR: f(log, level, msg, args) distutils.log.Log._log = _log yield distutils.log.Log._log = f
[ "Hack", "to", "hide", "noise", "generated", "by", "setup", ".", "py", "develop", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/passa/internals/_pip.py#L258-L272
[ "def", "_suppress_distutils_logs", "(", ")", ":", "f", "=", "distutils", ".", "log", ".", "Log", ".", "_log", "def", "_log", "(", "log", ",", "level", ",", "msg", ",", "args", ")", ":", "if", "level", ">=", "distutils", ".", "log", ".", "ERROR", ":...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
_find_egg_info
Find this package's .egg-info directory. Due to how sdists are designed, the .egg-info directory cannot be reliably found without running setup.py to aggregate all configurations. This function instead uses some heuristics to locate the egg-info directory that most likely represents this package. The best .egg-info directory's path is returned as a string. None is returned if no matches can be found.
pipenv/vendor/passa/internals/_pip.py
def _find_egg_info(ireq): """Find this package's .egg-info directory. Due to how sdists are designed, the .egg-info directory cannot be reliably found without running setup.py to aggregate all configurations. This function instead uses some heuristics to locate the egg-info directory that most likely represents this package. The best .egg-info directory's path is returned as a string. None is returned if no matches can be found. """ root = ireq.setup_py_dir directory_iterator = _iter_egg_info_directories(root, ireq.name) try: top_egg_info = next(directory_iterator) except StopIteration: # No egg-info found. Wat. return None directory_iterator = itertools.chain([top_egg_info], directory_iterator) # Read the sdist's PKG-INFO to determine which egg_info is best. pkg_info = _read_pkg_info(root) # PKG-INFO not readable. Just return whatever comes first, I guess. if pkg_info is None: return top_egg_info # Walk the sdist to find the egg-info with matching PKG-INFO. for directory in directory_iterator: egg_pkg_info = _read_pkg_info(directory) if egg_pkg_info == pkg_info: return directory # Nothing matches...? Use the first one we found, I guess. return top_egg_info
def _find_egg_info(ireq): """Find this package's .egg-info directory. Due to how sdists are designed, the .egg-info directory cannot be reliably found without running setup.py to aggregate all configurations. This function instead uses some heuristics to locate the egg-info directory that most likely represents this package. The best .egg-info directory's path is returned as a string. None is returned if no matches can be found. """ root = ireq.setup_py_dir directory_iterator = _iter_egg_info_directories(root, ireq.name) try: top_egg_info = next(directory_iterator) except StopIteration: # No egg-info found. Wat. return None directory_iterator = itertools.chain([top_egg_info], directory_iterator) # Read the sdist's PKG-INFO to determine which egg_info is best. pkg_info = _read_pkg_info(root) # PKG-INFO not readable. Just return whatever comes first, I guess. if pkg_info is None: return top_egg_info # Walk the sdist to find the egg-info with matching PKG-INFO. for directory in directory_iterator: egg_pkg_info = _read_pkg_info(directory) if egg_pkg_info == pkg_info: return directory # Nothing matches...? Use the first one we found, I guess. return top_egg_info
[ "Find", "this", "package", "s", ".", "egg", "-", "info", "directory", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/passa/internals/_pip.py#L355-L389
[ "def", "_find_egg_info", "(", "ireq", ")", ":", "root", "=", "ireq", ".", "setup_py_dir", "directory_iterator", "=", "_iter_egg_info_directories", "(", "root", ",", "ireq", ".", "name", ")", "try", ":", "top_egg_info", "=", "next", "(", "directory_iterator", "...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
fs_str
Encodes a string into the proper filesystem encoding Borrowed from pip-tools
pipenv/vendor/vistir/compat.py
def fs_str(string): """Encodes a string into the proper filesystem encoding Borrowed from pip-tools """ if isinstance(string, str): return string assert not isinstance(string, bytes) return string.encode(_fs_encoding)
def fs_str(string): """Encodes a string into the proper filesystem encoding Borrowed from pip-tools """ if isinstance(string, str): return string assert not isinstance(string, bytes) return string.encode(_fs_encoding)
[ "Encodes", "a", "string", "into", "the", "proper", "filesystem", "encoding" ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/vistir/compat.py#L208-L217
[ "def", "fs_str", "(", "string", ")", ":", "if", "isinstance", "(", "string", ",", "str", ")", ":", "return", "string", "assert", "not", "isinstance", "(", "string", ",", "bytes", ")", "return", "string", ".", "encode", "(", "_fs_encoding", ")" ]
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
_get_path
Fetch the string value from a path-like object Returns **None** if there is no string value.
pipenv/vendor/vistir/compat.py
def _get_path(path): """ Fetch the string value from a path-like object Returns **None** if there is no string value. """ if isinstance(path, (six.string_types, bytes)): return path path_type = type(path) try: path_repr = path_type.__fspath__(path) except AttributeError: return if isinstance(path_repr, (six.string_types, bytes)): return path_repr return
def _get_path(path): """ Fetch the string value from a path-like object Returns **None** if there is no string value. """ if isinstance(path, (six.string_types, bytes)): return path path_type = type(path) try: path_repr = path_type.__fspath__(path) except AttributeError: return if isinstance(path_repr, (six.string_types, bytes)): return path_repr return
[ "Fetch", "the", "string", "value", "from", "a", "path", "-", "like", "object" ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/vistir/compat.py#L220-L236
[ "def", "_get_path", "(", "path", ")", ":", "if", "isinstance", "(", "path", ",", "(", "six", ".", "string_types", ",", "bytes", ")", ")", ":", "return", "path", "path_type", "=", "type", "(", "path", ")", "try", ":", "path_repr", "=", "path_type", "....
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
fs_encode
Encode a filesystem path to the proper filesystem encoding :param Union[str, bytes] path: A string-like path :returns: A bytes-encoded filesystem path representation
pipenv/vendor/vistir/compat.py
def fs_encode(path): """ Encode a filesystem path to the proper filesystem encoding :param Union[str, bytes] path: A string-like path :returns: A bytes-encoded filesystem path representation """ path = _get_path(path) if path is None: raise TypeError("expected a valid path to encode") if isinstance(path, six.text_type): path = path.encode(_fs_encoding, _fs_encode_errors) return path
def fs_encode(path): """ Encode a filesystem path to the proper filesystem encoding :param Union[str, bytes] path: A string-like path :returns: A bytes-encoded filesystem path representation """ path = _get_path(path) if path is None: raise TypeError("expected a valid path to encode") if isinstance(path, six.text_type): path = path.encode(_fs_encoding, _fs_encode_errors) return path
[ "Encode", "a", "filesystem", "path", "to", "the", "proper", "filesystem", "encoding" ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/vistir/compat.py#L239-L252
[ "def", "fs_encode", "(", "path", ")", ":", "path", "=", "_get_path", "(", "path", ")", "if", "path", "is", "None", ":", "raise", "TypeError", "(", "\"expected a valid path to encode\"", ")", "if", "isinstance", "(", "path", ",", "six", ".", "text_type", ")...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
fs_decode
Decode a filesystem path using the proper filesystem encoding :param path: The filesystem path to decode from bytes or string :return: [description] :rtype: [type]
pipenv/vendor/vistir/compat.py
def fs_decode(path): """ Decode a filesystem path using the proper filesystem encoding :param path: The filesystem path to decode from bytes or string :return: [description] :rtype: [type] """ path = _get_path(path) if path is None: raise TypeError("expected a valid path to decode") if isinstance(path, six.binary_type): path = path.decode(_fs_encoding, _fs_decode_errors) return path
def fs_decode(path): """ Decode a filesystem path using the proper filesystem encoding :param path: The filesystem path to decode from bytes or string :return: [description] :rtype: [type] """ path = _get_path(path) if path is None: raise TypeError("expected a valid path to decode") if isinstance(path, six.binary_type): path = path.decode(_fs_encoding, _fs_decode_errors) return path
[ "Decode", "a", "filesystem", "path", "using", "the", "proper", "filesystem", "encoding" ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/vistir/compat.py#L255-L269
[ "def", "fs_decode", "(", "path", ")", ":", "path", "=", "_get_path", "(", "path", ")", "if", "path", "is", "None", ":", "raise", "TypeError", "(", "\"expected a valid path to decode\"", ")", "if", "isinstance", "(", "path", ",", "six", ".", "binary_type", ...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
trace_graph
Build a collection of "traces" for each package. A trace is a list of names that eventually leads to the package. For example, if A and B are root dependencies, A depends on C and D, B depends on C, and C depends on D, the return value would be like:: { None: [], "A": [None], "B": [None], "C": [[None, "A"], [None, "B"]], "D": [[None, "B", "C"], [None, "A"]], }
pipenv/vendor/passa/internals/traces.py
def trace_graph(graph): """Build a collection of "traces" for each package. A trace is a list of names that eventually leads to the package. For example, if A and B are root dependencies, A depends on C and D, B depends on C, and C depends on D, the return value would be like:: { None: [], "A": [None], "B": [None], "C": [[None, "A"], [None, "B"]], "D": [[None, "B", "C"], [None, "A"]], } """ result = {None: []} for vertex in graph: result[vertex] = [] for root in graph.iter_children(None): paths = [] _trace_visit_vertex(graph, root, vertex, {None}, [None], paths) result[vertex].extend(paths) return result
def trace_graph(graph): """Build a collection of "traces" for each package. A trace is a list of names that eventually leads to the package. For example, if A and B are root dependencies, A depends on C and D, B depends on C, and C depends on D, the return value would be like:: { None: [], "A": [None], "B": [None], "C": [[None, "A"], [None, "B"]], "D": [[None, "B", "C"], [None, "A"]], } """ result = {None: []} for vertex in graph: result[vertex] = [] for root in graph.iter_children(None): paths = [] _trace_visit_vertex(graph, root, vertex, {None}, [None], paths) result[vertex].extend(paths) return result
[ "Build", "a", "collection", "of", "traces", "for", "each", "package", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/passa/internals/traces.py#L18-L40
[ "def", "trace_graph", "(", "graph", ")", ":", "result", "=", "{", "None", ":", "[", "]", "}", "for", "vertex", "in", "graph", ":", "result", "[", "vertex", "]", "=", "[", "]", "for", "root", "in", "graph", ".", "iter_children", "(", "None", ")", ...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Timeout._validate_timeout
Check that a timeout attribute is valid. :param value: The timeout value to validate :param name: The name of the timeout attribute to validate. This is used to specify in error messages. :return: The validated and casted version of the given value. :raises ValueError: If it is a numeric value less than or equal to zero, or the type is not an integer, float, or None.
pipenv/vendor/urllib3/util/timeout.py
def _validate_timeout(cls, value, name): """ Check that a timeout attribute is valid. :param value: The timeout value to validate :param name: The name of the timeout attribute to validate. This is used to specify in error messages. :return: The validated and casted version of the given value. :raises ValueError: If it is a numeric value less than or equal to zero, or the type is not an integer, float, or None. """ if value is _Default: return cls.DEFAULT_TIMEOUT if value is None or value is cls.DEFAULT_TIMEOUT: return value if isinstance(value, bool): raise ValueError("Timeout cannot be a boolean value. It must " "be an int, float or None.") try: float(value) except (TypeError, ValueError): raise ValueError("Timeout value %s was %s, but it must be an " "int, float or None." % (name, value)) try: if value <= 0: raise ValueError("Attempted to set %s timeout to %s, but the " "timeout cannot be set to a value less " "than or equal to 0." % (name, value)) except TypeError: # Python 3 raise ValueError("Timeout value %s was %s, but it must be an " "int, float or None." % (name, value)) return value
def _validate_timeout(cls, value, name): """ Check that a timeout attribute is valid. :param value: The timeout value to validate :param name: The name of the timeout attribute to validate. This is used to specify in error messages. :return: The validated and casted version of the given value. :raises ValueError: If it is a numeric value less than or equal to zero, or the type is not an integer, float, or None. """ if value is _Default: return cls.DEFAULT_TIMEOUT if value is None or value is cls.DEFAULT_TIMEOUT: return value if isinstance(value, bool): raise ValueError("Timeout cannot be a boolean value. It must " "be an int, float or None.") try: float(value) except (TypeError, ValueError): raise ValueError("Timeout value %s was %s, but it must be an " "int, float or None." % (name, value)) try: if value <= 0: raise ValueError("Attempted to set %s timeout to %s, but the " "timeout cannot be set to a value less " "than or equal to 0." % (name, value)) except TypeError: # Python 3 raise ValueError("Timeout value %s was %s, but it must be an " "int, float or None." % (name, value)) return value
[ "Check", "that", "a", "timeout", "attribute", "is", "valid", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/urllib3/util/timeout.py#L104-L138
[ "def", "_validate_timeout", "(", "cls", ",", "value", ",", "name", ")", ":", "if", "value", "is", "_Default", ":", "return", "cls", ".", "DEFAULT_TIMEOUT", "if", "value", "is", "None", "or", "value", "is", "cls", ".", "DEFAULT_TIMEOUT", ":", "return", "v...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Timeout.clone
Create a copy of the timeout object Timeout properties are stored per-pool but each request needs a fresh Timeout object to ensure each one has its own start/stop configured. :return: a copy of the timeout object :rtype: :class:`Timeout`
pipenv/vendor/urllib3/util/timeout.py
def clone(self): """ Create a copy of the timeout object Timeout properties are stored per-pool but each request needs a fresh Timeout object to ensure each one has its own start/stop configured. :return: a copy of the timeout object :rtype: :class:`Timeout` """ # We can't use copy.deepcopy because that will also create a new object # for _GLOBAL_DEFAULT_TIMEOUT, which socket.py uses as a sentinel to # detect the user default. return Timeout(connect=self._connect, read=self._read, total=self.total)
def clone(self): """ Create a copy of the timeout object Timeout properties are stored per-pool but each request needs a fresh Timeout object to ensure each one has its own start/stop configured. :return: a copy of the timeout object :rtype: :class:`Timeout` """ # We can't use copy.deepcopy because that will also create a new object # for _GLOBAL_DEFAULT_TIMEOUT, which socket.py uses as a sentinel to # detect the user default. return Timeout(connect=self._connect, read=self._read, total=self.total)
[ "Create", "a", "copy", "of", "the", "timeout", "object" ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/urllib3/util/timeout.py#L156-L169
[ "def", "clone", "(", "self", ")", ":", "# We can't use copy.deepcopy because that will also create a new object", "# for _GLOBAL_DEFAULT_TIMEOUT, which socket.py uses as a sentinel to", "# detect the user default.", "return", "Timeout", "(", "connect", "=", "self", ".", "_connect", ...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Timeout.start_connect
Start the timeout clock, used during a connect() attempt :raises urllib3.exceptions.TimeoutStateError: if you attempt to start a timer that has been started already.
pipenv/vendor/urllib3/util/timeout.py
def start_connect(self): """ Start the timeout clock, used during a connect() attempt :raises urllib3.exceptions.TimeoutStateError: if you attempt to start a timer that has been started already. """ if self._start_connect is not None: raise TimeoutStateError("Timeout timer has already been started.") self._start_connect = current_time() return self._start_connect
def start_connect(self): """ Start the timeout clock, used during a connect() attempt :raises urllib3.exceptions.TimeoutStateError: if you attempt to start a timer that has been started already. """ if self._start_connect is not None: raise TimeoutStateError("Timeout timer has already been started.") self._start_connect = current_time() return self._start_connect
[ "Start", "the", "timeout", "clock", "used", "during", "a", "connect", "()", "attempt" ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/urllib3/util/timeout.py#L171-L180
[ "def", "start_connect", "(", "self", ")", ":", "if", "self", ".", "_start_connect", "is", "not", "None", ":", "raise", "TimeoutStateError", "(", "\"Timeout timer has already been started.\"", ")", "self", ".", "_start_connect", "=", "current_time", "(", ")", "retu...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Timeout.connect_timeout
Get the value to use when setting a connection timeout. This will be a positive float or integer, the value None (never timeout), or the default system timeout. :return: Connect timeout. :rtype: int, float, :attr:`Timeout.DEFAULT_TIMEOUT` or None
pipenv/vendor/urllib3/util/timeout.py
def connect_timeout(self): """ Get the value to use when setting a connection timeout. This will be a positive float or integer, the value None (never timeout), or the default system timeout. :return: Connect timeout. :rtype: int, float, :attr:`Timeout.DEFAULT_TIMEOUT` or None """ if self.total is None: return self._connect if self._connect is None or self._connect is self.DEFAULT_TIMEOUT: return self.total return min(self._connect, self.total)
def connect_timeout(self): """ Get the value to use when setting a connection timeout. This will be a positive float or integer, the value None (never timeout), or the default system timeout. :return: Connect timeout. :rtype: int, float, :attr:`Timeout.DEFAULT_TIMEOUT` or None """ if self.total is None: return self._connect if self._connect is None or self._connect is self.DEFAULT_TIMEOUT: return self.total return min(self._connect, self.total)
[ "Get", "the", "value", "to", "use", "when", "setting", "a", "connection", "timeout", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/urllib3/util/timeout.py#L196-L211
[ "def", "connect_timeout", "(", "self", ")", ":", "if", "self", ".", "total", "is", "None", ":", "return", "self", ".", "_connect", "if", "self", ".", "_connect", "is", "None", "or", "self", ".", "_connect", "is", "self", ".", "DEFAULT_TIMEOUT", ":", "r...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Timeout.read_timeout
Get the value for the read timeout. This assumes some time has elapsed in the connection timeout and computes the read timeout appropriately. If self.total is set, the read timeout is dependent on the amount of time taken by the connect timeout. If the connection time has not been established, a :exc:`~urllib3.exceptions.TimeoutStateError` will be raised. :return: Value to use for the read timeout. :rtype: int, float, :attr:`Timeout.DEFAULT_TIMEOUT` or None :raises urllib3.exceptions.TimeoutStateError: If :meth:`start_connect` has not yet been called on this object.
pipenv/vendor/urllib3/util/timeout.py
def read_timeout(self): """ Get the value for the read timeout. This assumes some time has elapsed in the connection timeout and computes the read timeout appropriately. If self.total is set, the read timeout is dependent on the amount of time taken by the connect timeout. If the connection time has not been established, a :exc:`~urllib3.exceptions.TimeoutStateError` will be raised. :return: Value to use for the read timeout. :rtype: int, float, :attr:`Timeout.DEFAULT_TIMEOUT` or None :raises urllib3.exceptions.TimeoutStateError: If :meth:`start_connect` has not yet been called on this object. """ if (self.total is not None and self.total is not self.DEFAULT_TIMEOUT and self._read is not None and self._read is not self.DEFAULT_TIMEOUT): # In case the connect timeout has not yet been established. if self._start_connect is None: return self._read return max(0, min(self.total - self.get_connect_duration(), self._read)) elif self.total is not None and self.total is not self.DEFAULT_TIMEOUT: return max(0, self.total - self.get_connect_duration()) else: return self._read
def read_timeout(self): """ Get the value for the read timeout. This assumes some time has elapsed in the connection timeout and computes the read timeout appropriately. If self.total is set, the read timeout is dependent on the amount of time taken by the connect timeout. If the connection time has not been established, a :exc:`~urllib3.exceptions.TimeoutStateError` will be raised. :return: Value to use for the read timeout. :rtype: int, float, :attr:`Timeout.DEFAULT_TIMEOUT` or None :raises urllib3.exceptions.TimeoutStateError: If :meth:`start_connect` has not yet been called on this object. """ if (self.total is not None and self.total is not self.DEFAULT_TIMEOUT and self._read is not None and self._read is not self.DEFAULT_TIMEOUT): # In case the connect timeout has not yet been established. if self._start_connect is None: return self._read return max(0, min(self.total - self.get_connect_duration(), self._read)) elif self.total is not None and self.total is not self.DEFAULT_TIMEOUT: return max(0, self.total - self.get_connect_duration()) else: return self._read
[ "Get", "the", "value", "for", "the", "read", "timeout", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/urllib3/util/timeout.py#L214-L242
[ "def", "read_timeout", "(", "self", ")", ":", "if", "(", "self", ".", "total", "is", "not", "None", "and", "self", ".", "total", "is", "not", "self", ".", "DEFAULT_TIMEOUT", "and", "self", ".", "_read", "is", "not", "None", "and", "self", ".", "_read...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
SOCKSConnection._new_conn
Establish a new connection via the SOCKS proxy.
pipenv/vendor/urllib3/contrib/socks.py
def _new_conn(self): """ Establish a new connection via the SOCKS proxy. """ extra_kw = {} if self.source_address: extra_kw['source_address'] = self.source_address if self.socket_options: extra_kw['socket_options'] = self.socket_options try: conn = socks.create_connection( (self.host, self.port), proxy_type=self._socks_options['socks_version'], proxy_addr=self._socks_options['proxy_host'], proxy_port=self._socks_options['proxy_port'], proxy_username=self._socks_options['username'], proxy_password=self._socks_options['password'], proxy_rdns=self._socks_options['rdns'], timeout=self.timeout, **extra_kw ) except SocketTimeout as e: raise ConnectTimeoutError( self, "Connection to %s timed out. (connect timeout=%s)" % (self.host, self.timeout)) except socks.ProxyError as e: # This is fragile as hell, but it seems to be the only way to raise # useful errors here. if e.socket_err: error = e.socket_err if isinstance(error, SocketTimeout): raise ConnectTimeoutError( self, "Connection to %s timed out. (connect timeout=%s)" % (self.host, self.timeout) ) else: raise NewConnectionError( self, "Failed to establish a new connection: %s" % error ) else: raise NewConnectionError( self, "Failed to establish a new connection: %s" % e ) except SocketError as e: # Defensive: PySocks should catch all these. raise NewConnectionError( self, "Failed to establish a new connection: %s" % e) return conn
def _new_conn(self): """ Establish a new connection via the SOCKS proxy. """ extra_kw = {} if self.source_address: extra_kw['source_address'] = self.source_address if self.socket_options: extra_kw['socket_options'] = self.socket_options try: conn = socks.create_connection( (self.host, self.port), proxy_type=self._socks_options['socks_version'], proxy_addr=self._socks_options['proxy_host'], proxy_port=self._socks_options['proxy_port'], proxy_username=self._socks_options['username'], proxy_password=self._socks_options['password'], proxy_rdns=self._socks_options['rdns'], timeout=self.timeout, **extra_kw ) except SocketTimeout as e: raise ConnectTimeoutError( self, "Connection to %s timed out. (connect timeout=%s)" % (self.host, self.timeout)) except socks.ProxyError as e: # This is fragile as hell, but it seems to be the only way to raise # useful errors here. if e.socket_err: error = e.socket_err if isinstance(error, SocketTimeout): raise ConnectTimeoutError( self, "Connection to %s timed out. (connect timeout=%s)" % (self.host, self.timeout) ) else: raise NewConnectionError( self, "Failed to establish a new connection: %s" % error ) else: raise NewConnectionError( self, "Failed to establish a new connection: %s" % e ) except SocketError as e: # Defensive: PySocks should catch all these. raise NewConnectionError( self, "Failed to establish a new connection: %s" % e) return conn
[ "Establish", "a", "new", "connection", "via", "the", "SOCKS", "proxy", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/urllib3/contrib/socks.py#L67-L122
[ "def", "_new_conn", "(", "self", ")", ":", "extra_kw", "=", "{", "}", "if", "self", ".", "source_address", ":", "extra_kw", "[", "'source_address'", "]", "=", "self", ".", "source_address", "if", "self", ".", "socket_options", ":", "extra_kw", "[", "'socke...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
get_requirement_info
Compute and return values (req, editable, comments) for use in FrozenRequirement.from_dist().
pipenv/patched/notpip/_internal/operations/freeze.py
def get_requirement_info(dist): # type: (Distribution) -> RequirementInfo """ Compute and return values (req, editable, comments) for use in FrozenRequirement.from_dist(). """ if not dist_is_editable(dist): return (None, False, []) location = os.path.normcase(os.path.abspath(dist.location)) from pipenv.patched.notpip._internal.vcs import vcs, RemoteNotFoundError vc_type = vcs.get_backend_type(location) if not vc_type: req = dist.as_requirement() logger.debug( 'No VCS found for editable requirement {!r} in: {!r}', req, location, ) comments = [ '# Editable install with no version control ({})'.format(req) ] return (location, True, comments) try: req = vc_type.get_src_requirement(location, dist.project_name) except RemoteNotFoundError: req = dist.as_requirement() comments = [ '# Editable {} install with no remote ({})'.format( vc_type.__name__, req, ) ] return (location, True, comments) except BadCommand: logger.warning( 'cannot determine version of editable source in %s ' '(%s command not found in path)', location, vc_type.name, ) return (None, True, []) except InstallationError as exc: logger.warning( "Error when trying to get requirement for VCS system %s, " "falling back to uneditable format", exc ) else: if req is not None: return (req, True, []) logger.warning( 'Could not determine repository location of %s', location ) comments = ['## !! Could not determine repository location'] return (None, False, comments)
def get_requirement_info(dist): # type: (Distribution) -> RequirementInfo """ Compute and return values (req, editable, comments) for use in FrozenRequirement.from_dist(). """ if not dist_is_editable(dist): return (None, False, []) location = os.path.normcase(os.path.abspath(dist.location)) from pipenv.patched.notpip._internal.vcs import vcs, RemoteNotFoundError vc_type = vcs.get_backend_type(location) if not vc_type: req = dist.as_requirement() logger.debug( 'No VCS found for editable requirement {!r} in: {!r}', req, location, ) comments = [ '# Editable install with no version control ({})'.format(req) ] return (location, True, comments) try: req = vc_type.get_src_requirement(location, dist.project_name) except RemoteNotFoundError: req = dist.as_requirement() comments = [ '# Editable {} install with no remote ({})'.format( vc_type.__name__, req, ) ] return (location, True, comments) except BadCommand: logger.warning( 'cannot determine version of editable source in %s ' '(%s command not found in path)', location, vc_type.name, ) return (None, True, []) except InstallationError as exc: logger.warning( "Error when trying to get requirement for VCS system %s, " "falling back to uneditable format", exc ) else: if req is not None: return (req, True, []) logger.warning( 'Could not determine repository location of %s', location ) comments = ['## !! Could not determine repository location'] return (None, False, comments)
[ "Compute", "and", "return", "values", "(", "req", "editable", "comments", ")", "for", "use", "in", "FrozenRequirement", ".", "from_dist", "()", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_internal/operations/freeze.py#L164-L223
[ "def", "get_requirement_info", "(", "dist", ")", ":", "# type: (Distribution) -> RequirementInfo", "if", "not", "dist_is_editable", "(", "dist", ")", ":", "return", "(", "None", ",", "False", ",", "[", "]", ")", "location", "=", "os", ".", "path", ".", "norm...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
detect_proc
Detect /proc filesystem style. This checks the /proc/{pid} directory for possible formats. Returns one of the followings as str: * `stat`: Linux-style, i.e. ``/proc/{pid}/stat``. * `status`: BSD-style, i.e. ``/proc/{pid}/status``.
pipenv/vendor/shellingham/posix/proc.py
def detect_proc(): """Detect /proc filesystem style. This checks the /proc/{pid} directory for possible formats. Returns one of the followings as str: * `stat`: Linux-style, i.e. ``/proc/{pid}/stat``. * `status`: BSD-style, i.e. ``/proc/{pid}/status``. """ pid = os.getpid() for name in ('stat', 'status'): if os.path.exists(os.path.join('/proc', str(pid), name)): return name raise ProcFormatError('unsupported proc format')
def detect_proc(): """Detect /proc filesystem style. This checks the /proc/{pid} directory for possible formats. Returns one of the followings as str: * `stat`: Linux-style, i.e. ``/proc/{pid}/stat``. * `status`: BSD-style, i.e. ``/proc/{pid}/status``. """ pid = os.getpid() for name in ('stat', 'status'): if os.path.exists(os.path.join('/proc', str(pid), name)): return name raise ProcFormatError('unsupported proc format')
[ "Detect", "/", "proc", "filesystem", "style", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/shellingham/posix/proc.py#L15-L28
[ "def", "detect_proc", "(", ")", ":", "pid", "=", "os", ".", "getpid", "(", ")", "for", "name", "in", "(", "'stat'", ",", "'status'", ")", ":", "if", "os", ".", "path", ".", "exists", "(", "os", ".", "path", ".", "join", "(", "'/proc'", ",", "st...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
get_process_mapping
Try to look up the process tree via the /proc interface.
pipenv/vendor/shellingham/posix/proc.py
def get_process_mapping(): """Try to look up the process tree via the /proc interface. """ stat_name = detect_proc() self_tty = _get_stat(os.getpid(), stat_name)[0] processes = {} for pid in os.listdir('/proc'): if not pid.isdigit(): continue try: tty, ppid = _get_stat(pid, stat_name) if tty != self_tty: continue args = _get_cmdline(pid) processes[pid] = Process(args=args, pid=pid, ppid=ppid) except IOError: # Process has disappeared - just ignore it. continue return processes
def get_process_mapping(): """Try to look up the process tree via the /proc interface. """ stat_name = detect_proc() self_tty = _get_stat(os.getpid(), stat_name)[0] processes = {} for pid in os.listdir('/proc'): if not pid.isdigit(): continue try: tty, ppid = _get_stat(pid, stat_name) if tty != self_tty: continue args = _get_cmdline(pid) processes[pid] = Process(args=args, pid=pid, ppid=ppid) except IOError: # Process has disappeared - just ignore it. continue return processes
[ "Try", "to", "look", "up", "the", "process", "tree", "via", "the", "/", "proc", "interface", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/shellingham/posix/proc.py#L54-L72
[ "def", "get_process_mapping", "(", ")", ":", "stat_name", "=", "detect_proc", "(", ")", "self_tty", "=", "_get_stat", "(", "os", ".", "getpid", "(", ")", ",", "stat_name", ")", "[", "0", "]", "processes", "=", "{", "}", "for", "pid", "in", "os", ".",...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
NamedTemporaryFile
Create and return a temporary file. Arguments: 'prefix', 'suffix', 'dir' -- as for mkstemp. 'mode' -- the mode argument to io.open (default "w+b"). 'buffering' -- the buffer size argument to io.open (default -1). 'encoding' -- the encoding argument to io.open (default None) 'newline' -- the newline argument to io.open (default None) 'delete' -- whether the file is deleted on close (default True). The file is created as mkstemp() would do it. Returns an object with a file-like interface; the name of the file is accessible as its 'name' attribute. The file will be automatically deleted when it is closed unless the 'delete' argument is set to False.
pipenv/vendor/vistir/backports/tempfile.py
def NamedTemporaryFile( mode="w+b", buffering=-1, encoding=None, newline=None, suffix=None, prefix=None, dir=None, delete=True, wrapper_class_override=None, ): """Create and return a temporary file. Arguments: 'prefix', 'suffix', 'dir' -- as for mkstemp. 'mode' -- the mode argument to io.open (default "w+b"). 'buffering' -- the buffer size argument to io.open (default -1). 'encoding' -- the encoding argument to io.open (default None) 'newline' -- the newline argument to io.open (default None) 'delete' -- whether the file is deleted on close (default True). The file is created as mkstemp() would do it. Returns an object with a file-like interface; the name of the file is accessible as its 'name' attribute. The file will be automatically deleted when it is closed unless the 'delete' argument is set to False. """ prefix, suffix, dir, output_type = _sanitize_params(prefix, suffix, dir) flags = _bin_openflags # Setting O_TEMPORARY in the flags causes the OS to delete # the file when it is closed. This is only supported by Windows. if not wrapper_class_override: wrapper_class_override = _TemporaryFileWrapper if os.name == "nt" and delete: flags |= os.O_TEMPORARY if sys.version_info < (3, 5): (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags) else: (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags, output_type) try: file = io.open(fd, mode, buffering=buffering, newline=newline, encoding=encoding) if wrapper_class_override is not None: return type(str("_TempFileWrapper"), (wrapper_class_override, object), {})( file, name, delete ) else: return _TemporaryFileWrapper(file, name, delete) except BaseException: os.unlink(name) os.close(fd) raise
def NamedTemporaryFile( mode="w+b", buffering=-1, encoding=None, newline=None, suffix=None, prefix=None, dir=None, delete=True, wrapper_class_override=None, ): """Create and return a temporary file. Arguments: 'prefix', 'suffix', 'dir' -- as for mkstemp. 'mode' -- the mode argument to io.open (default "w+b"). 'buffering' -- the buffer size argument to io.open (default -1). 'encoding' -- the encoding argument to io.open (default None) 'newline' -- the newline argument to io.open (default None) 'delete' -- whether the file is deleted on close (default True). The file is created as mkstemp() would do it. Returns an object with a file-like interface; the name of the file is accessible as its 'name' attribute. The file will be automatically deleted when it is closed unless the 'delete' argument is set to False. """ prefix, suffix, dir, output_type = _sanitize_params(prefix, suffix, dir) flags = _bin_openflags # Setting O_TEMPORARY in the flags causes the OS to delete # the file when it is closed. This is only supported by Windows. if not wrapper_class_override: wrapper_class_override = _TemporaryFileWrapper if os.name == "nt" and delete: flags |= os.O_TEMPORARY if sys.version_info < (3, 5): (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags) else: (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags, output_type) try: file = io.open(fd, mode, buffering=buffering, newline=newline, encoding=encoding) if wrapper_class_override is not None: return type(str("_TempFileWrapper"), (wrapper_class_override, object), {})( file, name, delete ) else: return _TemporaryFileWrapper(file, name, delete) except BaseException: os.unlink(name) os.close(fd) raise
[ "Create", "and", "return", "a", "temporary", "file", ".", "Arguments", ":", "prefix", "suffix", "dir", "--", "as", "for", "mkstemp", ".", "mode", "--", "the", "mode", "argument", "to", "io", ".", "open", "(", "default", "w", "+", "b", ")", ".", "buff...
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/vistir/backports/tempfile.py#L168-L216
[ "def", "NamedTemporaryFile", "(", "mode", "=", "\"w+b\"", ",", "buffering", "=", "-", "1", ",", "encoding", "=", "None", ",", "newline", "=", "None", ",", "suffix", "=", "None", ",", "prefix", "=", "None", ",", "dir", "=", "None", ",", "delete", "=",...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
fast_exit
Exit without garbage collection, this speeds up exit by about 10ms for things like bash completion.
pipenv/vendor/click/core.py
def fast_exit(code): """Exit without garbage collection, this speeds up exit by about 10ms for things like bash completion. """ sys.stdout.flush() sys.stderr.flush() os._exit(code)
def fast_exit(code): """Exit without garbage collection, this speeds up exit by about 10ms for things like bash completion. """ sys.stdout.flush() sys.stderr.flush() os._exit(code)
[ "Exit", "without", "garbage", "collection", "this", "speeds", "up", "exit", "by", "about", "10ms", "for", "things", "like", "bash", "completion", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L39-L45
[ "def", "fast_exit", "(", "code", ")", ":", "sys", ".", "stdout", ".", "flush", "(", ")", "sys", ".", "stderr", ".", "flush", "(", ")", "os", ".", "_exit", "(", "code", ")" ]
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
_bashcomplete
Internal handler for the bash completion support.
pipenv/vendor/click/core.py
def _bashcomplete(cmd, prog_name, complete_var=None): """Internal handler for the bash completion support.""" if complete_var is None: complete_var = '_%s_COMPLETE' % (prog_name.replace('-', '_')).upper() complete_instr = os.environ.get(complete_var) if not complete_instr: return from ._bashcomplete import bashcomplete if bashcomplete(cmd, prog_name, complete_var, complete_instr): fast_exit(1)
def _bashcomplete(cmd, prog_name, complete_var=None): """Internal handler for the bash completion support.""" if complete_var is None: complete_var = '_%s_COMPLETE' % (prog_name.replace('-', '_')).upper() complete_instr = os.environ.get(complete_var) if not complete_instr: return from ._bashcomplete import bashcomplete if bashcomplete(cmd, prog_name, complete_var, complete_instr): fast_exit(1)
[ "Internal", "handler", "for", "the", "bash", "completion", "support", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L48-L58
[ "def", "_bashcomplete", "(", "cmd", ",", "prog_name", ",", "complete_var", "=", "None", ")", ":", "if", "complete_var", "is", "None", ":", "complete_var", "=", "'_%s_COMPLETE'", "%", "(", "prog_name", ".", "replace", "(", "'-'", ",", "'_'", ")", ")", "."...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
augment_usage_errors
Context manager that attaches extra information to exceptions that fly.
pipenv/vendor/click/core.py
def augment_usage_errors(ctx, param=None): """Context manager that attaches extra information to exceptions that fly. """ try: yield except BadParameter as e: if e.ctx is None: e.ctx = ctx if param is not None and e.param is None: e.param = param raise except UsageError as e: if e.ctx is None: e.ctx = ctx raise
def augment_usage_errors(ctx, param=None): """Context manager that attaches extra information to exceptions that fly. """ try: yield except BadParameter as e: if e.ctx is None: e.ctx = ctx if param is not None and e.param is None: e.param = param raise except UsageError as e: if e.ctx is None: e.ctx = ctx raise
[ "Context", "manager", "that", "attaches", "extra", "information", "to", "exceptions", "that", "fly", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L100-L115
[ "def", "augment_usage_errors", "(", "ctx", ",", "param", "=", "None", ")", ":", "try", ":", "yield", "except", "BadParameter", "as", "e", ":", "if", "e", ".", "ctx", "is", "None", ":", "e", ".", "ctx", "=", "ctx", "if", "param", "is", "not", "None"...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
iter_params_for_processing
Given a sequence of parameters in the order as should be considered for processing and an iterable of parameters that exist, this returns a list in the correct order as they should be processed.
pipenv/vendor/click/core.py
def iter_params_for_processing(invocation_order, declaration_order): """Given a sequence of parameters in the order as should be considered for processing and an iterable of parameters that exist, this returns a list in the correct order as they should be processed. """ def sort_key(item): try: idx = invocation_order.index(item) except ValueError: idx = float('inf') return (not item.is_eager, idx) return sorted(declaration_order, key=sort_key)
def iter_params_for_processing(invocation_order, declaration_order): """Given a sequence of parameters in the order as should be considered for processing and an iterable of parameters that exist, this returns a list in the correct order as they should be processed. """ def sort_key(item): try: idx = invocation_order.index(item) except ValueError: idx = float('inf') return (not item.is_eager, idx) return sorted(declaration_order, key=sort_key)
[ "Given", "a", "sequence", "of", "parameters", "in", "the", "order", "as", "should", "be", "considered", "for", "processing", "and", "an", "iterable", "of", "parameters", "that", "exist", "this", "returns", "a", "list", "in", "the", "correct", "order", "as", ...
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L118-L130
[ "def", "iter_params_for_processing", "(", "invocation_order", ",", "declaration_order", ")", ":", "def", "sort_key", "(", "item", ")", ":", "try", ":", "idx", "=", "invocation_order", ".", "index", "(", "item", ")", "except", "ValueError", ":", "idx", "=", "...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Context.scope
This helper method can be used with the context object to promote it to the current thread local (see :func:`get_current_context`). The default behavior of this is to invoke the cleanup functions which can be disabled by setting `cleanup` to `False`. The cleanup functions are typically used for things such as closing file handles. If the cleanup is intended the context object can also be directly used as a context manager. Example usage:: with ctx.scope(): assert get_current_context() is ctx This is equivalent:: with ctx: assert get_current_context() is ctx .. versionadded:: 5.0 :param cleanup: controls if the cleanup functions should be run or not. The default is to run these functions. In some situations the context only wants to be temporarily pushed in which case this can be disabled. Nested pushes automatically defer the cleanup.
pipenv/vendor/click/core.py
def scope(self, cleanup=True): """This helper method can be used with the context object to promote it to the current thread local (see :func:`get_current_context`). The default behavior of this is to invoke the cleanup functions which can be disabled by setting `cleanup` to `False`. The cleanup functions are typically used for things such as closing file handles. If the cleanup is intended the context object can also be directly used as a context manager. Example usage:: with ctx.scope(): assert get_current_context() is ctx This is equivalent:: with ctx: assert get_current_context() is ctx .. versionadded:: 5.0 :param cleanup: controls if the cleanup functions should be run or not. The default is to run these functions. In some situations the context only wants to be temporarily pushed in which case this can be disabled. Nested pushes automatically defer the cleanup. """ if not cleanup: self._depth += 1 try: with self as rv: yield rv finally: if not cleanup: self._depth -= 1
def scope(self, cleanup=True): """This helper method can be used with the context object to promote it to the current thread local (see :func:`get_current_context`). The default behavior of this is to invoke the cleanup functions which can be disabled by setting `cleanup` to `False`. The cleanup functions are typically used for things such as closing file handles. If the cleanup is intended the context object can also be directly used as a context manager. Example usage:: with ctx.scope(): assert get_current_context() is ctx This is equivalent:: with ctx: assert get_current_context() is ctx .. versionadded:: 5.0 :param cleanup: controls if the cleanup functions should be run or not. The default is to run these functions. In some situations the context only wants to be temporarily pushed in which case this can be disabled. Nested pushes automatically defer the cleanup. """ if not cleanup: self._depth += 1 try: with self as rv: yield rv finally: if not cleanup: self._depth -= 1
[ "This", "helper", "method", "can", "be", "used", "with", "the", "context", "object", "to", "promote", "it", "to", "the", "current", "thread", "local", "(", "see", ":", "func", ":", "get_current_context", ")", ".", "The", "default", "behavior", "of", "this"...
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L355-L390
[ "def", "scope", "(", "self", ",", "cleanup", "=", "True", ")", ":", "if", "not", "cleanup", ":", "self", ".", "_depth", "+=", "1", "try", ":", "with", "self", "as", "rv", ":", "yield", "rv", "finally", ":", "if", "not", "cleanup", ":", "self", "....
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Context.command_path
The computed command path. This is used for the ``usage`` information on the help page. It's automatically created by combining the info names of the chain of contexts to the root.
pipenv/vendor/click/core.py
def command_path(self): """The computed command path. This is used for the ``usage`` information on the help page. It's automatically created by combining the info names of the chain of contexts to the root. """ rv = '' if self.info_name is not None: rv = self.info_name if self.parent is not None: rv = self.parent.command_path + ' ' + rv return rv.lstrip()
def command_path(self): """The computed command path. This is used for the ``usage`` information on the help page. It's automatically created by combining the info names of the chain of contexts to the root. """ rv = '' if self.info_name is not None: rv = self.info_name if self.parent is not None: rv = self.parent.command_path + ' ' + rv return rv.lstrip()
[ "The", "computed", "command", "path", ".", "This", "is", "used", "for", "the", "usage", "information", "on", "the", "help", "page", ".", "It", "s", "automatically", "created", "by", "combining", "the", "info", "names", "of", "the", "chain", "of", "contexts...
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L444-L454
[ "def", "command_path", "(", "self", ")", ":", "rv", "=", "''", "if", "self", ".", "info_name", "is", "not", "None", ":", "rv", "=", "self", ".", "info_name", "if", "self", ".", "parent", "is", "not", "None", ":", "rv", "=", "self", ".", "parent", ...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Context.find_root
Finds the outermost context.
pipenv/vendor/click/core.py
def find_root(self): """Finds the outermost context.""" node = self while node.parent is not None: node = node.parent return node
def find_root(self): """Finds the outermost context.""" node = self while node.parent is not None: node = node.parent return node
[ "Finds", "the", "outermost", "context", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L456-L461
[ "def", "find_root", "(", "self", ")", ":", "node", "=", "self", "while", "node", ".", "parent", "is", "not", "None", ":", "node", "=", "node", ".", "parent", "return", "node" ]
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Context.find_object
Finds the closest object of a given type.
pipenv/vendor/click/core.py
def find_object(self, object_type): """Finds the closest object of a given type.""" node = self while node is not None: if isinstance(node.obj, object_type): return node.obj node = node.parent
def find_object(self, object_type): """Finds the closest object of a given type.""" node = self while node is not None: if isinstance(node.obj, object_type): return node.obj node = node.parent
[ "Finds", "the", "closest", "object", "of", "a", "given", "type", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L463-L469
[ "def", "find_object", "(", "self", ",", "object_type", ")", ":", "node", "=", "self", "while", "node", "is", "not", "None", ":", "if", "isinstance", "(", "node", ".", "obj", ",", "object_type", ")", ":", "return", "node", ".", "obj", "node", "=", "no...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Context.ensure_object
Like :meth:`find_object` but sets the innermost object to a new instance of `object_type` if it does not exist.
pipenv/vendor/click/core.py
def ensure_object(self, object_type): """Like :meth:`find_object` but sets the innermost object to a new instance of `object_type` if it does not exist. """ rv = self.find_object(object_type) if rv is None: self.obj = rv = object_type() return rv
def ensure_object(self, object_type): """Like :meth:`find_object` but sets the innermost object to a new instance of `object_type` if it does not exist. """ rv = self.find_object(object_type) if rv is None: self.obj = rv = object_type() return rv
[ "Like", ":", "meth", ":", "find_object", "but", "sets", "the", "innermost", "object", "to", "a", "new", "instance", "of", "object_type", "if", "it", "does", "not", "exist", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L471-L478
[ "def", "ensure_object", "(", "self", ",", "object_type", ")", ":", "rv", "=", "self", ".", "find_object", "(", "object_type", ")", "if", "rv", "is", "None", ":", "self", ".", "obj", "=", "rv", "=", "object_type", "(", ")", "return", "rv" ]
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Context.lookup_default
Looks up the default for a parameter name. This by default looks into the :attr:`default_map` if available.
pipenv/vendor/click/core.py
def lookup_default(self, name): """Looks up the default for a parameter name. This by default looks into the :attr:`default_map` if available. """ if self.default_map is not None: rv = self.default_map.get(name) if callable(rv): rv = rv() return rv
def lookup_default(self, name): """Looks up the default for a parameter name. This by default looks into the :attr:`default_map` if available. """ if self.default_map is not None: rv = self.default_map.get(name) if callable(rv): rv = rv() return rv
[ "Looks", "up", "the", "default", "for", "a", "parameter", "name", ".", "This", "by", "default", "looks", "into", "the", ":", "attr", ":", "default_map", "if", "available", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L480-L488
[ "def", "lookup_default", "(", "self", ",", "name", ")", ":", "if", "self", ".", "default_map", "is", "not", "None", ":", "rv", "=", "self", ".", "default_map", ".", "get", "(", "name", ")", "if", "callable", "(", "rv", ")", ":", "rv", "=", "rv", ...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Context.invoke
Invokes a command callback in exactly the way it expects. There are two ways to invoke this method: 1. the first argument can be a callback and all other arguments and keyword arguments are forwarded directly to the function. 2. the first argument is a click command object. In that case all arguments are forwarded as well but proper click parameters (options and click arguments) must be keyword arguments and Click will fill in defaults. Note that before Click 3.2 keyword arguments were not properly filled in against the intention of this code and no context was created. For more information about this change and why it was done in a bugfix release see :ref:`upgrade-to-3.2`.
pipenv/vendor/click/core.py
def invoke(*args, **kwargs): """Invokes a command callback in exactly the way it expects. There are two ways to invoke this method: 1. the first argument can be a callback and all other arguments and keyword arguments are forwarded directly to the function. 2. the first argument is a click command object. In that case all arguments are forwarded as well but proper click parameters (options and click arguments) must be keyword arguments and Click will fill in defaults. Note that before Click 3.2 keyword arguments were not properly filled in against the intention of this code and no context was created. For more information about this change and why it was done in a bugfix release see :ref:`upgrade-to-3.2`. """ self, callback = args[:2] ctx = self # It's also possible to invoke another command which might or # might not have a callback. In that case we also fill # in defaults and make a new context for this command. if isinstance(callback, Command): other_cmd = callback callback = other_cmd.callback ctx = Context(other_cmd, info_name=other_cmd.name, parent=self) if callback is None: raise TypeError('The given command does not have a ' 'callback that can be invoked.') for param in other_cmd.params: if param.name not in kwargs and param.expose_value: kwargs[param.name] = param.get_default(ctx) args = args[2:] with augment_usage_errors(self): with ctx: return callback(*args, **kwargs)
def invoke(*args, **kwargs): """Invokes a command callback in exactly the way it expects. There are two ways to invoke this method: 1. the first argument can be a callback and all other arguments and keyword arguments are forwarded directly to the function. 2. the first argument is a click command object. In that case all arguments are forwarded as well but proper click parameters (options and click arguments) must be keyword arguments and Click will fill in defaults. Note that before Click 3.2 keyword arguments were not properly filled in against the intention of this code and no context was created. For more information about this change and why it was done in a bugfix release see :ref:`upgrade-to-3.2`. """ self, callback = args[:2] ctx = self # It's also possible to invoke another command which might or # might not have a callback. In that case we also fill # in defaults and make a new context for this command. if isinstance(callback, Command): other_cmd = callback callback = other_cmd.callback ctx = Context(other_cmd, info_name=other_cmd.name, parent=self) if callback is None: raise TypeError('The given command does not have a ' 'callback that can be invoked.') for param in other_cmd.params: if param.name not in kwargs and param.expose_value: kwargs[param.name] = param.get_default(ctx) args = args[2:] with augment_usage_errors(self): with ctx: return callback(*args, **kwargs)
[ "Invokes", "a", "command", "callback", "in", "exactly", "the", "way", "it", "expects", ".", "There", "are", "two", "ways", "to", "invoke", "this", "method", ":" ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L518-L555
[ "def", "invoke", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", ",", "callback", "=", "args", "[", ":", "2", "]", "ctx", "=", "self", "# It's also possible to invoke another command which might or", "# might not have a callback. In that case we also fil...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Context.forward
Similar to :meth:`invoke` but fills in default keyword arguments from the current context if the other command expects it. This cannot invoke callbacks directly, only other commands.
pipenv/vendor/click/core.py
def forward(*args, **kwargs): """Similar to :meth:`invoke` but fills in default keyword arguments from the current context if the other command expects it. This cannot invoke callbacks directly, only other commands. """ self, cmd = args[:2] # It's also possible to invoke another command which might or # might not have a callback. if not isinstance(cmd, Command): raise TypeError('Callback is not a command.') for param in self.params: if param not in kwargs: kwargs[param] = self.params[param] return self.invoke(cmd, **kwargs)
def forward(*args, **kwargs): """Similar to :meth:`invoke` but fills in default keyword arguments from the current context if the other command expects it. This cannot invoke callbacks directly, only other commands. """ self, cmd = args[:2] # It's also possible to invoke another command which might or # might not have a callback. if not isinstance(cmd, Command): raise TypeError('Callback is not a command.') for param in self.params: if param not in kwargs: kwargs[param] = self.params[param] return self.invoke(cmd, **kwargs)
[ "Similar", "to", ":", "meth", ":", "invoke", "but", "fills", "in", "default", "keyword", "arguments", "from", "the", "current", "context", "if", "the", "other", "command", "expects", "it", ".", "This", "cannot", "invoke", "callbacks", "directly", "only", "ot...
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L557-L573
[ "def", "forward", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", ",", "cmd", "=", "args", "[", ":", "2", "]", "# It's also possible to invoke another command which might or", "# might not have a callback.", "if", "not", "isinstance", "(", "cmd", ",...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
BaseCommand.main
This is the way to invoke a script with all the bells and whistles as a command line application. This will always terminate the application after a call. If this is not wanted, ``SystemExit`` needs to be caught. This method is also available by directly calling the instance of a :class:`Command`. .. versionadded:: 3.0 Added the `standalone_mode` flag to control the standalone mode. :param args: the arguments that should be used for parsing. If not provided, ``sys.argv[1:]`` is used. :param prog_name: the program name that should be used. By default the program name is constructed by taking the file name from ``sys.argv[0]``. :param complete_var: the environment variable that controls the bash completion support. The default is ``"_<prog_name>_COMPLETE"`` with prog_name in uppercase. :param standalone_mode: the default behavior is to invoke the script in standalone mode. Click will then handle exceptions and convert them into error messages and the function will never return but shut down the interpreter. If this is set to `False` they will be propagated to the caller and the return value of this function is the return value of :meth:`invoke`. :param extra: extra keyword arguments are forwarded to the context constructor. See :class:`Context` for more information.
pipenv/vendor/click/core.py
def main(self, args=None, prog_name=None, complete_var=None, standalone_mode=True, **extra): """This is the way to invoke a script with all the bells and whistles as a command line application. This will always terminate the application after a call. If this is not wanted, ``SystemExit`` needs to be caught. This method is also available by directly calling the instance of a :class:`Command`. .. versionadded:: 3.0 Added the `standalone_mode` flag to control the standalone mode. :param args: the arguments that should be used for parsing. If not provided, ``sys.argv[1:]`` is used. :param prog_name: the program name that should be used. By default the program name is constructed by taking the file name from ``sys.argv[0]``. :param complete_var: the environment variable that controls the bash completion support. The default is ``"_<prog_name>_COMPLETE"`` with prog_name in uppercase. :param standalone_mode: the default behavior is to invoke the script in standalone mode. Click will then handle exceptions and convert them into error messages and the function will never return but shut down the interpreter. If this is set to `False` they will be propagated to the caller and the return value of this function is the return value of :meth:`invoke`. :param extra: extra keyword arguments are forwarded to the context constructor. See :class:`Context` for more information. """ # If we are in Python 3, we will verify that the environment is # sane at this point or reject further execution to avoid a # broken script. if not PY2: _verify_python3_env() else: _check_for_unicode_literals() if args is None: args = get_os_args() else: args = list(args) if prog_name is None: prog_name = make_str(os.path.basename( sys.argv and sys.argv[0] or __file__)) # Hook for the Bash completion. This only activates if the Bash # completion is actually enabled, otherwise this is quite a fast # noop. _bashcomplete(self, prog_name, complete_var) try: try: with self.make_context(prog_name, args, **extra) as ctx: rv = self.invoke(ctx) if not standalone_mode: return rv # it's not safe to `ctx.exit(rv)` here! # note that `rv` may actually contain data like "1" which # has obvious effects # more subtle case: `rv=[None, None]` can come out of # chained commands which all returned `None` -- so it's not # even always obvious that `rv` indicates success/failure # by its truthiness/falsiness ctx.exit() except (EOFError, KeyboardInterrupt): echo(file=sys.stderr) raise Abort() except ClickException as e: if not standalone_mode: raise e.show() sys.exit(e.exit_code) except IOError as e: if e.errno == errno.EPIPE: sys.stdout = PacifyFlushWrapper(sys.stdout) sys.stderr = PacifyFlushWrapper(sys.stderr) sys.exit(1) else: raise except Exit as e: if standalone_mode: sys.exit(e.exit_code) else: # in non-standalone mode, return the exit code # note that this is only reached if `self.invoke` above raises # an Exit explicitly -- thus bypassing the check there which # would return its result # the results of non-standalone execution may therefore be # somewhat ambiguous: if there are codepaths which lead to # `ctx.exit(1)` and to `return 1`, the caller won't be able to # tell the difference between the two return e.exit_code except Abort: if not standalone_mode: raise echo('Aborted!', file=sys.stderr) sys.exit(1)
def main(self, args=None, prog_name=None, complete_var=None, standalone_mode=True, **extra): """This is the way to invoke a script with all the bells and whistles as a command line application. This will always terminate the application after a call. If this is not wanted, ``SystemExit`` needs to be caught. This method is also available by directly calling the instance of a :class:`Command`. .. versionadded:: 3.0 Added the `standalone_mode` flag to control the standalone mode. :param args: the arguments that should be used for parsing. If not provided, ``sys.argv[1:]`` is used. :param prog_name: the program name that should be used. By default the program name is constructed by taking the file name from ``sys.argv[0]``. :param complete_var: the environment variable that controls the bash completion support. The default is ``"_<prog_name>_COMPLETE"`` with prog_name in uppercase. :param standalone_mode: the default behavior is to invoke the script in standalone mode. Click will then handle exceptions and convert them into error messages and the function will never return but shut down the interpreter. If this is set to `False` they will be propagated to the caller and the return value of this function is the return value of :meth:`invoke`. :param extra: extra keyword arguments are forwarded to the context constructor. See :class:`Context` for more information. """ # If we are in Python 3, we will verify that the environment is # sane at this point or reject further execution to avoid a # broken script. if not PY2: _verify_python3_env() else: _check_for_unicode_literals() if args is None: args = get_os_args() else: args = list(args) if prog_name is None: prog_name = make_str(os.path.basename( sys.argv and sys.argv[0] or __file__)) # Hook for the Bash completion. This only activates if the Bash # completion is actually enabled, otherwise this is quite a fast # noop. _bashcomplete(self, prog_name, complete_var) try: try: with self.make_context(prog_name, args, **extra) as ctx: rv = self.invoke(ctx) if not standalone_mode: return rv # it's not safe to `ctx.exit(rv)` here! # note that `rv` may actually contain data like "1" which # has obvious effects # more subtle case: `rv=[None, None]` can come out of # chained commands which all returned `None` -- so it's not # even always obvious that `rv` indicates success/failure # by its truthiness/falsiness ctx.exit() except (EOFError, KeyboardInterrupt): echo(file=sys.stderr) raise Abort() except ClickException as e: if not standalone_mode: raise e.show() sys.exit(e.exit_code) except IOError as e: if e.errno == errno.EPIPE: sys.stdout = PacifyFlushWrapper(sys.stdout) sys.stderr = PacifyFlushWrapper(sys.stderr) sys.exit(1) else: raise except Exit as e: if standalone_mode: sys.exit(e.exit_code) else: # in non-standalone mode, return the exit code # note that this is only reached if `self.invoke` above raises # an Exit explicitly -- thus bypassing the check there which # would return its result # the results of non-standalone execution may therefore be # somewhat ambiguous: if there are codepaths which lead to # `ctx.exit(1)` and to `return 1`, the caller won't be able to # tell the difference between the two return e.exit_code except Abort: if not standalone_mode: raise echo('Aborted!', file=sys.stderr) sys.exit(1)
[ "This", "is", "the", "way", "to", "invoke", "a", "script", "with", "all", "the", "bells", "and", "whistles", "as", "a", "command", "line", "application", ".", "This", "will", "always", "terminate", "the", "application", "after", "a", "call", ".", "If", "...
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L658-L760
[ "def", "main", "(", "self", ",", "args", "=", "None", ",", "prog_name", "=", "None", ",", "complete_var", "=", "None", ",", "standalone_mode", "=", "True", ",", "*", "*", "extra", ")", ":", "# If we are in Python 3, we will verify that the environment is", "# sa...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Command.format_usage
Writes the usage line into the formatter.
pipenv/vendor/click/core.py
def format_usage(self, ctx, formatter): """Writes the usage line into the formatter.""" pieces = self.collect_usage_pieces(ctx) formatter.write_usage(ctx.command_path, ' '.join(pieces))
def format_usage(self, ctx, formatter): """Writes the usage line into the formatter.""" pieces = self.collect_usage_pieces(ctx) formatter.write_usage(ctx.command_path, ' '.join(pieces))
[ "Writes", "the", "usage", "line", "into", "the", "formatter", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L830-L833
[ "def", "format_usage", "(", "self", ",", "ctx", ",", "formatter", ")", ":", "pieces", "=", "self", ".", "collect_usage_pieces", "(", "ctx", ")", "formatter", ".", "write_usage", "(", "ctx", ".", "command_path", ",", "' '", ".", "join", "(", "pieces", ")"...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Command.collect_usage_pieces
Returns all the pieces that go into the usage line and returns it as a list of strings.
pipenv/vendor/click/core.py
def collect_usage_pieces(self, ctx): """Returns all the pieces that go into the usage line and returns it as a list of strings. """ rv = [self.options_metavar] for param in self.get_params(ctx): rv.extend(param.get_usage_pieces(ctx)) return rv
def collect_usage_pieces(self, ctx): """Returns all the pieces that go into the usage line and returns it as a list of strings. """ rv = [self.options_metavar] for param in self.get_params(ctx): rv.extend(param.get_usage_pieces(ctx)) return rv
[ "Returns", "all", "the", "pieces", "that", "go", "into", "the", "usage", "line", "and", "returns", "it", "as", "a", "list", "of", "strings", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L835-L842
[ "def", "collect_usage_pieces", "(", "self", ",", "ctx", ")", ":", "rv", "=", "[", "self", ".", "options_metavar", "]", "for", "param", "in", "self", ".", "get_params", "(", "ctx", ")", ":", "rv", ".", "extend", "(", "param", ".", "get_usage_pieces", "(...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Command.get_help_option_names
Returns the names for the help option.
pipenv/vendor/click/core.py
def get_help_option_names(self, ctx): """Returns the names for the help option.""" all_names = set(ctx.help_option_names) for param in self.params: all_names.difference_update(param.opts) all_names.difference_update(param.secondary_opts) return all_names
def get_help_option_names(self, ctx): """Returns the names for the help option.""" all_names = set(ctx.help_option_names) for param in self.params: all_names.difference_update(param.opts) all_names.difference_update(param.secondary_opts) return all_names
[ "Returns", "the", "names", "for", "the", "help", "option", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L844-L850
[ "def", "get_help_option_names", "(", "self", ",", "ctx", ")", ":", "all_names", "=", "set", "(", "ctx", ".", "help_option_names", ")", "for", "param", "in", "self", ".", "params", ":", "all_names", ".", "difference_update", "(", "param", ".", "opts", ")", ...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Command.get_help_option
Returns the help option object.
pipenv/vendor/click/core.py
def get_help_option(self, ctx): """Returns the help option object.""" help_options = self.get_help_option_names(ctx) if not help_options or not self.add_help_option: return def show_help(ctx, param, value): if value and not ctx.resilient_parsing: echo(ctx.get_help(), color=ctx.color) ctx.exit() return Option(help_options, is_flag=True, is_eager=True, expose_value=False, callback=show_help, help='Show this message and exit.')
def get_help_option(self, ctx): """Returns the help option object.""" help_options = self.get_help_option_names(ctx) if not help_options or not self.add_help_option: return def show_help(ctx, param, value): if value and not ctx.resilient_parsing: echo(ctx.get_help(), color=ctx.color) ctx.exit() return Option(help_options, is_flag=True, is_eager=True, expose_value=False, callback=show_help, help='Show this message and exit.')
[ "Returns", "the", "help", "option", "object", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L852-L865
[ "def", "get_help_option", "(", "self", ",", "ctx", ")", ":", "help_options", "=", "self", ".", "get_help_option_names", "(", "ctx", ")", "if", "not", "help_options", "or", "not", "self", ".", "add_help_option", ":", "return", "def", "show_help", "(", "ctx", ...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Command.make_parser
Creates the underlying option parser for this command.
pipenv/vendor/click/core.py
def make_parser(self, ctx): """Creates the underlying option parser for this command.""" parser = OptionParser(ctx) for param in self.get_params(ctx): param.add_to_parser(parser, ctx) return parser
def make_parser(self, ctx): """Creates the underlying option parser for this command.""" parser = OptionParser(ctx) for param in self.get_params(ctx): param.add_to_parser(parser, ctx) return parser
[ "Creates", "the", "underlying", "option", "parser", "for", "this", "command", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L867-L872
[ "def", "make_parser", "(", "self", ",", "ctx", ")", ":", "parser", "=", "OptionParser", "(", "ctx", ")", "for", "param", "in", "self", ".", "get_params", "(", "ctx", ")", ":", "param", ".", "add_to_parser", "(", "parser", ",", "ctx", ")", "return", "...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Command.get_help
Formats the help into a string and returns it. This creates a formatter and will call into the following formatting methods:
pipenv/vendor/click/core.py
def get_help(self, ctx): """Formats the help into a string and returns it. This creates a formatter and will call into the following formatting methods: """ formatter = ctx.make_formatter() self.format_help(ctx, formatter) return formatter.getvalue().rstrip('\n')
def get_help(self, ctx): """Formats the help into a string and returns it. This creates a formatter and will call into the following formatting methods: """ formatter = ctx.make_formatter() self.format_help(ctx, formatter) return formatter.getvalue().rstrip('\n')
[ "Formats", "the", "help", "into", "a", "string", "and", "returns", "it", ".", "This", "creates", "a", "formatter", "and", "will", "call", "into", "the", "following", "formatting", "methods", ":" ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L874-L880
[ "def", "get_help", "(", "self", ",", "ctx", ")", ":", "formatter", "=", "ctx", ".", "make_formatter", "(", ")", "self", ".", "format_help", "(", "ctx", ",", "formatter", ")", "return", "formatter", ".", "getvalue", "(", ")", ".", "rstrip", "(", "'\\n'"...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Command.get_short_help_str
Gets short help for the command or makes it by shortening the long help string.
pipenv/vendor/click/core.py
def get_short_help_str(self, limit=45): """Gets short help for the command or makes it by shortening the long help string.""" return self.short_help or self.help and make_default_short_help(self.help, limit) or ''
def get_short_help_str(self, limit=45): """Gets short help for the command or makes it by shortening the long help string.""" return self.short_help or self.help and make_default_short_help(self.help, limit) or ''
[ "Gets", "short", "help", "for", "the", "command", "or", "makes", "it", "by", "shortening", "the", "long", "help", "string", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L882-L884
[ "def", "get_short_help_str", "(", "self", ",", "limit", "=", "45", ")", ":", "return", "self", ".", "short_help", "or", "self", ".", "help", "and", "make_default_short_help", "(", "self", ".", "help", ",", "limit", ")", "or", "''" ]
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Command.format_help
Writes the help into the formatter if it exists. This calls into the following methods: - :meth:`format_usage` - :meth:`format_help_text` - :meth:`format_options` - :meth:`format_epilog`
pipenv/vendor/click/core.py
def format_help(self, ctx, formatter): """Writes the help into the formatter if it exists. This calls into the following methods: - :meth:`format_usage` - :meth:`format_help_text` - :meth:`format_options` - :meth:`format_epilog` """ self.format_usage(ctx, formatter) self.format_help_text(ctx, formatter) self.format_options(ctx, formatter) self.format_epilog(ctx, formatter)
def format_help(self, ctx, formatter): """Writes the help into the formatter if it exists. This calls into the following methods: - :meth:`format_usage` - :meth:`format_help_text` - :meth:`format_options` - :meth:`format_epilog` """ self.format_usage(ctx, formatter) self.format_help_text(ctx, formatter) self.format_options(ctx, formatter) self.format_epilog(ctx, formatter)
[ "Writes", "the", "help", "into", "the", "formatter", "if", "it", "exists", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L886-L899
[ "def", "format_help", "(", "self", ",", "ctx", ",", "formatter", ")", ":", "self", ".", "format_usage", "(", "ctx", ",", "formatter", ")", "self", ".", "format_help_text", "(", "ctx", ",", "formatter", ")", "self", ".", "format_options", "(", "ctx", ",",...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Command.format_help_text
Writes the help text to the formatter if it exists.
pipenv/vendor/click/core.py
def format_help_text(self, ctx, formatter): """Writes the help text to the formatter if it exists.""" if self.help: formatter.write_paragraph() with formatter.indentation(): help_text = self.help if self.deprecated: help_text += DEPRECATED_HELP_NOTICE formatter.write_text(help_text) elif self.deprecated: formatter.write_paragraph() with formatter.indentation(): formatter.write_text(DEPRECATED_HELP_NOTICE)
def format_help_text(self, ctx, formatter): """Writes the help text to the formatter if it exists.""" if self.help: formatter.write_paragraph() with formatter.indentation(): help_text = self.help if self.deprecated: help_text += DEPRECATED_HELP_NOTICE formatter.write_text(help_text) elif self.deprecated: formatter.write_paragraph() with formatter.indentation(): formatter.write_text(DEPRECATED_HELP_NOTICE)
[ "Writes", "the", "help", "text", "to", "the", "formatter", "if", "it", "exists", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L901-L913
[ "def", "format_help_text", "(", "self", ",", "ctx", ",", "formatter", ")", ":", "if", "self", ".", "help", ":", "formatter", ".", "write_paragraph", "(", ")", "with", "formatter", ".", "indentation", "(", ")", ":", "help_text", "=", "self", ".", "help", ...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Command.format_options
Writes all the options into the formatter if they exist.
pipenv/vendor/click/core.py
def format_options(self, ctx, formatter): """Writes all the options into the formatter if they exist.""" opts = [] for param in self.get_params(ctx): rv = param.get_help_record(ctx) if rv is not None: opts.append(rv) if opts: with formatter.section('Options'): formatter.write_dl(opts)
def format_options(self, ctx, formatter): """Writes all the options into the formatter if they exist.""" opts = [] for param in self.get_params(ctx): rv = param.get_help_record(ctx) if rv is not None: opts.append(rv) if opts: with formatter.section('Options'): formatter.write_dl(opts)
[ "Writes", "all", "the", "options", "into", "the", "formatter", "if", "they", "exist", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L915-L925
[ "def", "format_options", "(", "self", ",", "ctx", ",", "formatter", ")", ":", "opts", "=", "[", "]", "for", "param", "in", "self", ".", "get_params", "(", "ctx", ")", ":", "rv", "=", "param", ".", "get_help_record", "(", "ctx", ")", "if", "rv", "is...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Command.format_epilog
Writes the epilog into the formatter if it exists.
pipenv/vendor/click/core.py
def format_epilog(self, ctx, formatter): """Writes the epilog into the formatter if it exists.""" if self.epilog: formatter.write_paragraph() with formatter.indentation(): formatter.write_text(self.epilog)
def format_epilog(self, ctx, formatter): """Writes the epilog into the formatter if it exists.""" if self.epilog: formatter.write_paragraph() with formatter.indentation(): formatter.write_text(self.epilog)
[ "Writes", "the", "epilog", "into", "the", "formatter", "if", "it", "exists", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L927-L932
[ "def", "format_epilog", "(", "self", ",", "ctx", ",", "formatter", ")", ":", "if", "self", ".", "epilog", ":", "formatter", ".", "write_paragraph", "(", ")", "with", "formatter", ".", "indentation", "(", ")", ":", "formatter", ".", "write_text", "(", "se...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Command.invoke
Given a context, this invokes the attached callback (if it exists) in the right way.
pipenv/vendor/click/core.py
def invoke(self, ctx): """Given a context, this invokes the attached callback (if it exists) in the right way. """ _maybe_show_deprecated_notice(self) if self.callback is not None: return ctx.invoke(self.callback, **ctx.params)
def invoke(self, ctx): """Given a context, this invokes the attached callback (if it exists) in the right way. """ _maybe_show_deprecated_notice(self) if self.callback is not None: return ctx.invoke(self.callback, **ctx.params)
[ "Given", "a", "context", "this", "invokes", "the", "attached", "callback", "(", "if", "it", "exists", ")", "in", "the", "right", "way", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L950-L956
[ "def", "invoke", "(", "self", ",", "ctx", ")", ":", "_maybe_show_deprecated_notice", "(", "self", ")", "if", "self", ".", "callback", "is", "not", "None", ":", "return", "ctx", ".", "invoke", "(", "self", ".", "callback", ",", "*", "*", "ctx", ".", "...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
MultiCommand.resultcallback
Adds a result callback to the chain command. By default if a result callback is already registered this will chain them but this can be disabled with the `replace` parameter. The result callback is invoked with the return value of the subcommand (or the list of return values from all subcommands if chaining is enabled) as well as the parameters as they would be passed to the main callback. Example:: @click.group() @click.option('-i', '--input', default=23) def cli(input): return 42 @cli.resultcallback() def process_result(result, input): return result + input .. versionadded:: 3.0 :param replace: if set to `True` an already existing result callback will be removed.
pipenv/vendor/click/core.py
def resultcallback(self, replace=False): """Adds a result callback to the chain command. By default if a result callback is already registered this will chain them but this can be disabled with the `replace` parameter. The result callback is invoked with the return value of the subcommand (or the list of return values from all subcommands if chaining is enabled) as well as the parameters as they would be passed to the main callback. Example:: @click.group() @click.option('-i', '--input', default=23) def cli(input): return 42 @cli.resultcallback() def process_result(result, input): return result + input .. versionadded:: 3.0 :param replace: if set to `True` an already existing result callback will be removed. """ def decorator(f): old_callback = self.result_callback if old_callback is None or replace: self.result_callback = f return f def function(__value, *args, **kwargs): return f(old_callback(__value, *args, **kwargs), *args, **kwargs) self.result_callback = rv = update_wrapper(function, f) return rv return decorator
def resultcallback(self, replace=False): """Adds a result callback to the chain command. By default if a result callback is already registered this will chain them but this can be disabled with the `replace` parameter. The result callback is invoked with the return value of the subcommand (or the list of return values from all subcommands if chaining is enabled) as well as the parameters as they would be passed to the main callback. Example:: @click.group() @click.option('-i', '--input', default=23) def cli(input): return 42 @cli.resultcallback() def process_result(result, input): return result + input .. versionadded:: 3.0 :param replace: if set to `True` an already existing result callback will be removed. """ def decorator(f): old_callback = self.result_callback if old_callback is None or replace: self.result_callback = f return f def function(__value, *args, **kwargs): return f(old_callback(__value, *args, **kwargs), *args, **kwargs) self.result_callback = rv = update_wrapper(function, f) return rv return decorator
[ "Adds", "a", "result", "callback", "to", "the", "chain", "command", ".", "By", "default", "if", "a", "result", "callback", "is", "already", "registered", "this", "will", "chain", "them", "but", "this", "can", "be", "disabled", "with", "the", "replace", "pa...
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L1019-L1054
[ "def", "resultcallback", "(", "self", ",", "replace", "=", "False", ")", ":", "def", "decorator", "(", "f", ")", ":", "old_callback", "=", "self", ".", "result_callback", "if", "old_callback", "is", "None", "or", "replace", ":", "self", ".", "result_callba...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
MultiCommand.format_commands
Extra format methods for multi methods that adds all the commands after the options.
pipenv/vendor/click/core.py
def format_commands(self, ctx, formatter): """Extra format methods for multi methods that adds all the commands after the options. """ commands = [] for subcommand in self.list_commands(ctx): cmd = self.get_command(ctx, subcommand) # What is this, the tool lied about a command. Ignore it if cmd is None: continue if cmd.hidden: continue commands.append((subcommand, cmd)) # allow for 3 times the default spacing if len(commands): limit = formatter.width - 6 - max(len(cmd[0]) for cmd in commands) rows = [] for subcommand, cmd in commands: help = cmd.get_short_help_str(limit) rows.append((subcommand, help)) if rows: with formatter.section('Commands'): formatter.write_dl(rows)
def format_commands(self, ctx, formatter): """Extra format methods for multi methods that adds all the commands after the options. """ commands = [] for subcommand in self.list_commands(ctx): cmd = self.get_command(ctx, subcommand) # What is this, the tool lied about a command. Ignore it if cmd is None: continue if cmd.hidden: continue commands.append((subcommand, cmd)) # allow for 3 times the default spacing if len(commands): limit = formatter.width - 6 - max(len(cmd[0]) for cmd in commands) rows = [] for subcommand, cmd in commands: help = cmd.get_short_help_str(limit) rows.append((subcommand, help)) if rows: with formatter.section('Commands'): formatter.write_dl(rows)
[ "Extra", "format", "methods", "for", "multi", "methods", "that", "adds", "all", "the", "commands", "after", "the", "options", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L1056-L1082
[ "def", "format_commands", "(", "self", ",", "ctx", ",", "formatter", ")", ":", "commands", "=", "[", "]", "for", "subcommand", "in", "self", ".", "list_commands", "(", "ctx", ")", ":", "cmd", "=", "self", ".", "get_command", "(", "ctx", ",", "subcomman...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Group.add_command
Registers another :class:`Command` with this group. If the name is not provided, the name of the command is used.
pipenv/vendor/click/core.py
def add_command(self, cmd, name=None): """Registers another :class:`Command` with this group. If the name is not provided, the name of the command is used. """ name = name or cmd.name if name is None: raise TypeError('Command has no name.') _check_multicommand(self, name, cmd, register=True) self.commands[name] = cmd
def add_command(self, cmd, name=None): """Registers another :class:`Command` with this group. If the name is not provided, the name of the command is used. """ name = name or cmd.name if name is None: raise TypeError('Command has no name.') _check_multicommand(self, name, cmd, register=True) self.commands[name] = cmd
[ "Registers", "another", ":", "class", ":", "Command", "with", "this", "group", ".", "If", "the", "name", "is", "not", "provided", "the", "name", "of", "the", "command", "is", "used", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L1217-L1225
[ "def", "add_command", "(", "self", ",", "cmd", ",", "name", "=", "None", ")", ":", "name", "=", "name", "or", "cmd", ".", "name", "if", "name", "is", "None", ":", "raise", "TypeError", "(", "'Command has no name.'", ")", "_check_multicommand", "(", "self...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Group.command
A shortcut decorator for declaring and attaching a command to the group. This takes the same arguments as :func:`command` but immediately registers the created command with this instance by calling into :meth:`add_command`.
pipenv/vendor/click/core.py
def command(self, *args, **kwargs): """A shortcut decorator for declaring and attaching a command to the group. This takes the same arguments as :func:`command` but immediately registers the created command with this instance by calling into :meth:`add_command`. """ def decorator(f): cmd = command(*args, **kwargs)(f) self.add_command(cmd) return cmd return decorator
def command(self, *args, **kwargs): """A shortcut decorator for declaring and attaching a command to the group. This takes the same arguments as :func:`command` but immediately registers the created command with this instance by calling into :meth:`add_command`. """ def decorator(f): cmd = command(*args, **kwargs)(f) self.add_command(cmd) return cmd return decorator
[ "A", "shortcut", "decorator", "for", "declaring", "and", "attaching", "a", "command", "to", "the", "group", ".", "This", "takes", "the", "same", "arguments", "as", ":", "func", ":", "command", "but", "immediately", "registers", "the", "created", "command", "...
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L1227-L1237
[ "def", "command", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "def", "decorator", "(", "f", ")", ":", "cmd", "=", "command", "(", "*", "args", ",", "*", "*", "kwargs", ")", "(", "f", ")", "self", ".", "add_command", "(", ...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Group.group
A shortcut decorator for declaring and attaching a group to the group. This takes the same arguments as :func:`group` but immediately registers the created command with this instance by calling into :meth:`add_command`.
pipenv/vendor/click/core.py
def group(self, *args, **kwargs): """A shortcut decorator for declaring and attaching a group to the group. This takes the same arguments as :func:`group` but immediately registers the created command with this instance by calling into :meth:`add_command`. """ def decorator(f): cmd = group(*args, **kwargs)(f) self.add_command(cmd) return cmd return decorator
def group(self, *args, **kwargs): """A shortcut decorator for declaring and attaching a group to the group. This takes the same arguments as :func:`group` but immediately registers the created command with this instance by calling into :meth:`add_command`. """ def decorator(f): cmd = group(*args, **kwargs)(f) self.add_command(cmd) return cmd return decorator
[ "A", "shortcut", "decorator", "for", "declaring", "and", "attaching", "a", "group", "to", "the", "group", ".", "This", "takes", "the", "same", "arguments", "as", ":", "func", ":", "group", "but", "immediately", "registers", "the", "created", "command", "with...
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L1239-L1249
[ "def", "group", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "def", "decorator", "(", "f", ")", ":", "cmd", "=", "group", "(", "*", "args", ",", "*", "*", "kwargs", ")", "(", "f", ")", "self", ".", "add_command", "(", "cm...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Parameter.get_default
Given a context variable this calculates the default value.
pipenv/vendor/click/core.py
def get_default(self, ctx): """Given a context variable this calculates the default value.""" # Otherwise go with the regular default. if callable(self.default): rv = self.default() else: rv = self.default return self.type_cast_value(ctx, rv)
def get_default(self, ctx): """Given a context variable this calculates the default value.""" # Otherwise go with the regular default. if callable(self.default): rv = self.default() else: rv = self.default return self.type_cast_value(ctx, rv)
[ "Given", "a", "context", "variable", "this", "calculates", "the", "default", "value", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L1378-L1385
[ "def", "get_default", "(", "self", ",", "ctx", ")", ":", "# Otherwise go with the regular default.", "if", "callable", "(", "self", ".", "default", ")", ":", "rv", "=", "self", ".", "default", "(", ")", "else", ":", "rv", "=", "self", ".", "default", "re...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde
train
Parameter.type_cast_value
Given a value this runs it properly through the type system. This automatically handles things like `nargs` and `multiple` as well as composite types.
pipenv/vendor/click/core.py
def type_cast_value(self, ctx, value): """Given a value this runs it properly through the type system. This automatically handles things like `nargs` and `multiple` as well as composite types. """ if self.type.is_composite: if self.nargs <= 1: raise TypeError('Attempted to invoke composite type ' 'but nargs has been set to %s. This is ' 'not supported; nargs needs to be set to ' 'a fixed value > 1.' % self.nargs) if self.multiple: return tuple(self.type(x or (), self, ctx) for x in value or ()) return self.type(value or (), self, ctx) def _convert(value, level): if level == 0: return self.type(value, self, ctx) return tuple(_convert(x, level - 1) for x in value or ()) return _convert(value, (self.nargs != 1) + bool(self.multiple))
def type_cast_value(self, ctx, value): """Given a value this runs it properly through the type system. This automatically handles things like `nargs` and `multiple` as well as composite types. """ if self.type.is_composite: if self.nargs <= 1: raise TypeError('Attempted to invoke composite type ' 'but nargs has been set to %s. This is ' 'not supported; nargs needs to be set to ' 'a fixed value > 1.' % self.nargs) if self.multiple: return tuple(self.type(x or (), self, ctx) for x in value or ()) return self.type(value or (), self, ctx) def _convert(value, level): if level == 0: return self.type(value, self, ctx) return tuple(_convert(x, level - 1) for x in value or ()) return _convert(value, (self.nargs != 1) + bool(self.multiple))
[ "Given", "a", "value", "this", "runs", "it", "properly", "through", "the", "type", "system", ".", "This", "automatically", "handles", "things", "like", "nargs", "and", "multiple", "as", "well", "as", "composite", "types", "." ]
pypa/pipenv
python
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/click/core.py#L1398-L1417
[ "def", "type_cast_value", "(", "self", ",", "ctx", ",", "value", ")", ":", "if", "self", ".", "type", ".", "is_composite", ":", "if", "self", ".", "nargs", "<=", "1", ":", "raise", "TypeError", "(", "'Attempted to invoke composite type '", "'but nargs has been...
cae8d76c210b9777e90aab76e9c4b0e53bb19cde