def run_docstring_examples(f, globs, verbose=False, name="<STR_LIT>",<EOL>compileflags=None, optionflags=<NUM_LIT:0>):

<EOL>finder = DocTestFinder(verbose=verbose, recurse=False)<EOL>runner = DocTestRunner(verbose=verbose, optionflags=optionflags)<EOL>for test in finder.find(f, name, globs=globs):<EOL><INDENT>runner.run(test, compileflags=compileflags)<EOL><DEDENT>

Test examples in the given object's docstring (`f`), using `globs`
as globals.  Optional argument `name` is used in failure messages.
If the optional argument `verbose` is true, then generate output
even if there are no failures.

`compileflags` gives the set of flags that should be used by the
Python compiler when running the examples.  If not specified, then
it will default to the set of future-import flags that apply to
`globs`.

Optional keyword arg `optionflags` specifies options for the
testing and output.  See the documentation for `testmod` for more
information.


suite = unittest.TestSuite()<EOL>if kw.get('<STR_LIT>', True):<EOL><INDENT>kw['<STR_LIT>'] = _normalize_module(kw.get('<STR_LIT>'))<EOL><DEDENT>for path in paths:<EOL><INDENT>suite.addTest(DocFileTest(path, **kw))<EOL><DEDENT>return suite<EOL>

A unittest suite for one or more doctest files.

    The path to each doctest file is given as a string; the
    interpretation of that string depends on the keyword argument
    "module_relative".

    A number of options may be provided as keyword arguments:

    module_relative
      If "module_relative" is True, then the given file paths are
      interpreted as os-independent module-relative paths.  By
      default, these paths are relative to the calling module's
      directory; but if the "package" argument is specified, then
      they are relative to that package.  To ensure os-independence,
      "filename" should use "/" characters to separate path
      segments, and may not be an absolute path (i.e., it may not
      begin with "/").

      If "module_relative" is False, then the given file paths are
      interpreted as os-specific paths.  These paths may be absolute
      or relative (to the current working directory).

    package
      A Python package or the name of a Python package whose directory
      should be used as the base directory for module relative paths.
      If "package" is not specified, then the calling module's
      directory is used as the base directory for module relative
      filenames.  It is an error to specify "package" if
      "module_relative" is False.

    setUp
      A set-up function.  This is called before running the
      tests in each file. The setUp function will be passed a DocTest
      object.  The setUp function can access the test globals as the
      globs attribute of the test passed.

    tearDown
      A tear-down function.  This is called after running the
      tests in each file.  The tearDown function will be passed a DocTest
      object.  The tearDown function can access the test globals as the
      globs attribute of the test passed.

    globs
      A dictionary containing initial global variables for the tests.

    optionflags
      A set of doctest option flags expressed as an integer.

    parser
      A DocTestParser (or subclass) that should be used to extract
      tests from the files.


output = []<EOL>for piece in DocTestParser().parse(s):<EOL><INDENT>if isinstance(piece, Example):<EOL><INDENT>output.append(piece.source[:-<NUM_LIT:1>])<EOL>want = piece.want<EOL>if want:<EOL><INDENT>output.append('<STR_LIT>')<EOL>output += ['<STR_LIT>'+l for l in want.split('<STR_LIT:\n>')[:-<NUM_LIT:1>]]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>output += [_comment_line(l)<EOL>for l in piece.split('<STR_LIT:\n>')[:-<NUM_LIT:1>]]<EOL><DEDENT><DEDENT>while output and output[-<NUM_LIT:1>] == '<STR_LIT:#>':<EOL><INDENT>output.pop()<EOL><DEDENT>while output and output[<NUM_LIT:0>] == '<STR_LIT:#>':<EOL><INDENT>output.pop(<NUM_LIT:0>)<EOL><DEDENT>return '<STR_LIT:\n>'.join(output)<EOL>

