def assertDictContainsSubset(self, expected, actual, msg=None):

missing = []<EOL>mismatched = []<EOL>for key, value in expected.items():<EOL><INDENT>if key not in actual:<EOL><INDENT>missing.append(key)<EOL><DEDENT>elif value != actual[key]:<EOL><INDENT>mismatched.append('<STR_LIT>' %<EOL>(safe_repr(key), safe_repr(value),<EOL>safe_repr(actual[key])))<EOL><DEDENT><DEDENT>if not (missing or mismatched):<EOL><INDENT>return<EOL><DEDENT>standardMsg = '<STR_LIT>'<EOL>if missing:<EOL><INDENT>standardMsg = '<STR_LIT>' % '<STR_LIT:U+002C>'.join(safe_repr(m) for m in<EOL>missing)<EOL><DEDENT>if mismatched:<EOL><INDENT>if standardMsg:<EOL><INDENT>standardMsg += '<STR_LIT>'<EOL><DEDENT>standardMsg += '<STR_LIT>' % '<STR_LIT:U+002C>'.join(mismatched)<EOL><DEDENT>self.fail(self._formatMessage(msg, standardMsg))<EOL>

Checks whether actual is a superset of expected.


def assertItemsEqual(self, expected_seq, actual_seq, msg=None):

first_seq, second_seq = list(expected_seq), list(actual_seq)<EOL>with warnings.catch_warnings():<EOL><INDENT>if sys.py3kwarning:<EOL><INDENT>for _msg in ["<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>"]:<EOL><INDENT>warnings.filterwarnings("<STR_LIT:ignore>", _msg, DeprecationWarning)<EOL><DEDENT><DEDENT>try:<EOL><INDENT>first = collections.Counter(first_seq)<EOL>second = collections.Counter(second_seq)<EOL><DEDENT>except TypeError:<EOL><INDENT>differences = _count_diff_all_purpose(first_seq, second_seq)<EOL><DEDENT>else:<EOL><INDENT>if first == second:<EOL><INDENT>return<EOL><DEDENT>differences = _count_diff_hashable(first_seq, second_seq)<EOL><DEDENT><DEDENT>if differences:<EOL><INDENT>standardMsg = '<STR_LIT>'<EOL>lines = ['<STR_LIT>' % diff for diff in differences]<EOL>diffMsg = '<STR_LIT:\n>'.join(lines)<EOL>standardMsg = self._truncateMessage(standardMsg, diffMsg)<EOL>msg = self._formatMessage(msg, standardMsg)<EOL>self.fail(msg)<EOL><DEDENT>

An unordered sequence specific comparison. It asserts that
        actual_seq and expected_seq have the same element counts.
        Equivalent to::

            self.assertEqual(Counter(iter(actual_seq)),
                             Counter(iter(expected_seq)))

        Asserts that each element has the same count in both sequences.
        Example:
            - [0, 1, 1] and [1, 0, 1] compare equal.
            - [0, 0, 1] and [0, 1] compare unequal.


def assertMultiLineEqual(self, first, second, msg=None):

self.assertIsInstance(first, str,<EOL>'<STR_LIT>')<EOL>self.assertIsInstance(second, str,<EOL>'<STR_LIT>')<EOL>if first != second:<EOL><INDENT>if (len(first) > self._diffThreshold or<EOL>len(second) > self._diffThreshold):<EOL><INDENT>self._baseAssertEqual(first, second, msg)<EOL><DEDENT>firstlines = first.splitlines(True)<EOL>secondlines = second.splitlines(True)<EOL>if len(firstlines) == <NUM_LIT:1> and first.strip('<STR_LIT:\r\n>') == first:<EOL><INDENT>firstlines = [first + '<STR_LIT:\n>']<EOL>secondlines = [second + '<STR_LIT:\n>']<EOL><DEDENT>standardMsg = '<STR_LIT>' % (safe_repr(first, True),<EOL>safe_repr(second, True))<EOL>diff = '<STR_LIT:\n>' + '<STR_LIT>'.join(difflib.ndiff(firstlines, secondlines))<EOL>standardMsg = self._truncateMessage(standardMsg, diff)<EOL>self.fail(self._formatMessage(msg, standardMsg))<EOL><DEDENT>

Assert that two multi-line strings are equal.


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

Just like self.assertTrue(a < b), but with a nicer default message.


def assertLessEqual(self, a, b, msg=None):

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

Just like self.assertTrue(a <= b), but with a nicer default message.


def assertGreater(self, a, b, msg=None):

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

Just like self.assertTrue(a > b), but with a nicer default message.


def assertGreaterEqual(self, a, b, msg=None):

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

Just like self.assertTrue(a >= b), but with a nicer default message.


if obj is not None:<EOL><INDENT>standardMsg = '<STR_LIT>' % (safe_repr(obj),)<EOL>self.fail(self._formatMessage(msg, standardMsg))<EOL><DEDENT>

Same as self.assertTrue(obj is None), with a nicer default message.


def assertIsNotNone(self, obj, msg=None):

if obj is None:<EOL><INDENT>standardMsg = '<STR_LIT>'<EOL>self.fail(self._formatMessage(msg, standardMsg))<EOL><DEDENT>

Included for symmetry with assertIsNone.


def assertIsInstance(self, obj, cls, msg=None):

if not isinstance(obj, cls):<EOL><INDENT>standardMsg = '<STR_LIT>' % (safe_repr(obj), cls)<EOL>self.fail(self._formatMessage(msg, standardMsg))<EOL><DEDENT>

Same as self.assertTrue(isinstance(obj, cls)), with a nicer
        default message.


def assertNotIsInstance(self, obj, cls, msg=None):

if isinstance(obj, cls):<EOL><INDENT>standardMsg = '<STR_LIT>' % (safe_repr(obj), cls)<EOL>self.fail(self._formatMessage(msg, standardMsg))<EOL><DEDENT>

Included for symmetry with assertIsInstance.


def assertRaisesRegexp(self, expected_exception, expected_regexp,<EOL>callable_obj=None, *args, **kwargs):

if expected_regexp is not None:<EOL><INDENT>expected_regexp = re.compile(expected_regexp)<EOL><DEDENT>context = _AssertRaisesContext(expected_exception, self, expected_regexp)<EOL>if callable_obj is None:<EOL><INDENT>return context<EOL><DEDENT>with context:<EOL><INDENT>callable_obj(*args, **kwargs)<EOL><DEDENT>

Asserts that the message in a raised exception matches a regexp.

        Args:
            expected_exception: Exception class expected to be raised.
            expected_regexp: Regexp (re pattern object or string) expected
                    to be found in error message.
            callable_obj: Function to be called.
            args: Extra args.
            kwargs: Extra kwargs.


def assertRegexpMatches(self, text, expected_regexp, msg=None):

if isinstance(expected_regexp, str):<EOL><INDENT>expected_regexp = re.compile(expected_regexp)<EOL><DEDENT>if not expected_regexp.search(text):<EOL><INDENT>msg = msg or "<STR_LIT>"<EOL>msg = '<STR_LIT>' % (msg, expected_regexp.pattern, text)<EOL>raise self.failureException(msg)<EOL><DEDENT>

Fail the test unless the text matches the regular expression.


def assertNotRegexpMatches(self, text, unexpected_regexp, msg=None):

if isinstance(unexpected_regexp, str):<EOL><INDENT>unexpected_regexp = re.compile(unexpected_regexp)<EOL><DEDENT>match = unexpected_regexp.search(text)<EOL>if match:<EOL><INDENT>msg = msg or "<STR_LIT>"<EOL>msg = '<STR_LIT>' % (msg,<EOL>text[match.start():match.end()],<EOL>unexpected_regexp.pattern,<EOL>text)<EOL>raise self.failureException(msg)<EOL><DEDENT>

Fail the test if the text matches the regular expression.


if not args:<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>self = args[<NUM_LIT:0>]<EOL>args = args[<NUM_LIT:1>:]<EOL>if len(args) > <NUM_LIT:1>:<EOL><INDENT>raise TypeError('<STR_LIT>' % len(args))<EOL><DEDENT>try:<EOL><INDENT>self.__root<EOL><DEDENT>except AttributeError:<EOL><INDENT>self.__root = root = []                     <EOL>root[:] = [root, root, None]<EOL>self.__map = {}<EOL><DEDENT>self.__update(*args, **kwds)<EOL>

Initialize an ordered dictionary.  The signature is the same as
        regular dictionaries, but keyword arguments are not recommended because
        their insertion order is arbitrary.


def __setitem__(self, key, value, dict_setitem=dict.__setitem__):

<EOL>if key not in self:<EOL><INDENT>root = self.__root<EOL>last = root[<NUM_LIT:0>]<EOL>last[<NUM_LIT:1>] = root[<NUM_LIT:0>] = self.__map[key] = [last, root, key]<EOL><DEDENT>return dict_setitem(self, key, value)<EOL>


def __delitem__(self, key, dict_delitem=dict.__delitem__):

<EOL>dict_delitem(self, key)<EOL>link_prev, link_next, _ = self.__map.pop(key)<EOL>link_prev[<NUM_LIT:1>] = link_next                        <EOL>link_next[<NUM_LIT:0>] = link_prev                        <EOL>


<EOL>root = self.__root<EOL>curr = root[<NUM_LIT:1>]                                  <EOL>while curr is not root:<EOL><INDENT>yield curr[<NUM_LIT:2>]                               <EOL>curr = curr[<NUM_LIT:1>]                              <EOL><DEDENT>


<EOL>root = self.__root<EOL>curr = root[<NUM_LIT:0>]                                  <EOL>while curr is not root:<EOL><INDENT>yield curr[<NUM_LIT:2>]                               <EOL>curr = curr[<NUM_LIT:0>]                              <EOL><DEDENT>


root = self.__root<EOL>root[:] = [root, root, None]<EOL>self.__map.clear()<EOL>dict.clear(self)<EOL>

od.clear() -> None.  Remove all items from od.


return list(self)<EOL>


return [self[key] for key in self]<EOL>


return [(key, self[key]) for key in self]<EOL>

od.items() -> list of (key, value) pairs in od


return iter(self)<EOL>

od.iterkeys() -> an iterator over the keys in od


for k in self:<EOL><INDENT>yield self[k]<EOL><DEDENT>

od.itervalues -> an iterator over the values in od


for k in self:<EOL><INDENT>yield (k, self[k])<EOL><DEDENT>

od.iteritems -> an iterator over the (key, value) pairs in od


if key in self:<EOL><INDENT>result = self[key]<EOL>del self[key]<EOL>return result<EOL><DEDENT>if default is self.__marker:<EOL><INDENT>raise KeyError(key)<EOL><DEDENT>return default<EOL>

od.pop(k[,d]) -> v, remove specified key and return the corresponding
        value.  If key is not found, d is returned if given, otherwise KeyError
        is raised.


def setdefault(self, key, default=None):

if key in self:<EOL><INDENT>return self[key]<EOL><DEDENT>self[key] = default<EOL>return default<EOL>

od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od


if not self:<EOL><INDENT>raise KeyError('<STR_LIT>')<EOL><DEDENT>key = next(reversed(self) if last else iter(self))<EOL>value = self.pop(key)<EOL>return key, value<EOL>

od.popitem() -> (k, v), return and remove a (key, value) pair.
        Pairs are returned in LIFO order if last is true or FIFO order if false.


call_key = id(self), _get_ident()<EOL>if call_key in _repr_running:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>_repr_running[call_key] = <NUM_LIT:1><EOL>try:<EOL><INDENT>if not self:<EOL><INDENT>return '<STR_LIT>' % (self.__class__.__name__,)<EOL><DEDENT>return '<STR_LIT>' % (self.__class__.__name__, self.items())<EOL><DEDENT>finally:<EOL><INDENT>del _repr_running[call_key]<EOL><DEDENT>


items = [[k, self[k]] for k in self]<EOL>inst_dict = vars(self).copy()<EOL>for k in vars(OrderedDict()):<EOL><INDENT>inst_dict.pop(k, None)<EOL><DEDENT>if inst_dict:<EOL><INDENT>return (self.__class__, (items,), inst_dict)<EOL><DEDENT>return self.__class__, (items,)<EOL>


return self.__class__(self)<EOL>


@classmethod<EOL><INDENT>def fromkeys(cls, iterable, value=None):<DEDENT>

self = cls()<EOL>for key in iterable:<EOL><INDENT>self[key] = value<EOL><DEDENT>return self<EOL>

OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S.
        If not specified, the value defaults to None.


if isinstance(other, OrderedDict):<EOL><INDENT>return dict.__eq__(self, other) and all(_imap(_eq, self, other))<EOL><DEDENT>return dict.__eq__(self, other)<EOL>

od.__eq__(y) <==> od==y.  Comparison to another OD is order-sensitive
        while comparison to a regular mapping is order-insensitive.


return not self == other<EOL>


return KeysView(self)<EOL>

od.viewkeys() -> a set-like object providing a view on od's keys


return ValuesView(self)<EOL>

od.viewvalues() -> an object providing a view on od's values


return ItemsView(self)<EOL>

od.viewitems() -> a set-like object providing a view on od's items


if not args:<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>self = args[<NUM_LIT:0>]<EOL>args = args[<NUM_LIT:1>:]<EOL>if len(args) > <NUM_LIT:1>:<EOL><INDENT>raise TypeError('<STR_LIT>' % len(args))<EOL><DEDENT>super(Counter, self).__init__()<EOL>self.update(*args, **kwds)<EOL>

Create a new, empty Counter object.  And if given, count elements
        from an input iterable.  Or, initialize the count from another mapping
        of elements to their counts.

        >>> c = Counter()                           # a new, empty counter
        >>> c = Counter('gallahad')                 # a new counter from an iterable
        >>> c = Counter({'a': 4, 'b': 2})           # a new counter from a mapping
        >>> c = Counter(a=4, b=2)                   # a new counter from keyword args


<EOL>return <NUM_LIT:0><EOL>

The count of elements not in the Counter is zero.


<EOL>if n is None:<EOL><INDENT>return sorted(self.iteritems(), key=_itemgetter(<NUM_LIT:1>), reverse=True)<EOL><DEDENT>return _heapq.nlargest(n, self.iteritems(), key=_itemgetter(<NUM_LIT:1>))<EOL>

List the n most common elements and their counts from the most
        common to the least.  If n is None, then list all element counts.

        >>> Counter('abcdeabcdabcaba').most_common(3)
        [('a', 5), ('b', 4), ('c', 3)]


<EOL>return _chain.from_iterable(_starmap(_repeat, self.iteritems()))<EOL>

