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 | Locator.score_url | Give an url a score which can be used to choose preferred URLs
for a given project release. | pipenv/vendor/distlib/locators.py | def score_url(self, url):
"""
Give an url a score which can be used to choose preferred URLs
for a given project release.
"""
t = urlparse(url)
basename = posixpath.basename(t.path)
compatible = True
is_wheel = basename.endswith('.whl')
is_downloadable = basename.endswith(self.downloadable_extensions)
if is_wheel:
compatible = is_compatible(Wheel(basename), self.wheel_tags)
return (t.scheme == 'https', 'pypi.python.org' in t.netloc,
is_downloadable, is_wheel, compatible, basename) | def score_url(self, url):
"""
Give an url a score which can be used to choose preferred URLs
for a given project release.
"""
t = urlparse(url)
basename = posixpath.basename(t.path)
compatible = True
is_wheel = basename.endswith('.whl')
is_downloadable = basename.endswith(self.downloadable_extensions)
if is_wheel:
compatible = is_compatible(Wheel(basename), self.wheel_tags)
return (t.scheme == 'https', 'pypi.python.org' in t.netloc,
is_downloadable, is_wheel, compatible, basename) | [
"Give",
"an",
"url",
"a",
"score",
"which",
"can",
"be",
"used",
"to",
"choose",
"preferred",
"URLs",
"for",
"a",
"given",
"project",
"release",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/distlib/locators.py#L188-L201 | [
"def",
"score_url",
"(",
"self",
",",
"url",
")",
":",
"t",
"=",
"urlparse",
"(",
"url",
")",
"basename",
"=",
"posixpath",
".",
"basename",
"(",
"t",
".",
"path",
")",
"compatible",
"=",
"True",
"is_wheel",
"=",
"basename",
".",
"endswith",
"(",
"'.... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Locator.prefer_url | Choose one of two URLs where both are candidates for distribution
archives for the same version of a distribution (for example,
.tar.gz vs. zip).
The current implementation favours https:// URLs over http://, archives
from PyPI over those from other locations, wheel compatibility (if a
wheel) and then the archive name. | pipenv/vendor/distlib/locators.py | def prefer_url(self, url1, url2):
"""
Choose one of two URLs where both are candidates for distribution
archives for the same version of a distribution (for example,
.tar.gz vs. zip).
The current implementation favours https:// URLs over http://, archives
from PyPI over those from other locations, wheel compatibility (if a
wheel) and then the archive name.
"""
result = url2
if url1:
s1 = self.score_url(url1)
s2 = self.score_url(url2)
if s1 > s2:
result = url1
if result != url2:
logger.debug('Not replacing %r with %r', url1, url2)
else:
logger.debug('Replacing %r with %r', url1, url2)
return result | def prefer_url(self, url1, url2):
"""
Choose one of two URLs where both are candidates for distribution
archives for the same version of a distribution (for example,
.tar.gz vs. zip).
The current implementation favours https:// URLs over http://, archives
from PyPI over those from other locations, wheel compatibility (if a
wheel) and then the archive name.
"""
result = url2
if url1:
s1 = self.score_url(url1)
s2 = self.score_url(url2)
if s1 > s2:
result = url1
if result != url2:
logger.debug('Not replacing %r with %r', url1, url2)
else:
logger.debug('Replacing %r with %r', url1, url2)
return result | [
"Choose",
"one",
"of",
"two",
"URLs",
"where",
"both",
"are",
"candidates",
"for",
"distribution",
"archives",
"for",
"the",
"same",
"version",
"of",
"a",
"distribution",
"(",
"for",
"example",
".",
"tar",
".",
"gz",
"vs",
".",
"zip",
")",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/distlib/locators.py#L203-L223 | [
"def",
"prefer_url",
"(",
"self",
",",
"url1",
",",
"url2",
")",
":",
"result",
"=",
"url2",
"if",
"url1",
":",
"s1",
"=",
"self",
".",
"score_url",
"(",
"url1",
")",
"s2",
"=",
"self",
".",
"score_url",
"(",
"url2",
")",
"if",
"s1",
">",
"s2",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Locator._get_digest | Get a digest from a dictionary by looking at keys of the form
'algo_digest'.
Returns a 2-tuple (algo, digest) if found, else None. Currently
looks only for SHA256, then MD5. | pipenv/vendor/distlib/locators.py | def _get_digest(self, info):
"""
Get a digest from a dictionary by looking at keys of the form
'algo_digest'.
Returns a 2-tuple (algo, digest) if found, else None. Currently
looks only for SHA256, then MD5.
"""
result = None
for algo in ('sha256', 'md5'):
key = '%s_digest' % algo
if key in info:
result = (algo, info[key])
break
return result | def _get_digest(self, info):
"""
Get a digest from a dictionary by looking at keys of the form
'algo_digest'.
Returns a 2-tuple (algo, digest) if found, else None. Currently
looks only for SHA256, then MD5.
"""
result = None
for algo in ('sha256', 'md5'):
key = '%s_digest' % algo
if key in info:
result = (algo, info[key])
break
return result | [
"Get",
"a",
"digest",
"from",
"a",
"dictionary",
"by",
"looking",
"at",
"keys",
"of",
"the",
"form",
"algo_digest",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/distlib/locators.py#L305-L319 | [
"def",
"_get_digest",
"(",
"self",
",",
"info",
")",
":",
"result",
"=",
"None",
"for",
"algo",
"in",
"(",
"'sha256'",
",",
"'md5'",
")",
":",
"key",
"=",
"'%s_digest'",
"%",
"algo",
"if",
"key",
"in",
"info",
":",
"result",
"=",
"(",
"algo",
",",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Page.links | Return the URLs of all the links on a page together with information
about their "rel" attribute, for determining which ones to treat as
downloads and which ones to queue for further scraping. | pipenv/vendor/distlib/locators.py | def links(self):
"""
Return the URLs of all the links on a page together with information
about their "rel" attribute, for determining which ones to treat as
downloads and which ones to queue for further scraping.
"""
def clean(url):
"Tidy up an URL."
scheme, netloc, path, params, query, frag = urlparse(url)
return urlunparse((scheme, netloc, quote(path),
params, query, frag))
result = set()
for match in self._href.finditer(self.data):
d = match.groupdict('')
rel = (d['rel1'] or d['rel2'] or d['rel3'] or
d['rel4'] or d['rel5'] or d['rel6'])
url = d['url1'] or d['url2'] or d['url3']
url = urljoin(self.base_url, url)
url = unescape(url)
url = self._clean_re.sub(lambda m: '%%%2x' % ord(m.group(0)), url)
result.add((url, rel))
# We sort the result, hoping to bring the most recent versions
# to the front
result = sorted(result, key=lambda t: t[0], reverse=True)
return result | def links(self):
"""
Return the URLs of all the links on a page together with information
about their "rel" attribute, for determining which ones to treat as
downloads and which ones to queue for further scraping.
"""
def clean(url):
"Tidy up an URL."
scheme, netloc, path, params, query, frag = urlparse(url)
return urlunparse((scheme, netloc, quote(path),
params, query, frag))
result = set()
for match in self._href.finditer(self.data):
d = match.groupdict('')
rel = (d['rel1'] or d['rel2'] or d['rel3'] or
d['rel4'] or d['rel5'] or d['rel6'])
url = d['url1'] or d['url2'] or d['url3']
url = urljoin(self.base_url, url)
url = unescape(url)
url = self._clean_re.sub(lambda m: '%%%2x' % ord(m.group(0)), url)
result.add((url, rel))
# We sort the result, hoping to bring the most recent versions
# to the front
result = sorted(result, key=lambda t: t[0], reverse=True)
return result | [
"Return",
"the",
"URLs",
"of",
"all",
"the",
"links",
"on",
"a",
"page",
"together",
"with",
"information",
"about",
"their",
"rel",
"attribute",
"for",
"determining",
"which",
"ones",
"to",
"treat",
"as",
"downloads",
"and",
"which",
"ones",
"to",
"queue",
... | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/distlib/locators.py#L551-L576 | [
"def",
"links",
"(",
"self",
")",
":",
"def",
"clean",
"(",
"url",
")",
":",
"\"Tidy up an URL.\"",
"scheme",
",",
"netloc",
",",
"path",
",",
"params",
",",
"query",
",",
"frag",
"=",
"urlparse",
"(",
"url",
")",
"return",
"urlunparse",
"(",
"(",
"s... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | SimpleScrapingLocator._prepare_threads | Threads are created only when get_project is called, and terminate
before it returns. They are there primarily to parallelise I/O (i.e.
fetching web pages). | pipenv/vendor/distlib/locators.py | def _prepare_threads(self):
"""
Threads are created only when get_project is called, and terminate
before it returns. They are there primarily to parallelise I/O (i.e.
fetching web pages).
"""
self._threads = []
for i in range(self.num_workers):
t = threading.Thread(target=self._fetch)
t.setDaemon(True)
t.start()
self._threads.append(t) | def _prepare_threads(self):
"""
Threads are created only when get_project is called, and terminate
before it returns. They are there primarily to parallelise I/O (i.e.
fetching web pages).
"""
self._threads = []
for i in range(self.num_workers):
t = threading.Thread(target=self._fetch)
t.setDaemon(True)
t.start()
self._threads.append(t) | [
"Threads",
"are",
"created",
"only",
"when",
"get_project",
"is",
"called",
"and",
"terminate",
"before",
"it",
"returns",
".",
"They",
"are",
"there",
"primarily",
"to",
"parallelise",
"I",
"/",
"O",
"(",
"i",
".",
"e",
".",
"fetching",
"web",
"pages",
... | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/distlib/locators.py#L620-L631 | [
"def",
"_prepare_threads",
"(",
"self",
")",
":",
"self",
".",
"_threads",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"num_workers",
")",
":",
"t",
"=",
"threading",
".",
"Thread",
"(",
"target",
"=",
"self",
".",
"_fetch",
")",
"t... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | SimpleScrapingLocator._wait_threads | Tell all the threads to terminate (by sending a sentinel value) and
wait for them to do so. | pipenv/vendor/distlib/locators.py | def _wait_threads(self):
"""
Tell all the threads to terminate (by sending a sentinel value) and
wait for them to do so.
"""
# Note that you need two loops, since you can't say which
# thread will get each sentinel
for t in self._threads:
self._to_fetch.put(None) # sentinel
for t in self._threads:
t.join()
self._threads = [] | def _wait_threads(self):
"""
Tell all the threads to terminate (by sending a sentinel value) and
wait for them to do so.
"""
# Note that you need two loops, since you can't say which
# thread will get each sentinel
for t in self._threads:
self._to_fetch.put(None) # sentinel
for t in self._threads:
t.join()
self._threads = [] | [
"Tell",
"all",
"the",
"threads",
"to",
"terminate",
"(",
"by",
"sending",
"a",
"sentinel",
"value",
")",
"and",
"wait",
"for",
"them",
"to",
"do",
"so",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/distlib/locators.py#L633-L644 | [
"def",
"_wait_threads",
"(",
"self",
")",
":",
"# Note that you need two loops, since you can't say which",
"# thread will get each sentinel",
"for",
"t",
"in",
"self",
".",
"_threads",
":",
"self",
".",
"_to_fetch",
".",
"put",
"(",
"None",
")",
"# sentinel",
"for",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | SimpleScrapingLocator._process_download | See if an URL is a suitable download for a project.
If it is, register information in the result dictionary (for
_get_project) about the specific version it's for.
Note that the return value isn't actually used other than as a boolean
value. | pipenv/vendor/distlib/locators.py | def _process_download(self, url):
"""
See if an URL is a suitable download for a project.
If it is, register information in the result dictionary (for
_get_project) about the specific version it's for.
Note that the return value isn't actually used other than as a boolean
value.
"""
if self.platform_check and self._is_platform_dependent(url):
info = None
else:
info = self.convert_url_to_download_info(url, self.project_name)
logger.debug('process_download: %s -> %s', url, info)
if info:
with self._lock: # needed because self.result is shared
self._update_version_data(self.result, info)
return info | def _process_download(self, url):
"""
See if an URL is a suitable download for a project.
If it is, register information in the result dictionary (for
_get_project) about the specific version it's for.
Note that the return value isn't actually used other than as a boolean
value.
"""
if self.platform_check and self._is_platform_dependent(url):
info = None
else:
info = self.convert_url_to_download_info(url, self.project_name)
logger.debug('process_download: %s -> %s', url, info)
if info:
with self._lock: # needed because self.result is shared
self._update_version_data(self.result, info)
return info | [
"See",
"if",
"an",
"URL",
"is",
"a",
"suitable",
"download",
"for",
"a",
"project",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/distlib/locators.py#L673-L691 | [
"def",
"_process_download",
"(",
"self",
",",
"url",
")",
":",
"if",
"self",
".",
"platform_check",
"and",
"self",
".",
"_is_platform_dependent",
"(",
"url",
")",
":",
"info",
"=",
"None",
"else",
":",
"info",
"=",
"self",
".",
"convert_url_to_download_info"... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | SimpleScrapingLocator._should_queue | Determine whether a link URL from a referring page and with a
particular "rel" attribute should be queued for scraping. | pipenv/vendor/distlib/locators.py | def _should_queue(self, link, referrer, rel):
"""
Determine whether a link URL from a referring page and with a
particular "rel" attribute should be queued for scraping.
"""
scheme, netloc, path, _, _, _ = urlparse(link)
if path.endswith(self.source_extensions + self.binary_extensions +
self.excluded_extensions):
result = False
elif self.skip_externals and not link.startswith(self.base_url):
result = False
elif not referrer.startswith(self.base_url):
result = False
elif rel not in ('homepage', 'download'):
result = False
elif scheme not in ('http', 'https', 'ftp'):
result = False
elif self._is_platform_dependent(link):
result = False
else:
host = netloc.split(':', 1)[0]
if host.lower() == 'localhost':
result = False
else:
result = True
logger.debug('should_queue: %s (%s) from %s -> %s', link, rel,
referrer, result)
return result | def _should_queue(self, link, referrer, rel):
"""
Determine whether a link URL from a referring page and with a
particular "rel" attribute should be queued for scraping.
"""
scheme, netloc, path, _, _, _ = urlparse(link)
if path.endswith(self.source_extensions + self.binary_extensions +
self.excluded_extensions):
result = False
elif self.skip_externals and not link.startswith(self.base_url):
result = False
elif not referrer.startswith(self.base_url):
result = False
elif rel not in ('homepage', 'download'):
result = False
elif scheme not in ('http', 'https', 'ftp'):
result = False
elif self._is_platform_dependent(link):
result = False
else:
host = netloc.split(':', 1)[0]
if host.lower() == 'localhost':
result = False
else:
result = True
logger.debug('should_queue: %s (%s) from %s -> %s', link, rel,
referrer, result)
return result | [
"Determine",
"whether",
"a",
"link",
"URL",
"from",
"a",
"referring",
"page",
"and",
"with",
"a",
"particular",
"rel",
"attribute",
"should",
"be",
"queued",
"for",
"scraping",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/distlib/locators.py#L693-L720 | [
"def",
"_should_queue",
"(",
"self",
",",
"link",
",",
"referrer",
",",
"rel",
")",
":",
"scheme",
",",
"netloc",
",",
"path",
",",
"_",
",",
"_",
",",
"_",
"=",
"urlparse",
"(",
"link",
")",
"if",
"path",
".",
"endswith",
"(",
"self",
".",
"sour... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | SimpleScrapingLocator._fetch | Get a URL to fetch from the work queue, get the HTML page, examine its
links for download candidates and candidates for further scraping.
This is a handy method to run in a thread. | pipenv/vendor/distlib/locators.py | def _fetch(self):
"""
Get a URL to fetch from the work queue, get the HTML page, examine its
links for download candidates and candidates for further scraping.
This is a handy method to run in a thread.
"""
while True:
url = self._to_fetch.get()
try:
if url:
page = self.get_page(url)
if page is None: # e.g. after an error
continue
for link, rel in page.links:
if link not in self._seen:
try:
self._seen.add(link)
if (not self._process_download(link) and
self._should_queue(link, url, rel)):
logger.debug('Queueing %s from %s', link, url)
self._to_fetch.put(link)
except MetadataInvalidError: # e.g. invalid versions
pass
except Exception as e: # pragma: no cover
self.errors.put(text_type(e))
finally:
# always do this, to avoid hangs :-)
self._to_fetch.task_done()
if not url:
#logger.debug('Sentinel seen, quitting.')
break | def _fetch(self):
"""
Get a URL to fetch from the work queue, get the HTML page, examine its
links for download candidates and candidates for further scraping.
This is a handy method to run in a thread.
"""
while True:
url = self._to_fetch.get()
try:
if url:
page = self.get_page(url)
if page is None: # e.g. after an error
continue
for link, rel in page.links:
if link not in self._seen:
try:
self._seen.add(link)
if (not self._process_download(link) and
self._should_queue(link, url, rel)):
logger.debug('Queueing %s from %s', link, url)
self._to_fetch.put(link)
except MetadataInvalidError: # e.g. invalid versions
pass
except Exception as e: # pragma: no cover
self.errors.put(text_type(e))
finally:
# always do this, to avoid hangs :-)
self._to_fetch.task_done()
if not url:
#logger.debug('Sentinel seen, quitting.')
break | [
"Get",
"a",
"URL",
"to",
"fetch",
"from",
"the",
"work",
"queue",
"get",
"the",
"HTML",
"page",
"examine",
"its",
"links",
"for",
"download",
"candidates",
"and",
"candidates",
"for",
"further",
"scraping",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/distlib/locators.py#L722-L753 | [
"def",
"_fetch",
"(",
"self",
")",
":",
"while",
"True",
":",
"url",
"=",
"self",
".",
"_to_fetch",
".",
"get",
"(",
")",
"try",
":",
"if",
"url",
":",
"page",
"=",
"self",
".",
"get_page",
"(",
"url",
")",
"if",
"page",
"is",
"None",
":",
"# e... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | SimpleScrapingLocator.get_distribution_names | Return all the distribution names known to this locator. | pipenv/vendor/distlib/locators.py | def get_distribution_names(self):
"""
Return all the distribution names known to this locator.
"""
result = set()
page = self.get_page(self.base_url)
if not page:
raise DistlibException('Unable to get %s' % self.base_url)
for match in self._distname_re.finditer(page.data):
result.add(match.group(1))
return result | def get_distribution_names(self):
"""
Return all the distribution names known to this locator.
"""
result = set()
page = self.get_page(self.base_url)
if not page:
raise DistlibException('Unable to get %s' % self.base_url)
for match in self._distname_re.finditer(page.data):
result.add(match.group(1))
return result | [
"Return",
"all",
"the",
"distribution",
"names",
"known",
"to",
"this",
"locator",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/distlib/locators.py#L816-L826 | [
"def",
"get_distribution_names",
"(",
"self",
")",
":",
"result",
"=",
"set",
"(",
")",
"page",
"=",
"self",
".",
"get_page",
"(",
"self",
".",
"base_url",
")",
"if",
"not",
"page",
":",
"raise",
"DistlibException",
"(",
"'Unable to get %s'",
"%",
"self",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | DirectoryLocator.get_distribution_names | Return all the distribution names known to this locator. | pipenv/vendor/distlib/locators.py | def get_distribution_names(self):
"""
Return all the distribution names known to this locator.
"""
result = set()
for root, dirs, files in os.walk(self.base_dir):
for fn in files:
if self.should_include(fn, root):
fn = os.path.join(root, fn)
url = urlunparse(('file', '',
pathname2url(os.path.abspath(fn)),
'', '', ''))
info = self.convert_url_to_download_info(url, None)
if info:
result.add(info['name'])
if not self.recursive:
break
return result | def get_distribution_names(self):
"""
Return all the distribution names known to this locator.
"""
result = set()
for root, dirs, files in os.walk(self.base_dir):
for fn in files:
if self.should_include(fn, root):
fn = os.path.join(root, fn)
url = urlunparse(('file', '',
pathname2url(os.path.abspath(fn)),
'', '', ''))
info = self.convert_url_to_download_info(url, None)
if info:
result.add(info['name'])
if not self.recursive:
break
return result | [
"Return",
"all",
"the",
"distribution",
"names",
"known",
"to",
"this",
"locator",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/distlib/locators.py#L874-L891 | [
"def",
"get_distribution_names",
"(",
"self",
")",
":",
"result",
"=",
"set",
"(",
")",
"for",
"root",
",",
"dirs",
",",
"files",
"in",
"os",
".",
"walk",
"(",
"self",
".",
"base_dir",
")",
":",
"for",
"fn",
"in",
"files",
":",
"if",
"self",
".",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | AggregatingLocator.get_distribution_names | Return all the distribution names known to this locator. | pipenv/vendor/distlib/locators.py | def get_distribution_names(self):
"""
Return all the distribution names known to this locator.
"""
result = set()
for locator in self.locators:
try:
result |= locator.get_distribution_names()
except NotImplementedError:
pass
return result | def get_distribution_names(self):
"""
Return all the distribution names known to this locator.
"""
result = set()
for locator in self.locators:
try:
result |= locator.get_distribution_names()
except NotImplementedError:
pass
return result | [
"Return",
"all",
"the",
"distribution",
"names",
"known",
"to",
"this",
"locator",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/distlib/locators.py#L1035-L1045 | [
"def",
"get_distribution_names",
"(",
"self",
")",
":",
"result",
"=",
"set",
"(",
")",
"for",
"locator",
"in",
"self",
".",
"locators",
":",
"try",
":",
"result",
"|=",
"locator",
".",
"get_distribution_names",
"(",
")",
"except",
"NotImplementedError",
":"... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | DependencyFinder.add_distribution | Add a distribution to the finder. This will update internal information
about who provides what.
:param dist: The distribution to add. | pipenv/vendor/distlib/locators.py | def add_distribution(self, dist):
"""
Add a distribution to the finder. This will update internal information
about who provides what.
:param dist: The distribution to add.
"""
logger.debug('adding distribution %s', dist)
name = dist.key
self.dists_by_name[name] = dist
self.dists[(name, dist.version)] = dist
for p in dist.provides:
name, version = parse_name_and_version(p)
logger.debug('Add to provided: %s, %s, %s', name, version, dist)
self.provided.setdefault(name, set()).add((version, dist)) | def add_distribution(self, dist):
"""
Add a distribution to the finder. This will update internal information
about who provides what.
:param dist: The distribution to add.
"""
logger.debug('adding distribution %s', dist)
name = dist.key
self.dists_by_name[name] = dist
self.dists[(name, dist.version)] = dist
for p in dist.provides:
name, version = parse_name_and_version(p)
logger.debug('Add to provided: %s, %s, %s', name, version, dist)
self.provided.setdefault(name, set()).add((version, dist)) | [
"Add",
"a",
"distribution",
"to",
"the",
"finder",
".",
"This",
"will",
"update",
"internal",
"information",
"about",
"who",
"provides",
"what",
".",
":",
"param",
"dist",
":",
"The",
"distribution",
"to",
"add",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/distlib/locators.py#L1074-L1087 | [
"def",
"add_distribution",
"(",
"self",
",",
"dist",
")",
":",
"logger",
".",
"debug",
"(",
"'adding distribution %s'",
",",
"dist",
")",
"name",
"=",
"dist",
".",
"key",
"self",
".",
"dists_by_name",
"[",
"name",
"]",
"=",
"dist",
"self",
".",
"dists",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | DependencyFinder.remove_distribution | Remove a distribution from the finder. This will update internal
information about who provides what.
:param dist: The distribution to remove. | pipenv/vendor/distlib/locators.py | def remove_distribution(self, dist):
"""
Remove a distribution from the finder. This will update internal
information about who provides what.
:param dist: The distribution to remove.
"""
logger.debug('removing distribution %s', dist)
name = dist.key
del self.dists_by_name[name]
del self.dists[(name, dist.version)]
for p in dist.provides:
name, version = parse_name_and_version(p)
logger.debug('Remove from provided: %s, %s, %s', name, version, dist)
s = self.provided[name]
s.remove((version, dist))
if not s:
del self.provided[name] | def remove_distribution(self, dist):
"""
Remove a distribution from the finder. This will update internal
information about who provides what.
:param dist: The distribution to remove.
"""
logger.debug('removing distribution %s', dist)
name = dist.key
del self.dists_by_name[name]
del self.dists[(name, dist.version)]
for p in dist.provides:
name, version = parse_name_and_version(p)
logger.debug('Remove from provided: %s, %s, %s', name, version, dist)
s = self.provided[name]
s.remove((version, dist))
if not s:
del self.provided[name] | [
"Remove",
"a",
"distribution",
"from",
"the",
"finder",
".",
"This",
"will",
"update",
"internal",
"information",
"about",
"who",
"provides",
"what",
".",
":",
"param",
"dist",
":",
"The",
"distribution",
"to",
"remove",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/distlib/locators.py#L1089-L1105 | [
"def",
"remove_distribution",
"(",
"self",
",",
"dist",
")",
":",
"logger",
".",
"debug",
"(",
"'removing distribution %s'",
",",
"dist",
")",
"name",
"=",
"dist",
".",
"key",
"del",
"self",
".",
"dists_by_name",
"[",
"name",
"]",
"del",
"self",
".",
"di... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | DependencyFinder.get_matcher | Get a version matcher for a requirement.
:param reqt: The requirement
:type reqt: str
:return: A version matcher (an instance of
:class:`distlib.version.Matcher`). | pipenv/vendor/distlib/locators.py | def get_matcher(self, reqt):
"""
Get a version matcher for a requirement.
:param reqt: The requirement
:type reqt: str
:return: A version matcher (an instance of
:class:`distlib.version.Matcher`).
"""
try:
matcher = self.scheme.matcher(reqt)
except UnsupportedVersionError: # pragma: no cover
# XXX compat-mode if cannot read the version
name = reqt.split()[0]
matcher = self.scheme.matcher(name)
return matcher | def get_matcher(self, reqt):
"""
Get a version matcher for a requirement.
:param reqt: The requirement
:type reqt: str
:return: A version matcher (an instance of
:class:`distlib.version.Matcher`).
"""
try:
matcher = self.scheme.matcher(reqt)
except UnsupportedVersionError: # pragma: no cover
# XXX compat-mode if cannot read the version
name = reqt.split()[0]
matcher = self.scheme.matcher(name)
return matcher | [
"Get",
"a",
"version",
"matcher",
"for",
"a",
"requirement",
".",
":",
"param",
"reqt",
":",
"The",
"requirement",
":",
"type",
"reqt",
":",
"str",
":",
"return",
":",
"A",
"version",
"matcher",
"(",
"an",
"instance",
"of",
":",
"class",
":",
"distlib"... | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/distlib/locators.py#L1107-L1121 | [
"def",
"get_matcher",
"(",
"self",
",",
"reqt",
")",
":",
"try",
":",
"matcher",
"=",
"self",
".",
"scheme",
".",
"matcher",
"(",
"reqt",
")",
"except",
"UnsupportedVersionError",
":",
"# pragma: no cover",
"# XXX compat-mode if cannot read the version",
"name",
"... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | DependencyFinder.find_providers | Find the distributions which can fulfill a requirement.
:param reqt: The requirement.
:type reqt: str
:return: A set of distribution which can fulfill the requirement. | pipenv/vendor/distlib/locators.py | def find_providers(self, reqt):
"""
Find the distributions which can fulfill a requirement.
:param reqt: The requirement.
:type reqt: str
:return: A set of distribution which can fulfill the requirement.
"""
matcher = self.get_matcher(reqt)
name = matcher.key # case-insensitive
result = set()
provided = self.provided
if name in provided:
for version, provider in provided[name]:
try:
match = matcher.match(version)
except UnsupportedVersionError:
match = False
if match:
result.add(provider)
break
return result | def find_providers(self, reqt):
"""
Find the distributions which can fulfill a requirement.
:param reqt: The requirement.
:type reqt: str
:return: A set of distribution which can fulfill the requirement.
"""
matcher = self.get_matcher(reqt)
name = matcher.key # case-insensitive
result = set()
provided = self.provided
if name in provided:
for version, provider in provided[name]:
try:
match = matcher.match(version)
except UnsupportedVersionError:
match = False
if match:
result.add(provider)
break
return result | [
"Find",
"the",
"distributions",
"which",
"can",
"fulfill",
"a",
"requirement",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/distlib/locators.py#L1123-L1145 | [
"def",
"find_providers",
"(",
"self",
",",
"reqt",
")",
":",
"matcher",
"=",
"self",
".",
"get_matcher",
"(",
"reqt",
")",
"name",
"=",
"matcher",
".",
"key",
"# case-insensitive",
"result",
"=",
"set",
"(",
")",
"provided",
"=",
"self",
".",
"provided",... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | DependencyFinder.try_to_replace | Attempt to replace one provider with another. This is typically used
when resolving dependencies from multiple sources, e.g. A requires
(B >= 1.0) while C requires (B >= 1.1).
For successful replacement, ``provider`` must meet all the requirements
which ``other`` fulfills.
:param provider: The provider we are trying to replace with.
:param other: The provider we're trying to replace.
:param problems: If False is returned, this will contain what
problems prevented replacement. This is currently
a tuple of the literal string 'cantreplace',
``provider``, ``other`` and the set of requirements
that ``provider`` couldn't fulfill.
:return: True if we can replace ``other`` with ``provider``, else
False. | pipenv/vendor/distlib/locators.py | def try_to_replace(self, provider, other, problems):
"""
Attempt to replace one provider with another. This is typically used
when resolving dependencies from multiple sources, e.g. A requires
(B >= 1.0) while C requires (B >= 1.1).
For successful replacement, ``provider`` must meet all the requirements
which ``other`` fulfills.
:param provider: The provider we are trying to replace with.
:param other: The provider we're trying to replace.
:param problems: If False is returned, this will contain what
problems prevented replacement. This is currently
a tuple of the literal string 'cantreplace',
``provider``, ``other`` and the set of requirements
that ``provider`` couldn't fulfill.
:return: True if we can replace ``other`` with ``provider``, else
False.
"""
rlist = self.reqts[other]
unmatched = set()
for s in rlist:
matcher = self.get_matcher(s)
if not matcher.match(provider.version):
unmatched.add(s)
if unmatched:
# can't replace other with provider
problems.add(('cantreplace', provider, other,
frozenset(unmatched)))
result = False
else:
# can replace other with provider
self.remove_distribution(other)
del self.reqts[other]
for s in rlist:
self.reqts.setdefault(provider, set()).add(s)
self.add_distribution(provider)
result = True
return result | def try_to_replace(self, provider, other, problems):
"""
Attempt to replace one provider with another. This is typically used
when resolving dependencies from multiple sources, e.g. A requires
(B >= 1.0) while C requires (B >= 1.1).
For successful replacement, ``provider`` must meet all the requirements
which ``other`` fulfills.
:param provider: The provider we are trying to replace with.
:param other: The provider we're trying to replace.
:param problems: If False is returned, this will contain what
problems prevented replacement. This is currently
a tuple of the literal string 'cantreplace',
``provider``, ``other`` and the set of requirements
that ``provider`` couldn't fulfill.
:return: True if we can replace ``other`` with ``provider``, else
False.
"""
rlist = self.reqts[other]
unmatched = set()
for s in rlist:
matcher = self.get_matcher(s)
if not matcher.match(provider.version):
unmatched.add(s)
if unmatched:
# can't replace other with provider
problems.add(('cantreplace', provider, other,
frozenset(unmatched)))
result = False
else:
# can replace other with provider
self.remove_distribution(other)
del self.reqts[other]
for s in rlist:
self.reqts.setdefault(provider, set()).add(s)
self.add_distribution(provider)
result = True
return result | [
"Attempt",
"to",
"replace",
"one",
"provider",
"with",
"another",
".",
"This",
"is",
"typically",
"used",
"when",
"resolving",
"dependencies",
"from",
"multiple",
"sources",
"e",
".",
"g",
".",
"A",
"requires",
"(",
"B",
">",
"=",
"1",
".",
"0",
")",
"... | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/distlib/locators.py#L1147-L1185 | [
"def",
"try_to_replace",
"(",
"self",
",",
"provider",
",",
"other",
",",
"problems",
")",
":",
"rlist",
"=",
"self",
".",
"reqts",
"[",
"other",
"]",
"unmatched",
"=",
"set",
"(",
")",
"for",
"s",
"in",
"rlist",
":",
"matcher",
"=",
"self",
".",
"... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | DependencyFinder.find | Find a distribution and all distributions it depends on.
:param requirement: The requirement specifying the distribution to
find, or a Distribution instance.
:param meta_extras: A list of meta extras such as :test:, :build: and
so on.
:param prereleases: If ``True``, allow pre-release versions to be
returned - otherwise, don't return prereleases
unless they're all that's available.
Return a set of :class:`Distribution` instances and a set of
problems.
The distributions returned should be such that they have the
:attr:`required` attribute set to ``True`` if they were
from the ``requirement`` passed to ``find()``, and they have the
:attr:`build_time_dependency` attribute set to ``True`` unless they
are post-installation dependencies of the ``requirement``.
The problems should be a tuple consisting of the string
``'unsatisfied'`` and the requirement which couldn't be satisfied
by any distribution known to the locator. | pipenv/vendor/distlib/locators.py | def find(self, requirement, meta_extras=None, prereleases=False):
"""
Find a distribution and all distributions it depends on.
:param requirement: The requirement specifying the distribution to
find, or a Distribution instance.
:param meta_extras: A list of meta extras such as :test:, :build: and
so on.
:param prereleases: If ``True``, allow pre-release versions to be
returned - otherwise, don't return prereleases
unless they're all that's available.
Return a set of :class:`Distribution` instances and a set of
problems.
The distributions returned should be such that they have the
:attr:`required` attribute set to ``True`` if they were
from the ``requirement`` passed to ``find()``, and they have the
:attr:`build_time_dependency` attribute set to ``True`` unless they
are post-installation dependencies of the ``requirement``.
The problems should be a tuple consisting of the string
``'unsatisfied'`` and the requirement which couldn't be satisfied
by any distribution known to the locator.
"""
self.provided = {}
self.dists = {}
self.dists_by_name = {}
self.reqts = {}
meta_extras = set(meta_extras or [])
if ':*:' in meta_extras:
meta_extras.remove(':*:')
# :meta: and :run: are implicitly included
meta_extras |= set([':test:', ':build:', ':dev:'])
if isinstance(requirement, Distribution):
dist = odist = requirement
logger.debug('passed %s as requirement', odist)
else:
dist = odist = self.locator.locate(requirement,
prereleases=prereleases)
if dist is None:
raise DistlibException('Unable to locate %r' % requirement)
logger.debug('located %s', odist)
dist.requested = True
problems = set()
todo = set([dist])
install_dists = set([odist])
while todo:
dist = todo.pop()
name = dist.key # case-insensitive
if name not in self.dists_by_name:
self.add_distribution(dist)
else:
#import pdb; pdb.set_trace()
other = self.dists_by_name[name]
if other != dist:
self.try_to_replace(dist, other, problems)
ireqts = dist.run_requires | dist.meta_requires
sreqts = dist.build_requires
ereqts = set()
if meta_extras and dist in install_dists:
for key in ('test', 'build', 'dev'):
e = ':%s:' % key
if e in meta_extras:
ereqts |= getattr(dist, '%s_requires' % key)
all_reqts = ireqts | sreqts | ereqts
for r in all_reqts:
providers = self.find_providers(r)
if not providers:
logger.debug('No providers found for %r', r)
provider = self.locator.locate(r, prereleases=prereleases)
# If no provider is found and we didn't consider
# prereleases, consider them now.
if provider is None and not prereleases:
provider = self.locator.locate(r, prereleases=True)
if provider is None:
logger.debug('Cannot satisfy %r', r)
problems.add(('unsatisfied', r))
else:
n, v = provider.key, provider.version
if (n, v) not in self.dists:
todo.add(provider)
providers.add(provider)
if r in ireqts and dist in install_dists:
install_dists.add(provider)
logger.debug('Adding %s to install_dists',
provider.name_and_version)
for p in providers:
name = p.key
if name not in self.dists_by_name:
self.reqts.setdefault(p, set()).add(r)
else:
other = self.dists_by_name[name]
if other != p:
# see if other can be replaced by p
self.try_to_replace(p, other, problems)
dists = set(self.dists.values())
for dist in dists:
dist.build_time_dependency = dist not in install_dists
if dist.build_time_dependency:
logger.debug('%s is a build-time dependency only.',
dist.name_and_version)
logger.debug('find done for %s', odist)
return dists, problems | def find(self, requirement, meta_extras=None, prereleases=False):
"""
Find a distribution and all distributions it depends on.
:param requirement: The requirement specifying the distribution to
find, or a Distribution instance.
:param meta_extras: A list of meta extras such as :test:, :build: and
so on.
:param prereleases: If ``True``, allow pre-release versions to be
returned - otherwise, don't return prereleases
unless they're all that's available.
Return a set of :class:`Distribution` instances and a set of
problems.
The distributions returned should be such that they have the
:attr:`required` attribute set to ``True`` if they were
from the ``requirement`` passed to ``find()``, and they have the
:attr:`build_time_dependency` attribute set to ``True`` unless they
are post-installation dependencies of the ``requirement``.
The problems should be a tuple consisting of the string
``'unsatisfied'`` and the requirement which couldn't be satisfied
by any distribution known to the locator.
"""
self.provided = {}
self.dists = {}
self.dists_by_name = {}
self.reqts = {}
meta_extras = set(meta_extras or [])
if ':*:' in meta_extras:
meta_extras.remove(':*:')
# :meta: and :run: are implicitly included
meta_extras |= set([':test:', ':build:', ':dev:'])
if isinstance(requirement, Distribution):
dist = odist = requirement
logger.debug('passed %s as requirement', odist)
else:
dist = odist = self.locator.locate(requirement,
prereleases=prereleases)
if dist is None:
raise DistlibException('Unable to locate %r' % requirement)
logger.debug('located %s', odist)
dist.requested = True
problems = set()
todo = set([dist])
install_dists = set([odist])
while todo:
dist = todo.pop()
name = dist.key # case-insensitive
if name not in self.dists_by_name:
self.add_distribution(dist)
else:
#import pdb; pdb.set_trace()
other = self.dists_by_name[name]
if other != dist:
self.try_to_replace(dist, other, problems)
ireqts = dist.run_requires | dist.meta_requires
sreqts = dist.build_requires
ereqts = set()
if meta_extras and dist in install_dists:
for key in ('test', 'build', 'dev'):
e = ':%s:' % key
if e in meta_extras:
ereqts |= getattr(dist, '%s_requires' % key)
all_reqts = ireqts | sreqts | ereqts
for r in all_reqts:
providers = self.find_providers(r)
if not providers:
logger.debug('No providers found for %r', r)
provider = self.locator.locate(r, prereleases=prereleases)
# If no provider is found and we didn't consider
# prereleases, consider them now.
if provider is None and not prereleases:
provider = self.locator.locate(r, prereleases=True)
if provider is None:
logger.debug('Cannot satisfy %r', r)
problems.add(('unsatisfied', r))
else:
n, v = provider.key, provider.version
if (n, v) not in self.dists:
todo.add(provider)
providers.add(provider)
if r in ireqts and dist in install_dists:
install_dists.add(provider)
logger.debug('Adding %s to install_dists',
provider.name_and_version)
for p in providers:
name = p.key
if name not in self.dists_by_name:
self.reqts.setdefault(p, set()).add(r)
else:
other = self.dists_by_name[name]
if other != p:
# see if other can be replaced by p
self.try_to_replace(p, other, problems)
dists = set(self.dists.values())
for dist in dists:
dist.build_time_dependency = dist not in install_dists
if dist.build_time_dependency:
logger.debug('%s is a build-time dependency only.',
dist.name_and_version)
logger.debug('find done for %s', odist)
return dists, problems | [
"Find",
"a",
"distribution",
"and",
"all",
"distributions",
"it",
"depends",
"on",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/distlib/locators.py#L1187-L1295 | [
"def",
"find",
"(",
"self",
",",
"requirement",
",",
"meta_extras",
"=",
"None",
",",
"prereleases",
"=",
"False",
")",
":",
"self",
".",
"provided",
"=",
"{",
"}",
"self",
".",
"dists",
"=",
"{",
"}",
"self",
".",
"dists_by_name",
"=",
"{",
"}",
"... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | PopenSpawn._read_incoming | Run in a thread to move output from a pipe to a queue. | pipenv/vendor/pexpect/popen_spawn.py | def _read_incoming(self):
"""Run in a thread to move output from a pipe to a queue."""
fileno = self.proc.stdout.fileno()
while 1:
buf = b''
try:
buf = os.read(fileno, 1024)
except OSError as e:
self._log(e, 'read')
if not buf:
# This indicates we have reached EOF
self._read_queue.put(None)
return
self._read_queue.put(buf) | def _read_incoming(self):
"""Run in a thread to move output from a pipe to a queue."""
fileno = self.proc.stdout.fileno()
while 1:
buf = b''
try:
buf = os.read(fileno, 1024)
except OSError as e:
self._log(e, 'read')
if not buf:
# This indicates we have reached EOF
self._read_queue.put(None)
return
self._read_queue.put(buf) | [
"Run",
"in",
"a",
"thread",
"to",
"move",
"output",
"from",
"a",
"pipe",
"to",
"a",
"queue",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pexpect/popen_spawn.py#L100-L115 | [
"def",
"_read_incoming",
"(",
"self",
")",
":",
"fileno",
"=",
"self",
".",
"proc",
".",
"stdout",
".",
"fileno",
"(",
")",
"while",
"1",
":",
"buf",
"=",
"b''",
"try",
":",
"buf",
"=",
"os",
".",
"read",
"(",
"fileno",
",",
"1024",
")",
"except"... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | PopenSpawn.send | Send data to the subprocess' stdin.
Returns the number of bytes written. | pipenv/vendor/pexpect/popen_spawn.py | def send(self, s):
'''Send data to the subprocess' stdin.
Returns the number of bytes written.
'''
s = self._coerce_send_string(s)
self._log(s, 'send')
b = self._encoder.encode(s, final=False)
if PY3:
return self.proc.stdin.write(b)
else:
# On Python 2, .write() returns None, so we return the length of
# bytes written ourselves. This assumes they all got written.
self.proc.stdin.write(b)
return len(b) | def send(self, s):
'''Send data to the subprocess' stdin.
Returns the number of bytes written.
'''
s = self._coerce_send_string(s)
self._log(s, 'send')
b = self._encoder.encode(s, final=False)
if PY3:
return self.proc.stdin.write(b)
else:
# On Python 2, .write() returns None, so we return the length of
# bytes written ourselves. This assumes they all got written.
self.proc.stdin.write(b)
return len(b) | [
"Send",
"data",
"to",
"the",
"subprocess",
"stdin",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pexpect/popen_spawn.py#L132-L147 | [
"def",
"send",
"(",
"self",
",",
"s",
")",
":",
"s",
"=",
"self",
".",
"_coerce_send_string",
"(",
"s",
")",
"self",
".",
"_log",
"(",
"s",
",",
"'send'",
")",
"b",
"=",
"self",
".",
"_encoder",
".",
"encode",
"(",
"s",
",",
"final",
"=",
"Fals... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | PopenSpawn.sendline | Wraps send(), sending string ``s`` to child process, with os.linesep
automatically appended. Returns number of bytes written. | pipenv/vendor/pexpect/popen_spawn.py | def sendline(self, s=''):
'''Wraps send(), sending string ``s`` to child process, with os.linesep
automatically appended. Returns number of bytes written. '''
n = self.send(s)
return n + self.send(self.linesep) | def sendline(self, s=''):
'''Wraps send(), sending string ``s`` to child process, with os.linesep
automatically appended. Returns number of bytes written. '''
n = self.send(s)
return n + self.send(self.linesep) | [
"Wraps",
"send",
"()",
"sending",
"string",
"s",
"to",
"child",
"process",
"with",
"os",
".",
"linesep",
"automatically",
"appended",
".",
"Returns",
"number",
"of",
"bytes",
"written",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pexpect/popen_spawn.py#L149-L154 | [
"def",
"sendline",
"(",
"self",
",",
"s",
"=",
"''",
")",
":",
"n",
"=",
"self",
".",
"send",
"(",
"s",
")",
"return",
"n",
"+",
"self",
".",
"send",
"(",
"self",
".",
"linesep",
")"
] | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | PopenSpawn.wait | Wait for the subprocess to finish.
Returns the exit code. | pipenv/vendor/pexpect/popen_spawn.py | def wait(self):
'''Wait for the subprocess to finish.
Returns the exit code.
'''
status = self.proc.wait()
if status >= 0:
self.exitstatus = status
self.signalstatus = None
else:
self.exitstatus = None
self.signalstatus = -status
self.terminated = True
return status | def wait(self):
'''Wait for the subprocess to finish.
Returns the exit code.
'''
status = self.proc.wait()
if status >= 0:
self.exitstatus = status
self.signalstatus = None
else:
self.exitstatus = None
self.signalstatus = -status
self.terminated = True
return status | [
"Wait",
"for",
"the",
"subprocess",
"to",
"finish",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pexpect/popen_spawn.py#L156-L169 | [
"def",
"wait",
"(",
"self",
")",
":",
"status",
"=",
"self",
".",
"proc",
".",
"wait",
"(",
")",
"if",
"status",
">=",
"0",
":",
"self",
".",
"exitstatus",
"=",
"status",
"self",
".",
"signalstatus",
"=",
"None",
"else",
":",
"self",
".",
"exitstat... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | PopenSpawn.kill | Sends a Unix signal to the subprocess.
Use constants from the :mod:`signal` module to specify which signal. | pipenv/vendor/pexpect/popen_spawn.py | def kill(self, sig):
'''Sends a Unix signal to the subprocess.
Use constants from the :mod:`signal` module to specify which signal.
'''
if sys.platform == 'win32':
if sig in [signal.SIGINT, signal.CTRL_C_EVENT]:
sig = signal.CTRL_C_EVENT
elif sig in [signal.SIGBREAK, signal.CTRL_BREAK_EVENT]:
sig = signal.CTRL_BREAK_EVENT
else:
sig = signal.SIGTERM
os.kill(self.proc.pid, sig) | def kill(self, sig):
'''Sends a Unix signal to the subprocess.
Use constants from the :mod:`signal` module to specify which signal.
'''
if sys.platform == 'win32':
if sig in [signal.SIGINT, signal.CTRL_C_EVENT]:
sig = signal.CTRL_C_EVENT
elif sig in [signal.SIGBREAK, signal.CTRL_BREAK_EVENT]:
sig = signal.CTRL_BREAK_EVENT
else:
sig = signal.SIGTERM
os.kill(self.proc.pid, sig) | [
"Sends",
"a",
"Unix",
"signal",
"to",
"the",
"subprocess",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pexpect/popen_spawn.py#L171-L184 | [
"def",
"kill",
"(",
"self",
",",
"sig",
")",
":",
"if",
"sys",
".",
"platform",
"==",
"'win32'",
":",
"if",
"sig",
"in",
"[",
"signal",
".",
"SIGINT",
",",
"signal",
".",
"CTRL_C_EVENT",
"]",
":",
"sig",
"=",
"signal",
".",
"CTRL_C_EVENT",
"elif",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | mkdir_p | Like `mkdir`, but does not raise an exception if the
directory already exists. | pipenv/vendor/pep517/build.py | def mkdir_p(*args, **kwargs):
"""Like `mkdir`, but does not raise an exception if the
directory already exists.
"""
try:
return os.mkdir(*args, **kwargs)
except OSError as exc:
if exc.errno != errno.EEXIST:
raise | def mkdir_p(*args, **kwargs):
"""Like `mkdir`, but does not raise an exception if the
directory already exists.
"""
try:
return os.mkdir(*args, **kwargs)
except OSError as exc:
if exc.errno != errno.EEXIST:
raise | [
"Like",
"mkdir",
"but",
"does",
"not",
"raise",
"an",
"exception",
"if",
"the",
"directory",
"already",
"exists",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pep517/build.py#L45-L53 | [
"def",
"mkdir_p",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"return",
"os",
".",
"mkdir",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"except",
"OSError",
"as",
"exc",
":",
"if",
"exc",
".",
"errno",
"!=",
"errno",
".... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | with_pattern | Attach a regular expression pattern matcher to a custom type converter
function.
This annotates the type converter with the :attr:`pattern` attribute.
EXAMPLE:
>>> import parse
>>> @parse.with_pattern(r"\d+")
... def parse_number(text):
... return int(text)
is equivalent to:
>>> def parse_number(text):
... return int(text)
>>> parse_number.pattern = r"\d+"
:param pattern: regular expression pattern (as text)
:param regex_group_count: Indicates how many regex-groups are in pattern.
:return: wrapped function | pipenv/vendor/parse.py | def with_pattern(pattern, regex_group_count=None):
"""Attach a regular expression pattern matcher to a custom type converter
function.
This annotates the type converter with the :attr:`pattern` attribute.
EXAMPLE:
>>> import parse
>>> @parse.with_pattern(r"\d+")
... def parse_number(text):
... return int(text)
is equivalent to:
>>> def parse_number(text):
... return int(text)
>>> parse_number.pattern = r"\d+"
:param pattern: regular expression pattern (as text)
:param regex_group_count: Indicates how many regex-groups are in pattern.
:return: wrapped function
"""
def decorator(func):
func.pattern = pattern
func.regex_group_count = regex_group_count
return func
return decorator | def with_pattern(pattern, regex_group_count=None):
"""Attach a regular expression pattern matcher to a custom type converter
function.
This annotates the type converter with the :attr:`pattern` attribute.
EXAMPLE:
>>> import parse
>>> @parse.with_pattern(r"\d+")
... def parse_number(text):
... return int(text)
is equivalent to:
>>> def parse_number(text):
... return int(text)
>>> parse_number.pattern = r"\d+"
:param pattern: regular expression pattern (as text)
:param regex_group_count: Indicates how many regex-groups are in pattern.
:return: wrapped function
"""
def decorator(func):
func.pattern = pattern
func.regex_group_count = regex_group_count
return func
return decorator | [
"Attach",
"a",
"regular",
"expression",
"pattern",
"matcher",
"to",
"a",
"custom",
"type",
"converter",
"function",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/parse.py#L433-L459 | [
"def",
"with_pattern",
"(",
"pattern",
",",
"regex_group_count",
"=",
"None",
")",
":",
"def",
"decorator",
"(",
"func",
")",
":",
"func",
".",
"pattern",
"=",
"pattern",
"func",
".",
"regex_group_count",
"=",
"regex_group_count",
"return",
"func",
"return",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | int_convert | Convert a string to an integer.
The string may start with a sign.
It may be of a base other than 10.
If may start with a base indicator, 0#nnnn, which we assume should
override the specified base.
It may also have other non-numeric characters that we can ignore. | pipenv/vendor/parse.py | def int_convert(base):
'''Convert a string to an integer.
The string may start with a sign.
It may be of a base other than 10.
If may start with a base indicator, 0#nnnn, which we assume should
override the specified base.
It may also have other non-numeric characters that we can ignore.
'''
CHARS = '0123456789abcdefghijklmnopqrstuvwxyz'
def f(string, match, base=base):
if string[0] == '-':
sign = -1
else:
sign = 1
if string[0] == '0' and len(string) > 2:
if string[1] in 'bB':
base = 2
elif string[1] in 'oO':
base = 8
elif string[1] in 'xX':
base = 16
else:
# just go with the base specifed
pass
chars = CHARS[:base]
string = re.sub('[^%s]' % chars, '', string.lower())
return sign * int(string, base)
return f | def int_convert(base):
'''Convert a string to an integer.
The string may start with a sign.
It may be of a base other than 10.
If may start with a base indicator, 0#nnnn, which we assume should
override the specified base.
It may also have other non-numeric characters that we can ignore.
'''
CHARS = '0123456789abcdefghijklmnopqrstuvwxyz'
def f(string, match, base=base):
if string[0] == '-':
sign = -1
else:
sign = 1
if string[0] == '0' and len(string) > 2:
if string[1] in 'bB':
base = 2
elif string[1] in 'oO':
base = 8
elif string[1] in 'xX':
base = 16
else:
# just go with the base specifed
pass
chars = CHARS[:base]
string = re.sub('[^%s]' % chars, '', string.lower())
return sign * int(string, base)
return f | [
"Convert",
"a",
"string",
"to",
"an",
"integer",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/parse.py#L462-L496 | [
"def",
"int_convert",
"(",
"base",
")",
":",
"CHARS",
"=",
"'0123456789abcdefghijklmnopqrstuvwxyz'",
"def",
"f",
"(",
"string",
",",
"match",
",",
"base",
"=",
"base",
")",
":",
"if",
"string",
"[",
"0",
"]",
"==",
"'-'",
":",
"sign",
"=",
"-",
"1",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | date_convert | Convert the incoming string containing some date / time info into a
datetime instance. | pipenv/vendor/parse.py | def date_convert(string, match, ymd=None, mdy=None, dmy=None,
d_m_y=None, hms=None, am=None, tz=None, mm=None, dd=None):
'''Convert the incoming string containing some date / time info into a
datetime instance.
'''
groups = match.groups()
time_only = False
if mm and dd:
y=datetime.today().year
m=groups[mm]
d=groups[dd]
elif ymd is not None:
y, m, d = re.split(r'[-/\s]', groups[ymd])
elif mdy is not None:
m, d, y = re.split(r'[-/\s]', groups[mdy])
elif dmy is not None:
d, m, y = re.split(r'[-/\s]', groups[dmy])
elif d_m_y is not None:
d, m, y = d_m_y
d = groups[d]
m = groups[m]
y = groups[y]
else:
time_only = True
H = M = S = u = 0
if hms is not None and groups[hms]:
t = groups[hms].split(':')
if len(t) == 2:
H, M = t
else:
H, M, S = t
if '.' in S:
S, u = S.split('.')
u = int(float('.' + u) * 1000000)
S = int(S)
H = int(H)
M = int(M)
if am is not None:
am = groups[am]
if am:
am = am.strip()
if am == 'AM' and H == 12:
# correction for "12" hour functioning as "0" hour: 12:15 AM = 00:15 by 24 hr clock
H -= 12
elif am == 'PM' and H == 12:
# no correction needed: 12PM is midday, 12:00 by 24 hour clock
pass
elif am == 'PM':
H += 12
if tz is not None:
tz = groups[tz]
if tz == 'Z':
tz = FixedTzOffset(0, 'UTC')
elif tz:
tz = tz.strip()
if tz.isupper():
# TODO use the awesome python TZ module?
pass
else:
sign = tz[0]
if ':' in tz:
tzh, tzm = tz[1:].split(':')
elif len(tz) == 4: # 'snnn'
tzh, tzm = tz[1], tz[2:4]
else:
tzh, tzm = tz[1:3], tz[3:5]
offset = int(tzm) + int(tzh) * 60
if sign == '-':
offset = -offset
tz = FixedTzOffset(offset, tz)
if time_only:
d = time(H, M, S, u, tzinfo=tz)
else:
y = int(y)
if m.isdigit():
m = int(m)
else:
m = MONTHS_MAP[m]
d = int(d)
d = datetime(y, m, d, H, M, S, u, tzinfo=tz)
return d | def date_convert(string, match, ymd=None, mdy=None, dmy=None,
d_m_y=None, hms=None, am=None, tz=None, mm=None, dd=None):
'''Convert the incoming string containing some date / time info into a
datetime instance.
'''
groups = match.groups()
time_only = False
if mm and dd:
y=datetime.today().year
m=groups[mm]
d=groups[dd]
elif ymd is not None:
y, m, d = re.split(r'[-/\s]', groups[ymd])
elif mdy is not None:
m, d, y = re.split(r'[-/\s]', groups[mdy])
elif dmy is not None:
d, m, y = re.split(r'[-/\s]', groups[dmy])
elif d_m_y is not None:
d, m, y = d_m_y
d = groups[d]
m = groups[m]
y = groups[y]
else:
time_only = True
H = M = S = u = 0
if hms is not None and groups[hms]:
t = groups[hms].split(':')
if len(t) == 2:
H, M = t
else:
H, M, S = t
if '.' in S:
S, u = S.split('.')
u = int(float('.' + u) * 1000000)
S = int(S)
H = int(H)
M = int(M)
if am is not None:
am = groups[am]
if am:
am = am.strip()
if am == 'AM' and H == 12:
# correction for "12" hour functioning as "0" hour: 12:15 AM = 00:15 by 24 hr clock
H -= 12
elif am == 'PM' and H == 12:
# no correction needed: 12PM is midday, 12:00 by 24 hour clock
pass
elif am == 'PM':
H += 12
if tz is not None:
tz = groups[tz]
if tz == 'Z':
tz = FixedTzOffset(0, 'UTC')
elif tz:
tz = tz.strip()
if tz.isupper():
# TODO use the awesome python TZ module?
pass
else:
sign = tz[0]
if ':' in tz:
tzh, tzm = tz[1:].split(':')
elif len(tz) == 4: # 'snnn'
tzh, tzm = tz[1], tz[2:4]
else:
tzh, tzm = tz[1:3], tz[3:5]
offset = int(tzm) + int(tzh) * 60
if sign == '-':
offset = -offset
tz = FixedTzOffset(offset, tz)
if time_only:
d = time(H, M, S, u, tzinfo=tz)
else:
y = int(y)
if m.isdigit():
m = int(m)
else:
m = MONTHS_MAP[m]
d = int(d)
d = datetime(y, m, d, H, M, S, u, tzinfo=tz)
return d | [
"Convert",
"the",
"incoming",
"string",
"containing",
"some",
"date",
"/",
"time",
"info",
"into",
"a",
"datetime",
"instance",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/parse.py#L551-L636 | [
"def",
"date_convert",
"(",
"string",
",",
"match",
",",
"ymd",
"=",
"None",
",",
"mdy",
"=",
"None",
",",
"dmy",
"=",
"None",
",",
"d_m_y",
"=",
"None",
",",
"hms",
"=",
"None",
",",
"am",
"=",
"None",
",",
"tz",
"=",
"None",
",",
"mm",
"=",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | extract_format | Pull apart the format [[fill]align][0][width][.precision][type] | pipenv/vendor/parse.py | def extract_format(format, extra_types):
'''Pull apart the format [[fill]align][0][width][.precision][type]
'''
fill = align = None
if format[0] in '<>=^':
align = format[0]
format = format[1:]
elif len(format) > 1 and format[1] in '<>=^':
fill = format[0]
align = format[1]
format = format[2:]
zero = False
if format and format[0] == '0':
zero = True
format = format[1:]
width = ''
while format:
if not format[0].isdigit():
break
width += format[0]
format = format[1:]
if format.startswith('.'):
# Precision isn't needed but we need to capture it so that
# the ValueError isn't raised.
format = format[1:] # drop the '.'
precision = ''
while format:
if not format[0].isdigit():
break
precision += format[0]
format = format[1:]
# the rest is the type, if present
type = format
if type and type not in ALLOWED_TYPES and type not in extra_types:
raise ValueError('format spec %r not recognised' % type)
return locals() | def extract_format(format, extra_types):
'''Pull apart the format [[fill]align][0][width][.precision][type]
'''
fill = align = None
if format[0] in '<>=^':
align = format[0]
format = format[1:]
elif len(format) > 1 and format[1] in '<>=^':
fill = format[0]
align = format[1]
format = format[2:]
zero = False
if format and format[0] == '0':
zero = True
format = format[1:]
width = ''
while format:
if not format[0].isdigit():
break
width += format[0]
format = format[1:]
if format.startswith('.'):
# Precision isn't needed but we need to capture it so that
# the ValueError isn't raised.
format = format[1:] # drop the '.'
precision = ''
while format:
if not format[0].isdigit():
break
precision += format[0]
format = format[1:]
# the rest is the type, if present
type = format
if type and type not in ALLOWED_TYPES and type not in extra_types:
raise ValueError('format spec %r not recognised' % type)
return locals() | [
"Pull",
"apart",
"the",
"format",
"[[",
"fill",
"]",
"align",
"]",
"[",
"0",
"]",
"[",
"width",
"]",
"[",
".",
"precision",
"]",
"[",
"type",
"]"
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/parse.py#L656-L696 | [
"def",
"extract_format",
"(",
"format",
",",
"extra_types",
")",
":",
"fill",
"=",
"align",
"=",
"None",
"if",
"format",
"[",
"0",
"]",
"in",
"'<>=^'",
":",
"align",
"=",
"format",
"[",
"0",
"]",
"format",
"=",
"format",
"[",
"1",
":",
"]",
"elif",... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | parse | Using "format" attempt to pull values from "string".
The format must match the string contents exactly. If the value
you're looking for is instead just a part of the string use
search().
If ``evaluate_result`` is True the return value will be an Result instance with two attributes:
.fixed - tuple of fixed-position values from the string
.named - dict of named values from the string
If ``evaluate_result`` is False the return value will be a Match instance with one method:
.evaluate_result() - This will return a Result instance like you would get
with ``evaluate_result`` set to True
The default behaviour is to match strings case insensitively. You may match with
case by specifying case_sensitive=True.
If the format is invalid a ValueError will be raised.
See the module documentation for the use of "extra_types".
In the case there is no match parse() will return None. | pipenv/vendor/parse.py | def parse(format, string, extra_types=None, evaluate_result=True, case_sensitive=False):
'''Using "format" attempt to pull values from "string".
The format must match the string contents exactly. If the value
you're looking for is instead just a part of the string use
search().
If ``evaluate_result`` is True the return value will be an Result instance with two attributes:
.fixed - tuple of fixed-position values from the string
.named - dict of named values from the string
If ``evaluate_result`` is False the return value will be a Match instance with one method:
.evaluate_result() - This will return a Result instance like you would get
with ``evaluate_result`` set to True
The default behaviour is to match strings case insensitively. You may match with
case by specifying case_sensitive=True.
If the format is invalid a ValueError will be raised.
See the module documentation for the use of "extra_types".
In the case there is no match parse() will return None.
'''
p = Parser(format, extra_types=extra_types, case_sensitive=case_sensitive)
return p.parse(string, evaluate_result=evaluate_result) | def parse(format, string, extra_types=None, evaluate_result=True, case_sensitive=False):
'''Using "format" attempt to pull values from "string".
The format must match the string contents exactly. If the value
you're looking for is instead just a part of the string use
search().
If ``evaluate_result`` is True the return value will be an Result instance with two attributes:
.fixed - tuple of fixed-position values from the string
.named - dict of named values from the string
If ``evaluate_result`` is False the return value will be a Match instance with one method:
.evaluate_result() - This will return a Result instance like you would get
with ``evaluate_result`` set to True
The default behaviour is to match strings case insensitively. You may match with
case by specifying case_sensitive=True.
If the format is invalid a ValueError will be raised.
See the module documentation for the use of "extra_types".
In the case there is no match parse() will return None.
'''
p = Parser(format, extra_types=extra_types, case_sensitive=case_sensitive)
return p.parse(string, evaluate_result=evaluate_result) | [
"Using",
"format",
"attempt",
"to",
"pull",
"values",
"from",
"string",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/parse.py#L1201-L1228 | [
"def",
"parse",
"(",
"format",
",",
"string",
",",
"extra_types",
"=",
"None",
",",
"evaluate_result",
"=",
"True",
",",
"case_sensitive",
"=",
"False",
")",
":",
"p",
"=",
"Parser",
"(",
"format",
",",
"extra_types",
"=",
"extra_types",
",",
"case_sensiti... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | search | Search "string" for the first occurrence of "format".
The format may occur anywhere within the string. If
instead you wish for the format to exactly match the string
use parse().
Optionally start the search at "pos" character index and limit the search
to a maximum index of endpos - equivalent to search(string[:endpos]).
If ``evaluate_result`` is True the return value will be an Result instance with two attributes:
.fixed - tuple of fixed-position values from the string
.named - dict of named values from the string
If ``evaluate_result`` is False the return value will be a Match instance with one method:
.evaluate_result() - This will return a Result instance like you would get
with ``evaluate_result`` set to True
The default behaviour is to match strings case insensitively. You may match with
case by specifying case_sensitive=True.
If the format is invalid a ValueError will be raised.
See the module documentation for the use of "extra_types".
In the case there is no match parse() will return None. | pipenv/vendor/parse.py | def search(format, string, pos=0, endpos=None, extra_types=None, evaluate_result=True,
case_sensitive=False):
'''Search "string" for the first occurrence of "format".
The format may occur anywhere within the string. If
instead you wish for the format to exactly match the string
use parse().
Optionally start the search at "pos" character index and limit the search
to a maximum index of endpos - equivalent to search(string[:endpos]).
If ``evaluate_result`` is True the return value will be an Result instance with two attributes:
.fixed - tuple of fixed-position values from the string
.named - dict of named values from the string
If ``evaluate_result`` is False the return value will be a Match instance with one method:
.evaluate_result() - This will return a Result instance like you would get
with ``evaluate_result`` set to True
The default behaviour is to match strings case insensitively. You may match with
case by specifying case_sensitive=True.
If the format is invalid a ValueError will be raised.
See the module documentation for the use of "extra_types".
In the case there is no match parse() will return None.
'''
p = Parser(format, extra_types=extra_types, case_sensitive=case_sensitive)
return p.search(string, pos, endpos, evaluate_result=evaluate_result) | def search(format, string, pos=0, endpos=None, extra_types=None, evaluate_result=True,
case_sensitive=False):
'''Search "string" for the first occurrence of "format".
The format may occur anywhere within the string. If
instead you wish for the format to exactly match the string
use parse().
Optionally start the search at "pos" character index and limit the search
to a maximum index of endpos - equivalent to search(string[:endpos]).
If ``evaluate_result`` is True the return value will be an Result instance with two attributes:
.fixed - tuple of fixed-position values from the string
.named - dict of named values from the string
If ``evaluate_result`` is False the return value will be a Match instance with one method:
.evaluate_result() - This will return a Result instance like you would get
with ``evaluate_result`` set to True
The default behaviour is to match strings case insensitively. You may match with
case by specifying case_sensitive=True.
If the format is invalid a ValueError will be raised.
See the module documentation for the use of "extra_types".
In the case there is no match parse() will return None.
'''
p = Parser(format, extra_types=extra_types, case_sensitive=case_sensitive)
return p.search(string, pos, endpos, evaluate_result=evaluate_result) | [
"Search",
"string",
"for",
"the",
"first",
"occurrence",
"of",
"format",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/parse.py#L1231-L1262 | [
"def",
"search",
"(",
"format",
",",
"string",
",",
"pos",
"=",
"0",
",",
"endpos",
"=",
"None",
",",
"extra_types",
"=",
"None",
",",
"evaluate_result",
"=",
"True",
",",
"case_sensitive",
"=",
"False",
")",
":",
"p",
"=",
"Parser",
"(",
"format",
"... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Parser.parse | Match my format to the string exactly.
Return a Result or Match instance or None if there's no match. | pipenv/vendor/parse.py | def parse(self, string, evaluate_result=True):
'''Match my format to the string exactly.
Return a Result or Match instance or None if there's no match.
'''
m = self._match_re.match(string)
if m is None:
return None
if evaluate_result:
return self.evaluate_result(m)
else:
return Match(self, m) | def parse(self, string, evaluate_result=True):
'''Match my format to the string exactly.
Return a Result or Match instance or None if there's no match.
'''
m = self._match_re.match(string)
if m is None:
return None
if evaluate_result:
return self.evaluate_result(m)
else:
return Match(self, m) | [
"Match",
"my",
"format",
"to",
"the",
"string",
"exactly",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/parse.py#L773-L785 | [
"def",
"parse",
"(",
"self",
",",
"string",
",",
"evaluate_result",
"=",
"True",
")",
":",
"m",
"=",
"self",
".",
"_match_re",
".",
"match",
"(",
"string",
")",
"if",
"m",
"is",
"None",
":",
"return",
"None",
"if",
"evaluate_result",
":",
"return",
"... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Parser.search | Search the string for my format.
Optionally start the search at "pos" character index and limit the
search to a maximum index of endpos - equivalent to
search(string[:endpos]).
If the ``evaluate_result`` argument is set to ``False`` a
Match instance is returned instead of the actual Result instance.
Return either a Result instance or None if there's no match. | pipenv/vendor/parse.py | def search(self, string, pos=0, endpos=None, evaluate_result=True):
'''Search the string for my format.
Optionally start the search at "pos" character index and limit the
search to a maximum index of endpos - equivalent to
search(string[:endpos]).
If the ``evaluate_result`` argument is set to ``False`` a
Match instance is returned instead of the actual Result instance.
Return either a Result instance or None if there's no match.
'''
if endpos is None:
endpos = len(string)
m = self._search_re.search(string, pos, endpos)
if m is None:
return None
if evaluate_result:
return self.evaluate_result(m)
else:
return Match(self, m) | def search(self, string, pos=0, endpos=None, evaluate_result=True):
'''Search the string for my format.
Optionally start the search at "pos" character index and limit the
search to a maximum index of endpos - equivalent to
search(string[:endpos]).
If the ``evaluate_result`` argument is set to ``False`` a
Match instance is returned instead of the actual Result instance.
Return either a Result instance or None if there's no match.
'''
if endpos is None:
endpos = len(string)
m = self._search_re.search(string, pos, endpos)
if m is None:
return None
if evaluate_result:
return self.evaluate_result(m)
else:
return Match(self, m) | [
"Search",
"the",
"string",
"for",
"my",
"format",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/parse.py#L787-L808 | [
"def",
"search",
"(",
"self",
",",
"string",
",",
"pos",
"=",
"0",
",",
"endpos",
"=",
"None",
",",
"evaluate_result",
"=",
"True",
")",
":",
"if",
"endpos",
"is",
"None",
":",
"endpos",
"=",
"len",
"(",
"string",
")",
"m",
"=",
"self",
".",
"_se... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Parser.findall | Search "string" for all occurrences of "format".
Optionally start the search at "pos" character index and limit the
search to a maximum index of endpos - equivalent to
search(string[:endpos]).
Returns an iterator that holds Result or Match instances for each format match
found. | pipenv/vendor/parse.py | def findall(self, string, pos=0, endpos=None, extra_types=None, evaluate_result=True):
'''Search "string" for all occurrences of "format".
Optionally start the search at "pos" character index and limit the
search to a maximum index of endpos - equivalent to
search(string[:endpos]).
Returns an iterator that holds Result or Match instances for each format match
found.
'''
if endpos is None:
endpos = len(string)
return ResultIterator(self, string, pos, endpos, evaluate_result=evaluate_result) | def findall(self, string, pos=0, endpos=None, extra_types=None, evaluate_result=True):
'''Search "string" for all occurrences of "format".
Optionally start the search at "pos" character index and limit the
search to a maximum index of endpos - equivalent to
search(string[:endpos]).
Returns an iterator that holds Result or Match instances for each format match
found.
'''
if endpos is None:
endpos = len(string)
return ResultIterator(self, string, pos, endpos, evaluate_result=evaluate_result) | [
"Search",
"string",
"for",
"all",
"occurrences",
"of",
"format",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/parse.py#L810-L822 | [
"def",
"findall",
"(",
"self",
",",
"string",
",",
"pos",
"=",
"0",
",",
"endpos",
"=",
"None",
",",
"extra_types",
"=",
"None",
",",
"evaluate_result",
"=",
"True",
")",
":",
"if",
"endpos",
"is",
"None",
":",
"endpos",
"=",
"len",
"(",
"string",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Parser.evaluate_result | Generate a Result instance for the given regex match object | pipenv/vendor/parse.py | def evaluate_result(self, m):
'''Generate a Result instance for the given regex match object'''
# ok, figure the fixed fields we've pulled out and type convert them
fixed_fields = list(m.groups())
for n in self._fixed_fields:
if n in self._type_conversions:
fixed_fields[n] = self._type_conversions[n](fixed_fields[n], m)
fixed_fields = tuple(fixed_fields[n] for n in self._fixed_fields)
# grab the named fields, converting where requested
groupdict = m.groupdict()
named_fields = {}
name_map = {}
for k in self._named_fields:
korig = self._group_to_name_map[k]
name_map[korig] = k
if k in self._type_conversions:
value = self._type_conversions[k](groupdict[k], m)
else:
value = groupdict[k]
named_fields[korig] = value
# now figure the match spans
spans = dict((n, m.span(name_map[n])) for n in named_fields)
spans.update((i, m.span(n + 1))
for i, n in enumerate(self._fixed_fields))
# and that's our result
return Result(fixed_fields, self._expand_named_fields(named_fields), spans) | def evaluate_result(self, m):
'''Generate a Result instance for the given regex match object'''
# ok, figure the fixed fields we've pulled out and type convert them
fixed_fields = list(m.groups())
for n in self._fixed_fields:
if n in self._type_conversions:
fixed_fields[n] = self._type_conversions[n](fixed_fields[n], m)
fixed_fields = tuple(fixed_fields[n] for n in self._fixed_fields)
# grab the named fields, converting where requested
groupdict = m.groupdict()
named_fields = {}
name_map = {}
for k in self._named_fields:
korig = self._group_to_name_map[k]
name_map[korig] = k
if k in self._type_conversions:
value = self._type_conversions[k](groupdict[k], m)
else:
value = groupdict[k]
named_fields[korig] = value
# now figure the match spans
spans = dict((n, m.span(name_map[n])) for n in named_fields)
spans.update((i, m.span(n + 1))
for i, n in enumerate(self._fixed_fields))
# and that's our result
return Result(fixed_fields, self._expand_named_fields(named_fields), spans) | [
"Generate",
"a",
"Result",
"instance",
"for",
"the",
"given",
"regex",
"match",
"object"
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/parse.py#L844-L873 | [
"def",
"evaluate_result",
"(",
"self",
",",
"m",
")",
":",
"# ok, figure the fixed fields we've pulled out and type convert them",
"fixed_fields",
"=",
"list",
"(",
"m",
".",
"groups",
"(",
")",
")",
"for",
"n",
"in",
"self",
".",
"_fixed_fields",
":",
"if",
"n"... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | install | Installs provided packages and adds them to Pipfile, or (if no packages are given), installs all packages from Pipfile. | pipenv/cli/command.py | def install(
ctx,
state,
**kwargs
):
"""Installs provided packages and adds them to Pipfile, or (if no packages are given), installs all packages from Pipfile."""
from ..core import do_install
retcode = do_install(
dev=state.installstate.dev,
three=state.three,
python=state.python,
pypi_mirror=state.pypi_mirror,
system=state.system,
lock=not state.installstate.skip_lock,
ignore_pipfile=state.installstate.ignore_pipfile,
skip_lock=state.installstate.skip_lock,
requirements=state.installstate.requirementstxt,
sequential=state.installstate.sequential,
pre=state.installstate.pre,
code=state.installstate.code,
deploy=state.installstate.deploy,
keep_outdated=state.installstate.keep_outdated,
selective_upgrade=state.installstate.selective_upgrade,
index_url=state.index,
extra_index_url=state.extra_index_urls,
packages=state.installstate.packages,
editable_packages=state.installstate.editables,
)
if retcode:
ctx.abort() | def install(
ctx,
state,
**kwargs
):
"""Installs provided packages and adds them to Pipfile, or (if no packages are given), installs all packages from Pipfile."""
from ..core import do_install
retcode = do_install(
dev=state.installstate.dev,
three=state.three,
python=state.python,
pypi_mirror=state.pypi_mirror,
system=state.system,
lock=not state.installstate.skip_lock,
ignore_pipfile=state.installstate.ignore_pipfile,
skip_lock=state.installstate.skip_lock,
requirements=state.installstate.requirementstxt,
sequential=state.installstate.sequential,
pre=state.installstate.pre,
code=state.installstate.code,
deploy=state.installstate.deploy,
keep_outdated=state.installstate.keep_outdated,
selective_upgrade=state.installstate.selective_upgrade,
index_url=state.index,
extra_index_url=state.extra_index_urls,
packages=state.installstate.packages,
editable_packages=state.installstate.editables,
)
if retcode:
ctx.abort() | [
"Installs",
"provided",
"packages",
"and",
"adds",
"them",
"to",
"Pipfile",
"or",
"(",
"if",
"no",
"packages",
"are",
"given",
")",
"installs",
"all",
"packages",
"from",
"Pipfile",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/cli/command.py#L228-L258 | [
"def",
"install",
"(",
"ctx",
",",
"state",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
".",
".",
"core",
"import",
"do_install",
"retcode",
"=",
"do_install",
"(",
"dev",
"=",
"state",
".",
"installstate",
".",
"dev",
",",
"three",
"=",
"state",
".",... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | uninstall | Un-installs a provided package and removes it from Pipfile. | pipenv/cli/command.py | def uninstall(
ctx,
state,
all_dev=False,
all=False,
**kwargs
):
"""Un-installs a provided package and removes it from Pipfile."""
from ..core import do_uninstall
retcode = do_uninstall(
packages=state.installstate.packages,
editable_packages=state.installstate.editables,
three=state.three,
python=state.python,
system=state.system,
lock=not state.installstate.skip_lock,
all_dev=all_dev,
all=all,
keep_outdated=state.installstate.keep_outdated,
pypi_mirror=state.pypi_mirror,
ctx=ctx
)
if retcode:
sys.exit(retcode) | def uninstall(
ctx,
state,
all_dev=False,
all=False,
**kwargs
):
"""Un-installs a provided package and removes it from Pipfile."""
from ..core import do_uninstall
retcode = do_uninstall(
packages=state.installstate.packages,
editable_packages=state.installstate.editables,
three=state.three,
python=state.python,
system=state.system,
lock=not state.installstate.skip_lock,
all_dev=all_dev,
all=all,
keep_outdated=state.installstate.keep_outdated,
pypi_mirror=state.pypi_mirror,
ctx=ctx
)
if retcode:
sys.exit(retcode) | [
"Un",
"-",
"installs",
"a",
"provided",
"package",
"and",
"removes",
"it",
"from",
"Pipfile",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/cli/command.py#L280-L303 | [
"def",
"uninstall",
"(",
"ctx",
",",
"state",
",",
"all_dev",
"=",
"False",
",",
"all",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
".",
".",
"core",
"import",
"do_uninstall",
"retcode",
"=",
"do_uninstall",
"(",
"packages",
"=",
"state",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | lock | Generates Pipfile.lock. | pipenv/cli/command.py | def lock(
ctx,
state,
**kwargs
):
"""Generates Pipfile.lock."""
from ..core import ensure_project, do_init, do_lock
# Ensure that virtualenv is available.
ensure_project(three=state.three, python=state.python, pypi_mirror=state.pypi_mirror)
if state.installstate.requirementstxt:
do_init(
dev=state.installstate.dev,
requirements=state.installstate.requirementstxt,
pypi_mirror=state.pypi_mirror,
pre=state.installstate.pre,
)
do_lock(
ctx=ctx,
clear=state.clear,
pre=state.installstate.pre,
keep_outdated=state.installstate.keep_outdated,
pypi_mirror=state.pypi_mirror,
) | def lock(
ctx,
state,
**kwargs
):
"""Generates Pipfile.lock."""
from ..core import ensure_project, do_init, do_lock
# Ensure that virtualenv is available.
ensure_project(three=state.three, python=state.python, pypi_mirror=state.pypi_mirror)
if state.installstate.requirementstxt:
do_init(
dev=state.installstate.dev,
requirements=state.installstate.requirementstxt,
pypi_mirror=state.pypi_mirror,
pre=state.installstate.pre,
)
do_lock(
ctx=ctx,
clear=state.clear,
pre=state.installstate.pre,
keep_outdated=state.installstate.keep_outdated,
pypi_mirror=state.pypi_mirror,
) | [
"Generates",
"Pipfile",
".",
"lock",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/cli/command.py#L310-L333 | [
"def",
"lock",
"(",
"ctx",
",",
"state",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
".",
".",
"core",
"import",
"ensure_project",
",",
"do_init",
",",
"do_lock",
"# Ensure that virtualenv is available.",
"ensure_project",
"(",
"three",
"=",
"state",
".",
"th... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | shell | Spawns a shell within the virtualenv. | pipenv/cli/command.py | def shell(
state,
fancy=False,
shell_args=None,
anyway=False,
):
"""Spawns a shell within the virtualenv."""
from ..core import load_dot_env, do_shell
# Prevent user from activating nested environments.
if "PIPENV_ACTIVE" in os.environ:
# If PIPENV_ACTIVE is set, VIRTUAL_ENV should always be set too.
venv_name = os.environ.get("VIRTUAL_ENV", "UNKNOWN_VIRTUAL_ENVIRONMENT")
if not anyway:
echo(
"{0} {1} {2}\nNo action taken to avoid nested environments.".format(
crayons.normal("Shell for"),
crayons.green(venv_name, bold=True),
crayons.normal("already activated.", bold=True),
),
err=True,
)
sys.exit(1)
# Load .env file.
load_dot_env()
# Use fancy mode for Windows.
if os.name == "nt":
fancy = True
do_shell(
three=state.three,
python=state.python,
fancy=fancy,
shell_args=shell_args,
pypi_mirror=state.pypi_mirror,
) | def shell(
state,
fancy=False,
shell_args=None,
anyway=False,
):
"""Spawns a shell within the virtualenv."""
from ..core import load_dot_env, do_shell
# Prevent user from activating nested environments.
if "PIPENV_ACTIVE" in os.environ:
# If PIPENV_ACTIVE is set, VIRTUAL_ENV should always be set too.
venv_name = os.environ.get("VIRTUAL_ENV", "UNKNOWN_VIRTUAL_ENVIRONMENT")
if not anyway:
echo(
"{0} {1} {2}\nNo action taken to avoid nested environments.".format(
crayons.normal("Shell for"),
crayons.green(venv_name, bold=True),
crayons.normal("already activated.", bold=True),
),
err=True,
)
sys.exit(1)
# Load .env file.
load_dot_env()
# Use fancy mode for Windows.
if os.name == "nt":
fancy = True
do_shell(
three=state.three,
python=state.python,
fancy=fancy,
shell_args=shell_args,
pypi_mirror=state.pypi_mirror,
) | [
"Spawns",
"a",
"shell",
"within",
"the",
"virtualenv",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/cli/command.py#L357-L391 | [
"def",
"shell",
"(",
"state",
",",
"fancy",
"=",
"False",
",",
"shell_args",
"=",
"None",
",",
"anyway",
"=",
"False",
",",
")",
":",
"from",
".",
".",
"core",
"import",
"load_dot_env",
",",
"do_shell",
"# Prevent user from activating nested environments.",
"i... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | run | Spawns a command installed into the virtualenv. | pipenv/cli/command.py | def run(state, command, args):
"""Spawns a command installed into the virtualenv."""
from ..core import do_run
do_run(
command=command, args=args, three=state.three, python=state.python, pypi_mirror=state.pypi_mirror
) | def run(state, command, args):
"""Spawns a command installed into the virtualenv."""
from ..core import do_run
do_run(
command=command, args=args, three=state.three, python=state.python, pypi_mirror=state.pypi_mirror
) | [
"Spawns",
"a",
"command",
"installed",
"into",
"the",
"virtualenv",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/cli/command.py#L403-L408 | [
"def",
"run",
"(",
"state",
",",
"command",
",",
"args",
")",
":",
"from",
".",
".",
"core",
"import",
"do_run",
"do_run",
"(",
"command",
"=",
"command",
",",
"args",
"=",
"args",
",",
"three",
"=",
"state",
".",
"three",
",",
"python",
"=",
"stat... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | check | Checks for security vulnerabilities and against PEP 508 markers provided in Pipfile. | pipenv/cli/command.py | def check(
state,
unused=False,
style=False,
ignore=None,
args=None,
**kwargs
):
"""Checks for security vulnerabilities and against PEP 508 markers provided in Pipfile."""
from ..core import do_check
do_check(
three=state.three,
python=state.python,
system=state.system,
unused=unused,
ignore=ignore,
args=args,
pypi_mirror=state.pypi_mirror,
) | def check(
state,
unused=False,
style=False,
ignore=None,
args=None,
**kwargs
):
"""Checks for security vulnerabilities and against PEP 508 markers provided in Pipfile."""
from ..core import do_check
do_check(
three=state.three,
python=state.python,
system=state.system,
unused=unused,
ignore=ignore,
args=args,
pypi_mirror=state.pypi_mirror,
) | [
"Checks",
"for",
"security",
"vulnerabilities",
"and",
"against",
"PEP",
"508",
"markers",
"provided",
"in",
"Pipfile",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/cli/command.py#L431-L450 | [
"def",
"check",
"(",
"state",
",",
"unused",
"=",
"False",
",",
"style",
"=",
"False",
",",
"ignore",
"=",
"None",
",",
"args",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
".",
".",
"core",
"import",
"do_check",
"do_check",
"(",
"three"... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | update | Runs lock, then sync. | pipenv/cli/command.py | def update(
ctx,
state,
bare=False,
dry_run=None,
outdated=False,
**kwargs
):
"""Runs lock, then sync."""
from ..core import (
ensure_project,
do_outdated,
do_lock,
do_sync,
project,
)
ensure_project(three=state.three, python=state.python, warn=True, pypi_mirror=state.pypi_mirror)
if not outdated:
outdated = bool(dry_run)
if outdated:
do_outdated(pypi_mirror=state.pypi_mirror)
packages = [p for p in state.installstate.packages if p]
editable = [p for p in state.installstate.editables if p]
if not packages:
echo(
"{0} {1} {2} {3}{4}".format(
crayons.white("Running", bold=True),
crayons.red("$ pipenv lock", bold=True),
crayons.white("then", bold=True),
crayons.red("$ pipenv sync", bold=True),
crayons.white(".", bold=True),
)
)
else:
for package in packages + editable:
if package not in project.all_packages:
echo(
"{0}: {1} was not found in your Pipfile! Aborting."
"".format(
crayons.red("Warning", bold=True),
crayons.green(package, bold=True),
),
err=True,
)
ctx.abort()
do_lock(
clear=state.clear,
pre=state.installstate.pre,
keep_outdated=state.installstate.keep_outdated,
pypi_mirror=state.pypi_mirror,
)
do_sync(
ctx=ctx,
dev=state.installstate.dev,
three=state.three,
python=state.python,
bare=bare,
dont_upgrade=not state.installstate.keep_outdated,
user=False,
clear=state.clear,
unused=False,
sequential=state.installstate.sequential,
pypi_mirror=state.pypi_mirror,
) | def update(
ctx,
state,
bare=False,
dry_run=None,
outdated=False,
**kwargs
):
"""Runs lock, then sync."""
from ..core import (
ensure_project,
do_outdated,
do_lock,
do_sync,
project,
)
ensure_project(three=state.three, python=state.python, warn=True, pypi_mirror=state.pypi_mirror)
if not outdated:
outdated = bool(dry_run)
if outdated:
do_outdated(pypi_mirror=state.pypi_mirror)
packages = [p for p in state.installstate.packages if p]
editable = [p for p in state.installstate.editables if p]
if not packages:
echo(
"{0} {1} {2} {3}{4}".format(
crayons.white("Running", bold=True),
crayons.red("$ pipenv lock", bold=True),
crayons.white("then", bold=True),
crayons.red("$ pipenv sync", bold=True),
crayons.white(".", bold=True),
)
)
else:
for package in packages + editable:
if package not in project.all_packages:
echo(
"{0}: {1} was not found in your Pipfile! Aborting."
"".format(
crayons.red("Warning", bold=True),
crayons.green(package, bold=True),
),
err=True,
)
ctx.abort()
do_lock(
clear=state.clear,
pre=state.installstate.pre,
keep_outdated=state.installstate.keep_outdated,
pypi_mirror=state.pypi_mirror,
)
do_sync(
ctx=ctx,
dev=state.installstate.dev,
three=state.three,
python=state.python,
bare=bare,
dont_upgrade=not state.installstate.keep_outdated,
user=False,
clear=state.clear,
unused=False,
sequential=state.installstate.sequential,
pypi_mirror=state.pypi_mirror,
) | [
"Runs",
"lock",
"then",
"sync",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/cli/command.py#L462-L527 | [
"def",
"update",
"(",
"ctx",
",",
"state",
",",
"bare",
"=",
"False",
",",
"dry_run",
"=",
"None",
",",
"outdated",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
".",
".",
"core",
"import",
"(",
"ensure_project",
",",
"do_outdated",
",",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | graph | Displays currently-installed dependency graph information. | pipenv/cli/command.py | def graph(bare=False, json=False, json_tree=False, reverse=False):
"""Displays currently-installed dependency graph information."""
from ..core import do_graph
do_graph(bare=bare, json=json, json_tree=json_tree, reverse=reverse) | def graph(bare=False, json=False, json_tree=False, reverse=False):
"""Displays currently-installed dependency graph information."""
from ..core import do_graph
do_graph(bare=bare, json=json, json_tree=json_tree, reverse=reverse) | [
"Displays",
"currently",
"-",
"installed",
"dependency",
"graph",
"information",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/cli/command.py#L538-L542 | [
"def",
"graph",
"(",
"bare",
"=",
"False",
",",
"json",
"=",
"False",
",",
"json_tree",
"=",
"False",
",",
"reverse",
"=",
"False",
")",
":",
"from",
".",
".",
"core",
"import",
"do_graph",
"do_graph",
"(",
"bare",
"=",
"bare",
",",
"json",
"=",
"j... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | run_open | View a given module in your editor.
This uses the EDITOR environment variable. You can temporarily override it,
for example:
EDITOR=atom pipenv open requests | pipenv/cli/command.py | def run_open(state, module, *args, **kwargs):
"""View a given module in your editor.
This uses the EDITOR environment variable. You can temporarily override it,
for example:
EDITOR=atom pipenv open requests
"""
from ..core import which, ensure_project, inline_activate_virtual_environment
# Ensure that virtualenv is available.
ensure_project(
three=state.three, python=state.python,
validate=False, pypi_mirror=state.pypi_mirror,
)
c = delegator.run(
'{0} -c "import {1}; print({1}.__file__);"'.format(which("python"), module)
)
try:
assert c.return_code == 0
except AssertionError:
echo(crayons.red("Module not found!"))
sys.exit(1)
if "__init__.py" in c.out:
p = os.path.dirname(c.out.strip().rstrip("cdo"))
else:
p = c.out.strip().rstrip("cdo")
echo(crayons.normal("Opening {0!r} in your EDITOR.".format(p), bold=True))
inline_activate_virtual_environment()
edit(filename=p)
return 0 | def run_open(state, module, *args, **kwargs):
"""View a given module in your editor.
This uses the EDITOR environment variable. You can temporarily override it,
for example:
EDITOR=atom pipenv open requests
"""
from ..core import which, ensure_project, inline_activate_virtual_environment
# Ensure that virtualenv is available.
ensure_project(
three=state.three, python=state.python,
validate=False, pypi_mirror=state.pypi_mirror,
)
c = delegator.run(
'{0} -c "import {1}; print({1}.__file__);"'.format(which("python"), module)
)
try:
assert c.return_code == 0
except AssertionError:
echo(crayons.red("Module not found!"))
sys.exit(1)
if "__init__.py" in c.out:
p = os.path.dirname(c.out.strip().rstrip("cdo"))
else:
p = c.out.strip().rstrip("cdo")
echo(crayons.normal("Opening {0!r} in your EDITOR.".format(p), bold=True))
inline_activate_virtual_environment()
edit(filename=p)
return 0 | [
"View",
"a",
"given",
"module",
"in",
"your",
"editor",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/cli/command.py#L552-L582 | [
"def",
"run_open",
"(",
"state",
",",
"module",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
".",
".",
"core",
"import",
"which",
",",
"ensure_project",
",",
"inline_activate_virtual_environment",
"# Ensure that virtualenv is available.",
"ensure_p... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | sync | Installs all packages specified in Pipfile.lock. | pipenv/cli/command.py | def sync(
ctx,
state,
bare=False,
user=False,
unused=False,
**kwargs
):
"""Installs all packages specified in Pipfile.lock."""
from ..core import do_sync
retcode = do_sync(
ctx=ctx,
dev=state.installstate.dev,
three=state.three,
python=state.python,
bare=bare,
dont_upgrade=(not state.installstate.keep_outdated),
user=user,
clear=state.clear,
unused=unused,
sequential=state.installstate.sequential,
pypi_mirror=state.pypi_mirror,
)
if retcode:
ctx.abort() | def sync(
ctx,
state,
bare=False,
user=False,
unused=False,
**kwargs
):
"""Installs all packages specified in Pipfile.lock."""
from ..core import do_sync
retcode = do_sync(
ctx=ctx,
dev=state.installstate.dev,
three=state.three,
python=state.python,
bare=bare,
dont_upgrade=(not state.installstate.keep_outdated),
user=user,
clear=state.clear,
unused=unused,
sequential=state.installstate.sequential,
pypi_mirror=state.pypi_mirror,
)
if retcode:
ctx.abort() | [
"Installs",
"all",
"packages",
"specified",
"in",
"Pipfile",
".",
"lock",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/cli/command.py#L593-L618 | [
"def",
"sync",
"(",
"ctx",
",",
"state",
",",
"bare",
"=",
"False",
",",
"user",
"=",
"False",
",",
"unused",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
".",
".",
"core",
"import",
"do_sync",
"retcode",
"=",
"do_sync",
"(",
"ctx",
"... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | clean | Uninstalls all packages not specified in Pipfile.lock. | pipenv/cli/command.py | def clean(ctx, state, dry_run=False, bare=False, user=False):
"""Uninstalls all packages not specified in Pipfile.lock."""
from ..core import do_clean
do_clean(ctx=ctx, three=state.three, python=state.python, dry_run=dry_run,
system=state.system) | def clean(ctx, state, dry_run=False, bare=False, user=False):
"""Uninstalls all packages not specified in Pipfile.lock."""
from ..core import do_clean
do_clean(ctx=ctx, three=state.three, python=state.python, dry_run=dry_run,
system=state.system) | [
"Uninstalls",
"all",
"packages",
"not",
"specified",
"in",
"Pipfile",
".",
"lock",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/cli/command.py#L632-L636 | [
"def",
"clean",
"(",
"ctx",
",",
"state",
",",
"dry_run",
"=",
"False",
",",
"bare",
"=",
"False",
",",
"user",
"=",
"False",
")",
":",
"from",
".",
".",
"core",
"import",
"do_clean",
"do_clean",
"(",
"ctx",
"=",
"ctx",
",",
"three",
"=",
"state",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | HTMLTokenizer.consumeNumberEntity | This function returns either U+FFFD or the character based on the
decimal or hexadecimal representation. It also discards ";" if present.
If not present self.tokenQueue.append({"type": tokenTypes["ParseError"]}) is invoked. | pipenv/patched/notpip/_vendor/html5lib/_tokenizer.py | def consumeNumberEntity(self, isHex):
"""This function returns either U+FFFD or the character based on the
decimal or hexadecimal representation. It also discards ";" if present.
If not present self.tokenQueue.append({"type": tokenTypes["ParseError"]}) is invoked.
"""
allowed = digits
radix = 10
if isHex:
allowed = hexDigits
radix = 16
charStack = []
# Consume all the characters that are in range while making sure we
# don't hit an EOF.
c = self.stream.char()
while c in allowed and c is not EOF:
charStack.append(c)
c = self.stream.char()
# Convert the set of characters consumed to an int.
charAsInt = int("".join(charStack), radix)
# Certain characters get replaced with others
if charAsInt in replacementCharacters:
char = replacementCharacters[charAsInt]
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"illegal-codepoint-for-numeric-entity",
"datavars": {"charAsInt": charAsInt}})
elif ((0xD800 <= charAsInt <= 0xDFFF) or
(charAsInt > 0x10FFFF)):
char = "\uFFFD"
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"illegal-codepoint-for-numeric-entity",
"datavars": {"charAsInt": charAsInt}})
else:
# Should speed up this check somehow (e.g. move the set to a constant)
if ((0x0001 <= charAsInt <= 0x0008) or
(0x000E <= charAsInt <= 0x001F) or
(0x007F <= charAsInt <= 0x009F) or
(0xFDD0 <= charAsInt <= 0xFDEF) or
charAsInt in frozenset([0x000B, 0xFFFE, 0xFFFF, 0x1FFFE,
0x1FFFF, 0x2FFFE, 0x2FFFF, 0x3FFFE,
0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE,
0x5FFFF, 0x6FFFE, 0x6FFFF, 0x7FFFE,
0x7FFFF, 0x8FFFE, 0x8FFFF, 0x9FFFE,
0x9FFFF, 0xAFFFE, 0xAFFFF, 0xBFFFE,
0xBFFFF, 0xCFFFE, 0xCFFFF, 0xDFFFE,
0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE,
0xFFFFF, 0x10FFFE, 0x10FFFF])):
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data":
"illegal-codepoint-for-numeric-entity",
"datavars": {"charAsInt": charAsInt}})
try:
# Try/except needed as UCS-2 Python builds' unichar only works
# within the BMP.
char = chr(charAsInt)
except ValueError:
v = charAsInt - 0x10000
char = chr(0xD800 | (v >> 10)) + chr(0xDC00 | (v & 0x3FF))
# Discard the ; if present. Otherwise, put it back on the queue and
# invoke parseError on parser.
if c != ";":
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"numeric-entity-without-semicolon"})
self.stream.unget(c)
return char | def consumeNumberEntity(self, isHex):
"""This function returns either U+FFFD or the character based on the
decimal or hexadecimal representation. It also discards ";" if present.
If not present self.tokenQueue.append({"type": tokenTypes["ParseError"]}) is invoked.
"""
allowed = digits
radix = 10
if isHex:
allowed = hexDigits
radix = 16
charStack = []
# Consume all the characters that are in range while making sure we
# don't hit an EOF.
c = self.stream.char()
while c in allowed and c is not EOF:
charStack.append(c)
c = self.stream.char()
# Convert the set of characters consumed to an int.
charAsInt = int("".join(charStack), radix)
# Certain characters get replaced with others
if charAsInt in replacementCharacters:
char = replacementCharacters[charAsInt]
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"illegal-codepoint-for-numeric-entity",
"datavars": {"charAsInt": charAsInt}})
elif ((0xD800 <= charAsInt <= 0xDFFF) or
(charAsInt > 0x10FFFF)):
char = "\uFFFD"
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"illegal-codepoint-for-numeric-entity",
"datavars": {"charAsInt": charAsInt}})
else:
# Should speed up this check somehow (e.g. move the set to a constant)
if ((0x0001 <= charAsInt <= 0x0008) or
(0x000E <= charAsInt <= 0x001F) or
(0x007F <= charAsInt <= 0x009F) or
(0xFDD0 <= charAsInt <= 0xFDEF) or
charAsInt in frozenset([0x000B, 0xFFFE, 0xFFFF, 0x1FFFE,
0x1FFFF, 0x2FFFE, 0x2FFFF, 0x3FFFE,
0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE,
0x5FFFF, 0x6FFFE, 0x6FFFF, 0x7FFFE,
0x7FFFF, 0x8FFFE, 0x8FFFF, 0x9FFFE,
0x9FFFF, 0xAFFFE, 0xAFFFF, 0xBFFFE,
0xBFFFF, 0xCFFFE, 0xCFFFF, 0xDFFFE,
0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE,
0xFFFFF, 0x10FFFE, 0x10FFFF])):
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data":
"illegal-codepoint-for-numeric-entity",
"datavars": {"charAsInt": charAsInt}})
try:
# Try/except needed as UCS-2 Python builds' unichar only works
# within the BMP.
char = chr(charAsInt)
except ValueError:
v = charAsInt - 0x10000
char = chr(0xD800 | (v >> 10)) + chr(0xDC00 | (v & 0x3FF))
# Discard the ; if present. Otherwise, put it back on the queue and
# invoke parseError on parser.
if c != ";":
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"numeric-entity-without-semicolon"})
self.stream.unget(c)
return char | [
"This",
"function",
"returns",
"either",
"U",
"+",
"FFFD",
"or",
"the",
"character",
"based",
"on",
"the",
"decimal",
"or",
"hexadecimal",
"representation",
".",
"It",
"also",
"discards",
";",
"if",
"present",
".",
"If",
"not",
"present",
"self",
".",
"tok... | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/html5lib/_tokenizer.py#L65-L135 | [
"def",
"consumeNumberEntity",
"(",
"self",
",",
"isHex",
")",
":",
"allowed",
"=",
"digits",
"radix",
"=",
"10",
"if",
"isHex",
":",
"allowed",
"=",
"hexDigits",
"radix",
"=",
"16",
"charStack",
"=",
"[",
"]",
"# Consume all the characters that are in range whil... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | HTMLTokenizer.emitCurrentToken | This method is a generic handler for emitting the tags. It also sets
the state to "data" because that's what's needed after a token has been
emitted. | pipenv/patched/notpip/_vendor/html5lib/_tokenizer.py | def emitCurrentToken(self):
"""This method is a generic handler for emitting the tags. It also sets
the state to "data" because that's what's needed after a token has been
emitted.
"""
token = self.currentToken
# Add token to the queue to be yielded
if (token["type"] in tagTokenTypes):
token["name"] = token["name"].translate(asciiUpper2Lower)
if token["type"] == tokenTypes["EndTag"]:
if token["data"]:
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "attributes-in-end-tag"})
if token["selfClosing"]:
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "self-closing-flag-on-end-tag"})
self.tokenQueue.append(token)
self.state = self.dataState | def emitCurrentToken(self):
"""This method is a generic handler for emitting the tags. It also sets
the state to "data" because that's what's needed after a token has been
emitted.
"""
token = self.currentToken
# Add token to the queue to be yielded
if (token["type"] in tagTokenTypes):
token["name"] = token["name"].translate(asciiUpper2Lower)
if token["type"] == tokenTypes["EndTag"]:
if token["data"]:
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "attributes-in-end-tag"})
if token["selfClosing"]:
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "self-closing-flag-on-end-tag"})
self.tokenQueue.append(token)
self.state = self.dataState | [
"This",
"method",
"is",
"a",
"generic",
"handler",
"for",
"emitting",
"the",
"tags",
".",
"It",
"also",
"sets",
"the",
"state",
"to",
"data",
"because",
"that",
"s",
"what",
"s",
"needed",
"after",
"a",
"token",
"has",
"been",
"emitted",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/html5lib/_tokenizer.py#L222-L239 | [
"def",
"emitCurrentToken",
"(",
"self",
")",
":",
"token",
"=",
"self",
".",
"currentToken",
"# Add token to the queue to be yielded",
"if",
"(",
"token",
"[",
"\"type\"",
"]",
"in",
"tagTokenTypes",
")",
":",
"token",
"[",
"\"name\"",
"]",
"=",
"token",
"[",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | create_package_set_from_installed | Converts a list of distributions into a PackageSet. | pipenv/patched/notpip/_internal/operations/check.py | def create_package_set_from_installed(**kwargs):
# type: (**Any) -> Tuple[PackageSet, bool]
"""Converts a list of distributions into a PackageSet.
"""
# Default to using all packages installed on the system
if kwargs == {}:
kwargs = {"local_only": False, "skip": ()}
package_set = {}
problems = False
for dist in get_installed_distributions(**kwargs):
name = canonicalize_name(dist.project_name)
try:
package_set[name] = PackageDetails(dist.version, dist.requires())
except RequirementParseError as e:
# Don't crash on broken metadata
logging.warning("Error parsing requirements for %s: %s", name, e)
problems = True
return package_set, problems | def create_package_set_from_installed(**kwargs):
# type: (**Any) -> Tuple[PackageSet, bool]
"""Converts a list of distributions into a PackageSet.
"""
# Default to using all packages installed on the system
if kwargs == {}:
kwargs = {"local_only": False, "skip": ()}
package_set = {}
problems = False
for dist in get_installed_distributions(**kwargs):
name = canonicalize_name(dist.project_name)
try:
package_set[name] = PackageDetails(dist.version, dist.requires())
except RequirementParseError as e:
# Don't crash on broken metadata
logging.warning("Error parsing requirements for %s: %s", name, e)
problems = True
return package_set, problems | [
"Converts",
"a",
"list",
"of",
"distributions",
"into",
"a",
"PackageSet",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_internal/operations/check.py#L34-L52 | [
"def",
"create_package_set_from_installed",
"(",
"*",
"*",
"kwargs",
")",
":",
"# type: (**Any) -> Tuple[PackageSet, bool]",
"# Default to using all packages installed on the system",
"if",
"kwargs",
"==",
"{",
"}",
":",
"kwargs",
"=",
"{",
"\"local_only\"",
":",
"False",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | check_package_set | Check if a package set is consistent
If should_ignore is passed, it should be a callable that takes a
package name and returns a boolean. | pipenv/patched/notpip/_internal/operations/check.py | def check_package_set(package_set, should_ignore=None):
# type: (PackageSet, Optional[Callable[[str], bool]]) -> CheckResult
"""Check if a package set is consistent
If should_ignore is passed, it should be a callable that takes a
package name and returns a boolean.
"""
if should_ignore is None:
def should_ignore(name):
return False
missing = dict()
conflicting = dict()
for package_name in package_set:
# Info about dependencies of package_name
missing_deps = set() # type: Set[Missing]
conflicting_deps = set() # type: Set[Conflicting]
if should_ignore(package_name):
continue
for req in package_set[package_name].requires:
name = canonicalize_name(req.project_name) # type: str
# Check if it's missing
if name not in package_set:
missed = True
if req.marker is not None:
missed = req.marker.evaluate()
if missed:
missing_deps.add((name, req))
continue
# Check if there's a conflict
version = package_set[name].version # type: str
if not req.specifier.contains(version, prereleases=True):
conflicting_deps.add((name, version, req))
if missing_deps:
missing[package_name] = sorted(missing_deps, key=str)
if conflicting_deps:
conflicting[package_name] = sorted(conflicting_deps, key=str)
return missing, conflicting | def check_package_set(package_set, should_ignore=None):
# type: (PackageSet, Optional[Callable[[str], bool]]) -> CheckResult
"""Check if a package set is consistent
If should_ignore is passed, it should be a callable that takes a
package name and returns a boolean.
"""
if should_ignore is None:
def should_ignore(name):
return False
missing = dict()
conflicting = dict()
for package_name in package_set:
# Info about dependencies of package_name
missing_deps = set() # type: Set[Missing]
conflicting_deps = set() # type: Set[Conflicting]
if should_ignore(package_name):
continue
for req in package_set[package_name].requires:
name = canonicalize_name(req.project_name) # type: str
# Check if it's missing
if name not in package_set:
missed = True
if req.marker is not None:
missed = req.marker.evaluate()
if missed:
missing_deps.add((name, req))
continue
# Check if there's a conflict
version = package_set[name].version # type: str
if not req.specifier.contains(version, prereleases=True):
conflicting_deps.add((name, version, req))
if missing_deps:
missing[package_name] = sorted(missing_deps, key=str)
if conflicting_deps:
conflicting[package_name] = sorted(conflicting_deps, key=str)
return missing, conflicting | [
"Check",
"if",
"a",
"package",
"set",
"is",
"consistent"
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_internal/operations/check.py#L55-L99 | [
"def",
"check_package_set",
"(",
"package_set",
",",
"should_ignore",
"=",
"None",
")",
":",
"# type: (PackageSet, Optional[Callable[[str], bool]]) -> CheckResult",
"if",
"should_ignore",
"is",
"None",
":",
"def",
"should_ignore",
"(",
"name",
")",
":",
"return",
"False... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | check_install_conflicts | For checking if the dependency graph would be consistent after \
installing given requirements | pipenv/patched/notpip/_internal/operations/check.py | def check_install_conflicts(to_install):
# type: (List[InstallRequirement]) -> Tuple[PackageSet, CheckResult]
"""For checking if the dependency graph would be consistent after \
installing given requirements
"""
# Start from the current state
package_set, _ = create_package_set_from_installed()
# Install packages
would_be_installed = _simulate_installation_of(to_install, package_set)
# Only warn about directly-dependent packages; create a whitelist of them
whitelist = _create_whitelist(would_be_installed, package_set)
return (
package_set,
check_package_set(
package_set, should_ignore=lambda name: name not in whitelist
)
) | def check_install_conflicts(to_install):
# type: (List[InstallRequirement]) -> Tuple[PackageSet, CheckResult]
"""For checking if the dependency graph would be consistent after \
installing given requirements
"""
# Start from the current state
package_set, _ = create_package_set_from_installed()
# Install packages
would_be_installed = _simulate_installation_of(to_install, package_set)
# Only warn about directly-dependent packages; create a whitelist of them
whitelist = _create_whitelist(would_be_installed, package_set)
return (
package_set,
check_package_set(
package_set, should_ignore=lambda name: name not in whitelist
)
) | [
"For",
"checking",
"if",
"the",
"dependency",
"graph",
"would",
"be",
"consistent",
"after",
"\\",
"installing",
"given",
"requirements"
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_internal/operations/check.py#L102-L120 | [
"def",
"check_install_conflicts",
"(",
"to_install",
")",
":",
"# type: (List[InstallRequirement]) -> Tuple[PackageSet, CheckResult]",
"# Start from the current state",
"package_set",
",",
"_",
"=",
"create_package_set_from_installed",
"(",
")",
"# Install packages",
"would_be_instal... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | _simulate_installation_of | Computes the version of packages after installing to_install. | pipenv/patched/notpip/_internal/operations/check.py | def _simulate_installation_of(to_install, package_set):
# type: (List[InstallRequirement], PackageSet) -> Set[str]
"""Computes the version of packages after installing to_install.
"""
# Keep track of packages that were installed
installed = set()
# Modify it as installing requirement_set would (assuming no errors)
for inst_req in to_install:
dist = make_abstract_dist(inst_req).dist()
name = canonicalize_name(dist.key)
package_set[name] = PackageDetails(dist.version, dist.requires())
installed.add(name)
return installed | def _simulate_installation_of(to_install, package_set):
# type: (List[InstallRequirement], PackageSet) -> Set[str]
"""Computes the version of packages after installing to_install.
"""
# Keep track of packages that were installed
installed = set()
# Modify it as installing requirement_set would (assuming no errors)
for inst_req in to_install:
dist = make_abstract_dist(inst_req).dist()
name = canonicalize_name(dist.key)
package_set[name] = PackageDetails(dist.version, dist.requires())
installed.add(name)
return installed | [
"Computes",
"the",
"version",
"of",
"packages",
"after",
"installing",
"to_install",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_internal/operations/check.py#L123-L139 | [
"def",
"_simulate_installation_of",
"(",
"to_install",
",",
"package_set",
")",
":",
"# type: (List[InstallRequirement], PackageSet) -> Set[str]",
"# Keep track of packages that were installed",
"installed",
"=",
"set",
"(",
")",
"# Modify it as installing requirement_set would (assumi... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | CharSetProber.filter_international_words | We define three types of bytes:
alphabet: english alphabets [a-zA-Z]
international: international characters [\x80-\xFF]
marker: everything else [^a-zA-Z\x80-\xFF]
The input buffer can be thought to contain a series of words delimited
by markers. This function works to filter all words that contain at
least one international character. All contiguous sequences of markers
are replaced by a single space ascii character.
This filter applies to all scripts which do not use English characters. | pipenv/vendor/chardet/charsetprober.py | def filter_international_words(buf):
"""
We define three types of bytes:
alphabet: english alphabets [a-zA-Z]
international: international characters [\x80-\xFF]
marker: everything else [^a-zA-Z\x80-\xFF]
The input buffer can be thought to contain a series of words delimited
by markers. This function works to filter all words that contain at
least one international character. All contiguous sequences of markers
are replaced by a single space ascii character.
This filter applies to all scripts which do not use English characters.
"""
filtered = bytearray()
# This regex expression filters out only words that have at-least one
# international character. The word may include one marker character at
# the end.
words = re.findall(b'[a-zA-Z]*[\x80-\xFF]+[a-zA-Z]*[^a-zA-Z\x80-\xFF]?',
buf)
for word in words:
filtered.extend(word[:-1])
# If the last character in the word is a marker, replace it with a
# space as markers shouldn't affect our analysis (they are used
# similarly across all languages and may thus have similar
# frequencies).
last_char = word[-1:]
if not last_char.isalpha() and last_char < b'\x80':
last_char = b' '
filtered.extend(last_char)
return filtered | def filter_international_words(buf):
"""
We define three types of bytes:
alphabet: english alphabets [a-zA-Z]
international: international characters [\x80-\xFF]
marker: everything else [^a-zA-Z\x80-\xFF]
The input buffer can be thought to contain a series of words delimited
by markers. This function works to filter all words that contain at
least one international character. All contiguous sequences of markers
are replaced by a single space ascii character.
This filter applies to all scripts which do not use English characters.
"""
filtered = bytearray()
# This regex expression filters out only words that have at-least one
# international character. The word may include one marker character at
# the end.
words = re.findall(b'[a-zA-Z]*[\x80-\xFF]+[a-zA-Z]*[^a-zA-Z\x80-\xFF]?',
buf)
for word in words:
filtered.extend(word[:-1])
# If the last character in the word is a marker, replace it with a
# space as markers shouldn't affect our analysis (they are used
# similarly across all languages and may thus have similar
# frequencies).
last_char = word[-1:]
if not last_char.isalpha() and last_char < b'\x80':
last_char = b' '
filtered.extend(last_char)
return filtered | [
"We",
"define",
"three",
"types",
"of",
"bytes",
":",
"alphabet",
":",
"english",
"alphabets",
"[",
"a",
"-",
"zA",
"-",
"Z",
"]",
"international",
":",
"international",
"characters",
"[",
"\\",
"x80",
"-",
"\\",
"xFF",
"]",
"marker",
":",
"everything",
... | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/chardet/charsetprober.py#L67-L101 | [
"def",
"filter_international_words",
"(",
"buf",
")",
":",
"filtered",
"=",
"bytearray",
"(",
")",
"# This regex expression filters out only words that have at-least one",
"# international character. The word may include one marker character at",
"# the end.",
"words",
"=",
"re",
"... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | CharSetProber.filter_with_english_letters | Returns a copy of ``buf`` that retains only the sequences of English
alphabet and high byte characters that are not between <> characters.
Also retains English alphabet and high byte characters immediately
before occurrences of >.
This filter can be applied to all scripts which contain both English
characters and extended ASCII characters, but is currently only used by
``Latin1Prober``. | pipenv/vendor/chardet/charsetprober.py | def filter_with_english_letters(buf):
"""
Returns a copy of ``buf`` that retains only the sequences of English
alphabet and high byte characters that are not between <> characters.
Also retains English alphabet and high byte characters immediately
before occurrences of >.
This filter can be applied to all scripts which contain both English
characters and extended ASCII characters, but is currently only used by
``Latin1Prober``.
"""
filtered = bytearray()
in_tag = False
prev = 0
for curr in range(len(buf)):
# Slice here to get bytes instead of an int with Python 3
buf_char = buf[curr:curr + 1]
# Check if we're coming out of or entering an HTML tag
if buf_char == b'>':
in_tag = False
elif buf_char == b'<':
in_tag = True
# If current character is not extended-ASCII and not alphabetic...
if buf_char < b'\x80' and not buf_char.isalpha():
# ...and we're not in a tag
if curr > prev and not in_tag:
# Keep everything after last non-extended-ASCII,
# non-alphabetic character
filtered.extend(buf[prev:curr])
# Output a space to delimit stretch we kept
filtered.extend(b' ')
prev = curr + 1
# If we're not in a tag...
if not in_tag:
# Keep everything after last non-extended-ASCII, non-alphabetic
# character
filtered.extend(buf[prev:])
return filtered | def filter_with_english_letters(buf):
"""
Returns a copy of ``buf`` that retains only the sequences of English
alphabet and high byte characters that are not between <> characters.
Also retains English alphabet and high byte characters immediately
before occurrences of >.
This filter can be applied to all scripts which contain both English
characters and extended ASCII characters, but is currently only used by
``Latin1Prober``.
"""
filtered = bytearray()
in_tag = False
prev = 0
for curr in range(len(buf)):
# Slice here to get bytes instead of an int with Python 3
buf_char = buf[curr:curr + 1]
# Check if we're coming out of or entering an HTML tag
if buf_char == b'>':
in_tag = False
elif buf_char == b'<':
in_tag = True
# If current character is not extended-ASCII and not alphabetic...
if buf_char < b'\x80' and not buf_char.isalpha():
# ...and we're not in a tag
if curr > prev and not in_tag:
# Keep everything after last non-extended-ASCII,
# non-alphabetic character
filtered.extend(buf[prev:curr])
# Output a space to delimit stretch we kept
filtered.extend(b' ')
prev = curr + 1
# If we're not in a tag...
if not in_tag:
# Keep everything after last non-extended-ASCII, non-alphabetic
# character
filtered.extend(buf[prev:])
return filtered | [
"Returns",
"a",
"copy",
"of",
"buf",
"that",
"retains",
"only",
"the",
"sequences",
"of",
"English",
"alphabet",
"and",
"high",
"byte",
"characters",
"that",
"are",
"not",
"between",
"<",
">",
"characters",
".",
"Also",
"retains",
"English",
"alphabet",
"and... | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/chardet/charsetprober.py#L104-L145 | [
"def",
"filter_with_english_letters",
"(",
"buf",
")",
":",
"filtered",
"=",
"bytearray",
"(",
")",
"in_tag",
"=",
"False",
"prev",
"=",
"0",
"for",
"curr",
"in",
"range",
"(",
"len",
"(",
"buf",
")",
")",
":",
"# Slice here to get bytes instead of an int with... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | _Flavour.join_parsed_parts | Join the two paths represented by the respective
(drive, root, parts) tuples. Return a new (drive, root, parts) tuple. | pipenv/vendor/pathlib2/__init__.py | def join_parsed_parts(self, drv, root, parts, drv2, root2, parts2):
"""
Join the two paths represented by the respective
(drive, root, parts) tuples. Return a new (drive, root, parts) tuple.
"""
if root2:
if not drv2 and drv:
return drv, root2, [drv + root2] + parts2[1:]
elif drv2:
if drv2 == drv or self.casefold(drv2) == self.casefold(drv):
# Same drive => second path is relative to the first
return drv, root, parts + parts2[1:]
else:
# Second path is non-anchored (common case)
return drv, root, parts + parts2
return drv2, root2, parts2 | def join_parsed_parts(self, drv, root, parts, drv2, root2, parts2):
"""
Join the two paths represented by the respective
(drive, root, parts) tuples. Return a new (drive, root, parts) tuple.
"""
if root2:
if not drv2 and drv:
return drv, root2, [drv + root2] + parts2[1:]
elif drv2:
if drv2 == drv or self.casefold(drv2) == self.casefold(drv):
# Same drive => second path is relative to the first
return drv, root, parts + parts2[1:]
else:
# Second path is non-anchored (common case)
return drv, root, parts + parts2
return drv2, root2, parts2 | [
"Join",
"the",
"two",
"paths",
"represented",
"by",
"the",
"respective",
"(",
"drive",
"root",
"parts",
")",
"tuples",
".",
"Return",
"a",
"new",
"(",
"drive",
"root",
"parts",
")",
"tuple",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L239-L254 | [
"def",
"join_parsed_parts",
"(",
"self",
",",
"drv",
",",
"root",
",",
"parts",
",",
"drv2",
",",
"root2",
",",
"parts2",
")",
":",
"if",
"root2",
":",
"if",
"not",
"drv2",
"and",
"drv",
":",
"return",
"drv",
",",
"root2",
",",
"[",
"drv",
"+",
"... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | _Selector.select_from | Iterate over all child paths of `parent_path` matched by this
selector. This can contain parent_path itself. | pipenv/vendor/pathlib2/__init__.py | def select_from(self, parent_path):
"""Iterate over all child paths of `parent_path` matched by this
selector. This can contain parent_path itself."""
path_cls = type(parent_path)
is_dir = path_cls.is_dir
exists = path_cls.exists
scandir = parent_path._accessor.scandir
if not is_dir(parent_path):
return iter([])
return self._select_from(parent_path, is_dir, exists, scandir) | def select_from(self, parent_path):
"""Iterate over all child paths of `parent_path` matched by this
selector. This can contain parent_path itself."""
path_cls = type(parent_path)
is_dir = path_cls.is_dir
exists = path_cls.exists
scandir = parent_path._accessor.scandir
if not is_dir(parent_path):
return iter([])
return self._select_from(parent_path, is_dir, exists, scandir) | [
"Iterate",
"over",
"all",
"child",
"paths",
"of",
"parent_path",
"matched",
"by",
"this",
"selector",
".",
"This",
"can",
"contain",
"parent_path",
"itself",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L639-L648 | [
"def",
"select_from",
"(",
"self",
",",
"parent_path",
")",
":",
"path_cls",
"=",
"type",
"(",
"parent_path",
")",
"is_dir",
"=",
"path_cls",
".",
"is_dir",
"exists",
"=",
"path_cls",
".",
"exists",
"scandir",
"=",
"parent_path",
".",
"_accessor",
".",
"sc... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | PurePath.as_posix | Return the string representation of the path with forward (/)
slashes. | pipenv/vendor/pathlib2/__init__.py | def as_posix(self):
"""Return the string representation of the path with forward (/)
slashes."""
f = self._flavour
return str(self).replace(f.sep, '/') | def as_posix(self):
"""Return the string representation of the path with forward (/)
slashes."""
f = self._flavour
return str(self).replace(f.sep, '/') | [
"Return",
"the",
"string",
"representation",
"of",
"the",
"path",
"with",
"forward",
"(",
"/",
")",
"slashes",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L896-L900 | [
"def",
"as_posix",
"(",
"self",
")",
":",
"f",
"=",
"self",
".",
"_flavour",
"return",
"str",
"(",
"self",
")",
".",
"replace",
"(",
"f",
".",
"sep",
",",
"'/'",
")"
] | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | PurePath.name | The final path component, if any. | pipenv/vendor/pathlib2/__init__.py | def name(self):
"""The final path component, if any."""
parts = self._parts
if len(parts) == (1 if (self._drv or self._root) else 0):
return ''
return parts[-1] | def name(self):
"""The final path component, if any."""
parts = self._parts
if len(parts) == (1 if (self._drv or self._root) else 0):
return ''
return parts[-1] | [
"The",
"final",
"path",
"component",
"if",
"any",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L981-L986 | [
"def",
"name",
"(",
"self",
")",
":",
"parts",
"=",
"self",
".",
"_parts",
"if",
"len",
"(",
"parts",
")",
"==",
"(",
"1",
"if",
"(",
"self",
".",
"_drv",
"or",
"self",
".",
"_root",
")",
"else",
"0",
")",
":",
"return",
"''",
"return",
"parts"... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | PurePath.suffix | The final component's last suffix, if any. | pipenv/vendor/pathlib2/__init__.py | def suffix(self):
"""The final component's last suffix, if any."""
name = self.name
i = name.rfind('.')
if 0 < i < len(name) - 1:
return name[i:]
else:
return '' | def suffix(self):
"""The final component's last suffix, if any."""
name = self.name
i = name.rfind('.')
if 0 < i < len(name) - 1:
return name[i:]
else:
return '' | [
"The",
"final",
"component",
"s",
"last",
"suffix",
"if",
"any",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L989-L996 | [
"def",
"suffix",
"(",
"self",
")",
":",
"name",
"=",
"self",
".",
"name",
"i",
"=",
"name",
".",
"rfind",
"(",
"'.'",
")",
"if",
"0",
"<",
"i",
"<",
"len",
"(",
"name",
")",
"-",
"1",
":",
"return",
"name",
"[",
"i",
":",
"]",
"else",
":",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | PurePath.suffixes | A list of the final component's suffixes, if any. | pipenv/vendor/pathlib2/__init__.py | def suffixes(self):
"""A list of the final component's suffixes, if any."""
name = self.name
if name.endswith('.'):
return []
name = name.lstrip('.')
return ['.' + suffix for suffix in name.split('.')[1:]] | def suffixes(self):
"""A list of the final component's suffixes, if any."""
name = self.name
if name.endswith('.'):
return []
name = name.lstrip('.')
return ['.' + suffix for suffix in name.split('.')[1:]] | [
"A",
"list",
"of",
"the",
"final",
"component",
"s",
"suffixes",
"if",
"any",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L999-L1005 | [
"def",
"suffixes",
"(",
"self",
")",
":",
"name",
"=",
"self",
".",
"name",
"if",
"name",
".",
"endswith",
"(",
"'.'",
")",
":",
"return",
"[",
"]",
"name",
"=",
"name",
".",
"lstrip",
"(",
"'.'",
")",
"return",
"[",
"'.'",
"+",
"suffix",
"for",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | PurePath.stem | The final path component, minus its last suffix. | pipenv/vendor/pathlib2/__init__.py | def stem(self):
"""The final path component, minus its last suffix."""
name = self.name
i = name.rfind('.')
if 0 < i < len(name) - 1:
return name[:i]
else:
return name | def stem(self):
"""The final path component, minus its last suffix."""
name = self.name
i = name.rfind('.')
if 0 < i < len(name) - 1:
return name[:i]
else:
return name | [
"The",
"final",
"path",
"component",
"minus",
"its",
"last",
"suffix",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1008-L1015 | [
"def",
"stem",
"(",
"self",
")",
":",
"name",
"=",
"self",
".",
"name",
"i",
"=",
"name",
".",
"rfind",
"(",
"'.'",
")",
"if",
"0",
"<",
"i",
"<",
"len",
"(",
"name",
")",
"-",
"1",
":",
"return",
"name",
"[",
":",
"i",
"]",
"else",
":",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | PurePath.with_name | Return a new path with the file name changed. | pipenv/vendor/pathlib2/__init__.py | def with_name(self, name):
"""Return a new path with the file name changed."""
if not self.name:
raise ValueError("%r has an empty name" % (self,))
drv, root, parts = self._flavour.parse_parts((name,))
if (not name or name[-1] in [self._flavour.sep, self._flavour.altsep]
or drv or root or len(parts) != 1):
raise ValueError("Invalid name %r" % (name))
return self._from_parsed_parts(self._drv, self._root,
self._parts[:-1] + [name]) | def with_name(self, name):
"""Return a new path with the file name changed."""
if not self.name:
raise ValueError("%r has an empty name" % (self,))
drv, root, parts = self._flavour.parse_parts((name,))
if (not name or name[-1] in [self._flavour.sep, self._flavour.altsep]
or drv or root or len(parts) != 1):
raise ValueError("Invalid name %r" % (name))
return self._from_parsed_parts(self._drv, self._root,
self._parts[:-1] + [name]) | [
"Return",
"a",
"new",
"path",
"with",
"the",
"file",
"name",
"changed",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1017-L1026 | [
"def",
"with_name",
"(",
"self",
",",
"name",
")",
":",
"if",
"not",
"self",
".",
"name",
":",
"raise",
"ValueError",
"(",
"\"%r has an empty name\"",
"%",
"(",
"self",
",",
")",
")",
"drv",
",",
"root",
",",
"parts",
"=",
"self",
".",
"_flavour",
".... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | PurePath.with_suffix | Return a new path with the file suffix changed (or added, if
none). | pipenv/vendor/pathlib2/__init__.py | def with_suffix(self, suffix):
"""Return a new path with the file suffix changed (or added, if
none).
"""
# XXX if suffix is None, should the current suffix be removed?
f = self._flavour
if f.sep in suffix or f.altsep and f.altsep in suffix:
raise ValueError("Invalid suffix %r" % (suffix))
if suffix and not suffix.startswith('.') or suffix == '.':
raise ValueError("Invalid suffix %r" % (suffix))
name = self.name
if not name:
raise ValueError("%r has an empty name" % (self,))
old_suffix = self.suffix
if not old_suffix:
name = name + suffix
else:
name = name[:-len(old_suffix)] + suffix
return self._from_parsed_parts(self._drv, self._root,
self._parts[:-1] + [name]) | def with_suffix(self, suffix):
"""Return a new path with the file suffix changed (or added, if
none).
"""
# XXX if suffix is None, should the current suffix be removed?
f = self._flavour
if f.sep in suffix or f.altsep and f.altsep in suffix:
raise ValueError("Invalid suffix %r" % (suffix))
if suffix and not suffix.startswith('.') or suffix == '.':
raise ValueError("Invalid suffix %r" % (suffix))
name = self.name
if not name:
raise ValueError("%r has an empty name" % (self,))
old_suffix = self.suffix
if not old_suffix:
name = name + suffix
else:
name = name[:-len(old_suffix)] + suffix
return self._from_parsed_parts(self._drv, self._root,
self._parts[:-1] + [name]) | [
"Return",
"a",
"new",
"path",
"with",
"the",
"file",
"suffix",
"changed",
"(",
"or",
"added",
"if",
"none",
")",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1028-L1047 | [
"def",
"with_suffix",
"(",
"self",
",",
"suffix",
")",
":",
"# XXX if suffix is None, should the current suffix be removed?",
"f",
"=",
"self",
".",
"_flavour",
"if",
"f",
".",
"sep",
"in",
"suffix",
"or",
"f",
".",
"altsep",
"and",
"f",
".",
"altsep",
"in",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | PurePath.parts | An object providing sequence-like access to the
components in the filesystem path. | pipenv/vendor/pathlib2/__init__.py | def parts(self):
"""An object providing sequence-like access to the
components in the filesystem path."""
# We cache the tuple to avoid building a new one each time .parts
# is accessed. XXX is this necessary?
try:
return self._pparts
except AttributeError:
self._pparts = tuple(self._parts)
return self._pparts | def parts(self):
"""An object providing sequence-like access to the
components in the filesystem path."""
# We cache the tuple to avoid building a new one each time .parts
# is accessed. XXX is this necessary?
try:
return self._pparts
except AttributeError:
self._pparts = tuple(self._parts)
return self._pparts | [
"An",
"object",
"providing",
"sequence",
"-",
"like",
"access",
"to",
"the",
"components",
"in",
"the",
"filesystem",
"path",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1082-L1091 | [
"def",
"parts",
"(",
"self",
")",
":",
"# We cache the tuple to avoid building a new one each time .parts",
"# is accessed. XXX is this necessary?",
"try",
":",
"return",
"self",
".",
"_pparts",
"except",
"AttributeError",
":",
"self",
".",
"_pparts",
"=",
"tuple",
"(",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | PurePath.parent | The logical parent of the path. | pipenv/vendor/pathlib2/__init__.py | def parent(self):
"""The logical parent of the path."""
drv = self._drv
root = self._root
parts = self._parts
if len(parts) == 1 and (drv or root):
return self
return self._from_parsed_parts(drv, root, parts[:-1]) | def parent(self):
"""The logical parent of the path."""
drv = self._drv
root = self._root
parts = self._parts
if len(parts) == 1 and (drv or root):
return self
return self._from_parsed_parts(drv, root, parts[:-1]) | [
"The",
"logical",
"parent",
"of",
"the",
"path",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1112-L1119 | [
"def",
"parent",
"(",
"self",
")",
":",
"drv",
"=",
"self",
".",
"_drv",
"root",
"=",
"self",
".",
"_root",
"parts",
"=",
"self",
".",
"_parts",
"if",
"len",
"(",
"parts",
")",
"==",
"1",
"and",
"(",
"drv",
"or",
"root",
")",
":",
"return",
"se... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | PurePath.is_absolute | True if the path is absolute (has both a root and, if applicable,
a drive). | pipenv/vendor/pathlib2/__init__.py | def is_absolute(self):
"""True if the path is absolute (has both a root and, if applicable,
a drive)."""
if not self._root:
return False
return not self._flavour.has_drv or bool(self._drv) | def is_absolute(self):
"""True if the path is absolute (has both a root and, if applicable,
a drive)."""
if not self._root:
return False
return not self._flavour.has_drv or bool(self._drv) | [
"True",
"if",
"the",
"path",
"is",
"absolute",
"(",
"has",
"both",
"a",
"root",
"and",
"if",
"applicable",
"a",
"drive",
")",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1126-L1131 | [
"def",
"is_absolute",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_root",
":",
"return",
"False",
"return",
"not",
"self",
".",
"_flavour",
".",
"has_drv",
"or",
"bool",
"(",
"self",
".",
"_drv",
")"
] | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | PurePath.match | Return True if this path matches the given pattern. | pipenv/vendor/pathlib2/__init__.py | def match(self, path_pattern):
"""
Return True if this path matches the given pattern.
"""
cf = self._flavour.casefold
path_pattern = cf(path_pattern)
drv, root, pat_parts = self._flavour.parse_parts((path_pattern,))
if not pat_parts:
raise ValueError("empty pattern")
if drv and drv != cf(self._drv):
return False
if root and root != cf(self._root):
return False
parts = self._cparts
if drv or root:
if len(pat_parts) != len(parts):
return False
pat_parts = pat_parts[1:]
elif len(pat_parts) > len(parts):
return False
for part, pat in zip(reversed(parts), reversed(pat_parts)):
if not fnmatch.fnmatchcase(part, pat):
return False
return True | def match(self, path_pattern):
"""
Return True if this path matches the given pattern.
"""
cf = self._flavour.casefold
path_pattern = cf(path_pattern)
drv, root, pat_parts = self._flavour.parse_parts((path_pattern,))
if not pat_parts:
raise ValueError("empty pattern")
if drv and drv != cf(self._drv):
return False
if root and root != cf(self._root):
return False
parts = self._cparts
if drv or root:
if len(pat_parts) != len(parts):
return False
pat_parts = pat_parts[1:]
elif len(pat_parts) > len(parts):
return False
for part, pat in zip(reversed(parts), reversed(pat_parts)):
if not fnmatch.fnmatchcase(part, pat):
return False
return True | [
"Return",
"True",
"if",
"this",
"path",
"matches",
"the",
"given",
"pattern",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1138-L1161 | [
"def",
"match",
"(",
"self",
",",
"path_pattern",
")",
":",
"cf",
"=",
"self",
".",
"_flavour",
".",
"casefold",
"path_pattern",
"=",
"cf",
"(",
"path_pattern",
")",
"drv",
",",
"root",
",",
"pat_parts",
"=",
"self",
".",
"_flavour",
".",
"parse_parts",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Path._raw_open | Open the file pointed by this path and return a file descriptor,
as os.open() does. | pipenv/vendor/pathlib2/__init__.py | def _raw_open(self, flags, mode=0o777):
"""
Open the file pointed by this path and return a file descriptor,
as os.open() does.
"""
if self._closed:
self._raise_closed()
return self._accessor.open(self, flags, mode) | def _raw_open(self, flags, mode=0o777):
"""
Open the file pointed by this path and return a file descriptor,
as os.open() does.
"""
if self._closed:
self._raise_closed()
return self._accessor.open(self, flags, mode) | [
"Open",
"the",
"file",
"pointed",
"by",
"this",
"path",
"and",
"return",
"a",
"file",
"descriptor",
"as",
"os",
".",
"open",
"()",
"does",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1230-L1237 | [
"def",
"_raw_open",
"(",
"self",
",",
"flags",
",",
"mode",
"=",
"0o777",
")",
":",
"if",
"self",
".",
"_closed",
":",
"self",
".",
"_raise_closed",
"(",
")",
"return",
"self",
".",
"_accessor",
".",
"open",
"(",
"self",
",",
"flags",
",",
"mode",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Path.samefile | Return whether other_path is the same or not as this file
(as returned by os.path.samefile()). | pipenv/vendor/pathlib2/__init__.py | def samefile(self, other_path):
"""Return whether other_path is the same or not as this file
(as returned by os.path.samefile()).
"""
if hasattr(os.path, "samestat"):
st = self.stat()
try:
other_st = other_path.stat()
except AttributeError:
other_st = os.stat(other_path)
return os.path.samestat(st, other_st)
else:
filename1 = six.text_type(self)
filename2 = six.text_type(other_path)
st1 = _win32_get_unique_path_id(filename1)
st2 = _win32_get_unique_path_id(filename2)
return st1 == st2 | def samefile(self, other_path):
"""Return whether other_path is the same or not as this file
(as returned by os.path.samefile()).
"""
if hasattr(os.path, "samestat"):
st = self.stat()
try:
other_st = other_path.stat()
except AttributeError:
other_st = os.stat(other_path)
return os.path.samestat(st, other_st)
else:
filename1 = six.text_type(self)
filename2 = six.text_type(other_path)
st1 = _win32_get_unique_path_id(filename1)
st2 = _win32_get_unique_path_id(filename2)
return st1 == st2 | [
"Return",
"whether",
"other_path",
"is",
"the",
"same",
"or",
"not",
"as",
"this",
"file",
"(",
"as",
"returned",
"by",
"os",
".",
"path",
".",
"samefile",
"()",
")",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1255-L1271 | [
"def",
"samefile",
"(",
"self",
",",
"other_path",
")",
":",
"if",
"hasattr",
"(",
"os",
".",
"path",
",",
"\"samestat\"",
")",
":",
"st",
"=",
"self",
".",
"stat",
"(",
")",
"try",
":",
"other_st",
"=",
"other_path",
".",
"stat",
"(",
")",
"except... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Path.iterdir | Iterate over the files in this directory. Does not yield any
result for the special paths '.' and '..'. | pipenv/vendor/pathlib2/__init__.py | def iterdir(self):
"""Iterate over the files in this directory. Does not yield any
result for the special paths '.' and '..'.
"""
if self._closed:
self._raise_closed()
for name in self._accessor.listdir(self):
if name in ('.', '..'):
# Yielding a path object for these makes little sense
continue
yield self._make_child_relpath(name)
if self._closed:
self._raise_closed() | def iterdir(self):
"""Iterate over the files in this directory. Does not yield any
result for the special paths '.' and '..'.
"""
if self._closed:
self._raise_closed()
for name in self._accessor.listdir(self):
if name in ('.', '..'):
# Yielding a path object for these makes little sense
continue
yield self._make_child_relpath(name)
if self._closed:
self._raise_closed() | [
"Iterate",
"over",
"the",
"files",
"in",
"this",
"directory",
".",
"Does",
"not",
"yield",
"any",
"result",
"for",
"the",
"special",
"paths",
".",
"and",
"..",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1273-L1285 | [
"def",
"iterdir",
"(",
"self",
")",
":",
"if",
"self",
".",
"_closed",
":",
"self",
".",
"_raise_closed",
"(",
")",
"for",
"name",
"in",
"self",
".",
"_accessor",
".",
"listdir",
"(",
"self",
")",
":",
"if",
"name",
"in",
"(",
"'.'",
",",
"'..'",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Path.touch | Create this file with the given access mode, if it doesn't exist. | pipenv/vendor/pathlib2/__init__.py | def touch(self, mode=0o666, exist_ok=True):
"""
Create this file with the given access mode, if it doesn't exist.
"""
if self._closed:
self._raise_closed()
if exist_ok:
# First try to bump modification time
# Implementation note: GNU touch uses the UTIME_NOW option of
# the utimensat() / futimens() functions.
try:
self._accessor.utime(self, None)
except OSError:
# Avoid exception chaining
pass
else:
return
flags = os.O_CREAT | os.O_WRONLY
if not exist_ok:
flags |= os.O_EXCL
fd = self._raw_open(flags, mode)
os.close(fd) | def touch(self, mode=0o666, exist_ok=True):
"""
Create this file with the given access mode, if it doesn't exist.
"""
if self._closed:
self._raise_closed()
if exist_ok:
# First try to bump modification time
# Implementation note: GNU touch uses the UTIME_NOW option of
# the utimensat() / futimens() functions.
try:
self._accessor.utime(self, None)
except OSError:
# Avoid exception chaining
pass
else:
return
flags = os.O_CREAT | os.O_WRONLY
if not exist_ok:
flags |= os.O_EXCL
fd = self._raw_open(flags, mode)
os.close(fd) | [
"Create",
"this",
"file",
"with",
"the",
"given",
"access",
"mode",
"if",
"it",
"doesn",
"t",
"exist",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1424-L1445 | [
"def",
"touch",
"(",
"self",
",",
"mode",
"=",
"0o666",
",",
"exist_ok",
"=",
"True",
")",
":",
"if",
"self",
".",
"_closed",
":",
"self",
".",
"_raise_closed",
"(",
")",
"if",
"exist_ok",
":",
"# First try to bump modification time",
"# Implementation note: G... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Path.mkdir | Create a new directory at this given path. | pipenv/vendor/pathlib2/__init__.py | def mkdir(self, mode=0o777, parents=False, exist_ok=False):
"""
Create a new directory at this given path.
"""
if self._closed:
self._raise_closed()
def _try_func():
self._accessor.mkdir(self, mode)
def _exc_func(exc):
if not parents or self.parent == self:
raise exc
self.parent.mkdir(parents=True, exist_ok=True)
self.mkdir(mode, parents=False, exist_ok=exist_ok)
try:
_try_except_filenotfounderror(_try_func, _exc_func)
except OSError:
if not exist_ok or not self.is_dir():
raise | def mkdir(self, mode=0o777, parents=False, exist_ok=False):
"""
Create a new directory at this given path.
"""
if self._closed:
self._raise_closed()
def _try_func():
self._accessor.mkdir(self, mode)
def _exc_func(exc):
if not parents or self.parent == self:
raise exc
self.parent.mkdir(parents=True, exist_ok=True)
self.mkdir(mode, parents=False, exist_ok=exist_ok)
try:
_try_except_filenotfounderror(_try_func, _exc_func)
except OSError:
if not exist_ok or not self.is_dir():
raise | [
"Create",
"a",
"new",
"directory",
"at",
"this",
"given",
"path",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1447-L1467 | [
"def",
"mkdir",
"(",
"self",
",",
"mode",
"=",
"0o777",
",",
"parents",
"=",
"False",
",",
"exist_ok",
"=",
"False",
")",
":",
"if",
"self",
".",
"_closed",
":",
"self",
".",
"_raise_closed",
"(",
")",
"def",
"_try_func",
"(",
")",
":",
"self",
"."... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Path.chmod | Change the permissions of the path, like os.chmod(). | pipenv/vendor/pathlib2/__init__.py | def chmod(self, mode):
"""
Change the permissions of the path, like os.chmod().
"""
if self._closed:
self._raise_closed()
self._accessor.chmod(self, mode) | def chmod(self, mode):
"""
Change the permissions of the path, like os.chmod().
"""
if self._closed:
self._raise_closed()
self._accessor.chmod(self, mode) | [
"Change",
"the",
"permissions",
"of",
"the",
"path",
"like",
"os",
".",
"chmod",
"()",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1469-L1475 | [
"def",
"chmod",
"(",
"self",
",",
"mode",
")",
":",
"if",
"self",
".",
"_closed",
":",
"self",
".",
"_raise_closed",
"(",
")",
"self",
".",
"_accessor",
".",
"chmod",
"(",
"self",
",",
"mode",
")"
] | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Path.lchmod | Like chmod(), except if the path points to a symlink, the symlink's
permissions are changed, rather than its target's. | pipenv/vendor/pathlib2/__init__.py | def lchmod(self, mode):
"""
Like chmod(), except if the path points to a symlink, the symlink's
permissions are changed, rather than its target's.
"""
if self._closed:
self._raise_closed()
self._accessor.lchmod(self, mode) | def lchmod(self, mode):
"""
Like chmod(), except if the path points to a symlink, the symlink's
permissions are changed, rather than its target's.
"""
if self._closed:
self._raise_closed()
self._accessor.lchmod(self, mode) | [
"Like",
"chmod",
"()",
"except",
"if",
"the",
"path",
"points",
"to",
"a",
"symlink",
"the",
"symlink",
"s",
"permissions",
"are",
"changed",
"rather",
"than",
"its",
"target",
"s",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1477-L1484 | [
"def",
"lchmod",
"(",
"self",
",",
"mode",
")",
":",
"if",
"self",
".",
"_closed",
":",
"self",
".",
"_raise_closed",
"(",
")",
"self",
".",
"_accessor",
".",
"lchmod",
"(",
"self",
",",
"mode",
")"
] | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Path.unlink | Remove this file or link.
If the path is a directory, use rmdir() instead. | pipenv/vendor/pathlib2/__init__.py | def unlink(self):
"""
Remove this file or link.
If the path is a directory, use rmdir() instead.
"""
if self._closed:
self._raise_closed()
self._accessor.unlink(self) | def unlink(self):
"""
Remove this file or link.
If the path is a directory, use rmdir() instead.
"""
if self._closed:
self._raise_closed()
self._accessor.unlink(self) | [
"Remove",
"this",
"file",
"or",
"link",
".",
"If",
"the",
"path",
"is",
"a",
"directory",
"use",
"rmdir",
"()",
"instead",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1486-L1493 | [
"def",
"unlink",
"(",
"self",
")",
":",
"if",
"self",
".",
"_closed",
":",
"self",
".",
"_raise_closed",
"(",
")",
"self",
".",
"_accessor",
".",
"unlink",
"(",
"self",
")"
] | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Path.rmdir | Remove this directory. The directory must be empty. | pipenv/vendor/pathlib2/__init__.py | def rmdir(self):
"""
Remove this directory. The directory must be empty.
"""
if self._closed:
self._raise_closed()
self._accessor.rmdir(self) | def rmdir(self):
"""
Remove this directory. The directory must be empty.
"""
if self._closed:
self._raise_closed()
self._accessor.rmdir(self) | [
"Remove",
"this",
"directory",
".",
"The",
"directory",
"must",
"be",
"empty",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1495-L1501 | [
"def",
"rmdir",
"(",
"self",
")",
":",
"if",
"self",
".",
"_closed",
":",
"self",
".",
"_raise_closed",
"(",
")",
"self",
".",
"_accessor",
".",
"rmdir",
"(",
"self",
")"
] | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Path.lstat | Like stat(), except if the path points to a symlink, the symlink's
status information is returned, rather than its target's. | pipenv/vendor/pathlib2/__init__.py | def lstat(self):
"""
Like stat(), except if the path points to a symlink, the symlink's
status information is returned, rather than its target's.
"""
if self._closed:
self._raise_closed()
return self._accessor.lstat(self) | def lstat(self):
"""
Like stat(), except if the path points to a symlink, the symlink's
status information is returned, rather than its target's.
"""
if self._closed:
self._raise_closed()
return self._accessor.lstat(self) | [
"Like",
"stat",
"()",
"except",
"if",
"the",
"path",
"points",
"to",
"a",
"symlink",
"the",
"symlink",
"s",
"status",
"information",
"is",
"returned",
"rather",
"than",
"its",
"target",
"s",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1503-L1510 | [
"def",
"lstat",
"(",
"self",
")",
":",
"if",
"self",
".",
"_closed",
":",
"self",
".",
"_raise_closed",
"(",
")",
"return",
"self",
".",
"_accessor",
".",
"lstat",
"(",
"self",
")"
] | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Path.rename | Rename this path to the given path. | pipenv/vendor/pathlib2/__init__.py | def rename(self, target):
"""
Rename this path to the given path.
"""
if self._closed:
self._raise_closed()
self._accessor.rename(self, target) | def rename(self, target):
"""
Rename this path to the given path.
"""
if self._closed:
self._raise_closed()
self._accessor.rename(self, target) | [
"Rename",
"this",
"path",
"to",
"the",
"given",
"path",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1512-L1518 | [
"def",
"rename",
"(",
"self",
",",
"target",
")",
":",
"if",
"self",
".",
"_closed",
":",
"self",
".",
"_raise_closed",
"(",
")",
"self",
".",
"_accessor",
".",
"rename",
"(",
"self",
",",
"target",
")"
] | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Path.replace | Rename this path to the given path, clobbering the existing
destination if it exists. | pipenv/vendor/pathlib2/__init__.py | def replace(self, target):
"""
Rename this path to the given path, clobbering the existing
destination if it exists.
"""
if sys.version_info < (3, 3):
raise NotImplementedError("replace() is only available "
"with Python 3.3 and later")
if self._closed:
self._raise_closed()
self._accessor.replace(self, target) | def replace(self, target):
"""
Rename this path to the given path, clobbering the existing
destination if it exists.
"""
if sys.version_info < (3, 3):
raise NotImplementedError("replace() is only available "
"with Python 3.3 and later")
if self._closed:
self._raise_closed()
self._accessor.replace(self, target) | [
"Rename",
"this",
"path",
"to",
"the",
"given",
"path",
"clobbering",
"the",
"existing",
"destination",
"if",
"it",
"exists",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1520-L1530 | [
"def",
"replace",
"(",
"self",
",",
"target",
")",
":",
"if",
"sys",
".",
"version_info",
"<",
"(",
"3",
",",
"3",
")",
":",
"raise",
"NotImplementedError",
"(",
"\"replace() is only available \"",
"\"with Python 3.3 and later\"",
")",
"if",
"self",
".",
"_clo... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Path.symlink_to | Make this path a symlink pointing to the given path.
Note the order of arguments (self, target) is the reverse of
os.symlink's. | pipenv/vendor/pathlib2/__init__.py | def symlink_to(self, target, target_is_directory=False):
"""
Make this path a symlink pointing to the given path.
Note the order of arguments (self, target) is the reverse of
os.symlink's.
"""
if self._closed:
self._raise_closed()
self._accessor.symlink(target, self, target_is_directory) | def symlink_to(self, target, target_is_directory=False):
"""
Make this path a symlink pointing to the given path.
Note the order of arguments (self, target) is the reverse of
os.symlink's.
"""
if self._closed:
self._raise_closed()
self._accessor.symlink(target, self, target_is_directory) | [
"Make",
"this",
"path",
"a",
"symlink",
"pointing",
"to",
"the",
"given",
"path",
".",
"Note",
"the",
"order",
"of",
"arguments",
"(",
"self",
"target",
")",
"is",
"the",
"reverse",
"of",
"os",
".",
"symlink",
"s",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1532-L1540 | [
"def",
"symlink_to",
"(",
"self",
",",
"target",
",",
"target_is_directory",
"=",
"False",
")",
":",
"if",
"self",
".",
"_closed",
":",
"self",
".",
"_raise_closed",
"(",
")",
"self",
".",
"_accessor",
".",
"symlink",
"(",
"target",
",",
"self",
",",
"... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Path.exists | Whether this path exists. | pipenv/vendor/pathlib2/__init__.py | def exists(self):
"""
Whether this path exists.
"""
try:
self.stat()
except OSError as e:
if e.errno not in (ENOENT, ENOTDIR):
raise
return False
return True | def exists(self):
"""
Whether this path exists.
"""
try:
self.stat()
except OSError as e:
if e.errno not in (ENOENT, ENOTDIR):
raise
return False
return True | [
"Whether",
"this",
"path",
"exists",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1544-L1554 | [
"def",
"exists",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"stat",
"(",
")",
"except",
"OSError",
"as",
"e",
":",
"if",
"e",
".",
"errno",
"not",
"in",
"(",
"ENOENT",
",",
"ENOTDIR",
")",
":",
"raise",
"return",
"False",
"return",
"True"
] | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Path.is_dir | Whether this path is a directory. | pipenv/vendor/pathlib2/__init__.py | def is_dir(self):
"""
Whether this path is a directory.
"""
try:
return S_ISDIR(self.stat().st_mode)
except OSError as e:
if e.errno not in (ENOENT, ENOTDIR):
raise
# Path doesn't exist or is a broken symlink
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
return False | def is_dir(self):
"""
Whether this path is a directory.
"""
try:
return S_ISDIR(self.stat().st_mode)
except OSError as e:
if e.errno not in (ENOENT, ENOTDIR):
raise
# Path doesn't exist or is a broken symlink
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
return False | [
"Whether",
"this",
"path",
"is",
"a",
"directory",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1556-L1567 | [
"def",
"is_dir",
"(",
"self",
")",
":",
"try",
":",
"return",
"S_ISDIR",
"(",
"self",
".",
"stat",
"(",
")",
".",
"st_mode",
")",
"except",
"OSError",
"as",
"e",
":",
"if",
"e",
".",
"errno",
"not",
"in",
"(",
"ENOENT",
",",
"ENOTDIR",
")",
":",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Path.is_file | Whether this path is a regular file (also True for symlinks pointing
to regular files). | pipenv/vendor/pathlib2/__init__.py | def is_file(self):
"""
Whether this path is a regular file (also True for symlinks pointing
to regular files).
"""
try:
return S_ISREG(self.stat().st_mode)
except OSError as e:
if e.errno not in (ENOENT, ENOTDIR):
raise
# Path doesn't exist or is a broken symlink
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
return False | def is_file(self):
"""
Whether this path is a regular file (also True for symlinks pointing
to regular files).
"""
try:
return S_ISREG(self.stat().st_mode)
except OSError as e:
if e.errno not in (ENOENT, ENOTDIR):
raise
# Path doesn't exist or is a broken symlink
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
return False | [
"Whether",
"this",
"path",
"is",
"a",
"regular",
"file",
"(",
"also",
"True",
"for",
"symlinks",
"pointing",
"to",
"regular",
"files",
")",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1569-L1581 | [
"def",
"is_file",
"(",
"self",
")",
":",
"try",
":",
"return",
"S_ISREG",
"(",
"self",
".",
"stat",
"(",
")",
".",
"st_mode",
")",
"except",
"OSError",
"as",
"e",
":",
"if",
"e",
".",
"errno",
"not",
"in",
"(",
"ENOENT",
",",
"ENOTDIR",
")",
":",... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Path.is_fifo | Whether this path is a FIFO. | pipenv/vendor/pathlib2/__init__.py | def is_fifo(self):
"""
Whether this path is a FIFO.
"""
try:
return S_ISFIFO(self.stat().st_mode)
except OSError as e:
if e.errno not in (ENOENT, ENOTDIR):
raise
# Path doesn't exist or is a broken symlink
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
return False | def is_fifo(self):
"""
Whether this path is a FIFO.
"""
try:
return S_ISFIFO(self.stat().st_mode)
except OSError as e:
if e.errno not in (ENOENT, ENOTDIR):
raise
# Path doesn't exist or is a broken symlink
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
return False | [
"Whether",
"this",
"path",
"is",
"a",
"FIFO",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1621-L1632 | [
"def",
"is_fifo",
"(",
"self",
")",
":",
"try",
":",
"return",
"S_ISFIFO",
"(",
"self",
".",
"stat",
"(",
")",
".",
"st_mode",
")",
"except",
"OSError",
"as",
"e",
":",
"if",
"e",
".",
"errno",
"not",
"in",
"(",
"ENOENT",
",",
"ENOTDIR",
")",
":"... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Path.is_socket | Whether this path is a socket. | pipenv/vendor/pathlib2/__init__.py | def is_socket(self):
"""
Whether this path is a socket.
"""
try:
return S_ISSOCK(self.stat().st_mode)
except OSError as e:
if e.errno not in (ENOENT, ENOTDIR):
raise
# Path doesn't exist or is a broken symlink
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
return False | def is_socket(self):
"""
Whether this path is a socket.
"""
try:
return S_ISSOCK(self.stat().st_mode)
except OSError as e:
if e.errno not in (ENOENT, ENOTDIR):
raise
# Path doesn't exist or is a broken symlink
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
return False | [
"Whether",
"this",
"path",
"is",
"a",
"socket",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1634-L1645 | [
"def",
"is_socket",
"(",
"self",
")",
":",
"try",
":",
"return",
"S_ISSOCK",
"(",
"self",
".",
"stat",
"(",
")",
".",
"st_mode",
")",
"except",
"OSError",
"as",
"e",
":",
"if",
"e",
".",
"errno",
"not",
"in",
"(",
"ENOENT",
",",
"ENOTDIR",
")",
"... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | Path.expanduser | Return a new path with expanded ~ and ~user constructs
(as returned by os.path.expanduser) | pipenv/vendor/pathlib2/__init__.py | def expanduser(self):
""" Return a new path with expanded ~ and ~user constructs
(as returned by os.path.expanduser)
"""
if (not (self._drv or self._root)
and self._parts and self._parts[0][:1] == '~'):
homedir = self._flavour.gethomedir(self._parts[0][1:])
return self._from_parts([homedir] + self._parts[1:])
return self | def expanduser(self):
""" Return a new path with expanded ~ and ~user constructs
(as returned by os.path.expanduser)
"""
if (not (self._drv or self._root)
and self._parts and self._parts[0][:1] == '~'):
homedir = self._flavour.gethomedir(self._parts[0][1:])
return self._from_parts([homedir] + self._parts[1:])
return self | [
"Return",
"a",
"new",
"path",
"with",
"expanded",
"~",
"and",
"~user",
"constructs",
"(",
"as",
"returned",
"by",
"os",
".",
"path",
".",
"expanduser",
")"
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pathlib2/__init__.py#L1647-L1656 | [
"def",
"expanduser",
"(",
"self",
")",
":",
"if",
"(",
"not",
"(",
"self",
".",
"_drv",
"or",
"self",
".",
"_root",
")",
"and",
"self",
".",
"_parts",
"and",
"self",
".",
"_parts",
"[",
"0",
"]",
"[",
":",
"1",
"]",
"==",
"'~'",
")",
":",
"ho... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | lookupEncoding | Return the python codec name corresponding to an encoding or None if the
string doesn't correspond to a valid encoding. | pipenv/patched/notpip/_vendor/html5lib/_inputstream.py | def lookupEncoding(encoding):
"""Return the python codec name corresponding to an encoding or None if the
string doesn't correspond to a valid encoding."""
if isinstance(encoding, binary_type):
try:
encoding = encoding.decode("ascii")
except UnicodeDecodeError:
return None
if encoding is not None:
try:
return webencodings.lookup(encoding)
except AttributeError:
return None
else:
return None | def lookupEncoding(encoding):
"""Return the python codec name corresponding to an encoding or None if the
string doesn't correspond to a valid encoding."""
if isinstance(encoding, binary_type):
try:
encoding = encoding.decode("ascii")
except UnicodeDecodeError:
return None
if encoding is not None:
try:
return webencodings.lookup(encoding)
except AttributeError:
return None
else:
return None | [
"Return",
"the",
"python",
"codec",
"name",
"corresponding",
"to",
"an",
"encoding",
"or",
"None",
"if",
"the",
"string",
"doesn",
"t",
"correspond",
"to",
"a",
"valid",
"encoding",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/html5lib/_inputstream.py#L908-L923 | [
"def",
"lookupEncoding",
"(",
"encoding",
")",
":",
"if",
"isinstance",
"(",
"encoding",
",",
"binary_type",
")",
":",
"try",
":",
"encoding",
"=",
"encoding",
".",
"decode",
"(",
"\"ascii\"",
")",
"except",
"UnicodeDecodeError",
":",
"return",
"None",
"if",... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | HTMLUnicodeInputStream.openStream | Produces a file object from source.
source can be either a file object, local filename or a string. | pipenv/patched/notpip/_vendor/html5lib/_inputstream.py | def openStream(self, source):
"""Produces a file object from source.
source can be either a file object, local filename or a string.
"""
# Already a file object
if hasattr(source, 'read'):
stream = source
else:
stream = StringIO(source)
return stream | def openStream(self, source):
"""Produces a file object from source.
source can be either a file object, local filename or a string.
"""
# Already a file object
if hasattr(source, 'read'):
stream = source
else:
stream = StringIO(source)
return stream | [
"Produces",
"a",
"file",
"object",
"from",
"source",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/html5lib/_inputstream.py#L210-L222 | [
"def",
"openStream",
"(",
"self",
",",
"source",
")",
":",
"# Already a file object",
"if",
"hasattr",
"(",
"source",
",",
"'read'",
")",
":",
"stream",
"=",
"source",
"else",
":",
"stream",
"=",
"StringIO",
"(",
"source",
")",
"return",
"stream"
] | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | HTMLUnicodeInputStream.position | Returns (line, col) of the current position in the stream. | pipenv/patched/notpip/_vendor/html5lib/_inputstream.py | def position(self):
"""Returns (line, col) of the current position in the stream."""
line, col = self._position(self.chunkOffset)
return (line + 1, col) | def position(self):
"""Returns (line, col) of the current position in the stream."""
line, col = self._position(self.chunkOffset)
return (line + 1, col) | [
"Returns",
"(",
"line",
"col",
")",
"of",
"the",
"current",
"position",
"in",
"the",
"stream",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/html5lib/_inputstream.py#L235-L238 | [
"def",
"position",
"(",
"self",
")",
":",
"line",
",",
"col",
"=",
"self",
".",
"_position",
"(",
"self",
".",
"chunkOffset",
")",
"return",
"(",
"line",
"+",
"1",
",",
"col",
")"
] | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | HTMLUnicodeInputStream.char | Read one character from the stream or queue if available. Return
EOF when EOF is reached. | pipenv/patched/notpip/_vendor/html5lib/_inputstream.py | def char(self):
""" Read one character from the stream or queue if available. Return
EOF when EOF is reached.
"""
# Read a new chunk from the input stream if necessary
if self.chunkOffset >= self.chunkSize:
if not self.readChunk():
return EOF
chunkOffset = self.chunkOffset
char = self.chunk[chunkOffset]
self.chunkOffset = chunkOffset + 1
return char | def char(self):
""" Read one character from the stream or queue if available. Return
EOF when EOF is reached.
"""
# Read a new chunk from the input stream if necessary
if self.chunkOffset >= self.chunkSize:
if not self.readChunk():
return EOF
chunkOffset = self.chunkOffset
char = self.chunk[chunkOffset]
self.chunkOffset = chunkOffset + 1
return char | [
"Read",
"one",
"character",
"from",
"the",
"stream",
"or",
"queue",
"if",
"available",
".",
"Return",
"EOF",
"when",
"EOF",
"is",
"reached",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/html5lib/_inputstream.py#L240-L253 | [
"def",
"char",
"(",
"self",
")",
":",
"# Read a new chunk from the input stream if necessary",
"if",
"self",
".",
"chunkOffset",
">=",
"self",
".",
"chunkSize",
":",
"if",
"not",
"self",
".",
"readChunk",
"(",
")",
":",
"return",
"EOF",
"chunkOffset",
"=",
"se... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | HTMLUnicodeInputStream.charsUntil | Returns a string of characters from the stream up to but not
including any character in 'characters' or EOF. 'characters' must be
a container that supports the 'in' method and iteration over its
characters. | pipenv/patched/notpip/_vendor/html5lib/_inputstream.py | def charsUntil(self, characters, opposite=False):
""" Returns a string of characters from the stream up to but not
including any character in 'characters' or EOF. 'characters' must be
a container that supports the 'in' method and iteration over its
characters.
"""
# Use a cache of regexps to find the required characters
try:
chars = charsUntilRegEx[(characters, opposite)]
except KeyError:
if __debug__:
for c in characters:
assert(ord(c) < 128)
regex = "".join(["\\x%02x" % ord(c) for c in characters])
if not opposite:
regex = "^%s" % regex
chars = charsUntilRegEx[(characters, opposite)] = re.compile("[%s]+" % regex)
rv = []
while True:
# Find the longest matching prefix
m = chars.match(self.chunk, self.chunkOffset)
if m is None:
# If nothing matched, and it wasn't because we ran out of chunk,
# then stop
if self.chunkOffset != self.chunkSize:
break
else:
end = m.end()
# If not the whole chunk matched, return everything
# up to the part that didn't match
if end != self.chunkSize:
rv.append(self.chunk[self.chunkOffset:end])
self.chunkOffset = end
break
# If the whole remainder of the chunk matched,
# use it all and read the next chunk
rv.append(self.chunk[self.chunkOffset:])
if not self.readChunk():
# Reached EOF
break
r = "".join(rv)
return r | def charsUntil(self, characters, opposite=False):
""" Returns a string of characters from the stream up to but not
including any character in 'characters' or EOF. 'characters' must be
a container that supports the 'in' method and iteration over its
characters.
"""
# Use a cache of regexps to find the required characters
try:
chars = charsUntilRegEx[(characters, opposite)]
except KeyError:
if __debug__:
for c in characters:
assert(ord(c) < 128)
regex = "".join(["\\x%02x" % ord(c) for c in characters])
if not opposite:
regex = "^%s" % regex
chars = charsUntilRegEx[(characters, opposite)] = re.compile("[%s]+" % regex)
rv = []
while True:
# Find the longest matching prefix
m = chars.match(self.chunk, self.chunkOffset)
if m is None:
# If nothing matched, and it wasn't because we ran out of chunk,
# then stop
if self.chunkOffset != self.chunkSize:
break
else:
end = m.end()
# If not the whole chunk matched, return everything
# up to the part that didn't match
if end != self.chunkSize:
rv.append(self.chunk[self.chunkOffset:end])
self.chunkOffset = end
break
# If the whole remainder of the chunk matched,
# use it all and read the next chunk
rv.append(self.chunk[self.chunkOffset:])
if not self.readChunk():
# Reached EOF
break
r = "".join(rv)
return r | [
"Returns",
"a",
"string",
"of",
"characters",
"from",
"the",
"stream",
"up",
"to",
"but",
"not",
"including",
"any",
"character",
"in",
"characters",
"or",
"EOF",
".",
"characters",
"must",
"be",
"a",
"container",
"that",
"supports",
"the",
"in",
"method",
... | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/html5lib/_inputstream.py#L320-L365 | [
"def",
"charsUntil",
"(",
"self",
",",
"characters",
",",
"opposite",
"=",
"False",
")",
":",
"# Use a cache of regexps to find the required characters",
"try",
":",
"chars",
"=",
"charsUntilRegEx",
"[",
"(",
"characters",
",",
"opposite",
")",
"]",
"except",
"Key... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | HTMLBinaryInputStream.openStream | Produces a file object from source.
source can be either a file object, local filename or a string. | pipenv/patched/notpip/_vendor/html5lib/_inputstream.py | def openStream(self, source):
"""Produces a file object from source.
source can be either a file object, local filename or a string.
"""
# Already a file object
if hasattr(source, 'read'):
stream = source
else:
stream = BytesIO(source)
try:
stream.seek(stream.tell())
except: # pylint:disable=bare-except
stream = BufferedStream(stream)
return stream | def openStream(self, source):
"""Produces a file object from source.
source can be either a file object, local filename or a string.
"""
# Already a file object
if hasattr(source, 'read'):
stream = source
else:
stream = BytesIO(source)
try:
stream.seek(stream.tell())
except: # pylint:disable=bare-except
stream = BufferedStream(stream)
return stream | [
"Produces",
"a",
"file",
"object",
"from",
"source",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/html5lib/_inputstream.py#L438-L455 | [
"def",
"openStream",
"(",
"self",
",",
"source",
")",
":",
"# Already a file object",
"if",
"hasattr",
"(",
"source",
",",
"'read'",
")",
":",
"stream",
"=",
"source",
"else",
":",
"stream",
"=",
"BytesIO",
"(",
"source",
")",
"try",
":",
"stream",
".",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | HTMLBinaryInputStream.detectEncodingMeta | Report the encoding declared by the meta element | pipenv/patched/notpip/_vendor/html5lib/_inputstream.py | def detectEncodingMeta(self):
"""Report the encoding declared by the meta element
"""
buffer = self.rawStream.read(self.numBytesMeta)
assert isinstance(buffer, bytes)
parser = EncodingParser(buffer)
self.rawStream.seek(0)
encoding = parser.getEncoding()
if encoding is not None and encoding.name in ("utf-16be", "utf-16le"):
encoding = lookupEncoding("utf-8")
return encoding | def detectEncodingMeta(self):
"""Report the encoding declared by the meta element
"""
buffer = self.rawStream.read(self.numBytesMeta)
assert isinstance(buffer, bytes)
parser = EncodingParser(buffer)
self.rawStream.seek(0)
encoding = parser.getEncoding()
if encoding is not None and encoding.name in ("utf-16be", "utf-16le"):
encoding = lookupEncoding("utf-8")
return encoding | [
"Report",
"the",
"encoding",
"declared",
"by",
"the",
"meta",
"element"
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/html5lib/_inputstream.py#L569-L581 | [
"def",
"detectEncodingMeta",
"(",
"self",
")",
":",
"buffer",
"=",
"self",
".",
"rawStream",
".",
"read",
"(",
"self",
".",
"numBytesMeta",
")",
"assert",
"isinstance",
"(",
"buffer",
",",
"bytes",
")",
"parser",
"=",
"EncodingParser",
"(",
"buffer",
")",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | EncodingBytes.skip | Skip past a list of characters | pipenv/patched/notpip/_vendor/html5lib/_inputstream.py | def skip(self, chars=spaceCharactersBytes):
"""Skip past a list of characters"""
p = self.position # use property for the error-checking
while p < len(self):
c = self[p:p + 1]
if c not in chars:
self._position = p
return c
p += 1
self._position = p
return None | def skip(self, chars=spaceCharactersBytes):
"""Skip past a list of characters"""
p = self.position # use property for the error-checking
while p < len(self):
c = self[p:p + 1]
if c not in chars:
self._position = p
return c
p += 1
self._position = p
return None | [
"Skip",
"past",
"a",
"list",
"of",
"characters"
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/html5lib/_inputstream.py#L640-L650 | [
"def",
"skip",
"(",
"self",
",",
"chars",
"=",
"spaceCharactersBytes",
")",
":",
"p",
"=",
"self",
".",
"position",
"# use property for the error-checking",
"while",
"p",
"<",
"len",
"(",
"self",
")",
":",
"c",
"=",
"self",
"[",
"p",
":",
"p",
"+",
"1"... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | EncodingBytes.matchBytes | Look for a sequence of bytes at the start of a string. If the bytes
are found return True and advance the position to the byte after the
match. Otherwise return False and leave the position alone | pipenv/patched/notpip/_vendor/html5lib/_inputstream.py | def matchBytes(self, bytes):
"""Look for a sequence of bytes at the start of a string. If the bytes
are found return True and advance the position to the byte after the
match. Otherwise return False and leave the position alone"""
p = self.position
data = self[p:p + len(bytes)]
rv = data.startswith(bytes)
if rv:
self.position += len(bytes)
return rv | def matchBytes(self, bytes):
"""Look for a sequence of bytes at the start of a string. If the bytes
are found return True and advance the position to the byte after the
match. Otherwise return False and leave the position alone"""
p = self.position
data = self[p:p + len(bytes)]
rv = data.startswith(bytes)
if rv:
self.position += len(bytes)
return rv | [
"Look",
"for",
"a",
"sequence",
"of",
"bytes",
"at",
"the",
"start",
"of",
"a",
"string",
".",
"If",
"the",
"bytes",
"are",
"found",
"return",
"True",
"and",
"advance",
"the",
"position",
"to",
"the",
"byte",
"after",
"the",
"match",
".",
"Otherwise",
... | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/html5lib/_inputstream.py#L663-L672 | [
"def",
"matchBytes",
"(",
"self",
",",
"bytes",
")",
":",
"p",
"=",
"self",
".",
"position",
"data",
"=",
"self",
"[",
"p",
":",
"p",
"+",
"len",
"(",
"bytes",
")",
"]",
"rv",
"=",
"data",
".",
"startswith",
"(",
"bytes",
")",
"if",
"rv",
":",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | EncodingBytes.jumpTo | Look for the next sequence of bytes matching a given sequence. If
a match is found advance the position to the last byte of the match | pipenv/patched/notpip/_vendor/html5lib/_inputstream.py | def jumpTo(self, bytes):
"""Look for the next sequence of bytes matching a given sequence. If
a match is found advance the position to the last byte of the match"""
newPosition = self[self.position:].find(bytes)
if newPosition > -1:
# XXX: This is ugly, but I can't see a nicer way to fix this.
if self._position == -1:
self._position = 0
self._position += (newPosition + len(bytes) - 1)
return True
else:
raise StopIteration | def jumpTo(self, bytes):
"""Look for the next sequence of bytes matching a given sequence. If
a match is found advance the position to the last byte of the match"""
newPosition = self[self.position:].find(bytes)
if newPosition > -1:
# XXX: This is ugly, but I can't see a nicer way to fix this.
if self._position == -1:
self._position = 0
self._position += (newPosition + len(bytes) - 1)
return True
else:
raise StopIteration | [
"Look",
"for",
"the",
"next",
"sequence",
"of",
"bytes",
"matching",
"a",
"given",
"sequence",
".",
"If",
"a",
"match",
"is",
"found",
"advance",
"the",
"position",
"to",
"the",
"last",
"byte",
"of",
"the",
"match"
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/html5lib/_inputstream.py#L674-L685 | [
"def",
"jumpTo",
"(",
"self",
",",
"bytes",
")",
":",
"newPosition",
"=",
"self",
"[",
"self",
".",
"position",
":",
"]",
".",
"find",
"(",
"bytes",
")",
"if",
"newPosition",
">",
"-",
"1",
":",
"# XXX: This is ugly, but I can't see a nicer way to fix this.",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | EncodingParser.getAttribute | Return a name,value pair for the next attribute in the stream,
if one is found, or None | pipenv/patched/notpip/_vendor/html5lib/_inputstream.py | def getAttribute(self):
"""Return a name,value pair for the next attribute in the stream,
if one is found, or None"""
data = self.data
# Step 1 (skip chars)
c = data.skip(spaceCharactersBytes | frozenset([b"/"]))
assert c is None or len(c) == 1
# Step 2
if c in (b">", None):
return None
# Step 3
attrName = []
attrValue = []
# Step 4 attribute name
while True:
if c == b"=" and attrName:
break
elif c in spaceCharactersBytes:
# Step 6!
c = data.skip()
break
elif c in (b"/", b">"):
return b"".join(attrName), b""
elif c in asciiUppercaseBytes:
attrName.append(c.lower())
elif c is None:
return None
else:
attrName.append(c)
# Step 5
c = next(data)
# Step 7
if c != b"=":
data.previous()
return b"".join(attrName), b""
# Step 8
next(data)
# Step 9
c = data.skip()
# Step 10
if c in (b"'", b'"'):
# 10.1
quoteChar = c
while True:
# 10.2
c = next(data)
# 10.3
if c == quoteChar:
next(data)
return b"".join(attrName), b"".join(attrValue)
# 10.4
elif c in asciiUppercaseBytes:
attrValue.append(c.lower())
# 10.5
else:
attrValue.append(c)
elif c == b">":
return b"".join(attrName), b""
elif c in asciiUppercaseBytes:
attrValue.append(c.lower())
elif c is None:
return None
else:
attrValue.append(c)
# Step 11
while True:
c = next(data)
if c in spacesAngleBrackets:
return b"".join(attrName), b"".join(attrValue)
elif c in asciiUppercaseBytes:
attrValue.append(c.lower())
elif c is None:
return None
else:
attrValue.append(c) | def getAttribute(self):
"""Return a name,value pair for the next attribute in the stream,
if one is found, or None"""
data = self.data
# Step 1 (skip chars)
c = data.skip(spaceCharactersBytes | frozenset([b"/"]))
assert c is None or len(c) == 1
# Step 2
if c in (b">", None):
return None
# Step 3
attrName = []
attrValue = []
# Step 4 attribute name
while True:
if c == b"=" and attrName:
break
elif c in spaceCharactersBytes:
# Step 6!
c = data.skip()
break
elif c in (b"/", b">"):
return b"".join(attrName), b""
elif c in asciiUppercaseBytes:
attrName.append(c.lower())
elif c is None:
return None
else:
attrName.append(c)
# Step 5
c = next(data)
# Step 7
if c != b"=":
data.previous()
return b"".join(attrName), b""
# Step 8
next(data)
# Step 9
c = data.skip()
# Step 10
if c in (b"'", b'"'):
# 10.1
quoteChar = c
while True:
# 10.2
c = next(data)
# 10.3
if c == quoteChar:
next(data)
return b"".join(attrName), b"".join(attrValue)
# 10.4
elif c in asciiUppercaseBytes:
attrValue.append(c.lower())
# 10.5
else:
attrValue.append(c)
elif c == b">":
return b"".join(attrName), b""
elif c in asciiUppercaseBytes:
attrValue.append(c.lower())
elif c is None:
return None
else:
attrValue.append(c)
# Step 11
while True:
c = next(data)
if c in spacesAngleBrackets:
return b"".join(attrName), b"".join(attrValue)
elif c in asciiUppercaseBytes:
attrValue.append(c.lower())
elif c is None:
return None
else:
attrValue.append(c) | [
"Return",
"a",
"name",
"value",
"pair",
"for",
"the",
"next",
"attribute",
"in",
"the",
"stream",
"if",
"one",
"is",
"found",
"or",
"None"
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/html5lib/_inputstream.py#L792-L866 | [
"def",
"getAttribute",
"(",
"self",
")",
":",
"data",
"=",
"self",
".",
"data",
"# Step 1 (skip chars)",
"c",
"=",
"data",
".",
"skip",
"(",
"spaceCharactersBytes",
"|",
"frozenset",
"(",
"[",
"b\"/\"",
"]",
")",
")",
"assert",
"c",
"is",
"None",
"or",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | _build_backend | Find and load the build backend | pipenv/vendor/pep517/_in_process.py | def _build_backend():
"""Find and load the build backend"""
ep = os.environ['PEP517_BUILD_BACKEND']
mod_path, _, obj_path = ep.partition(':')
try:
obj = import_module(mod_path)
except ImportError:
raise BackendUnavailable
if obj_path:
for path_part in obj_path.split('.'):
obj = getattr(obj, path_part)
return obj | def _build_backend():
"""Find and load the build backend"""
ep = os.environ['PEP517_BUILD_BACKEND']
mod_path, _, obj_path = ep.partition(':')
try:
obj = import_module(mod_path)
except ImportError:
raise BackendUnavailable
if obj_path:
for path_part in obj_path.split('.'):
obj = getattr(obj, path_part)
return obj | [
"Find",
"and",
"load",
"the",
"build",
"backend"
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pep517/_in_process.py#L29-L40 | [
"def",
"_build_backend",
"(",
")",
":",
"ep",
"=",
"os",
".",
"environ",
"[",
"'PEP517_BUILD_BACKEND'",
"]",
"mod_path",
",",
"_",
",",
"obj_path",
"=",
"ep",
".",
"partition",
"(",
"':'",
")",
"try",
":",
"obj",
"=",
"import_module",
"(",
"mod_path",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | get_requires_for_build_wheel | Invoke the optional get_requires_for_build_wheel hook
Returns [] if the hook is not defined. | pipenv/vendor/pep517/_in_process.py | def get_requires_for_build_wheel(config_settings):
"""Invoke the optional get_requires_for_build_wheel hook
Returns [] if the hook is not defined.
"""
backend = _build_backend()
try:
hook = backend.get_requires_for_build_wheel
except AttributeError:
return []
else:
return hook(config_settings) | def get_requires_for_build_wheel(config_settings):
"""Invoke the optional get_requires_for_build_wheel hook
Returns [] if the hook is not defined.
"""
backend = _build_backend()
try:
hook = backend.get_requires_for_build_wheel
except AttributeError:
return []
else:
return hook(config_settings) | [
"Invoke",
"the",
"optional",
"get_requires_for_build_wheel",
"hook"
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pep517/_in_process.py#L43-L54 | [
"def",
"get_requires_for_build_wheel",
"(",
"config_settings",
")",
":",
"backend",
"=",
"_build_backend",
"(",
")",
"try",
":",
"hook",
"=",
"backend",
".",
"get_requires_for_build_wheel",
"except",
"AttributeError",
":",
"return",
"[",
"]",
"else",
":",
"return"... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | prepare_metadata_for_build_wheel | Invoke optional prepare_metadata_for_build_wheel
Implements a fallback by building a wheel if the hook isn't defined. | pipenv/vendor/pep517/_in_process.py | def prepare_metadata_for_build_wheel(metadata_directory, config_settings):
"""Invoke optional prepare_metadata_for_build_wheel
Implements a fallback by building a wheel if the hook isn't defined.
"""
backend = _build_backend()
try:
hook = backend.prepare_metadata_for_build_wheel
except AttributeError:
return _get_wheel_metadata_from_wheel(backend, metadata_directory,
config_settings)
else:
return hook(metadata_directory, config_settings) | def prepare_metadata_for_build_wheel(metadata_directory, config_settings):
"""Invoke optional prepare_metadata_for_build_wheel
Implements a fallback by building a wheel if the hook isn't defined.
"""
backend = _build_backend()
try:
hook = backend.prepare_metadata_for_build_wheel
except AttributeError:
return _get_wheel_metadata_from_wheel(backend, metadata_directory,
config_settings)
else:
return hook(metadata_directory, config_settings) | [
"Invoke",
"optional",
"prepare_metadata_for_build_wheel"
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pep517/_in_process.py#L57-L69 | [
"def",
"prepare_metadata_for_build_wheel",
"(",
"metadata_directory",
",",
"config_settings",
")",
":",
"backend",
"=",
"_build_backend",
"(",
")",
"try",
":",
"hook",
"=",
"backend",
".",
"prepare_metadata_for_build_wheel",
"except",
"AttributeError",
":",
"return",
... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
train | _dist_info_files | Identify the .dist-info folder inside a wheel ZipFile. | pipenv/vendor/pep517/_in_process.py | def _dist_info_files(whl_zip):
"""Identify the .dist-info folder inside a wheel ZipFile."""
res = []
for path in whl_zip.namelist():
m = re.match(r'[^/\\]+-[^/\\]+\.dist-info/', path)
if m:
res.append(path)
if res:
return res
raise Exception("No .dist-info folder found in wheel") | def _dist_info_files(whl_zip):
"""Identify the .dist-info folder inside a wheel ZipFile."""
res = []
for path in whl_zip.namelist():
m = re.match(r'[^/\\]+-[^/\\]+\.dist-info/', path)
if m:
res.append(path)
if res:
return res
raise Exception("No .dist-info folder found in wheel") | [
"Identify",
"the",
".",
"dist",
"-",
"info",
"folder",
"inside",
"a",
"wheel",
"ZipFile",
"."
] | pypa/pipenv | python | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pep517/_in_process.py#L75-L84 | [
"def",
"_dist_info_files",
"(",
"whl_zip",
")",
":",
"res",
"=",
"[",
"]",
"for",
"path",
"in",
"whl_zip",
".",
"namelist",
"(",
")",
":",
"m",
"=",
"re",
".",
"match",
"(",
"r'[^/\\\\]+-[^/\\\\]+\\.dist-info/'",
",",
"path",
")",
"if",
"m",
":",
"res"... | cae8d76c210b9777e90aab76e9c4b0e53bb19cde |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.