r"""Extract script from text with examples.

       Converts text with examples to a Python script.  Example input is
       converted to regular code.  Example output and all other words
       are converted to comments:

       >>> text = '''
       ...       Here are examples of simple math.
       ...
       ...           Python has super accurate integer addition
       ...
       ...           >>> 2 + 2
       ...           5
       ...
       ...           And very friendly error messages:
       ...
       ...           >>> 1/0
       ...           To Infinity
       ...           And
       ...           Beyond
       ...
       ...           You can use logic if you want:
       ...
       ...           >>> if 0:
       ...           ...    blah
       ...           ...    blah
       ...           ...
       ...
       ...           Ho hum
       ...           '''

       >>> print script_from_examples(text)
       # Here are examples of simple math.
       #
       #     Python has super accurate integer addition
       #
       2 + 2
       # Expected:
       ## 5
       #
       #     And very friendly error messages:
       #
       1/0
       # Expected:
       ## To Infinity
       ## And
       ## Beyond
       #
       #     You can use logic if you want:
       #
       if 0:
          blah
          blah
       #
       #     Ho hum


def debug_src(src, pm=False, globs=None):

testsrc = script_from_examples(src)<EOL>debug_script(testsrc, pm, globs)<EOL>

Debug a single doctest docstring, in argument `src`


def debug_script(src, pm=False, globs=None):

import pdb<EOL>srcfilename = tempfile.mktemp("<STR_LIT>", "<STR_LIT>")<EOL>f = open(srcfilename, '<STR_LIT:w>')<EOL>f.write(src)<EOL>f.close()<EOL>try:<EOL><INDENT>if globs:<EOL><INDENT>globs = globs.copy()<EOL><DEDENT>else:<EOL><INDENT>globs = {}<EOL><DEDENT>if pm:<EOL><INDENT>try:<EOL><INDENT>exec(compile(open(srcfilename, "<STR_LIT:rb>").read(), srcfilename, '<STR_LIT>'), globs, globs)<EOL><DEDENT>except:<EOL><INDENT>print(sys.exc_info()[<NUM_LIT:1>])<EOL>pdb.post_mortem(sys.exc_info()[<NUM_LIT:2>])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>pdb.run("<STR_LIT>" % srcfilename, globs, globs)<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>os.remove(srcfilename)<EOL><DEDENT>

Debug a test script.  `src` is the script, as a string.


module = _normalize_module(module)<EOL>testsrc = testsource(module, name)<EOL>debug_script(testsrc, pm, module.__dict__)<EOL>

Debug a single doctest docstring.

    Provide the module (or dotted name of the module) containing the
    test to be debugged and the name (within the module) of the object
    with the docstring with tests to be debugged.


def __init__(self, examples, globs, name, filename, lineno, docstring):

assert not isinstance(examples, str),"<STR_LIT>"<EOL>self.examples = examples<EOL>self.docstring = docstring<EOL>self.globs = globs.copy()<EOL>self.name = name<EOL>self.filename = filename<EOL>self.lineno = lineno<EOL>

Create a new DocTest containing the given examples.  The
DocTest's globals are initialized with a copy of `globs`.


def parse(self, string, name='<STR_LIT>'):

string = string.expandtabs()<EOL>min_indent = self._min_indent(string)<EOL>if min_indent > <NUM_LIT:0>:<EOL><INDENT>string = '<STR_LIT:\n>'.join([l[min_indent:] for l in string.split('<STR_LIT:\n>')])<EOL><DEDENT>output = []<EOL>charno, lineno = <NUM_LIT:0>, <NUM_LIT:0><EOL>for m in self._EXAMPLE_RE.finditer(string):<EOL><INDENT>output.append(string[charno:m.start()])<EOL>lineno += string.count('<STR_LIT:\n>', charno, m.start())<EOL>(source, options, want, exc_msg) =self._parse_example(m, name, lineno)<EOL>if not self._IS_BLANK_OR_COMMENT(source):<EOL><INDENT>output.append( Example(source, want, exc_msg,<EOL>lineno=lineno,<EOL>indent=min_indent+len(m.group('<STR_LIT>')),<EOL>options=options) )<EOL><DEDENT>lineno += string.count('<STR_LIT:\n>', m.start(), m.end())<EOL>charno = m.end()<EOL><DEDENT>output.append(string[charno:])<EOL>return output<EOL>

Divide the given string into examples and intervening text,
and return them as a list of alternating Examples and strings.
Line numbers for the Examples are 0-based.  The optional
argument `name` is a name identifying this string, and is only
used for error messages.


def get_examples(self, string, name='<STR_LIT>'):

return [x for x in self.parse(string, name)<EOL>if isinstance(x, Example)]<EOL>

Extract all doctest examples from the given string, and return
them as a list of `Example` objects.  Line numbers are
0-based, because it's most common in doctests that nothing
interesting appears on the same line as opening triple-quote,
and so the first interesting line is called \"line 1\" then.

The optional argument `name` is a name identifying this
string, and is only used for error messages.


def _parse_example(self, m, name, lineno):

<EOL>indent = len(m.group('<STR_LIT>'))<EOL>source_lines = m.group('<STR_LIT:source>').split('<STR_LIT:\n>')<EOL>self._check_prompt_blank(source_lines, indent, name, lineno)<EOL>self._check_prefix(source_lines[<NUM_LIT:1>:], '<STR_LIT:U+0020>'*indent + '<STR_LIT:.>', name, lineno)<EOL>source = '<STR_LIT:\n>'.join([sl[indent+<NUM_LIT:4>:] for sl in source_lines])<EOL>want = m.group('<STR_LIT>')<EOL>want_lines = want.split('<STR_LIT:\n>')<EOL>if len(want_lines) > <NUM_LIT:1> and re.match(r'<STR_LIT>', want_lines[-<NUM_LIT:1>]):<EOL><INDENT>del want_lines[-<NUM_LIT:1>]  <EOL><DEDENT>self._check_prefix(want_lines, '<STR_LIT:U+0020>'*indent, name,<EOL>lineno + len(source_lines))<EOL>want = '<STR_LIT:\n>'.join([wl[indent:] for wl in want_lines])<EOL>m = self._EXCEPTION_RE.match(want)<EOL>if m:<EOL><INDENT>exc_msg = m.group('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>exc_msg = None<EOL><DEDENT>options = self._find_options(source, name, lineno)<EOL>return source, options, want, exc_msg<EOL>

Given a regular expression match from `_EXAMPLE_RE` (`m`),
return a pair `(source, want)`, where `source` is the matched
example's source code (with prompts and indentation stripped);
and `want` is the example's expected output (with indentation
stripped).

`name` is the string's name, and `lineno` is the line number
where the example starts; both are used for error messages.


def _find_options(self, source, name, lineno):

options = {}<EOL>for m in self._OPTION_DIRECTIVE_RE.finditer(source):<EOL><INDENT>option_strings = m.group(<NUM_LIT:1>).replace('<STR_LIT:U+002C>', '<STR_LIT:U+0020>').split()<EOL>for option in option_strings:<EOL><INDENT>if (option[<NUM_LIT:0>] not in '<STR_LIT>' or<EOL>option[<NUM_LIT:1>:] not in OPTIONFLAGS_BY_NAME):<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(lineno+<NUM_LIT:1>, name, option))<EOL><DEDENT>flag = OPTIONFLAGS_BY_NAME[option[<NUM_LIT:1>:]]<EOL>options[flag] = (option[<NUM_LIT:0>] == '<STR_LIT:+>')<EOL><DEDENT><DEDENT>if options and self._IS_BLANK_OR_COMMENT(source):<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(lineno, name, source))<EOL><DEDENT>return options<EOL>

Return a dictionary containing option overrides extracted from
option directives in the given source string.

`name` is the string's name, and `lineno` is the line number
where the example starts; both are used for error messages.


indents = [len(indent) for indent in self._INDENT_RE.findall(s)]<EOL>if len(indents) > <NUM_LIT:0>:<EOL><INDENT>return min(indents)<EOL><DEDENT>else:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>

Return the minimum indentation of any non-blank line in `s`


def _check_prompt_blank(self, lines, indent, name, lineno):

for i, line in enumerate(lines):<EOL><INDENT>if len(line) >= indent+<NUM_LIT:4> and line[indent+<NUM_LIT:3>] != '<STR_LIT:U+0020>':<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(lineno+i+<NUM_LIT:1>, name,<EOL>line[indent:indent+<NUM_LIT:3>], line))<EOL><DEDENT><DEDENT>

Given the lines of a source string (including prompts and
leading indentation), check to make sure that every prompt is
followed by a space character.  If any line is not followed by
a space character, then raise ValueError.


def _check_prefix(self, lines, prefix, name, lineno):

for i, line in enumerate(lines):<EOL><INDENT>if line and not line.startswith(prefix):<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(lineno+i+<NUM_LIT:1>, name, line))<EOL><DEDENT><DEDENT>

Check that every line in the given list starts with the given
prefix; if any line does not, then raise a ValueError.


def __init__(self, verbose=False, parser=DocTestParser(),<EOL>recurse=True, _namefilter=None, exclude_empty=True):

self._parser = parser<EOL>self._verbose = verbose<EOL>self._recurse = recurse<EOL>self._exclude_empty = exclude_empty<EOL>self._namefilter = _namefilter<EOL>

Create a new doctest finder.

The optional argument `parser` specifies a class or
function that should be used to create new DocTest objects (or
objects that implement the same interface as DocTest).  The
signature for this factory function should match the signature
of the DocTest constructor.

If the optional argument `recurse` is false, then `find` will
only examine the given object, and not any contained objects.

If the optional argument `exclude_empty` is false, then `find`
will include tests for objects with empty docstrings.


def find(self, obj, name=None, module=None, globs=None,<EOL>extraglobs=None):

<EOL>if name is None:<EOL><INDENT>name = getattr(obj, '<STR_LIT>', None)<EOL>if name is None:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" %<EOL>(type(obj),))<EOL><DEDENT><DEDENT>if module is False:<EOL><INDENT>module = None<EOL><DEDENT>elif module is None:<EOL><INDENT>module = inspect.getmodule(obj)<EOL><DEDENT>try:<EOL><INDENT>file = inspect.getsourcefile(obj) or inspect.getfile(obj)<EOL>source_lines = linecache.getlines(file)<EOL>if not source_lines:<EOL><INDENT>source_lines = None<EOL><DEDENT><DEDENT>except TypeError:<EOL><INDENT>source_lines = None<EOL><DEDENT>if globs is None:<EOL><INDENT>if module is None:<EOL><INDENT>globs = {}<EOL><DEDENT>else:<EOL><INDENT>globs = module.__dict__.copy()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>globs = globs.copy()<EOL><DEDENT>if extraglobs is not None:<EOL><INDENT>globs.update(extraglobs)<EOL><DEDENT>tests = []<EOL>self._find(tests, obj, name, module, source_lines, globs, {})<EOL>return tests<EOL>

Return a list of the DocTests that are defined by the given
object's docstring, or by any of its contained objects'
docstrings.

The optional parameter `module` is the module that contains
the given object.  If the module is not specified or is None, then
the test finder will attempt to automatically determine the
correct module.  The object's module is used:

    - As a default namespace, if `globs` is not specified.
    - To prevent the DocTestFinder from extracting DocTests
      from objects that are imported from other modules.
    - To find the name of the file containing the object.
    - To help find the line number of the object within its
      file.

Contained objects whose module does not match `module` are ignored.

If `module` is False, no attempt to find the module will be made.
This is obscure, of use mostly in tests:  if `module` is False, or
is None but cannot be found automatically, then all objects are
considered to belong to the (non-existent) module, so all contained
objects will (recursively) be searched for doctests.

The globals for each DocTest is formed by combining `globs`
and `extraglobs` (bindings in `extraglobs` override bindings
in `globs`).  A new copy of the globals dictionary is created
for each DocTest.  If `globs` is not specified, then it
defaults to the module's `__dict__`, if specified, or {}
otherwise.  If `extraglobs` is not specified, then it defaults
to {}.


return (self._namefilter is not None and<EOL>self._namefilter(prefix, base))<EOL>

Return true if the given object should not be examined.


if module is None:<EOL><INDENT>return True<EOL><DEDENT>elif inspect.isfunction(object):<EOL><INDENT>return module.__dict__ is object.__globals__<EOL><DEDENT>elif inspect.isclass(object):<EOL><INDENT>return module.__name__ == object.__module__<EOL><DEDENT>elif inspect.getmodule(object) is not None:<EOL><INDENT>return module is inspect.getmodule(object)<EOL><DEDENT>elif hasattr(object, '<STR_LIT>'):<EOL><INDENT>return module.__name__ == object.__module__<EOL><DEDENT>elif isinstance(object, property):<EOL><INDENT>return True <EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>

Return true if the given object is defined in the given
module.


def _find_lineno(self, obj, source_lines):

lineno = None<EOL>if inspect.ismodule(obj):<EOL><INDENT>lineno = <NUM_LIT:0><EOL><DEDENT>if inspect.isclass(obj):<EOL><INDENT>if source_lines is None:<EOL><INDENT>return None<EOL><DEDENT>pat = re.compile(r'<STR_LIT>' %<EOL>getattr(obj, '<STR_LIT>', '<STR_LIT:->'))<EOL>for i, line in enumerate(source_lines):<EOL><INDENT>if pat.match(line):<EOL><INDENT>lineno = i<EOL>break<EOL><DEDENT><DEDENT><DEDENT>if inspect.ismethod(obj): obj = obj.__func__<EOL>if inspect.isfunction(obj): obj = obj.__code__<EOL>if inspect.istraceback(obj): obj = obj.tb_frame<EOL>if inspect.isframe(obj): obj = obj.f_code<EOL>if inspect.iscode(obj):<EOL><INDENT>lineno = getattr(obj, '<STR_LIT>', None)-<NUM_LIT:1><EOL><DEDENT>if lineno is not None:<EOL><INDENT>if source_lines is None:<EOL><INDENT>return lineno+<NUM_LIT:1><EOL><DEDENT>pat = re.compile('<STR_LIT>')<EOL>for lineno in range(lineno, len(source_lines)):<EOL><INDENT>if pat.match(source_lines[lineno]):<EOL><INDENT>return lineno<EOL><DEDENT><DEDENT><DEDENT>return None<EOL>

Return a line number of the given object's docstring.  Note:
this method assumes that the object has a docstring.


def __init__(self, checker=None, verbose=None, optionflags=<NUM_LIT:0>):

self._checker = checker or OutputChecker()<EOL>if verbose is None:<EOL><INDENT>verbose = '<STR_LIT>' in sys.argv<EOL><DEDENT>self._verbose = verbose<EOL>self.optionflags = optionflags<EOL>self.original_optionflags = optionflags<EOL>self.tries = <NUM_LIT:0><EOL>self.failures = <NUM_LIT:0><EOL>self._name2ft = {}<EOL>self._fakeout = _SpoofOut()<EOL>

Create a new test runner.

Optional keyword arg `checker` is the `OutputChecker` that
should be used to compare the expected outputs and actual
outputs of doctest examples.

Optional keyword arg 'verbose' prints lots of stuff if true,
only failures if false; by default, it's true iff '-v' is in
sys.argv.

Optional argument `optionflags` can be used to control how the
test runner compares expected output to actual output, and how
it displays failures.  See the documentation for `testmod` for
more information.


if verbose is None:<EOL><INDENT>verbose = self._verbose<EOL><DEDENT>notests = []<EOL>passed = []<EOL>failed = []<EOL>totalt = totalf = <NUM_LIT:0><EOL>for x in list(self._name2ft.items()):<EOL><INDENT>name, (f, t) = x<EOL>assert f <= t<EOL>totalt += t<EOL>totalf += f<EOL>if t == <NUM_LIT:0>:<EOL><INDENT>notests.append(name)<EOL><DEDENT>elif f == <NUM_LIT:0>:<EOL><INDENT>passed.append( (name, t) )<EOL><DEDENT>else:<EOL><INDENT>failed.append(x)<EOL><DEDENT><DEDENT>if verbose:<EOL><INDENT>if notests:<EOL><INDENT>print(len(notests), "<STR_LIT>")<EOL>notests.sort()<EOL>for thing in notests:<EOL><INDENT>print("<STR_LIT:U+0020>", thing)<EOL><DEDENT><DEDENT>if passed:<EOL><INDENT>print(len(passed), "<STR_LIT>")<EOL>passed.sort()<EOL>for thing, count in passed:<EOL><INDENT>print("<STR_LIT>" % (count, thing))<EOL><DEDENT><DEDENT><DEDENT>if failed:<EOL><INDENT>print(self.DIVIDER)<EOL>print(len(failed), "<STR_LIT>")<EOL>failed.sort()<EOL>for thing, (f, t) in failed:<EOL><INDENT>print("<STR_LIT>" % (f, t, thing))<EOL><DEDENT><DEDENT>if verbose:<EOL><INDENT>print(totalt, "<STR_LIT>", len(self._name2ft), "<STR_LIT>")<EOL>print(totalt - totalf, "<STR_LIT>", totalf, "<STR_LIT>")<EOL><DEDENT>if totalf:<EOL><INDENT>print("<STR_LIT>", totalf, "<STR_LIT>")<EOL><DEDENT>elif verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>return totalf, totalt<EOL>

Print a summary of all the test cases that have been run by
this DocTestRunner, and return a tuple `(f, t)`, where `f` is
the total number of failed examples, and `t` is the total
number of tried examples.

The optional `verbose` argument controls how detailed the
summary is.  If the verbosity is not specified, then the
DocTestRunner's verbosity is used.


def check_output(self, want, got, optionflags):

<EOL>if got == want:<EOL><INDENT>return True<EOL><DEDENT>if not (optionflags & DONT_ACCEPT_TRUE_FOR_1):<EOL><INDENT>if (got,want) == ("<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>return True<EOL><DEDENT>if (got,want) == ("<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>if not (optionflags & DONT_ACCEPT_BLANKLINE):<EOL><INDENT>want = re.sub('<STR_LIT>' % re.escape(BLANKLINE_MARKER),<EOL>'<STR_LIT>', want)<EOL>got = re.sub('<STR_LIT>', '<STR_LIT>', got)<EOL>if got == want:<EOL><INDENT>return True<EOL><DEDENT><DEDENT>if optionflags & NORMALIZE_WHITESPACE:<EOL><INDENT>got = '<STR_LIT:U+0020>'.join(got.split())<EOL>want = '<STR_LIT:U+0020>'.join(want.split())<EOL>if got == want:<EOL><INDENT>return True<EOL><DEDENT><DEDENT>if optionflags & ELLIPSIS:<EOL><INDENT>if _ellipsis_match(want, got):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>return False<EOL>

Return True iff the actual output from an example (`got`)
matches the expected output (`want`).  These strings are
always considered to match if they are identical; but
depending on what option flags the test runner is using,
several non-exact match types are also possible.  See the
documentation for `TestRunner` for more information about
option flags.


def output_difference(self, example, got, optionflags):

want = example.want<EOL>if not (optionflags & DONT_ACCEPT_BLANKLINE):<EOL><INDENT>got = re.sub('<STR_LIT>', BLANKLINE_MARKER, got)<EOL><DEDENT>if self._do_a_fancy_diff(want, got, optionflags):<EOL><INDENT>want_lines = want.splitlines(True)  <EOL>got_lines = got.splitlines(True)<EOL>if optionflags & REPORT_UDIFF:<EOL><INDENT>diff = difflib.unified_diff(want_lines, got_lines, n=<NUM_LIT:2>)<EOL>diff = list(diff)[<NUM_LIT:2>:] <EOL>kind = '<STR_LIT>'<EOL><DEDENT>elif optionflags & REPORT_CDIFF:<EOL><INDENT>diff = difflib.context_diff(want_lines, got_lines, n=<NUM_LIT:2>)<EOL>diff = list(diff)[<NUM_LIT:2>:] <EOL>kind = '<STR_LIT>'<EOL><DEDENT>elif optionflags & REPORT_NDIFF:<EOL><INDENT>engine = difflib.Differ(charjunk=difflib.IS_CHARACTER_JUNK)<EOL>diff = list(engine.compare(want_lines, got_lines))<EOL>kind = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>assert <NUM_LIT:0>, '<STR_LIT>'<EOL><DEDENT>diff = [line.rstrip() + '<STR_LIT:\n>' for line in diff]<EOL>return '<STR_LIT>' % kind + _indent('<STR_LIT>'.join(diff))<EOL><DEDENT>if want and got:<EOL><INDENT>return '<STR_LIT>' % (_indent(want), _indent(got))<EOL><DEDENT>elif want:<EOL><INDENT>return '<STR_LIT>' % _indent(want)<EOL><DEDENT>elif got:<EOL><INDENT>return '<STR_LIT>' % _indent(got)<EOL><DEDENT>else:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>

Return a string describing the differences between the
expected output for a given example (`example`) and the actual
output (`got`).  `optionflags` is the set of option flags used
to compare `want` and `got`.


self.setUp()<EOL>runner = DebugRunner(optionflags=self._dt_optionflags,<EOL>checker=self._dt_checker, verbose=False)<EOL>runner.run(self._dt_test)<EOL>self.tearDown()<EOL>

r"""Run the test case without results and without catching exceptions

           The unit test framework includes a debug method on test cases
           and test suites to support post-mortem debugging.  The test code
           is run in such a way that errors are not caught.  This way a
           caller can catch the errors and initiate post-mortem debugging.

           The DocTestCase provides a debug method that raises
           UnexpectedException errors if there is an unexepcted
           exception:

             >>> test = DocTestParser().get_doctest('>>> raise KeyError\n42',
             ...                {}, 'foo', 'foo.py', 0)
             >>> case = DocTestCase(test)
             >>> try:
             ...     case.debug()
             ... except UnexpectedException, failure:
             ...     pass

           The UnexpectedException contains the test, the example, and
           the original exception:

             >>> failure.test is test
             True

             >>> failure.example.want
             '42\n'

             >>> exc_info = failure.exc_info
             >>> raise exc_info[0], exc_info[1], exc_info[2]
             Traceback (most recent call last):
             ...
             KeyError

           If the output doesn't match, then a DocTestFailure is raised:

             >>> test = DocTestParser().get_doctest('''
             ...      >>> x = 1
             ...      >>> x
             ...      2
             ...      ''', {}, 'foo', 'foo.py', 0)
             >>> case = DocTestCase(test)

             >>> try:
             ...    case.debug()
             ... except DocTestFailure, failure:
             ...    pass

           DocTestFailure objects provide access to the test:

             >>> failure.test is test
             True

           As well as to the example:

             >>> failure.example.want
             '2\n'

           and the actual output:

             >>> failure.got
             '1\n'


self.val = val<EOL>

val -> _TestClass object with associated value val.

        >>> t = _TestClass(123)
        >>> print t.get()
        123


self.val = self.val ** <NUM_LIT:2><EOL>return self<EOL>

square() -> square TestClass's associated value

        >>> _TestClass(13).square().get()
        169


return self.val<EOL>

get() -> return TestClass's associated value.

        >>> x = _TestClass(-42)
        >>> print x.get()
        -42


try:<EOL><INDENT>result = repr(obj)<EOL><DEDENT>except Exception:<EOL><INDENT>result = object.__repr__(obj)<EOL><DEDENT>if not short or len(result) < _MAX_LENGTH:<EOL><INDENT>return result<EOL><DEDENT>return result[:_MAX_LENGTH] + '<STR_LIT>'<EOL>


if member not in container:<EOL><INDENT>standardMsg = '<STR_LIT>' % (safe_repr(member),<EOL>safe_repr(container))<EOL>self.fail(self._formatMessage(msg, standardMsg))<EOL><DEDENT>

assertIn and assertTrue does not exist in Python2.3


test_setup_attrs = {<EOL>'<STR_LIT:name>': '<STR_LIT>', '<STR_LIT:version>': '<STR_LIT>',<EOL>'<STR_LIT>': ['<STR_LIT>'],<EOL>'<STR_LIT>': [os.path.abspath(path)]<EOL>}<EOL>test_pkg = os.path.join(path, '<STR_LIT>')<EOL>test_setup_py = os.path.join(test_pkg, '<STR_LIT>')<EOL>test_setup_cfg = os.path.join(test_pkg, '<STR_LIT>')<EOL>os.mkdir(test_pkg)<EOL>f = open(test_setup_py, '<STR_LIT:w>')<EOL>f.write(textwrap.dedent("""<STR_LIT>""" % test_setup_attrs))<EOL>f.close()<EOL>foobar_path = os.path.join(path, '<STR_LIT>')<EOL>make_trivial_sdist(<EOL>foobar_path,<EOL>textwrap.dedent("""<STR_LIT>"""))<EOL>return test_pkg<EOL>

Creates a source tree under path for a trivial test package that has a
    single requirement in setup_requires--a tarball for that requirement is
    also created and added to the dependency_links argument.


setup_py_file = tarfile.TarInfo(name='<STR_LIT>')<EOL>try:<EOL><INDENT>MemFile = StringIO.BytesIO<EOL><DEDENT>except AttributeError:<EOL><INDENT>MemFile = StringIO.StringIO<EOL><DEDENT>setup_py_bytes = MemFile(setup_py.encode('<STR_LIT:utf-8>'))<EOL>setup_py_file.size = len(setup_py_bytes.getvalue())<EOL>dist = tarfile.open(dist_path, '<STR_LIT>')<EOL>try:<EOL><INDENT>dist.addfile(setup_py_file, fileobj=setup_py_bytes)<EOL><DEDENT>finally:<EOL><INDENT>dist.close()<EOL><DEDENT>

Create a simple sdist tarball at dist_path, containing just a
    setup.py, the contents of which are provided by the setup_py string.


def tempdir_context(f, cd=lambda dir:None):

temp_dir = tempfile.mkdtemp()<EOL>orig_dir = os.getcwd()<EOL>try:<EOL><INDENT>cd(temp_dir)<EOL>f(temp_dir)<EOL><DEDENT>finally:<EOL><INDENT>cd(orig_dir)<EOL>shutil.rmtree(temp_dir)<EOL><DEDENT>


