source_file = cu.source_file()<EOL>try:<EOL><INDENT>source = source_file.read()<EOL><DEDENT>finally:<EOL><INDENT>source_file.close()<EOL><DEDENT>flat_rootname = cu.flat_rootname()<EOL>this_hash = self.file_hash(source, cu)<EOL>that_hash = self.status.file_hash(flat_rootname)<EOL>if this_hash == that_hash:<EOL><INDENT>self.files.append(self.status.index_info(flat_rootname))<EOL>return<EOL><DEDENT>self.status.set_file_hash(flat_rootname, this_hash)<EOL>if sys.version_info < (<NUM_LIT:3>, <NUM_LIT:0>):<EOL><INDENT>encoding = source_encoding(source)<EOL>if encoding.startswith("<STR_LIT:utf-8>") and source[:<NUM_LIT:3>] == "<STR_LIT>":<EOL><INDENT>source = source[<NUM_LIT:3>:]<EOL>encoding = "<STR_LIT:utf-8>"<EOL><DEDENT><DEDENT>nums = analysis.numbers<EOL>if self.arcs:<EOL><INDENT>missing_branch_arcs = analysis.missing_branch_arcs()<EOL><DEDENT>c_run = "<STR_LIT>"<EOL>c_exc = "<STR_LIT>"<EOL>c_mis = "<STR_LIT>"<EOL>c_par = "<STR_LIT>" + c_run<EOL>lines = []<EOL>for lineno, line in enumerate(source_token_lines(source)):<EOL><INDENT>lineno += <NUM_LIT:1>     <EOL>line_class = []<EOL>annotate_html = "<STR_LIT>"<EOL>annotate_title = "<STR_LIT>"<EOL>if lineno in analysis.statements:<EOL><INDENT>line_class.append("<STR_LIT>")<EOL><DEDENT>if lineno in analysis.excluded:<EOL><INDENT>line_class.append(c_exc)<EOL><DEDENT>elif lineno in analysis.missing:<EOL><INDENT>line_class.append(c_mis)<EOL><DEDENT>elif self.arcs and lineno in missing_branch_arcs:<EOL><INDENT>line_class.append(c_par)<EOL>annlines = []<EOL>for b in missing_branch_arcs[lineno]:<EOL><INDENT>if b < <NUM_LIT:0>:<EOL><INDENT>annlines.append("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>annlines.append(str(b))<EOL><DEDENT><DEDENT>annotate_html = "<STR_LIT>".join(annlines)<EOL>if len(annlines) > <NUM_LIT:1>:<EOL><INDENT>annotate_title = "<STR_LIT>"<EOL><DEDENT>elif len(annlines) == <NUM_LIT:1>:<EOL><INDENT>annotate_title = "<STR_LIT>"<EOL><DEDENT><DEDENT>elif lineno in analysis.statements:<EOL><INDENT>line_class.append(c_run)<EOL><DEDENT>html = []<EOL>for tok_type, tok_text in line:<EOL><INDENT>if tok_type == "<STR_LIT>":<EOL><INDENT>html.append(escape(tok_text))<EOL><DEDENT>else:<EOL><INDENT>tok_html = escape(tok_text) or '<STR_LIT>'<EOL>html.append(<EOL>"<STR_LIT>" % (tok_type, tok_html)<EOL>)<EOL><DEDENT><DEDENT>lines.append({<EOL>'<STR_LIT:html>': '<STR_LIT>'.join(html),<EOL>'<STR_LIT>': lineno,<EOL>'<STR_LIT:class>': '<STR_LIT:U+0020>'.join(line_class) or "<STR_LIT>",<EOL>'<STR_LIT>': annotate_html,<EOL>'<STR_LIT>': annotate_title,<EOL>})<EOL><DEDENT>html = spaceless(self.source_tmpl.render({<EOL>'<STR_LIT>': c_exc, '<STR_LIT>': c_mis, '<STR_LIT>': c_par, '<STR_LIT>': c_run,<EOL>'<STR_LIT>': self.arcs, '<STR_LIT>': self.extra_css,<EOL>'<STR_LIT>': cu, '<STR_LIT>': nums, '<STR_LIT>': lines,<EOL>}))<EOL>if sys.version_info < (<NUM_LIT:3>, <NUM_LIT:0>):<EOL><INDENT>html = html.decode(encoding)<EOL><DEDENT>html_filename = flat_rootname + "<STR_LIT>"<EOL>html_path = os.path.join(self.directory, html_filename)<EOL>self.write_html(html_path, html)<EOL>index_info = {<EOL>'<STR_LIT>': nums,<EOL>'<STR_LIT>': html_filename,<EOL>'<STR_LIT:name>': cu.name,<EOL>}<EOL>self.files.append(index_info)<EOL>self.status.set_index_info(flat_rootname, index_info)<EOL>

Generate an HTML file for one source file.


self.files.setdefault(fname, {})['<STR_LIT>'] = val<EOL>


self.coverage = coverage<EOL>self.config = config<EOL>self.code_units = []<EOL>self.directory = None<EOL>

Create a reporter.

        `coverage` is the coverage instance. `config` is an instance  of
        CoverageConfig, for controlling all sorts of behavior.


morfs = morfs or self.coverage.data.measured_files()<EOL>file_locator = self.coverage.file_locator<EOL>self.code_units = code_unit_factory(morfs, file_locator)<EOL>if self.config.include:<EOL><INDENT>patterns = prep_patterns(self.config.include)<EOL>filtered = []<EOL>for cu in self.code_units:<EOL><INDENT>for pattern in patterns:<EOL><INDENT>if fnmatch.fnmatch(cu.filename, pattern):<EOL><INDENT>filtered.append(cu)<EOL>break<EOL><DEDENT><DEDENT><DEDENT>self.code_units = filtered<EOL><DEDENT>if self.config.omit:<EOL><INDENT>patterns = prep_patterns(self.config.omit)<EOL>filtered = []<EOL>for cu in self.code_units:<EOL><INDENT>for pattern in patterns:<EOL><INDENT>if fnmatch.fnmatch(cu.filename, pattern):<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>filtered.append(cu)<EOL><DEDENT><DEDENT>self.code_units = filtered<EOL><DEDENT>self.code_units.sort()<EOL>

Find the code units we'll report on.

        `morfs` is a list of modules or filenames.


self.options = options<EOL>self.output = output<EOL>

Configure the options and output file for debugging.


<EOL>assert sys.version_info < (<NUM_LIT:3>, <NUM_LIT:0>)<EOL>cookie_re = re.compile(r"<STR_LIT>")<EOL>readline = iter(source.splitlines(True)).next<EOL>def _get_normal_name(orig_enc):<EOL><INDENT>"""<STR_LIT>"""<EOL>enc = orig_enc[:<NUM_LIT:12>].lower().replace("<STR_LIT:_>", "<STR_LIT:->")<EOL>if re.match(r"<STR_LIT>", enc):<EOL><INDENT>return "<STR_LIT:utf-8>"<EOL><DEDENT>if re.match(r"<STR_LIT>", enc):<EOL><INDENT>return "<STR_LIT>"<EOL><DEDENT>return orig_enc<EOL><DEDENT>if sys.version_info <= (<NUM_LIT:2>, <NUM_LIT:4>):<EOL><INDENT>default = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>default = '<STR_LIT:ascii>'<EOL><DEDENT>bom_found = False<EOL>encoding = None<EOL>def read_or_stop():<EOL><INDENT>"""<STR_LIT>"""<EOL>try:<EOL><INDENT>return readline()<EOL><DEDENT>except StopIteration:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT><DEDENT>def find_cookie(line):<EOL><INDENT>"""<STR_LIT>"""<EOL>try:<EOL><INDENT>line_string = line.decode('<STR_LIT:ascii>')<EOL><DEDENT>except UnicodeDecodeError:<EOL><INDENT>return None<EOL><DEDENT>matches = cookie_re.findall(line_string)<EOL>if not matches:<EOL><INDENT>return None<EOL><DEDENT>encoding = _get_normal_name(matches[<NUM_LIT:0>])<EOL>try:<EOL><INDENT>codec = codecs.lookup(encoding)<EOL><DEDENT>except LookupError:<EOL><INDENT>raise SyntaxError("<STR_LIT>" + encoding)<EOL><DEDENT>if bom_found:<EOL><INDENT>codec_name = getattr(codec, '<STR_LIT:name>', encoding)<EOL>if codec_name != '<STR_LIT:utf-8>':<EOL><INDENT>raise SyntaxError('<STR_LIT>')<EOL><DEDENT>encoding += '<STR_LIT>'<EOL><DEDENT>return encoding<EOL><DEDENT>first = read_or_stop()<EOL>if first.startswith(codecs.BOM_UTF8):<EOL><INDENT>bom_found = True<EOL>first = first[<NUM_LIT:3>:]<EOL>default = '<STR_LIT>'<EOL><DEDENT>if not first:<EOL><INDENT>return default<EOL><DEDENT>encoding = find_cookie(first)<EOL>if encoding:<EOL><INDENT>return encoding<EOL><DEDENT>second = read_or_stop()<EOL>if not second:<EOL><INDENT>return default<EOL><DEDENT>encoding = find_cookie(second)<EOL>if encoding:<EOL><INDENT>return encoding<EOL><DEDENT>return default<EOL>

Determine the encoding for `source` (a string), according to PEP 263.

    Returns a string, the name of the encoding.


ws_tokens = set([token.INDENT, token.DEDENT, token.NEWLINE, tokenize.NL])<EOL>line = []<EOL>col = <NUM_LIT:0><EOL>source = source.expandtabs(<NUM_LIT:8>).replace('<STR_LIT:\r\n>', '<STR_LIT:\n>')<EOL>tokgen = generate_tokens(source)<EOL>for ttype, ttext, (_, scol), (_, ecol), _ in phys_tokens(tokgen):<EOL><INDENT>mark_start = True<EOL>for part in re.split('<STR_LIT>', ttext):<EOL><INDENT>if part == '<STR_LIT:\n>':<EOL><INDENT>yield line<EOL>line = []<EOL>col = <NUM_LIT:0><EOL>mark_end = False<EOL><DEDENT>elif part == '<STR_LIT>':<EOL><INDENT>mark_end = False<EOL><DEDENT>elif ttype in ws_tokens:<EOL><INDENT>mark_end = False<EOL><DEDENT>else:<EOL><INDENT>if mark_start and scol > col:<EOL><INDENT>line.append(("<STR_LIT>", "<STR_LIT:U+0020>" * (scol - col)))<EOL>mark_start = False<EOL><DEDENT>tok_class = tokenize.tok_name.get(ttype, '<STR_LIT>').lower()[:<NUM_LIT:3>]<EOL>if ttype == token.NAME and keyword.iskeyword(ttext):<EOL><INDENT>tok_class = "<STR_LIT:key>"<EOL><DEDENT>line.append((tok_class, part))<EOL>mark_end = True<EOL><DEDENT>scol = <NUM_LIT:0><EOL><DEDENT>if mark_end:<EOL><INDENT>col = ecol<EOL><DEDENT><DEDENT>if line:<EOL><INDENT>yield line<EOL><DEDENT>

Generate a series of lines, one for each line in `source`.

    Each line is a list of pairs, each pair is a token::

        [('key', 'def'), ('ws', ' '), ('nam', 'hello'), ('op', '('), ... ]

    Each pair has a token class, and the token text.

    If you concatenate all the token texts, and then join them with newlines,
    you should have your original `source` back, with two differences:
    trailing whitespace is not preserved, and a final line with no newline
    is indistinguishable from a final line with a newline.


last_line = None<EOL>last_lineno = -<NUM_LIT:1><EOL>last_ttype = None<EOL>for ttype, ttext, (slineno, scol), (elineno, ecol), ltext in toks:<EOL><INDENT>if last_lineno != elineno:<EOL><INDENT>if last_line and last_line.endswith("<STR_LIT>"):<EOL><INDENT>inject_backslash = True<EOL>if last_ttype == tokenize.COMMENT:<EOL><INDENT>inject_backslash = False<EOL><DEDENT>elif ttype == token.STRING:<EOL><INDENT>if "<STR_LIT:\n>" in ttext and ttext.split('<STR_LIT:\n>', <NUM_LIT:1>)[<NUM_LIT:0>][-<NUM_LIT:1>] == '<STR_LIT:\\>':<EOL><INDENT>inject_backslash = False<EOL><DEDENT><DEDENT>if inject_backslash:<EOL><INDENT>ccol = len(last_line.split("<STR_LIT:\n>")[-<NUM_LIT:2>]) - <NUM_LIT:1><EOL>yield (<EOL><NUM_LIT>, "<STR_LIT>",<EOL>(slineno, ccol), (slineno, ccol+<NUM_LIT:2>),<EOL>last_line<EOL>)<EOL><DEDENT><DEDENT>last_line = ltext<EOL>last_ttype = ttype<EOL><DEDENT>yield ttype, ttext, (slineno, scol), (elineno, ecol), ltext<EOL>last_lineno = elineno<EOL><DEDENT>

Return all physical tokens, even line continuations.

    tokenize.generate_tokens() doesn't return a token for the backslash that
    continues lines.  This wrapper provides those tokens so that we can
    re-create a faithful representation of the original source.

    Returns the same values as generate_tokens()


return "<STR_LIT>" % (float(hit) / (num or <NUM_LIT:1.0>))<EOL>

Return the fraction of `hit`/`num`, as a string.


<EOL>outfile = outfile or sys.stdout<EOL>impl = xml.dom.minidom.getDOMImplementation()<EOL>docType = impl.createDocumentType(<EOL>"<STR_LIT>", None,<EOL>"<STR_LIT>"<EOL>)<EOL>self.xml_out = impl.createDocument(None, "<STR_LIT>", docType)<EOL>xcoverage = self.xml_out.documentElement<EOL>xcoverage.setAttribute("<STR_LIT:version>", __version__)<EOL>xcoverage.setAttribute("<STR_LIT>", str(int(time.time()*<NUM_LIT:1000>)))<EOL>xcoverage.appendChild(self.xml_out.createComment(<EOL>"<STR_LIT>" % __url__<EOL>))<EOL>xpackages = self.xml_out.createElement("<STR_LIT>")<EOL>xcoverage.appendChild(xpackages)<EOL>self.packages = {}<EOL>self.report_files(self.xml_file, morfs)<EOL>lnum_tot, lhits_tot = <NUM_LIT:0>, <NUM_LIT:0><EOL>bnum_tot, bhits_tot = <NUM_LIT:0>, <NUM_LIT:0><EOL>for pkg_name in sorted(self.packages.keys()):<EOL><INDENT>pkg_data = self.packages[pkg_name]<EOL>class_elts, lhits, lnum, bhits, bnum = pkg_data<EOL>xpackage = self.xml_out.createElement("<STR_LIT>")<EOL>xpackages.appendChild(xpackage)<EOL>xclasses = self.xml_out.createElement("<STR_LIT>")<EOL>xpackage.appendChild(xclasses)<EOL>for class_name in sorted(class_elts.keys()):<EOL><INDENT>xclasses.appendChild(class_elts[class_name])<EOL><DEDENT>xpackage.setAttribute("<STR_LIT:name>", pkg_name.replace(os.sep, '<STR_LIT:.>'))<EOL>xpackage.setAttribute("<STR_LIT>", rate(lhits, lnum))<EOL>xpackage.setAttribute("<STR_LIT>", rate(bhits, bnum))<EOL>xpackage.setAttribute("<STR_LIT>", "<STR_LIT:0>")<EOL>lnum_tot += lnum<EOL>lhits_tot += lhits<EOL>bnum_tot += bnum<EOL>bhits_tot += bhits<EOL><DEDENT>xcoverage.setAttribute("<STR_LIT>", rate(lhits_tot, lnum_tot))<EOL>xcoverage.setAttribute("<STR_LIT>", rate(bhits_tot, bnum_tot))<EOL>outfile.write(self.xml_out.toprettyxml())<EOL>denom = lnum_tot + bnum_tot<EOL>if denom == <NUM_LIT:0>:<EOL><INDENT>pct = <NUM_LIT:0.0><EOL><DEDENT>else:<EOL><INDENT>pct = <NUM_LIT> * (lhits_tot + bhits_tot) / denom<EOL><DEDENT>return pct<EOL>

Generate a Cobertura-compatible XML report for `morfs`.

        `morfs` is a list of modules or filenames.

        `outfile` is a file object to write the XML to.


vcs = detect_vcs()<EOL>return normalize_names(vcs.get_versioned_files())<EOL>

List all files under version control in the current directory.


<EOL>if not os.path.isfile('<STR_LIT>'):<EOL><INDENT>return<EOL><DEDENT>with open('<STR_LIT>') as manifest:<EOL><INDENT>contents = manifest.read()<EOL><DEDENT>ignore, ignore_regexps = _get_ignore_from_manifest(contents)<EOL>IGNORE.extend(ignore)<EOL>IGNORE_REGEXPS.extend(ignore_regexps)<EOL>

Read existing configuration from MANIFEST.in.

    We use that to ignore anything the MANIFEST.in ignores.


dirname = tempfile.mkdtemp(prefix='<STR_LIT>', suffix=hint)<EOL>try:<EOL><INDENT>yield dirname<EOL><DEDENT>finally:<EOL><INDENT>shutil.rmtree(dirname)<EOL><DEDENT>

Create a temporary directory, then clean it up.

    Use as a context manager: with mkdtemp('-purpose'): ...


def check_manifest(source_tree='<STR_LIT:.>', create=False, update=False,<EOL>python=sys.executable):

all_ok = True<EOL>python = os.path.abspath(python)  <EOL>with cd(source_tree):<EOL><INDENT>if not is_package():<EOL><INDENT>raise Failure('<STR_LIT>')<EOL><DEDENT>read_config()<EOL>read_manifest()<EOL>info_begin("<STR_LIT>")<EOL>all_source_files = sorted(get_vcs_files())<EOL>source_files = strip_sdist_extras(all_source_files)<EOL>info_continue("<STR_LIT>" % len(source_files))<EOL>info_begin("<STR_LIT>")<EOL>with mkdtemp('<STR_LIT>') as tempdir:<EOL><INDENT>run([python, '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', tempdir])<EOL>sdist_filename = get_one_file_in(tempdir)<EOL>info_continue("<STR_LIT>" % os.path.basename(sdist_filename))<EOL>sdist_files = sorted(normalize_names(strip_sdist_extras(<EOL>strip_toplevel_name(get_archive_file_list(sdist_filename)))))<EOL>info_continue("<STR_LIT>" % len(sdist_files))<EOL><DEDENT>existing_source_files = list(filter(os.path.exists, all_source_files))<EOL>missing_source_files = sorted(set(all_source_files) - set(existing_source_files))<EOL>if missing_source_files:<EOL><INDENT>warning("<STR_LIT>"<EOL>% format_list(missing_source_files))<EOL><DEDENT>info_begin("<STR_LIT>")<EOL>with mkdtemp('<STR_LIT>') as tempsourcedir:<EOL><INDENT>copy_files(existing_source_files, tempsourcedir)<EOL>if os.path.exists('<STR_LIT>') and '<STR_LIT>' not in source_files:<EOL><INDENT>copy_files(['<STR_LIT>'], tempsourcedir)<EOL><DEDENT>if '<STR_LIT>' not in source_files:<EOL><INDENT>copy_files(['<STR_LIT>'], tempsourcedir)<EOL><DEDENT>info_begin("<STR_LIT>")<EOL>with cd(tempsourcedir):<EOL><INDENT>with mkdtemp('<STR_LIT>') as tempdir:<EOL><INDENT>run([python, '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', tempdir])<EOL>sdist_filename = get_one_file_in(tempdir)<EOL>info_continue("<STR_LIT>" % os.path.basename(sdist_filename))<EOL>clean_sdist_files = sorted(normalize_names(strip_sdist_extras(<EOL>strip_toplevel_name(get_archive_file_list(sdist_filename)))))<EOL>info_continue("<STR_LIT>" % len(clean_sdist_files))<EOL><DEDENT><DEDENT><DEDENT>missing_from_manifest = set(source_files) - set(clean_sdist_files)<EOL>missing_from_VCS = set(sdist_files + clean_sdist_files) - set(source_files)<EOL>if not missing_from_manifest and not missing_from_VCS:<EOL><INDENT>info("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>error("<STR_LIT>"<EOL>% format_missing(missing_from_VCS, missing_from_manifest,<EOL>"<STR_LIT>", "<STR_LIT>"))<EOL>suggestions, unknowns = find_suggestions(missing_from_manifest)<EOL>user_asked_for_help = update or (create and not<EOL>os.path.exists('<STR_LIT>'))<EOL>if '<STR_LIT>' not in existing_source_files:<EOL><INDENT>if suggestions and not user_asked_for_help:<EOL><INDENT>info("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>info("<STR_LIT>")<EOL><DEDENT><DEDENT>if suggestions:<EOL><INDENT>info("<STR_LIT>"<EOL>% format_list(suggestions))<EOL>if user_asked_for_help:<EOL><INDENT>existed = os.path.exists('<STR_LIT>')<EOL>with open('<STR_LIT>', '<STR_LIT:a>') as f:<EOL><INDENT>if not existed:<EOL><INDENT>info("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>info("<STR_LIT>")<EOL>f.write('<STR_LIT>')<EOL><DEDENT>f.write('<STR_LIT:\n>'.join(suggestions) + '<STR_LIT:\n>')<EOL><DEDENT>if unknowns:<EOL><INDENT>info("<STR_LIT>"<EOL>% format_list(unknowns))<EOL><DEDENT><DEDENT><DEDENT>elif user_asked_for_help:<EOL><INDENT>info("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>all_ok = False<EOL><DEDENT>bad_ideas = find_bad_ideas(all_source_files)<EOL>if bad_ideas:<EOL><INDENT>warning("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% bad_ideas[<NUM_LIT:0>])<EOL>if len(bad_ideas) > <NUM_LIT:1>:<EOL><INDENT>warning("<STR_LIT>"<EOL>% format_list(bad_ideas[<NUM_LIT:1>:]))<EOL><DEDENT>all_ok = False<EOL><DEDENT><DEDENT>return all_ok<EOL>

Compare a generated source distribution with list of files in a VCS.

    Returns True if the manifest is fine.


return any(fnmatch.fnmatch(filename, pat) for pat in patterns)<EOL>

Does this filename match any of the patterns?


old_dir = os.getcwd()<EOL>try:<EOL><INDENT>os.chdir(directory)<EOL>yield<EOL><DEDENT>finally:<EOL><INDENT>os.chdir(old_dir)<EOL><DEDENT>

Change the current working directory, temporarily.

    Use as a context manager: with cd(d): ...


suggestions = set()<EOL>unknowns = []<EOL>for filename in filelist:<EOL><INDENT>if os.path.isdir(filename):<EOL><INDENT>continue<EOL><DEDENT>for pattern, suggestion in SUGGESTIONS:<EOL><INDENT>m = pattern.match(filename)<EOL>if m is not None:<EOL><INDENT>suggestions.add(pattern.sub(suggestion, filename))<EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>unknowns.append(filename)<EOL><DEDENT><DEDENT>return sorted(suggestions), unknowns<EOL>

Suggest MANIFEST.in patterns for missing files.


return base64.urlsafe_b64encode(data).rstrip(binary('<STR_LIT:=>'))<EOL>


pad = b'<STR_LIT:=>' * (<NUM_LIT:4> - (len(data) & <NUM_LIT:3>))<EOL>return base64.urlsafe_b64decode(data + pad)<EOL>


try:<EOL><INDENT>from pkg_resources import Distribution, Requirement<EOL><DEDENT>except ImportError:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>req = Requirement.parse(req)<EOL>selected = []<EOL>for wf in wheels:<EOL><INDENT>f = wf.parsed_filename<EOL>dist = Distribution(project_name=f.group("<STR_LIT:name>"), version=f.group("<STR_LIT>"))<EOL>if dist in req:<EOL><INDENT>selected.append(wf)<EOL><DEDENT><DEDENT>return selected<EOL>

List of wheels matching a requirement.

    :param req: The requirement to satisfy
    :param wheels: List of wheels to search.


egginfo = None<EOL>if egginfo_name:<EOL><INDENT>egginfo = egg_info_re.search(egginfo_name)<EOL>if not egginfo:<EOL><INDENT>raise ValueError("<STR_LIT>" %<EOL>(egginfo_name,))<EOL><DEDENT><DEDENT>w_name, sep, rest = wininfo_name.partition('<STR_LIT:->')<EOL>if not sep:<EOL><INDENT>raise ValueError("<STR_LIT>" %<EOL>(wininfo_name,))<EOL><DEDENT>rest = rest[:-<NUM_LIT:4>]<EOL>rest2, sep, w_pyver = rest.rpartition('<STR_LIT:->')<EOL>if sep and w_pyver.startswith('<STR_LIT>'):<EOL><INDENT>rest = rest2<EOL>w_pyver = w_pyver.replace('<STR_LIT:.>', '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>w_pyver = '<STR_LIT>'<EOL><DEDENT>w_ver, sep, w_arch = rest.rpartition('<STR_LIT:.>')<EOL>if not sep:<EOL><INDENT>raise ValueError("<STR_LIT>" %<EOL>(wininfo_name,))<EOL><DEDENT>if egginfo:<EOL><INDENT>w_name = egginfo.group('<STR_LIT:name>')<EOL>w_ver = egginfo.group('<STR_LIT>')<EOL><DEDENT>return dict(name=w_name, ver=w_ver, arch=w_arch, pyver=w_pyver)<EOL>

Extract metadata from filenames.

    Extracts the 4 metadataitems needed (name, version, pyversion, arch) from
    the installer filename and the name of the egg-info directory embedded in
    the zipfile (if any).

    The egginfo filename has the format::

        name-ver(-pyver)(-arch).egg-info

    The installer filename has the format::

        name-ver.arch(-pyver).exe

    Some things to note:

    1. The installer filename is not definitive. An installer can be renamed
       and work perfectly well as an installer. So more reliable data should
       be used whenever possible.
    2. The egg-info data should be preferred for the name and version, because
       these come straight from the distutils metadata, and are mandatory.
    3. The pyver from the egg-info data should be ignored, as it is
       constructed from the version of Python used to build the installer,
       which is irrelevant - the installer filename is correct here (even to
       the point that when it's not there, any version is implied).
    4. The architecture must be taken from the installer filename, as it is
       not included in the egg-info data.
    5. Architecture-neutral installers still have an architecture because the
       installer format itself (being executable) is architecture-specific. We
       should therefore ignore the architecture if the content is pure-python.


additional = list(self.setupcfg_requirements())<EOL>if not additional: return<EOL>pkg_info = read_pkg_info(metadata_path)<EOL>if '<STR_LIT>' in pkg_info or '<STR_LIT>' in pkg_info:<EOL><INDENT>warnings.warn('<STR_LIT>')<EOL>del pkg_info['<STR_LIT>']<EOL>del pkg_info['<STR_LIT>']<EOL><DEDENT>for k, v in additional:<EOL><INDENT>pkg_info[k] = v<EOL><DEDENT>write_pkg_info(metadata_path, pkg_info)<EOL>

Add additional requirements from setup.cfg to file metadata_path


def egg2dist(self, egginfo_path, distinfo_path):

def adios(p):<EOL><INDENT>"""<STR_LIT>"""<EOL>if os.path.exists(p) and not os.path.islink(p) and os.path.isdir(p):<EOL><INDENT>shutil.rmtree(p)<EOL><DEDENT>elif os.path.exists(p):<EOL><INDENT>os.unlink(p)<EOL><DEDENT><DEDENT>adios(distinfo_path)<EOL>if not os.path.exists(egginfo_path):<EOL><INDENT>import glob<EOL>pat = os.path.join(os.path.dirname(egginfo_path), '<STR_LIT>')<EOL>possible = glob.glob(pat)<EOL>err = "<STR_LIT>" % (egginfo_path,)<EOL>if possible:<EOL><INDENT>alt = os.path.basename(possible[<NUM_LIT:0>])<EOL>err += "<STR_LIT>" % (alt,)<EOL><DEDENT>raise ValueError(err)<EOL><DEDENT>if os.path.isfile(egginfo_path):<EOL><INDENT>pkginfo_path = egginfo_path<EOL>pkg_info = self._pkginfo_to_metadata(egginfo_path, egginfo_path)<EOL>os.mkdir(distinfo_path)<EOL><DEDENT>else:<EOL><INDENT>pkginfo_path = os.path.join(egginfo_path, '<STR_LIT>')<EOL>pkg_info = self._pkginfo_to_metadata(egginfo_path, pkginfo_path)<EOL>shutil.copytree(egginfo_path, distinfo_path,<EOL>ignore=lambda x, y: set(('<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',)))<EOL>dependency_links = os.path.join(distinfo_path, '<STR_LIT>')<EOL>if not open(dependency_links, '<STR_LIT:r>').read().strip():<EOL><INDENT>adios(dependency_links)<EOL><DEDENT><DEDENT>write_pkg_info(os.path.join(distinfo_path, '<STR_LIT>'), pkg_info)<EOL>metadata_path = os.path.join(distinfo_path, '<STR_LIT>')<EOL>self.add_requirements(metadata_path)<EOL>metadata_json_path = os.path.join(distinfo_path, '<STR_LIT>')<EOL>pymeta = pkginfo_to_dict(metadata_path,<EOL>distribution=self.distribution)<EOL>if '<STR_LIT:description>' in pymeta:<EOL><INDENT>description_filename = '<STR_LIT>'<EOL>description_text = pymeta.pop('<STR_LIT:description>')<EOL>description_path = os.path.join(distinfo_path,<EOL>description_filename)<EOL>with open(description_path, "<STR_LIT:wb>") as description_file:<EOL><INDENT>description_file.write(description_text.encode('<STR_LIT:utf-8>'))<EOL><DEDENT>pymeta['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT:description>'] = description_filename<EOL><DEDENT>license = self.license_file()<EOL>if license:<EOL><INDENT>license_filename = '<STR_LIT>'<EOL>shutil.copy(license, os.path.join(self.distinfo_dir, license_filename))<EOL>pymeta['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] = license_filename<EOL><DEDENT>with open(metadata_json_path, "<STR_LIT:w>") as metadata_json:<EOL><INDENT>json.dump(pymeta, metadata_json)<EOL><DEDENT>adios(egginfo_path)<EOL>

Convert an .egg-info directory into a .dist-info directory


return self.compatibility_rank(self.context())<EOL>

Lowest index of any of this wheel's tags in self.context(), and the
arity e.g. (0, 1)


tags = self.parsed_filename.groupdict()<EOL>for pyver in tags['<STR_LIT>'].split('<STR_LIT:.>'):<EOL><INDENT>for abi in tags['<STR_LIT>'].split('<STR_LIT:.>'):<EOL><INDENT>for plat in tags['<STR_LIT>'].split('<STR_LIT:.>'):<EOL><INDENT>yield (pyver, abi, plat)<EOL><DEDENT><DEDENT><DEDENT>

A wheel file is compatible with the Cartesian product of the
        period-delimited tags in its filename.
        To choose a wheel file among several candidates having the same
        distribution version 'ver', an installer ranks each triple of
        (pyver, abi, plat) that its Python installation can run, sorting
        the wheels by the best-ranked tag it supports and then by their
        arity which is just len(list(compatibility_tags)).


return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))<EOL>

Parse wheel metadata (the .data/WHEEL file)


global parse_version<EOL>try:<EOL><INDENT>from pkg_resources import parse_version<EOL><DEDENT>except ImportError:<EOL><INDENT>from distutils.version import LooseVersion as parse_version<EOL><DEDENT>return parse_version(version)<EOL>

Use parse_version from pkg_resources or distutils as available.


preferences = []<EOL>for tag in self.compatibility_tags:<EOL><INDENT>try:<EOL><INDENT>preferences.append(supported.index(tag))<EOL><DEDENT>except ValueError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>if len(preferences):<EOL><INDENT>return (min(preferences), self.arity)<EOL><DEDENT>return (_big_number, <NUM_LIT:0>)<EOL>

Rank the wheel against the supported tags. Smaller ranks are more
        compatible!

        :param supported: A list of compatibility tags that the current
            Python implemenation can run.


return len(list(self.compatibility_tags))<EOL>

The number of compatibility tags the wheel declares.


for req in requirements:<EOL><INDENT>parsed_requirement = pkg_resources.Requirement.parse(req)<EOL>spec = requires_to_requires_dist(parsed_requirement)<EOL>extras = "<STR_LIT:U+002C>".join(parsed_requirement.extras)<EOL>if extras:<EOL><INDENT>extras = "<STR_LIT>" % extras<EOL><DEDENT>yield (parsed_requirement.project_name + extras + spec)<EOL><DEDENT>

Yield Requires-Dist: strings for parsed requirements strings.


description = pkg_info['<STR_LIT>']<EOL>surrogates = False<EOL>if not isinstance(description, str):<EOL><INDENT>surrogates = True<EOL>description = pkginfo_unicode(pkg_info, '<STR_LIT>')<EOL><DEDENT>description_lines = description.splitlines()<EOL>description_dedent = '<STR_LIT:\n>'.join(<EOL>(description_lines[<NUM_LIT:0>].lstrip(),<EOL>textwrap.dedent('<STR_LIT:\n>'.join(description_lines[<NUM_LIT:1>:])),<EOL>'<STR_LIT:\n>'))<EOL>if surrogates:<EOL><INDENT>description_dedent = description_dedent.encode("<STR_LIT:utf8>").decode("<STR_LIT:ascii>", "<STR_LIT>")<EOL><DEDENT>return description_dedent<EOL>

Dedent and convert pkg_info['Description'] to Unicode.


requires_dist = []<EOL>for op, ver in requirement.specs:<EOL><INDENT>requires_dist.append(op + ver)<EOL><DEDENT>if not requires_dist:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>return "<STR_LIT>" % '<STR_LIT:U+002C>'.join(requires_dist)<EOL>

Compose the version predicates for requirement in PEP 345 fashion.


trust = [(x['<STR_LIT>'], x['<STR_LIT>']) for x in self.data['<STR_LIT>'] if x['<STR_LIT>'] in (scope, '<STR_LIT:+>')]<EOL>trust.sort(key=lambda x: x[<NUM_LIT:0>])<EOL>trust.reverse()<EOL>return trust<EOL>

Return list of [(scope, trusted key), ...] for given scope.


self.data['<STR_LIT>'].remove({'<STR_LIT>':scope, '<STR_LIT>':vk})<EOL>return self<EOL>

Stop trusting a particular key for given scope.


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 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 '<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


<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


raise NotImplementedError<EOL>

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


raise NotImplementedError<EOL>

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


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

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


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


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


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


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.


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>


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


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 isinstance(value, list):<EOL><INDENT>value = tuple(value)<EOL><DEDENT>return value<EOL>

Utility function which converts lists to tuples.


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.


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.


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


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.


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)


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


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


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 =


<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>


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.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


with open(filename, '<STR_LIT:rb>') as fp:<EOL><INDENT>data = fp.read()<EOL><DEDENT>encodings = ['<STR_LIT:utf-8>', locale.getpreferredencoding(False), '<STR_LIT>']<EOL>for enc in encodings:<EOL><INDENT>try:<EOL><INDENT>data = data.decode(enc)<EOL><DEDENT>except UnicodeDecodeError:<EOL><INDENT>continue<EOL><DEDENT>break<EOL><DEDENT>assert type(data) != bytes  <EOL>return data<EOL>

Return the contents of *filename*.

    Try to decode the file contents with utf-8, the preferred system encoding
    (e.g., cp1252 on some Windows machines), and latin1, in that order.
    Decoding a byte string with latin1 will never raise an error. In the worst
    case, the returned string will contain some garbage characters.


return captured_output('<STR_LIT>')<EOL>

Capture the output of sys.stdout:

       with captured_stdout() as stdout:
           print('hello')
       self.assertEqual(stdout.getvalue(), 'hello\n')

    Taken from Lib/support/__init__.py in the CPython repo.


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."


if not os.path.exists(location):<EOL><INDENT>os.makedirs(location)<EOL><DEDENT>if filename.lower().endswith('<STR_LIT>') or filename.lower().endswith('<STR_LIT>'):<EOL><INDENT>mode = '<STR_LIT>'<EOL><DEDENT>elif (filename.lower().endswith('<STR_LIT>')<EOL>or filename.lower().endswith('<STR_LIT>')):<EOL><INDENT>mode = '<STR_LIT>'<EOL><DEDENT>elif filename.lower().endswith('<STR_LIT>'):<EOL><INDENT>mode = '<STR_LIT:r>'<EOL><DEDENT>else:<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>', filename,<EOL>)<EOL>mode = '<STR_LIT>'<EOL><DEDENT>tar = tarfile.open(filename, mode)<EOL>try:<EOL><INDENT>leading = has_leading_dir([<EOL>member.name for member in tar.getmembers()<EOL>if member.name != '<STR_LIT>'<EOL>])<EOL>for member in tar.getmembers():<EOL><INDENT>fn = member.name<EOL>if fn == '<STR_LIT>':<EOL><INDENT>continue<EOL><DEDENT>if leading:<EOL><INDENT>fn = split_leading_dir(fn)[<NUM_LIT:1>]<EOL><DEDENT>path = os.path.join(location, fn)<EOL>if member.isdir():<EOL><INDENT>if not os.path.exists(path):<EOL><INDENT>os.makedirs(path)<EOL><DEDENT><DEDENT>elif member.issym():<EOL><INDENT>try:<EOL><INDENT>tar._extract_member(member, path)<EOL><DEDENT>except Exception as exc:<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>',<EOL>filename, member.name, exc,<EOL>)<EOL>continue<EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>fp = tar.extractfile(member)<EOL><DEDENT>except (KeyError, AttributeError) as exc:<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>',<EOL>filename, member.name, exc,<EOL>)<EOL>continue<EOL><DEDENT>if not os.path.exists(os.path.dirname(path)):<EOL><INDENT>os.makedirs(os.path.dirname(path))<EOL><DEDENT>destfp = open(path, '<STR_LIT:wb>')<EOL>try:<EOL><INDENT>shutil.copyfileobj(fp, destfp)<EOL><DEDENT>finally:<EOL><INDENT>destfp.close()<EOL><DEDENT>fp.close()<EOL>if member.mode & <NUM_LIT>:<EOL><INDENT>os.chmod(path, (<NUM_LIT> - current_umask() | <NUM_LIT>))<EOL><DEDENT><DEDENT><DEDENT><DEDENT>finally:<EOL><INDENT>tar.close()<EOL><DEDENT>

Untar the file (with path `filename`) to the destination `location`.
All files are written based on system defaults and umask (i.e. permissions
are not preserved), except that regular file members with any execute
permissions (user, group, or world) have "chmod +x" applied after being
written.  Note that for windows, any execute changes using os.chmod are
no-ops per the python docs.


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.


shells = COMPLETION_SCRIPTS.keys()<EOL>shell_options = ['<STR_LIT>' + shell for shell in sorted(shells)]<EOL>if options.shell in shells:<EOL><INDENT>script = COMPLETION_SCRIPTS.get(options.shell, '<STR_LIT>')<EOL>print(BASE_COMPLETION % {'<STR_LIT>': script, '<STR_LIT>': options.shell})<EOL><DEDENT>else:<EOL><INDENT>sys.stderr.write(<EOL>'<STR_LIT>' % '<STR_LIT>'.join(shell_options)<EOL>)<EOL><DEDENT>

Prints the completion code of the given shell


packages = {}<EOL>for hit in hits:<EOL><INDENT>name = hit['<STR_LIT:name>']<EOL>summary = hit['<STR_LIT>']<EOL>version = hit['<STR_LIT:version>']<EOL>score = hit['<STR_LIT>']<EOL>if score is None:<EOL><INDENT>score = <NUM_LIT:0><EOL><DEDENT>if name not in packages.keys():<EOL><INDENT>packages[name] = {<EOL>'<STR_LIT:name>': name,<EOL>'<STR_LIT>': summary,<EOL>'<STR_LIT>': [version],<EOL>'<STR_LIT>': score,<EOL>}<EOL><DEDENT>else:<EOL><INDENT>packages[name]['<STR_LIT>'].append(version)<EOL>if version == highest_version(packages[name]['<STR_LIT>']):<EOL><INDENT>packages[name]['<STR_LIT>'] = summary<EOL>packages[name]['<STR_LIT>'] = score<EOL><DEDENT><DEDENT><DEDENT>package_list = sorted(<EOL>packages.values(),<EOL>key=lambda x: x['<STR_LIT>'],<EOL>reverse=True,<EOL>)<EOL>return package_list<EOL>

The list from pypi is really a list of versions. We want a list of
packages with the list of versions stored inline. This converts the
list from pypi into one we can use.


def _build_package_finder(self, options, index_urls, session):

Create a package finder appropriate to this install command.
This method is meant to be overridden by subclasses, not
called directly.


from difflib import get_close_matches<EOL>name = name.lower()<EOL>close_commands = get_close_matches(name, commands_dict.keys())<EOL>if close_commands:<EOL><INDENT>return close_commands[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>


return self.convert or self.strip or self.autoreset<EOL>

True if this class is actually needed. If false, then the output
stream will not be affected, nor will win32 calls be issued, so
wrapping stdout is not actually required. This will generally be
False on non-Windows platforms, unless optional functionality like
autoreset has been requested using kwargs to init()


cursor = <NUM_LIT:0><EOL>text = self.convert_osc(text)<EOL>for match in self.ANSI_CSI_RE.finditer(text):<EOL><INDENT>start, end = match.span()<EOL>self.write_plain_text(text, cursor, start)<EOL>self.convert_ansi(*match.groups())<EOL>cursor = end<EOL><DEDENT>self.write_plain_text(text, cursor, len(text))<EOL>

Write the given text to our wrapped stream, stripping any ANSI
sequences from the text, and optionally converting them into win32
calls.


def parseFragment(self, stream, container="<STR_LIT>", encoding=None,<EOL>parseMeta=False, useChardet=True):

self._parse(stream, True, container=container, encoding=encoding)<EOL>return self.tree.getFragment()<EOL>

Parse a HTML fragment into a well-formed tree fragment

        container - name of the element we're setting the innerHTML property
        if set to None, default to 'div'

        stream - a filelike object or string containing the HTML to be parsed

        The optional encoding parameter must be a string that indicates
        the encoding.  If specified, that encoding will be used,
        regardless of any BOM or later declaration (such as in a meta
        element)


def parse(doc, treebuilder="<STR_LIT>", encoding=None,<EOL>namespaceHTMLElements=True):

tb = treebuilders.getTreeBuilder(treebuilder)<EOL>p = HTMLParser(tb, namespaceHTMLElements=namespaceHTMLElements)<EOL>return p.parse(doc, encoding=encoding)<EOL>

Parse a string or file-like object into a tree


def __init__(self, tree=None, tokenizer=tokenizer.HTMLTokenizer,<EOL>strict=False, namespaceHTMLElements=True, debug=False):

<EOL>self.strict = strict<EOL>if tree is None:<EOL><INDENT>tree = treebuilders.getTreeBuilder("<STR_LIT>")<EOL><DEDENT>self.tree = tree(namespaceHTMLElements)<EOL>self.tokenizer_class = tokenizer<EOL>self.errors = []<EOL>self.phases = dict([(name, cls(self, self.tree)) for name, cls in<EOL>getPhases(debug).items()])<EOL>

strict - raise an exception when a parse error is encountered

tree - a treebuilder class controlling the type of tree that will be
returned. Built in treebuilders can be accessed through
html5lib.treebuilders.getTreeBuilder(treeType)

tokenizer - a class that provides a stream of tokens to the treebuilder.
This may be replaced for e.g. a sanitizer which converts some tags to
text


raise NotImplementedError<EOL>

Return a shallow copy of the current node i.e. a node with the same
        name and attributes but with no parent or child nodes


raise NotImplementedError<EOL>

Insert node as a child of the current node


name = token["<STR_LIT:name>"]<EOL>namespace = token.get("<STR_LIT>", self.defaultNamespace)<EOL>element = self.elementClass(name, namespace)<EOL>element.attributes = token["<STR_LIT:data>"]<EOL>return element<EOL>

Create an element but don't insert it anywhere


def insertText(self, data, parent=None):

if parent is None:<EOL><INDENT>parent = self.openElements[-<NUM_LIT:1>]<EOL><DEDENT>if (not self.insertFromTable or (self.insertFromTable and<EOL>self.openElements[-<NUM_LIT:1>].name<EOL>not in tableInsertModeElements)):<EOL><INDENT>parent.insertText(data)<EOL><DEDENT>else:<EOL><INDENT>parent, insertBefore = self.getTableMisnestedNodePosition()<EOL>parent.insertText(data, insertBefore)<EOL><DEDENT>


self._insertFromTable = value<EOL>if value:<EOL><INDENT>self.insertElement = self.insertElementTable<EOL><DEDENT>else:<EOL><INDENT>self.insertElement = self.insertElementNormal<EOL><DEDENT>

Switch the function used to insert an element from the
        normal one to the misnested table one and back again


raise NotImplementedError<EOL>

Insert node as a child of the current node, before refNode in the
        list of child nodes. Raises ValueError if refNode is not a child of
        the current node


rv = []<EOL>finalText = None<EOL>def serializeElement(element):<EOL><INDENT>if not hasattr(element, "<STR_LIT>"):<EOL><INDENT>if element.docinfo.internalDTD:<EOL><INDENT>if element.docinfo.doctype:<EOL><INDENT>dtd_str = element.docinfo.doctype<EOL><DEDENT>else:<EOL><INDENT>dtd_str = "<STR_LIT>" % element.docinfo.root_name<EOL><DEDENT>rv.append(dtd_str)<EOL><DEDENT>serializeElement(element.getroot())<EOL><DEDENT>elif element.tag == comment_type:<EOL><INDENT>rv.append("<STR_LIT>" % (element.text,))<EOL><DEDENT>else:<EOL><INDENT>if not element.attrib:<EOL><INDENT>rv.append("<STR_LIT>" % (element.tag,))<EOL><DEDENT>else:<EOL><INDENT>attr = "<STR_LIT:U+0020>".join(["<STR_LIT>" % (name, value)<EOL>for name, value in element.attrib.items()])<EOL>rv.append("<STR_LIT>" % (element.tag, attr))<EOL><DEDENT>if element.text:<EOL><INDENT>rv.append(element.text)<EOL><DEDENT>for child in element:<EOL><INDENT>serializeElement(child)<EOL><DEDENT>rv.append("<STR_LIT>" % (element.tag,))<EOL><DEDENT>if hasattr(element, "<STR_LIT>") and element.tail:<EOL><INDENT>rv.append(element.tail)<EOL><DEDENT><DEDENT>serializeElement(element)<EOL>if finalText is not None:<EOL><INDENT>rv.append("<STR_LIT>" % ('<STR_LIT:U+0020>' * <NUM_LIT:2>, finalText))<EOL><DEDENT>return "<STR_LIT>".join(rv)<EOL>

Serialize an element and its child nodes to a string


p = self.position<EOL>data = self[p:p + len(bytes)]<EOL>rv = data.startswith(bytes)<EOL>if rv:<EOL><INDENT>self.position += len(bytes)<EOL><DEDENT>return rv<EOL>

Look for a sequence of bytes at the start of a string. If the bytes
        are found return True and advance the position to the byte after the
        match. Otherwise return False and leave the position alone


<EOL>if hasattr(source, '<STR_LIT>'):<EOL><INDENT>stream = source<EOL><DEDENT>else:<EOL><INDENT>stream = StringIO(source)<EOL><DEDENT>return stream<EOL>

Produces a file object from source.

        source can be either a file object, local filename or a string.


pass<EOL>


List of resource names in the directory (like ``os.listdir()``)


self.entry_keys.setdefault(entry, [])<EOL>self.entries.append(entry)<EOL>for dist in find_distributions(entry, True):<EOL><INDENT>self.add(dist, entry, False)<EOL><DEDENT>

Add a path item to ``.entries``, finding any distributions on it

        ``find_distributions(entry, True)`` is used to find distributions
        corresponding to the path entry, and they are added.  `entry` is
        always appended to ``.entries``, even if it is already present.
        (This is because ``sys.path`` can contain the same value more than
        once, and the ``.entries`` of the ``sys.path`` WorkingSet should always
        equal ``sys.path``.)


parts = requires_dist.split('<STR_LIT:;>', <NUM_LIT:1>) + ['<STR_LIT>']<EOL>distvers = parts[<NUM_LIT:0>].strip()<EOL>mark = parts[<NUM_LIT:1>].strip()<EOL>distvers = re.sub(self.EQEQ, r"<STR_LIT>", distvers)<EOL>distvers = distvers.replace('<STR_LIT:(>', '<STR_LIT>').replace('<STR_LIT:)>', '<STR_LIT>')<EOL>return (distvers, mark)<EOL>

Convert 'Foobar (1); baz' to ('Foobar ==1', 'baz')
        Split environment marker, add == prefix to version specifiers as
        necessary, and remove parenthesis.


ws = cls()<EOL>try:<EOL><INDENT>from __main__ import __requires__<EOL><DEDENT>except ImportError:<EOL><INDENT>return ws<EOL><DEDENT>try:<EOL><INDENT>ws.require(__requires__)<EOL><DEDENT>except VersionConflict:<EOL><INDENT>return cls._build_from_requirements(__requires__)<EOL><DEDENT>return ws<EOL>


importer = get_importer(path_item)<EOL>finder = _find_adapter(_distribution_finders, importer)<EOL>return finder(importer, path_item, only)<EOL>

Yield distributions accessible via `path_item`


filename = "<STR_LIT>" % (<EOL>to_filename(self.project_name), to_filename(self.version),<EOL>self.py_version or PY_MAJOR<EOL>)<EOL>if self.platform:<EOL><INDENT>filename += '<STR_LIT:->' + self.platform<EOL><DEDENT>return filename<EOL>

Return what this distribution's standard .egg filename should be


Does the package contain the named resource?


try:<EOL><INDENT>return os.environ['<STR_LIT>']<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT>if os.name!='<STR_LIT>':<EOL><INDENT>return os.path.expanduser('<STR_LIT>')<EOL><DEDENT>app_data = '<STR_LIT>'<EOL>app_homes = [<EOL>(('<STR_LIT>',), None),<EOL>(('<STR_LIT>',), app_data),<EOL>(('<STR_LIT>','<STR_LIT>'), app_data),<EOL>(('<STR_LIT>',), app_data),<EOL>(('<STR_LIT>',), None),<EOL>(('<STR_LIT>',), app_data),<EOL>]<EOL>for keys, subdir in app_homes:<EOL><INDENT>dirname = '<STR_LIT>'<EOL>for key in keys:<EOL><INDENT>if key in os.environ:<EOL><INDENT>dirname = os.path.join(dirname, os.environ[key])<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if subdir:<EOL><INDENT>dirname = os.path.join(dirname, subdir)<EOL><DEDENT>return os.path.join(dirname, '<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise RuntimeError(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>

Determine the default cache location

    This returns the ``PYTHON_EGG_CACHE`` environment variable, if set.
    Otherwise, on Windows, it returns a "Python-Eggs" subdirectory of the
    "Application Data" directory.  On all other systems, it's "~/.python-eggs".


def _is_current(self, file_path, zip_path):

timestamp, size = self._get_date_and_size(self.zipinfo[zip_path])<EOL>if not os.path.isfile(file_path):<EOL><INDENT>return False<EOL><DEDENT>stat = os.stat(file_path)<EOL>if stat.st_size!=size or stat.st_mtime!=timestamp:<EOL><INDENT>return False<EOL><DEDENT>zip_contents = self.loader.get_data(zip_path)<EOL>with open(file_path, '<STR_LIT:rb>') as f:<EOL><INDENT>file_contents = f.read()<EOL><DEDENT>return zip_contents == file_contents<EOL>

Return True if the file_path is current for this zip_path


def resource_stream(self, package_or_requirement, resource_name):

return get_provider(package_or_requirement).get_resource_stream(<EOL>self, resource_name<EOL>)<EOL>

Return a readable file-like object for specified resource


def find_plugins(self, plugin_env, full_env=None, installer=None,<EOL>fallback=True):

plugin_projects = list(plugin_env)<EOL>plugin_projects.sort()<EOL>error_info = {}<EOL>distributions = {}<EOL>if full_env is None:<EOL><INDENT>env = Environment(self.entries)<EOL>env += plugin_env<EOL><DEDENT>else:<EOL><INDENT>env = full_env + plugin_env<EOL><DEDENT>shadow_set = self.__class__([])<EOL>list(map(shadow_set.add, self))<EOL>for project_name in plugin_projects:<EOL><INDENT>for dist in plugin_env[project_name]:<EOL><INDENT>req = [dist.as_requirement()]<EOL>try:<EOL><INDENT>resolvees = shadow_set.resolve(req, env, installer)<EOL><DEDENT>except ResolutionError:<EOL><INDENT>v = sys.exc_info()[<NUM_LIT:1>]<EOL>error_info[dist] = v<EOL>if fallback:<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>list(map(shadow_set.add, resolvees))<EOL>distributions.update(dict.fromkeys(resolvees))<EOL>break<EOL><DEDENT><DEDENT><DEDENT>distributions = list(distributions)<EOL>distributions.sort()<EOL>return distributions, error_info<EOL>

Find all activatable distributions in `plugin_env`

        Example usage::

            distributions, errors = working_set.find_plugins(
                Environment(plugin_dirlist)
            )
            # add plugins+libs to sys.path
            map(working_set.add, distributions)
            # display errors
            print('Could not load', errors)

        The `plugin_env` should be an ``Environment`` instance that contains
        only distributions that are in the project's "plugin directory" or
        directories. The `full_env`, if supplied, should be an ``Environment``
        contains all currently-available distributions.  If `full_env` is not
        supplied, one is created automatically from the ``WorkingSet`` this
        method is called on, which will typically mean that every directory on
        ``sys.path`` will be scanned for distributions.

        `installer` is a standard installer callback as used by the
        ``resolve()`` method. The `fallback` flag indicates whether we should
        attempt to resolve older versions of a plugin if the newest version
        cannot be resolved.

        This method returns a 2-tuple: (`distributions`, `error_info`), where
        `distributions` is a list of the distributions found in `plugin_env`
        that were loadable, along with any other distributions that are needed
        to resolve their dependencies.  `error_info` is a dictionary mapping
        unloadable plugin distributions to an exception instance describing the
        error that occurred. Usually this will be a ``DistributionNotFound`` or
        ``VersionConflict`` instance.


for key in self._distmap.keys():<EOL><INDENT>if self[key]:<EOL><INDENT>yield key<EOL><DEDENT><DEDENT>

Yield the unique project names of the available distributions


if attr.startswith('<STR_LIT:_>'):<EOL><INDENT>raise AttributeError(attr)<EOL><DEDENT>return getattr(self._provider, attr)<EOL>

Delegate all unrecognized public attributes to .metadata provider


for t in _get_mro(getattr(ob, '<STR_LIT>', type(ob))):<EOL><INDENT>if t in registry:<EOL><INDENT>return registry[t]<EOL><DEDENT><DEDENT>

Return an adapter factory for `ob` from `registry`


def __init__(self, search_path=None, platform=get_supported_platform(),<EOL>python=PY_MAJOR):

self._distmap = {}<EOL>self.platform = platform<EOL>self.python = python<EOL>self.scan(search_path)<EOL>

Snapshot distributions available on a search path

        Any distributions found on `search_path` are added to the environment.
        `search_path` should be a sequence of ``sys.path`` items.  If not
        supplied, ``sys.path`` is used.

        `platform` is an optional string specifying the name of the platform
        that platform-specific distributions must be compatible with.  If
        unspecified, it defaults to the current platform.  `python` is an
        optional string naming the desired version of Python (e.g. ``'3.3'``);
        it defaults to the current version.

        You may explicitly set `platform` (and/or `python`) to ``None`` if you
        wish to map *all* distributions, not just those compatible with the
        running platform or Python version.


def find_on_path(importer, path_item, only=False):

path_item = _normalize_cached(path_item)<EOL>if os.path.isdir(path_item) and os.access(path_item, os.R_OK):<EOL><INDENT>if path_item.lower().endswith('<STR_LIT>'):<EOL><INDENT>yield Distribution.from_filename(<EOL>path_item, metadata=PathMetadata(<EOL>path_item, os.path.join(path_item,'<STR_LIT>')<EOL>)<EOL>)<EOL><DEDENT>else:<EOL><INDENT>for entry in os.listdir(path_item):<EOL><INDENT>lower = entry.lower()<EOL>if lower.endswith('<STR_LIT>') or lower.endswith('<STR_LIT>'):<EOL><INDENT>fullpath = os.path.join(path_item, entry)<EOL>if os.path.isdir(fullpath):<EOL><INDENT>metadata = PathMetadata(path_item, fullpath)<EOL><DEDENT>else:<EOL><INDENT>metadata = FileMetadata(fullpath)<EOL><DEDENT>yield Distribution.from_location(<EOL>path_item, entry, metadata, precedence=DEVELOP_DIST<EOL>)<EOL><DEDENT>elif not only and lower.endswith('<STR_LIT>'):<EOL><INDENT>dists = find_distributions(os.path.join(path_item, entry))<EOL>for dist in dists:<EOL><INDENT>yield dist<EOL><DEDENT><DEDENT>elif not only and lower.endswith('<STR_LIT>'):<EOL><INDENT>with open(os.path.join(path_item, entry)) as entry_file:<EOL><INDENT>entry_lines = entry_file.readlines()<EOL><DEDENT>for line in entry_lines:<EOL><INDENT>if not line.strip():<EOL><INDENT>continue<EOL><DEDENT>path = os.path.join(path_item, line.rstrip())<EOL>dists = find_distributions(path)<EOL>for item in dists:<EOL><INDENT>yield item<EOL><DEDENT>break<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>

Yield distributions accessible on a sys.path directory


return get_distribution(dist).get_entry_info(group, name)<EOL>

Return the EntryPoint object for `group`+`name`, or ``None``


def find_eggs_in_zip(importer, path_item, only=False):

if importer.archive.endswith('<STR_LIT>'):<EOL><INDENT>return<EOL><DEDENT>metadata = EggMetadata(importer)<EOL>if metadata.has_metadata('<STR_LIT>'):<EOL><INDENT>yield Distribution.from_filename(path_item, metadata=metadata)<EOL><DEDENT>if only:<EOL><INDENT>return<EOL><DEDENT>for subitem in metadata.resource_listdir('<STR_LIT:/>'):<EOL><INDENT>if subitem.endswith('<STR_LIT>'):<EOL><INDENT>subpath = os.path.join(path_item, subitem)<EOL>for dist in find_eggs_in_zip(zipimport.zipimporter(subpath), subpath):<EOL><INDENT>yield dist<EOL><DEDENT><DEDENT><DEDENT>

Find eggs in zip files; possibly multiple nested eggs.


def add(self, dist, entry=None, insert=True, replace=False):

if insert:<EOL><INDENT>dist.insert_on(self.entries, entry)<EOL><DEDENT>if entry is None:<EOL><INDENT>entry = dist.location<EOL><DEDENT>keys = self.entry_keys.setdefault(entry,[])<EOL>keys2 = self.entry_keys.setdefault(dist.location,[])<EOL>if not replace and dist.key in self.by_key:<EOL><INDENT>return<EOL><DEDENT>self.by_key[dist.key] = dist<EOL>if dist.key not in keys:<EOL><INDENT>keys.append(dist.key)<EOL><DEDENT>if dist.key not in keys2:<EOL><INDENT>keys2.append(dist.key)<EOL><DEDENT>self._added_new(dist)<EOL>

Add `dist` to working set, associated with `entry`

        If `entry` is unspecified, it defaults to the ``.location`` of `dist`.
        On exit from this routine, `entry` is added to the end of the working
        set's ``.entries`` (if it wasn't already present).

        `dist` is only added to the working set if it's for a project that
        doesn't already have a distribution in the set, unless `replace=True`.
        If it's added, any callbacks registered with the ``subscribe()`` method
        will be called.


names = '<STR_LIT>'<EOL>for attr in names.split():<EOL><INDENT>kw.setdefault(attr, getattr(self, attr, None))<EOL><DEDENT>kw.setdefault('<STR_LIT>', self._provider)<EOL>return self.__class__(**kw)<EOL>

Copy this distribution, substituting in any changed keyword args


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

Normalize a file/dir name for comparison purposes


return name.replace('<STR_LIT:->','<STR_LIT:_>')<EOL>

Convert a project or version name to its filename-escaped form

    Any '-' characters are currently replaced with '_'.


old_exc = sys.exc_info()[<NUM_LIT:1>]<EOL>cache_path = self.extraction_path or get_default_cache()<EOL>err = ExtractionError(

Give an error message for problems extracting file(s)


_namespace_handlers[importer_type] = namespace_handler<EOL>

Register `namespace_handler` to declare namespace packages

    `importer_type` is the type or class of a PEP 302 "Importer" (sys.path item
    handler), and `namespace_handler` is a callable like this::

        def namespace_handler(importer, path_entry, moduleName, module):
            # return a path_entry to use for child packages

    Namespace handlers are only called if the importer object has already
    agreed that it can handle the relevant path item, and they should only
    return a subpath if the module __path__ does not already contain an
    equivalent subpath.  For an example namespace handler, see
    ``pkg_resources.file_ns_handler``.


Does the package's distribution contain the named metadata?


Execute the named script in the supplied namespace dictionary


subs = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>exc.filename = None<EOL>exc.lineno = None<EOL>exc.msg = subs.get(exc.msg, exc.msg)<EOL>return exc<EOL>

Given a SyntaxError from a marker evaluation, normalize the error
message:
 - Remove indications of filename and line number.
 - Replace platform-specific error messages with standard error
   messages.


def load_entry_point(dist, group, name):

return get_distribution(dist).load_entry_point(group, name)<EOL>

Return `name` entry point of `group` for `dist` or raise ImportError


self._distmap[dist.key].remove(dist)<EOL>


def resource_string(self, package_or_requirement, resource_name):

return get_provider(package_or_requirement).get_resource_string(<EOL>self, resource_name<EOL>)<EOL>


def load_entry_point(self, group, name):

ep = self.get_entry_info(group, name)<EOL>if ep is None:<EOL><INDENT>raise ImportError("<STR_LIT>" % ((group, name),))<EOL><DEDENT>return ep.load()<EOL>

Return the `name` entry point of `group` or raise ImportError


_distribution_finders[importer_type] = distribution_finder<EOL>

Register `distribution_finder` to find distributions in sys.path items

    `importer_type` is the type or class of a PEP 302 "Importer" (sys.path item
    handler), and `distribution_finder` is a callable that, passed a path
    item and the importer instance, yields ``Distribution`` instances found on
    that path item.  See ``pkg_resources.find_on_path`` for an example.


dirname = os.path.dirname(path)<EOL>if not os.path.isdir(dirname):<EOL><INDENT>os.makedirs(dirname)<EOL><DEDENT>

Ensure that the parent directory of `path` exists


Yield named metadata resource as list of non-blank non-comment lines

       Leading and trailing whitespace is stripped from each line, and lines
       with ``#`` as the first non-blank character are omitted.


Return a readable file-like object for `resource_name`

        `manager` must be an ``IResourceManager``


List of metadata names in the directory (like ``os.listdir()``)


def create_cookie(name, value, **kwargs):

result = dict(<EOL>version=<NUM_LIT:0>,<EOL>name=name,<EOL>value=value,<EOL>port=None,<EOL>domain='<STR_LIT>',<EOL>path='<STR_LIT:/>',<EOL>secure=False,<EOL>expires=None,<EOL>discard=True,<EOL>comment=None,<EOL>comment_url=None,<EOL>rest={'<STR_LIT>': None},<EOL>rfc2109=False,)<EOL>badargs = set(kwargs) - set(result)<EOL>if badargs:<EOL><INDENT>err = '<STR_LIT>'<EOL>raise TypeError(err % list(badargs))<EOL><DEDENT>result.update(kwargs)<EOL>result['<STR_LIT>'] = bool(result['<STR_LIT:port>'])<EOL>result['<STR_LIT>'] = bool(result['<STR_LIT>'])<EOL>result['<STR_LIT>'] = result['<STR_LIT>'].startswith('<STR_LIT:.>')<EOL>result['<STR_LIT>'] = bool(result['<STR_LIT:path>'])<EOL>return cookielib.Cookie(**result)<EOL>

Make a cookie from underspecified parameters.

    By default, the pair of `name` and `value` will be set for the domain ''
    and sent on every request (this is sometimes called a "supercookie").


<EOL>if value is None:<EOL><INDENT>remove_cookie_by_name(self, name, domain=kwargs.get('<STR_LIT>'), path=kwargs.get('<STR_LIT:path>'))<EOL>return<EOL><DEDENT>if isinstance(value, Morsel):<EOL><INDENT>c = morsel_to_cookie(value)<EOL><DEDENT>else:<EOL><INDENT>c = create_cookie(name, value, **kwargs)<EOL><DEDENT>self.set_cookie(c)<EOL>return c<EOL>

Dict-like set() that also supports optional domain and path args in
        order to resolve naming collisions from using one cookie jar over
        multiple domains.


return list(self.iterkeys())<EOL>

Dict-like keys() that returns a list of names of cookies from the jar.
        See values() and items().


new_cj = RequestsCookieJar()<EOL>new_cj.update(self)<EOL>return new_cj<EOL>

Return a copy of this RequestsCookieJar.


def extract_cookies_to_jar(jar, request, response):

if not (hasattr(response, '<STR_LIT>') and<EOL>response._original_response):<EOL><INDENT>return<EOL><DEDENT>req = MockRequest(request)<EOL>res = MockResponse(response._original_response.msg)<EOL>jar.extract_cookies(res, req)<EOL>

Extract the cookies from the response into a CookieJar.

    :param jar: cookielib.CookieJar (not necessarily a RequestsCookieJar)
    :param request: our own requests.Request object
    :param response: urllib3.HTTPResponse object


def get(self, name, default=None, domain=None, path=None):

try:<EOL><INDENT>return self._find_no_duplicates(name, domain, path)<EOL><DEDENT>except KeyError:<EOL><INDENT>return default<EOL><DEDENT>

Dict-like get() that also supports optional domain and path args in
        order to resolve naming collisions from using one cookie jar over
        multiple domains. Caution: operation is O(n), not O(1).


def _find(self, name, domain=None, path=None):

for cookie in iter(self):<EOL><INDENT>if cookie.name == name:<EOL><INDENT>if domain is None or cookie.domain == domain:<EOL><INDENT>if path is None or cookie.path == path:<EOL><INDENT>return cookie.value<EOL><DEDENT><DEDENT><DEDENT><DEDENT>raise KeyError('<STR_LIT>' % (name, domain, path))<EOL>

Requests uses this method internally to get cookie values. Takes as args name
        and optional domain and path. Returns a cookie.value. If there are conflicting cookies,
        _find arbitrarily chooses one. See _find_no_duplicates if you want an exception thrown
        if there are conflicting cookies.


for cookie in iter(self):<EOL><INDENT>yield cookie.name, cookie.value<EOL><DEDENT>

Dict-like iteritems() that returns an iterator of name-value tuples from the jar.
        See iterkeys() and itervalues().


remove_cookie_by_name(self, name)<EOL>

Deletes a cookie given a name. Wraps cookielib.CookieJar's remove_cookie_by_name().


if url.startswith('<STR_LIT:/>'):<EOL><INDENT>return True<EOL><DEDENT>scheme, host, port = get_host(url)<EOL>if self.port and not port:<EOL><INDENT>port = port_by_scheme.get(scheme)<EOL><DEDENT>elif not self.port and port == port_by_scheme.get(scheme):<EOL><INDENT>port = None<EOL><DEDENT>return (scheme, host, port) == (self.scheme, self.host, self.port)<EOL>

Check if the given ``url`` is a member of the same host as this
connection pool.


pass<EOL>

Called right before a request is made, after the socket is created.


super(HTTPSConnectionPool, self)._validate_conn(conn)<EOL>if not getattr(conn, '<STR_LIT>', None):  <EOL><INDENT>conn.connect()<EOL><DEDENT>if not conn.is_verified:<EOL><INDENT>warnings.warn((<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'),<EOL>InsecureRequestWarning)<EOL><DEDENT>


def urlopen(self, method, url, body=None, headers=None, retries=None,<EOL>redirect=True, assert_same_host=True, timeout=_Default,<EOL>pool_timeout=None, release_conn=None, **response_kw):

if headers is None:<EOL><INDENT>headers = self.headers<EOL><DEDENT>if not isinstance(retries, Retry):<EOL><INDENT>retries = Retry.from_int(retries, redirect=redirect, default=self.retries)<EOL><DEDENT>if release_conn is None:<EOL><INDENT>release_conn = response_kw.get('<STR_LIT>', True)<EOL><DEDENT>if assert_same_host and not self.is_same_host(url):<EOL><INDENT>raise HostChangedError(self, url, retries)<EOL><DEDENT>conn = None<EOL>if self.scheme == '<STR_LIT:http>':<EOL><INDENT>headers = headers.copy()<EOL>headers.update(self.proxy_headers)<EOL><DEDENT>err = None<EOL>try:<EOL><INDENT>conn = self._get_conn(timeout=pool_timeout)<EOL>httplib_response = self._make_request(conn, method, url,<EOL>timeout=timeout,<EOL>body=body, headers=headers)<EOL>response_conn = not release_conn and conn<EOL>response = HTTPResponse.from_httplib(httplib_response,<EOL>pool=self,<EOL>connection=response_conn,<EOL>**response_kw)<EOL><DEDENT>except Empty:<EOL><INDENT>raise EmptyPoolError(self, "<STR_LIT>")<EOL><DEDENT>except (BaseSSLError, CertificateError) as e:<EOL><INDENT>if conn:<EOL><INDENT>conn.close()<EOL>conn = None<EOL><DEDENT>raise SSLError(e)<EOL><DEDENT>except (TimeoutError, HTTPException, SocketError, ConnectionError) as e:<EOL><INDENT>if conn:<EOL><INDENT>conn.close()<EOL>conn = None<EOL><DEDENT>stacktrace = sys.exc_info()[<NUM_LIT:2>]<EOL>if isinstance(e, SocketError) and self.proxy:<EOL><INDENT>e = ProxyError('<STR_LIT>', e)<EOL><DEDENT>elif isinstance(e, (SocketError, HTTPException)):<EOL><INDENT>e = ProtocolError('<STR_LIT>', e)<EOL><DEDENT>retries = retries.increment(method, url, error=e,<EOL>_pool=self, _stacktrace=stacktrace)<EOL>retries.sleep()<EOL>err = e<EOL><DEDENT>finally:<EOL><INDENT>if release_conn:<EOL><INDENT>self._put_conn(conn)<EOL><DEDENT><DEDENT>if not conn:<EOL><INDENT>log.warning("<STR_LIT>"<EOL>"<STR_LIT>" % (retries, err, url))<EOL>return self.urlopen(method, url, body, headers, retries,<EOL>redirect, assert_same_host,<EOL>timeout=timeout, pool_timeout=pool_timeout,<EOL>release_conn=release_conn, **response_kw)<EOL><DEDENT>redirect_location = redirect and response.get_redirect_location()<EOL>if redirect_location:<EOL><INDENT>if response.status == <NUM_LIT>:<EOL><INDENT>method = '<STR_LIT:GET>'<EOL><DEDENT>try:<EOL><INDENT>retries = retries.increment(method, url, response=response, _pool=self)<EOL><DEDENT>except MaxRetryError:<EOL><INDENT>if retries.raise_on_redirect:<EOL><INDENT>raise<EOL><DEDENT>return response<EOL><DEDENT>log.info("<STR_LIT>" % (url, redirect_location))<EOL>return self.urlopen(method, redirect_location, body, headers,<EOL>retries=retries, redirect=redirect,<EOL>assert_same_host=assert_same_host,<EOL>timeout=timeout, pool_timeout=pool_timeout,<EOL>release_conn=release_conn, **response_kw)<EOL><DEDENT>if retries.is_forced_retry(method, status_code=response.status):<EOL><INDENT>retries = retries.increment(method, url, response=response, _pool=self)<EOL>retries.sleep()<EOL>log.info("<STR_LIT>" % url)<EOL>return self.urlopen(method, url, body, headers,<EOL>retries=retries, redirect=redirect,<EOL>assert_same_host=assert_same_host,<EOL>timeout=timeout, pool_timeout=pool_timeout,<EOL>release_conn=release_conn, **response_kw)<EOL><DEDENT>return response<EOL>

Get a connection from the pool and perform an HTTP request. This is the
lowest level call for making a request, so you'll need to specify all
the raw details.

.. note::

   More commonly, it's appropriate to use a convenience method provided
   by :class:`.RequestMethods`, such as :meth:`request`.

.. note::

   `release_conn` will only behave as expected if
   `preload_content=False` because we want to make
   `preload_content=False` the default behaviour someday soon without
   breaking backwards compatibility.

:param method:
    HTTP request method (such as GET, POST, PUT, etc.)

:param body:
    Data to send in the request body (useful for creating
    POST requests, see HTTPConnectionPool.post_url for
    more convenience).

:param headers:
    Dictionary of custom headers to send, such as User-Agent,
    If-None-Match, etc. If None, pool headers are used. If provided,
    these headers completely replace any pool-specific headers.

:param retries:
    Configure the number of retries to allow before raising a
    :class:`~urllib3.exceptions.MaxRetryError` exception.

    Pass ``None`` to retry until you receive a response. Pass a
    :class:`~urllib3.util.retry.Retry` object for fine-grained control
    over different types of retries.
    Pass an integer number to retry connection errors that many times,
    but no other types of errors. Pass zero to never retry.

    If ``False``, then retries are disabled and any exception is raised
    immediately. Also, instead of raising a MaxRetryError on redirects,
    the redirect response will be returned.

:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int.

:param redirect:
    If True, automatically handle redirects (status codes 301, 302,
    303, 307, 308). Each redirect counts as a retry. Disabling retries
    will disable redirect, too.

:param assert_same_host:
    If ``True``, will make sure that the host of the pool requests is
    consistent else will raise HostChangedError. When False, you can
    use the pool on an HTTP proxy and request foreign hosts.

:param timeout:
    If specified, overrides the default timeout for this one
    request. It may be a float (in seconds) or an instance of
    :class:`urllib3.util.Timeout`.

:param pool_timeout:
    If set and the pool is set to block=True, then this method will
    block for ``pool_timeout`` seconds and raise EmptyPoolError if no
    connection is available within the time period.

:param release_conn:
    If False, then the urlopen call will not release the connection
    back into the pool once a response is received (but will release if
    you read the entire contents of the response such as when
    `preload_content=True`). This is useful if you're not preloading
    the response's content immediately. You will need to call
    ``r.release_conn()`` on the response ``r`` to return the connection
    back into the pool. If None, it takes the value of
    ``response_kw.get('preload_content', True)``.

:param \**response_kw:
    Additional parameters are passed to
    :meth:`urllib3.response.HTTPResponse.from_httplib`


self.num_connections += <NUM_LIT:1><EOL>log.info("<STR_LIT>"<EOL>% (self.num_connections, self.host))<EOL>if not self.ConnectionCls or self.ConnectionCls is DummyConnection:<EOL><INDENT>raise SSLError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>actual_host = self.host<EOL>actual_port = self.port<EOL>if self.proxy is not None:<EOL><INDENT>actual_host = self.proxy.host<EOL>actual_port = self.proxy.port<EOL><DEDENT>conn = self.ConnectionCls(host=actual_host, port=actual_port,<EOL>timeout=self.timeout.connect_timeout,<EOL>strict=self.strict, **self.conn_kw)<EOL>return self._prepare_conn(conn)<EOL>

Return a fresh :class:`httplib.HTTPSConnection`.


<EOL>hashfunc_map = {<EOL><NUM_LIT:16>: md5,<EOL><NUM_LIT:20>: sha1<EOL>}<EOL>fingerprint = fingerprint.replace('<STR_LIT::>', '<STR_LIT>').lower()<EOL>digest_length, odd = divmod(len(fingerprint), <NUM_LIT:2>)<EOL>if odd or digest_length not in hashfunc_map:<EOL><INDENT>raise SSLError('<STR_LIT>')<EOL><DEDENT>fingerprint_bytes = unhexlify(fingerprint.encode())<EOL>hashfunc = hashfunc_map[digest_length]<EOL>cert_digest = hashfunc(cert).digest()<EOL>if not cert_digest == fingerprint_bytes:<EOL><INDENT>raise SSLError('<STR_LIT>'<EOL>.format(hexlify(fingerprint_bytes),<EOL>hexlify(cert_digest)))<EOL><DEDENT>

Checks if given fingerprint matches the supplied certificate.

:param cert:
    Certificate as bytes object.
:param fingerprint:
    Fingerprint as string of hexdigits, can be interspersed by colons.


@classmethod<EOL><INDENT>def from_int(cls, retries, redirect=True, default=None):<DEDENT>

if retries is None:<EOL><INDENT>retries = default if default is not None else cls.DEFAULT<EOL><DEDENT>if isinstance(retries, Retry):<EOL><INDENT>return retries<EOL><DEDENT>redirect = bool(redirect) and None<EOL>new_retries = cls(retries, redirect=redirect)<EOL>log.debug("<STR_LIT>" % (retries, new_retries))<EOL>return new_retries<EOL>

Backwards-compatibility for the old retries format.


return isinstance(err, (ReadTimeoutError, ProtocolError))<EOL>

Errors that occur after the request has been started, so we should
        assume that the server began processing it.


return isinstance(err, ConnectTimeoutError)<EOL>

Errors when we're fairly sure that the server did not receive the
        request, so it should be safe to retry.


u = parse_url(url)<EOL>return self.connection_from_host(u.host, port=u.port, scheme=u.scheme)<EOL>

Similar to :func:`urllib3.connectionpool.connection_from_url` but
doesn't pass any additional parameters to the
:class:`urllib3.connectionpool.ConnectionPool` constructor.

Additional parameters are taken from the :class:`.PoolManager`
constructor.


def connection_from_host(self, host, port=None, scheme='<STR_LIT:http>'):

if not host:<EOL><INDENT>raise LocationValueError("<STR_LIT>")<EOL><DEDENT>scheme = scheme or '<STR_LIT:http>'<EOL>port = port or port_by_scheme.get(scheme, <NUM_LIT>)<EOL>pool_key = (scheme, host, port)<EOL>with self.pools.lock:<EOL><INDENT>pool = self.pools.get(pool_key)<EOL>if pool:<EOL><INDENT>return pool<EOL><DEDENT>pool = self._new_pool(scheme, host, port)<EOL>self.pools[pool_key] = pool<EOL><DEDENT>return pool<EOL>

Get a :class:`ConnectionPool` based on the host, port, and scheme.

If ``port`` isn't given, it will be derived from the ``scheme`` using
``urllib3.connectionpool.port_by_scheme``.


warnings.simplefilter('<STR_LIT:ignore>', category)<EOL>

Helper for quickly disabling all urllib3 warnings.


self._data.setdefault(key.lower(), []).append((key, value))<EOL>

Adds a (name, value) pair, doesn't overwrite the value if it already
        exists.

        >>> headers = HTTPHeaderDict(foo='bar')
        >>> headers.add('Foo', 'baz')
        >>> headers['foo']
        'bar, baz'


def read(self, amt=None, decode_content=None, cache_content=False):

<EOL>content_encoding = self.headers.get('<STR_LIT>', '<STR_LIT>').lower()<EOL>if self._decoder is None:<EOL><INDENT>if content_encoding in self.CONTENT_DECODERS:<EOL><INDENT>self._decoder = _get_decoder(content_encoding)<EOL><DEDENT><DEDENT>if decode_content is None:<EOL><INDENT>decode_content = self.decode_content<EOL><DEDENT>if self._fp is None:<EOL><INDENT>return<EOL><DEDENT>flush_decoder = False<EOL>try:<EOL><INDENT>try:<EOL><INDENT>if amt is None:<EOL><INDENT>data = self._fp.read()<EOL>flush_decoder = True<EOL><DEDENT>else:<EOL><INDENT>cache_content = False<EOL>data = self._fp.read(amt)<EOL>if amt != <NUM_LIT:0> and not data:  <EOL><INDENT>self._fp.close()<EOL>flush_decoder = True<EOL><DEDENT><DEDENT><DEDENT>except SocketTimeout:<EOL><INDENT>raise ReadTimeoutError(self._pool, None, '<STR_LIT>')<EOL><DEDENT>except BaseSSLError as e:<EOL><INDENT>if not '<STR_LIT>' in str(e):  <EOL><INDENT>raise<EOL><DEDENT>raise ReadTimeoutError(self._pool, None, '<STR_LIT>')<EOL><DEDENT>except HTTPException as e:<EOL><INDENT>raise ProtocolError('<STR_LIT>' % e, e)<EOL><DEDENT>self._fp_bytes_read += len(data)<EOL>try:<EOL><INDENT>if decode_content and self._decoder:<EOL><INDENT>data = self._decoder.decompress(data)<EOL><DEDENT><DEDENT>except (IOError, zlib.error) as e:<EOL><INDENT>raise DecodeError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % content_encoding, e)<EOL><DEDENT>if flush_decoder and decode_content and self._decoder:<EOL><INDENT>buf = self._decoder.decompress(binary_type())<EOL>data += buf + self._decoder.flush()<EOL><DEDENT>if cache_content:<EOL><INDENT>self._body = data<EOL><DEDENT>return data<EOL><DEDENT>finally:<EOL><INDENT>if self._original_response and self._original_response.isclosed():<EOL><INDENT>self.release_conn()<EOL><DEDENT><DEDENT>

Similar to :meth:`httplib.HTTPResponse.read`, but with two additional
parameters: ``decode_content`` and ``cache_content``.

:param amt:
    How much of the content to read. If specified, caching is skipped
    because it doesn't make sense to cache partial content as the full
    response.

:param decode_content:
    If True, will attempt to decode the body based on the
    'content-encoding' header.

:param cache_content:
    If True, will save the returned data such that the same result is
    returned despite of the state of the underlying file object. This
    is useful if you want the ``.data`` property to continue working
    after having ``.read()`` the file object. (Overridden if ``amt`` is
    set.)


if self.pos is not None:<EOL><INDENT>r.request.body.seek(self.pos)<EOL><DEDENT>num_401_calls = getattr(self, '<STR_LIT>', <NUM_LIT:1>)<EOL>s_auth = r.headers.get('<STR_LIT>', '<STR_LIT>')<EOL>if '<STR_LIT>' in s_auth.lower() and num_401_calls < <NUM_LIT:2>:<EOL><INDENT>self.num_401_calls += <NUM_LIT:1><EOL>pat = re.compile(r'<STR_LIT>', flags=re.IGNORECASE)<EOL>self.chal = parse_dict_header(pat.sub('<STR_LIT>', s_auth, count=<NUM_LIT:1>))<EOL>r.content<EOL>r.raw.release_conn()<EOL>prep = r.request.copy()<EOL>extract_cookies_to_jar(prep._cookies, r.request, r.raw)<EOL>prep.prepare_cookies(prep._cookies)<EOL>prep.headers['<STR_LIT>'] = self.build_digest_header(<EOL>prep.method, prep.url)<EOL>_r = r.connection.send(prep, **kwargs)<EOL>_r.history.append(r)<EOL>_r.request = prep<EOL>return _r<EOL><DEDENT>self.num_401_calls = <NUM_LIT:1><EOL>return r<EOL>

Takes the given response and tries digest-auth, if needed.


def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None):

conn = self.get_connection(request.url, proxies)<EOL>self.cert_verify(conn, request.url, verify, cert)<EOL>url = self.request_url(request, proxies)<EOL>self.add_headers(request)<EOL>chunked = not (request.body is None or '<STR_LIT>' in request.headers)<EOL>if isinstance(timeout, tuple):<EOL><INDENT>try:<EOL><INDENT>connect, read = timeout<EOL>timeout = TimeoutSauce(connect=connect, read=read)<EOL><DEDENT>except ValueError as e:<EOL><INDENT>err = ("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(timeout))<EOL>raise ValueError(err)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>timeout = TimeoutSauce(connect=timeout, read=timeout)<EOL><DEDENT>try:<EOL><INDENT>if not chunked:<EOL><INDENT>resp = conn.urlopen(<EOL>method=request.method,<EOL>url=url,<EOL>body=request.body,<EOL>headers=request.headers,<EOL>redirect=False,<EOL>assert_same_host=False,<EOL>preload_content=False,<EOL>decode_content=False,<EOL>retries=self.max_retries,<EOL>timeout=timeout<EOL>)<EOL><DEDENT>else:<EOL><INDENT>if hasattr(conn, '<STR_LIT>'):<EOL><INDENT>conn = conn.proxy_pool<EOL><DEDENT>low_conn = conn._get_conn(timeout=timeout)<EOL>try:<EOL><INDENT>low_conn.putrequest(request.method,<EOL>url,<EOL>skip_accept_encoding=True)<EOL>for header, value in request.headers.items():<EOL><INDENT>low_conn.putheader(header, value)<EOL><DEDENT>low_conn.endheaders()<EOL>for i in request.body:<EOL><INDENT>low_conn.send(hex(len(i))[<NUM_LIT:2>:].encode('<STR_LIT:utf-8>'))<EOL>low_conn.send(b'<STR_LIT:\r\n>')<EOL>low_conn.send(i)<EOL>low_conn.send(b'<STR_LIT:\r\n>')<EOL><DEDENT>low_conn.send(b'<STR_LIT>')<EOL>r = low_conn.getresponse()<EOL>resp = HTTPResponse.from_httplib(<EOL>r,<EOL>pool=conn,<EOL>connection=low_conn,<EOL>preload_content=False,<EOL>decode_content=False<EOL>)<EOL><DEDENT>except:<EOL><INDENT>low_conn.close()<EOL>raise<EOL><DEDENT>else:<EOL><INDENT>conn._put_conn(low_conn)<EOL><DEDENT><DEDENT><DEDENT>except (ProtocolError, socket.error) as err:<EOL><INDENT>raise ConnectionError(err, request=request)<EOL><DEDENT>except MaxRetryError as e:<EOL><INDENT>if isinstance(e.reason, ConnectTimeoutError):<EOL><INDENT>raise ConnectTimeout(e, request=request)<EOL><DEDENT>if isinstance(e.reason, ResponseError):<EOL><INDENT>raise RetryError(e, request=request)<EOL><DEDENT>raise ConnectionError(e, request=request)<EOL><DEDENT>except _ProxyError as e:<EOL><INDENT>raise ProxyError(e)<EOL><DEDENT>except (_SSLError, _HTTPError) as e:<EOL><INDENT>if isinstance(e, _SSLError):<EOL><INDENT>raise SSLError(e, request=request)<EOL><DEDENT>elif isinstance(e, ReadTimeoutError):<EOL><INDENT>raise ReadTimeout(e, request=request)<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>return self.build_response(request, resp)<EOL>

Sends PreparedRequest object. Returns Response object.

        :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
        :param stream: (optional) Whether to stream the request content.
        :param timeout: (optional) How long to wait for the server to send
            data before giving up, as a float, or a (`connect timeout, read
            timeout <user/advanced.html#timeouts>`_) tuple.
        :type timeout: float or tuple
        :param verify: (optional) Whether to verify SSL certificates.
        :param cert: (optional) Any user-provided SSL certificate to be trusted.
        :param proxies: (optional) The proxies dictionary to apply to the request.


def cert_verify(self, conn, url, verify, cert):

if url.lower().startswith('<STR_LIT>') and verify:<EOL><INDENT>cert_loc = None<EOL>if verify is not True:<EOL><INDENT>cert_loc = verify<EOL><DEDENT>if not cert_loc:<EOL><INDENT>cert_loc = DEFAULT_CA_BUNDLE_PATH<EOL><DEDENT>if not cert_loc:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>conn.cert_reqs = '<STR_LIT>'<EOL>conn.ca_certs = cert_loc<EOL><DEDENT>else:<EOL><INDENT>conn.cert_reqs = '<STR_LIT>'<EOL>conn.ca_certs = None<EOL><DEDENT>if cert:<EOL><INDENT>if not isinstance(cert, basestring):<EOL><INDENT>conn.cert_file = cert[<NUM_LIT:0>]<EOL>conn.key_file = cert[<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>conn.cert_file = cert<EOL><DEDENT><DEDENT>

Verify a SSL certificate. This method should not be called from user
        code, and is only exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        :param conn: The urllib3 connection object associated with the cert.
        :param url: The requested URL.
        :param verify: Whether we should actually verify the certificate.
        :param cert: The SSL certificate to verify.