Iterator over elements repeating each as many times as its count.

        >>> c = Counter('ABCABC')
        >>> sorted(c.elements())
        ['A', 'A', 'B', 'B', 'C', 'C']

        # Knuth's example for prime factors of 1836:  2**2 * 3**3 * 17**1
        >>> prime_factors = Counter({2: 2, 3: 3, 17: 1})
        >>> product = 1
        >>> for factor in prime_factors.elements():     # loop over factors
        ...     product *= factor                       # and multiply them
        >>> product
        1836

        Note, if an element's count has been set to zero or is a negative
        number, elements() will ignore it.


<EOL>if not args:<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>self = args[<NUM_LIT:0>]<EOL>args = args[<NUM_LIT:1>:]<EOL>if len(args) > <NUM_LIT:1>:<EOL><INDENT>raise TypeError('<STR_LIT>' % len(args))<EOL><DEDENT>iterable = args[<NUM_LIT:0>] if args else None<EOL>if iterable is not None:<EOL><INDENT>if isinstance(iterable, Mapping):<EOL><INDENT>if self:<EOL><INDENT>self_get = self.get<EOL>for elem, count in iterable.iteritems():<EOL><INDENT>self[elem] = self_get(elem, <NUM_LIT:0>) + count<EOL><DEDENT><DEDENT>else:<EOL><INDENT>super(Counter, self).update(iterable) <EOL><DEDENT><DEDENT>else:<EOL><INDENT>self_get = self.get<EOL>for elem in iterable:<EOL><INDENT>self[elem] = self_get(elem, <NUM_LIT:0>) + <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>if kwds:<EOL><INDENT>self.update(kwds)<EOL><DEDENT>

Like dict.update() but add counts instead of replacing them.

        Source can be an iterable, a dictionary, or another Counter instance.

        >>> c = Counter('which')
        >>> c.update('witch')           # add elements from another iterable
        >>> d = Counter('watch')
        >>> c.update(d)                 # add elements from another counter
        >>> c['h']                      # four 'h' in which, witch, and watch
        4


if not args:<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>self = args[<NUM_LIT:0>]<EOL>args = args[<NUM_LIT:1>:]<EOL>if len(args) > <NUM_LIT:1>:<EOL><INDENT>raise TypeError('<STR_LIT>' % len(args))<EOL><DEDENT>iterable = args[<NUM_LIT:0>] if args else None<EOL>if iterable is not None:<EOL><INDENT>self_get = self.get<EOL>if isinstance(iterable, Mapping):<EOL><INDENT>for elem, count in iterable.items():<EOL><INDENT>self[elem] = self_get(elem, <NUM_LIT:0>) - count<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for elem in iterable:<EOL><INDENT>self[elem] = self_get(elem, <NUM_LIT:0>) - <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>if kwds:<EOL><INDENT>self.subtract(kwds)<EOL><DEDENT>

Like dict.update() but subtracts counts instead of replacing them.
        Counts can be reduced below zero.  Both the inputs and outputs are
        allowed to contain zero and negative counts.

        Source can be an iterable, a dictionary, or another Counter instance.

        >>> c = Counter('which')
        >>> c.subtract('witch')             # subtract elements from another iterable
        >>> c.subtract(Counter('watch'))    # subtract elements from another counter
        >>> c['h']                          # 2 in which, minus 1 in witch, minus 1 in watch
        0
        >>> c['w']                          # 1 in which, minus 1 in witch, minus 1 in watch
        -1


if elem in self:<EOL><INDENT>super(Counter, self).__delitem__(elem)<EOL><DEDENT>

Like dict.__delitem__() but does not raise KeyError for missing values.


if not isinstance(other, Counter):<EOL><INDENT>return NotImplemented<EOL><DEDENT>result = Counter()<EOL>for elem, count in self.items():<EOL><INDENT>newcount = count + other[elem]<EOL>if newcount > <NUM_LIT:0>:<EOL><INDENT>result[elem] = newcount<EOL><DEDENT><DEDENT>for elem, count in other.items():<EOL><INDENT>if elem not in self and count > <NUM_LIT:0>:<EOL><INDENT>result[elem] = count<EOL><DEDENT><DEDENT>return result<EOL>

Add counts from two counters.

        >>> Counter('abbb') + Counter('bcc')
        Counter({'b': 4, 'c': 2, 'a': 1})


if not isinstance(other, Counter):<EOL><INDENT>return NotImplemented<EOL><DEDENT>result = Counter()<EOL>for elem, count in self.items():<EOL><INDENT>newcount = count - other[elem]<EOL>if newcount > <NUM_LIT:0>:<EOL><INDENT>result[elem] = newcount<EOL><DEDENT><DEDENT>for elem, count in other.items():<EOL><INDENT>if elem not in self and count < <NUM_LIT:0>:<EOL><INDENT>result[elem] = <NUM_LIT:0> - count<EOL><DEDENT><DEDENT>return result<EOL>

Subtract count, but keep only results with positive counts.

        >>> Counter('abbbc') - Counter('bccd')
        Counter({'b': 2, 'a': 1})


if not isinstance(other, Counter):<EOL><INDENT>return NotImplemented<EOL><DEDENT>result = Counter()<EOL>for elem, count in self.items():<EOL><INDENT>other_count = other[elem]<EOL>newcount = other_count if count < other_count else count<EOL>if newcount > <NUM_LIT:0>:<EOL><INDENT>result[elem] = newcount<EOL><DEDENT><DEDENT>for elem, count in other.items():<EOL><INDENT>if elem not in self and count > <NUM_LIT:0>:<EOL><INDENT>result[elem] = count<EOL><DEDENT><DEDENT>return result<EOL>

Union is the maximum of value in either of the input counters.

        >>> Counter('abbb') | Counter('bcc')
        Counter({'b': 3, 'c': 2, 'a': 1})


if not isinstance(other, Counter):<EOL><INDENT>return NotImplemented<EOL><DEDENT>result = Counter()<EOL>for elem, count in self.items():<EOL><INDENT>other_count = other[elem]<EOL>newcount = count if count < other_count else other_count<EOL>if newcount > <NUM_LIT:0>:<EOL><INDENT>result[elem] = newcount<EOL><DEDENT><DEDENT>return result<EOL>

Intersection is the minimum of corresponding counts.

        >>> Counter('abbb') & Counter('bcc')
        Counter({'b': 1})


def pprint(o, stream=None, indent=<NUM_LIT:1>, width=<NUM_LIT>, depth=None):

printer = PrettyPrinter(<EOL>stream=stream, indent=indent, width=width, depth=depth)<EOL>printer.pprint(o)<EOL>

Pretty-print a Python o to a stream [default is sys.stdout].


def pformat(o, indent=<NUM_LIT:1>, width=<NUM_LIT>, depth=None):

return PrettyPrinter(indent=indent, width=width, depth=depth).pformat(o)<EOL>

Format a Python o into a pretty-printed representation.


return _safe_repr(o, {}, None, <NUM_LIT:0>)[<NUM_LIT:0>]<EOL>

Version of repr() which can handle recursive data structures.


return _safe_repr(o, {}, None, <NUM_LIT:0>)[<NUM_LIT:1>]<EOL>

Determine if saferepr(o) is readable by eval().


return _safe_repr(o, {}, None, <NUM_LIT:0>)[<NUM_LIT:2>]<EOL>

Determine if o requires a recursive representation.


def __init__(self, indent=<NUM_LIT:1>, width=<NUM_LIT>, depth=None, stream=None):

indent = int(indent)<EOL>width = int(width)<EOL>assert indent >= <NUM_LIT:0>, "<STR_LIT>"<EOL>assert depth is None or depth > <NUM_LIT:0>, "<STR_LIT>"<EOL>assert width, "<STR_LIT>"<EOL>self._depth = depth<EOL>self._indent_per_level = indent<EOL>self._width = width<EOL>if stream is not None:<EOL><INDENT>self._stream = stream<EOL><DEDENT>else:<EOL><INDENT>self._stream = _sys.stdout<EOL><DEDENT>

Handle pretty printing operations onto a stream using a set of
        configured parameters.

        indent
            Number of spaces to indent for each level of nesting.

        width
            Attempted maximum number of columns in the output.

        depth
            The maximum depth to print out nested structures.

        stream
            The desired output stream.  If omitted (or false), the standard
            output stream available at construction will be used.


def format(self, o, context, maxlevels, level):

return _safe_repr(o, context, maxlevels, level)<EOL>

Format o for a specific context, returning a string
        and flags indicating whether the representation is 'readable'
        and whether the o represents a recursive construct.


@wraps(func)<EOL>def helper(*args, **kwds):<EOL><INDENT>return GeneratorContextManager(func(*args, **kwds))<EOL><DEDENT>return helper<EOL>

@contextmanager decorator.

    Typical usage:

        @contextmanager
        def some_generator(<arguments>):
            <setup>
            try:
                yield <value>
            finally:
                <cleanup>

    This makes this:

        with some_generator(<arguments>) as <variable>:
            <body>

    equivalent to this:

        <setup>
        try:
            <variable> = <value>
            <body>
        finally:
            <cleanup>


warn("<STR_LIT>",<EOL>DeprecationWarning, <NUM_LIT:3>)<EOL>exits = []<EOL>vars = []<EOL>exc = (None, None, None)<EOL>try:<EOL><INDENT>for mgr in managers:<EOL><INDENT>exit = mgr.__exit__<EOL>enter = mgr.__enter__<EOL>vars.append(enter())<EOL>exits.append(exit)<EOL><DEDENT>yield vars<EOL><DEDENT>except:<EOL><INDENT>exc = sys.exc_info()<EOL><DEDENT>finally:<EOL><INDENT>while exits:<EOL><INDENT>exit = exits.pop()<EOL>try:<EOL><INDENT>if exit(*exc):<EOL><INDENT>exc = (None, None, None)<EOL><DEDENT><DEDENT>except:<EOL><INDENT>exc = sys.exc_info()<EOL><DEDENT><DEDENT>if exc != (None, None, None):<EOL><INDENT>raise exc[<NUM_LIT:0>](exc[<NUM_LIT:1>]).with_traceback(exc[<NUM_LIT:2>])<EOL><DEDENT><DEDENT>

Combine multiple context managers into a single nested context manager.

   This function has been deprecated in favour of the multiple manager form
   of the with statement.

   The one advantage of this function over the multiple manager form of the
   with statement is that argument unpacking allows it to be
   used with a variable number of context managers as follows:

      with nested(*managers):
          do_something()


def urlparse(url, scheme='<STR_LIT>', allow_fragments=True):

tuple = urlsplit(url, scheme, allow_fragments)<EOL>scheme, netloc, url, query, fragment = tuple<EOL>if scheme in uses_params and '<STR_LIT:;>' in url:<EOL><INDENT>url, params = _splitparams(url)<EOL><DEDENT>else:<EOL><INDENT>params = '<STR_LIT>'<EOL><DEDENT>return ParseResult(scheme, netloc, url, params, query, fragment)<EOL>

Parse a URL into 6 components:
    <scheme>://<netloc>/<path>;<params>?<query>#<fragment>
    Return a 6-tuple: (scheme, netloc, path, params, query, fragment).
    Note that we don't break the components up in smaller bits
    (e.g. netloc is a single string) and we don't expand % escapes.


def urlsplit(url, scheme='<STR_LIT>', allow_fragments=True):