old_env = os.environ.copy()<EOL>os.environ.update(updates)<EOL>try:<EOL><INDENT>f()<EOL><DEDENT>finally:<EOL><INDENT>for key in updates:<EOL><INDENT>del os.environ[key]<EOL><DEDENT>os.environ.update(old_env)<EOL><DEDENT>


old_argv = sys.argv[:]<EOL>sys.argv[:] = repl<EOL>try:<EOL><INDENT>f()<EOL><DEDENT>finally:<EOL><INDENT>sys.argv[:] = old_argv<EOL><DEDENT>


setup_stop_after = distutils.core._setup_stop_after<EOL>distutils.core._setup_stop_after = None<EOL>try:<EOL><INDENT>f()<EOL><DEDENT>finally:<EOL><INDENT>distutils.core._setup_stop_after = setup_stop_after<EOL><DEDENT>

When the distribute tests are run using setup.py test, and then
one wants to invoke another setup() command (such as easy_install)
within those tests, it's necessary to reset the global variable
in distutils.core so that the setup() command will run naturally.


old_stdout = sys.stdout<EOL>old_stderr = sys.stderr<EOL>new_stdout = sys.stdout = StringIO.StringIO()<EOL>new_stderr = sys.stderr = StringIO.StringIO()<EOL>try:<EOL><INDENT>f()<EOL><DEDENT>finally:<EOL><INDENT>sys.stdout = old_stdout<EOL>sys.stderr = old_stderr<EOL><DEDENT>return new_stdout.getvalue(), new_stderr.getvalue()<EOL>

Redirect stdout/stderr to StringIO objects to prevent console output from
distutils commands.


def build_sdist(dir):<EOL><INDENT>dist_path = os.path.join(dir, '<STR_LIT>')<EOL>make_trivial_sdist(<EOL>dist_path,<EOL>textwrap.dedent("""<STR_LIT>""").lstrip())<EOL>installer(dist_path)<EOL><DEDENT>tempdir_context(build_sdist)<EOL>

