get_ed25519ll()    <EOL>recipients = jwsjs["<STR_LIT>"]<EOL>encoded_payload = binary(jwsjs["<STR_LIT>"])<EOL>headers = []<EOL>for recipient in recipients:<EOL><INDENT>assertTrue(len(recipient) == <NUM_LIT:2>, "<STR_LIT>".format(recipient))<EOL>h = binary(recipient["<STR_LIT>"])<EOL>s = binary(recipient["<STR_LIT>"])<EOL>header = json.loads(native(urlsafe_b64decode(h)))<EOL>assertTrue(header["<STR_LIT>"] == ALG, <EOL>"<STR_LIT>".format(header["<STR_LIT>"]))<EOL>if "<STR_LIT>" in header["<STR_LIT>"] and not "<STR_LIT>" in header["<STR_LIT>"]:<EOL><INDENT>header["<STR_LIT>"]["<STR_LIT>"] = header["<STR_LIT>"]["<STR_LIT>"] <EOL><DEDENT>assertTrue(header["<STR_LIT>"]["<STR_LIT>"] == ALG, <EOL>"<STR_LIT>".format(header["<STR_LIT>"]["<STR_LIT>"]))<EOL>vk = urlsafe_b64decode(binary(header["<STR_LIT>"]["<STR_LIT>"]))<EOL>secured_input = b"<STR_LIT:.>".join((h, encoded_payload))<EOL>sig = urlsafe_b64decode(s)<EOL>sig_msg = sig+secured_input<EOL>verified_input = native(ed25519ll.crypto_sign_open(sig_msg, vk))<EOL>verified_header, verified_payload = verified_input.split('<STR_LIT:.>')<EOL>verified_header = binary(verified_header)<EOL>decoded_header = native(urlsafe_b64decode(verified_header))<EOL>headers.append(json.loads(decoded_header))<EOL><DEDENT>verified_payload = binary(verified_payload)<EOL>payload = json.loads(native(urlsafe_b64decode(verified_payload)))<EOL>return headers, payload<EOL>

Return (decoded headers, payload) if all signatures in jwsjs are
    consistent, else raise ValueError.

    Caller must decide whether the keys are actually trusted.


if seed is None:<EOL><INDENT>seed = os.urandom(PUBLICKEYBYTES)<EOL><DEDENT>else:<EOL><INDENT>warnings.warn("<STR_LIT>",<EOL>RuntimeWarning)<EOL><DEDENT>if len(seed) != <NUM_LIT:32>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>skbytes = seed<EOL>vkbytes = djbec.publickey(skbytes)<EOL>return Keypair(vkbytes, skbytes+vkbytes)<EOL>

Return (verifying, secret) key from a given seed, or os.urandom(32)


if len(sk) != SECRETKEYBYTES:<EOL><INDENT>raise ValueError("<STR_LIT>" % len(sk))<EOL><DEDENT>vkbytes = sk[PUBLICKEYBYTES:]<EOL>skbytes = sk[:PUBLICKEYBYTES]<EOL>sig = djbec.signature(msg, skbytes, vkbytes)<EOL>return sig + msg<EOL>

Return signature+message given message and secret key.
    The signature is the first SIGNATUREBYTES bytes of the return value.
    A copy of msg is in the remainder.


if len(vk) != PUBLICKEYBYTES:<EOL><INDENT>raise ValueError("<STR_LIT>" % len(vk))<EOL><DEDENT>rc = djbec.checkvalid(signed[:SIGNATUREBYTES], signed[SIGNATUREBYTES:], vk)<EOL>if not rc:<EOL><INDENT>raise ValueError("<STR_LIT>", rc)    <EOL><DEDENT>return signed[SIGNATUREBYTES:]<EOL>

Return message given signature+message and the verifying key.


WheelKeys, keyring = get_keyring()<EOL>ed25519ll = signatures.get_ed25519ll()<EOL>wk = WheelKeys().load()<EOL>keypair = ed25519ll.crypto_sign_keypair()<EOL>vk = native(urlsafe_b64encode(keypair.vk))<EOL>sk = native(urlsafe_b64encode(keypair.sk))<EOL>kr = keyring.get_keyring()<EOL>kr.set_password("<STR_LIT>", vk, sk)<EOL>sys.stdout.write("<STR_LIT>".format(vk))<EOL>if isinstance(kr, keyring.backends.file.BaseKeyring):<EOL><INDENT>sys.stdout.write("<STR_LIT>".format(kr.file_path))<EOL><DEDENT>else:<EOL><INDENT>sys.stdout.write("<STR_LIT>" % kr.__class__)<EOL><DEDENT>sk2 = kr.get_password('<STR_LIT>', vk)<EOL>if sk2 != sk:<EOL><INDENT>raise WheelError("<STR_LIT>")<EOL><DEDENT>sys.stdout.write("<STR_LIT>".format(vk))<EOL>wk.add_signer('<STR_LIT:+>', vk)<EOL>wk.trust('<STR_LIT:+>', vk)<EOL>wk.save()<EOL>


def sign(wheelfile, replace=False, get_keyring=get_keyring):

WheelKeys, keyring = get_keyring()<EOL>ed25519ll = signatures.get_ed25519ll()<EOL>wf = WheelFile(wheelfile, append=True)<EOL>wk = WheelKeys().load()<EOL>name = wf.parsed_filename.group('<STR_LIT:name>')<EOL>sign_with = wk.signers(name)[<NUM_LIT:0>]<EOL>sys.stdout.write("<STR_LIT>".format(name, sign_with[<NUM_LIT:1>]))<EOL>vk = sign_with[<NUM_LIT:1>]<EOL>kr = keyring.get_keyring()<EOL>sk = kr.get_password('<STR_LIT>', vk)<EOL>keypair = ed25519ll.Keypair(urlsafe_b64decode(binary(vk)),<EOL>urlsafe_b64decode(binary(sk)))<EOL>record_name = wf.distinfo_name + '<STR_LIT>'<EOL>sig_name = wf.distinfo_name + '<STR_LIT>'<EOL>if sig_name in wf.zipfile.namelist():<EOL><INDENT>raise WheelError("<STR_LIT>")<EOL><DEDENT>record_data = wf.zipfile.read(record_name)<EOL>payload = {"<STR_LIT>":"<STR_LIT>" + native(urlsafe_b64encode(hashlib.sha256(record_data).digest()))}<EOL>sig = signatures.sign(payload, keypair)<EOL>wf.zipfile.writestr(sig_name, json.dumps(sig, sort_keys=True))<EOL>wf.zipfile.close()<EOL>


import wheel.install<EOL>vzf = wheel.install.VerifyingZipFile(wheelfile, "<STR_LIT:a>")<EOL>info = vzf.infolist()<EOL>if not (len(info) and info[-<NUM_LIT:1>].filename.endswith('<STR_LIT>')):<EOL><INDENT>raise WheelError("<STR_LIT>")<EOL><DEDENT>vzf.pop()<EOL>vzf.close()<EOL>

Remove RECORD.jws from a wheel by truncating the zip file.

RECORD.jws must be at the end of the archive. The zip file must be an
ordinary archive, with the compressed files and the directory in the same
order, and without any non-zip content after the truncation point.


wf = WheelFile(wheelfile)<EOL>sig_name = wf.distinfo_name + '<STR_LIT>'<EOL>sig = json.loads(native(wf.zipfile.open(sig_name).read()))<EOL>verified = signatures.verify(sig)<EOL>sys.stderr.write("<STR_LIT>")<EOL>sys.stdout.write(json.dumps(verified, indent=<NUM_LIT:2>))<EOL>sys.stdout.write('<STR_LIT:\n>')<EOL>

Verify a wheel.

    The signature will be verified for internal consistency ONLY and printed.
    Wheel's own unpack/install commands verify the manifest against the
    signature and file contents.


wf = WheelFile(wheelfile)<EOL>namever = wf.parsed_filename.group('<STR_LIT>')<EOL>destination = os.path.join(dest, namever)<EOL>sys.stderr.write("<STR_LIT>" % (destination))<EOL>wf.zipfile.extractall(destination)<EOL>wf.zipfile.close()<EOL>

Unpack a wheel.

    Wheel content will be unpacked to {dest}/{name}-{ver}, where {name}
    is the package name and {ver} its version.

    :param wheelfile: The path to the wheel.
    :param dest: Destination directory (default to current directory).


def install(requirements, requirements_file=None,<EOL>wheel_dirs=None, force=False, list_files=False,<EOL>dry_run=False):

<EOL>if not wheel_dirs:<EOL><INDENT>wheelpath = os.getenv("<STR_LIT>")<EOL>if wheelpath:<EOL><INDENT>wheel_dirs = wheelpath.split(os.pathsep)<EOL><DEDENT>else:<EOL><INDENT>wheel_dirs = [ os.path.curdir ]<EOL><DEDENT><DEDENT>all_wheels = []<EOL>for d in wheel_dirs:<EOL><INDENT>for w in os.listdir(d):<EOL><INDENT>if w.endswith('<STR_LIT>'):<EOL><INDENT>wf = WheelFile(os.path.join(d, w))<EOL>if wf.compatible:<EOL><INDENT>all_wheels.append(wf)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if requirements_file:<EOL><INDENT>if not os.path.exists(requirements_file):<EOL><INDENT>for d in wheel_dirs:<EOL><INDENT>name = os.path.join(d, requirements_file)<EOL>if os.path.exists(name):<EOL><INDENT>requirements_file = name<EOL>break<EOL><DEDENT><DEDENT><DEDENT>with open(requirements_file) as fd:<EOL><INDENT>requirements.extend(fd)<EOL><DEDENT><DEDENT>to_install = []<EOL>for req in requirements:<EOL><INDENT>if req.endswith('<STR_LIT>'):<EOL><INDENT>if os.path.exists(req):<EOL><INDENT>wf = WheelFile(req)<EOL>if wf.compatible or force:<EOL><INDENT>to_install.append(wf)<EOL><DEDENT>else:<EOL><INDENT>msg = ("<STR_LIT>"<EOL>"<STR_LIT>".format(req))<EOL>raise WheelError(msg)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise WheelError("<STR_LIT>".format(req))<EOL><DEDENT>continue<EOL><DEDENT>matches = matches_requirement(req, all_wheels)<EOL>if not matches:<EOL><INDENT>raise WheelError("<STR_LIT>".format(req))<EOL><DEDENT>to_install.append(max(matches))<EOL><DEDENT>if list_files:<EOL><INDENT>sys.stdout.write("<STR_LIT>")<EOL><DEDENT>if dry_run:<EOL><INDENT>return<EOL><DEDENT>for wf in to_install:<EOL><INDENT>if list_files:<EOL><INDENT>sys.stdout.write("<STR_LIT>".format(wf.filename))<EOL>continue<EOL><DEDENT>wf.install(force=force)<EOL>wf.zipfile.close()<EOL><DEDENT>

Install wheels.

    :param requirements: A list of requirements or wheel files to install.
    :param requirements_file: A file containing requirements to install.
    :param wheel_dirs: A list of directories to search for wheels.
    :param force: Install a wheel file even if it is not compatible.
    :param list_files: Only list the files to install, don't install them.
    :param dry_run: Do everything but the actual install.


try:<EOL><INDENT>from setuptools.command import easy_install<EOL>import pkg_resources<EOL><DEDENT>except ImportError:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>for dist in distributions:<EOL><INDENT>pkg_resources_dist = pkg_resources.get_distribution(dist)<EOL>install = wheel.paths.get_install_command(dist)<EOL>command = easy_install.easy_install(install.distribution)<EOL>command.args = ['<STR_LIT>'] <EOL>command.finalize_options()<EOL>command.install_egg_scripts(pkg_resources_dist)<EOL><DEDENT>

Regenerate the entry_points console_scripts for the named distribution.


if header.lower() == '<STR_LIT:description>':  <EOL><INDENT>return '<STR_LIT:\n>'.join([x[<NUM_LIT:8>:] if x.startswith('<STR_LIT:U+0020>' * <NUM_LIT:8>) else x<EOL>for x in txt.strip().splitlines()])<EOL><DEDENT>else:<EOL><INDENT>return '<STR_LIT:U+0020>'.join([x.strip() for x in txt.splitlines()])<EOL><DEDENT>

``Description`` header must preserve newlines; all others need not


if isinstance(path_or_module, ModuleType):<EOL><INDENT>try:<EOL><INDENT>return Installed(path_or_module, metadata_version)<EOL><DEDENT>except (ValueError, IOError): <EOL><INDENT>pass<EOL><DEDENT><DEDENT>try:<EOL><INDENT>__import__(path_or_module)<EOL><DEDENT>except ImportError:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>return Installed(path_or_module, metadata_version)<EOL><DEDENT>except (ValueError, IOError): <EOL><INDENT>pass<EOL><DEDENT><DEDENT>if os.path.isfile(path_or_module):<EOL><INDENT>try:<EOL><INDENT>return SDist(path_or_module, metadata_version)<EOL><DEDENT>except (ValueError, IOError):<EOL><INDENT>pass<EOL><DEDENT>try:<EOL><INDENT>return BDist(path_or_module, metadata_version)<EOL><DEDENT>except (ValueError, IOError): <EOL><INDENT>pass<EOL><DEDENT>try:<EOL><INDENT>return Wheel(path_or_module, metadata_version)<EOL><DEDENT>except (ValueError, IOError): <EOL><INDENT>pass<EOL><DEDENT><DEDENT>if os.path.isdir(path_or_module):<EOL><INDENT>try:<EOL><INDENT>return Develop(path_or_module, metadata_version)<EOL><DEDENT>except (ValueError, IOError): <EOL><INDENT>pass<EOL><DEDENT><DEDENT>

Try to create a Distribution 'path_or_module'.

    o 'path_or_module' may be a module object.

    o If a string, 'path_or_module' may point to an sdist file, a bdist
      file, an installed package, or a working checkout (if it contains
      PKG-INFO).

    o Return None if 'path_or_module' can't be parsed.


options, paths = _parse_options(args)<EOL>format = getattr(options, '<STR_LIT>', '<STR_LIT>')<EOL>formatter = _FORMATTERS[format](options)<EOL>for path in paths:<EOL><INDENT>meta = get_metadata(path, options.metadata_version)<EOL>if meta is None:<EOL><INDENT>continue<EOL><DEDENT>if options.download_url_prefix:<EOL><INDENT>if meta.download_url is None:<EOL><INDENT>filename = os.path.basename(path)<EOL>meta.download_url = '<STR_LIT>' % (options.download_url_prefix,<EOL>filename)<EOL><DEDENT><DEDENT>formatter(meta)<EOL><DEDENT>formatter.finish()<EOL>


temp_dir = tempfile.mkdtemp('<STR_LIT>', '<STR_LIT>')<EOL>self.unpack(temp_dir)<EOL>try:<EOL><INDENT>if not location.endswith('<STR_LIT:/>'):<EOL><INDENT>location = location + '<STR_LIT:/>'<EOL><DEDENT>call_subprocess(<EOL>[self.cmd, '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', location],<EOL>filter_stdout=self._filter, show_stdout=False, cwd=temp_dir)<EOL><DEDENT>finally:<EOL><INDENT>rmtree(temp_dir)<EOL><DEDENT>

Export the Git repository at the url to the destination location


def check_rev_options(self, rev, dest, rev_options):