allow_fragments = bool(allow_fragments)<EOL>key = url, scheme, allow_fragments, type(url), type(scheme)<EOL>cached = _parse_cache.get(key, None)<EOL>if cached:<EOL><INDENT>return cached<EOL><DEDENT>if len(_parse_cache) >= MAX_CACHE_SIZE: <EOL><INDENT>clear_cache()<EOL><DEDENT>netloc = query = fragment = '<STR_LIT>'<EOL>i = url.find('<STR_LIT::>')<EOL>if i > <NUM_LIT:0>:<EOL><INDENT>if url[:i] == '<STR_LIT:http>': <EOL><INDENT>scheme = url[:i].lower()<EOL>url = url[i+<NUM_LIT:1>:]<EOL>if url[:<NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>netloc, url = _splitnetloc(url, <NUM_LIT:2>)<EOL>if (('<STR_LIT:[>' in netloc and '<STR_LIT:]>' not in netloc) or<EOL>('<STR_LIT:]>' in netloc and '<STR_LIT:[>' not in netloc)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>if allow_fragments and '<STR_LIT:#>' in url:<EOL><INDENT>url, fragment = url.split('<STR_LIT:#>', <NUM_LIT:1>)<EOL><DEDENT>if '<STR_LIT:?>' in url:<EOL><INDENT>url, query = url.split('<STR_LIT:?>', <NUM_LIT:1>)<EOL><DEDENT>v = SplitResult(scheme, netloc, url, query, fragment)<EOL>_parse_cache[key] = v<EOL>return v<EOL><DEDENT>for c in url[:i]:<EOL><INDENT>if c not in scheme_chars:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>rest = url[i+<NUM_LIT:1>:]<EOL>if not rest or any(c not in '<STR_LIT>' for c in rest):<EOL><INDENT>scheme, url = url[:i].lower(), rest<EOL><DEDENT><DEDENT><DEDENT>if url[:<NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>netloc, url = _splitnetloc(url, <NUM_LIT:2>)<EOL>if (('<STR_LIT:[>' in netloc and '<STR_LIT:]>' not in netloc) or<EOL>('<STR_LIT:]>' in netloc and '<STR_LIT:[>' not in netloc)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>if allow_fragments and '<STR_LIT:#>' in url:<EOL><INDENT>url, fragment = url.split('<STR_LIT:#>', <NUM_LIT:1>)<EOL><DEDENT>if '<STR_LIT:?>' in url:<EOL><INDENT>url, query = url.split('<STR_LIT:?>', <NUM_LIT:1>)<EOL><DEDENT>v = SplitResult(scheme, netloc, url, query, fragment)<EOL>_parse_cache[key] = v<EOL>return v<EOL>

Parse a URL into 5 components:
    <scheme>://<netloc>/<path>?<query>#<fragment>
    Return a 5-tuple: (scheme, netloc, path, query, fragment).
    Note that we don't break the components up in smaller bits
    (e.g. netloc is a single string) and we don't expand % escapes.


scheme, netloc, url, params, query, fragment = data<EOL>if params:<EOL><INDENT>url = "<STR_LIT>" % (url, params)<EOL><DEDENT>return urlunsplit((scheme, netloc, url, query, fragment))<EOL>

Put a parsed URL back together again.  This may result in a
    slightly different, but equivalent URL, if the URL that was parsed
    originally had redundant delimiters, e.g. a ? with an empty query
    (the draft states that these are equivalent).


scheme, netloc, url, query, fragment = data<EOL>if netloc or (scheme and scheme in uses_netloc and url[:<NUM_LIT:2>] != '<STR_LIT>'):<EOL><INDENT>if url and url[:<NUM_LIT:1>] != '<STR_LIT:/>': url = '<STR_LIT:/>' + url<EOL>url = '<STR_LIT>' + (netloc or '<STR_LIT>') + url<EOL><DEDENT>if scheme:<EOL><INDENT>url = scheme + '<STR_LIT::>' + url<EOL><DEDENT>if query:<EOL><INDENT>url = url + '<STR_LIT:?>' + query<EOL><DEDENT>if fragment:<EOL><INDENT>url = url + '<STR_LIT:#>' + fragment<EOL><DEDENT>return url<EOL>

Combine the elements of a tuple as returned by urlsplit() into a
    complete URL as a string. The data argument can be any five-item iterable.
    This may result in a slightly different, but equivalent URL, if the URL that
    was parsed originally had unnecessary delimiters (for example, a ? with an
    empty query; the RFC states that these are equivalent).


def urljoin(base, url, allow_fragments=True):

if not base:<EOL><INDENT>return url<EOL><DEDENT>if not url:<EOL><INDENT>return base<EOL><DEDENT>bscheme, bnetloc, bpath, bparams, bquery, bfragment =urlparse(base, '<STR_LIT>', allow_fragments)<EOL>scheme, netloc, path, params, query, fragment =urlparse(url, bscheme, allow_fragments)<EOL>if scheme != bscheme or scheme not in uses_relative:<EOL><INDENT>return url<EOL><DEDENT>if scheme in uses_netloc:<EOL><INDENT>if netloc:<EOL><INDENT>return urlunparse((scheme, netloc, path,<EOL>params, query, fragment))<EOL><DEDENT>netloc = bnetloc<EOL><DEDENT>if path[:<NUM_LIT:1>] == '<STR_LIT:/>':<EOL><INDENT>return urlunparse((scheme, netloc, path,<EOL>params, query, fragment))<EOL><DEDENT>if not path and not params:<EOL><INDENT>path = bpath<EOL>params = bparams<EOL>if not query:<EOL><INDENT>query = bquery<EOL><DEDENT>return urlunparse((scheme, netloc, path,<EOL>params, query, fragment))<EOL><DEDENT>segments = bpath.split('<STR_LIT:/>')[:-<NUM_LIT:1>] + path.split('<STR_LIT:/>')<EOL>if segments[-<NUM_LIT:1>] == '<STR_LIT:.>':<EOL><INDENT>segments[-<NUM_LIT:1>] = '<STR_LIT>'<EOL><DEDENT>while '<STR_LIT:.>' in segments:<EOL><INDENT>segments.remove('<STR_LIT:.>')<EOL><DEDENT>while <NUM_LIT:1>:<EOL><INDENT>i = <NUM_LIT:1><EOL>n = len(segments) - <NUM_LIT:1><EOL>while i < n:<EOL><INDENT>if (segments[i] == '<STR_LIT:..>'<EOL>and segments[i-<NUM_LIT:1>] not in ('<STR_LIT>', '<STR_LIT:..>')):<EOL><INDENT>del segments[i-<NUM_LIT:1>:i+<NUM_LIT:1>]<EOL>break<EOL><DEDENT>i = i+<NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if segments == ['<STR_LIT>', '<STR_LIT:..>']:<EOL><INDENT>segments[-<NUM_LIT:1>] = '<STR_LIT>'<EOL><DEDENT>elif len(segments) >= <NUM_LIT:2> and segments[-<NUM_LIT:1>] == '<STR_LIT:..>':<EOL><INDENT>segments[-<NUM_LIT:2>:] = ['<STR_LIT>']<EOL><DEDENT>return urlunparse((scheme, netloc, '<STR_LIT:/>'.join(segments),<EOL>params, query, fragment))<EOL>

Join a base URL and a possibly relative URL to form an absolute
    interpretation of the latter.


if '<STR_LIT:#>' in url:<EOL><INDENT>s, n, p, a, q, frag = urlparse(url)<EOL>defrag = urlunparse((s, n, p, a, q, '<STR_LIT>'))<EOL>return defrag, frag<EOL><DEDENT>else:<EOL><INDENT>return url, '<STR_LIT>'<EOL><DEDENT>

Removes any existing fragment from URL.

    Returns a tuple of the defragmented URL and the fragment.  If
    the URL contained no fragments, the second element is the
    empty string.


if _is_unicode(s):<EOL><INDENT>if '<STR_LIT:%>' not in s:<EOL><INDENT>return s<EOL><DEDENT>bits = _asciire.split(s)<EOL>res = [bits[<NUM_LIT:0>]]<EOL>append = res.append<EOL>for i in range(<NUM_LIT:1>, len(bits), <NUM_LIT:2>):<EOL><INDENT>append(unquote(str(bits[i])).decode('<STR_LIT>'))<EOL>append(bits[i + <NUM_LIT:1>])<EOL><DEDENT>return '<STR_LIT>'.join(res)<EOL><DEDENT>bits = s.split('<STR_LIT:%>')<EOL>if len(bits) == <NUM_LIT:1>:<EOL><INDENT>return s<EOL><DEDENT>res = [bits[<NUM_LIT:0>]]<EOL>append = res.append<EOL>for item in bits[<NUM_LIT:1>:]:<EOL><INDENT>try:<EOL><INDENT>append(_hextochr[item[:<NUM_LIT:2>]])<EOL>append(item[<NUM_LIT:2>:])<EOL><DEDENT>except KeyError:<EOL><INDENT>append('<STR_LIT:%>')<EOL>append(item)<EOL><DEDENT><DEDENT>return '<STR_LIT>'.join(res)<EOL>


def parse_qs(qs, keep_blank_values=<NUM_LIT:0>, strict_parsing=<NUM_LIT:0>):

dict = {}<EOL>for name, value in parse_qsl(qs, keep_blank_values, strict_parsing):<EOL><INDENT>if name in dict:<EOL><INDENT>dict[name].append(value)<EOL><DEDENT>else:<EOL><INDENT>dict[name] = [value]<EOL><DEDENT><DEDENT>return dict<EOL>

Parse a query given as a string argument.

        Arguments:

        qs: percent-encoded query string to be parsed

        keep_blank_values: flag indicating whether blank values in
            percent-encoded queries should be treated as blank strings.
            A true value indicates that blanks should be retained as
            blank strings.  The default false value indicates that
            blank values are to be ignored and treated as if they were
            not included.

        strict_parsing: flag indicating what to do with parsing errors.
            If false (the default), errors are silently ignored.
            If true, errors raise a ValueError exception.


def parse_qsl(qs, keep_blank_values=<NUM_LIT:0>, strict_parsing=<NUM_LIT:0>):

pairs = [s2 for s1 in qs.split('<STR_LIT:&>') for s2 in s1.split('<STR_LIT:;>')]<EOL>r = []<EOL>for name_value in pairs:<EOL><INDENT>if not name_value and not strict_parsing:<EOL><INDENT>continue<EOL><DEDENT>nv = name_value.split('<STR_LIT:=>', <NUM_LIT:1>)<EOL>if len(nv) != <NUM_LIT:2>:<EOL><INDENT>if strict_parsing:<EOL><INDENT>raise ValueError("<STR_LIT>" % (name_value,))<EOL><DEDENT>if keep_blank_values:<EOL><INDENT>nv.append('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>if len(nv[<NUM_LIT:1>]) or keep_blank_values:<EOL><INDENT>name = unquote(nv[<NUM_LIT:0>].replace('<STR_LIT:+>', '<STR_LIT:U+0020>'))<EOL>value = unquote(nv[<NUM_LIT:1>].replace('<STR_LIT:+>', '<STR_LIT:U+0020>'))<EOL>r.append((name, value))<EOL><DEDENT><DEDENT>return r<EOL>

Parse a query given as a string argument.

    Arguments:

    qs: percent-encoded query string to be parsed

    keep_blank_values: flag indicating whether blank values in
        percent-encoded queries should be treated as blank strings.  A
        true value indicates that blanks should be retained as blank
        strings.  The default false value indicates that blank values
        are to be ignored and treated as if they were  not included.

    strict_parsing: flag indicating what to do with parsing errors. If
        false (the default), errors are silently ignored. If true,
        errors raise a ValueError exception.

    Returns a list, as G-d intended.


def __new__(_cls, scheme, netloc, path, query, fragment):

return _tuple.__new__(_cls, (scheme, netloc, path, query, fragment))<EOL>

Create new instance of SplitResult(scheme, netloc, path, query, fragment)


def _make(cls, iterable, new=tuple.__new__, len=len):

result = new(cls, iterable)<EOL>if len(result) != <NUM_LIT:5>:<EOL><INDENT>raise TypeError('<STR_LIT>' % len(result))<EOL><DEDENT>return result<EOL>

Make a new SplitResult object from a sequence or iterable


return '<STR_LIT>' % self<EOL>

Return a nicely formatted representation string


return OrderedDict(list(zip(self._fields, self)))<EOL>

Return a new OrderedDict which maps field names to their values


result = _self._make(list(map(kwds.pop, ('<STR_LIT>', '<STR_LIT>', '<STR_LIT:path>', '<STR_LIT>', '<STR_LIT>'), _self)))<EOL>if kwds:<EOL><INDENT>raise ValueError('<STR_LIT>' % list(kwds.keys()))<EOL><DEDENT>return result<EOL>

Return a new SplitResult object replacing specified fields with new values


return tuple(self)<EOL>

Return self as a plain tuple.  Used by copy and pickle.


pass<EOL>


def __new__(_cls, scheme, netloc, path, params, query, fragment):

return _tuple.__new__(_cls, (scheme, netloc, path, params, query, fragment))<EOL>

Create new instance of ParseResult(scheme, netloc, path, params, query, fragment)


result = new(cls, iterable)<EOL>if len(result) != <NUM_LIT:6>:<EOL><INDENT>raise TypeError('<STR_LIT>' % len(result))<EOL><DEDENT>return result<EOL>

Make a new ParseResult object from a sequence or iterable


return '<STR_LIT>' % self<EOL>


result = _self._make(list(map(kwds.pop, ('<STR_LIT>', '<STR_LIT>', '<STR_LIT:path>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'), _self)))<EOL>if kwds:<EOL><INDENT>raise ValueError('<STR_LIT>' % list(kwds.keys()))<EOL><DEDENT>return result<EOL>

Return a new ParseResult object replacing specified fields with new values


return tuple(self)<EOL>


if c in '<STR_LIT>':<EOL><INDENT>return quotetabs<EOL><DEDENT>if c == '<STR_LIT:_>':<EOL><INDENT>return header<EOL><DEDENT>return c == ESCAPE or not ('<STR_LIT:U+0020>' <= c <= '<STR_LIT>')<EOL>

Decide whether a particular character needs to be quoted.

    The 'quotetabs' flag indicates whether embedded tabs and spaces should be
    quoted.  Note that line-ending tabs and spaces are always encoded, as per
    RFC 1521.


i = ord(c)<EOL>return ESCAPE + HEX[i//<NUM_LIT:16>] + HEX[i%<NUM_LIT:16>]<EOL>


def encode(input, output, quotetabs, header = <NUM_LIT:0>):

if b2a_qp is not None:<EOL><INDENT>data = input.read()<EOL>odata = b2a_qp(data, quotetabs = quotetabs, header = header)<EOL>output.write(odata)<EOL>return<EOL><DEDENT>def write(s, output=output, lineEnd='<STR_LIT:\n>'):<EOL><INDENT>if s and s[-<NUM_LIT:1>:] in '<STR_LIT>':<EOL><INDENT>output.write(s[:-<NUM_LIT:1>] + quote(s[-<NUM_LIT:1>]) + lineEnd)<EOL><DEDENT>elif s == '<STR_LIT:.>':<EOL><INDENT>output.write(quote(s) + lineEnd)<EOL><DEDENT>else:<EOL><INDENT>output.write(s + lineEnd)<EOL><DEDENT><DEDENT>prevline = None<EOL>while <NUM_LIT:1>:<EOL><INDENT>line = input.readline()<EOL>if not line:<EOL><INDENT>break<EOL><DEDENT>outline = []<EOL>stripped = '<STR_LIT>'<EOL>if line[-<NUM_LIT:1>:] == '<STR_LIT:\n>':<EOL><INDENT>line = line[:-<NUM_LIT:1>]<EOL>stripped = '<STR_LIT:\n>'<EOL><DEDENT>for c in line:<EOL><INDENT>if needsquoting(c, quotetabs, header):<EOL><INDENT>c = quote(c)<EOL><DEDENT>if header and c == '<STR_LIT:U+0020>':<EOL><INDENT>outline.append('<STR_LIT:_>')<EOL><DEDENT>else:<EOL><INDENT>outline.append(c)<EOL><DEDENT><DEDENT>if prevline is not None:<EOL><INDENT>write(prevline)<EOL><DEDENT>thisline = EMPTYSTRING.join(outline)<EOL>while len(thisline) > MAXLINESIZE:<EOL><INDENT>write(thisline[:MAXLINESIZE-<NUM_LIT:1>], lineEnd='<STR_LIT>')<EOL>thisline = thisline[MAXLINESIZE-<NUM_LIT:1>:]<EOL><DEDENT>prevline = thisline<EOL><DEDENT>if prevline is not None:<EOL><INDENT>write(prevline, lineEnd=stripped)<EOL><DEDENT>

Read 'input', apply quoted-printable encoding, and write to 'output'.

    'input' and 'output' are files with readline() and write() methods.
    The 'quotetabs' flag indicates whether embedded tabs and spaces should be
    quoted.  Note that line-ending tabs and spaces are always encoded, as per
    RFC 1521.
    The 'header' flag indicates whether we are encoding spaces as _ as per
    RFC 1522.


def decode(input, output, header = <NUM_LIT:0>):

if a2b_qp is not None:<EOL><INDENT>data = input.read()<EOL>odata = a2b_qp(data, header = header)<EOL>output.write(odata)<EOL>return<EOL><DEDENT>new = '<STR_LIT>'<EOL>while <NUM_LIT:1>:<EOL><INDENT>line = input.readline()<EOL>if not line: break<EOL>i, n = <NUM_LIT:0>, len(line)<EOL>if n > <NUM_LIT:0> and line[n-<NUM_LIT:1>] == '<STR_LIT:\n>':<EOL><INDENT>partial = <NUM_LIT:0>; n = n-<NUM_LIT:1><EOL>while n > <NUM_LIT:0> and line[n-<NUM_LIT:1>] in "<STR_LIT>":<EOL><INDENT>n = n-<NUM_LIT:1><EOL><DEDENT><DEDENT>else:<EOL><INDENT>partial = <NUM_LIT:1><EOL><DEDENT>while i < n:<EOL><INDENT>c = line[i]<EOL>if c == '<STR_LIT:_>' and header:<EOL><INDENT>new = new + '<STR_LIT:U+0020>'; i = i+<NUM_LIT:1><EOL><DEDENT>elif c != ESCAPE:<EOL><INDENT>new = new + c; i = i+<NUM_LIT:1><EOL><DEDENT>elif i+<NUM_LIT:1> == n and not partial:<EOL><INDENT>partial = <NUM_LIT:1>; break<EOL><DEDENT>elif i+<NUM_LIT:1> < n and line[i+<NUM_LIT:1>] == ESCAPE:<EOL><INDENT>new = new + ESCAPE; i = i+<NUM_LIT:2><EOL><DEDENT>elif i+<NUM_LIT:2> < n and ishex(line[i+<NUM_LIT:1>]) and ishex(line[i+<NUM_LIT:2>]):<EOL><INDENT>new = new + chr(unhex(line[i+<NUM_LIT:1>:i+<NUM_LIT:3>])); i = i+<NUM_LIT:3><EOL><DEDENT>else: <EOL><INDENT>new = new + c; i = i+<NUM_LIT:1><EOL><DEDENT><DEDENT>if not partial:<EOL><INDENT>output.write(new + '<STR_LIT:\n>')<EOL>new = '<STR_LIT>'<EOL><DEDENT><DEDENT>if new:<EOL><INDENT>output.write(new)<EOL><DEDENT>

Read 'input', apply quoted-printable decoding, and write to 'output'.
    'input' and 'output' are files with readline() and write() methods.
    If 'header' is true, decode underscore as space (per RFC 1522).


return '<STR_LIT:0>' <= c <= '<STR_LIT>' or '<STR_LIT:a>' <= c <= '<STR_LIT:f>' or '<STR_LIT:A>' <= c <= '<STR_LIT:F>'<EOL>

Return true if the character 'c' is a hexadecimal digit.


bits = <NUM_LIT:0><EOL>for c in s:<EOL><INDENT>if '<STR_LIT:0>' <= c <= '<STR_LIT>':<EOL><INDENT>i = ord('<STR_LIT:0>')<EOL><DEDENT>elif '<STR_LIT:a>' <= c <= '<STR_LIT:f>':<EOL><INDENT>i = ord('<STR_LIT:a>')-<NUM_LIT:10><EOL><DEDENT>elif '<STR_LIT:A>' <= c <= '<STR_LIT:F>':<EOL><INDENT>i = ord('<STR_LIT:A>')-<NUM_LIT:10><EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT>bits = bits*<NUM_LIT:16> + (ord(c) - i)<EOL><DEDENT>return bits<EOL>

Get the integer value of a hexadecimal number.


<EOL>encoded = binascii.b2a_base64(s)[:-<NUM_LIT:1>]<EOL>if altchars is not None:<EOL><INDENT>return encoded.translate(string.maketrans(b'<STR_LIT>', altchars[:<NUM_LIT:2>]))<EOL><DEDENT>return encoded<EOL>

Encode a string using Base64.

    s is the string to encode.  Optional altchars must be a string of at least
    length 2 (additional characters are ignored) which specifies an
    alternative alphabet for the '+' and '/' characters.  This allows an
    application to e.g. generate url or filesystem safe Base64 strings.

    The encoded string is returned.


if altchars is not None:<EOL><INDENT>s = s.translate(string.maketrans(altchars[:<NUM_LIT:2>], '<STR_LIT>'))<EOL><DEDENT>try:<EOL><INDENT>return binascii.a2b_base64(s)<EOL><DEDENT>except binascii.Error as msg:<EOL><INDENT>raise TypeError(msg)<EOL><DEDENT>

Decode a Base64 encoded string.

    s is the string to decode.  Optional altchars must be a string of at least
    length 2 (additional characters are ignored) which specifies the
    alternative alphabet used instead of the '+' and '/' characters.

    The decoded string is returned.  A TypeError is raised if s is
    incorrectly padded.  Characters that are neither in the normal base-64
    alphabet nor the alternative alphabet are discarded prior to the padding
    check.


return b64encode(s)<EOL>

Encode a string using the standard Base64 alphabet.

    s is the string to encode.  The encoded string is returned.


return b64decode(s)<EOL>

Decode a string encoded with the standard Base64 alphabet.

    Argument s is the string to decode.  The decoded string is returned.  A
    TypeError is raised if the string is incorrectly padded.  Characters that
    are not in the standard alphabet are discarded prior to the padding
    check.


return b64encode(s).translate(_urlsafe_encode_translation)<EOL>

Encode a string using the URL- and filesystem-safe Base64 alphabet.

    Argument s is the string to encode.  The encoded string is returned.  The
    alphabet uses '-' instead of '+' and '_' instead of '/'.


return b64decode(s.translate(_urlsafe_decode_translation))<EOL>

Decode a string using the URL- and filesystem-safe Base64 alphabet.

    Argument s is the string to decode.  The decoded string is returned.  A
    TypeError is raised if the string is incorrectly padded.  Characters that
    are not in the URL-safe base-64 alphabet, and are not a plus '+' or slash
    '/', are discarded prior to the padding check.

    The alphabet uses '-' instead of '+' and '_' instead of '/'.


parts = []<EOL>quanta, leftover = divmod(len(s), <NUM_LIT:5>)<EOL>if leftover:<EOL><INDENT>s += ('<STR_LIT>' * (<NUM_LIT:5> - leftover))<EOL>quanta += <NUM_LIT:1><EOL><DEDENT>for i in range(quanta):<EOL><INDENT>c1, c2, c3 = struct.unpack('<STR_LIT>', s[i*<NUM_LIT:5>:(i+<NUM_LIT:1>)*<NUM_LIT:5>])<EOL>c2 += (c1 & <NUM_LIT:1>) << <NUM_LIT:16> <EOL>c3 += (c2 & <NUM_LIT:3>) << <NUM_LIT:8>  <EOL>parts.extend([_b32tab[c1 >> <NUM_LIT:11>],         <EOL>_b32tab[(c1 >> <NUM_LIT:6>) & <NUM_LIT>], <EOL>_b32tab[(c1 >> <NUM_LIT:1>) & <NUM_LIT>], <EOL>_b32tab[c2 >> <NUM_LIT:12>],         <EOL>_b32tab[(c2 >> <NUM_LIT:7>) & <NUM_LIT>], <EOL>_b32tab[(c2 >> <NUM_LIT:2>) & <NUM_LIT>], <EOL>_b32tab[c3 >> <NUM_LIT:5>],          <EOL>_b32tab[c3 & <NUM_LIT>],        <EOL>])<EOL><DEDENT>encoded = EMPTYSTRING.join(parts)<EOL>if leftover == <NUM_LIT:1>:<EOL><INDENT>return encoded[:-<NUM_LIT:6>] + '<STR_LIT>'<EOL><DEDENT>elif leftover == <NUM_LIT:2>:<EOL><INDENT>return encoded[:-<NUM_LIT:4>] + '<STR_LIT>'<EOL><DEDENT>elif leftover == <NUM_LIT:3>:<EOL><INDENT>return encoded[:-<NUM_LIT:3>] + '<STR_LIT>'<EOL><DEDENT>elif leftover == <NUM_LIT:4>:<EOL><INDENT>return encoded[:-<NUM_LIT:1>] + '<STR_LIT:=>'<EOL><DEDENT>return encoded<EOL>

Encode a string using Base32.

    s is the string to encode.  The encoded string is returned.


def b32decode(s, casefold=False, map01=None):

quanta, leftover = divmod(len(s), <NUM_LIT:8>)<EOL>if leftover:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>if map01:<EOL><INDENT>s = s.translate(string.maketrans(b'<STR_LIT>', b'<STR_LIT:O>' + map01))<EOL><DEDENT>if casefold:<EOL><INDENT>s = s.upper()<EOL><DEDENT>padchars = <NUM_LIT:0><EOL>mo = re.search('<STR_LIT>', s)<EOL>if mo:<EOL><INDENT>padchars = len(mo.group('<STR_LIT>'))<EOL>if padchars > <NUM_LIT:0>:<EOL><INDENT>s = s[:-padchars]<EOL><DEDENT><DEDENT>parts = []<EOL>acc = <NUM_LIT:0><EOL>shift = <NUM_LIT><EOL>for c in s:<EOL><INDENT>val = _b32rev.get(c)<EOL>if val is None:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>acc += _b32rev[c] << shift<EOL>shift -= <NUM_LIT:5><EOL>if shift < <NUM_LIT:0>:<EOL><INDENT>parts.append(binascii.unhexlify('<STR_LIT>' % acc))<EOL>acc = <NUM_LIT:0><EOL>shift = <NUM_LIT><EOL><DEDENT><DEDENT>last = binascii.unhexlify('<STR_LIT>' % acc)<EOL>if padchars == <NUM_LIT:0>:<EOL><INDENT>last = '<STR_LIT>'                       <EOL><DEDENT>elif padchars == <NUM_LIT:1>:<EOL><INDENT>last = last[:-<NUM_LIT:1>]<EOL><DEDENT>elif padchars == <NUM_LIT:3>:<EOL><INDENT>last = last[:-<NUM_LIT:2>]<EOL><DEDENT>elif padchars == <NUM_LIT:4>:<EOL><INDENT>last = last[:-<NUM_LIT:3>]<EOL><DEDENT>elif padchars == <NUM_LIT:6>:<EOL><INDENT>last = last[:-<NUM_LIT:4>]<EOL><DEDENT>else:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>parts.append(last)<EOL>return EMPTYSTRING.join(parts)<EOL>

Decode a Base32 encoded string.

    s is the string to decode.  Optional casefold is a flag specifying whether
    a lowercase alphabet is acceptable as input.  For security purposes, the
    default is False.

    RFC 3548 allows for optional mapping of the digit 0 (zero) to the letter O
    (oh), and for optional mapping of the digit 1 (one) to either the letter I
    (eye) or letter L (el).  The optional argument map01 when not None,
    specifies which letter the digit 1 should be mapped to (when map01 is not
    None, the digit 0 is always mapped to the letter O).  For security
    purposes the default is None, so that 0 and 1 are not allowed in the
    input.

    The decoded string is returned.  A TypeError is raised if s were
    incorrectly padded or if there are non-alphabet characters present in the
    string.


return binascii.hexlify(s).upper()<EOL>

Encode a string using Base16.

    s is the string to encode.  The encoded string is returned.


if casefold:<EOL><INDENT>s = s.upper()<EOL><DEDENT>if re.search('<STR_LIT>', s):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>return binascii.unhexlify(s)<EOL>

Decode a Base16 encoded string.

    s is the string to decode.  Optional casefold is a flag specifying whether
    a lowercase alphabet is acceptable as input.  For security purposes, the
    default is False.

    The decoded string is returned.  A TypeError is raised if s is
    incorrectly padded or if there are non-alphabet characters present in the
    string.


while True:<EOL><INDENT>s = input.read(MAXBINSIZE)<EOL>if not s:<EOL><INDENT>break<EOL><DEDENT>while len(s) < MAXBINSIZE:<EOL><INDENT>ns = input.read(MAXBINSIZE-len(s))<EOL>if not ns:<EOL><INDENT>break<EOL><DEDENT>s += ns<EOL><DEDENT>line = binascii.b2a_base64(s)<EOL>output.write(line)<EOL><DEDENT>


while True:<EOL><INDENT>line = input.readline()<EOL>if not line:<EOL><INDENT>break<EOL><DEDENT>s = binascii.a2b_base64(line)<EOL>output.write(s)<EOL><DEDENT>


pieces = []<EOL>for i in range(<NUM_LIT:0>, len(s), MAXBINSIZE):<EOL><INDENT>chunk = s[i : i + MAXBINSIZE]<EOL>pieces.append(binascii.b2a_base64(chunk))<EOL><DEDENT>return "<STR_LIT>".join(pieces)<EOL>

Encode a string into multiple lines of base-64 data.


return binascii.a2b_base64(s)<EOL>


<EOL>names = cls.__dict__.get("<STR_LIT>")<EOL>if names is not None:<EOL><INDENT>return names<EOL><DEDENT>names = []<EOL>if not hasattr(cls, "<STR_LIT>"):<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>for c in cls.__mro__:<EOL><INDENT>if "<STR_LIT>" in c.__dict__:<EOL><INDENT>slots = c.__dict__['<STR_LIT>']<EOL>if isinstance(slots, str):<EOL><INDENT>slots = (slots,)<EOL><DEDENT>for name in slots:<EOL><INDENT>if name in ("<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>continue<EOL><DEDENT>elif name.startswith('<STR_LIT>') and not name.endswith('<STR_LIT>'):<EOL><INDENT>names.append('<STR_LIT>' % (c.__name__, name))<EOL><DEDENT>else:<EOL><INDENT>names.append(name)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>try:<EOL><INDENT>cls.__slotnames__ = names<EOL><DEDENT>except:<EOL><INDENT>pass <EOL><DEDENT>return names<EOL>

Return a list of slot names for a given class.

    This needs to find slots defined by the class and its bases, so we
    can't simply return the __slots__ attribute.  We must walk down
    the Method Resolution Order and concatenate the __slots__ of each
    class found there.  (This assumes classes don't modify their
    __slots__ attribute to misrepresent their slots after the class is
    defined.)


code = int(code)<EOL>if not <NUM_LIT:1> <= code <= <NUM_LIT>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>key = (module, name)<EOL>if (_extension_registry.get(key) == code and<EOL>_inverted_registry.get(code) == key):<EOL><INDENT>return <EOL><DEDENT>if key in _extension_registry:<EOL><INDENT>raise ValueError("<STR_LIT>" %<EOL>(key, _extension_registry[key]))<EOL><DEDENT>if code in _inverted_registry:<EOL><INDENT>raise ValueError("<STR_LIT>" %<EOL>(code, _inverted_registry[code]))<EOL><DEDENT>_extension_registry[key] = code<EOL>_inverted_registry[code] = key<EOL>


def remove_extension(module, name, code):

key = (module, name)<EOL>if (_extension_registry.get(key) != code or<EOL>_inverted_registry.get(code) != key):<EOL><INDENT>raise ValueError("<STR_LIT>" %<EOL>(key, code))<EOL><DEDENT>del _extension_registry[key]<EOL>del _inverted_registry[code]<EOL>if code in _extension_cache:<EOL><INDENT>del _extension_cache[code]<EOL><DEDENT>

Unregister an extension code.  For testing only.


self.all_tasks_done.acquire()<EOL>try:<EOL><INDENT>unfinished = self.unfinished_tasks - <NUM_LIT:1><EOL>if unfinished <= <NUM_LIT:0>:<EOL><INDENT>if unfinished < <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>self.all_tasks_done.notify_all()<EOL><DEDENT>self.unfinished_tasks = unfinished<EOL><DEDENT>finally:<EOL><INDENT>self.all_tasks_done.release()<EOL><DEDENT>

Indicate that a formerly enqueued task is complete.

        Used by Queue consumer threads.  For each get() used to fetch a task,
        a subsequent call to task_done() tells the queue that the processing
        on the task is complete.

        If a join() is currently blocking, it will resume when all items
        have been processed (meaning that a task_done() call was received
        for every item that had been put() into the queue).

        Raises a ValueError if called more times than there were items
        placed in the queue.


Blocks until all items in the Queue have been gotten and processed.

        The count of unfinished tasks goes up whenever an item is added to the
        queue. The count goes down whenever a consumer thread calls task_done()
        to indicate the item was retrieved and all work on it is complete.

        When the count of unfinished tasks drops to zero, join() unblocks.


self.mutex.acquire()<EOL>n = self._qsize()<EOL>self.mutex.release()<EOL>return n<EOL>

Return the approximate size of the queue (not reliable!).


self.mutex.acquire()<EOL>n = not self._qsize()<EOL>self.mutex.release()<EOL>return n<EOL>

Return True if the queue is empty, False otherwise (not reliable!).


self.mutex.acquire()<EOL>n = <NUM_LIT:0> < self.maxsize == self._qsize()<EOL>self.mutex.release()<EOL>return n<EOL>

Return True if the queue is full, False otherwise (not reliable!).


def put(self, item, block=True, timeout=None):

self.not_full.acquire()<EOL>try:<EOL><INDENT>if self.maxsize > <NUM_LIT:0>:<EOL><INDENT>if not block:<EOL><INDENT>if self._qsize() == self.maxsize:<EOL><INDENT>raise Full<EOL><DEDENT><DEDENT>elif timeout is None:<EOL><INDENT>while self._qsize() == self.maxsize:<EOL><INDENT>self.not_full.wait()<EOL><DEDENT><DEDENT>elif timeout < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>endtime = _time() + timeout<EOL>while self._qsize() == self.maxsize:<EOL><INDENT>remaining = endtime - _time()<EOL>if remaining <= <NUM_LIT:0.0>:<EOL><INDENT>raise Full<EOL><DEDENT>self.not_full.wait(remaining)<EOL><DEDENT><DEDENT><DEDENT>self._put(item)<EOL>self.unfinished_tasks += <NUM_LIT:1><EOL>self.not_empty.notify()<EOL><DEDENT>finally:<EOL><INDENT>self.not_full.release()<EOL><DEDENT>

Put an item into the queue.

        If optional args 'block' is true and 'timeout' is None (the default),
        block if necessary until a free slot is available. If 'timeout' is
        a non-negative number, it blocks at most 'timeout' seconds and raises
        the Full exception if no free slot was available within that time.
        Otherwise ('block' is false), put an item on the queue if a free slot
        is immediately available, else raise the Full exception ('timeout'
        is ignored in that case).


return self.put(item, False)<EOL>

Put an item into the queue without blocking.

        Only enqueue the item if a free slot is immediately available.
        Otherwise raise the Full exception.


def get(self, block=True, timeout=None):

self.not_empty.acquire()<EOL>try:<EOL><INDENT>if not block:<EOL><INDENT>if not self._qsize():<EOL><INDENT>raise Empty<EOL><DEDENT><DEDENT>elif timeout is None:<EOL><INDENT>while not self._qsize():<EOL><INDENT>self.not_empty.wait()<EOL><DEDENT><DEDENT>elif timeout < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>endtime = _time() + timeout<EOL>while not self._qsize():<EOL><INDENT>remaining = endtime - _time()<EOL>if remaining <= <NUM_LIT:0.0>:<EOL><INDENT>raise Empty<EOL><DEDENT>self.not_empty.wait(remaining)<EOL><DEDENT><DEDENT>item = self._get()<EOL>self.not_full.notify()<EOL>return item<EOL><DEDENT>finally:<EOL><INDENT>self.not_empty.release()<EOL><DEDENT>

Remove and return an item from the queue.

        If optional args 'block' is true and 'timeout' is None (the default),
        block if necessary until an item is available. If 'timeout' is
        a non-negative number, it blocks at most 'timeout' seconds and raises
        the Empty exception if no item was available within that time.
        Otherwise ('block' is false), return an item if one is immediately
        available, else raise the Empty exception ('timeout' is ignored
        in that case).


return self.get(False)<EOL>

Remove and return an item from the queue without blocking.

        Only get an item if one is immediately available. Otherwise
        raise the Empty exception.


def get_close_matches(word, possibilities, n=<NUM_LIT:3>, cutoff=<NUM_LIT>):

if not n >  <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>" % (n,))<EOL><DEDENT>if not <NUM_LIT:0.0> <= cutoff <= <NUM_LIT:1.0>:<EOL><INDENT>raise ValueError("<STR_LIT>" % (cutoff,))<EOL><DEDENT>result = []<EOL>s = SequenceMatcher()<EOL>s.set_seq2(word)<EOL>for x in possibilities:<EOL><INDENT>s.set_seq1(x)<EOL>if s.real_quick_ratio() >= cutoff ands.quick_ratio() >= cutoff ands.ratio() >= cutoff:<EOL><INDENT>result.append((s.ratio(), x))<EOL><DEDENT><DEDENT>result = heapq.nlargest(n, result)<EOL>return [x for score, x in result]<EOL>

Use SequenceMatcher to return list of the best "good enough" matches.

    word is a sequence for which close matches are desired (typically a
    string).

    possibilities is a list of sequences against which to match word
    (typically a list of strings).

    Optional arg n (default 3) is the maximum number of close matches to
    return.  n must be > 0.

    Optional arg cutoff (default 0.6) is a float in [0, 1].  Possibilities
    that don't score at least that similar to word are ignored.

    The best (no more than n) matches among the possibilities are returned
    in a list, sorted by similarity score, most similar first.

    >>> get_close_matches("appel", ["ape", "apple", "peach", "puppy"])
    ['apple', 'ape']
    >>> import keyword as _keyword
    >>> get_close_matches("wheel", _keyword.kwlist)
    ['while']
    >>> get_close_matches("apple", _keyword.kwlist)
    []
    >>> get_close_matches("accept", _keyword.kwlist)
    ['except']


i, n = <NUM_LIT:0>, len(line)<EOL>while i < n and line[i] == ch:<EOL><INDENT>i += <NUM_LIT:1><EOL><DEDENT>return i<EOL>

Return number of `ch` characters at the start of `line`.

Example:

>>> _count_leading('   abc', ' ')
3


return pat(line) is not None<EOL>

r"""
    Return 1 for ignorable line: iff `line` is blank or contains a single '#'.

    Examples:

    >>> IS_LINE_JUNK('\n')
    True
    >>> IS_LINE_JUNK('  #   \n')
    True
    >>> IS_LINE_JUNK('hello\n')
    False


return ch in ws<EOL>

r"""
    Return 1 for ignorable character: iff `ch` is a space or tab.

    Examples:

    >>> IS_CHARACTER_JUNK(' ')
    True
    >>> IS_CHARACTER_JUNK('\t')
    True
    >>> IS_CHARACTER_JUNK('\n')
    False
    >>> IS_CHARACTER_JUNK('x')
    False


<EOL>beginning = start + <NUM_LIT:1>     <EOL>length = stop - start<EOL>if length == <NUM_LIT:1>:<EOL><INDENT>return '<STR_LIT:%s>' % (beginning)<EOL><DEDENT>if not length:<EOL><INDENT>beginning -= <NUM_LIT:1>        <EOL><DEDENT>return '<STR_LIT>' % (beginning, length)<EOL>


def unified_diff(a, b, fromfile='<STR_LIT>', tofile='<STR_LIT>', fromfiledate='<STR_LIT>',<EOL>tofiledate='<STR_LIT>', n=<NUM_LIT:3>, lineterm='<STR_LIT:\n>'):

started = False<EOL>for group in SequenceMatcher(None,a,b).get_grouped_opcodes(n):<EOL><INDENT>if not started:<EOL><INDENT>started = True<EOL>fromdate = '<STR_LIT>' % (fromfiledate) if fromfiledate else '<STR_LIT>'<EOL>todate = '<STR_LIT>' % (tofiledate) if tofiledate else '<STR_LIT>'<EOL>yield '<STR_LIT>' % (fromfile, fromdate, lineterm)<EOL>yield '<STR_LIT>' % (tofile, todate, lineterm)<EOL><DEDENT>first, last = group[<NUM_LIT:0>], group[-<NUM_LIT:1>]<EOL>file1_range = _format_range_unified(first[<NUM_LIT:1>], last[<NUM_LIT:2>])<EOL>file2_range = _format_range_unified(first[<NUM_LIT:3>], last[<NUM_LIT:4>])<EOL>yield '<STR_LIT>' % (file1_range, file2_range, lineterm)<EOL>for tag, i1, i2, j1, j2 in group:<EOL><INDENT>if tag == '<STR_LIT>':<EOL><INDENT>for line in a[i1:i2]:<EOL><INDENT>yield '<STR_LIT:U+0020>' + line<EOL><DEDENT>continue<EOL><DEDENT>if tag in ('<STR_LIT:replace>', '<STR_LIT>'):<EOL><INDENT>for line in a[i1:i2]:<EOL><INDENT>yield '<STR_LIT:->' + line<EOL><DEDENT><DEDENT>if tag in ('<STR_LIT:replace>', '<STR_LIT>'):<EOL><INDENT>for line in b[j1:j2]:<EOL><INDENT>yield '<STR_LIT:+>' + line<EOL><DEDENT><DEDENT><DEDENT><DEDENT>

r"""
    Compare two sequences of lines; generate the delta as a unified diff.

    Unified diffs are a compact way of showing line changes and a few
    lines of context.  The number of context lines is set by 'n' which
    defaults to three.

    By default, the diff control lines (those with ---, +++, or @@) are
    created with a trailing newline.  This is helpful so that inputs
    created from file.readlines() result in diffs that are suitable for
    file.writelines() since both the inputs and outputs have trailing
    newlines.

    For inputs that do not have trailing newlines, set the lineterm
    argument to "" so that the output will be uniformly newline free.

    The unidiff format normally has a header for filenames and modification
    times.  Any or all of these may be specified using strings for
    'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'.
    The modification times are normally expressed in the ISO 8601 format.

    Example:

    >>> for line in unified_diff('one two three four'.split(),
    ...             'zero one tree four'.split(), 'Original', 'Current',
    ...             '2005-01-26 23:30:50', '2010-04-02 10:20:52',
    ...             lineterm=''):
    ...     print line                  # doctest: +NORMALIZE_WHITESPACE
    --- Original        2005-01-26 23:30:50
    +++ Current         2010-04-02 10:20:52
    @@ -1,4 +1,4 @@
    +zero
     one
    -two
    -three
    +tree
     four


<EOL>beginning = start + <NUM_LIT:1>     <EOL>length = stop - start<EOL>if not length:<EOL><INDENT>beginning -= <NUM_LIT:1>        <EOL><DEDENT>if length <= <NUM_LIT:1>:<EOL><INDENT>return '<STR_LIT:%s>' % (beginning)<EOL><DEDENT>return '<STR_LIT>' % (beginning, beginning + length - <NUM_LIT:1>)<EOL>


def context_diff(a, b, fromfile='<STR_LIT>', tofile='<STR_LIT>',<EOL>fromfiledate='<STR_LIT>', tofiledate='<STR_LIT>', n=<NUM_LIT:3>, lineterm='<STR_LIT:\n>'):

prefix = dict(insert='<STR_LIT>', delete='<STR_LIT>', replace='<STR_LIT>', equal='<STR_LIT:U+0020>')<EOL>started = False<EOL>for group in SequenceMatcher(None,a,b).get_grouped_opcodes(n):<EOL><INDENT>if not started:<EOL><INDENT>started = True<EOL>fromdate = '<STR_LIT>' % (fromfiledate) if fromfiledate else '<STR_LIT>'<EOL>todate = '<STR_LIT>' % (tofiledate) if tofiledate else '<STR_LIT>'<EOL>yield '<STR_LIT>' % (fromfile, fromdate, lineterm)<EOL>yield '<STR_LIT>' % (tofile, todate, lineterm)<EOL><DEDENT>first, last = group[<NUM_LIT:0>], group[-<NUM_LIT:1>]<EOL>yield '<STR_LIT>' + lineterm<EOL>file1_range = _format_range_context(first[<NUM_LIT:1>], last[<NUM_LIT:2>])<EOL>yield '<STR_LIT>' % (file1_range, lineterm)<EOL>if any(tag in ('<STR_LIT:replace>', '<STR_LIT>') for tag, _, _, _, _ in group):<EOL><INDENT>for tag, i1, i2, _, _ in group:<EOL><INDENT>if tag != '<STR_LIT>':<EOL><INDENT>for line in a[i1:i2]:<EOL><INDENT>yield prefix[tag] + line<EOL><DEDENT><DEDENT><DEDENT><DEDENT>file2_range = _format_range_context(first[<NUM_LIT:3>], last[<NUM_LIT:4>])<EOL>yield '<STR_LIT>' % (file2_range, lineterm)<EOL>if any(tag in ('<STR_LIT:replace>', '<STR_LIT>') for tag, _, _, _, _ in group):<EOL><INDENT>for tag, _, _, j1, j2 in group:<EOL><INDENT>if tag != '<STR_LIT>':<EOL><INDENT>for line in b[j1:j2]:<EOL><INDENT>yield prefix[tag] + line<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>

r"""
    Compare two sequences of lines; generate the delta as a context diff.

    Context diffs are a compact way of showing line changes and a few
    lines of context.  The number of context lines is set by 'n' which
    defaults to three.

    By default, the diff control lines (those with *** or ---) are
    created with a trailing newline.  This is helpful so that inputs
    created from file.readlines() result in diffs that are suitable for
    file.writelines() since both the inputs and outputs have trailing
    newlines.

    For inputs that do not have trailing newlines, set the lineterm
    argument to "" so that the output will be uniformly newline free.

    The context diff format normally has a header for filenames and
    modification times.  Any or all of these may be specified using
    strings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'.
    The modification times are normally expressed in the ISO 8601 format.
    If not specified, the strings default to blanks.

    Example:

    >>> print ''.join(context_diff('one\ntwo\nthree\nfour\n'.splitlines(1),
    ...       'zero\none\ntree\nfour\n'.splitlines(1), 'Original', 'Current')),
    *** Original
    --- Current
    ***************
    *** 1,4 ****
      one
    ! two
    ! three
      four
    --- 1,4 ----
    + zero
      one
    ! tree
      four


def ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK):

return Differ(linejunk, charjunk).compare(a, b)<EOL>

r"""
    Compare `a` and `b` (lists of strings); return a `Differ`-style delta.

    Optional keyword parameters `linejunk` and `charjunk` are for filter
    functions (or None):

    - linejunk: A function that should accept a single string argument, and
      return true iff the string is junk.  The default is None, and is
      recommended; as of Python 2.3, an adaptive notion of "noise" lines is
      used that does a good job on its own.

    - charjunk: A function that should accept a string of length 1. The
      default is module-level function IS_CHARACTER_JUNK, which filters out
      whitespace characters (a blank or tab; note: bad idea to include newline
      in this!).

    Tools/scripts/ndiff.py is a command-line front-end to this function.

    Example:

    >>> diff = ndiff('one\ntwo\nthree\n'.splitlines(1),
    ...              'ore\ntree\nemu\n'.splitlines(1))
    >>> print ''.join(diff),
    - one
    ?  ^
    + ore
    ?  ^
    - two
    - three
    ?  -
    + tree
    + emu


def _mdiff(fromlines, tolines, context=None, linejunk=None,<EOL>charjunk=IS_CHARACTER_JUNK):

import re<EOL>change_re = re.compile('<STR_LIT>')<EOL>diff_lines_iterator = ndiff(fromlines,tolines,linejunk,charjunk)<EOL>def _make_line(lines, format_key, side, num_lines=[<NUM_LIT:0>,<NUM_LIT:0>]):<EOL><INDENT>"""<STR_LIT>"""<EOL>num_lines[side] += <NUM_LIT:1><EOL>if format_key is None:<EOL><INDENT>return (num_lines[side],lines.pop(<NUM_LIT:0>)[<NUM_LIT:2>:])<EOL><DEDENT>if format_key == '<STR_LIT:?>':<EOL><INDENT>text, markers = lines.pop(<NUM_LIT:0>), lines.pop(<NUM_LIT:0>)<EOL>sub_info = []<EOL>def record_sub_info(match_object,sub_info=sub_info):<EOL><INDENT>sub_info.append([match_object.group(<NUM_LIT:1>)[<NUM_LIT:0>],match_object.span()])<EOL>return match_object.group(<NUM_LIT:1>)<EOL><DEDENT>change_re.sub(record_sub_info,markers)<EOL>for key,(begin,end) in sub_info[::-<NUM_LIT:1>]:<EOL><INDENT>text = text[<NUM_LIT:0>:begin]+'<STR_LIT>'+key+text[begin:end]+'<STR_LIT>'+text[end:]<EOL><DEDENT>text = text[<NUM_LIT:2>:]<EOL><DEDENT>else:<EOL><INDENT>text = lines.pop(<NUM_LIT:0>)[<NUM_LIT:2>:]<EOL>if not text:<EOL><INDENT>text = '<STR_LIT:U+0020>'<EOL><DEDENT>text = '<STR_LIT>' + format_key + text + '<STR_LIT>'<EOL><DEDENT>return (num_lines[side],text)<EOL><DEDENT>def _line_iterator():<EOL><INDENT>"""<STR_LIT>"""<EOL>lines = []<EOL>num_blanks_pending, num_blanks_to_yield = <NUM_LIT:0>, <NUM_LIT:0><EOL>while True:<EOL><INDENT>while len(lines) < <NUM_LIT:4>:<EOL><INDENT>try:<EOL><INDENT>lines.append(next(diff_lines_iterator))<EOL><DEDENT>except StopIteration:<EOL><INDENT>lines.append('<STR_LIT:X>')<EOL><DEDENT><DEDENT>s = '<STR_LIT>'.join([line[<NUM_LIT:0>] for line in lines])<EOL>if s.startswith('<STR_LIT:X>'):<EOL><INDENT>num_blanks_to_yield = num_blanks_pending<EOL><DEDENT>elif s.startswith('<STR_LIT>'):<EOL><INDENT>yield _make_line(lines,'<STR_LIT:?>',<NUM_LIT:0>), _make_line(lines,'<STR_LIT:?>',<NUM_LIT:1>), True<EOL>continue<EOL><DEDENT>elif s.startswith('<STR_LIT>'):<EOL><INDENT>num_blanks_pending -= <NUM_LIT:1><EOL>yield _make_line(lines,'<STR_LIT:->',<NUM_LIT:0>), None, True<EOL>continue<EOL><DEDENT>elif s.startswith(('<STR_LIT>', '<STR_LIT>', '<STR_LIT>')):<EOL><INDENT>from_line,to_line = _make_line(lines,'<STR_LIT:->',<NUM_LIT:0>), None<EOL>num_blanks_to_yield,num_blanks_pending = num_blanks_pending-<NUM_LIT:1>,<NUM_LIT:0><EOL><DEDENT>elif s.startswith('<STR_LIT>'):<EOL><INDENT>yield _make_line(lines,None,<NUM_LIT:0>), _make_line(lines,'<STR_LIT:?>',<NUM_LIT:1>), True<EOL>continue<EOL><DEDENT>elif s.startswith('<STR_LIT>'):<EOL><INDENT>yield _make_line(lines,'<STR_LIT:?>',<NUM_LIT:0>), _make_line(lines,None,<NUM_LIT:1>), True<EOL>continue<EOL><DEDENT>elif s.startswith('<STR_LIT:->'):<EOL><INDENT>num_blanks_pending -= <NUM_LIT:1><EOL>yield _make_line(lines,'<STR_LIT:->',<NUM_LIT:0>), None, True<EOL>continue<EOL><DEDENT>elif s.startswith('<STR_LIT>'):<EOL><INDENT>num_blanks_pending += <NUM_LIT:1><EOL>yield None, _make_line(lines,'<STR_LIT:+>',<NUM_LIT:1>), True<EOL>continue<EOL><DEDENT>elif s.startswith(('<STR_LIT>', '<STR_LIT>')):<EOL><INDENT>from_line, to_line = None, _make_line(lines,'<STR_LIT:+>',<NUM_LIT:1>)<EOL>num_blanks_to_yield,num_blanks_pending = num_blanks_pending+<NUM_LIT:1>,<NUM_LIT:0><EOL><DEDENT>elif s.startswith('<STR_LIT:+>'):<EOL><INDENT>num_blanks_pending += <NUM_LIT:1><EOL>yield None, _make_line(lines,'<STR_LIT:+>',<NUM_LIT:1>), True<EOL>continue<EOL><DEDENT>elif s.startswith('<STR_LIT:U+0020>'):<EOL><INDENT>yield _make_line(lines[:],None,<NUM_LIT:0>),_make_line(lines,None,<NUM_LIT:1>),False<EOL>continue<EOL><DEDENT>while(num_blanks_to_yield < <NUM_LIT:0>):<EOL><INDENT>num_blanks_to_yield += <NUM_LIT:1><EOL>yield None,('<STR_LIT>','<STR_LIT:\n>'),True<EOL><DEDENT>while(num_blanks_to_yield > <NUM_LIT:0>):<EOL><INDENT>num_blanks_to_yield -= <NUM_LIT:1><EOL>yield ('<STR_LIT>','<STR_LIT:\n>'),None,True<EOL><DEDENT>if s.startswith('<STR_LIT:X>'):<EOL><INDENT>raise StopIteration<EOL><DEDENT>else:<EOL><INDENT>yield from_line,to_line,True<EOL><DEDENT><DEDENT><DEDENT>def _line_pair_iterator():<EOL><INDENT>"""<STR_LIT>"""<EOL>line_iterator = _line_iterator()<EOL>fromlines,tolines=[],[]<EOL>while True:<EOL><INDENT>while (len(fromlines)==<NUM_LIT:0> or len(tolines)==<NUM_LIT:0>):<EOL><INDENT>from_line, to_line, found_diff =next(line_iterator)<EOL>if from_line is not None:<EOL><INDENT>fromlines.append((from_line,found_diff))<EOL><DEDENT>if to_line is not None:<EOL><INDENT>tolines.append((to_line,found_diff))<EOL><DEDENT><DEDENT>from_line, fromDiff = fromlines.pop(<NUM_LIT:0>)<EOL>to_line, to_diff = tolines.pop(<NUM_LIT:0>)<EOL>yield (from_line,to_line,fromDiff or to_diff)<EOL><DEDENT><DEDENT>line_pair_iterator = _line_pair_iterator()<EOL>if context is None:<EOL><INDENT>while True:<EOL><INDENT>yield next(line_pair_iterator)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>context += <NUM_LIT:1><EOL>lines_to_write = <NUM_LIT:0><EOL>while True:<EOL><INDENT>index, contextLines = <NUM_LIT:0>, [None]*(context)<EOL>found_diff = False<EOL>while(found_diff is False):<EOL><INDENT>from_line, to_line, found_diff = next(line_pair_iterator)<EOL>i = index % context<EOL>contextLines[i] = (from_line, to_line, found_diff)<EOL>index += <NUM_LIT:1><EOL><DEDENT>if index > context:<EOL><INDENT>yield None, None, None<EOL>lines_to_write = context<EOL><DEDENT>else:<EOL><INDENT>lines_to_write = index<EOL>index = <NUM_LIT:0><EOL><DEDENT>while(lines_to_write):<EOL><INDENT>i = index % context<EOL>index += <NUM_LIT:1><EOL>yield contextLines[i]<EOL>lines_to_write -= <NUM_LIT:1><EOL><DEDENT>lines_to_write = context-<NUM_LIT:1><EOL>while(lines_to_write):<EOL><INDENT>from_line, to_line, found_diff = next(line_pair_iterator)<EOL>if found_diff:<EOL><INDENT>lines_to_write = context-<NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>lines_to_write -= <NUM_LIT:1><EOL><DEDENT>yield from_line, to_line, found_diff<EOL><DEDENT><DEDENT><DEDENT>

r"""Returns generator yielding marked up from/to side by side differences.

    Arguments:
    fromlines -- list of text lines to compared to tolines
    tolines -- list of text lines to be compared to fromlines
    context -- number of context lines to display on each side of difference,
               if None, all from/to text lines will be generated.
    linejunk -- passed on to ndiff (see ndiff documentation)
    charjunk -- passed on to ndiff (see ndiff documentation)

    This function returns an iterator which returns a tuple:
    (from line tuple, to line tuple, boolean flag)

    from/to line tuple -- (line num, line text)
        line num -- integer or None (to indicate a context separation)
        line text -- original line text with following markers inserted:
            '\0+' -- marks start of added text
            '\0-' -- marks start of deleted text
            '\0^' -- marks start of changed text
            '\1' -- marks end of added/deleted/changed text

    boolean flag -- None indicates context separation, True indicates
        either "from" or "to" line contains a change, otherwise False.

    This function/iterator was originally developed to generate side by side
    file difference for making HTML pages (see HtmlDiff class for example
    usage).

    Note, this function utilizes the ndiff function to generate the side by
    side difference markup.  Optional ndiff arguments may be passed to this
    function and they in turn will be passed to ndiff.


try:<EOL><INDENT>tag = {<NUM_LIT:1>: "<STR_LIT>", <NUM_LIT:2>: "<STR_LIT>"}[int(which)]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>% which)<EOL><DEDENT>prefixes = ("<STR_LIT:U+0020>", tag)<EOL>for line in delta:<EOL><INDENT>if line[:<NUM_LIT:2>] in prefixes:<EOL><INDENT>yield line[<NUM_LIT:2>:]<EOL><DEDENT><DEDENT>

r"""
    Generate one of the two sequences that generated a delta.

    Given a `delta` produced by `Differ.compare()` or `ndiff()`, extract
    lines originating from file 1 or 2 (parameter `which`), stripping off line
    prefixes.

    Examples:

    >>> diff = ndiff('one\ntwo\nthree\n'.splitlines(1),
    ...              'ore\ntree\nemu\n'.splitlines(1))
    >>> diff = list(diff)
    >>> print ''.join(restore(diff, 1)),
    one
    two
    three
    >>> print ''.join(restore(diff, 2)),
    ore
    tree
    emu


return _tuple.__new__(_cls, (a, b, size))<EOL>

Create new instance of Match(a, b, size)


result = new(cls, iterable)<EOL>if len(result) != <NUM_LIT:3>:<EOL><INDENT>raise TypeError('<STR_LIT>' % len(result))<EOL><DEDENT>return result<EOL>

Make a new Match object from a sequence or iterable


return '<STR_LIT>' % self<EOL>

Return a nicely formatted representation string


return OrderedDict(list(zip(self._fields, self)))<EOL>

Return a new OrderedDict which maps field names to their values


result = _self._make(list(map(kwds.pop, ('<STR_LIT:a>', '<STR_LIT:b>', '<STR_LIT:size>'), _self)))<EOL>if kwds:<EOL><INDENT>raise ValueError('<STR_LIT>' % list(kwds.keys()))<EOL><DEDENT>return result<EOL>

Return a new Match object replacing specified fields with new values


return tuple(self)<EOL>

Return self as a plain tuple.  Used by copy and pickle.


pass<EOL>


def __init__(self, isjunk=None, a='<STR_LIT>', b='<STR_LIT>', autojunk=True):

<EOL>self.isjunk = isjunk<EOL>self.a = self.b = None<EOL>self.autojunk = autojunk<EOL>self.set_seqs(a, b)<EOL>

Construct a SequenceMatcher.

        Optional arg isjunk is None (the default), or a one-argument
        function that takes a sequence element and returns true iff the
        element is junk.  None is equivalent to passing "lambda x: 0", i.e.
        no elements are considered to be junk.  For example, pass
            lambda x: x in " \\t"
        if you're comparing lines as sequences of characters, and don't
        want to synch up on blanks or hard tabs.

        Optional arg a is the first of two sequences to be compared.  By
        default, an empty string.  The elements of a must be hashable.  See
        also .set_seqs() and .set_seq1().

        Optional arg b is the second of two sequences to be compared.  By
        default, an empty string.  The elements of b must be hashable. See
        also .set_seqs() and .set_seq2().

        Optional arg autojunk should be set to False to disable the
        "automatic junk heuristic" that treats popular elements as junk
        (see module documentation for more information).


self.set_seq1(a)<EOL>self.set_seq2(b)<EOL>

Set the two sequences to be compared.

        >>> s = SequenceMatcher()
        >>> s.set_seqs("abcd", "bcde")
        >>> s.ratio()
        0.75


if a is self.a:<EOL><INDENT>return<EOL><DEDENT>self.a = a<EOL>self.matching_blocks = self.opcodes = None<EOL>

Set the first sequence to be compared.

        The second sequence to be compared is not changed.

        >>> s = SequenceMatcher(None, "abcd", "bcde")
        >>> s.ratio()
        0.75
        >>> s.set_seq1("bcde")
        >>> s.ratio()
        1.0
        >>>

        SequenceMatcher computes and caches detailed information about the
        second sequence, so if you want to compare one sequence S against
        many sequences, use .set_seq2(S) once and call .set_seq1(x)
        repeatedly for each of the other sequences.

        See also set_seqs() and set_seq2().


if b is self.b:<EOL><INDENT>return<EOL><DEDENT>self.b = b<EOL>self.matching_blocks = self.opcodes = None<EOL>self.fullbcount = None<EOL>self.__chain_b()<EOL>

Set the second sequence to be compared.

        The first sequence to be compared is not changed.

        >>> s = SequenceMatcher(None, "abcd", "bcde")
        >>> s.ratio()
        0.75
        >>> s.set_seq2("abcd")
        >>> s.ratio()
        1.0
        >>>

        SequenceMatcher computes and caches detailed information about the
        second sequence, so if you want to compare one sequence S against
        many sequences, use .set_seq2(S) once and call .set_seq1(x)
        repeatedly for each of the other sequences.

        See also set_seqs() and set_seq1().


def find_longest_match(self, alo, ahi, blo, bhi):

<EOL>a, b, b2j, isbjunk = self.a, self.b, self.b2j, self.isbjunk<EOL>besti, bestj, bestsize = alo, blo, <NUM_LIT:0><EOL>j2len = {}<EOL>nothing = []<EOL>for i in range(alo, ahi):<EOL><INDENT>j2lenget = j2len.get<EOL>newj2len = {}<EOL>for j in b2j.get(a[i], nothing):<EOL><INDENT>if j < blo:<EOL><INDENT>continue<EOL><DEDENT>if j >= bhi:<EOL><INDENT>break<EOL><DEDENT>k = newj2len[j] = j2lenget(j-<NUM_LIT:1>, <NUM_LIT:0>) + <NUM_LIT:1><EOL>if k > bestsize:<EOL><INDENT>besti, bestj, bestsize = i-k+<NUM_LIT:1>, j-k+<NUM_LIT:1>, k<EOL><DEDENT><DEDENT>j2len = newj2len<EOL><DEDENT>while besti > alo and bestj > blo andnot isbjunk(b[bestj-<NUM_LIT:1>]) anda[besti-<NUM_LIT:1>] == b[bestj-<NUM_LIT:1>]:<EOL><INDENT>besti, bestj, bestsize = besti-<NUM_LIT:1>, bestj-<NUM_LIT:1>, bestsize+<NUM_LIT:1><EOL><DEDENT>while besti+bestsize < ahi and bestj+bestsize < bhi andnot isbjunk(b[bestj+bestsize]) anda[besti+bestsize] == b[bestj+bestsize]:<EOL><INDENT>bestsize += <NUM_LIT:1><EOL><DEDENT>while besti > alo and bestj > blo andisbjunk(b[bestj-<NUM_LIT:1>]) anda[besti-<NUM_LIT:1>] == b[bestj-<NUM_LIT:1>]:<EOL><INDENT>besti, bestj, bestsize = besti-<NUM_LIT:1>, bestj-<NUM_LIT:1>, bestsize+<NUM_LIT:1><EOL><DEDENT>while besti+bestsize < ahi and bestj+bestsize < bhi andisbjunk(b[bestj+bestsize]) anda[besti+bestsize] == b[bestj+bestsize]:<EOL><INDENT>bestsize = bestsize + <NUM_LIT:1><EOL><DEDENT>return Match(besti, bestj, bestsize)<EOL>

Find longest matching block in a[alo:ahi] and b[blo:bhi].

        If isjunk is not defined:

        Return (i,j,k) such that a[i:i+k] is equal to b[j:j+k], where
            alo <= i <= i+k <= ahi
            blo <= j <= j+k <= bhi
        and for all (i',j',k') meeting those conditions,
            k >= k'
            i <= i'
            and if i == i', j <= j'

        In other words, of all maximal matching blocks, return one that
        starts earliest in a, and of all those maximal matching blocks that
        start earliest in a, return the one that starts earliest in b.

        >>> s = SequenceMatcher(None, " abcd", "abcd abcd")
        >>> s.find_longest_match(0, 5, 0, 9)
        Match(a=0, b=4, size=5)

        If isjunk is defined, first the longest matching block is
        determined as above, but with the additional restriction that no
        junk element appears in the block.  Then that block is extended as
        far as possible by matching (only) junk elements on both sides.  So
        the resulting block never matches on junk except as identical junk
        happens to be adjacent to an "interesting" match.

        Here's the same example as before, but considering blanks to be
        junk.  That prevents " abcd" from matching the " abcd" at the tail
        end of the second sequence directly.  Instead only the "abcd" can
        match, and matches the leftmost "abcd" in the second sequence:

        >>> s = SequenceMatcher(lambda x: x==" ", " abcd", "abcd abcd")
        >>> s.find_longest_match(0, 5, 0, 9)
        Match(a=1, b=0, size=4)

        If no blocks match, return (alo, blo, 0).

        >>> s = SequenceMatcher(None, "ab", "c")
        >>> s.find_longest_match(0, 2, 0, 1)
        Match(a=0, b=0, size=0)


if self.matching_blocks is not None:<EOL><INDENT>return self.matching_blocks<EOL><DEDENT>la, lb = len(self.a), len(self.b)<EOL>queue = [(<NUM_LIT:0>, la, <NUM_LIT:0>, lb)]<EOL>matching_blocks = []<EOL>while queue:<EOL><INDENT>alo, ahi, blo, bhi = queue.pop()<EOL>i, j, k = x = self.find_longest_match(alo, ahi, blo, bhi)<EOL>if k:   <EOL><INDENT>matching_blocks.append(x)<EOL>if alo < i and blo < j:<EOL><INDENT>queue.append((alo, i, blo, j))<EOL><DEDENT>if i+k < ahi and j+k < bhi:<EOL><INDENT>queue.append((i+k, ahi, j+k, bhi))<EOL><DEDENT><DEDENT><DEDENT>matching_blocks.sort()<EOL>i1 = j1 = k1 = <NUM_LIT:0><EOL>non_adjacent = []<EOL>for i2, j2, k2 in matching_blocks:<EOL><INDENT>if i1 + k1 == i2 and j1 + k1 == j2:<EOL><INDENT>k1 += k2<EOL><DEDENT>else:<EOL><INDENT>if k1:<EOL><INDENT>non_adjacent.append((i1, j1, k1))<EOL><DEDENT>i1, j1, k1 = i2, j2, k2<EOL><DEDENT><DEDENT>if k1:<EOL><INDENT>non_adjacent.append((i1, j1, k1))<EOL><DEDENT>non_adjacent.append( (la, lb, <NUM_LIT:0>) )<EOL>self.matching_blocks = list(map(Match._make, non_adjacent))<EOL>return self.matching_blocks<EOL>

Return list of triples describing matching subsequences.

        Each triple is of the form (i, j, n), and means that
        a[i:i+n] == b[j:j+n].  The triples are monotonically increasing in
        i and in j.  New in Python 2.5, it's also guaranteed that if
        (i, j, n) and (i', j', n') are adjacent triples in the list, and
        the second is not the last triple in the list, then i+n != i' or
        j+n != j'.  IOW, adjacent triples never describe adjacent equal
        blocks.

        The last triple is a dummy, (len(a), len(b), 0), and is the only
        triple with n==0.

        >>> s = SequenceMatcher(None, "abxcd", "abcd")
        >>> s.get_matching_blocks()
        [Match(a=0, b=0, size=2), Match(a=3, b=2, size=2), Match(a=5, b=4, size=0)]


if self.opcodes is not None:<EOL><INDENT>return self.opcodes<EOL><DEDENT>i = j = <NUM_LIT:0><EOL>self.opcodes = answer = []<EOL>for ai, bj, size in self.get_matching_blocks():<EOL><INDENT>tag = '<STR_LIT>'<EOL>if i < ai and j < bj:<EOL><INDENT>tag = '<STR_LIT:replace>'<EOL><DEDENT>elif i < ai:<EOL><INDENT>tag = '<STR_LIT>'<EOL><DEDENT>elif j < bj:<EOL><INDENT>tag = '<STR_LIT>'<EOL><DEDENT>if tag:<EOL><INDENT>answer.append( (tag, i, ai, j, bj) )<EOL><DEDENT>i, j = ai+size, bj+size<EOL>if size:<EOL><INDENT>answer.append( ('<STR_LIT>', ai, i, bj, j) )<EOL><DEDENT><DEDENT>return answer<EOL>

Return list of 5-tuples describing how to turn a into b.

        Each tuple is of the form (tag, i1, i2, j1, j2).  The first tuple
        has i1 == j1 == 0, and remaining tuples have i1 == the i2 from the
        tuple preceding it, and likewise for j1 == the previous j2.

        The tags are strings, with these meanings:

        'replace':  a[i1:i2] should be replaced by b[j1:j2]
        'delete':   a[i1:i2] should be deleted.
                    Note that j1==j2 in this case.
        'insert':   b[j1:j2] should be inserted at a[i1:i1].
                    Note that i1==i2 in this case.
        'equal':    a[i1:i2] == b[j1:j2]

        >>> a = "qabxcd"
        >>> b = "abycdf"
        >>> s = SequenceMatcher(None, a, b)
        >>> for tag, i1, i2, j1, j2 in s.get_opcodes():
        ...    print ("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
        ...           (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2]))
         delete a[0:1] (q) b[0:0] ()
          equal a[1:3] (ab) b[0:2] (ab)
        replace a[3:4] (x) b[2:3] (y)
          equal a[4:6] (cd) b[3:5] (cd)
         insert a[6:6] () b[5:6] (f)


codes = self.get_opcodes()<EOL>if not codes:<EOL><INDENT>codes = [("<STR_LIT>", <NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:0>, <NUM_LIT:1>)]<EOL><DEDENT>if codes[<NUM_LIT:0>][<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>tag, i1, i2, j1, j2 = codes[<NUM_LIT:0>]<EOL>codes[<NUM_LIT:0>] = tag, max(i1, i2-n), i2, max(j1, j2-n), j2<EOL><DEDENT>if codes[-<NUM_LIT:1>][<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>tag, i1, i2, j1, j2 = codes[-<NUM_LIT:1>]<EOL>codes[-<NUM_LIT:1>] = tag, i1, min(i2, i1+n), j1, min(j2, j1+n)<EOL><DEDENT>nn = n + n<EOL>group = []<EOL>for tag, i1, i2, j1, j2 in codes:<EOL><INDENT>if tag == '<STR_LIT>' and i2-i1 > nn:<EOL><INDENT>group.append((tag, i1, min(i2, i1+n), j1, min(j2, j1+n)))<EOL>yield group<EOL>group = []<EOL>i1, j1 = max(i1, i2-n), max(j1, j2-n)<EOL><DEDENT>group.append((tag, i1, i2, j1 ,j2))<EOL><DEDENT>if group and not (len(group)==<NUM_LIT:1> and group[<NUM_LIT:0>][<NUM_LIT:0>] == '<STR_LIT>'):<EOL><INDENT>yield group<EOL><DEDENT>

Isolate change clusters by eliminating ranges with no changes.

        Return a generator of groups with up to n lines of context.
        Each group is in the same format as returned by get_opcodes().

        >>> from pprint import pprint
        >>> a = map(str, range(1,40))
        >>> b = a[:]
        >>> b[8:8] = ['i']     # Make an insertion
        >>> b[20] += 'x'       # Make a replacement
        >>> b[23:28] = []      # Make a deletion
        >>> b[30] += 'y'       # Make another replacement
        >>> pprint(list(SequenceMatcher(None,a,b).get_grouped_opcodes()))
        [[('equal', 5, 8, 5, 8), ('insert', 8, 8, 8, 9), ('equal', 8, 11, 9, 12)],
         [('equal', 16, 19, 17, 20),
          ('replace', 19, 20, 20, 21),
          ('equal', 20, 22, 21, 23),
          ('delete', 22, 27, 23, 23),
          ('equal', 27, 30, 23, 26)],
         [('equal', 31, 34, 27, 30),
          ('replace', 34, 35, 30, 31),
          ('equal', 35, 38, 31, 34)]]


matches = reduce(lambda sum, triple: sum + triple[-<NUM_LIT:1>],<EOL>self.get_matching_blocks(), <NUM_LIT:0>)<EOL>return _calculate_ratio(matches, len(self.a) + len(self.b))<EOL>

Return a measure of the sequences' similarity (float in [0,1]).

        Where T is the total number of elements in both sequences, and
        M is the number of matches, this is 2.0*M / T.
        Note that this is 1 if the sequences are identical, and 0 if
        they have nothing in common.

        .ratio() is expensive to compute if you haven't already computed
        .get_matching_blocks() or .get_opcodes(), in which case you may
        want to try .quick_ratio() or .real_quick_ratio() first to get an
        upper bound.

        >>> s = SequenceMatcher(None, "abcd", "bcde")
        >>> s.ratio()
        0.75
        >>> s.quick_ratio()
        0.75
        >>> s.real_quick_ratio()
        1.0


<EOL>if self.fullbcount is None:<EOL><INDENT>self.fullbcount = fullbcount = {}<EOL>for elt in self.b:<EOL><INDENT>fullbcount[elt] = fullbcount.get(elt, <NUM_LIT:0>) + <NUM_LIT:1><EOL><DEDENT><DEDENT>fullbcount = self.fullbcount<EOL>avail = {}<EOL>availhas, matches = avail.__contains__, <NUM_LIT:0><EOL>for elt in self.a:<EOL><INDENT>if availhas(elt):<EOL><INDENT>numb = avail[elt]<EOL><DEDENT>else:<EOL><INDENT>numb = fullbcount.get(elt, <NUM_LIT:0>)<EOL><DEDENT>avail[elt] = numb - <NUM_LIT:1><EOL>if numb > <NUM_LIT:0>:<EOL><INDENT>matches = matches + <NUM_LIT:1><EOL><DEDENT><DEDENT>return _calculate_ratio(matches, len(self.a) + len(self.b))<EOL>

Return an upper bound on ratio() relatively quickly.

        This isn't defined beyond that it is an upper bound on .ratio(), and
        is faster to compute.


la, lb = len(self.a), len(self.b)<EOL>return _calculate_ratio(min(la, lb), la + lb)<EOL>

Return an upper bound on ratio() very quickly.

        This isn't defined beyond that it is an upper bound on .ratio(), and
        is faster to compute than either .ratio() or .quick_ratio().


def __init__(self, linejunk=None, charjunk=None):

self.linejunk = linejunk<EOL>self.charjunk = charjunk<EOL>

Construct a text differencer, with optional filters.

The two optional keyword parameters are for filter functions:

- `linejunk`: A function that should accept a single string argument,
  and return true iff the string is junk. The module-level function
  `IS_LINE_JUNK` may be used to filter out lines without visible
  characters, except for at most one splat ('#').  It is recommended
  to leave linejunk None; as of Python 2.3, the underlying
  SequenceMatcher class has grown an adaptive notion of "noise" lines
  that's better than any static definition the author has ever been
  able to craft.

- `charjunk`: A function that should accept a string of length 1. The
  module-level function `IS_CHARACTER_JUNK` may be used to filter out
  whitespace characters (a blank or tab; **note**: bad idea to include
  newline in this!).  Use of IS_CHARACTER_JUNK is recommended.


cruncher = SequenceMatcher(self.linejunk, a, b)<EOL>for tag, alo, ahi, blo, bhi in cruncher.get_opcodes():<EOL><INDENT>if tag == '<STR_LIT:replace>':<EOL><INDENT>g = self._fancy_replace(a, alo, ahi, b, blo, bhi)<EOL><DEDENT>elif tag == '<STR_LIT>':<EOL><INDENT>g = self._dump('<STR_LIT:->', a, alo, ahi)<EOL><DEDENT>elif tag == '<STR_LIT>':<EOL><INDENT>g = self._dump('<STR_LIT:+>', b, blo, bhi)<EOL><DEDENT>elif tag == '<STR_LIT>':<EOL><INDENT>g = self._dump('<STR_LIT:U+0020>', a, alo, ahi)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>' % (tag,))<EOL><DEDENT>for line in g:<EOL><INDENT>yield line<EOL><DEDENT><DEDENT>

r"""
        Compare two sequences of lines; generate the resulting delta.

        Each sequence must contain individual single-line strings ending with
        newlines. Such sequences can be obtained from the `readlines()` method
        of file-like objects.  The delta generated also consists of newline-
        terminated strings, ready to be printed as-is via the writeline()
        method of a file-like object.

        Example:

        >>> print ''.join(Differ().compare('one\ntwo\nthree\n'.splitlines(1),
        ...                                'ore\ntree\nemu\n'.splitlines(1))),
        - one
        ?  ^
        + ore
        ?  ^
        - two
        - three
        ?  -
        + tree
        + emu


for i in range(lo, hi):<EOL><INDENT>yield '<STR_LIT>' % (tag, x[i])<EOL><DEDENT>

Generate comparison results for a same-tagged range.


def _fancy_replace(self, a, alo, ahi, b, blo, bhi):

<EOL>best_ratio, cutoff = <NUM_LIT>, <NUM_LIT><EOL>cruncher = SequenceMatcher(self.charjunk)<EOL>eqi, eqj = None, None   <EOL>for j in range(blo, bhi):<EOL><INDENT>bj = b[j]<EOL>cruncher.set_seq2(bj)<EOL>for i in range(alo, ahi):<EOL><INDENT>ai = a[i]<EOL>if ai == bj:<EOL><INDENT>if eqi is None:<EOL><INDENT>eqi, eqj = i, j<EOL><DEDENT>continue<EOL><DEDENT>cruncher.set_seq1(ai)<EOL>if cruncher.real_quick_ratio() > best_ratio andcruncher.quick_ratio() > best_ratio andcruncher.ratio() > best_ratio:<EOL><INDENT>best_ratio, best_i, best_j = cruncher.ratio(), i, j<EOL><DEDENT><DEDENT><DEDENT>if best_ratio < cutoff:<EOL><INDENT>if eqi is None:<EOL><INDENT>for line in self._plain_replace(a, alo, ahi, b, blo, bhi):<EOL><INDENT>yield line<EOL><DEDENT>return<EOL><DEDENT>best_i, best_j, best_ratio = eqi, eqj, <NUM_LIT:1.0><EOL><DEDENT>else:<EOL><INDENT>eqi = None<EOL><DEDENT>for line in self._fancy_helper(a, alo, best_i, b, blo, best_j):<EOL><INDENT>yield line<EOL><DEDENT>aelt, belt = a[best_i], b[best_j]<EOL>if eqi is None:<EOL><INDENT>atags = btags = "<STR_LIT>"<EOL>cruncher.set_seqs(aelt, belt)<EOL>for tag, ai1, ai2, bj1, bj2 in cruncher.get_opcodes():<EOL><INDENT>la, lb = ai2 - ai1, bj2 - bj1<EOL>if tag == '<STR_LIT:replace>':<EOL><INDENT>atags += '<STR_LIT>' * la<EOL>btags += '<STR_LIT>' * lb<EOL><DEDENT>elif tag == '<STR_LIT>':<EOL><INDENT>atags += '<STR_LIT:->' * la<EOL><DEDENT>elif tag == '<STR_LIT>':<EOL><INDENT>btags += '<STR_LIT:+>' * lb<EOL><DEDENT>elif tag == '<STR_LIT>':<EOL><INDENT>atags += '<STR_LIT:U+0020>' * la<EOL>btags += '<STR_LIT:U+0020>' * lb<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>' % (tag,))<EOL><DEDENT><DEDENT>for line in self._qformat(aelt, belt, atags, btags):<EOL><INDENT>yield line<EOL><DEDENT><DEDENT>else:<EOL><INDENT>yield '<STR_LIT:U+0020>' + aelt<EOL><DEDENT>for line in self._fancy_helper(a, best_i+<NUM_LIT:1>, ahi, b, best_j+<NUM_LIT:1>, bhi):<EOL><INDENT>yield line<EOL><DEDENT>

r"""
        When replacing one block of lines with another, search the blocks
        for *similar* lines; the best-matching pair (if any) is used as a
        synch point, and intraline difference marking is done on the
        similar pair. Lots of work, but often worth it.

        Example:

        >>> d = Differ()
        >>> results = d._fancy_replace(['abcDefghiJkl\n'], 0, 1,
        ...                            ['abcdefGhijkl\n'], 0, 1)
        >>> print ''.join(results),
        - abcDefghiJkl
        ?    ^  ^  ^
        + abcdefGhijkl
        ?    ^  ^  ^


def _qformat(self, aline, bline, atags, btags):

<EOL>common = min(_count_leading(aline, "<STR_LIT:\t>"),<EOL>_count_leading(bline, "<STR_LIT:\t>"))<EOL>common = min(common, _count_leading(atags[:common], "<STR_LIT:U+0020>"))<EOL>common = min(common, _count_leading(btags[:common], "<STR_LIT:U+0020>"))<EOL>atags = atags[common:].rstrip()<EOL>btags = btags[common:].rstrip()<EOL>yield "<STR_LIT>" + aline<EOL>if atags:<EOL><INDENT>yield "<STR_LIT>" % ("<STR_LIT:\t>" * common, atags)<EOL><DEDENT>yield "<STR_LIT>" + bline<EOL>if btags:<EOL><INDENT>yield "<STR_LIT>" % ("<STR_LIT:\t>" * common, btags)<EOL><DEDENT>

r"""
        Format "?" output and deal with leading tabs.

        Example:

        >>> d = Differ()
        >>> results = d._qformat('\tabcDefghiJkl\n', '\tabcdefGhijkl\n',
        ...                      '  ^ ^  ^      ', '  ^ ^  ^      ')
        >>> for line in results: print repr(line)
        ...
        '- \tabcDefghiJkl\n'
        '? \t ^ ^  ^\n'
        '+ \tabcdefGhijkl\n'
        '? \t ^ ^  ^\n'


self._tabsize = tabsize<EOL>self._wrapcolumn = wrapcolumn<EOL>self._linejunk = linejunk<EOL>self._charjunk = charjunk<EOL>

HtmlDiff instance initializer

        Arguments:
        tabsize -- tab stop spacing, defaults to 8.
        wrapcolumn -- column number where lines are broken and wrapped,
            defaults to None where lines are not wrapped.
        linejunk,charjunk -- keyword arguments passed into ndiff() (used to by
            HtmlDiff() to generate the side by side HTML differences).  See
            ndiff() documentation for argument default values and descriptions.


return self._file_template % dict(<EOL>styles = self._styles,<EOL>legend = self._legend,<EOL>table = self.make_table(fromlines,tolines,fromdesc,todesc,<EOL>context=context,numlines=numlines))<EOL>

Returns HTML file of side by side comparison with change highlights

        Arguments:
        fromlines -- list of "from" lines
        tolines -- list of "to" lines
        fromdesc -- "from" file column header string
        todesc -- "to" file column header string
        context -- set to True for contextual differences (defaults to False
            which shows full differences).
        numlines -- number of context lines.  When context is set True,
            controls number of lines displayed before and after the change.
            When context is False, controls the number of lines to place
            the "next" link anchors before the next change (so click of
            "next" link jumps to just before the change).


def expand_tabs(line):<EOL><INDENT>line = line.replace('<STR_LIT:U+0020>','<STR_LIT>')<EOL>line = line.expandtabs(self._tabsize)<EOL>line = line.replace('<STR_LIT:U+0020>','<STR_LIT:\t>')<EOL>return line.replace('<STR_LIT>','<STR_LIT:U+0020>').rstrip('<STR_LIT:\n>')<EOL><DEDENT>fromlines = [expand_tabs(line) for line in fromlines]<EOL>tolines = [expand_tabs(line) for line in tolines]<EOL>return fromlines,tolines<EOL>

Returns from/to line lists with tabs expanded and newlines removed.

        Instead of tab characters being replaced by the number of spaces
        needed to fill in to the next tab stop, this function will fill
        the space with tab characters.  This is done so that the difference
        algorithms can identify changes in a file when tabs are replaced by
        spaces and vice versa.  At the end of the HTML generation, the tab
        characters will be replaced with a nonbreakable space.


<EOL>if not line_num:<EOL><INDENT>data_list.append((line_num,text))<EOL>return<EOL><DEDENT>size = len(text)<EOL>max = self._wrapcolumn<EOL>if (size <= max) or ((size -(text.count('<STR_LIT>')*<NUM_LIT:3>)) <= max):<EOL><INDENT>data_list.append((line_num,text))<EOL>return<EOL><DEDENT>i = <NUM_LIT:0><EOL>n = <NUM_LIT:0><EOL>mark = '<STR_LIT>'<EOL>while n < max and i < size:<EOL><INDENT>if text[i] == '<STR_LIT>':<EOL><INDENT>i += <NUM_LIT:1><EOL>mark = text[i]<EOL>i += <NUM_LIT:1><EOL><DEDENT>elif text[i] == '<STR_LIT>':<EOL><INDENT>i += <NUM_LIT:1><EOL>mark = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>i += <NUM_LIT:1><EOL>n += <NUM_LIT:1><EOL><DEDENT><DEDENT>line1 = text[:i]<EOL>line2 = text[i:]<EOL>if mark:<EOL><INDENT>line1 = line1 + '<STR_LIT>'<EOL>line2 = '<STR_LIT>' + mark + line2<EOL><DEDENT>data_list.append((line_num,line1))<EOL>self._split_line(data_list,'<STR_LIT:>>',line2)<EOL>

Builds list of text lines by splitting text lines at wrap point

        This function will determine if the input text line needs to be
        wrapped (split) into separate lines.  If so, the first wrap point
        will be determined and the first line appended to the output
        text line list.  This function is used recursively to handle
        the second part of the split line to further split it.


<EOL>for fromdata,todata,flag in diffs:<EOL><INDENT>if flag is None:<EOL><INDENT>yield fromdata,todata,flag<EOL>continue<EOL><DEDENT>(fromline,fromtext),(toline,totext) = fromdata,todata<EOL>fromlist,tolist = [],[]<EOL>self._split_line(fromlist,fromline,fromtext)<EOL>self._split_line(tolist,toline,totext)<EOL>while fromlist or tolist:<EOL><INDENT>if fromlist:<EOL><INDENT>fromdata = fromlist.pop(<NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>fromdata = ('<STR_LIT>','<STR_LIT:U+0020>')<EOL><DEDENT>if tolist:<EOL><INDENT>todata = tolist.pop(<NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>todata = ('<STR_LIT>','<STR_LIT:U+0020>')<EOL><DEDENT>yield fromdata,todata,flag<EOL><DEDENT><DEDENT>

Returns iterator that splits (wraps) mdiff text lines


fromlist,tolist,flaglist = [],[],[]<EOL>for fromdata,todata,flag in diffs:<EOL><INDENT>try:<EOL><INDENT>fromlist.append(self._format_line(<NUM_LIT:0>,flag,*fromdata))<EOL>tolist.append(self._format_line(<NUM_LIT:1>,flag,*todata))<EOL><DEDENT>except TypeError:<EOL><INDENT>fromlist.append(None)<EOL>tolist.append(None)<EOL><DEDENT>flaglist.append(flag)<EOL><DEDENT>return fromlist,tolist,flaglist<EOL>

Collects mdiff output into separate lists

        Before storing the mdiff from/to data into a list, it is converted
        into a single line of text with HTML markup.


try:<EOL><INDENT>linenum = '<STR_LIT>' % linenum<EOL>id = '<STR_LIT>' % (self._prefix[side],linenum)<EOL><DEDENT>except TypeError:<EOL><INDENT>id = '<STR_LIT>'<EOL><DEDENT>text=text.replace("<STR_LIT:&>","<STR_LIT>").replace("<STR_LIT:>>","<STR_LIT>").replace("<STR_LIT:<>","<STR_LIT>")<EOL>text = text.replace('<STR_LIT:U+0020>','<STR_LIT>').rstrip()<EOL>return '<STR_LIT>'% (id,linenum,text)<EOL>

Returns HTML markup of "from" / "to" text lines

        side -- 0 or 1 indicating "from" or "to" text
        flag -- indicates if difference on line
        linenum -- line number (used for line number column)
        text -- line text to be marked up


<EOL>fromprefix = "<STR_LIT>" % HtmlDiff._default_prefix<EOL>toprefix = "<STR_LIT>" % HtmlDiff._default_prefix<EOL>HtmlDiff._default_prefix += <NUM_LIT:1><EOL>self._prefix = [fromprefix,toprefix]<EOL>


<EOL>toprefix = self._prefix[<NUM_LIT:1>]<EOL>next_id = ['<STR_LIT>']*len(flaglist)<EOL>next_href = ['<STR_LIT>']*len(flaglist)<EOL>num_chg, in_change = <NUM_LIT:0>, False<EOL>last = <NUM_LIT:0><EOL>for i,flag in enumerate(flaglist):<EOL><INDENT>if flag:<EOL><INDENT>if not in_change:<EOL><INDENT>in_change = True<EOL>last = i<EOL>i = max([<NUM_LIT:0>,i-numlines])<EOL>next_id[i] = '<STR_LIT>' % (toprefix,num_chg)<EOL>num_chg += <NUM_LIT:1><EOL>next_href[last] = '<STR_LIT>' % (<EOL>toprefix,num_chg)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>in_change = False<EOL><DEDENT><DEDENT>if not flaglist:<EOL><INDENT>flaglist = [False]<EOL>next_id = ['<STR_LIT>']<EOL>next_href = ['<STR_LIT>']<EOL>last = <NUM_LIT:0><EOL>if context:<EOL><INDENT>fromlist = ['<STR_LIT>']<EOL>tolist = fromlist<EOL><DEDENT>else:<EOL><INDENT>fromlist = tolist = ['<STR_LIT>']<EOL><DEDENT><DEDENT>if not flaglist[<NUM_LIT:0>]:<EOL><INDENT>next_href[<NUM_LIT:0>] = '<STR_LIT>' % toprefix<EOL><DEDENT>next_href[last] = '<STR_LIT>' % (toprefix)<EOL>return fromlist,tolist,flaglist,next_href,next_id<EOL>