Create an sdist with a setup_requires dependency (of something that
doesn't exist) and invoke installer on it.


if not sys.platform.startswith('<STR_LIT:win32>'):<EOL><INDENT>return False<EOL><DEDENT>try:<EOL><INDENT>mod = __import__('<STR_LIT>')<EOL><DEDENT>except ImportError:<EOL><INDENT>return False<EOL><DEDENT>return True<EOL>

Run this to determine if the local machine has win32com, and if it
does, include additional tests.


return textwrap.dedent(s).lstrip()<EOL>


<EOL>time.sleep(<NUM_LIT:0.1>)<EOL>self._run = False<EOL>url = '<STR_LIT>' % vars(self)<EOL>try:<EOL><INDENT>if sys.version_info >= (<NUM_LIT:2>, <NUM_LIT:6>):<EOL><INDENT>urllib2.urlopen(url, timeout=<NUM_LIT:5>)<EOL><DEDENT>else:<EOL><INDENT>urllib2.urlopen(url)<EOL><DEDENT><DEDENT>except urllib2.URLError:<EOL><INDENT>pass<EOL><DEDENT>self.thread.join()<EOL>


distutils.core._setup_stop_after = "<STR_LIT>"<EOL>args.setdefault('<STR_LIT>',['<STR_LIT>'])<EOL>try:<EOL><INDENT>return setuptools.setup(**args)<EOL><DEDENT>finally:<EOL><INDENT>distutils.core._setup_stop_after = None<EOL><DEDENT>

Return distribution from 'setup(**args)', without executing commands


return dst<EOL>

The default progress/filter callback; returns True for all files


def unpack_archive(filename, extract_dir, progress_filter=default_filter,<EOL>drivers=None<EOL>):

for driver in drivers or extraction_drivers:<EOL><INDENT>try:<EOL><INDENT>driver(filename, extract_dir, progress_filter)<EOL><DEDENT>except UnrecognizedFormat:<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>return<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise UnrecognizedFormat(<EOL>"<STR_LIT>" % filename<EOL>)<EOL><DEDENT>

Unpack `filename` to `extract_dir`, or raise ``UnrecognizedFormat``

    `progress_filter` is a function taking two arguments: a source path
    internal to the archive ('/'-separated), and a filesystem path where it
    will be extracted.  The callback must return the desired extract path
    (which may be the same as the one passed in), or else ``None`` to skip
    that file or directory.  The callback can thus be used to report on the
    progress of the extraction, as well as to filter the items extracted or
    alter their extraction paths.

    `drivers`, if supplied, must be a non-empty sequence of functions with the
    same signature as this function (minus the `drivers` argument), that raise
    ``UnrecognizedFormat`` if they do not support extracting the designated
    archive type.  The `drivers` are tried in sequence until one is found that
    does not raise an error, or until all are exhausted (in which case
    ``UnrecognizedFormat`` is raised).  If you do not supply a sequence of
    drivers, the module's ``extraction_drivers`` constant will be used, which
    means that ``unpack_zipfile`` and ``unpack_tarfile`` will be tried, in that
    order.


def unpack_directory(filename, extract_dir, progress_filter=default_filter):

if not os.path.isdir(filename):<EOL><INDENT>raise UnrecognizedFormat("<STR_LIT>" % (filename,))<EOL><DEDENT>paths = {filename:('<STR_LIT>',extract_dir)}<EOL>for base, dirs, files in os.walk(filename):<EOL><INDENT>src,dst = paths[base]<EOL>for d in dirs:<EOL><INDENT>paths[os.path.join(base,d)] = src+d+'<STR_LIT:/>', os.path.join(dst,d)<EOL><DEDENT>for f in files:<EOL><INDENT>name = src+f<EOL>target = os.path.join(dst,f)<EOL>target = progress_filter(src+f, target)<EOL>if not target:<EOL><INDENT>continue    <EOL><DEDENT>ensure_directory(target)<EOL>f = os.path.join(base,f)<EOL>shutil.copyfile(f, target)<EOL>shutil.copystat(f, target)<EOL><DEDENT><DEDENT>

Unpack" a directory, using the same interface as for archives

    Raises ``UnrecognizedFormat`` if `filename` is not a directory


def unpack_zipfile(filename, extract_dir, progress_filter=default_filter):

if not zipfile.is_zipfile(filename):<EOL><INDENT>raise UnrecognizedFormat("<STR_LIT>" % (filename,))<EOL><DEDENT>z = zipfile.ZipFile(filename)<EOL>try:<EOL><INDENT>for info in z.infolist():<EOL><INDENT>name = info.filename<EOL>if name.startswith('<STR_LIT:/>') or '<STR_LIT:..>' in name:<EOL><INDENT>continue<EOL><DEDENT>target = os.path.join(extract_dir, *name.split('<STR_LIT:/>'))<EOL>target = progress_filter(name, target)<EOL>if not target:<EOL><INDENT>continue<EOL><DEDENT>if name.endswith('<STR_LIT:/>'):<EOL><INDENT>ensure_directory(target)<EOL><DEDENT>else:<EOL><INDENT>ensure_directory(target)<EOL>data = z.read(info.filename)<EOL>f = open(target,'<STR_LIT:wb>')<EOL>try:<EOL><INDENT>f.write(data)<EOL><DEDENT>finally:<EOL><INDENT>f.close()<EOL>del data<EOL><DEDENT><DEDENT>unix_attributes = info.external_attr >> <NUM_LIT:16><EOL>if unix_attributes:<EOL><INDENT>os.chmod(target, unix_attributes)<EOL><DEDENT><DEDENT><DEDENT>finally:<EOL><INDENT>z.close()<EOL><DEDENT>

Unpack zip `filename` to `extract_dir`

    Raises ``UnrecognizedFormat`` if `filename` is not a zipfile (as determined
    by ``zipfile.is_zipfile()``).  See ``unpack_archive()`` for an explanation
    of the `progress_filter` argument.


def unpack_tarfile(filename, extract_dir, progress_filter=default_filter):

try:<EOL><INDENT>tarobj = tarfile.open(filename)<EOL><DEDENT>except tarfile.TarError:<EOL><INDENT>raise UnrecognizedFormat(<EOL>"<STR_LIT>" % (filename,)<EOL>)<EOL><DEDENT>try:<EOL><INDENT>tarobj.chown = lambda *args: None   <EOL>for member in tarobj:<EOL><INDENT>name = member.name<EOL>if not name.startswith('<STR_LIT:/>') and '<STR_LIT:..>' not in name:<EOL><INDENT>prelim_dst = os.path.join(extract_dir, *name.split('<STR_LIT:/>'))<EOL>final_dst = progress_filter(name, prelim_dst)<EOL>if final_dst and (member.isfile() or member.isdir() or<EOL>member.islnk() or member.issym()):<EOL><INDENT>tarobj.extract(member, extract_dir)<EOL>if final_dst != prelim_dst:<EOL><INDENT>shutil.move(prelim_dst, final_dst)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return True<EOL><DEDENT>finally:<EOL><INDENT>tarobj.close()<EOL><DEDENT>

Unpack tar/tar.gz/tar.bz2 `filename` to `extract_dir`

    Raises ``UnrecognizedFormat`` if `filename` is not a tarfile (as determined
    by ``tarfile.open()``).  See ``unpack_archive()`` for an explanation
    of the `progress_filter` argument.


lower = name.lower()<EOL>base, py_ver, plat = None, None, None<EOL>if lower.endswith('<STR_LIT>'):<EOL><INDENT>if lower.endswith('<STR_LIT>'):<EOL><INDENT>base = name[:-<NUM_LIT:10>]<EOL>plat = '<STR_LIT:win32>'<EOL><DEDENT>elif lower.startswith('<STR_LIT>',-<NUM_LIT:16>):<EOL><INDENT>py_ver = name[-<NUM_LIT:7>:-<NUM_LIT:4>]<EOL>base = name[:-<NUM_LIT:16>]<EOL>plat = '<STR_LIT:win32>'<EOL><DEDENT>elif lower.endswith('<STR_LIT>'):<EOL><INDENT>base = name[:-<NUM_LIT>]<EOL>plat = '<STR_LIT>'<EOL><DEDENT>elif lower.startswith('<STR_LIT>',-<NUM_LIT:20>):<EOL><INDENT>py_ver = name[-<NUM_LIT:7>:-<NUM_LIT:4>]<EOL>base = name[:-<NUM_LIT:20>]<EOL>plat = '<STR_LIT>'<EOL><DEDENT><DEDENT>return base,py_ver,plat<EOL>

Return (base,pyversion) or (None,None) for possible .exe name


base, fragment = egg_info_for_url(url)<EOL>for dist in distros_for_location(url, base, metadata): yield dist<EOL>if fragment:<EOL><INDENT>match = EGG_FRAGMENT.match(fragment)<EOL>if match:<EOL><INDENT>for dist in interpret_distro_name(<EOL>url, match.group(<NUM_LIT:1>), metadata, precedence = CHECKOUT_DIST<EOL>):<EOL><INDENT>yield dist<EOL><DEDENT><DEDENT><DEDENT>

Yield egg or source distribution objects that might be found at a URL


def distros_for_location(location, basename, metadata=None):

if basename.endswith('<STR_LIT>'):<EOL><INDENT>basename = basename[:-<NUM_LIT:4>]    <EOL><DEDENT>if basename.endswith('<STR_LIT>') and '<STR_LIT:->' in basename:<EOL><INDENT>return [Distribution.from_location(location, basename, metadata)]<EOL><DEDENT>if basename.endswith('<STR_LIT>'):<EOL><INDENT>win_base, py_ver, platform = parse_bdist_wininst(basename)<EOL>if win_base is not None:<EOL><INDENT>return interpret_distro_name(<EOL>location, win_base, metadata, py_ver, BINARY_DIST, platform<EOL>)<EOL><DEDENT><DEDENT>for ext in EXTENSIONS:<EOL><INDENT>if basename.endswith(ext):<EOL><INDENT>basename = basename[:-len(ext)]<EOL>return interpret_distro_name(location, basename, metadata)<EOL><DEDENT><DEDENT>return []<EOL>

Yield egg or source distribution objects based on basename


return distros_for_location(<EOL>normalize_path(filename), os.path.basename(filename), metadata<EOL>)<EOL>

Yield possible egg or source distribution objects based on a filename


def interpret_distro_name(location, basename, metadata,<EOL>py_version=None, precedence=SOURCE_DIST, platform=None<EOL>):

<EOL>parts = basename.split('<STR_LIT:->')<EOL>if not py_version:<EOL><INDENT>for i,p in enumerate(parts[<NUM_LIT:2>:]):<EOL><INDENT>if len(p)==<NUM_LIT:5> and p.startswith('<STR_LIT>'):<EOL><INDENT>return <EOL><DEDENT><DEDENT><DEDENT>for p in range(<NUM_LIT:1>,len(parts)+<NUM_LIT:1>):<EOL><INDENT>yield Distribution(<EOL>location, metadata, '<STR_LIT:->'.join(parts[:p]), '<STR_LIT:->'.join(parts[p:]),<EOL>py_version=py_version, precedence = precedence,<EOL>platform = platform<EOL>)<EOL><DEDENT>

Generate alternative interpretations of a source distro name

    Note: if `location` is a filesystem filename, you should call
    ``pkg_resources.normalize_path()`` on it before passing it to this
    routine!


for match in REL.finditer(page):<EOL><INDENT>tag, rel = match.groups()<EOL>rels = list(map(str.strip, rel.lower().split('<STR_LIT:U+002C>')))<EOL>if '<STR_LIT>' in rels or '<STR_LIT>' in rels:<EOL><INDENT>for match in HREF.finditer(tag):<EOL><INDENT>yield urllib.parse.urljoin(url, htmldecode(match.group(<NUM_LIT:1>)))<EOL><DEDENT><DEDENT><DEDENT>for tag in ("<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>pos = page.find(tag)<EOL>if pos!=-<NUM_LIT:1>:<EOL><INDENT>match = HREF.search(page,pos)<EOL>if match:<EOL><INDENT>yield urllib.parse.urljoin(url, htmldecode(match.group(<NUM_LIT:1>)))<EOL><DEDENT><DEDENT><DEDENT>

Find rel="homepage" and rel="download" links in `page`, yielding URLs


return entity_sub(decode_entity, text)<EOL>


auth_s = urllib.parse.unquote(auth)<EOL>auth_bytes = auth_s.encode()<EOL>encoded_bytes = base64.encodestring(auth_bytes)<EOL>encoded = encoded_bytes.decode()<EOL>return encoded.rstrip()<EOL>

A function compatible with Python 2.3-3.3 that will encode
auth from a URL suitable for an HTTP header.
>>> _encode_auth('username%3Apassword')
u'dXNlcm5hbWU6cGFzc3dvcmQ='


scheme, netloc, path, params, query, frag = urllib.parse.urlparse(url)<EOL>if netloc.endswith('<STR_LIT::>'):<EOL><INDENT>raise http.client.InvalidURL("<STR_LIT>")<EOL><DEDENT>if scheme in ('<STR_LIT:http>', '<STR_LIT>'):<EOL><INDENT>auth, host = urllib.parse.splituser(netloc)<EOL><DEDENT>else:<EOL><INDENT>auth = None<EOL><DEDENT>if auth:<EOL><INDENT>auth = "<STR_LIT>" + _encode_auth(auth)<EOL>new_url = urllib.parse.urlunparse((scheme,host,path,params,query,frag))<EOL>request = urllib.request.Request(new_url)<EOL>request.add_header("<STR_LIT>", auth)<EOL><DEDENT>else:<EOL><INDENT>request = urllib.request.Request(url)<EOL><DEDENT>request.add_header('<STR_LIT>', user_agent)<EOL>fp = urllib.request.urlopen(request)<EOL>if auth:<EOL><INDENT>s2, h2, path2, param2, query2, frag2 = urllib.parse.urlparse(fp.url)<EOL>if s2==scheme and h2==host:<EOL><INDENT>fp.url = urllib.parse.urlunparse((s2,netloc,path2,param2,query2,frag2))<EOL><DEDENT><DEDENT>return fp<EOL>

Open a urllib2 request, handling HTTP authentication


scheme, server, path, param, query, frag = urllib.parse.urlparse(url)<EOL>filename = urllib.request.url2pathname(path)<EOL>if os.path.isfile(filename):<EOL><INDENT>return urllib.request.urlopen(url)<EOL><DEDENT>elif path.endswith('<STR_LIT:/>') and os.path.isdir(filename):<EOL><INDENT>files = []<EOL>for f in os.listdir(filename):<EOL><INDENT>if f=='<STR_LIT>':<EOL><INDENT>fp = open(os.path.join(filename,f),'<STR_LIT:rb>')<EOL>body = fp.read()<EOL>fp.close()<EOL>break<EOL><DEDENT>elif os.path.isdir(os.path.join(filename,f)):<EOL><INDENT>f+='<STR_LIT:/>'<EOL><DEDENT>files.append("<STR_LIT>" % (f,f))<EOL><DEDENT>else:<EOL><INDENT>body = ("<STR_LIT>" % url) +"<STR_LIT>" % '<STR_LIT:\n>'.join(files)<EOL><DEDENT>status, message = <NUM_LIT:200>, "<STR_LIT:OK>"<EOL><DEDENT>else:<EOL><INDENT>status, message, body = <NUM_LIT>, "<STR_LIT>", "<STR_LIT>"<EOL><DEDENT>return urllib.error.HTTPError(url, status, message,<EOL>{'<STR_LIT>':'<STR_LIT>'}, io.StringIO(body))<EOL>

Read a local path, with special support for directories


def process_url(self, url, retrieve=False):

if url in self.scanned_urls and not retrieve:<EOL><INDENT>return<EOL><DEDENT>self.scanned_urls[url] = True<EOL>if not URL_SCHEME(url):<EOL><INDENT>self.process_filename(url)<EOL>return<EOL><DEDENT>else:<EOL><INDENT>dists = list(distros_for_url(url))<EOL>if dists:<EOL><INDENT>if not self.url_ok(url):<EOL><INDENT>return<EOL><DEDENT>self.debug("<STR_LIT>", url)<EOL><DEDENT><DEDENT>if dists or not retrieve or url in self.fetched_urls:<EOL><INDENT>list(map(self.add, dists))<EOL>return  <EOL><DEDENT>if not self.url_ok(url):<EOL><INDENT>self.fetched_urls[url] = True<EOL>return<EOL><DEDENT>self.info("<STR_LIT>", url)<EOL>f = self.open_url(url, "<STR_LIT>" % url)<EOL>if f is None: return<EOL>self.fetched_urls[url] = self.fetched_urls[f.url] = True<EOL>if '<STR_LIT:html>' not in f.headers.get('<STR_LIT>', '<STR_LIT>').lower():<EOL><INDENT>f.close()   <EOL>return<EOL><DEDENT>base = f.url     <EOL>page = f.read()<EOL>if not isinstance(page, str): <EOL><INDENT>if isinstance(f, urllib.error.HTTPError):<EOL><INDENT>charset = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>charset = f.headers.get_param('<STR_LIT>') or '<STR_LIT>'<EOL><DEDENT>page = page.decode(charset, "<STR_LIT:ignore>")<EOL><DEDENT>f.close()<EOL>for match in HREF.finditer(page):<EOL><INDENT>link = urllib.parse.urljoin(base, htmldecode(match.group(<NUM_LIT:1>)))<EOL>self.process_url(link)<EOL><DEDENT>if url.startswith(self.index_url) and getattr(f,'<STR_LIT:code>',None)!=<NUM_LIT>:<EOL><INDENT>page = self.process_index(url, page)<EOL><DEDENT>

Evaluate a URL as a possible download, and maybe retrieve it


def scan(link):<EOL><INDENT>if link.startswith(self.index_url):<EOL><INDENT>parts = list(map(<EOL>urllib.parse.unquote, link[len(self.index_url):].split('<STR_LIT:/>')<EOL>))<EOL>if len(parts)==<NUM_LIT:2> and '<STR_LIT:#>' not in parts[<NUM_LIT:1>]:<EOL><INDENT>pkg = safe_name(parts[<NUM_LIT:0>])<EOL>ver = safe_version(parts[<NUM_LIT:1>])<EOL>self.package_pages.setdefault(pkg.lower(),{})[link] = True<EOL>return to_filename(pkg), to_filename(ver)<EOL><DEDENT><DEDENT>return None, None<EOL><DEDENT>for match in HREF.finditer(page):<EOL><INDENT>try:<EOL><INDENT>scan( urllib.parse.urljoin(url, htmldecode(match.group(<NUM_LIT:1>))) )<EOL><DEDENT>except ValueError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>pkg, ver = scan(url)   <EOL>if pkg:<EOL><INDENT>for new_url in find_external_links(url, page):<EOL><INDENT>base, frag = egg_info_for_url(new_url)<EOL>if base.endswith('<STR_LIT>') and not frag:<EOL><INDENT>if ver:<EOL><INDENT>new_url+='<STR_LIT>' % (pkg,ver)<EOL><DEDENT>else:<EOL><INDENT>self.need_version_info(url)<EOL><DEDENT><DEDENT>self.scan_url(new_url)<EOL><DEDENT>return PYPI_MD5.sub(<EOL>lambda m: '<STR_LIT>' % m.group(<NUM_LIT:1>,<NUM_LIT:3>,<NUM_LIT:2>), page<EOL>)<EOL><DEDENT>else:<EOL><INDENT>return "<STR_LIT>"<EOL><DEDENT>


for url in urls:<EOL><INDENT>if (<EOL>self.to_scan is None        <EOL>or not URL_SCHEME(url)      <EOL>or url.startswith('<STR_LIT>')<EOL>or list(distros_for_url(url))   <EOL>):<EOL><INDENT>self.scan_url(url)<EOL><DEDENT>else:<EOL><INDENT>self.to_scan.append(url)<EOL><DEDENT><DEDENT>

Add `urls` to the list that will be prescanned for searches


if self.to_scan:<EOL><INDENT>list(map(self.scan_url, self.to_scan))<EOL><DEDENT>self.to_scan = None<EOL>

Scan urls scheduled for prescanning (e.g. --find-links)


if not isinstance(spec,Requirement):<EOL><INDENT>scheme = URL_SCHEME(spec)<EOL>if scheme:<EOL><INDENT>found = self._download_url(scheme.group(<NUM_LIT:1>), spec, tmpdir)<EOL>base, fragment = egg_info_for_url(spec)<EOL>if base.endswith('<STR_LIT>'):<EOL><INDENT>found = self.gen_setup(found,fragment,tmpdir)<EOL><DEDENT>return found<EOL><DEDENT>elif os.path.exists(spec):<EOL><INDENT>return spec<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>spec = Requirement.parse(spec)<EOL><DEDENT>except ValueError:<EOL><INDENT>raise DistutilsError(<EOL>"<STR_LIT>" %<EOL>(spec,)<EOL>)<EOL><DEDENT><DEDENT><DEDENT>return getattr(self.fetch_distribution(spec, tmpdir),'<STR_LIT:location>',None)<EOL>

Locate and/or download `spec` to `tmpdir`, returning a local path

        `spec` may be a ``Requirement`` object, or a string containing a URL,
        an existing local filename, or a project/version requirement spec
        (i.e. the string form of a ``Requirement`` object).  If it is the URL
        of a .py file with an unambiguous ``#egg=name-version`` tag (i.e., one
        that escapes ``-`` as ``_`` throughout), a trivial ``setup.py`` is
        automatically created alongside the downloaded file.

        If `spec` is a ``Requirement`` object or a string containing a
        project/version requirement spec, this method returns the location of
        a matching distribution (possibly after downloading it to `tmpdir`).
        If `spec` is a locally existing file or directory name, it is simply
        returned unchanged.  If `spec` is a URL, it is downloaded to a subpath
        of `tmpdir`, and the local filename is returned.  Various errors may be
        raised if a problem occurs during downloading.


def fetch_distribution(self,<EOL>requirement, tmpdir, force_scan=False, source=False, develop_ok=False,<EOL>local_index=None<EOL>):

<EOL>self.info("<STR_LIT>", requirement)<EOL>skipped = {}<EOL>dist = None<EOL>def find(req, env=None):<EOL><INDENT>if env is None:<EOL><INDENT>env = self<EOL><DEDENT>for dist in env[req.key]:<EOL><INDENT>if dist.precedence==DEVELOP_DIST and not develop_ok:<EOL><INDENT>if dist not in skipped:<EOL><INDENT>self.warn("<STR_LIT>",dist)<EOL>skipped[dist] = <NUM_LIT:1><EOL><DEDENT>continue<EOL><DEDENT>if dist in req and (dist.precedence<=SOURCE_DIST or not source):<EOL><INDENT>self.info("<STR_LIT>", dist)<EOL>return dist.clone(<EOL>location=self.download(dist.location, tmpdir)<EOL>)<EOL><DEDENT><DEDENT><DEDENT>if force_scan:<EOL><INDENT>self.prescan()<EOL>self.find_packages(requirement)<EOL>dist = find(requirement)<EOL><DEDENT>if local_index is not None:<EOL><INDENT>dist = dist or find(requirement, local_index)<EOL><DEDENT>if dist is None and self.to_scan is not None:<EOL><INDENT>self.prescan()<EOL>dist = find(requirement)<EOL><DEDENT>if dist is None and not force_scan:<EOL><INDENT>self.find_packages(requirement)<EOL>dist = find(requirement)<EOL><DEDENT>if dist is None:<EOL><INDENT>self.warn(<EOL>"<STR_LIT>",<EOL>(source and "<STR_LIT>" or "<STR_LIT>"),<EOL>requirement,<EOL>)<EOL><DEDENT>return dist<EOL>

Obtain a distribution suitable for fulfilling `requirement`

        `requirement` must be a ``pkg_resources.Requirement`` instance.
        If necessary, or if the `force_scan` flag is set, the requirement is
        searched for in the (online) package index as well as the locally
        installed packages.  If a distribution matching `requirement` is found,
        the returned distribution's ``location`` is the value you would have
        gotten from calling the ``download()`` method with the matching
        distribution's URL or filename.  If no matching distribution is found,
        ``None`` is returned.

        If the `source` flag is set, only source distributions and source
        checkout links will be considered.  Unless the `develop_ok` flag is
        set, development and system eggs (i.e., those using the ``.egg-info``
        format) will be ignored.


def fetch(self, requirement, tmpdir, force_scan=False, source=False):

dist = self.fetch_distribution(requirement,tmpdir,force_scan,source)<EOL>if dist is not None:<EOL><INDENT>return dist.location<EOL><DEDENT>return None<EOL>

Obtain a file suitable for fulfilling `requirement`

        DEPRECATED; use the ``fetch_distribution()`` method now instead.  For
        backward compatibility, this routine is identical but returns the
        ``location`` of the downloaded distribution instead of a distribution
        object.


if not self.py_modules and not self.packages:<EOL><INDENT>return<EOL><DEDENT>if self.py_modules:<EOL><INDENT>self.build_modules()<EOL><DEDENT>if self.packages:<EOL><INDENT>self.build_packages()<EOL>self.build_package_data()<EOL><DEDENT>self.run_2to3(self.__updated_files, False)<EOL>self.run_2to3(self.__updated_files, True)<EOL>self.run_2to3(self.__doctests_2to3, True)<EOL>self.byte_compile(_build_py.get_outputs(self, include_bytecode=<NUM_LIT:0>))<EOL>

Build modules, packages, and copy data files to build directory


self.analyze_manifest()<EOL>data = []<EOL>for package in self.packages or ():<EOL><INDENT>src_dir = self.get_package_dir(package)<EOL>build_dir = os.path.join(*([self.build_lib] + package.split('<STR_LIT:.>')))<EOL>plen = len(src_dir)+<NUM_LIT:1><EOL>filenames = [<EOL>file[plen:] for file in self.find_data_files(package, src_dir)<EOL>]<EOL>data.append( (package, src_dir, build_dir, filenames) )<EOL><DEDENT>return data<EOL>

Generate list of '(package,src_dir,build_dir,filenames)' tuples


def find_data_files(self, package, src_dir):

globs = (self.package_data.get('<STR_LIT>', [])<EOL>+ self.package_data.get(package, []))<EOL>files = self.manifest_files.get(package, [])[:]<EOL>for pattern in globs:<EOL><INDENT>files.extend(glob(os.path.join(src_dir, convert_path(pattern))))<EOL><DEDENT>return self.exclude_data_files(package, src_dir, files)<EOL>

Return filenames for package's data files in 'src_dir


lastdir = None<EOL>for package, src_dir, build_dir, filenames in self.data_files:<EOL><INDENT>for filename in filenames:<EOL><INDENT>target = os.path.join(build_dir, filename)<EOL>self.mkpath(os.path.dirname(target))<EOL>srcfile = os.path.join(src_dir, filename)<EOL>outf, copied = self.copy_file(srcfile, target)<EOL>srcfile = os.path.abspath(srcfile)<EOL>if copied and srcfile in self.distribution.convert_2to3_doctests:<EOL><INDENT>self.__doctests_2to3.append(outf)<EOL><DEDENT><DEDENT><DEDENT>


def check_package(self, package, package_dir):

try:<EOL><INDENT>return self.packages_checked[package]<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT>init_py = _build_py.check_package(self, package, package_dir)<EOL>self.packages_checked[package] = init_py<EOL>if not init_py or not self.distribution.namespace_packages:<EOL><INDENT>return init_py<EOL><DEDENT>for pkg in self.distribution.namespace_packages:<EOL><INDENT>if pkg==package or pkg.startswith(package+'<STR_LIT:.>'):<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return init_py<EOL><DEDENT>f = open(init_py,'<STR_LIT>')<EOL>if '<STR_LIT>'.encode() not in f.read():<EOL><INDENT>from distutils import log<EOL>log.warn(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>'<STR_LIT>'<EOL>"<STR_LIT>", package<EOL>)<EOL><DEDENT>f.close()<EOL>return init_py<EOL>

Check namespace packages' __init__ for declare_namespace


def exclude_data_files(self, package, src_dir, files):

globs = (self.exclude_package_data.get('<STR_LIT>', [])<EOL>+ self.exclude_package_data.get(package, []))<EOL>bad = []<EOL>for pattern in globs:<EOL><INDENT>bad.extend(<EOL>fnmatch.filter(<EOL>files, os.path.join(src_dir, convert_path(pattern))<EOL>)<EOL>)<EOL><DEDENT>bad = dict.fromkeys(bad)<EOL>seen = {}<EOL>return [<EOL>f for f in files if f not in bad<EOL>and f not in seen and seen.setdefault(f,<NUM_LIT:1>)  <EOL>]<EOL>

Filter filenames for package's data files in 'src_dir


old_inplace, self.inplace = self.inplace, <NUM_LIT:0><EOL>_build_ext.run(self)<EOL>self.inplace = old_inplace<EOL>if old_inplace:<EOL><INDENT>self.copy_extensions_to_source()<EOL><DEDENT>

Build extensions in build directory, then copy if --inplace


<EOL>libnames = dict.fromkeys([lib._full_name for lib in self.shlibs])<EOL>pkg = '<STR_LIT:.>'.join(ext._full_name.split('<STR_LIT:.>')[:-<NUM_LIT:1>]+['<STR_LIT>'])<EOL>for libname in ext.libraries:<EOL><INDENT>if pkg+libname in libnames: return True<EOL><DEDENT>return False<EOL>

Return true if 'ext' links to a dynamic lib in the same package


seen = {}<EOL>for dirname in inputs:<EOL><INDENT>dirname = normalize_path(dirname)<EOL>if dirname in seen:<EOL><INDENT>continue<EOL><DEDENT>seen[dirname] = <NUM_LIT:1><EOL>if not os.path.isdir(dirname):<EOL><INDENT>continue<EOL><DEDENT>files = os.listdir(dirname)<EOL>yield dirname, files<EOL>for name in files:<EOL><INDENT>if not name.endswith('<STR_LIT>'):<EOL><INDENT>continue<EOL><DEDENT>if name in ('<STR_LIT>','<STR_LIT>'):<EOL><INDENT>continue<EOL><DEDENT>f = open(os.path.join(dirname,name))<EOL>lines = list(yield_lines(f))<EOL>f.close()<EOL>for line in lines:<EOL><INDENT>if not line.startswith("<STR_LIT>"):<EOL><INDENT>line = normalize_path(line.rstrip())<EOL>if line not in seen:<EOL><INDENT>seen[line] = <NUM_LIT:1><EOL>if not os.path.isdir(line):<EOL><INDENT>continue<EOL><DEDENT>yield line, os.listdir(line)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>

Yield sys.path directories that might contain "old-style" packages


f = open(dist_filename,'<STR_LIT:rb>')<EOL>try:<EOL><INDENT>endrec = zipfile._EndRecData(f)<EOL>if endrec is None:<EOL><INDENT>return None<EOL><DEDENT>prepended = (endrec[<NUM_LIT:9>] - endrec[<NUM_LIT:5>]) - endrec[<NUM_LIT:6>]<EOL>if prepended < <NUM_LIT:12>:  <EOL><INDENT>return None<EOL><DEDENT>f.seek(prepended-<NUM_LIT:12>)<EOL>import struct, io, configparser<EOL>tag, cfglen, bmlen = struct.unpack("<STR_LIT>",f.read(<NUM_LIT:12>))<EOL>if tag not in (<NUM_LIT>, <NUM_LIT>):<EOL><INDENT>return None     <EOL><DEDENT>f.seek(prepended-(<NUM_LIT:12>+cfglen))<EOL>cfg = configparser.RawConfigParser({'<STR_LIT:version>':'<STR_LIT>','<STR_LIT>':'<STR_LIT>'})<EOL>try:<EOL><INDENT>part = f.read(cfglen)<EOL>if sys.version_info >= (<NUM_LIT:2>,<NUM_LIT:6>):<EOL><INDENT>null_byte = bytes([<NUM_LIT:0>])<EOL><DEDENT>else:<EOL><INDENT>null_byte = chr(<NUM_LIT:0>)<EOL><DEDENT>config = part.split(null_byte, <NUM_LIT:1>)[<NUM_LIT:0>]<EOL>config = config.decode('<STR_LIT:ascii>')<EOL>cfg.readfp(io.StringIO(config))<EOL><DEDENT>except configparser.Error:<EOL><INDENT>return None<EOL><DEDENT>if not cfg.has_section('<STR_LIT>') or not cfg.has_section('<STR_LIT>'):<EOL><INDENT>return None<EOL><DEDENT>return cfg<EOL><DEDENT>finally:<EOL><INDENT>f.close()<EOL><DEDENT>

Extract configuration data from a bdist_wininst .exe

    Returns a ConfigParser.RawConfigParser, or None


prefixes = [<EOL>('<STR_LIT>', '<STR_LIT>'), ('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>]<EOL>z = zipfile.ZipFile(exe_filename)<EOL>try:<EOL><INDENT>for info in z.infolist():<EOL><INDENT>name = info.filename<EOL>parts = name.split('<STR_LIT:/>')<EOL>if len(parts)==<NUM_LIT:3> and parts[<NUM_LIT:2>]=='<STR_LIT>':<EOL><INDENT>if parts[<NUM_LIT:1>].endswith('<STR_LIT>'):<EOL><INDENT>prefixes.insert(<NUM_LIT:0>,('<STR_LIT:/>'.join(parts[:<NUM_LIT:2>]), '<STR_LIT>'))<EOL>break<EOL><DEDENT><DEDENT>if len(parts)!=<NUM_LIT:2> or not name.endswith('<STR_LIT>'):<EOL><INDENT>continue<EOL><DEDENT>if name.endswith('<STR_LIT>'):<EOL><INDENT>continue<EOL><DEDENT>if parts[<NUM_LIT:0>].upper() in ('<STR_LIT>','<STR_LIT>'):<EOL><INDENT>contents = z.read(name)<EOL>if sys.version_info >= (<NUM_LIT:3>,):<EOL><INDENT>contents = contents.decode()<EOL><DEDENT>for pth in yield_lines(contents):<EOL><INDENT>pth = pth.strip().replace('<STR_LIT:\\>','<STR_LIT:/>')<EOL>if not pth.startswith('<STR_LIT>'):<EOL><INDENT>prefixes.append((('<STR_LIT>' % (parts[<NUM_LIT:0>],pth)), '<STR_LIT>'))<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>finally:<EOL><INDENT>z.close()<EOL><DEDENT>prefixes = [(x.lower(),y) for x, y in prefixes]<EOL>prefixes.sort(); prefixes.reverse()<EOL>return prefixes<EOL>

Get exe->egg path translations for a given .exe file


def get_script_header(script_text, executable=sys_executable, wininst=False):

from distutils.command.build_scripts import first_line_re<EOL>if not isinstance(first_line_re.pattern, str):<EOL><INDENT>first_line_re = re.compile(first_line_re.pattern.decode())<EOL><DEDENT>first = (script_text+'<STR_LIT:\n>').splitlines()[<NUM_LIT:0>]<EOL>match = first_line_re.match(first)<EOL>options = '<STR_LIT>'<EOL>if match:<EOL><INDENT>options = match.group(<NUM_LIT:1>) or '<STR_LIT>'<EOL>if options: options = '<STR_LIT:U+0020>'+options<EOL><DEDENT>if wininst:<EOL><INDENT>executable = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>executable = nt_quote_arg(executable)<EOL><DEDENT>hdr = "<STR_LIT>" % locals()<EOL>if not isascii(hdr):<EOL><INDENT>if options:<EOL><INDENT>if options.strip().startswith('<STR_LIT:->'):<EOL><INDENT>options = '<STR_LIT>'+options.strip()[<NUM_LIT:1>:]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>options = '<STR_LIT>'<EOL><DEDENT><DEDENT>executable = fix_jython_executable(executable, options)<EOL>hdr = "<STR_LIT>" % locals()<EOL>return hdr<EOL>

Create a #! line, getting options (if any) from script_text


from zipimport import _zip_directory_cache as zdc<EOL>_uncache(path, zdc)<EOL>_uncache(path, sys.path_importer_cache)<EOL>

Ensure that the importer caches dont have stale info for `path`


try:<EOL><INDENT>compile(text, filename, '<STR_LIT>')<EOL><DEDENT>except (SyntaxError, TypeError):<EOL><INDENT>return False<EOL><DEDENT>else:<EOL><INDENT>return True<EOL><DEDENT>


try:<EOL><INDENT>fp = open(executable)<EOL>magic = fp.read(<NUM_LIT:2>)<EOL>fp.close()<EOL><DEDENT>except (OSError,IOError): return executable<EOL>return magic == '<STR_LIT>'<EOL>

Determine if the specified executable is a .sh (contains a #! line)


result = []<EOL>needquote = False<EOL>nb = <NUM_LIT:0><EOL>needquote = ("<STR_LIT:U+0020>" in arg) or ("<STR_LIT:\t>" in arg)<EOL>if needquote:<EOL><INDENT>result.append('<STR_LIT:">')<EOL><DEDENT>for c in arg:<EOL><INDENT>if c == '<STR_LIT:\\>':<EOL><INDENT>nb += <NUM_LIT:1><EOL><DEDENT>elif c == '<STR_LIT:">':<EOL><INDENT>result.append('<STR_LIT:\\>' * (nb*<NUM_LIT:2>) + '<STR_LIT>')<EOL>nb = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>if nb:<EOL><INDENT>result.append('<STR_LIT:\\>' * nb)<EOL>nb = <NUM_LIT:0><EOL><DEDENT>result.append(c)<EOL><DEDENT><DEDENT>if nb:<EOL><INDENT>result.append('<STR_LIT:\\>' * nb)<EOL><DEDENT>if needquote:<EOL><INDENT>result.append('<STR_LIT:\\>' * nb)    <EOL>result.append('<STR_LIT:">')<EOL><DEDENT>return '<STR_LIT>'.join(result)<EOL>

Quote a command line argument according to Windows parsing rules


if filename.endswith('<STR_LIT>') or filename.endswith('<STR_LIT>'):<EOL><INDENT>return True     <EOL><DEDENT>if is_python(script_text, filename):<EOL><INDENT>return True     <EOL><DEDENT>if script_text.startswith('<STR_LIT>'):<EOL><INDENT>return '<STR_LIT>' in script_text.splitlines()[<NUM_LIT:0>].lower()<EOL><DEDENT>return False    <EOL>

Is this text, as a whole, a Python script? (as opposed to shell/bat/etc.


def get_script_args(dist, executable=sys_executable, wininst=False):

spec = str(dist.as_requirement())<EOL>header = get_script_header("<STR_LIT>", executable, wininst)<EOL>for group in '<STR_LIT>', '<STR_LIT>':<EOL><INDENT>for name, ep in list(dist.get_entry_map(group).items()):<EOL><INDENT>script_text = (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT:\n>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT:\n>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>) % locals()<EOL>if sys.platform=='<STR_LIT:win32>' or wininst:<EOL><INDENT>if group=='<STR_LIT>':<EOL><INDENT>ext, launcher = '<STR_LIT>', '<STR_LIT>'<EOL>old = ['<STR_LIT>']<EOL>new_header = re.sub('<STR_LIT>','<STR_LIT>',header)<EOL><DEDENT>else:<EOL><INDENT>ext, launcher = '<STR_LIT>', '<STR_LIT>'<EOL>old = ['<STR_LIT>','<STR_LIT>','<STR_LIT>']<EOL>new_header = re.sub('<STR_LIT>','<STR_LIT>',header)<EOL><DEDENT>if is_64bit():<EOL><INDENT>launcher = launcher.replace("<STR_LIT:.>", "<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>launcher = launcher.replace("<STR_LIT:.>", "<STR_LIT>")<EOL><DEDENT>if os.path.exists(new_header[<NUM_LIT:2>:-<NUM_LIT:1>]) or sys.platform!='<STR_LIT:win32>':<EOL><INDENT>hdr = new_header<EOL><DEDENT>else:<EOL><INDENT>hdr = header<EOL><DEDENT>yield (name+ext, hdr+script_text, '<STR_LIT:t>', [name+x for x in old])<EOL>yield (<EOL>name+'<STR_LIT>', resource_string('<STR_LIT>', launcher),<EOL>'<STR_LIT:b>' <EOL>)<EOL><DEDENT>else:<EOL><INDENT>yield (name, header+script_text)<EOL><DEDENT><DEDENT><DEDENT>

Yield write_script() argument tuples for a distribution's entrypoints


def rmtree(path, ignore_errors=False, onerror=auto_chmod):

if ignore_errors:<EOL><INDENT>def onerror(*args):<EOL><INDENT>pass<EOL><DEDENT><DEDENT>elif onerror is None:<EOL><INDENT>def onerror(*args):<EOL><INDENT>raise<EOL><DEDENT><DEDENT>names = []<EOL>try:<EOL><INDENT>names = os.listdir(path)<EOL><DEDENT>except os.error as err:<EOL><INDENT>onerror(os.listdir, path, sys.exc_info())<EOL><DEDENT>for name in names:<EOL><INDENT>fullname = os.path.join(path, name)<EOL>try:<EOL><INDENT>mode = os.lstat(fullname).st_mode<EOL><DEDENT>except os.error:<EOL><INDENT>mode = <NUM_LIT:0><EOL><DEDENT>if stat.S_ISDIR(mode):<EOL><INDENT>rmtree(fullname, ignore_errors, onerror)<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>os.remove(fullname)<EOL><DEDENT>except os.error as err:<EOL><INDENT>onerror(os.remove, fullname, sys.exc_info())<EOL><DEDENT><DEDENT><DEDENT>try:<EOL><INDENT>os.rmdir(path)<EOL><DEDENT>except os.error:<EOL><INDENT>onerror(os.rmdir, path, sys.exc_info())<EOL><DEDENT>

Recursively delete a directory tree.

    This code is taken from the Python 2.4 version of 'shutil', because
    the 2.3 version doesn't really work right.


self._expand_attrs(['<STR_LIT>', '<STR_LIT>', '<STR_LIT:root>'])<EOL>

Calls `os.path.expanduser` on install_base, install_platbase and
        root.


self._expand_attrs(['<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>',])<EOL>

Calls `os.path.expanduser` on install dirs.


try:<EOL><INDENT>pid = os.getpid()<EOL><DEDENT>except:<EOL><INDENT>pid = random.randint(<NUM_LIT:0>,sys.maxsize)<EOL><DEDENT>return os.path.join(self.install_dir, "<STR_LIT>" % pid)<EOL>

Return a pseudo-tempname base in the install directory.
        This code is intentionally naive; if a malicious party can write to
        the target directory you're already in deep doodoo.


instdir = normalize_path(self.install_dir)<EOL>pth_file = os.path.join(instdir,'<STR_LIT>')<EOL>is_site_dir = instdir in self.all_site_dirs<EOL>if not is_site_dir:<EOL><INDENT>is_site_dir = self.check_pth_processing()<EOL><DEDENT>else:<EOL><INDENT>testfile = self.pseudo_tempname()+'<STR_LIT>'<EOL>test_exists = os.path.exists(testfile)<EOL>try:<EOL><INDENT>if test_exists: os.unlink(testfile)<EOL>open(testfile,'<STR_LIT:w>').close()<EOL>os.unlink(testfile)<EOL><DEDENT>except (OSError,IOError):<EOL><INDENT>self.cant_write_to_target()<EOL><DEDENT><DEDENT>if not is_site_dir and not self.multi_version:<EOL><INDENT>raise DistutilsError(self.no_default_version_msg())<EOL><DEDENT>if is_site_dir:<EOL><INDENT>if self.pth_file is None:<EOL><INDENT>self.pth_file = PthDistributions(pth_file, self.all_site_dirs)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self.pth_file = None<EOL><DEDENT>PYTHONPATH = os.environ.get('<STR_LIT>','<STR_LIT>').split(os.pathsep)<EOL>if instdir not in list(map(normalize_path, [_f for _f in PYTHONPATH if _f])):<EOL><INDENT>self.sitepy_installed = True<EOL><DEDENT>elif self.multi_version and not os.path.exists(pth_file):<EOL><INDENT>self.sitepy_installed = True    <EOL>self.pth_file = None            <EOL><DEDENT>self.install_dir = instdir<EOL>

Verify that self.install_dir is .pth-capable dir, if needed


instdir = self.install_dir<EOL>log.info("<STR_LIT>", instdir)<EOL>pth_file = self.pseudo_tempname()+"<STR_LIT>"<EOL>ok_file = pth_file+'<STR_LIT>'<EOL>ok_exists = os.path.exists(ok_file)<EOL>try:<EOL><INDENT>if ok_exists: os.unlink(ok_file)<EOL>dirname = os.path.dirname(ok_file)<EOL>if not os.path.exists(dirname):<EOL><INDENT>os.makedirs(dirname)<EOL><DEDENT>f = open(pth_file,'<STR_LIT:w>')<EOL><DEDENT>except (OSError,IOError):<EOL><INDENT>self.cant_write_to_target()<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>f.write("<STR_LIT>" % (ok_file,))<EOL>f.close(); f=None<EOL>executable = sys.executable<EOL>if os.name=='<STR_LIT>':<EOL><INDENT>dirname,basename = os.path.split(executable)<EOL>alt = os.path.join(dirname,'<STR_LIT>')<EOL>if basename.lower()=='<STR_LIT>' and os.path.exists(alt):<EOL><INDENT>executable = alt<EOL><DEDENT><DEDENT>from distutils.spawn import spawn<EOL>spawn([executable,'<STR_LIT>','<STR_LIT:-c>','<STR_LIT>'],<NUM_LIT:0>)<EOL>if os.path.exists(ok_file):<EOL><INDENT>log.info(<EOL>"<STR_LIT>",<EOL>instdir<EOL>)<EOL>return True<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>if f: f.close()<EOL>if os.path.exists(ok_file): os.unlink(ok_file)<EOL>if os.path.exists(pth_file): os.unlink(pth_file)<EOL><DEDENT><DEDENT>if not self.multi_version:<EOL><INDENT>log.warn("<STR_LIT>", instdir)<EOL><DEDENT>return False<EOL>

Empirically verify whether .pth files are supported in inst. dir


if not self.exclude_scripts and dist.metadata_isdir('<STR_LIT>'):<EOL><INDENT>for script_name in dist.metadata_listdir('<STR_LIT>'):<EOL><INDENT>self.install_script(<EOL>dist, script_name,<EOL>dist.get_metadata('<STR_LIT>'+script_name)<EOL>)<EOL><DEDENT><DEDENT>self.install_wrapper_scripts(dist)<EOL>

Write all the scripts for `dist`, unless scripts are excluded


<EOL>scheme = INSTALL_SCHEMES[name]<EOL>for key in SCHEME_KEYS:<EOL><INDENT>attrname = '<STR_LIT>' + key<EOL>if getattr(self, attrname) is None:<EOL><INDENT>setattr(self, attrname, scheme[key])<EOL><DEDENT><DEDENT>

Sets the install directories by applying the install schemes.


def install_script(self, dist, script_name, script_text, dev_path=None):

spec = str(dist.as_requirement())<EOL>is_script = is_python_script(script_text, script_name)<EOL>def get_template(filename):<EOL><INDENT>"""<STR_LIT>"""<EOL>raw_bytes = resource_string('<STR_LIT>', template_name)<EOL>template_str = raw_bytes.decode('<STR_LIT:utf-8>')<EOL>clean_template = template_str.replace('<STR_LIT>', '<STR_LIT>')<EOL>return clean_template<EOL><DEDENT>if is_script:<EOL><INDENT>template_name = '<STR_LIT>'<EOL>if dev_path:<EOL><INDENT>template_name = template_name.replace('<STR_LIT>', '<STR_LIT>')<EOL><DEDENT>script_text = (get_script_header(script_text) +<EOL>get_template(template_name) % locals())<EOL><DEDENT>self.write_script(script_name, _to_ascii(script_text), '<STR_LIT:b>')<EOL>

Generate a legacy script wrapper and install it


def write_script(self, script_name, contents, mode="<STR_LIT:t>", blockers=()):

self.delete_blockers(   <EOL>[os.path.join(self.script_dir,x) for x in blockers])<EOL>log.info("<STR_LIT>", script_name, self.script_dir)<EOL>target = os.path.join(self.script_dir, script_name)<EOL>self.add_output(target)<EOL>mask = current_umask()<EOL>if not self.dry_run:<EOL><INDENT>ensure_directory(target)<EOL>f = open(target,"<STR_LIT:w>"+mode)<EOL>f.write(contents)<EOL>f.close()<EOL>chmod(target, <NUM_LIT>-mask)<EOL><DEDENT>

Write an executable file to the scripts directory


def exe_to_egg(self, dist_filename, egg_tmp):

<EOL>prefixes = get_exe_prefixes(dist_filename)<EOL>to_compile = []<EOL>native_libs = []<EOL>top_level = {}<EOL>def process(src,dst):<EOL><INDENT>s = src.lower()<EOL>for old,new in prefixes:<EOL><INDENT>if s.startswith(old):<EOL><INDENT>src = new+src[len(old):]<EOL>parts = src.split('<STR_LIT:/>')<EOL>dst = os.path.join(egg_tmp, *parts)<EOL>dl = dst.lower()<EOL>if dl.endswith('<STR_LIT>') or dl.endswith('<STR_LIT>'):<EOL><INDENT>parts[-<NUM_LIT:1>] = bdist_egg.strip_module(parts[-<NUM_LIT:1>])<EOL>top_level[os.path.splitext(parts[<NUM_LIT:0>])[<NUM_LIT:0>]] = <NUM_LIT:1><EOL>native_libs.append(src)<EOL><DEDENT>elif dl.endswith('<STR_LIT>') and old!='<STR_LIT>':<EOL><INDENT>top_level[os.path.splitext(parts[<NUM_LIT:0>])[<NUM_LIT:0>]] = <NUM_LIT:1><EOL>to_compile.append(dst)<EOL><DEDENT>return dst<EOL><DEDENT><DEDENT>if not src.endswith('<STR_LIT>'):<EOL><INDENT>log.warn("<STR_LIT>", src)<EOL><DEDENT>return None<EOL><DEDENT>unpack_archive(dist_filename, egg_tmp, process)<EOL>stubs = []<EOL>for res in native_libs:<EOL><INDENT>if res.lower().endswith('<STR_LIT>'):    <EOL><INDENT>parts = res.split('<STR_LIT:/>')<EOL>resource = parts[-<NUM_LIT:1>]<EOL>parts[-<NUM_LIT:1>] = bdist_egg.strip_module(parts[-<NUM_LIT:1>])+'<STR_LIT>'<EOL>pyfile = os.path.join(egg_tmp, *parts)<EOL>to_compile.append(pyfile); stubs.append(pyfile)<EOL>bdist_egg.write_stub(resource, pyfile)<EOL><DEDENT><DEDENT>self.byte_compile(to_compile)   <EOL>bdist_egg.write_safety_flag(os.path.join(egg_tmp,'<STR_LIT>'),<EOL>bdist_egg.analyze_egg(egg_tmp, stubs))  <EOL>for name in '<STR_LIT>','<STR_LIT>':<EOL><INDENT>if locals()[name]:<EOL><INDENT>txt = os.path.join(egg_tmp, '<STR_LIT>', name+'<STR_LIT>')<EOL>if not os.path.exists(txt):<EOL><INDENT>f = open(txt,'<STR_LIT:w>')<EOL>f.write('<STR_LIT:\n>'.join(locals()[name])+'<STR_LIT:\n>')<EOL>f.close()<EOL><DEDENT><DEDENT><DEDENT>

Extract a bdist_wininst to the directories an egg would use


return dist     <EOL>from imp import find_module, get_suffixes<EOL>from glob import glob<EOL>blockers = []<EOL>names = dict.fromkeys(dist._get_metadata('<STR_LIT>')) <EOL>exts = {'<STR_LIT>':<NUM_LIT:1>, '<STR_LIT>':<NUM_LIT:1>}     <EOL>for ext,mode,typ in get_suffixes():<EOL><INDENT>exts[ext] = <NUM_LIT:1><EOL><DEDENT>for path,files in expand_paths([self.install_dir]+self.all_site_dirs):<EOL><INDENT>for filename in files:<EOL><INDENT>base,ext = os.path.splitext(filename)<EOL>if base in names:<EOL><INDENT>if not ext:<EOL><INDENT>try:<EOL><INDENT>f, filename, descr = find_module(base, [path])<EOL><DEDENT>except ImportError:<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>if f: f.close()<EOL>if filename not in blockers:<EOL><INDENT>blockers.append(filename)<EOL><DEDENT><DEDENT><DEDENT>elif ext in exts and base!='<STR_LIT>':  <EOL><INDENT>blockers.append(os.path.join(path,filename))<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if blockers:<EOL><INDENT>self.found_conflicts(dist, blockers)<EOL><DEDENT>return dist<EOL>

Verify that there are no conflicting "old-style" packages


def installation_report(self, req, dist, what="<STR_LIT>"):

msg = "<STR_LIT>"<EOL>if self.multi_version and not self.no_report:<EOL><INDENT>msg += """<STR_LIT>"""<EOL><DEDENT>o that the installation directory must be on sys.path at runtime for<EOL>work.  (e.g. by being the application's script directory, by being on<EOL>TH, or by being added to sys.path by your code.)<EOL>eggloc = dist.location<EOL>name = dist.project_name<EOL>version = dist.version<EOL>extras = '<STR_LIT>' <EOL>return msg % locals()<EOL>

Helpful installation message for display to package users


<EOL>ei_opts = self.distribution.get_option_dict('<STR_LIT>').copy()<EOL>fetch_directives = (<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>',<EOL>)<EOL>fetch_options = {}<EOL>for key, val in ei_opts.items():<EOL><INDENT>if key not in fetch_directives: continue<EOL>fetch_options[key.replace('<STR_LIT:_>', '<STR_LIT:->')] = val[<NUM_LIT:1>]<EOL><DEDENT>settings = dict(easy_install=fetch_options)<EOL>cfg_filename = os.path.join(base, '<STR_LIT>')<EOL>setopt.edit_config(cfg_filename, settings)<EOL>

When easy_install is about to run bdist_egg on a source dist, that
source dist might have 'setup_requires' directives, requiring
additional fetching. Ensure the fetcher options given to easy_install
are available to that command as well.


if self.sitepy_installed:<EOL><INDENT>return  <EOL><DEDENT>sitepy = os.path.join(self.install_dir, "<STR_LIT>")<EOL>source = resource_string(Requirement.parse("<STR_LIT>"), "<STR_LIT>")<EOL>current = "<STR_LIT>"<EOL>if os.path.exists(sitepy):<EOL><INDENT>log.debug("<STR_LIT>", self.install_dir)<EOL>f = open(sitepy,'<STR_LIT:rb>')<EOL>current = f.read()<EOL>if sys.version_info >= (<NUM_LIT:3>,):<EOL><INDENT>current = current.decode()<EOL><DEDENT>f.close()<EOL>if not current.startswith('<STR_LIT>'):<EOL><INDENT>raise DistutilsError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % sitepy<EOL>)<EOL><DEDENT><DEDENT>if current != source:<EOL><INDENT>log.info("<STR_LIT>", sitepy)<EOL>if not self.dry_run:<EOL><INDENT>ensure_directory(sitepy)<EOL>f = open(sitepy,'<STR_LIT:wb>')<EOL>f.write(source)<EOL>f.close()<EOL><DEDENT>self.byte_compile([sitepy])<EOL><DEDENT>self.sitepy_installed = True<EOL>

Make sure there's a site.py in the target dir, if needed


if not self.user:<EOL><INDENT>return<EOL><DEDENT>home = convert_path(os.path.expanduser("<STR_LIT>"))<EOL>for name, path in self.config_vars.items():<EOL><INDENT>if path.startswith(home) and not os.path.isdir(path):<EOL><INDENT>self.debug_print("<STR_LIT>" % path)<EOL>os.makedirs(path, <NUM_LIT>)<EOL><DEDENT><DEDENT>


if not self.dirty:<EOL><INDENT>return<EOL><DEDENT>data = '<STR_LIT:\n>'.join(map(self.make_relative,self.paths))<EOL>if data:<EOL><INDENT>log.debug("<STR_LIT>", self.filename)<EOL>data = (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>) % data<EOL>if os.path.islink(self.filename):<EOL><INDENT>os.unlink(self.filename)<EOL><DEDENT>f = open(self.filename,'<STR_LIT>')<EOL>f.write(data); f.close()<EOL><DEDENT>elif os.path.exists(self.filename):<EOL><INDENT>log.debug("<STR_LIT>", self.filename)<EOL>os.unlink(self.filename)<EOL><DEDENT>self.dirty = False<EOL>


if (dist.location not in self.paths and (<EOL>dist.location not in self.sitedirs or<EOL>dist.location == os.getcwd() <EOL>)):<EOL><INDENT>self.paths.append(dist.location)<EOL>self.dirty = True<EOL><DEDENT>Environment.add(self,dist)<EOL>


while dist.location in self.paths:<EOL><INDENT>self.paths.remove(dist.location); self.dirty = True<EOL><DEDENT>Environment.remove(self,dist)<EOL>


for ep in pkg_resources.iter_entry_points('<STR_LIT>'):<EOL><INDENT>for item in ep.load()(dirname):<EOL><INDENT>yield item<EOL><DEDENT><DEDENT>


found = False<EOL>f = open(filename,'<STR_LIT>')<EOL>for line in iter(f.readline, '<STR_LIT>'):    <EOL><INDENT>parts = line.split()<EOL>if len(parts)==<NUM_LIT:2>:<EOL><INDENT>kind,length = parts<EOL>data = f.read(int(length))<EOL>if kind=='<STR_LIT>' and data=='<STR_LIT>':<EOL><INDENT>found = True<EOL><DEDENT>elif kind=='<STR_LIT>' and found:<EOL><INDENT>f.close()<EOL>break<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>f.close()<EOL>return<EOL><DEDENT>for line in data.splitlines():<EOL><INDENT>parts = line.split()<EOL>if parts:<EOL><INDENT>yield joinpath(dirname, parts[<NUM_LIT:0>])<EOL><DEDENT><DEDENT>


log.info("<STR_LIT>", self.manifest)<EOL>manifest = open(self.manifest, '<STR_LIT>')<EOL>for line in manifest:<EOL><INDENT>if sys.version_info >= (<NUM_LIT:3>,):<EOL><INDENT>try:<EOL><INDENT>line = line.decode('<STR_LIT>')<EOL><DEDENT>except UnicodeDecodeError:<EOL><INDENT>log.warn("<STR_LIT>" % line)<EOL>continue<EOL><DEDENT><DEDENT>line = line.strip()<EOL>if line.startswith('<STR_LIT:#>') or not line:<EOL><INDENT>continue<EOL><DEDENT>self.filelist.append(line)<EOL><DEDENT>manifest.close()<EOL>

Read the manifest file (named by 'self.manifest') and use it to
        fill in 'self.filelist', the list of files to include in the source
        distribution.


walker = os.walk(egg_dir)<EOL>base,dirs,files = next(walker)<EOL>if '<STR_LIT>' in dirs:<EOL><INDENT>dirs.remove('<STR_LIT>')<EOL><DEDENT>yield base,dirs,files<EOL>for bdf in walker:<EOL><INDENT>yield bdf<EOL><DEDENT>

Walk an unpacked egg's contents, skipping the metadata directory


def scan_module(egg_dir, base, name, stubs):

filename = os.path.join(base,name)<EOL>if filename[:-<NUM_LIT:1>] in stubs:<EOL><INDENT>return True     <EOL><DEDENT>pkg = base[len(egg_dir)+<NUM_LIT:1>:].replace(os.sep,'<STR_LIT:.>')<EOL>module = pkg+(pkg and '<STR_LIT:.>' or '<STR_LIT>')+os.path.splitext(name)[<NUM_LIT:0>]<EOL>if sys.version_info < (<NUM_LIT:3>, <NUM_LIT:3>):<EOL><INDENT>skip = <NUM_LIT:8>   <EOL><DEDENT>else:<EOL><INDENT>skip = <NUM_LIT:12>  <EOL><DEDENT>f = open(filename,'<STR_LIT:rb>'); f.read(skip)<EOL>code = marshal.load(f); f.close()<EOL>safe = True<EOL>symbols = dict.fromkeys(iter_symbols(code))<EOL>for bad in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>if bad in symbols:<EOL><INDENT>log.warn("<STR_LIT>", module, bad)<EOL>safe = False<EOL><DEDENT><DEDENT>if '<STR_LIT>' in symbols:<EOL><INDENT>for bad in [<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'<EOL>]:<EOL><INDENT>if bad in symbols:<EOL><INDENT>log.warn("<STR_LIT>", module, bad)<EOL>safe = False<EOL><DEDENT><DEDENT><DEDENT>if '<STR_LIT>' in symbols and '<STR_LIT:__main__>' in symbols and '<STR_LIT:.>' not in module:<EOL><INDENT>if sys.version[:<NUM_LIT:3>]=="<STR_LIT>":  <EOL><INDENT>log.warn("<STR_LIT>", module)<EOL>safe = False<EOL><DEDENT><DEDENT>return safe<EOL>

Check whether module possibly uses unsafe-for-zipfile stuff


for name in code.co_names: yield name<EOL>for const in code.co_consts:<EOL><INDENT>if isinstance(const,str):<EOL><INDENT>yield const<EOL><DEDENT>elif isinstance(const,CodeType):<EOL><INDENT>for name in iter_symbols(const):<EOL><INDENT>yield name<EOL><DEDENT><DEDENT><DEDENT>

Yield names and strings used by `code` and its nested code objects


def make_zipfile(zip_filename, base_dir, verbose=<NUM_LIT:0>, dry_run=<NUM_LIT:0>, compress=None,<EOL>mode='<STR_LIT:w>'<EOL>):

import zipfile<EOL>mkpath(os.path.dirname(zip_filename), dry_run=dry_run)<EOL>log.info("<STR_LIT>", zip_filename, base_dir)<EOL>def visit(z, dirname, names):<EOL><INDENT>for name in names:<EOL><INDENT>path = os.path.normpath(os.path.join(dirname, name))<EOL>if os.path.isfile(path):<EOL><INDENT>p = path[len(base_dir)+<NUM_LIT:1>:]<EOL>if not dry_run:<EOL><INDENT>z.write(path, p)<EOL><DEDENT>log.debug("<STR_LIT>" % p)<EOL><DEDENT><DEDENT><DEDENT>if compress is None:<EOL><INDENT>compress = (sys.version>="<STR_LIT>") <EOL><DEDENT>compression = [zipfile.ZIP_STORED, zipfile.ZIP_DEFLATED][bool(compress)]<EOL>if not dry_run:<EOL><INDENT>z = zipfile.ZipFile(zip_filename, mode, compression=compression)<EOL>for dirname, dirs, files in os.walk(base_dir):<EOL><INDENT>visit(z, dirname, files)<EOL><DEDENT>z.close()<EOL><DEDENT>else:<EOL><INDENT>for dirname, dirs, files in os.walk(base_dir):<EOL><INDENT>visit(None, dirname, files)<EOL><DEDENT><DEDENT>return zip_filename<EOL>

Create a zip file from all the files under 'base_dir'.  The output
    zip file will be named 'base_dir' + ".zip".  Uses either the "zipfile"
    Python module (if available) or the InfoZIP "zip" utility (if installed
    and found on the default search path).  If neither tool is available,
    raises DistutilsExecError.  Returns the name of the output zip file.


for dirname in INSTALL_DIRECTORY_ATTRS:<EOL><INDENT>kw.setdefault(dirname,self.bdist_dir)<EOL><DEDENT>kw.setdefault('<STR_LIT>',self.skip_build)<EOL>kw.setdefault('<STR_LIT>', self.dry_run)<EOL>cmd = self.reinitialize_command(cmdname, **kw)<EOL>self.run_command(cmdname)<EOL>return cmd<EOL>

Invoke reinitialized command `cmdname` with keyword args


init_files = []<EOL>for base,dirs,files in walk_egg(self.bdist_dir):<EOL><INDENT>if base==self.bdist_dir:<EOL><INDENT>continue<EOL><DEDENT>for name in files:<EOL><INDENT>if name.endswith('<STR_LIT>'):<EOL><INDENT>if '<STR_LIT>' not in files:<EOL><INDENT>pkg = base[len(self.bdist_dir)+<NUM_LIT:1>:].replace(os.sep,'<STR_LIT:.>')<EOL>if self.distribution.has_contents_for(pkg):<EOL><INDENT>log.warn("<STR_LIT>",pkg)<EOL>filename = os.path.join(base,'<STR_LIT>')<EOL>if not self.dry_run:<EOL><INDENT>f = open(filename,'<STR_LIT:w>'); f.write(NS_PKG_STUB)<EOL>f.close()<EOL><DEDENT>init_files.append(filename)<EOL><DEDENT><DEDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>dirs[:] = []<EOL><DEDENT><DEDENT>return init_files<EOL>


<EOL>norm_egg_info = os.path.normpath(self.egg_info)<EOL>prefix = os.path.join(norm_egg_info,'<STR_LIT>')<EOL>for path in self.ei_cmd.filelist.files:<EOL><INDENT>if path.startswith(prefix):<EOL><INDENT>target = os.path.join(target_dir, path[len(prefix):])<EOL>ensure_directory(target)<EOL>self.copy_file(path, target)<EOL><DEDENT><DEDENT>

Copy metadata (egg info) to the target_dir


all_outputs = []<EOL>ext_outputs = []<EOL>paths = {self.bdist_dir:'<STR_LIT>'}<EOL>for base, dirs, files in os.walk(self.bdist_dir):<EOL><INDENT>for filename in files:<EOL><INDENT>if os.path.splitext(filename)[<NUM_LIT:1>].lower() in NATIVE_EXTENSIONS:<EOL><INDENT>all_outputs.append(paths[base]+filename)<EOL><DEDENT><DEDENT>for filename in dirs:<EOL><INDENT>paths[os.path.join(base,filename)] = paths[base]+filename+'<STR_LIT:/>'<EOL><DEDENT><DEDENT>if self.distribution.has_ext_modules():<EOL><INDENT>build_cmd = self.get_finalized_command('<STR_LIT>')<EOL>for ext in build_cmd.extensions:<EOL><INDENT>if isinstance(ext,Library):<EOL><INDENT>continue<EOL><DEDENT>fullname = build_cmd.get_ext_fullname(ext.name)<EOL>filename = build_cmd.get_ext_filename(fullname)<EOL>if not os.path.basename(filename).startswith('<STR_LIT>'):<EOL><INDENT>if os.path.exists(os.path.join(self.bdist_dir,filename)):<EOL><INDENT>ext_outputs.append(filename)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return all_outputs, ext_outputs<EOL>

Get a list of relative paths to C extensions in the output distro


def write_script(self, script_name, contents, mode="<STR_LIT:t>", *ignored):

from setuptools.command.easy_install import chmod, current_umask<EOL>log.info("<STR_LIT>", script_name, self.install_dir)<EOL>target = os.path.join(self.install_dir, script_name)<EOL>self.outfiles.append(target)<EOL>mask = current_umask()<EOL>if not self.dry_run:<EOL><INDENT>ensure_directory(target)<EOL>f = open(target,"<STR_LIT:w>"+mode)<EOL>f.write(contents)<EOL>f.close()<EOL>chmod(target, <NUM_LIT>-mask)<EOL><DEDENT>


tests = []<EOL>if module.__name__!='<STR_LIT>':  <EOL><INDENT>tests.append(TestLoader.loadTestsFromModule(self,module))<EOL><DEDENT>if hasattr(module, "<STR_LIT>"):<EOL><INDENT>tests.append(module.additional_tests())<EOL><DEDENT>if hasattr(module, '<STR_LIT>'):<EOL><INDENT>for file in resource_listdir(module.__name__, '<STR_LIT>'):<EOL><INDENT>if file.endswith('<STR_LIT>') and file!='<STR_LIT>':<EOL><INDENT>submodule = module.__name__+'<STR_LIT:.>'+file[:-<NUM_LIT:3>]<EOL><DEDENT>else:<EOL><INDENT>if resource_exists(<EOL>module.__name__, file+'<STR_LIT>'<EOL>):<EOL><INDENT>submodule = module.__name__+'<STR_LIT:.>'+file<EOL><DEDENT>else:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>tests.append(self.loadTestsFromName(submodule))<EOL><DEDENT><DEDENT>if len(tests)!=<NUM_LIT:1>:<EOL><INDENT>return self.suiteClass(tests)<EOL><DEDENT>else:<EOL><INDENT>return tests[<NUM_LIT:0>]<EOL><DEDENT>

Return a suite of all tests cases contained in the given module

        If the module is a package, load tests from all the modules in it.
        If the module has an ``additional_tests`` function, call it and add
        the return value to the tests.


contents = "<STR_LIT:\n>".join(contents)<EOL>if sys.version_info >= (<NUM_LIT:3>,):<EOL><INDENT>contents = contents.encode("<STR_LIT:utf-8>")<EOL><DEDENT>f = open(filename, "<STR_LIT:wb>")        <EOL>f.write(contents)<EOL>f.close()<EOL>

Create a file with the specified name and write 'contents' (a
    sequence of strings without line terminators) to it.


def write_or_delete_file(self, what, filename, data, force=False):

if data:<EOL><INDENT>self.write_file(what, filename, data)<EOL><DEDENT>elif os.path.exists(filename):<EOL><INDENT>if data is None and not force:<EOL><INDENT>log.warn(<EOL>"<STR_LIT>", what, filename<EOL>)<EOL>return<EOL><DEDENT>else:<EOL><INDENT>self.delete_file(filename)<EOL><DEDENT><DEDENT>

Write `data` to `filename` or delete if empty

        If `data` is non-empty, this routine is the same as ``write_file()``.
        If `data` is empty but not ``None``, this is the same as calling
        ``delete_file(filename)`.  If `data` is ``None``, then this is a no-op
        unless `filename` exists, in which case a warning is issued about the
        orphaned file (if `force` is false), or deleted (if `force` is true).


def write_file(self, what, filename, data):

log.info("<STR_LIT>", what, filename)<EOL>if sys.version_info >= (<NUM_LIT:3>,):<EOL><INDENT>data = data.encode("<STR_LIT:utf-8>")<EOL><DEDENT>if not self.dry_run:<EOL><INDENT>f = open(filename, '<STR_LIT:wb>')<EOL>f.write(data)<EOL>f.close()<EOL><DEDENT>

Write `data` to `filename` (if not a dry run) after announcing it

        `what` is used in a log message to identify what is being written
        to the file.


log.info("<STR_LIT>", filename)<EOL>if not self.dry_run:<EOL><INDENT>os.unlink(filename)<EOL><DEDENT>

Delete `filename` (if not a dry run) after announcing it


manifest_filename = os.path.join(self.egg_info,"<STR_LIT>")<EOL>mm = manifest_maker(self.distribution)<EOL>mm.manifest = manifest_filename<EOL>mm.run()<EOL>self.filelist = mm.filelist<EOL>


<EOL>if sys.version_info >= (<NUM_LIT:3>,):<EOL><INDENT>files = []<EOL>for file in self.filelist.files:<EOL><INDENT>try:<EOL><INDENT>file.encode("<STR_LIT:utf-8>")<EOL><DEDENT>except UnicodeEncodeError:<EOL><INDENT>log.warn("<STR_LIT>" % file)<EOL><DEDENT>else:<EOL><INDENT>files.append(file)<EOL><DEDENT><DEDENT>self.filelist.files = files<EOL><DEDENT>files = self.filelist.files<EOL>if os.sep!='<STR_LIT:/>':<EOL><INDENT>files = [f.replace(os.sep,'<STR_LIT:/>') for f in files]<EOL><DEDENT>self.execute(write_file, (self.manifest, files),<EOL>"<STR_LIT>" % self.manifest)<EOL>

Write the file list in 'self.filelist' (presumably as filled in
        by 'add_defaults()' and 'read_template()') to the manifest file
        named by 'self.manifest'.


for c in '<STR_LIT:">', "<STR_LIT:'>", "<STR_LIT:\\>", "<STR_LIT:#>":<EOL><INDENT>if c in arg: return repr(arg)<EOL><DEDENT>if arg.split()!=[arg]:<EOL><INDENT>return repr(arg)<EOL><DEDENT>return arg<EOL>

Quote an argument for later parsing by shlex.split()


if kind=='<STR_LIT>':<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>if kind=='<STR_LIT>':<EOL><INDENT>return os.path.join(<EOL>os.path.dirname(distutils.__file__),'<STR_LIT>'<EOL>)<EOL><DEDENT>if kind=='<STR_LIT:user>':<EOL><INDENT>dot = os.name=='<STR_LIT>' and '<STR_LIT:.>' or '<STR_LIT>'<EOL>return os.path.expanduser(convert_path("<STR_LIT>" % dot))<EOL><DEDENT>raise ValueError(<EOL>"<STR_LIT>", kind<EOL>)<EOL>

Get the filename of the distutils, local, global, or per-user config

    `kind` must be one of "local", "global", or "user"


def edit_config(filename, settings, dry_run=False):

from ConfigParser import RawConfigParser<EOL>log.debug("<STR_LIT>", filename)<EOL>opts = RawConfigParser()<EOL>opts.read([filename])<EOL>for section, options in settings.items():<EOL><INDENT>if options is None:<EOL><INDENT>log.info("<STR_LIT>", section, filename)<EOL>opts.remove_section(section)<EOL><DEDENT>else:<EOL><INDENT>if not opts.has_section(section):<EOL><INDENT>log.debug("<STR_LIT>", section, filename)<EOL>opts.add_section(section)<EOL><DEDENT>for option,value in options.items():<EOL><INDENT>if value is None:<EOL><INDENT>log.debug("<STR_LIT>",<EOL>section, option, filename<EOL>)<EOL>opts.remove_option(section,option)<EOL>if not opts.options(section):<EOL><INDENT>log.info("<STR_LIT>",<EOL>section, filename)<EOL>opts.remove_section(section)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>log.debug(<EOL>"<STR_LIT>",<EOL>section, option, value, filename<EOL>)<EOL>opts.set(section,option,value)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>log.info("<STR_LIT>", filename)<EOL>if not dry_run:<EOL><INDENT>f = open(filename,'<STR_LIT:w>'); opts.write(f); f.close()<EOL><DEDENT>

Edit a configuration file to include `settings`

    `settings` is a dictionary of dictionaries or ``None`` values, keyed by
    command/section name.  A ``None`` value means to delete the entire section,
    while a dictionary lists settings to be changed or deleted in that section.
    A setting of ``None`` means to delete that setting.


out = []<EOL>stack=[(convert_path(where), '<STR_LIT>')]<EOL>while stack:<EOL><INDENT>where,prefix = stack.pop(<NUM_LIT:0>)<EOL>for name in os.listdir(where):<EOL><INDENT>fn = os.path.join(where,name)<EOL>if ('<STR_LIT:.>' not in name and os.path.isdir(fn) and<EOL>os.path.isfile(os.path.join(fn,'<STR_LIT>'))<EOL>):<EOL><INDENT>out.append(prefix+name); stack.append((fn,prefix+name+'<STR_LIT:.>'))<EOL><DEDENT><DEDENT><DEDENT>for pat in list(exclude)+['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>from fnmatch import fnmatchcase<EOL>out = [item for item in out if not fnmatchcase(item,pat)]<EOL><DEDENT>return out<EOL>

Return a list all Python packages found within directory 'where'

    'where' should be supplied as a "cross-platform" (i.e. URL-style) path; it
    will be converted to the appropriate local path syntax.  'exclude' is a
    sequence of package names to exclude; '*' can be used as a wildcard in the
    names, such that 'foo.*' will exclude all subpackages of 'foo' (but not
    'foo' itself).


all_files = []<EOL>for base, dirs, files in os.walk(dir):<EOL><INDENT>if base==os.curdir or base.startswith(os.curdir+os.sep):<EOL><INDENT>base = base[<NUM_LIT:2>:]<EOL><DEDENT>if base:<EOL><INDENT>files = [os.path.join(base, f) for f in files]<EOL><DEDENT>all_files.extend(filter(os.path.isfile, files))<EOL><DEDENT>return all_files<EOL>

Find all files under 'dir' and return the list of full filenames
    (relative to 'dir').


old_dir = os.getcwd()<EOL>save_argv = sys.argv[:]<EOL>save_path = sys.path[:]<EOL>setup_dir = os.path.abspath(os.path.dirname(setup_script))<EOL>temp_dir = os.path.join(setup_dir,'<STR_LIT>')<EOL>if not os.path.isdir(temp_dir): os.makedirs(temp_dir)<EOL>save_tmp = tempfile.tempdir<EOL>save_modules = sys.modules.copy()<EOL>pr_state = pkg_resources.__getstate__()<EOL>try:<EOL><INDENT>tempfile.tempdir = temp_dir<EOL>os.chdir(setup_dir)<EOL>try:<EOL><INDENT>sys.argv[:] = [setup_script]+list(args)<EOL>sys.path.insert(<NUM_LIT:0>, setup_dir)<EOL>DirectorySandbox(setup_dir).run(<EOL>lambda: exec(compile(open(<EOL>"<STR_LIT>", "<STR_LIT:rb>"<EOL>).read(), "<STR_LIT>", '<STR_LIT>'),<EOL>{'<STR_LIT>':setup_script, '<STR_LIT>':'<STR_LIT:__main__>'})<EOL>)<EOL><DEDENT>except SystemExit as v:<EOL><INDENT>if v.args and v.args[<NUM_LIT:0>]:<EOL><INDENT>raise<EOL><DEDENT><DEDENT><DEDENT>finally:<EOL><INDENT>pkg_resources.__setstate__(pr_state)<EOL>sys.modules.update(save_modules)<EOL>del_modules = [<EOL>mod_name for mod_name in sys.modules<EOL>if mod_name not in save_modules<EOL>and not mod_name.startswith('<STR_LIT>')<EOL>]<EOL>list(map(sys.modules.__delitem__, del_modules))<EOL>os.chdir(old_dir)<EOL>sys.path[:] = save_path<EOL>sys.argv[:] = save_argv<EOL>tempfile.tempdir = save_tmp<EOL><DEDENT>

Run a distutils setup script, sandboxed in its directory


try:<EOL><INDENT>self._copy(self)<EOL>if _file:<EOL><INDENT>builtins.file = self._file<EOL><DEDENT>builtins.open = self._open<EOL>self._active = True<EOL>return func()<EOL><DEDENT>finally:<EOL><INDENT>self._active = False<EOL>if _file:<EOL><INDENT>builtins.file = _file<EOL><DEDENT>builtins.open = _open<EOL>self._copy(_os)<EOL><DEDENT>


return path<EOL>

Called to remap or validate any path, whether input or output


return self._validate_path(path)<EOL>


return (<EOL>self._remap_input(operation+'<STR_LIT>',src,*args,**kw),<EOL>self._remap_input(operation+'<STR_LIT>',dst,*args,**kw)<EOL>)<EOL>

Called for path pairs like rename, link, and symlink operations


if operation in self.write_ops and not self._ok(path):<EOL><INDENT>self._violation(operation, os.path.realpath(path), *args, **kw)<EOL><DEDENT>return path<EOL>


if not self._ok(src) or not self._ok(dst):<EOL><INDENT>self._violation(operation, src, dst, *args, **kw)<EOL><DEDENT>return (src,dst)<EOL>


def open(self, file, flags, mode=<NUM_LIT>):

if flags & WRITE_FLAGS and not self._ok(file):<EOL><INDENT>self._violation("<STR_LIT>", file, flags, mode)<EOL><DEDENT>return _os.open(file,flags,mode)<EOL>


while cls.__module__.startswith('<STR_LIT>'):<EOL><INDENT>cls, = cls.__bases__<EOL><DEDENT>if not cls.__module__.startswith('<STR_LIT>'):<EOL><INDENT>raise AssertionError(<EOL>"<STR_LIT>" % cls<EOL>)<EOL><DEDENT>return cls<EOL>

Protect against re-patching the distutils if reloaded

    Also ensures that no other distutils extension monkeypatched the distutils
    first.


def assert_string_list(dist, attr, value):

try:<EOL><INDENT>assert '<STR_LIT>'.join(value)!=value<EOL><DEDENT>except (TypeError,ValueError,AttributeError,AssertionError):<EOL><INDENT>raise DistutilsSetupError(<EOL>"<STR_LIT>" % (attr,value)<EOL>)<EOL><DEDENT>

Verify that value is a string list or None


assert_string_list(dist,attr,value)<EOL>for nsp in value:<EOL><INDENT>if not dist.has_contents_for(nsp):<EOL><INDENT>raise DistutilsSetupError(<EOL>"<STR_LIT>" +<EOL>"<STR_LIT>" % nsp<EOL>)<EOL><DEDENT>if '<STR_LIT:.>' in nsp:<EOL><INDENT>parent = '<STR_LIT:.>'.join(nsp.split('<STR_LIT:.>')[:-<NUM_LIT:1>])<EOL>if parent not in value:<EOL><INDENT>distutils.log.warn(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>", nsp, parent<EOL>)<EOL><DEDENT><DEDENT><DEDENT>

Verify that namespace packages are valid


try:<EOL><INDENT>for k,v in list(value.items()):<EOL><INDENT>list(pkg_resources.parse_requirements(v))<EOL><DEDENT><DEDENT>except (TypeError,ValueError,AttributeError):<EOL><INDENT>raise DistutilsSetupError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>

Verify that extras_require mapping is valid


if bool(value) != value:<EOL><INDENT>raise DistutilsSetupError(<EOL>"<STR_LIT>" % (attr,value)<EOL>)<EOL><DEDENT>

Verify that value is True, False, 0, or 1


def check_requirements(dist, attr, value):

try:<EOL><INDENT>list(pkg_resources.parse_requirements(value))<EOL><DEDENT>except (TypeError,ValueError):<EOL><INDENT>raise DistutilsSetupError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (attr,)<EOL>)<EOL><DEDENT>

Verify that install_requires is a valid requirements list


def check_entry_points(dist, attr, value):

try:<EOL><INDENT>pkg_resources.EntryPoint.parse_map(value)<EOL><DEDENT>except ValueError as e:<EOL><INDENT>raise DistutilsSetupError(e)<EOL><DEDENT>

Verify that entry_points map is parseable


def check_package_data(dist, attr, value):

if isinstance(value,dict):<EOL><INDENT>for k,v in list(value.items()):<EOL><INDENT>if not isinstance(k,str): break<EOL>try: iter(v)<EOL>except TypeError:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return<EOL><DEDENT><DEDENT>raise DistutilsSetupError(<EOL>attr+"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL>

Verify that value is a dictionary of package names to glob lists


result = _Distribution.parse_command_line(self)<EOL>if self.features:<EOL><INDENT>self._finalize_features()<EOL><DEDENT>return result<EOL>

Process features after parsing command line options


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

Convert feature name to corresponding option attribute name


from pkg_resources import working_set, parse_requirements<EOL>for dist in working_set.resolve(<EOL>parse_requirements(requires), installer=self.fetch_build_egg,<EOL>replace_conflicting=True<EOL>):<EOL><INDENT>working_set.add(dist, replace=True)<EOL><DEDENT>


try:<EOL><INDENT>cmd = self._egg_fetcher<EOL>cmd.package_index.to_scan = []<EOL><DEDENT>except AttributeError:<EOL><INDENT>from setuptools.command.easy_install import easy_install<EOL>dist = self.__class__({'<STR_LIT>':['<STR_LIT>']})<EOL>dist.parse_config_files()<EOL>opts = dist.get_option_dict('<STR_LIT>')<EOL>keep = (<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>'<EOL>)<EOL>for key in list(opts.keys()):<EOL><INDENT>if key not in keep:<EOL><INDENT>del opts[key]   <EOL><DEDENT><DEDENT>if self.dependency_links:<EOL><INDENT>links = self.dependency_links[:]<EOL>if '<STR_LIT>' in opts:<EOL><INDENT>links = opts['<STR_LIT>'][<NUM_LIT:1>].split() + links<EOL><DEDENT>opts['<STR_LIT>'] = ('<STR_LIT>', links)<EOL><DEDENT>cmd = easy_install(<EOL>dist, args=["<STR_LIT:x>"], install_dir=os.curdir, exclude_scripts=True,<EOL>always_copy=False, build_directory=None, editable=False,<EOL>upgrade=False, multi_version=True, no_report=True, user=False<EOL>)<EOL>cmd.ensure_finalized()<EOL>self._egg_fetcher = cmd<EOL><DEDENT>return cmd.easy_install(req)<EOL>


go = []<EOL>no = self.negative_opt.copy()<EOL>for name,feature in list(self.features.items()):<EOL><INDENT>self._set_feature(name,None)<EOL>feature.validate(self)<EOL>if feature.optional:<EOL><INDENT>descr = feature.description<EOL>incdef = '<STR_LIT>'<EOL>excdef='<STR_LIT>'<EOL>if not feature.include_by_default():<EOL><INDENT>excdef, incdef = incdef, excdef<EOL><DEDENT>go.append(('<STR_LIT>'+name, None, '<STR_LIT>'+descr+incdef))<EOL>go.append(('<STR_LIT>'+name, None, '<STR_LIT>'+descr+excdef))<EOL>no['<STR_LIT>'+name] = '<STR_LIT>'+name<EOL><DEDENT><DEDENT>self.global_options = self.feature_options = go + self.global_options<EOL>self.negative_opt = self.feature_negopt = no<EOL>

Add --with-X/--without-X options based on optional features


<EOL>for name,feature in list(self.features.items()):<EOL><INDENT>enabled = self.feature_is_included(name)<EOL>if enabled or (enabled is None and feature.include_by_default()):<EOL><INDENT>feature.include_in(self)<EOL>self._set_feature(name,<NUM_LIT:1>)<EOL><DEDENT><DEDENT>for name,feature in list(self.features.items()):<EOL><INDENT>if not self.feature_is_included(name):<EOL><INDENT>feature.exclude_from(self)<EOL>self._set_feature(name,<NUM_LIT:0>)<EOL><DEDENT><DEDENT>

Add/remove features and resolve dependencies between them


if command in self.cmdclass:<EOL><INDENT>return self.cmdclass[command]<EOL><DEDENT>for ep in pkg_resources.iter_entry_points('<STR_LIT>',command):<EOL><INDENT>ep.require(installer=self.fetch_build_egg)<EOL>self.cmdclass[command] = cmdclass = ep.load()<EOL>return cmdclass<EOL><DEDENT>else:<EOL><INDENT>return _Distribution.get_command_class(self, command)<EOL><DEDENT>

Pluggable version of get_command_class()


setattr(self,self._feature_attrname(name),status)<EOL>


return getattr(self,self._feature_attrname(name))<EOL>

Return 1 if feature is included, 0 if excluded, 'None' if unknown