revisions = self.get_refs(dest)<EOL>origin_rev = '<STR_LIT>' % rev<EOL>if origin_rev in revisions:<EOL><INDENT>return [revisions[origin_rev]]<EOL><DEDENT>elif rev in revisions:<EOL><INDENT>return [revisions[rev]]<EOL><DEDENT>else:<EOL><INDENT>logger.warning(<EOL>"<STR_LIT>", rev,<EOL>)<EOL>return rev_options<EOL><DEDENT>

Check the revision options before checkout to compensate that tags
        and branches may need origin/ as a prefix.
        Returns the SHA1 of the branch or tag if found.


output = call_subprocess([self.cmd, '<STR_LIT>'],<EOL>show_stdout=False, cwd=location)<EOL>rv = {}<EOL>for line in output.strip().splitlines():<EOL><INDENT>commit, ref = line.split('<STR_LIT:U+0020>', <NUM_LIT:1>)<EOL>ref = ref.strip()<EOL>ref_name = None<EOL>if ref.startswith('<STR_LIT>'):<EOL><INDENT>ref_name = ref[len('<STR_LIT>'):]<EOL><DEDENT>elif ref.startswith('<STR_LIT>'):<EOL><INDENT>ref_name = ref[len('<STR_LIT>'):]<EOL><DEDENT>elif ref.startswith('<STR_LIT>'):<EOL><INDENT>ref_name = ref[len('<STR_LIT>'):]<EOL><DEDENT>if ref_name is not None:<EOL><INDENT>rv[ref_name] = commit.strip()<EOL><DEDENT><DEDENT>return rv<EOL>

Return map of named refs (branches or tags) to commit hashes.


if '<STR_LIT>' not in self.url:<EOL><INDENT>assert '<STR_LIT>' not in self.url<EOL>self.url = self.url.replace('<STR_LIT>', '<STR_LIT>')<EOL>url, rev = super(Git, self).get_url_rev()<EOL>url = url.replace('<STR_LIT>', '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>url, rev = super(Git, self).get_url_rev()<EOL><DEDENT>return url, rev<EOL>

Prefixes stub URLs like 'user@hostname:user/repo.git' with 'ssh://'.
That's required because although they use SSH they sometimes doesn't
work with a ssh:// scheme (e.g. Github). But we need a scheme for
parsing. Hence we remove it again afterwards and return it as a stub.


assert not location.rstrip('<STR_LIT:/>').endswith(self.dirname),'<STR_LIT>' % location<EOL>output = call_subprocess(<EOL>[self.cmd, '<STR_LIT:info>', location],<EOL>show_stdout=False,<EOL>extra_environ={'<STR_LIT>': '<STR_LIT:C>'},<EOL>)<EOL>match = _svn_url_re.search(output)<EOL>if not match:<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>',<EOL>display_path(location),<EOL>)<EOL>logger.debug('<STR_LIT>', output)<EOL>return None, None<EOL><DEDENT>url = match.group(<NUM_LIT:1>).strip()<EOL>match = _svn_revision_re.search(output)<EOL>if not match:<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>',<EOL>display_path(location),<EOL>)<EOL>logger.debug('<STR_LIT>', output)<EOL>return url, None<EOL><DEDENT>return url, match.group(<NUM_LIT:1>)<EOL>

Returns (url, revision), where both are strings


url, rev = self.get_url_rev()<EOL>rev_options = get_rev_options(url, rev)<EOL>logger.info('<STR_LIT>', url, location)<EOL>with indent_log():<EOL><INDENT>if os.path.exists(location):<EOL><INDENT>rmtree(location)<EOL><DEDENT>call_subprocess(<EOL>[self.cmd, '<STR_LIT>'] + rev_options + [url, location],<EOL>filter_stdout=self._filter, show_stdout=False)<EOL><DEDENT>

Export the svn repository at the url to the destination location


<EOL>revision = <NUM_LIT:0><EOL>for base, dirs, files in os.walk(location):<EOL><INDENT>if self.dirname not in dirs:<EOL><INDENT>dirs[:] = []<EOL>continue    <EOL><DEDENT>dirs.remove(self.dirname)<EOL>entries_fn = os.path.join(base, self.dirname, '<STR_LIT>')<EOL>if not os.path.exists(entries_fn):<EOL><INDENT>continue<EOL><DEDENT>dirurl, localrev = self._get_svn_url_rev(base)<EOL>if base == location:<EOL><INDENT>base_url = dirurl + '<STR_LIT:/>'   <EOL><DEDENT>elif not dirurl or not dirurl.startswith(base_url):<EOL><INDENT>dirs[:] = []<EOL>continue    <EOL><DEDENT>revision = max(revision, localrev)<EOL><DEDENT>return revision<EOL>

Return the maximum revision for all files under a given location


temp_dir = tempfile.mkdtemp('<STR_LIT>', '<STR_LIT>')<EOL>self.unpack(temp_dir)<EOL>try:<EOL><INDENT>call_subprocess(<EOL>[self.cmd, '<STR_LIT>', location],<EOL>filter_stdout=self._filter, show_stdout=False, cwd=temp_dir)<EOL><DEDENT>finally:<EOL><INDENT>rmtree(temp_dir)<EOL><DEDENT>

Export the Hg repository at the url to the destination location


for vc_type in self._registry.values():<EOL><INDENT>path = os.path.join(location, vc_type.dirname)<EOL>if os.path.exists(path):<EOL><INDENT>return vc_type.name<EOL><DEDENT><DEDENT>return None<EOL>

Return the name of the version control backend if found at given
location, e.g. vcs.get_backend_name('/path/to/vcs/checkout')


drive, tail = os.path.splitdrive(repo)<EOL>return repo.startswith(os.path.sep) or drive<EOL>

posix absolute paths start with os.path.sep,
win32 ones ones start with drive (like c:\\folder)


raise NotImplementedError<EOL>

Export the repository at the url to the destination location
i.e. only download the files, without vcs informations


error_message = (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL>assert '<STR_LIT:+>' in self.url, error_message % self.url<EOL>url = self.url.split('<STR_LIT:+>', <NUM_LIT:1>)[<NUM_LIT:1>]<EOL>scheme, netloc, path, query, frag = urllib_parse.urlsplit(url)<EOL>rev = None<EOL>if '<STR_LIT:@>' in path:<EOL><INDENT>path, rev = path.rsplit('<STR_LIT:@>', <NUM_LIT:1>)<EOL><DEDENT>url = urllib_parse.urlunsplit((scheme, netloc, path, query, '<STR_LIT>'))<EOL>return url, rev<EOL>

Returns the correct repository URL and revision by parsing the given
repository URL


assert not location.rstrip('<STR_LIT:/>').endswith(self.dirname),'<STR_LIT>' % location<EOL>return self.get_url(location), self.get_revision(location)<EOL>


return urllib_parse.unquote(url).rstrip('<STR_LIT:/>')<EOL>

Normalize a URL for comparison by unquoting it and removing any
trailing slash.


return (self.normalize_url(url1) == self.normalize_url(url2))<EOL>

Compare two repo URLs for identity, ignoring incidental differences.


raise NotImplementedError<EOL>

Called when installing or updating an editable package, takes the
source path of the checkout.


def switch(self, dest, url, rev_options):

raise NotImplementedError<EOL>

Switch the repo at ``dest`` to point to ``URL``.


raise NotImplementedError<EOL>

Update an already-existing repo to the given ``rev_options``.


def check_destination(self, dest, url, rev_options, rev_display):

checkout = True<EOL>prompt = False<EOL>if os.path.exists(dest):<EOL><INDENT>checkout = False<EOL>if os.path.exists(os.path.join(dest, self.dirname)):<EOL><INDENT>existing_url = self.get_url(dest)<EOL>if self.compare_urls(existing_url, url):<EOL><INDENT>logger.debug(<EOL>'<STR_LIT>',<EOL>self.repo_name.title(),<EOL>display_path(dest),<EOL>url,<EOL>)<EOL>logger.info(<EOL>'<STR_LIT>',<EOL>display_path(dest),<EOL>self.repo_name,<EOL>rev_display,<EOL>)<EOL>self.update(dest, rev_options)<EOL><DEDENT>else:<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>',<EOL>self.name,<EOL>self.repo_name,<EOL>display_path(dest),<EOL>existing_url,<EOL>)<EOL>prompt = ('<STR_LIT>',<EOL>('<STR_LIT:s>', '<STR_LIT:i>', '<STR_LIT:w>', '<STR_LIT:b>'))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>',<EOL>dest,<EOL>self.name,<EOL>self.repo_name,<EOL>)<EOL>prompt = ('<STR_LIT>', ('<STR_LIT:i>', '<STR_LIT:w>', '<STR_LIT:b>'))<EOL><DEDENT><DEDENT>if prompt:<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>',<EOL>self.name,<EOL>url,<EOL>)<EOL>response = ask_path_exists('<STR_LIT>' % prompt[<NUM_LIT:0>],<EOL>prompt[<NUM_LIT:1>])<EOL>if response == '<STR_LIT:s>':<EOL><INDENT>logger.info(<EOL>'<STR_LIT>',<EOL>self.repo_name,<EOL>display_path(dest),<EOL>url,<EOL>rev_display,<EOL>)<EOL>self.switch(dest, url, rev_options)<EOL><DEDENT>elif response == '<STR_LIT:i>':<EOL><INDENT>pass<EOL><DEDENT>elif response == '<STR_LIT:w>':<EOL><INDENT>logger.warning('<STR_LIT>', display_path(dest))<EOL>rmtree(dest)<EOL>checkout = True<EOL><DEDENT>elif response == '<STR_LIT:b>':<EOL><INDENT>dest_dir = backup_dir(dest)<EOL>logger.warning(<EOL>'<STR_LIT>', display_path(dest), dest_dir,<EOL>)<EOL>shutil.move(dest, dest_dir)<EOL>checkout = True<EOL><DEDENT><DEDENT>return checkout<EOL>

Prepare a location to receive a checkout/clone.

Return True if the location is ready for (and requires) a
checkout/clone, False otherwise.


if os.path.exists(location):<EOL><INDENT>rmtree(location)<EOL><DEDENT>self.obtain(location)<EOL>

Clean up current location and download the url repository
(and vcs infos) into location


def get_src_requirement(self, dist, location, find_tags=False):

raise NotImplementedError<EOL>

Return a string representing the requirement needed to
redownload the files currently present in location, something
like:
  {repository_url}@{revision}#egg={project_name}-{version_identifier}
If find_tags is True, try to find a tag matching the revision


raise NotImplementedError<EOL>

Return the url used at location
Used in get_info or check_destination


raise NotImplementedError<EOL>

Return the current revision of the files at location
Used in get_info


temp_dir = tempfile.mkdtemp('<STR_LIT>', '<STR_LIT>')<EOL>self.unpack(temp_dir)<EOL>if os.path.exists(location):<EOL><INDENT>rmtree(location)<EOL><DEDENT>try:<EOL><INDENT>call_subprocess([self.cmd, '<STR_LIT>', location], cwd=temp_dir,<EOL>filter_stdout=self._filter, show_stdout=False)<EOL><DEDENT>finally:<EOL><INDENT>rmtree(temp_dir)<EOL><DEDENT>

Export the Bazaar repository at the url to the destination location


data = {<EOL>"<STR_LIT>": {"<STR_LIT:name>": "<STR_LIT>", "<STR_LIT:version>": pip.__version__},<EOL>"<STR_LIT>": platform.python_version(),<EOL>"<STR_LIT>": {<EOL>"<STR_LIT:name>": platform.python_implementation(),<EOL>},<EOL>}<EOL>if data["<STR_LIT>"]["<STR_LIT:name>"] == '<STR_LIT>':<EOL><INDENT>data["<STR_LIT>"]["<STR_LIT:version>"] = platform.python_version()<EOL><DEDENT>elif data["<STR_LIT>"]["<STR_LIT:name>"] == '<STR_LIT>':<EOL><INDENT>if sys.pypy_version_info.releaselevel == '<STR_LIT>':<EOL><INDENT>pypy_version_info = sys.pypy_version_info[:<NUM_LIT:3>]<EOL><DEDENT>else:<EOL><INDENT>pypy_version_info = sys.pypy_version_info<EOL><DEDENT>data["<STR_LIT>"]["<STR_LIT:version>"] = "<STR_LIT:.>".join(<EOL>[str(x) for x in pypy_version_info]<EOL>)<EOL><DEDENT>elif data["<STR_LIT>"]["<STR_LIT:name>"] == '<STR_LIT>':<EOL><INDENT>data["<STR_LIT>"]["<STR_LIT:version>"] = platform.python_version()<EOL><DEDENT>elif data["<STR_LIT>"]["<STR_LIT:name>"] == '<STR_LIT>':<EOL><INDENT>data["<STR_LIT>"]["<STR_LIT:version>"] = platform.python_version()<EOL><DEDENT>if sys.platform.startswith("<STR_LIT>"):<EOL><INDENT>distro = dict(filter(<EOL>lambda x: x[<NUM_LIT:1>],<EOL>zip(["<STR_LIT:name>", "<STR_LIT:version>", "<STR_LIT:id>"], platform.linux_distribution()),<EOL>))<EOL>libc = dict(filter(<EOL>lambda x: x[<NUM_LIT:1>],<EOL>zip(["<STR_LIT>", "<STR_LIT:version>"], platform.libc_ver()),<EOL>))<EOL>if libc:<EOL><INDENT>distro["<STR_LIT>"] = libc<EOL><DEDENT>if distro:<EOL><INDENT>data["<STR_LIT>"] = distro<EOL><DEDENT><DEDENT>if sys.platform.startswith("<STR_LIT>") and platform.mac_ver()[<NUM_LIT:0>]:<EOL><INDENT>data["<STR_LIT>"] = {"<STR_LIT:name>": "<STR_LIT>", "<STR_LIT:version>": platform.mac_ver()[<NUM_LIT:0>]}<EOL><DEDENT>if platform.system():<EOL><INDENT>data.setdefault("<STR_LIT>", {})["<STR_LIT:name>"] = platform.system()<EOL><DEDENT>if platform.release():<EOL><INDENT>data.setdefault("<STR_LIT>", {})["<STR_LIT>"] = platform.release()<EOL><DEDENT>if platform.machine():<EOL><INDENT>data["<STR_LIT>"] = platform.machine()<EOL><DEDENT>return "<STR_LIT>".format(<EOL>data=data,<EOL>json=json.dumps(data, separators=("<STR_LIT:U+002C>", "<STR_LIT::>"), sort_keys=True),<EOL>)<EOL>

Return a string representing the user agent.


def get_file_content(url, comes_from=None, session=None):

if session is None:<EOL><INDENT>raise TypeError(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>match = _scheme_re.search(url)<EOL>if match:<EOL><INDENT>scheme = match.group(<NUM_LIT:1>).lower()<EOL>if (scheme == '<STR_LIT:file>' and comes_from<EOL>and comes_from.startswith('<STR_LIT:http>')):<EOL><INDENT>raise InstallationError(<EOL>'<STR_LIT>'<EOL>% (comes_from, url))<EOL><DEDENT>if scheme == '<STR_LIT:file>':<EOL><INDENT>path = url.split('<STR_LIT::>', <NUM_LIT:1>)[<NUM_LIT:1>]<EOL>path = path.replace('<STR_LIT:\\>', '<STR_LIT:/>')<EOL>match = _url_slash_drive_re.match(path)<EOL>if match:<EOL><INDENT>path = match.group(<NUM_LIT:1>) + '<STR_LIT::>' + path.split('<STR_LIT:|>', <NUM_LIT:1>)[<NUM_LIT:1>]<EOL><DEDENT>path = urllib_parse.unquote(path)<EOL>if path.startswith('<STR_LIT:/>'):<EOL><INDENT>path = '<STR_LIT:/>' + path.lstrip('<STR_LIT:/>')<EOL><DEDENT>url = path<EOL><DEDENT>else:<EOL><INDENT>resp = session.get(url)<EOL>resp.raise_for_status()<EOL>if six.PY3:<EOL><INDENT>return resp.url, resp.text<EOL><DEDENT>else:<EOL><INDENT>return resp.url, resp.content<EOL><DEDENT><DEDENT><DEDENT>try:<EOL><INDENT>with open(url) as f:<EOL><INDENT>content = f.read()<EOL><DEDENT><DEDENT>except IOError as exc:<EOL><INDENT>raise InstallationError(<EOL>'<STR_LIT>' % str(exc)<EOL>)<EOL><DEDENT>return url, content<EOL>

Gets the content of a file; it may be a filename, file: URL, or
    http: URL.  Returns (location, content).  Content is unicode.


if '<STR_LIT::>' not in name:<EOL><INDENT>return False<EOL><DEDENT>scheme = name.split('<STR_LIT::>', <NUM_LIT:1>)[<NUM_LIT:0>].lower()<EOL>return scheme in ['<STR_LIT:http>', '<STR_LIT>', '<STR_LIT:file>', '<STR_LIT>'] + vcs.all_schemes<EOL>

Returns true if the name looks like a URL


assert url.startswith('<STR_LIT>'), (<EOL>"<STR_LIT>" % url)<EOL>_, netloc, path, _, _ = urllib_parse.urlsplit(url)<EOL>if netloc:<EOL><INDENT>netloc = '<STR_LIT>' + netloc<EOL><DEDENT>path = urllib_request.url2pathname(netloc + path)<EOL>return path<EOL>


path = os.path.normpath(os.path.abspath(path))<EOL>url = urllib_parse.urljoin('<STR_LIT>', urllib_request.pathname2url(path))<EOL>return url<EOL>

Convert a path to a file: URL.  The path will be made absolute and have
quoted path parts.


archives = (<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'<EOL>)<EOL>ext = splitext(name)[<NUM_LIT:1>].lower()<EOL>if ext in archives:<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>

Return True if `name` is a considered as an archive file.


def unpack_file_url(link, location, download_dir=None):

link_path = url_to_path(link.url_without_fragment)<EOL>if os.path.isdir(link_path):<EOL><INDENT>if os.path.isdir(location):<EOL><INDENT>rmtree(location)<EOL><DEDENT>shutil.copytree(link_path, location, symlinks=True)<EOL>if download_dir:<EOL><INDENT>logger.info('<STR_LIT>')<EOL><DEDENT>return<EOL><DEDENT>if link.hash:<EOL><INDENT>link_path_hash = _get_hash_from_file(link_path, link)<EOL>_check_hash(link_path_hash, link)<EOL><DEDENT>already_downloaded_path = None<EOL>if download_dir:<EOL><INDENT>already_downloaded_path = _check_download_dir(link, download_dir)<EOL><DEDENT>if already_downloaded_path:<EOL><INDENT>from_path = already_downloaded_path<EOL><DEDENT>else:<EOL><INDENT>from_path = link_path<EOL><DEDENT>content_type = mimetypes.guess_type(from_path)[<NUM_LIT:0>]<EOL>unpack_file(from_path, location, content_type, link)<EOL>if download_dir and not already_downloaded_path:<EOL><INDENT>_copy_file(from_path, download_dir, content_type, link)<EOL><DEDENT>

Unpack link into location.
    If download_dir is provided and link points to a file, make a copy
    of the link file inside download_dir.


def unpack_url(link, location, download_dir=None,<EOL>only_download=False, session=None):

<EOL>if is_vcs_url(link):<EOL><INDENT>unpack_vcs_link(link, location, only_download)<EOL><DEDENT>elif is_file_url(link):<EOL><INDENT>unpack_file_url(link, location, download_dir)<EOL>if only_download:<EOL><INDENT>write_delete_marker_file(location)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if session is None:<EOL><INDENT>session = PipSession()<EOL><DEDENT>unpack_http_url(<EOL>link,<EOL>location,<EOL>download_dir,<EOL>session,<EOL>)<EOL>if only_download:<EOL><INDENT>write_delete_marker_file(location)<EOL><DEDENT><DEDENT>

Unpack link.
       If link is a VCS link:
         if only_download, export into download_dir and ignore location
          else unpack into location
       for other types of link:
         - unpack into location
         - if download_dir, copy the file into download_dir
         - if only_download, mark location for deletion


def _download_http_url(link, session, temp_dir):

target_url = link.url.split('<STR_LIT:#>', <NUM_LIT:1>)[<NUM_LIT:0>]<EOL>try:<EOL><INDENT>resp = session.get(<EOL>target_url,<EOL>headers={"<STR_LIT>": "<STR_LIT>"},<EOL>stream=True,<EOL>)<EOL>resp.raise_for_status()<EOL><DEDENT>except requests.HTTPError as exc:<EOL><INDENT>logger.critical(<EOL>"<STR_LIT>", exc.response.status_code, link,<EOL>)<EOL>raise<EOL><DEDENT>content_type = resp.headers.get('<STR_LIT>', '<STR_LIT>')<EOL>filename = link.filename  <EOL>content_disposition = resp.headers.get('<STR_LIT>')<EOL>if content_disposition:<EOL><INDENT>type, params = cgi.parse_header(content_disposition)<EOL>filename = params.get('<STR_LIT:filename>') or filename<EOL><DEDENT>ext = splitext(filename)[<NUM_LIT:1>]<EOL>if not ext:<EOL><INDENT>ext = mimetypes.guess_extension(content_type)<EOL>if ext:<EOL><INDENT>filename += ext<EOL><DEDENT><DEDENT>if not ext and link.url != resp.url:<EOL><INDENT>ext = os.path.splitext(resp.url)[<NUM_LIT:1>]<EOL>if ext:<EOL><INDENT>filename += ext<EOL><DEDENT><DEDENT>file_path = os.path.join(temp_dir, filename)<EOL>with open(file_path, '<STR_LIT:wb>') as content_file:<EOL><INDENT>_download_url(resp, link, content_file)<EOL><DEDENT>return file_path, content_type<EOL>

Download link url into temp_dir using provided session


download_path = os.path.join(download_dir, link.filename)<EOL>if os.path.exists(download_path):<EOL><INDENT>logger.info('<STR_LIT>', download_path)<EOL>if link.hash:<EOL><INDENT>download_hash = _get_hash_from_file(download_path, link)<EOL>try:<EOL><INDENT>_check_hash(download_hash, link)<EOL><DEDENT>except HashMismatch:<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>',<EOL>download_path<EOL>)<EOL>os.unlink(download_path)<EOL>return None<EOL><DEDENT><DEDENT>return download_path<EOL><DEDENT>return None<EOL>

Check download_dir for previously downloaded file with correct hash
        If a correct file is found return its path else None


dictConfigClass(config).configure()<EOL>


name = s.split('<STR_LIT:.>')<EOL>used = name.pop(<NUM_LIT:0>)<EOL>try:<EOL><INDENT>found = self.importer(used)<EOL>for frag in name:<EOL><INDENT>used += '<STR_LIT:.>' + frag<EOL>try:<EOL><INDENT>found = getattr(found, frag)<EOL><DEDENT>except AttributeError:<EOL><INDENT>self.importer(used)<EOL>found = getattr(found, frag)<EOL><DEDENT><DEDENT>return found<EOL><DEDENT>except ImportError:<EOL><INDENT>e, tb = sys.exc_info()[<NUM_LIT:1>:]<EOL>v = ValueError('<STR_LIT>' % (s, e))<EOL>v.__cause__, v.__traceback__ = e, tb<EOL>raise v<EOL><DEDENT>

Resolve strings to objects using standard import and attribute
syntax.


return self.resolve(value)<EOL>

Default converter for the ext:// protocol.


rest = value<EOL>m = self.WORD_PATTERN.match(rest)<EOL>if m is None:<EOL><INDENT>raise ValueError("<STR_LIT>" % value)<EOL><DEDENT>else:<EOL><INDENT>rest = rest[m.end():]<EOL>d = self.config[m.groups()[<NUM_LIT:0>]]<EOL>while rest:<EOL><INDENT>m = self.DOT_PATTERN.match(rest)<EOL>if m:<EOL><INDENT>d = d[m.groups()[<NUM_LIT:0>]]<EOL><DEDENT>else:<EOL><INDENT>m = self.INDEX_PATTERN.match(rest)<EOL>if m:<EOL><INDENT>idx = m.groups()[<NUM_LIT:0>]<EOL>if not self.DIGIT_PATTERN.match(idx):<EOL><INDENT>d = d[idx]<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>n = int(idx)  <EOL>d = d[n]<EOL><DEDENT>except TypeError:<EOL><INDENT>d = d[idx]<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if m:<EOL><INDENT>rest = rest[m.end():]<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' % (value, rest))<EOL><DEDENT><DEDENT><DEDENT>return d<EOL>

Default converter for the cfg:// protocol.


if not isinstance(value, ConvertingDict) and isinstance(value, dict):<EOL><INDENT>value = ConvertingDict(value)<EOL>value.configurator = self<EOL><DEDENT>elif not isinstance(value, ConvertingList) and isinstance(value, list):<EOL><INDENT>value = ConvertingList(value)<EOL>value.configurator = self<EOL><DEDENT>elif not isinstance(value, ConvertingTuple) andisinstance(value, tuple):<EOL><INDENT>value = ConvertingTuple(value)<EOL>value.configurator = self<EOL><DEDENT>elif isinstance(value, six.string_types):  <EOL><INDENT>m = self.CONVERT_PATTERN.match(value)<EOL>if m:<EOL><INDENT>d = m.groupdict()<EOL>prefix = d['<STR_LIT>']<EOL>converter = self.value_converters.get(prefix, None)<EOL>if converter:<EOL><INDENT>suffix = d['<STR_LIT>']<EOL>converter = getattr(self, converter)<EOL>value = converter(suffix)<EOL><DEDENT><DEDENT><DEDENT>return value<EOL>

Convert values to an appropriate type. dicts, lists and tuples are
replaced by their converting alternatives. Strings are checked to
see if they have a conversion format and are converted if they do.


c = config.pop('<STR_LIT>')<EOL>if not hasattr(c, '<STR_LIT>') and hasattr(types, '<STR_LIT>') and type(c) != types.ClassType:<EOL><INDENT>c = self.resolve(c)<EOL><DEDENT>props = config.pop('<STR_LIT:.>', None)<EOL>kwargs = dict((k, config[k]) for k in config if valid_ident(k))<EOL>result = c(**kwargs)<EOL>if props:<EOL><INDENT>for name, value in props.items():<EOL><INDENT>setattr(result, name, value)<EOL><DEDENT><DEDENT>return result<EOL>

Configure an object with a user-supplied factory.


if isinstance(value, list):<EOL><INDENT>value = tuple(value)<EOL><DEDENT>return value<EOL>

Utility function which converts lists to tuples.


config = self.config<EOL>if '<STR_LIT:version>' not in config:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if config['<STR_LIT:version>'] != <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>" % config['<STR_LIT:version>'])<EOL><DEDENT>incremental = config.pop('<STR_LIT>', False)<EOL>EMPTY_DICT = {}<EOL>logging._acquireLock()<EOL>try:<EOL><INDENT>if incremental:<EOL><INDENT>handlers = config.get('<STR_LIT>', EMPTY_DICT)<EOL>if sys.version_info[:<NUM_LIT:2>] == (<NUM_LIT:2>, <NUM_LIT:7>):<EOL><INDENT>for name in handlers:<EOL><INDENT>if name not in logging._handlers:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>'  % name)<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>handler = logging._handlers[name]<EOL>handler_config = handlers[name]<EOL>level = handler_config.get('<STR_LIT>', None)<EOL>if level:<EOL><INDENT>handler.setLevel(_checkLevel(level))<EOL><DEDENT><DEDENT>except StandardError as e:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' % (name, e))<EOL><DEDENT><DEDENT><DEDENT><DEDENT>loggers = config.get('<STR_LIT>', EMPTY_DICT)<EOL>for name in loggers:<EOL><INDENT>try:<EOL><INDENT>self.configure_logger(name, loggers[name], True)<EOL><DEDENT>except StandardError as e:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' % (name, e))<EOL><DEDENT><DEDENT>root = config.get('<STR_LIT:root>', None)<EOL>if root:<EOL><INDENT>try:<EOL><INDENT>self.configure_root(root, True)<EOL><DEDENT>except StandardError as e:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' % e)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>disable_existing = config.pop('<STR_LIT>', True)<EOL>logging._handlers.clear()<EOL>del logging._handlerList[:]<EOL>formatters = config.get('<STR_LIT>', EMPTY_DICT)<EOL>for name in formatters:<EOL><INDENT>try:<EOL><INDENT>formatters[name] = self.configure_formatter(<EOL>formatters[name])<EOL><DEDENT>except StandardError as e:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' % (name, e))<EOL><DEDENT><DEDENT>filters = config.get('<STR_LIT>', EMPTY_DICT)<EOL>for name in filters:<EOL><INDENT>try:<EOL><INDENT>filters[name] = self.configure_filter(filters[name])<EOL><DEDENT>except StandardError as e:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' % (name, e))<EOL><DEDENT><DEDENT>handlers = config.get('<STR_LIT>', EMPTY_DICT)<EOL>for name in sorted(handlers):<EOL><INDENT>try:<EOL><INDENT>handler = self.configure_handler(handlers[name])<EOL>handler.name = name<EOL>handlers[name] = handler<EOL><DEDENT>except StandardError as e:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' % (name, e))<EOL><DEDENT><DEDENT>root = logging.root<EOL>existing = list(root.manager.loggerDict)<EOL>existing.sort()<EOL>child_loggers = []<EOL>loggers = config.get('<STR_LIT>', EMPTY_DICT)<EOL>for name in loggers:<EOL><INDENT>if name in existing:<EOL><INDENT>i = existing.index(name)<EOL>prefixed = name + "<STR_LIT:.>"<EOL>pflen = len(prefixed)<EOL>num_existing = len(existing)<EOL>i = i + <NUM_LIT:1>  <EOL>while (i < num_existing) and(existing[i][:pflen] == prefixed):<EOL><INDENT>child_loggers.append(existing[i])<EOL>i = i + <NUM_LIT:1><EOL><DEDENT>existing.remove(name)<EOL><DEDENT>try:<EOL><INDENT>self.configure_logger(name, loggers[name])<EOL><DEDENT>except StandardError as e:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' % (name, e))<EOL><DEDENT><DEDENT>for log in existing:<EOL><INDENT>logger = root.manager.loggerDict[log]<EOL>if log in child_loggers:<EOL><INDENT>logger.level = logging.NOTSET<EOL>logger.handlers = []<EOL>logger.propagate = True<EOL><DEDENT>elif disable_existing:<EOL><INDENT>logger.disabled = True<EOL><DEDENT><DEDENT>root = config.get('<STR_LIT:root>', None)<EOL>if root:<EOL><INDENT>try:<EOL><INDENT>self.configure_root(root)<EOL><DEDENT>except StandardError as e:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' % e)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>finally:<EOL><INDENT>logging._releaseLock()<EOL><DEDENT>


if '<STR_LIT>' in config:<EOL><INDENT>factory = config['<STR_LIT>']  <EOL>try:<EOL><INDENT>result = self.configure_custom(config)<EOL><DEDENT>except TypeError as te:<EOL><INDENT>if "<STR_LIT>" not in str(te):<EOL><INDENT>raise<EOL><DEDENT>config['<STR_LIT>'] = config.pop('<STR_LIT>')<EOL>config['<STR_LIT>'] = factory<EOL>result = self.configure_custom(config)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>fmt = config.get('<STR_LIT>', None)<EOL>dfmt = config.get('<STR_LIT>', None)<EOL>result = logging.Formatter(fmt, dfmt)<EOL><DEDENT>return result<EOL>

Configure a formatter from a dictionary.


if '<STR_LIT>' in config:<EOL><INDENT>result = self.configure_custom(config)<EOL><DEDENT>else:<EOL><INDENT>name = config.get('<STR_LIT:name>', '<STR_LIT>')<EOL>result = logging.Filter(name)<EOL><DEDENT>return result<EOL>


def add_filters(self, filterer, filters):

for f in filters:<EOL><INDENT>try:<EOL><INDENT>filterer.addFilter(self.config['<STR_LIT>'][f])<EOL><DEDENT>except StandardError as e:<EOL><INDENT>raise ValueError('<STR_LIT>' % (f, e))<EOL><DEDENT><DEDENT>

Add filters to a filterer from a list of names.


formatter = config.pop('<STR_LIT>', None)<EOL>if formatter:<EOL><INDENT>try:<EOL><INDENT>formatter = self.config['<STR_LIT>'][formatter]<EOL><DEDENT>except StandardError as e:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' % (formatter, e))<EOL><DEDENT><DEDENT>level = config.pop('<STR_LIT>', None)<EOL>filters = config.pop('<STR_LIT>', None)<EOL>if '<STR_LIT>' in config:<EOL><INDENT>c = config.pop('<STR_LIT>')<EOL>if not hasattr(c, '<STR_LIT>') and hasattr(types, '<STR_LIT>') and type(c) != types.ClassType:<EOL><INDENT>c = self.resolve(c)<EOL><DEDENT>factory = c<EOL><DEDENT>else:<EOL><INDENT>klass = self.resolve(config.pop('<STR_LIT:class>'))<EOL>if issubclass(klass, logging.handlers.MemoryHandler) and'<STR_LIT:target>' in config:<EOL><INDENT>try:<EOL><INDENT>config['<STR_LIT:target>'] = self.config['<STR_LIT>'][config['<STR_LIT:target>']]<EOL><DEDENT>except StandardError as e:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' % (config['<STR_LIT:target>'], e))<EOL><DEDENT><DEDENT>elif issubclass(klass, logging.handlers.SMTPHandler) and'<STR_LIT>' in config:<EOL><INDENT>config['<STR_LIT>'] = self.as_tuple(config['<STR_LIT>'])<EOL><DEDENT>elif issubclass(klass, logging.handlers.SysLogHandler) and'<STR_LIT:address>' in config:<EOL><INDENT>config['<STR_LIT:address>'] = self.as_tuple(config['<STR_LIT:address>'])<EOL><DEDENT>factory = klass<EOL><DEDENT>kwargs = dict((k, config[k]) for k in config if valid_ident(k))<EOL>try:<EOL><INDENT>result = factory(**kwargs)<EOL><DEDENT>except TypeError as te:<EOL><INDENT>if "<STR_LIT>" not in str(te):<EOL><INDENT>raise<EOL><DEDENT>kwargs['<STR_LIT>'] = kwargs.pop('<STR_LIT>')<EOL>result = factory(**kwargs)<EOL><DEDENT>if formatter:<EOL><INDENT>result.setFormatter(formatter)<EOL><DEDENT>if level is not None:<EOL><INDENT>result.setLevel(_checkLevel(level))<EOL><DEDENT>if filters:<EOL><INDENT>self.add_filters(result, filters)<EOL><DEDENT>return result<EOL>


def add_handlers(self, logger, handlers):

for h in handlers:<EOL><INDENT>try:<EOL><INDENT>logger.addHandler(self.config['<STR_LIT>'][h])<EOL><DEDENT>except StandardError as e:<EOL><INDENT>raise ValueError('<STR_LIT>' % (h, e))<EOL><DEDENT><DEDENT>

Add handlers to a logger from a list of names.


def common_logger_config(self, logger, config, incremental=False):

level = config.get('<STR_LIT>', None)<EOL>if level is not None:<EOL><INDENT>logger.setLevel(_checkLevel(level))<EOL><DEDENT>if not incremental:<EOL><INDENT>for h in logger.handlers[:]:<EOL><INDENT>logger.removeHandler(h)<EOL><DEDENT>handlers = config.get('<STR_LIT>', None)<EOL>if handlers:<EOL><INDENT>self.add_handlers(logger, handlers)<EOL><DEDENT>filters = config.get('<STR_LIT>', None)<EOL>if filters:<EOL><INDENT>self.add_filters(logger, filters)<EOL><DEDENT><DEDENT>

Perform configuration which is common to root and non-root loggers.


def configure_logger(self, name, config, incremental=False):

logger = logging.getLogger(name)<EOL>self.common_logger_config(logger, config, incremental)<EOL>propagate = config.get('<STR_LIT>', None)<EOL>if propagate is not None:<EOL><INDENT>logger.propagate = propagate<EOL><DEDENT>

Configure a non-root logger from a dictionary.


def configure_root(self, config, incremental=False):

root = logging.getLogger()<EOL>self.common_logger_config(root, config, incremental)<EOL>

Configure a root logger from a dictionary.


if hasattr(os, '<STR_LIT>'):<EOL><INDENT>fd = os.open(path, os.O_RDONLY | os.O_NOFOLLOW)<EOL>file_uid = os.fstat(fd).st_uid<EOL>os.close(fd)<EOL><DEDENT>else:  <EOL><INDENT>if not os.path.islink(path):<EOL><INDENT>file_uid = os.stat(path).st_uid<EOL><DEDENT>else:<EOL><INDENT>raise OSError(<EOL>"<STR_LIT>" % path<EOL>)<EOL><DEDENT><DEDENT>return file_uid<EOL>

Return path's uid.

Does not follow symlinks:
    https://github.com/pypa/pip/pull/935#discussion_r5307003

Placed this function in compat due to differences on AIX and
Jython, that should eventually go away.

:raises OSError: When path is a symlink or can't be read.


files = []<EOL>urls = []<EOL>def sort_path(path):<EOL><INDENT>url = path_to_url(path)<EOL>if mimetypes.guess_type(url, strict=False)[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>urls.append(url)<EOL><DEDENT>else:<EOL><INDENT>files.append(url)<EOL><DEDENT><DEDENT>for url in locations:<EOL><INDENT>is_local_path = os.path.exists(url)<EOL>is_file_url = url.startswith('<STR_LIT>')<EOL>is_find_link = url in self.find_links<EOL>if is_local_path or is_file_url:<EOL><INDENT>if is_local_path:<EOL><INDENT>path = url<EOL><DEDENT>else:<EOL><INDENT>path = url_to_path(url)<EOL><DEDENT>if is_find_link and os.path.isdir(path):<EOL><INDENT>path = os.path.realpath(path)<EOL>for item in os.listdir(path):<EOL><INDENT>sort_path(os.path.join(path, item))<EOL><DEDENT><DEDENT>elif is_file_url and os.path.isdir(path):<EOL><INDENT>urls.append(url)<EOL><DEDENT>elif os.path.isfile(path):<EOL><INDENT>sort_path(path)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>urls.append(url)<EOL><DEDENT><DEDENT>return files, urls<EOL>

Sort locations into "files" (archives) and "urls", and return
a pair of lists (files,urls)


if self.use_wheel:<EOL><INDENT>support_num = len(supported_tags)<EOL>if candidate.location == INSTALLED_VERSION:<EOL><INDENT>pri = <NUM_LIT:1><EOL><DEDENT>elif candidate.location.ext == wheel_ext:<EOL><INDENT>wheel = Wheel(candidate.location.filename)<EOL>if not wheel.supported():<EOL><INDENT>raise UnsupportedWheel(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % wheel.filename<EOL>)<EOL><DEDENT>pri = -(wheel.support_index_min())<EOL><DEDENT>else:  <EOL><INDENT>pri = -(support_num)<EOL><DEDENT>return (candidate.version, pri)<EOL><DEDENT>else:<EOL><INDENT>return candidate.version<EOL><DEDENT>

Function used to generate link sort key for link tuples.
The greater the return value, the more preferred it is.
If not finding wheels, then sorted by version only.
If finding wheels, then the sort order is by version, then:
  1. existing installs
  2. wheels ordered via Wheel.support_index_min()
  3. source archives
Note: it was considered to embed this logic into the Link
      comparison operators, but then different sdist links
      with the same version, would have to be considered equal


return sorted(<EOL>applicable_versions,<EOL>key=self._candidate_sort_key,<EOL>reverse=True<EOL>)<EOL>

Bring the latest version (and wheels) to the front, but maintain the
existing ordering as secondary. See the docstring for `_link_sort_key`
for details. This function is isolated for easier unit testing.


def _find_url_name(self, index_url, url_name, req):

if not index_url.url.endswith('<STR_LIT:/>'):<EOL><INDENT>index_url.url += '<STR_LIT:/>'<EOL><DEDENT>page = self._get_page(index_url, req)<EOL>if page is None:<EOL><INDENT>logger.critical('<STR_LIT>', index_url)<EOL>return<EOL><DEDENT>norm_name = normalize_name(req.url_name)<EOL>for link in page.links:<EOL><INDENT>base = posixpath.basename(link.path.rstrip('<STR_LIT:/>'))<EOL>if norm_name == normalize_name(base):<EOL><INDENT>logger.debug(<EOL>'<STR_LIT>', url_name, base,<EOL>)<EOL>return base<EOL><DEDENT><DEDENT>return None<EOL>

Finds the true URL name of a package, when the given name isn't quite
correct.
This is usually used to implement case-insensitivity.


all_locations = list(locations)<EOL>seen = set()<EOL>while all_locations:<EOL><INDENT>location = all_locations.pop(<NUM_LIT:0>)<EOL>if location in seen:<EOL><INDENT>continue<EOL><DEDENT>seen.add(location)<EOL>page = self._get_page(location, req)<EOL>if page is None:<EOL><INDENT>continue<EOL><DEDENT>yield page<EOL>for link in page.rel_links():<EOL><INDENT>normalized = normalize_name(req.name).lower()<EOL>if (normalized not in self.allow_external<EOL>and not self.allow_all_external):<EOL><INDENT>self.need_warn_external = True<EOL>logger.debug(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>",<EOL>link,<EOL>)<EOL>continue<EOL><DEDENT>if (link.trusted is not None<EOL>and not link.trusted<EOL>and normalized not in self.allow_unverified):<EOL><INDENT>logger.debug(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>",<EOL>link,<EOL>)<EOL>self.need_warn_unverified = True<EOL>continue<EOL><DEDENT>all_locations.append(link)<EOL><DEDENT><DEDENT>

Yields (page, page_url) from the given locations, skipping
locations that have errors, and adding download/homepage links


eggs, no_eggs = [], []<EOL>seen = set()<EOL>for link in links:<EOL><INDENT>if link not in seen:<EOL><INDENT>seen.add(link)<EOL>if link.egg_fragment:<EOL><INDENT>eggs.append(link)<EOL><DEDENT>else:<EOL><INDENT>no_eggs.append(link)<EOL><DEDENT><DEDENT><DEDENT>return no_eggs + eggs<EOL>

Returns elements of links in order, non-egg links first, egg links
second, while eliminating duplicates


def _link_package_versions(self, link, search_name):

platform = get_platform()<EOL>version = None<EOL>if link.egg_fragment:<EOL><INDENT>egg_info = link.egg_fragment<EOL><DEDENT>else:<EOL><INDENT>egg_info, ext = link.splitext()<EOL>if not ext:<EOL><INDENT>if link not in self.logged_links:<EOL><INDENT>logger.debug('<STR_LIT>', link)<EOL>self.logged_links.add(link)<EOL><DEDENT>return<EOL><DEDENT>if egg_info.endswith('<STR_LIT>'):<EOL><INDENT>egg_info = egg_info[:-<NUM_LIT:4>]<EOL>ext = '<STR_LIT>' + ext<EOL><DEDENT>if ext not in self._known_extensions():<EOL><INDENT>if link not in self.logged_links:<EOL><INDENT>logger.debug(<EOL>'<STR_LIT>',<EOL>link,<EOL>ext,<EOL>)<EOL>self.logged_links.add(link)<EOL><DEDENT>return<EOL><DEDENT>if "<STR_LIT>" in link.path and ext == '<STR_LIT>':<EOL><INDENT>if link not in self.logged_links:<EOL><INDENT>logger.debug('<STR_LIT>', link)<EOL>self.logged_links.add(link)<EOL><DEDENT>return<EOL><DEDENT>if ext == wheel_ext:<EOL><INDENT>try:<EOL><INDENT>wheel = Wheel(link.filename)<EOL><DEDENT>except InvalidWheelFilename:<EOL><INDENT>logger.debug(<EOL>'<STR_LIT>',<EOL>link<EOL>)<EOL>return<EOL><DEDENT>if (pkg_resources.safe_name(wheel.name).lower()<EOL>!= pkg_resources.safe_name(search_name).lower()):<EOL><INDENT>logger.debug(<EOL>'<STR_LIT>',<EOL>link,<EOL>search_name,<EOL>)<EOL>return<EOL><DEDENT>if not wheel.supported():<EOL><INDENT>logger.debug(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>',<EOL>link,<EOL>)<EOL>return<EOL><DEDENT>comes_from = getattr(link, "<STR_LIT>", None)<EOL>if (<EOL>(<EOL>not platform.startswith('<STR_LIT>')<EOL>and not platform.startswith('<STR_LIT>')<EOL>and not platform == '<STR_LIT>'<EOL>)<EOL>and comes_from is not None<EOL>and urllib_parse.urlparse(<EOL>comes_from.url<EOL>).netloc.endswith(PyPI.netloc)):<EOL><INDENT>if not wheel.supported(tags=supported_tags_noarch):<EOL><INDENT>logger.debug(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>",<EOL>link,<EOL>)<EOL>return<EOL><DEDENT><DEDENT>version = wheel.version<EOL><DEDENT><DEDENT>if not version:<EOL><INDENT>version = self._egg_info_matches(egg_info, search_name, link)<EOL><DEDENT>if version is None:<EOL><INDENT>logger.debug(<EOL>'<STR_LIT>',<EOL>link,<EOL>search_name,<EOL>)<EOL>return<EOL><DEDENT>if (link.internal is not None<EOL>and not link.internal<EOL>and not normalize_name(search_name).lower()<EOL>in self.allow_external<EOL>and not self.allow_all_external):<EOL><INDENT>logger.debug("<STR_LIT>", link)<EOL>self.need_warn_external = True<EOL>return<EOL><DEDENT>if (link.verifiable is not None<EOL>and not link.verifiable<EOL>and not (normalize_name(search_name).lower()<EOL>in self.allow_unverified)):<EOL><INDENT>logger.debug(<EOL>"<STR_LIT>",<EOL>link,<EOL>)<EOL>self.need_warn_unverified = True<EOL>return<EOL><DEDENT>match = self._py_version_re.search(version)<EOL>if match:<EOL><INDENT>version = version[:match.start()]<EOL>py_version = match.group(<NUM_LIT:1>)<EOL>if py_version != sys.version[:<NUM_LIT:3>]:<EOL><INDENT>logger.debug(<EOL>'<STR_LIT>', link<EOL>)<EOL>return<EOL><DEDENT><DEDENT>logger.debug('<STR_LIT>', link, version)<EOL>return InstallationCandidate(search_name, version, link)<EOL>

Return an iterable of triples (pkg_resources_version_key,
link, python_version) that can be extracted from the given
link.

Meant to be overridden by subclasses, not called by clients.


scheme, netloc, path, query, fragment = urllib_parse.urlsplit(url)<EOL>if scheme not in ('<STR_LIT:http>', '<STR_LIT>'):<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>resp = session.head(url, allow_redirects=True)<EOL>resp.raise_for_status()<EOL>return resp.headers.get("<STR_LIT:Content-Type>", "<STR_LIT>")<EOL>

Get the Content-Type of the given url, using a HEAD request


for anchor in self.parsed.findall("<STR_LIT>"):<EOL><INDENT>if anchor.get("<STR_LIT>"):<EOL><INDENT>href = anchor.get("<STR_LIT>")<EOL>url = self.clean_link(<EOL>urllib_parse.urljoin(self.base_url, href)<EOL>)<EOL>internal = None<EOL>if self.api_version and self.api_version >= <NUM_LIT:2>:<EOL><INDENT>internal = bool(<EOL>anchor.get("<STR_LIT>")<EOL>and "<STR_LIT>" in anchor.get("<STR_LIT>").split()<EOL>)<EOL><DEDENT>yield Link(url, self, internal=internal)<EOL><DEDENT><DEDENT>


def explicit_rel_links(self, rels=('<STR_LIT>', '<STR_LIT>')):

rels = set(rels)<EOL>for anchor in self.parsed.findall("<STR_LIT>"):<EOL><INDENT>if anchor.get("<STR_LIT>") and anchor.get("<STR_LIT>"):<EOL><INDENT>found_rels = set(anchor.get("<STR_LIT>").split())<EOL>if found_rels & rels:<EOL><INDENT>href = anchor.get("<STR_LIT>")<EOL>url = self.clean_link(<EOL>urllib_parse.urljoin(self.base_url, href)<EOL>)<EOL>yield Link(url, self, trusted=False)<EOL><DEDENT><DEDENT><DEDENT>

Yields all links with the given relations


return self._clean_re.sub(<EOL>lambda match: '<STR_LIT>' % ord(match.group(<NUM_LIT:0>)), url)<EOL>

Makes sure a link is fully encoded.  That is, if a ' ' shows up in
        the link, it will be rewritten to %20 (while not over-quoting
        % or other characters).


trusted = self.trusted or getattr(self.comes_from, "<STR_LIT>", None)<EOL>if trusted is not None and trusted:<EOL><INDENT>try:<EOL><INDENT>api_version = getattr(self.comes_from, "<STR_LIT>", None)<EOL>api_version = int(api_version)<EOL><DEDENT>except (ValueError, TypeError):<EOL><INDENT>api_version = None<EOL><DEDENT>if api_version is None or api_version <= <NUM_LIT:1>:<EOL><INDENT>return<EOL><DEDENT>if self.hash:<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>elif trusted is not None:<EOL><INDENT>return False<EOL><DEDENT>

Returns True if this link can be verified after download, False if it
cannot, and None if we cannot determine.


def rehash(path, algo='<STR_LIT>', blocksize=<NUM_LIT:1> << <NUM_LIT:20>):

h = hashlib.new(algo)<EOL>length = <NUM_LIT:0><EOL>with open(path, '<STR_LIT:rb>') as f:<EOL><INDENT>block = f.read(blocksize)<EOL>while block:<EOL><INDENT>length += len(block)<EOL>h.update(block)<EOL>block = f.read(blocksize)<EOL><DEDENT><DEDENT>digest = '<STR_LIT>' + urlsafe_b64encode(<EOL>h.digest()<EOL>).decode('<STR_LIT>').rstrip('<STR_LIT:=>')<EOL>return (digest, length)<EOL>

Return (hash, length) for path using hashlib.new(algo)


<EOL>if os.path.isfile(path):<EOL><INDENT>with open(path, '<STR_LIT:rb>') as script:<EOL><INDENT>firstline = script.readline()<EOL>if not firstline.startswith(b'<STR_LIT>'):<EOL><INDENT>return False<EOL><DEDENT>exename = sys.executable.encode(sys.getfilesystemencoding())<EOL>firstline = b'<STR_LIT>' + exename + os.linesep.encode("<STR_LIT:ascii>")<EOL>rest = script.read()<EOL><DEDENT>with open(path, '<STR_LIT:wb>') as script:<EOL><INDENT>script.write(firstline)<EOL>script.write(rest)<EOL><DEDENT>return True<EOL><DEDENT>

Replace #!python with #!/path/to/python
    Return True if file was changed.


name_folded = name.replace("<STR_LIT:->", "<STR_LIT:_>")<EOL>for item in os.listdir(wheeldir):<EOL><INDENT>match = dist_info_re.match(item)<EOL>if match and match.group('<STR_LIT:name>') == name_folded:<EOL><INDENT>with open(os.path.join(wheeldir, item, '<STR_LIT>')) as wheel:<EOL><INDENT>for line in wheel:<EOL><INDENT>line = line.lower().rstrip()<EOL>if line == "<STR_LIT>":<EOL><INDENT>return True<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>return False<EOL>

Return True if the extracted wheel in wheeldir should go into purelib.


def move_wheel_files(name, req, wheeldir, user=False, home=None, root=None,<EOL>pycompile=True, scheme=None, isolated=False):

if not scheme:<EOL><INDENT>scheme = distutils_scheme(<EOL>name, user=user, home=home, root=root, isolated=isolated<EOL>)<EOL><DEDENT>if root_is_purelib(name, wheeldir):<EOL><INDENT>lib_dir = scheme['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>lib_dir = scheme['<STR_LIT>']<EOL><DEDENT>info_dir = []<EOL>data_dirs = []<EOL>source = wheeldir.rstrip(os.path.sep) + os.path.sep<EOL>installed = {}<EOL>changed = set()<EOL>generated = []<EOL>if pycompile:<EOL><INDENT>with captured_stdout() as stdout:<EOL><INDENT>compileall.compile_dir(source, force=True, quiet=True)<EOL><DEDENT>logger.info(remove_tracebacks(stdout.getvalue()))<EOL><DEDENT>def normpath(src, p):<EOL><INDENT>return make_path_relative(src, p).replace(os.path.sep, '<STR_LIT:/>')<EOL><DEDENT>def record_installed(srcfile, destfile, modified=False):<EOL><INDENT>"""<STR_LIT>"""<EOL>oldpath = normpath(srcfile, wheeldir)<EOL>newpath = normpath(destfile, lib_dir)<EOL>installed[oldpath] = newpath<EOL>if modified:<EOL><INDENT>changed.add(destfile)<EOL><DEDENT><DEDENT>def clobber(source, dest, is_base, fixer=None, filter=None):<EOL><INDENT>if not os.path.exists(dest):  <EOL><INDENT>os.makedirs(dest)<EOL><DEDENT>for dir, subdirs, files in os.walk(source):<EOL><INDENT>basedir = dir[len(source):].lstrip(os.path.sep)<EOL>destdir = os.path.join(dest, basedir)<EOL>if is_base and basedir.split(os.path.sep, <NUM_LIT:1>)[<NUM_LIT:0>].endswith('<STR_LIT>'):<EOL><INDENT>continue<EOL><DEDENT>for s in subdirs:<EOL><INDENT>destsubdir = os.path.join(dest, basedir, s)<EOL>if is_base and basedir == '<STR_LIT>' and destsubdir.endswith('<STR_LIT>'):<EOL><INDENT>data_dirs.append(s)<EOL>continue<EOL><DEDENT>elif (is_base<EOL>and s.endswith('<STR_LIT>')<EOL>and s.lower().startswith(<EOL>req.project_name.replace('<STR_LIT:->', '<STR_LIT:_>').lower())):<EOL><INDENT>assert not info_dir, '<STR_LIT>'<EOL>info_dir.append(destsubdir)<EOL><DEDENT><DEDENT>for f in files:<EOL><INDENT>if filter and filter(f):<EOL><INDENT>continue<EOL><DEDENT>srcfile = os.path.join(dir, f)<EOL>destfile = os.path.join(dest, basedir, f)<EOL>if not os.path.exists(destdir):<EOL><INDENT>os.makedirs(destdir)<EOL><DEDENT>shutil.copyfile(srcfile, destfile)<EOL>st = os.stat(srcfile)<EOL>if hasattr(os, "<STR_LIT>"):<EOL><INDENT>os.utime(destfile, (st.st_atime, st.st_mtime))<EOL><DEDENT>if os.access(srcfile, os.X_OK):<EOL><INDENT>st = os.stat(srcfile)<EOL>permissions = (<EOL>st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH<EOL>)<EOL>os.chmod(destfile, permissions)<EOL><DEDENT>changed = False<EOL>if fixer:<EOL><INDENT>changed = fixer(destfile)<EOL><DEDENT>record_installed(srcfile, destfile, changed)<EOL><DEDENT><DEDENT><DEDENT>clobber(source, lib_dir, True)<EOL>assert info_dir, "<STR_LIT>" % req<EOL>ep_file = os.path.join(info_dir[<NUM_LIT:0>], '<STR_LIT>')<EOL>console, gui = get_entrypoints(ep_file)<EOL>def is_entrypoint_wrapper(name):<EOL><INDENT>if name.lower().endswith('<STR_LIT>'):<EOL><INDENT>matchname = name[:-<NUM_LIT:4>]<EOL><DEDENT>elif name.lower().endswith('<STR_LIT>'):<EOL><INDENT>matchname = name[:-<NUM_LIT:10>]<EOL><DEDENT>elif name.lower().endswith("<STR_LIT>"):<EOL><INDENT>matchname = name[:-<NUM_LIT:4>]<EOL><DEDENT>else:<EOL><INDENT>matchname = name<EOL><DEDENT>return (matchname in console or matchname in gui)<EOL><DEDENT>for datadir in data_dirs:<EOL><INDENT>fixer = None<EOL>filter = None<EOL>for subdir in os.listdir(os.path.join(wheeldir, datadir)):<EOL><INDENT>fixer = None<EOL>if subdir == '<STR_LIT>':<EOL><INDENT>fixer = fix_script<EOL>filter = is_entrypoint_wrapper<EOL><DEDENT>source = os.path.join(wheeldir, datadir, subdir)<EOL>dest = scheme[subdir]<EOL>clobber(source, dest, False, fixer=fixer, filter=filter)<EOL><DEDENT><DEDENT>maker = ScriptMaker(None, scheme['<STR_LIT>'])<EOL>maker.clobber = True<EOL>maker.variants = set(('<STR_LIT>', ))<EOL>maker.set_mode = True<EOL>def _get_script_text(entry):<EOL><INDENT>return maker.script_template % {<EOL>"<STR_LIT>": entry.prefix,<EOL>"<STR_LIT>": entry.suffix.split("<STR_LIT:.>")[<NUM_LIT:0>],<EOL>"<STR_LIT>": entry.suffix,<EOL>}<EOL><DEDENT>maker._get_script_text = _get_script_text<EOL>maker.script_template =


from pip.utils import FakeFile  <EOL>r = csv.reader(FakeFile(dist.get_metadata_lines('<STR_LIT>')))<EOL>for row in r:<EOL><INDENT>path = os.path.join(dist.location, row[<NUM_LIT:0>])<EOL>yield path<EOL>if path.endswith('<STR_LIT>'):<EOL><INDENT>dn, fn = os.path.split(path)<EOL>base = fn[:-<NUM_LIT:3>]<EOL>path = os.path.join(dn, base + '<STR_LIT>')<EOL>yield path<EOL><DEDENT><DEDENT>

Yield all the uninstallation paths for dist based on RECORD-without-.pyc

Yield paths to all the files in RECORD. For each .py file in RECORD, add
the .pyc in the same directory.

UninstallPathSet.add() takes care of the __pycache__ .pyc.


try:<EOL><INDENT>dist = [d for d in pkg_resources.find_on_path(None, source_dir)][<NUM_LIT:0>]<EOL>wheel_data = dist.get_metadata('<STR_LIT>')<EOL>wheel_data = Parser().parsestr(wheel_data)<EOL>version = wheel_data['<STR_LIT>'].strip()<EOL>version = tuple(map(int, version.split('<STR_LIT:.>')))<EOL>return version<EOL><DEDENT>except:<EOL><INDENT>return False<EOL><DEDENT>

Return the Wheel-Version of an extracted wheel, if possible.

Otherwise, return False if we couldn't parse / extract it.


if not version:<EOL><INDENT>raise UnsupportedWheel(<EOL>"<STR_LIT>" % name<EOL>)<EOL><DEDENT>if version[<NUM_LIT:0>] > VERSION_COMPATIBLE[<NUM_LIT:0>]:<EOL><INDENT>raise UnsupportedWheel(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (name, '<STR_LIT:.>'.join(map(str, version)))<EOL>)<EOL><DEDENT>elif version > VERSION_COMPATIBLE:<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>',<EOL>'<STR_LIT:.>'.join(map(str, version)),<EOL>)<EOL><DEDENT>

Raises errors or warns if called with an incompatible Wheel-Version.

Pip should refuse to install a Wheel-Version that's a major series
ahead of what it's compatible with (e.g 2.0 > 1.1); and warn when
installing a version only minor version ahead (e.g 1.2 > 1.1).

version: a 2-tuple representing a Wheel-Version (Major, Minor)
name: name of wheel or package to raise exception about

:raises UnsupportedWheel: when an incompatible Wheel-Version is given


wheel_info = self.wheel_file_re.match(filename)<EOL>if not wheel_info:<EOL><INDENT>raise InvalidWheelFilename(<EOL>"<STR_LIT>" % filename<EOL>)<EOL><DEDENT>self.filename = filename<EOL>self.name = wheel_info.group('<STR_LIT:name>').replace('<STR_LIT:_>', '<STR_LIT:->')<EOL>self.version = wheel_info.group('<STR_LIT>').replace('<STR_LIT:_>', '<STR_LIT:->')<EOL>self.pyversions = wheel_info.group('<STR_LIT>').split('<STR_LIT:.>')<EOL>self.abis = wheel_info.group('<STR_LIT>').split('<STR_LIT:.>')<EOL>self.plats = wheel_info.group('<STR_LIT>').split('<STR_LIT:.>')<EOL>self.file_tags = set(<EOL>(x, y, z) for x in self.pyversions<EOL>for y in self.abis for z in self.plats<EOL>)<EOL>

:raises InvalidWheelFilename: when the filename is invalid for a wheel


if tags is None:  <EOL><INDENT>tags = pep425tags.supported_tags<EOL><DEDENT>indexes = [tags.index(c) for c in self.file_tags if c in tags]<EOL>return min(indexes) if indexes else None<EOL>

Return the lowest index that one of the wheel's file_tag combinations
achieves in the supported_tags list e.g. if there are 8 supported tags,
and one of the file tags is first in the list, then return 0.  Returns
None is the wheel is not supported.


if tags is None:  <EOL><INDENT>tags = pep425tags.supported_tags<EOL><DEDENT>return bool(set(tags).intersection(self.file_tags))<EOL>


base_args = [<EOL>sys.executable, '<STR_LIT:-c>',<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % req.setup_py<EOL>] + list(self.global_options)<EOL>logger.info('<STR_LIT>', req.name)<EOL>logger.info('<STR_LIT>', self.wheel_dir)<EOL>wheel_args = base_args + ['<STR_LIT>', '<STR_LIT>', self.wheel_dir]+ self.build_options<EOL>try:<EOL><INDENT>call_subprocess(wheel_args, cwd=req.source_dir, show_stdout=False)<EOL>return True<EOL><DEDENT>except:<EOL><INDENT>logger.error('<STR_LIT>', req.name)<EOL>return False<EOL><DEDENT>


<EOL>self.requirement_set.prepare_files(self.finder)<EOL>reqset = self.requirement_set.requirements.values()<EOL>buildset = []<EOL>for req in reqset:<EOL><INDENT>if req.is_wheel:<EOL><INDENT>logger.info(<EOL>'<STR_LIT>', req.name,<EOL>)<EOL><DEDENT>elif req.editable:<EOL><INDENT>logger.info(<EOL>'<STR_LIT>', req.name,<EOL>)<EOL><DEDENT>else:<EOL><INDENT>buildset.append(req)<EOL><DEDENT><DEDENT>if not buildset:<EOL><INDENT>return True<EOL><DEDENT>logger.info(<EOL>'<STR_LIT>',<EOL>'<STR_LIT:U+002CU+0020>'.join([req.name for req in buildset]),<EOL>)<EOL>with indent_log():<EOL><INDENT>build_success, build_failure = [], []<EOL>for req in buildset:<EOL><INDENT>if self._build_one(req):<EOL><INDENT>build_success.append(req)<EOL><DEDENT>else:<EOL><INDENT>build_failure.append(req)<EOL><DEDENT><DEDENT><DEDENT>if build_success:<EOL><INDENT>logger.info(<EOL>'<STR_LIT>',<EOL>'<STR_LIT:U+0020>'.join([req.name for req in build_success]),<EOL>)<EOL><DEDENT>if build_failure:<EOL><INDENT>logger.info(<EOL>'<STR_LIT>',<EOL>'<STR_LIT:U+0020>'.join([req.name for req in build_failure]),<EOL>)<EOL><DEDENT>return len(build_failure) == <NUM_LIT:0><EOL>


from pip.index import Link<EOL>unnamed = list(self.unnamed_requirements)<EOL>reqs = list(self.requirements.values())<EOL>while reqs or unnamed:<EOL><INDENT>if unnamed:<EOL><INDENT>req_to_install = unnamed.pop(<NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>req_to_install = reqs.pop(<NUM_LIT:0>)<EOL><DEDENT>install = True<EOL>best_installed = False<EOL>not_found = None<EOL>if not self.ignore_installed and not req_to_install.editable:<EOL><INDENT>req_to_install.check_if_exists()<EOL>if req_to_install.satisfied_by:<EOL><INDENT>if self.upgrade:<EOL><INDENT>if not self.force_reinstall and not req_to_install.url:<EOL><INDENT>try:<EOL><INDENT>url = finder.find_requirement(<EOL>req_to_install, self.upgrade)<EOL><DEDENT>except BestVersionAlreadyInstalled:<EOL><INDENT>best_installed = True<EOL>install = False<EOL><DEDENT>except DistributionNotFound as exc:<EOL><INDENT>not_found = exc<EOL><DEDENT>else:<EOL><INDENT>req_to_install.url = url.url<EOL><DEDENT><DEDENT>if not best_installed:<EOL><INDENT>if not (self.use_user_site<EOL>and not dist_in_usersite(<EOL>req_to_install.satisfied_by<EOL>)):<EOL><INDENT>req_to_install.conflicts_with =req_to_install.satisfied_by<EOL><DEDENT>req_to_install.satisfied_by = None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>install = False<EOL><DEDENT><DEDENT>if req_to_install.satisfied_by:<EOL><INDENT>if best_installed:<EOL><INDENT>logger.info(<EOL>'<STR_LIT>',<EOL>req_to_install,<EOL>)<EOL><DEDENT>else:<EOL><INDENT>logger.info(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>',<EOL>req_to_install,<EOL>)<EOL><DEDENT><DEDENT><DEDENT>if req_to_install.editable:<EOL><INDENT>logger.info('<STR_LIT>', req_to_install)<EOL><DEDENT>elif install:<EOL><INDENT>if (req_to_install.url<EOL>and req_to_install.url.lower().startswith('<STR_LIT>')):<EOL><INDENT>path = url_to_path(req_to_install.url)<EOL>logger.info('<STR_LIT>', display_path(path))<EOL><DEDENT>else:<EOL><INDENT>logger.info('<STR_LIT>', req_to_install)<EOL><DEDENT><DEDENT>with indent_log():<EOL><INDENT>is_wheel = False<EOL>if req_to_install.editable:<EOL><INDENT>if req_to_install.source_dir is None:<EOL><INDENT>location = req_to_install.build_location(self.src_dir)<EOL>req_to_install.source_dir = location<EOL><DEDENT>else:<EOL><INDENT>location = req_to_install.source_dir<EOL><DEDENT>if not os.path.exists(self.build_dir):<EOL><INDENT>_make_build_dir(self.build_dir)<EOL><DEDENT>req_to_install.update_editable(not self.is_download)<EOL>if self.is_download:<EOL><INDENT>req_to_install.run_egg_info()<EOL>req_to_install.archive(self.download_dir)<EOL><DEDENT>else:<EOL><INDENT>req_to_install.run_egg_info()<EOL><DEDENT><DEDENT>elif install:<EOL><INDENT>location = req_to_install.build_location(<EOL>self.build_dir,<EOL>)<EOL>unpack = True<EOL>url = None<EOL>if os.path.exists(os.path.join(location, '<STR_LIT>')):<EOL><INDENT>raise PreviousBuildDirError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% (req_to_install, location)<EOL>)<EOL><DEDENT>else:<EOL><INDENT>if req_to_install.url is None:<EOL><INDENT>if not_found:<EOL><INDENT>raise not_found<EOL><DEDENT>url = finder.find_requirement(<EOL>req_to_install,<EOL>upgrade=self.upgrade,<EOL>)<EOL><DEDENT>else:<EOL><INDENT>url = Link(req_to_install.url)<EOL>assert url<EOL><DEDENT>if url:<EOL><INDENT>try:<EOL><INDENT>if (<EOL>url.filename.endswith(wheel_ext)<EOL>and self.wheel_download_dir<EOL>):<EOL><INDENT>download_dir = self.wheel_download_dir<EOL>do_download = True<EOL><DEDENT>else:<EOL><INDENT>download_dir = self.download_dir<EOL>do_download = self.is_download<EOL><DEDENT>unpack_url(<EOL>url, location, download_dir,<EOL>do_download, session=self.session,<EOL>)<EOL><DEDENT>except requests.HTTPError as exc:<EOL><INDENT>logger.critical(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>',<EOL>req_to_install,<EOL>exc,<EOL>)<EOL>raise InstallationError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(req_to_install, exc, url)<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>unpack = False<EOL><DEDENT><DEDENT>if unpack:<EOL><INDENT>is_wheel = url and url.filename.endswith(wheel_ext)<EOL>if self.is_download:<EOL><INDENT>req_to_install.source_dir = location<EOL>if not is_wheel:<EOL><INDENT>req_to_install.run_egg_info()<EOL><DEDENT>if url and url.scheme in vcs.all_schemes:<EOL><INDENT>req_to_install.archive(self.download_dir)<EOL><DEDENT><DEDENT>elif is_wheel:<EOL><INDENT>req_to_install.source_dir = location<EOL>req_to_install.url = url.url<EOL><DEDENT>else:<EOL><INDENT>req_to_install.source_dir = location<EOL>req_to_install.run_egg_info()<EOL>req_to_install.assert_source_matches_version()<EOL><DEDENT>if not self.ignore_installed:<EOL><INDENT>req_to_install.check_if_exists()<EOL><DEDENT>if req_to_install.satisfied_by:<EOL><INDENT>if self.upgrade or self.ignore_installed:<EOL><INDENT>if not (self.use_user_site<EOL>and not dist_in_usersite(<EOL>req_to_install.satisfied_by)):<EOL><INDENT>req_to_install.conflicts_with =req_to_install.satisfied_by<EOL><DEDENT>req_to_install.satisfied_by = None<EOL><DEDENT>else:<EOL><INDENT>logger.info(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>',<EOL>req_to_install,<EOL>)<EOL>install = False<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if (req_to_install.extras):<EOL><INDENT>logger.debug(<EOL>"<STR_LIT>",<EOL>'<STR_LIT:U+002C>'.join(req_to_install.extras),<EOL>)<EOL><DEDENT>if is_wheel:<EOL><INDENT>dist = list(<EOL>pkg_resources.find_distributions(location)<EOL>)[<NUM_LIT:0>]<EOL><DEDENT>else:  <EOL><INDENT>if req_to_install.satisfied_by:<EOL><INDENT>dist = req_to_install.satisfied_by<EOL><DEDENT>else:<EOL><INDENT>dist = req_to_install.get_dist()<EOL><DEDENT>if dist.has_metadata('<STR_LIT>'):<EOL><INDENT>finder.add_dependency_links(<EOL>dist.get_metadata_lines('<STR_LIT>')<EOL>)<EOL><DEDENT><DEDENT>if not self.ignore_dependencies:<EOL><INDENT>for subreq in dist.requires(<EOL>req_to_install.extras):<EOL><INDENT>if self.has_requirement(<EOL>subreq.project_name):<EOL><INDENT>continue<EOL><DEDENT>subreq = InstallRequirement(<EOL>str(subreq),<EOL>req_to_install,<EOL>isolated=self.isolated,<EOL>)<EOL>reqs.append(subreq)<EOL>self.add_requirement(subreq)<EOL><DEDENT><DEDENT>if not self.has_requirement(req_to_install.name):<EOL><INDENT>self.add_requirement(req_to_install)<EOL><DEDENT>if (self.is_download or<EOL>req_to_install._temp_build_dir is not None):<EOL><INDENT>self.reqs_to_cleanup.append(req_to_install)<EOL><DEDENT>if install:<EOL><INDENT>self.successfully_downloaded.append(req_to_install)<EOL><DEDENT><DEDENT><DEDENT>

Prepare process. Create temp directories, download and/or unpack files.


logger.debug('<STR_LIT>')<EOL>with indent_log():<EOL><INDENT>for req in self.reqs_to_cleanup:<EOL><INDENT>req.remove_temporary_source()<EOL><DEDENT>if self._pip_has_created_build_dir():<EOL><INDENT>logger.debug('<STR_LIT>', self.build_dir)<EOL>rmtree(self.build_dir)<EOL><DEDENT><DEDENT>


def install(self, install_options, global_options=(), *args, **kwargs):

to_install = [r for r in self.requirements.values()[::-<NUM_LIT:1>]<EOL>if not r.satisfied_by]<EOL>distribute_req = pkg_resources.Requirement.parse("<STR_LIT>")<EOL>for req in to_install:<EOL><INDENT>if (req.name == '<STR_LIT>'<EOL>and req.installed_version is not None<EOL>and req.installed_version in distribute_req):<EOL><INDENT>to_install.remove(req)<EOL>to_install.append(req)<EOL><DEDENT><DEDENT>if to_install:<EOL><INDENT>logger.info(<EOL>'<STR_LIT>',<EOL>'<STR_LIT:U+002CU+0020>'.join([req.name for req in to_install]),<EOL>)<EOL><DEDENT>with indent_log():<EOL><INDENT>for requirement in to_install:<EOL><INDENT>if requirement.name == '<STR_LIT>':<EOL><INDENT>try:<EOL><INDENT>distribute_requirement =pkg_resources.Requirement.parse("<STR_LIT>")<EOL>existing_distribute =pkg_resources.get_distribution("<STR_LIT>")<EOL>if existing_distribute in distribute_requirement:<EOL><INDENT>requirement.conflicts_with = existing_distribute<EOL><DEDENT><DEDENT>except pkg_resources.DistributionNotFound:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>if requirement.conflicts_with:<EOL><INDENT>logger.info(<EOL>'<STR_LIT>',<EOL>requirement.conflicts_with,<EOL>)<EOL>with indent_log():<EOL><INDENT>requirement.uninstall(auto_confirm=True)<EOL><DEDENT><DEDENT>try:<EOL><INDENT>requirement.install(<EOL>install_options,<EOL>global_options,<EOL>*args,<EOL>**kwargs<EOL>)<EOL><DEDENT>except:<EOL><INDENT>if (requirement.conflicts_with<EOL>and not requirement.install_succeeded):<EOL><INDENT>requirement.rollback_uninstall()<EOL><DEDENT>raise<EOL><DEDENT>else:<EOL><INDENT>if (requirement.conflicts_with<EOL>and requirement.install_succeeded):<EOL><INDENT>requirement.commit_uninstall()<EOL><DEDENT><DEDENT>requirement.remove_temporary_source()<EOL><DEDENT><DEDENT>self.successfully_installed = to_install<EOL>

Install everything in this set (after having downloaded and unpacked
the packages)


return is_local(path)<EOL>

Return True if the given path is one we are permitted to
remove/modify, False otherwise.


short_paths = set()<EOL>for path in sorted(paths, key=len):<EOL><INDENT>if not any([<EOL>(path.startswith(shortpath) and<EOL>path[len(shortpath.rstrip(os.path.sep))] == os.path.sep)<EOL>for shortpath in short_paths]):<EOL><INDENT>short_paths.add(path)<EOL><DEDENT><DEDENT>return short_paths<EOL>

Compact a path set to contain the minimal number of paths
        necessary to contain all paths in the set. If /a/path/ and
        /a/path/to/a/file.txt are both in the set, leave only the
        shorter path.


if not self._can_uninstall():<EOL><INDENT>return<EOL><DEDENT>if not self.paths:<EOL><INDENT>logger.info(<EOL>"<STR_LIT>",<EOL>self.dist.project_name,<EOL>)<EOL>return<EOL><DEDENT>logger.info(<EOL>'<STR_LIT>',<EOL>self.dist.project_name, self.dist.version<EOL>)<EOL>with indent_log():<EOL><INDENT>paths = sorted(self.compact(self.paths))<EOL>if auto_confirm:<EOL><INDENT>response = '<STR_LIT:y>'<EOL><DEDENT>else:<EOL><INDENT>for path in paths:<EOL><INDENT>logger.info(path)<EOL><DEDENT>response = ask('<STR_LIT>', ('<STR_LIT:y>', '<STR_LIT:n>'))<EOL><DEDENT>if self._refuse:<EOL><INDENT>logger.info('<STR_LIT>')<EOL>for path in self.compact(self._refuse):<EOL><INDENT>logger.info(path)<EOL><DEDENT><DEDENT>if response == '<STR_LIT:y>':<EOL><INDENT>self.save_dir = tempfile.mkdtemp(suffix='<STR_LIT>',<EOL>prefix='<STR_LIT>')<EOL>for path in paths:<EOL><INDENT>new_path = self._stash(path)<EOL>logger.debug('<STR_LIT>', path)<EOL>self._moved_paths.append(path)<EOL>renames(path, new_path)<EOL><DEDENT>for pth in self.pth.values():<EOL><INDENT>pth.remove()<EOL><DEDENT>logger.info(<EOL>'<STR_LIT>',<EOL>self.dist.project_name, self.dist.version<EOL>)<EOL><DEDENT><DEDENT>

Remove paths in ``self.paths`` with confirmation (unless
        ``auto_confirm`` is True).


if self.save_dir is None:<EOL><INDENT>logger.error(<EOL>"<STR_LIT>",<EOL>self.dist.project_name,<EOL>)<EOL>return False<EOL><DEDENT>logger.info('<STR_LIT>', self.dist.project_name)<EOL>for path in self._moved_paths:<EOL><INDENT>tmp_path = self._stash(path)<EOL>logger.debug('<STR_LIT>', path)<EOL>renames(tmp_path, path)<EOL><DEDENT>for pth in self.pth.values():<EOL><INDENT>pth.rollback()<EOL><DEDENT>

Rollback the changes previously made by remove().


if self.save_dir is not None:<EOL><INDENT>rmtree(self.save_dir)<EOL>self.save_dir = None<EOL>self._moved_paths = []<EOL><DEDENT>

Remove temporary save dir: rollback will no longer be possible.


<EOL>match = re.search(r'<STR_LIT>', req)<EOL>if match:<EOL><INDENT>req = match.group(<NUM_LIT:1>)<EOL><DEDENT>return req<EOL>


regexp = re.compile(r"<STR_LIT>")<EOL>matched = regexp.findall(req)<EOL>if matched:<EOL><INDENT>ret = dict()<EOL>for option in matched:<EOL><INDENT>(name, value) = option<EOL>if name in ret:<EOL><INDENT>raise Exception("<STR_LIT>" % name)<EOL><DEDENT>ret[name] = value<EOL><DEDENT>return ret<EOL><DEDENT>return None<EOL>

This method generates a dictionary of the query string
parameters contained in a given editable URL.


url = editable_req<EOL>extras = None<EOL>m = re.match(r'<STR_LIT>', url)<EOL>if m:<EOL><INDENT>url_no_extras = m.group(<NUM_LIT:1>)<EOL>extras = m.group(<NUM_LIT:2>)<EOL><DEDENT>else:<EOL><INDENT>url_no_extras = url<EOL><DEDENT>if os.path.isdir(url_no_extras):<EOL><INDENT>if not os.path.exists(os.path.join(url_no_extras, '<STR_LIT>')):<EOL><INDENT>raise InstallationError(<EOL>"<STR_LIT>" %<EOL>url_no_extras<EOL>)<EOL><DEDENT>url_no_extras = path_to_url(url_no_extras)<EOL><DEDENT>if url_no_extras.lower().startswith('<STR_LIT>'):<EOL><INDENT>if extras:<EOL><INDENT>return (<EOL>None,<EOL>url_no_extras,<EOL>pkg_resources.Requirement.parse(<EOL>'<STR_LIT>' + extras<EOL>).extras,<EOL>{},<EOL>)<EOL><DEDENT>else:<EOL><INDENT>return None, url_no_extras, None, {}<EOL><DEDENT><DEDENT>for version_control in vcs:<EOL><INDENT>if url.lower().startswith('<STR_LIT>' % version_control):<EOL><INDENT>url = '<STR_LIT>' % (version_control, url)<EOL>break<EOL><DEDENT><DEDENT>if '<STR_LIT:+>' not in url:<EOL><INDENT>if default_vcs:<EOL><INDENT>url = default_vcs + '<STR_LIT:+>' + url<EOL><DEDENT>else:<EOL><INDENT>raise InstallationError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>editable_req<EOL>)<EOL><DEDENT><DEDENT>vc_type = url.split('<STR_LIT:+>', <NUM_LIT:1>)[<NUM_LIT:0>].lower()<EOL>if not vcs.get_backend(vc_type):<EOL><INDENT>error_message = '<STR_LIT>' % editable_req +'<STR_LIT:U+002CU+0020>'.join([backend.name + '<STR_LIT>' for backend in vcs.backends]) +'<STR_LIT>'<EOL>raise InstallationError(error_message)<EOL><DEDENT>try:<EOL><INDENT>options = _build_editable_options(editable_req)<EOL><DEDENT>except Exception as exc:<EOL><INDENT>raise InstallationError(<EOL>'<STR_LIT>' % (editable_req, exc)<EOL>)<EOL><DEDENT>if not options or '<STR_LIT>' not in options:<EOL><INDENT>req = _build_req_from_url(editable_req)<EOL>if not req:<EOL><INDENT>raise InstallationError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % editable_req<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>req = options['<STR_LIT>']<EOL><DEDENT>package = _strip_postfix(req)<EOL>return package, url, None, options<EOL>

Parses an editable requirement into:
        - a requirement name
        - an URL
        - extras
        - editable options
    Accepted requirements:
        svn+http://blahblah@rev#egg=Foobar[baz]&subdirectory=version_subdir
        .[some_extra]


@classmethod<EOL><INDENT>def from_line(cls, name, comes_from=None, isolated=False):<DEDENT>

from pip.index import Link<EOL>url = None<EOL>if is_url(name):<EOL><INDENT>marker_sep = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>marker_sep = '<STR_LIT:;>'<EOL><DEDENT>if marker_sep in name:<EOL><INDENT>name, markers = name.split(marker_sep, <NUM_LIT:1>)<EOL>markers = markers.strip()<EOL>if not markers:<EOL><INDENT>markers = None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>markers = None<EOL><DEDENT>name = name.strip()<EOL>req = None<EOL>path = os.path.normpath(os.path.abspath(name))<EOL>link = None<EOL>if is_url(name):<EOL><INDENT>link = Link(name)<EOL><DEDENT>elif (os.path.isdir(path)<EOL>and (os.path.sep in name or name.startswith('<STR_LIT:.>'))):<EOL><INDENT>if not is_installable_dir(path):<EOL><INDENT>raise InstallationError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % name<EOL>)<EOL><DEDENT>link = Link(path_to_url(name))<EOL><DEDENT>elif is_archive_file(path):<EOL><INDENT>if not os.path.isfile(path):<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>',<EOL>name<EOL>)<EOL><DEDENT>link = Link(path_to_url(name))<EOL><DEDENT>if link:<EOL><INDENT>url = link.url<EOL>if link.scheme == '<STR_LIT:file>' and re.search(r'<STR_LIT>', url):<EOL><INDENT>url = path_to_url(os.path.normpath(os.path.abspath(link.path)))<EOL><DEDENT>if link.ext == wheel_ext:<EOL><INDENT>wheel = Wheel(link.filename)  <EOL>if not wheel.supported():<EOL><INDENT>raise UnsupportedWheel(<EOL>"<STR_LIT>" %<EOL>wheel.filename<EOL>)<EOL><DEDENT>req = "<STR_LIT>" % (wheel.name, wheel.version)<EOL><DEDENT>else:<EOL><INDENT>req = link.egg_fragment<EOL><DEDENT><DEDENT>else:<EOL><INDENT>req = name<EOL><DEDENT>return cls(req, comes_from, url=url, markers=markers,<EOL>isolated=isolated)<EOL>

Creates an InstallRequirement from a name, which might be a
        requirement, directory containing 'setup.py', filename, or URL.


if self.source_dir is not None:<EOL><INDENT>return<EOL><DEDENT>assert self.req is not None<EOL>assert self._temp_build_dir<EOL>old_location = self._temp_build_dir<EOL>new_build_dir = self._ideal_build_dir<EOL>del self._ideal_build_dir<EOL>if self.editable:<EOL><INDENT>name = self.name.lower()<EOL><DEDENT>else:<EOL><INDENT>name = self.name<EOL><DEDENT>new_location = os.path.join(new_build_dir, name)<EOL>if not os.path.exists(new_build_dir):<EOL><INDENT>logger.debug('<STR_LIT>', new_build_dir)<EOL>_make_build_dir(new_build_dir)<EOL><DEDENT>if os.path.exists(new_location):<EOL><INDENT>raise InstallationError(<EOL>'<STR_LIT>'<EOL>% display_path(new_location))<EOL><DEDENT>logger.debug(<EOL>'<STR_LIT>',<EOL>self, display_path(old_location), display_path(new_location),<EOL>)<EOL>shutil.move(old_location, new_location)<EOL>self._temp_build_dir = new_location<EOL>self.source_dir = new_location<EOL>self._egg_info_path = None<EOL>

If the build location was a temporary directory, this will move it
        to a new more permanent location


if not self.check_if_exists():<EOL><INDENT>raise UninstallationError(<EOL>"<STR_LIT>" % (self.name,)<EOL>)<EOL><DEDENT>dist = self.satisfied_by or self.conflicts_with<EOL>paths_to_remove = UninstallPathSet(dist)<EOL>develop_egg_link = egg_link_path(dist)<EOL>egg_info_exists = dist.egg_info and os.path.exists(dist.egg_info)<EOL>distutils_egg_info = getattr(dist._provider, '<STR_LIT:path>', None)<EOL>if develop_egg_link:<EOL><INDENT>with open(develop_egg_link, '<STR_LIT:r>') as fh:<EOL><INDENT>link_pointer = os.path.normcase(fh.readline().strip())<EOL><DEDENT>assert (link_pointer == dist.location), (<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % (link_pointer, self.name, dist.location)<EOL>)<EOL>paths_to_remove.add(develop_egg_link)<EOL>easy_install_pth = os.path.join(os.path.dirname(develop_egg_link),<EOL>'<STR_LIT>')<EOL>paths_to_remove.add_pth(easy_install_pth, dist.location)<EOL><DEDENT>elif egg_info_exists and dist.egg_info.endswith('<STR_LIT>'):<EOL><INDENT>paths_to_remove.add(dist.egg_info)<EOL>if dist.has_metadata('<STR_LIT>'):<EOL><INDENT>for installed_file in dist.get_metadata(<EOL>'<STR_LIT>').splitlines():<EOL><INDENT>path = os.path.normpath(<EOL>os.path.join(dist.egg_info, installed_file)<EOL>)<EOL>paths_to_remove.add(path)<EOL><DEDENT><DEDENT>elif dist.has_metadata('<STR_LIT>'):<EOL><INDENT>if dist.has_metadata('<STR_LIT>'):<EOL><INDENT>namespaces = dist.get_metadata('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>namespaces = []<EOL><DEDENT>for top_level_pkg in [<EOL>p for p<EOL>in dist.get_metadata('<STR_LIT>').splitlines()<EOL>if p and p not in namespaces]:<EOL><INDENT>path = os.path.join(dist.location, top_level_pkg)<EOL>paths_to_remove.add(path)<EOL>paths_to_remove.add(path + '<STR_LIT>')<EOL>paths_to_remove.add(path + '<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>elif distutils_egg_info:<EOL><INDENT>warnings.warn(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(self.name),<EOL>RemovedInPip8Warning,<EOL>)<EOL>paths_to_remove.add(distutils_egg_info)<EOL><DEDENT>elif dist.location.endswith('<STR_LIT>'):<EOL><INDENT>paths_to_remove.add(dist.location)<EOL>easy_install_egg = os.path.split(dist.location)[<NUM_LIT:1>]<EOL>easy_install_pth = os.path.join(os.path.dirname(dist.location),<EOL>'<STR_LIT>')<EOL>paths_to_remove.add_pth(easy_install_pth, '<STR_LIT>' + easy_install_egg)<EOL><DEDENT>elif egg_info_exists and dist.egg_info.endswith('<STR_LIT>'):<EOL><INDENT>for path in pip.wheel.uninstallation_paths(dist):<EOL><INDENT>paths_to_remove.add(path)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>logger.debug(<EOL>'<STR_LIT>',<EOL>dist, dist.location)<EOL><DEDENT>if dist.has_metadata('<STR_LIT>') and dist.metadata_isdir('<STR_LIT>'):<EOL><INDENT>for script in dist.metadata_listdir('<STR_LIT>'):<EOL><INDENT>if dist_in_usersite(dist):<EOL><INDENT>bin_dir = bin_user<EOL><DEDENT>else:<EOL><INDENT>bin_dir = bin_py<EOL><DEDENT>paths_to_remove.add(os.path.join(bin_dir, script))<EOL>if WINDOWS:<EOL><INDENT>paths_to_remove.add(os.path.join(bin_dir, script) + '<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>if dist.has_metadata('<STR_LIT>'):<EOL><INDENT>config = configparser.SafeConfigParser()<EOL>config.readfp(<EOL>FakeFile(dist.get_metadata_lines('<STR_LIT>'))<EOL>)<EOL>if config.has_section('<STR_LIT>'):<EOL><INDENT>for name, value in config.items('<STR_LIT>'):<EOL><INDENT>if dist_in_usersite(dist):<EOL><INDENT>bin_dir = bin_user<EOL><DEDENT>else:<EOL><INDENT>bin_dir = bin_py<EOL><DEDENT>paths_to_remove.add(os.path.join(bin_dir, name))<EOL>if WINDOWS:<EOL><INDENT>paths_to_remove.add(<EOL>os.path.join(bin_dir, name) + '<STR_LIT>'<EOL>)<EOL>paths_to_remove.add(<EOL>os.path.join(bin_dir, name) + '<STR_LIT>'<EOL>)<EOL>paths_to_remove.add(<EOL>os.path.join(bin_dir, name) + '<STR_LIT>'<EOL>)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>paths_to_remove.remove(auto_confirm)<EOL>self.uninstalled = paths_to_remove<EOL>

Uninstall the distribution currently satisfying this requirement.

Prompts before removing or modifying files unless
``auto_confirm`` is True.

Refuses to delete or modify files outside of ``sys.prefix`` -
thus uninstallation within a virtual environment can only
modify that virtual environment, even if the virtualenv is
linked to global site-packages.


if self.source_dir and os.path.exists(<EOL>os.path.join(self.source_dir, PIP_DELETE_MARKER_FILENAME)):<EOL><INDENT>logger.debug('<STR_LIT>', self.source_dir)<EOL>rmtree(self.source_dir)<EOL><DEDENT>self.source_dir = None<EOL>if self._temp_build_dir and os.path.exists(self._temp_build_dir):<EOL><INDENT>rmtree(self._temp_build_dir)<EOL><DEDENT>self._temp_build_dir = None<EOL>

Remove the source files from this requirement, if they are marked
        for deletion


if self.req is None:<EOL><INDENT>return False<EOL><DEDENT>try:<EOL><INDENT>if (self.req.project_name == '<STR_LIT>'<EOL>and self.conflicts_with<EOL>and self.conflicts_with.project_name == '<STR_LIT>'):<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>self.satisfied_by = pkg_resources.get_distribution(self.req)<EOL><DEDENT><DEDENT>except pkg_resources.DistributionNotFound:<EOL><INDENT>return False<EOL><DEDENT>except pkg_resources.VersionConflict:<EOL><INDENT>existing_dist = pkg_resources.get_distribution(<EOL>self.req.project_name<EOL>)<EOL>if self.use_user_site:<EOL><INDENT>if dist_in_usersite(existing_dist):<EOL><INDENT>self.conflicts_with = existing_dist<EOL><DEDENT>elif (running_under_virtualenv()<EOL>and dist_in_site_packages(existing_dist)):<EOL><INDENT>raise InstallationError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" %<EOL>(existing_dist.project_name, existing_dist.location)<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self.conflicts_with = existing_dist<EOL><DEDENT><DEDENT>return True<EOL>

Find an installed distribution that satisfies or conflicts
        with this requirement, and set self.satisfied_by or
        self.conflicts_with appropriately.


egg_info = self.egg_info_path('<STR_LIT>')<EOL>base_dir = os.path.dirname(egg_info)<EOL>metadata = pkg_resources.PathMetadata(base_dir, egg_info)<EOL>dist_name = os.path.splitext(os.path.basename(egg_info))[<NUM_LIT:0>]<EOL>return pkg_resources.Distribution(<EOL>os.path.dirname(egg_info),<EOL>project_name=dist_name,<EOL>metadata=metadata)<EOL>

Return a pkg_resources.Distribution built from self.egg_info_path


filepath = os.path.join(directory, PIP_DELETE_MARKER_FILENAME)<EOL>with open(filepath, '<STR_LIT:w>') as marker_fp:<EOL><INDENT>marker_fp.write(DELETE_MARKER_MESSAGE)<EOL><DEDENT>

Write the pip delete marker file into this directory.


if hasattr(sys, '<STR_LIT>'):<EOL><INDENT>return True<EOL><DEDENT>elif sys.prefix != getattr(sys, "<STR_LIT>", sys.prefix):<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>

Return True if we're running inside a virtualenv, False otherwise.


<EOL>site_mod_dir = os.path.dirname(os.path.abspath(site.__file__))<EOL>no_global_file = os.path.join(site_mod_dir, '<STR_LIT>')<EOL>if running_under_virtualenv() and os.path.isfile(no_global_file):<EOL><INDENT>return True<EOL><DEDENT>

Return True if in a venv and no system site packages.


if WINDOWS:<EOL><INDENT>return getpass.getuser()<EOL><DEDENT>import pwd<EOL>return pwd.getpwuid(os.geteuid()).pw_name<EOL>

Returns the effective username of the current process.


path = os.path.join(<EOL>tempfile.gettempdir(),<EOL>'<STR_LIT>' % __get_username().replace('<STR_LIT:U+0020>', '<STR_LIT:_>')<EOL>)<EOL>if WINDOWS:<EOL><INDENT>"""<STR_LIT>"""<EOL>return path<EOL><DEDENT>try:<EOL><INDENT>os.mkdir(path)<EOL>write_delete_marker_file(path)<EOL><DEDENT>except OSError:<EOL><INDENT>file_uid = None<EOL>try:<EOL><INDENT>file_uid = get_path_uid(path)<EOL><DEDENT>except OSError:<EOL><INDENT>file_uid = None<EOL><DEDENT>if file_uid != os.geteuid():<EOL><INDENT>msg = (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % path<EOL>)<EOL>print(msg)<EOL>print(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL>raise exceptions.InstallationError(msg)<EOL><DEDENT><DEDENT>return path<EOL>


def distutils_scheme(dist_name, user=False, home=None, root=None,<EOL>isolated=False):

from distutils.dist import Distribution<EOL>scheme = {}<EOL>if isolated:<EOL><INDENT>extra_dist_args = {"<STR_LIT>": ["<STR_LIT>"]}<EOL><DEDENT>else:<EOL><INDENT>extra_dist_args = {}<EOL><DEDENT>dist_args = {'<STR_LIT:name>': dist_name}<EOL>dist_args.update(extra_dist_args)<EOL>d = Distribution(dist_args)<EOL>d.parse_config_files()<EOL>i = d.get_command_obj('<STR_LIT>', create=True)<EOL>i.user = user or i.user<EOL>i.home = home or i.home<EOL>i.root = root or i.root<EOL>i.finalize_options()<EOL>for key in SCHEME_KEYS:<EOL><INDENT>scheme[key] = getattr(i, '<STR_LIT>' + key)<EOL><DEDENT>if i.install_lib is not None:<EOL><INDENT>scheme.update(dict(purelib=i.install_lib, platlib=i.install_lib))<EOL><DEDENT>if running_under_virtualenv():<EOL><INDENT>scheme['<STR_LIT>'] = os.path.join(<EOL>sys.prefix,<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>' + sys.version[:<NUM_LIT:3>],<EOL>dist_name,<EOL>)<EOL>if root is not None:<EOL><INDENT>scheme["<STR_LIT>"] = os.path.join(<EOL>root,<EOL>os.path.abspath(scheme["<STR_LIT>"])[<NUM_LIT:1>:],<EOL>)<EOL><DEDENT><DEDENT>return scheme<EOL>


_log_state.indentation += num<EOL>yield<EOL>_log_state.indentation -= num<EOL>

A context manager which will cause the log output to be indented for any
log messages emited inside it.


formatted = logging.Formatter.format(self, record)<EOL>formatted = "<STR_LIT>".join([<EOL>("<STR_LIT:U+0020>" * get_indentation()) + line<EOL>for line in formatted.splitlines(True)<EOL>])<EOL>return formatted<EOL>

Calls the standard formatter, but will indent all of the log messages
by our current indentation level.


import pip  <EOL>pypi_version = None<EOL>try:<EOL><INDENT>state = load_selfcheck_statefile()<EOL>current_time = datetime.datetime.utcnow()<EOL>if "<STR_LIT>" in state.state and "<STR_LIT>" in state.state:<EOL><INDENT>last_check = datetime.datetime.strptime(<EOL>state.state["<STR_LIT>"],<EOL>SELFCHECK_DATE_FMT<EOL>)<EOL>if total_seconds(current_time - last_check) < <NUM_LIT:7> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT>:<EOL><INDENT>pypi_version = state.state["<STR_LIT>"]<EOL><DEDENT><DEDENT>if pypi_version is None:<EOL><INDENT>resp = session.get(<EOL>PyPI.pip_json_url,<EOL>headers={"<STR_LIT>": "<STR_LIT:application/json>"},<EOL>)<EOL>resp.raise_for_status()<EOL>pypi_version = resp.json()["<STR_LIT:info>"]["<STR_LIT:version>"]<EOL>state.save(pypi_version, current_time)<EOL><DEDENT>pip_version = pkg_resources.parse_version(pip.__version__)<EOL>if pip_version < pkg_resources.parse_version(pypi_version):<EOL><INDENT>logger.warning(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (pip.__version__,<EOL>pypi_version)<EOL>)<EOL><DEDENT><DEDENT>except Exception:<EOL><INDENT>logger.debug(<EOL>"<STR_LIT>",<EOL>exc_info=True,<EOL>)<EOL><DEDENT>

Check for an update for pip.

    Limit the frequency of checks to once per week. State is stored either in
    the active virtualenv or in the user's USER_CACHE_DIR keyed off the prefix
    of the pip script path.


def rmtree_errorhandler(func, path, exc_info):

<EOL>if os.stat(path).st_mode & stat.S_IREAD:<EOL><INDENT>os.chmod(path, stat.S_IWRITE)<EOL>func(path)<EOL>return<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT>

On Windows, the files in .svn are read-only, so when rmtree() tries to
    remove them, an exception is thrown.  We catch that here, remove the
    read-only attribute, and hopefully continue without problems.


path = os.path.normcase(os.path.abspath(path))<EOL>if sys.version_info[<NUM_LIT:0>] == <NUM_LIT:2>:<EOL><INDENT>path = path.decode(sys.getfilesystemencoding(), '<STR_LIT:replace>')<EOL>path = path.encode(sys.getdefaultencoding(), '<STR_LIT:replace>')<EOL><DEDENT>if path.startswith(os.getcwd() + os.path.sep):<EOL><INDENT>path = '<STR_LIT:.>' + path[len(os.getcwd()):]<EOL><DEDENT>return path<EOL>

Gives the display value for a given path, making it relative to cwd
    if possible.


n = <NUM_LIT:1><EOL>extension = ext<EOL>while os.path.exists(dir + extension):<EOL><INDENT>n += <NUM_LIT:1><EOL>extension = ext + str(n)<EOL><DEDENT>return dir + extension<EOL>

Figure out the name of a directory to back up the given dir to
    (adding .bak, .bak2, etc)


def find_command(cmd, paths=None, pathext=None):

if paths is None:<EOL><INDENT>paths = os.environ.get('<STR_LIT>', '<STR_LIT>').split(os.pathsep)<EOL><DEDENT>if isinstance(paths, six.string_types):<EOL><INDENT>paths = [paths]<EOL><DEDENT>if pathext is None:<EOL><INDENT>pathext = get_pathext()<EOL><DEDENT>pathext = [ext for ext in pathext.lower().split(os.pathsep) if len(ext)]<EOL>if os.path.splitext(cmd)[<NUM_LIT:1>].lower() in pathext:<EOL><INDENT>pathext = ['<STR_LIT>']<EOL><DEDENT>for path in paths:<EOL><INDENT>cmd_path = os.path.join(path, cmd)<EOL>for ext in pathext:<EOL><INDENT>cmd_path_ext = cmd_path + ext<EOL>if os.path.isfile(cmd_path_ext):<EOL><INDENT>return cmd_path_ext<EOL><DEDENT><DEDENT>if os.path.isfile(cmd_path):<EOL><INDENT>return cmd_path<EOL><DEDENT><DEDENT>raise BadCommand('<STR_LIT>' % cmd)<EOL>

Searches the PATH for the given command and returns its path


if default_pathext is None:<EOL><INDENT>default_pathext = os.pathsep.join(['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'])<EOL><DEDENT>pathext = os.environ.get('<STR_LIT>', default_pathext)<EOL>return pathext<EOL>

Returns the path extensions from environment or a default


while <NUM_LIT:1>:<EOL><INDENT>if os.environ.get('<STR_LIT>'):<EOL><INDENT>raise Exception(<EOL>'<STR_LIT>' %<EOL>message<EOL>)<EOL><DEDENT>response = input(message)<EOL>response = response.strip().lower()<EOL>if response not in options:<EOL><INDENT>print(<EOL>'<STR_LIT>'<EOL>'<STR_LIT:%s>' % (response, '<STR_LIT:U+002CU+0020>'.join(options))<EOL>)<EOL><DEDENT>else:<EOL><INDENT>return response<EOL><DEDENT><DEDENT>

Ask the message interactively, with the given possible responses


if not os.path.isdir(path):<EOL><INDENT>return False<EOL><DEDENT>setup_py = os.path.join(path, '<STR_LIT>')<EOL>if os.path.isfile(setup_py):<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>

Return True if `path` is a directory containing a setup.py file.


return (re.search(r'<STR_LIT>', html)<EOL>and re.search(r'<STR_LIT>', html, re.I))<EOL>

Returns true if the page appears to be the index page of an svn repository


common_prefix = None<EOL>for path in paths:<EOL><INDENT>prefix, rest = split_leading_dir(path)<EOL>if not prefix:<EOL><INDENT>return False<EOL><DEDENT>elif common_prefix is None:<EOL><INDENT>common_prefix = prefix<EOL><DEDENT>elif prefix != common_prefix:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>return True<EOL>

Returns true if all the paths have the same leading path name
    (i.e., everything is in one subdirectory in an archive)


path_filename = os.path.basename(path)<EOL>path = os.path.dirname(path)<EOL>path = os.path.normpath(os.path.abspath(path))<EOL>rel_to = os.path.normpath(os.path.abspath(rel_to))<EOL>path_parts = path.strip(os.path.sep).split(os.path.sep)<EOL>rel_to_parts = rel_to.strip(os.path.sep).split(os.path.sep)<EOL>while path_parts and rel_to_parts and path_parts[<NUM_LIT:0>] == rel_to_parts[<NUM_LIT:0>]:<EOL><INDENT>path_parts.pop(<NUM_LIT:0>)<EOL>rel_to_parts.pop(<NUM_LIT:0>)<EOL><DEDENT>full_parts = ['<STR_LIT:..>'] * len(rel_to_parts) + path_parts + [path_filename]<EOL>if full_parts == ['<STR_LIT>']:<EOL><INDENT>return '<STR_LIT:.>' + os.path.sep<EOL><DEDENT>return os.path.sep.join(full_parts)<EOL>

Make a filename relative, where the filename path, and it is
relative to rel_to

    >>> make_path_relative('/usr/share/something/a-file.pth',
    ...                    '/usr/share/another-place/src/Directory')
    '../../../something/a-file.pth'
    >>> make_path_relative('/usr/share/something/a-file.pth',
    ...                    '/home/user/src/Directory')
    '../../../usr/share/something/a-file.pth'
    >>> make_path_relative('/usr/share/a-file.pth', '/usr/share/')
    'a-file.pth'


return os.path.normcase(os.path.realpath(os.path.expanduser(path)))<EOL>

Convert a path to its canonical, case-normalized, absolute version.


base, ext = posixpath.splitext(path)<EOL>if base.lower().endswith('<STR_LIT>'):<EOL><INDENT>ext = base[-<NUM_LIT:4>:] + ext<EOL>base = base[:-<NUM_LIT:4>]<EOL><DEDENT>return base, ext<EOL>

Like os.path.splitext, but take off .tar too


<EOL>head, tail = os.path.split(new)<EOL>if head and tail and not os.path.exists(head):<EOL><INDENT>os.makedirs(head)<EOL><DEDENT>shutil.move(old, new)<EOL>head, tail = os.path.split(old)<EOL>if head and tail:<EOL><INDENT>try:<EOL><INDENT>os.removedirs(head)<EOL><DEDENT>except OSError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>

Like os.renames(), but handles renaming across devices.


if not running_under_virtualenv():<EOL><INDENT>return True<EOL><DEDENT>return normalize_path(path).startswith(normalize_path(sys.prefix))<EOL>

Return True if path is within sys.prefix, if we're running in a virtualenv.

If we're not in a virtualenv, all paths are considered "local."


return is_local(dist_location(dist))<EOL>

Return True if given Distribution object is installed locally
(i.e. within current virtualenv).

Always True if we're not in a virtualenv.


norm_path = normalize_path(dist_location(dist))<EOL>return norm_path.startswith(normalize_path(user_site))<EOL>

Return True if given Distribution is installed in user site.


return normalize_path(<EOL>dist_location(dist)<EOL>).startswith(normalize_path(site_packages))<EOL>

Return True if given Distribution is installed in
distutils.sysconfig.get_python_lib().


<EOL>from pip import FrozenRequirement<EOL>req = FrozenRequirement.from_dist(dist, [])<EOL>return req.editable<EOL>


if local_only:<EOL><INDENT>local_test = dist_is_local<EOL><DEDENT>else:<EOL><INDENT>local_test = lambda d: True<EOL><DEDENT>if include_editables:<EOL><INDENT>editable_test = lambda d: True<EOL><DEDENT>else:<EOL><INDENT>editable_test = lambda d: not dist_is_editable(d)<EOL><DEDENT>if editables_only:<EOL><INDENT>editables_only_test = lambda d: dist_is_editable(d)<EOL><DEDENT>else:<EOL><INDENT>editables_only_test = lambda d: True<EOL><DEDENT>if user_only:<EOL><INDENT>user_test = dist_in_usersite<EOL><DEDENT>else:<EOL><INDENT>user_test = lambda d: True<EOL><DEDENT>return [d for d in pkg_resources.working_set<EOL>if local_test(d)<EOL>and d.key not in skip<EOL>and editable_test(d)<EOL>and editables_only_test(d)<EOL>and user_test(d)<EOL>]<EOL>

Return a list of installed Distribution objects.

If ``local_only`` is True (default), only return installations
local to the current virtualenv, if in a virtualenv.

``skip`` argument is an iterable of lower-case project names to
ignore; defaults to stdlib_pkgs

If ``editables`` is False, don't report editables.

If ``editables_only`` is True , only report editables.

If ``user_only`` is True , only report installations in the user
site directory.