Sh3ll
OdayForums


Server : Apache
System : Linux server1.cgrithy.com 3.10.0-1160.95.1.el7.x86_64 #1 SMP Mon Jul 24 13:59:37 UTC 2023 x86_64
User : nobody ( 99)
PHP Version : 8.1.23
Disable Function : NONE
Directory :  /opt/alt/python311/lib64/python3.11/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //opt/alt/python311/lib64/python3.11/__pycache__/difflib.cpython-311.opt-1.pyc
�

�,dlE���dZgd�ZddlmZddlmZddlm	Z	edd��Z
d�ZGd	�d
��Zd+d
�Z
d�ZGd�d��ZddlZejd��jfd�Zd,d�Zd�Z		d-d�Zd�Z		d-d�Zd�Z		d.d�Zdefd �Zddefd!�Zd"Zd#Zd$Zd%Z Gd&�d'e!��Z"[d(�Z#d)�Z$e%d*kre$��dSdS)/ae
Module difflib -- helpers for computing deltas between objects.

Function get_close_matches(word, possibilities, n=3, cutoff=0.6):
    Use SequenceMatcher to return list of the best "good enough" matches.

Function context_diff(a, b):
    For two lists of strings, return a delta in context diff format.

Function ndiff(a, b):
    Return a delta: the difference between `a` and `b` (lists of strings).

Function restore(delta, which):
    Return one of the two sequences that generated an ndiff delta.

Function unified_diff(a, b):
    For two lists of strings, return a delta in unified diff format.

Class SequenceMatcher:
    A flexible class for comparing pairs of sequences of any type.

Class Differ:
    For producing human-readable deltas from sequences of lines of text.

Class HtmlDiff:
    For producing HTML side by side comparison with change highlights.
)�get_close_matches�ndiff�restore�SequenceMatcher�Differ�IS_CHARACTER_JUNK�IS_LINE_JUNK�context_diff�unified_diff�
diff_bytes�HtmlDiff�Match�)�nlargest)�
namedtuple)�GenericAliasr
za b sizec��|rd|z|zSdS)Ng@��?�)�matches�lengths  �./opt/alt/python311/lib64/python3.11/difflib.py�_calculate_ratior's��
�&��W�}�v�%�%��3�c�v�eZdZdZdd�Zd�Zd�Zd�Zd	�Zdd�Z	d�Z
d
�Zdd�Zd�Z
d�Zd�Zee��ZdS)rao

    SequenceMatcher is a flexible class for comparing pairs of sequences of
    any type, so long as the sequence elements are hashable.  The basic
    algorithm predates, and is a little fancier than, an algorithm
    published in the late 1980's by Ratcliff and Obershelp under the
    hyperbolic name "gestalt pattern matching".  The basic idea is to find
    the longest contiguous matching subsequence that contains no "junk"
    elements (R-O doesn't address junk).  The same idea is then applied
    recursively to the pieces of the sequences to the left and to the right
    of the matching subsequence.  This does not yield minimal edit
    sequences, but does tend to yield matches that "look right" to people.

    SequenceMatcher tries to compute a "human-friendly diff" between two
    sequences.  Unlike e.g. UNIX(tm) diff, the fundamental notion is the
    longest *contiguous* & junk-free matching subsequence.  That's what
    catches peoples' eyes.  The Windows(tm) windiff has another interesting
    notion, pairing up elements that appear uniquely in each sequence.
    That, and the method here, appear to yield more intuitive difference
    reports than does diff.  This method appears to be the least vulnerable
    to syncing up on blocks of "junk lines", though (like blank lines in
    ordinary text files, or maybe "<P>" lines in HTML files).  That may be
    because this is the only method of the 3 that has a *concept* of
    "junk" <wink>.

    Example, comparing two strings, and considering blanks to be "junk":

    >>> s = SequenceMatcher(lambda x: x == " ",
    ...                     "private Thread currentThread;",
    ...                     "private volatile Thread currentThread;")
    >>>

    .ratio() returns a float in [0, 1], measuring the "similarity" of the
    sequences.  As a rule of thumb, a .ratio() value over 0.6 means the
    sequences are close matches:

    >>> print(round(s.ratio(), 3))
    0.866
    >>>

    If you're only interested in where the sequences match,
    .get_matching_blocks() is handy:

    >>> for block in s.get_matching_blocks():
    ...     print("a[%d] and b[%d] match for %d elements" % block)
    a[0] and b[0] match for 8 elements
    a[8] and b[17] match for 21 elements
    a[29] and b[38] match for 0 elements

    Note that the last tuple returned by .get_matching_blocks() is always a
    dummy, (len(a), len(b), 0), and this is the only case in which the last
    tuple element (number of elements matched) is 0.

    If you want to know how to change the first sequence into the second,
    use .get_opcodes():

    >>> for opcode in s.get_opcodes():
    ...     print("%6s a[%d:%d] b[%d:%d]" % opcode)
     equal a[0:8] b[0:8]
    insert a[8:8] b[8:17]
     equal a[8:29] b[17:38]

    See the Differ class for a fancy human-friendly file differencer, which
    uses SequenceMatcher both to compare sequences of lines, and to compare
    sequences of characters within similar (near-matching) lines.

    See also function get_close_matches() in this module, which shows how
    simple code building on SequenceMatcher can be used to do useful work.

    Timing:  Basic R-O is cubic time worst case and quadratic time expected
    case.  SequenceMatcher is quadratic time for the worst case and has
    expected-case behavior dependent in a complicated way on how many
    elements the sequences have in common; best case time is linear.
    N�Tc�j�||_dx|_|_||_|�||��dS)a!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).
        N)�isjunk�a�b�autojunk�set_seqs)�selfrrrr s     r�__init__zSequenceMatcher.__init__xs;��v��������� ��
��
�
�a������rc�Z�|�|��|�|��dS)z�Set the two sequences to be compared.

        >>> s = SequenceMatcher()
        >>> s.set_seqs("abcd", "bcde")
        >>> s.ratio()
        0.75
        N)�set_seq1�set_seq2)r"rrs   rr!zSequenceMatcher.set_seqs�s.��	
�
�
�a�����
�
�a�����rc�F�||jurdS||_dx|_|_dS)aMSet 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().
        N)r�matching_blocks�opcodes)r"rs  rr%zSequenceMatcher.set_seq1�s.��*
���;�;��F����.2�2���t�|�|�|rc�|�||jurdS||_dx|_|_d|_|���dS)aMSet 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().
        N)rr(r)�
fullbcount�_SequenceMatcher__chain_b)r"rs  rr&zSequenceMatcher.set_seq2�sG��*
���;�;��F����.2�2���t�|�����������rc�n�|j}ix|_}t|��D]0\}}|�|g��}|�|���1t��x|_}|j}|r?|���D]"}||��r|�	|���#|D]}||=�t��x|_
}t|��}	|jrX|	dkrT|	dzdz}
|�
��D]-\}}t|��|
kr|�	|���.|D]	}||=�dSdSdS)N���d�)r�b2j�	enumerate�
setdefault�append�set�bjunkr�keys�add�bpopular�lenr �items)r"rr1�i�elt�indices�junkr�popular�n�ntest�idxss            r�	__chain_bzSequenceMatcher.__chain_b
ss��
�F������3���l�l�	�	�F�A�s��n�n�S�"�-�-�G��N�N�1����� �E�E�!��
�T�����	��x�x�z�z�
"�
"���6�#�;�;�"��H�H�S�M�M�M���
�
����H�H�#&�%�%�'��
����F�F���=�	�Q�#�X�X���H�q�L�E� �Y�Y�[�[�
%�
%�	��T��t�9�9�u�$�$��K�K��$�$�$���
�
����H�H�
	�	�X�X�

�
rrc��|j|j|j|jjf\}}}}|�t|��}|�t|��}||d}}
}	i}g}
t
||��D]j}|j}i}|�|||
��D]@}||kr�	||krn0||dz
d��dzx}||<||kr||z
dz||z
dz|}}
}	�A|}�k|	|kry|
|krs|||
dz
��s_||	dz
||
dz
krG|	dz
|
dz
|dz}}
}	|	|kr2|
|kr,|||
dz
��s||	dz
||
dz
k�G|	|z|krx|
|z|kro|||
|z��s[||	|z||
|zkrC|dz
}|	|z|kr5|
|z|kr,|||
|z��s||	|z||
|zk�C|	|kry|
|krs|||
dz
��r_||	dz
||
dz
krG|	dz
|
dz
|dz}}
}	|	|kr2|
|kr,|||
dz
��r||	dz
||
dz
k�G|	|z|krx|
|z|kro|||
|z��r[||	|z||
|zkrC|dz}|	|z|kr5|
|z|kr,|||
|z��r||	|z||
|zk�Ct|	|
|��S)aAFind longest matching block in a[alo:ahi] and b[blo:bhi].

        By default it will find the longest match in the entirety of a and b.

        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)
        Nrr0)	rrr1r6�__contains__r:�range�getr
)r"�alo�ahi�blo�bhirrr1�isbjunk�besti�bestj�bestsize�j2len�nothingr<�j2lenget�newj2len�j�ks                   r�find_longest_matchz"SequenceMatcher.find_longest_match1s���t"�V�T�V�T�X�t�z�7N�N���1�c�7��;��a�&�&�C��;��a�&�&�C�!$�c�1�h�u�������s�C���	�	�A��y�H��H��W�W�Q�q�T�7�+�+�
=�
=���s�7�7����8�8��E�"*�(�1�Q�3��"2�"2�Q�"6�6��H�Q�K��x�<�<�-.�q�S��U�A�a�C��E�1�(�5�E���E�E��c�k�k�e�c�k�k��'�!�E�!�G�*�%�%�*���a��j�A�e�A�g�J�&�&�%*�1�W�e�A�g�x��z�(�5�E��c�k�k�e�c�k�k��'�!�E�!�G�*�%�%�*���a��j�A�e�A�g�J�&�&��H�n�s�"�"�u�X�~��';�';��'�!�E�(�N�+�,�,�(<���h���1�U�8�^�#4�4�4���M�H��H�n�s�"�"�u�X�~��';�';��'�!�E�(�N�+�,�,�(<���h���1�U�8�^�#4�4�4��c�k�k�e�c�k�k��g�a��a��j�!�!�*���a��j�A�e�A�g�J�&�&�%*�1�W�e�A�g�x��z�(�5�E��c�k�k�e�c�k�k��g�a��a��j�!�!�*���a��j�A�e�A�g�J�&�&��H�n�s�"�"�u�X�~��';�';��g�a��h��'�(�(�(<���h���1�U�8�^�#4�4�4��!�|�H��H�n�s�"�"�u�X�~��';�';��g�a��h��'�(�(�(<���h���1�U�8�^�#4�4�4��U�E�8�,�,�,rc�T�|j�|jSt|j��t|j��}}d|d|fg}g}|r�|���\}}}}|�||||��x\}	}
}}|rk|�|��||	kr||
kr|�||	||
f��|	|z|kr(|
|z|kr|�|	|z||
|z|f��|��|���dx}
x}}g}|D]>\}}}|
|z|kr||z|kr||z
}�|r|�|
||f��|||}}}
�?|r|�|
||f��|�||df��tttj|����|_|jS)aReturn 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")
        >>> list(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)]
        Nr)r(r:rr�poprWr4�sort�list�mapr
�_make)r"�la�lb�queuer(rIrJrKrLr<rUrV�x�i1�j1�k1�non_adjacent�i2�j2�k2s                    r�get_matching_blocksz#SequenceMatcher.get_matching_blocks�s��&��+��'�'��T�V���c�$�&�k�k�B���R��B�� �����	7�!&������C��c�3��1�1�#�s�C��E�E�E�G�A�q�!�a��
7��&�&�q�)�)�)���7�7�s�Q�w�w��L�L�#�q�#�q�!1�2�2�2��Q�3��9�9��1��s����L�L�!�A�#�s�A�a�C��!5�6�6�6��	7�	������
����R�"���)�
	(�
	(�J�B��B��B�w�"�}�}��b��B����b����
�6� �'�'��R���5�5�5���R��B���
�	.�����R���-�-�-����b�"�a�[�*�*�*�#�C���\�$B�$B�C�C����#�#rc�:�|j�|jSdx}}gx|_}|���D]j\}}}d}||kr	||krd}n||krd}n||krd}|r|�|||||f��||z||z}}|r|�d||||f���k|S)a[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)
        Nrr�replace�delete�insert�equal)r)rir4)r"r<rU�answer�ai�bj�size�tags        r�get_opcodeszSequenceMatcher.get_opcodes�s���:�<�#��<���	��A� "�"���v� �4�4�6�6�	9�	9�L�B��D��C��2�v�v�!�b�&�&�����R�������R������
5��
�
��Q��A�r�2�4�4�4��d�7�B�t�G�q�A��
9��
�
���Q��A�6�8�8�8���
r�c#�K�|���}|sdg}|dddkr:|d\}}}}}|t|||z
��|t|||z
��|f|d<|dddkr:|d\}}}}}||t|||z��|t|||z��f|d<||z}g}	|D]�\}}}}}|dkrq||z
|krh|	�||t|||z��|t|||z��f��|	V�g}	t|||z
��t|||z
��}}|	�|||||f����|	r+t	|	��dkr|	dddks|	V�dSdSdS)a� 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 = list(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)]]
        )rnrr0rr0rrn���r0N)rt�max�minr4r:)
r"rA�codesrsrbrfrcrg�nn�groups
          r�get_grouped_opcodesz#SequenceMatcher.get_grouped_opcodes#s�����2� � �"�"���	,�*�+�E���8�A�;�'�!�!�"'��(��C��R��R��C��B�q�D�M�M�2�s�2�r�!�t�}�}�b�@�E�!�H���9�Q�<�7�"�"�"'��)��C��R��R��R��R��A�����C��B�q�D�M�M�A�E�"�I�
��U����#(�	0�	0��C��R��R��g�~�~�"�R�%�"�*�*����c�2�s�2�r�!�t�}�}�b�#�b�"�Q�$�-�-�H�I�I�I��������R��A�����B��1��
�
�B���L�L�#�r�2�r�2�.�/�/�/�/��	�#�e�*�*�a�-�-�E�!�H�Q�K�7�,B�,B��K�K�K�K�K�	�	�,B�,Brc���td�|���D����}t|t|j��t|j��z��S)a�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
        c3�&K�|]}|dV��
dS)rwNr)�.0�triples  r�	<genexpr>z(SequenceMatcher.ratio.<locals>.<genexpr>ks&����J�J�V�f�R�j�J�J�J�J�J�Jr)�sumrirr:rr)r"rs  r�ratiozSequenceMatcher.ratioUsQ��,�J�J�t�/G�/G�/I�/I�J�J�J�J�J�����T�V���s�4�6�{�{�)B�C�C�Crc��|j�/ix|_}|jD]}|�|d��dz||<�|j}i}|jd}}|jD]?}||��r	||}n|�|d��}|dz
||<|dkr|dz}�@t|t
|j��t
|j��z��S)z�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.
        Nrr0)r+rrHrFrrr:)r"r+r=�avail�availhasr�numbs       r�quick_ratiozSequenceMatcher.quick_rations����?�"�+-�-�D�O�j��v�
=�
=��",�.�.��a�"8�"8�1�"<�
�3����_�
���!�.��'���6�	&�	&�C��x��}�}�
.��S�z���!�~�~�c�1�-�-�����E�#�J��a�x�x�!�A�+������T�V���s�4�6�{�{�)B�C�C�Crc��t|j��t|j��}}tt	||��||z��S)z�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().
        )r:rrrry)r"r^r_s   r�real_quick_ratioz SequenceMatcher.real_quick_ratio�s;���T�V���c�$�&�k�k�B�� ��B����R�"�W�5�5�5r)NrrT)rNrN)ru)�__name__�
__module__�__qualname__�__doc__r#r!r%r&r,rWrirtr}r�r�r��classmethodr�__class_getitem__rrrrr,s������H�H�T>�>�>�>�@
�
�
�3�3�3�4���X%�%�%�Nr-�r-�r-�r-�hE$�E$�E$�N5�5�5�n0�0�0�0�dD�D�D�2D�D�D�:
6�
6�
6�$��L�1�1���rrru�333333�?c��|dkstd|�����d|cxkrdksntd|�����g}t��}|�|��|D]�}|�|��|���|krY|���|krA|���|kr)|�|���|f����t||��}d�|D��S)a�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']
    rzn must be > 0: grzcutoff must be in [0.0, 1.0]: c��g|]\}}|��Srr)r��scoreras   r�
<listcomp>z%get_close_matches.<locals>.<listcomp>�s��%�%�%�(�%��A�%�%�%r)	�
ValueErrorrr&r%r�r�r�r4�	_nlargest)�word�
possibilitiesrA�cutoff�result�sras       rrr�s��:
��6�6��j���3�4�4�4��&�����C������j�v�v�G�H�H�H�
�F����A��J�J�t����
�*�*��	�
�
�1�
�
�
������6�)�)��=�=�?�?�f�$�$��7�7�9�9�����M�M�1�7�7�9�9�a�.�)�)�)���q�&�
!�
!�F�%�%�f�%�%�%�%rc�\�d�d�t||��D����S)zAReplace whitespace with the original whitespace characters in `s`rc3�XK�|]%\}}|dkr|���r|n|V��&dS)� N)�isspace)r��c�tag_cs   rr�z$_keep_original_ws.<locals>.<genexpr>�sR�������A�u��c�\�\�a�i�i�k�k�\���u������r)�join�zip)r��tag_ss  r�_keep_original_wsr��s<��
�7�7����A�u�
�
������rc�>�eZdZdZd
d�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
dS)ra�
    Differ is a class for comparing sequences of lines of text, and
    producing human-readable differences or deltas.  Differ uses
    SequenceMatcher both to compare sequences of lines, and to compare
    sequences of characters within similar (near-matching) lines.

    Each line of a Differ delta begins with a two-letter code:

        '- '    line unique to sequence 1
        '+ '    line unique to sequence 2
        '  '    line common to both sequences
        '? '    line not present in either input sequence

    Lines beginning with '? ' attempt to guide the eye to intraline
    differences, and were not present in either input sequence.  These lines
    can be confusing if the sequences contain tab characters.

    Note that Differ makes no claim to produce a *minimal* diff.  To the
    contrary, minimal diffs are often counter-intuitive, because they synch
    up anywhere possible, sometimes accidental matches 100 pages apart.
    Restricting synch points to contiguous matches preserves some notion of
    locality, at the occasional cost of producing a longer diff.

    Example: Comparing two texts.

    First we set up the texts, sequences of individual single-line strings
    ending with newlines (such sequences can also be obtained from the
    `readlines()` method of file-like objects):

    >>> text1 = '''  1. Beautiful is better than ugly.
    ...   2. Explicit is better than implicit.
    ...   3. Simple is better than complex.
    ...   4. Complex is better than complicated.
    ... '''.splitlines(keepends=True)
    >>> len(text1)
    4
    >>> text1[0][-1]
    '\n'
    >>> text2 = '''  1. Beautiful is better than ugly.
    ...   3.   Simple is better than complex.
    ...   4. Complicated is better than complex.
    ...   5. Flat is better than nested.
    ... '''.splitlines(keepends=True)

    Next we instantiate a Differ object:

    >>> d = Differ()

    Note that when instantiating a Differ object we may pass functions to
    filter out line and character 'junk'.  See Differ.__init__ for details.

    Finally, we compare the two:

    >>> result = list(d.compare(text1, text2))

    'result' is a list of strings, so let's pretty-print it:

    >>> from pprint import pprint as _pprint
    >>> _pprint(result)
    ['    1. Beautiful is better than ugly.\n',
     '-   2. Explicit is better than implicit.\n',
     '-   3. Simple is better than complex.\n',
     '+   3.   Simple is better than complex.\n',
     '?     ++\n',
     '-   4. Complex is better than complicated.\n',
     '?            ^                     ---- ^\n',
     '+   4. Complicated is better than complex.\n',
     '?           ++++ ^                      ^\n',
     '+   5. Flat is better than nested.\n']

    As a single multi-line string it looks like this:

    >>> print(''.join(result), end="")
        1. Beautiful is better than ugly.
    -   2. Explicit is better than implicit.
    -   3. Simple is better than complex.
    +   3.   Simple is better than complex.
    ?     ++
    -   4. Complex is better than complicated.
    ?            ^                     ---- ^
    +   4. Complicated is better than complex.
    ?           ++++ ^                      ^
    +   5. Flat is better than nested.
    Nc�"�||_||_dS)a�
        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; the underlying SequenceMatcher class has
          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.
        N��linejunk�charjunk)r"r�r�s   rr#zDiffer.__init__*s��(!��
� ��
�
�
rc	#�K�t|j||��}|���D]�\}}}}}|dkr|�||||||��}	no|dkr|�d|||��}	nP|dkr|�d|||��}	n1|dkr|�d|||��}	ntd|�����|	Ed	{V����d	S)
a�
        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 writelines()
        method of a file-like object.

        Example:

        >>> print(''.join(Differ().compare('one\ntwo\nthree\n'.splitlines(True),
        ...                                'ore\ntree\nemu\n'.splitlines(True))),
        ...       end="")
        - one
        ?  ^
        + ore
        ?  ^
        - two
        - three
        ?  -
        + tree
        + emu
        rkrl�-rm�+rnr��unknown tag N)rr�rt�_fancy_replace�_dumpr�)
r"rr�cruncherrsrIrJrKrL�gs
          r�comparezDiffer.compareAs����4#�4�=�!�Q�7�7��'/�';�';�'=�'=�	�	�#�C��c�3���i����'�'��3��Q��S�A�A��������J�J�s�A�s�C�0�0��������J�J�s�A�s�C�0�0��������J�J�s�A�s�C�0�0��� �j�S�S�!:�;�;�;��L�L�L�L�L�L�L�L�	�	rc#�NK�t||��D]}|�d||��V��dS)z4Generate comparison results for a same-tagged range.r�N)rG)r"rsra�lo�hir<s      rr�zDiffer._dumpjsE�����r�2���	(�	(�A� �S�S�!�A�$�$�'�'�'�'�'�	(�	(rc#�K�||z
||z
kr1|�d|||��}|�d|||��}n0|�d|||��}|�d|||��}||fD]
}	|	Ed{V���dS)Nr�r�)r�)
r"rrIrJrrKrL�first�secondr�s
          r�_plain_replacezDiffer._plain_replaceos�������9�s�S�y� � ��Z�Z��Q��S�1�1�E��Z�Z��Q��S�1�1�F�F��Z�Z��Q��S�1�1�E��Z�Z��Q��S�1�1�F����	�	�A��L�L�L�L�L�L�L�L�	�	rc#�~K�d\}}t|j��}	d\}
}t||��D]�}||}
|	�|
��t||��D]�}||}||
kr|
�||}}
�|	�|��|	���|krH|	���|kr0|	���|kr|	���||}}}����||kr+|
�"|�||||||��Ed{V��dS|
|d}}}nd}
|�	||||||��Ed{V��||||}}|
��dx}}|	�
||��|	���D]o\}}}}}||z
||z
}}|dkr|d|zz
}|d|zz
}�)|dkr	|d	|zz
}�8|d
kr	|d|zz
}�G|dkr|d
|zz
}|d
|zz
}�^td|�����|�
||||��Ed{V��nd|zV�|�	||dz|||dz|��Ed{V��dS)aL
        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), end="")
        - abcDefghiJkl
        ?    ^  ^  ^
        + abcdefGhijkl
        ?    ^  ^  ^
        )g�G�z��?g�?�NNNrrrk�^rlr�rmr�rnr�r��  r0)rr�rGr&r%r�r�r�r��
_fancy_helperr!rtr��_qformat)r"rrIrJrrKrL�
best_ratior�r��eqi�eqjrUrqr<rp�best_i�best_j�aelt�belt�atags�btagsrs�ai1�ai2�bj1�bj2r^r_s                             rr�zDiffer._fancy_replace}s+����*(��
�F�"�4�=�1�1�����S�
�s�C���	H�	H�A��1��B����b�!�!�!��3��_�_�
H�
H���q�T����8�8��{�#$�a�S����!�!�"�%�%�%��,�,�.�.��;�;��*�*�,�,�z�9�9��n�n�&�&��3�3�19���1A�1A�1�a���J��!
H�"�����{��.�.�q�#�s�A�s�C�H�H�H�H�H�H�H�H�H���),�c�3�J�F�F�F��C��%�%�a��f�a��f�E�E�E�E�E�E�E�E�E��v�Y��&�	�d���;���E�E����d�D�)�)�)�+3�+?�+?�+A�+A�

@�

@�'��S�#�s�C��s��C�#�I�B���)�#�#��S�2�X�%�E��S�2�X�%�E�E��H�_�_��S�2�X�%�E�E��H�_�_��S�2�X�%�E�E��G�^�^��S�2�X�%�E��S�2�X�%�E�E�$�*���%>�?�?�?��}�}�T�4���>�>�>�>�>�>�>�>�>�>���+�����%�%�a����3��6�!�8�S�I�I�I�I�I�I�I�I�I�I�Irc#��K�g}||kr:||kr|�||||||��}n7|�d|||��}n||kr|�d|||��}|Ed{V��dS)Nr�r�)r�r�)r"rrIrJrrKrLr�s        rr�zDiffer._fancy_helper�s���������9�9��S�y�y��'�'��3��Q��S�A�A����J�J�s�A�s�C�0�0���
�3�Y�Y��
�
�3��3��,�,�A����������rc#��K�t||�����}t||�����}d|zV�|rd|�d�V�d|zV�|r
d|�d�V�dSdS)a�
        Format "?" output and deal with 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'
        �- z? �
�+ N)r��rstrip)r"�aline�bliner�r�s     rr�zDiffer._qformat�s����� "�%��/�/�6�6�8�8��!�%��/�/�6�6�8�8���U�l�����	!� �u�.�.�.� � � ��U�l�����	!� �u�.�.�.� � � � � �	!�	!rr�)r�r�r�r�r#r�r�r�r�r�r�rrrrr�s�������S�S�j!�!�!�!�.'�'�'�R(�(�(�
���\J�\J�\J�|
�
�
�!�!�!�!�!rrNz
\s*(?:#\s*)?$c��||��duS)z�
    Return True 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
    Nr)�line�pats  rrrs���3�t�9�9�D� � r� 	c�
�||vS)z�
    Return True 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
    r)�ch�wss  rrr%s
�� ��8�Orc��|dz}||z
}|dkrd�|��S|s|dz}d�||��S�z Convert range to the "ed" formatr0z{}z{},{}��format��start�stop�	beginningrs    r�_format_range_unifiedr�<sV����	�I�
�E�\�F�
��{�{��{�{�9�%�%�%����Q��	��>�>�)�V�,�,�,rrr�c	#��K�t|||||||��d}td||���|��D�]"}	|sfd}|rd�|��nd}
|rd�|��nd}d�||
|��V�d�|||��V�|	d|	d	}
}t	|d
|
d��}t	|d|
d
��}d�|||��V�|	D]S\}}}}}|dkr|||�D]	}d|zV��
�#|dvr|||�D]	}d|zV��
|dvr|||�D]	}d|zV��
�T��$dS)a�
    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
    FNT�	{}r�
--- {}{}{}z
+++ {}{}{}rrwr0�ru�z@@ -{} +{} @@{}rnr�>rlrkr�>rmrkr�)�_check_typesrr}r�r�)rr�fromfile�tofile�fromfiledate�
tofiledaterA�lineterm�startedr|�fromdate�todater��last�file1_range�file2_rangersrbrfrcrgr�s                      rr
r
Gs�����R��A�x���z�8�L�L�L��G� ��a��*�*�>�>�q�A�A�%�%���	@��G�6B�J�v�}�}�\�2�2�2��H�2<�D�V�]�]�:�.�.�.�"�F��%�%�h��(�C�C�C�C�C��%�%�f�f�h�?�?�?�?�?��A�h��b�	�t��+�E�!�H�d�1�g�>�>��+�E�!�H�d�1�g�>�>���&�&�{�K��J�J�J�J�J�#(�
	%�
	%��C��R��R��g�~�~��b��e�H�%�%�D���*�$�$�$�$���+�+�+��b��e�H�%�%�D���*�$�$�$�$��+�+�+��b��e�H�%�%�D���*�$�$�$�$��
	%�%�%rc��|dz}||z
}|s|dz}|dkrd�|��Sd�|||zdz
��Sr�r�r�s    r�_format_range_contextr��s`����	�I�
�E�\�F����Q��	�
��{�{��{�{�9�%�%�%��>�>�)�Y��%7�!�%;�<�<�<rc	#�K�t|||||||��tdddd���}d}	td||���|��D�]r}
|	sfd}	|rd	�|��nd
}|rd	�|��nd
}d�|||��V�d�|||��V�|
d
|
d}}
d|zV�t|
d|d��}d�||��V�t
d�|
D����r+|
D](\}}}}}|dkr|||�D]}|||zV���)t|
d|d��}d�||��V�t
d�|
D����r+|
D](\}}}}}|dkr|||�D]}|||zV���)��tdS)ah
    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(True),
    ...       'zero\none\ntree\nfour\n'.splitlines(True), 'Original', 'Current')),
    ...       end="")
    *** Original
    --- Current
    ***************
    *** 1,4 ****
      one
    ! two
    ! three
      four
    --- 1,4 ----
    + zero
      one
    ! tree
      four
    r�r�z! r�)rmrlrkrnFNTr�rz
*** {}{}{}r�rrwz***************r0r�z
*** {} ****{}c3�*K�|]\}}}}}|dvV��dS)>rlrkNr�r�rs�_s   rr�zcontext_diff.<locals>.<genexpr>��2����I�I���Q��1�a�s�+�+�I�I�I�I�I�Irrmrur�z
--- {} ----{}c3�*K�|]\}}}}}|dvV��dS)>rmrkNrr�s   rr�zcontext_diff.<locals>.<genexpr>�r�rrl)r��dictrr}r�r��any)rrr�r�r�r�rAr��prefixr�r|r�r�r�r�r�rsrbrfr�r�r�rcrgs                        rr	r	�s^����X��A�x���z�8�L�L�L�
��d�D��
E�
E�
E�F��G� ��a��*�*�>�>�q�A�A�1�1���	@��G�6B�J�v�}�}�\�2�2�2��H�2<�D�V�]�]�:�.�.�.�"�F��%�%�h��(�C�C�C�C�C��%�%�f�f�h�?�?�?�?�?��A�h��b�	�t���(�*�*�*�*�+�E�!�H�d�1�g�>�>���$�$�[�(�;�;�;�;�;��I�I�5�I�I�I�I�I�	1�%*�
1�
1�!��R��Q���(�?�?� !�"�R�%��1�1��$�S�k�D�0�0�0�0�0��+�E�!�H�d�1�g�>�>���$�$�[�(�;�;�;�;�;��I�I�5�I�I�I�I�I�	1�%*�
1�
1�!��Q��2�r��(�?�?� !�"�R�%��1�1��$�S�k�D�0�0�0�0�0���71�1rc��|rOt|dt��s4tdt|d��j�d|d�d����|rOt|dt��s4tdt|d��j�d|d�d����|D])}t|t��std|������*dS)Nrz"lines to compare must be str, not � (�)z all arguments must be str, not: )�
isinstance�str�	TypeError�typer�)rr�args�args    rr�r��s���	�5��A�a�D�#�&�&�5��i��a��d���,�,�,�a��d�d�d�4�5�5�	5��5��A�a�D�#�&�&�5��i��a��d���,�,�,�a��d�d�d�4�5�5�	5��K�K���#�s�#�#�	K��)�C�C�I�J�J�J�	K�K�Krr�
c	
#�PK�d�}	tt|	|����}tt|	|����}|	|��}|	|��}|	|��}|	|��}|	|��}|||||||||��}
|
D]}|�dd��V��dS)a�
    Compare `a` and `b`, two sequences of lines represented as bytes rather
    than str. This is a wrapper for `dfunc`, which is typically either
    unified_diff() or context_diff(). Inputs are losslessly converted to
    strings so that `dfunc` only has to worry about strings, and encoded
    back to bytes on return. This is necessary to compare files with
    unknown or inconsistent encoding. All other inputs (except `n`) must be
    bytes rather than str.
    c��	|�dd��S#t$r0}dt|��j�d|�d�}t	|��|�d}~wwxYw)N�ascii�surrogateescapez!all arguments must be bytes, not rr)�decode�AttributeErrorr
r�r	)r��err�msgs   rrzdiff_bytes.<locals>.decodesm��	*��8�8�G�%6�7�7�7���	*�	*�	*�	*���G�G�$�$�$�a�a�a�)�C��C�.�.�c�)�����	*���s��
A�+A
�
ArrN)r[r\�encode)�dfuncrrr�r�r�r�rAr�r�linesr�s            rrr�s�����*�*�*�	
�S���^�^���A��S���^�^���A��v�h���H�
�V�F�^�^�F��6�,�'�'�L���
�#�#�J��v�h���H��E�!�Q��&�,�
�A�x�P�P�E��6�6���k�k�'�#4�5�5�5�5�5�5�6�6rc�J�t||���||��S)aJ
    Compare `a` and `b` (lists of strings); return a `Differ`-style delta.

    Optional keyword parameters `linejunk` and `charjunk` are for filter
    functions, or can be 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; the underlying SequenceMatcher class has an adaptive
      notion of "noise" lines.

    - charjunk: A function that accepts a character (string of length
      1), and returns true iff the character is junk. The default is
      the module-level function IS_CHARACTER_JUNK, which filters out
      whitespace characters (a blank or tab; note: it's a 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(keepends=True),
    ...              'ore\ntree\nemu\n'.splitlines(keepends=True))
    >>> print(''.join(diff), end="")
    - one
    ?  ^
    + ore
    ?  ^
    - two
    - three
    ?  -
    + tree
    + emu
    )rr�)rrr�r�s    rrrs%��F�(�H�%�%�-�-�a��3�3�3rc#�6����K�ddl}|jd���t||||���ddgf�fd�	���fd���fd�}|��}|�
|Ed{V��dS|dz
}d}	ddg|z}
}	d	}|d	ur<	t|��\}}
}n#t$rYdSwxYw|	|z}||
|f|
|<|	dz
}	|d	u�<|	|krd
V�|}n|	}d}	|r|	|z}|	dz
}	|
|V�|dz}|�|dz
}	|r)t|��\}}
}|r|dz
}n|dz}||
|fV�|�)n#t$rYdSwxYw��)a�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.
    rNz
(\++|\-+|\^+)c���||xxdz
cc<|�%|||�d��dd�fS|dkr�|�d��|�d��}}g}|fd�}��||��t|��D]1\}\}	}
|d|	�dz|z||	|
�zdz||
d�z}�2|dd�}n,|�d��dd�}|sd	}d|z|zdz}|||fS)
aReturns line of text with user's change markup and line formatting.

        lines -- list of lines from the ndiff generator to produce a line of
                 text from.  When producing the line of text to return, the
                 lines used are removed from this list.
        format_key -- '+' return first line in list with "add" markup around
                          the entire line.
                      '-' return first line in list with "delete" markup around
                          the entire line.
                      '?' return first line in list with add/delete/change
                          intraline markup (indices obtained from second line)
                      None return first line in list with no markup
        side -- indice into the num_lines list (0=from,1=to)
        num_lines -- from/to current line number.  This is NOT intended to be a
                     passed parameter.  It is present as a keyword argument to
                     maintain memory of the current line numbers between calls
                     of this function.

        Note, this function is purposefully not defined at the module scope so
        that data it needs from its parent function (within whose context it
        is defined) does not need to be of module scope.
        r0Nrr��?c��|�|�d��d|���g��|�d��S)Nr0r)r4r|�span)�match_object�sub_infos  r�record_sub_infoz3_mdiff.<locals>._make_line.<locals>.record_sub_info�sL������!3�!3�A�!6�!6�q�!9�,�:K�:K�:M�:M� N�O�O�O�#�)�)�!�,�,�,r��r�)rY�sub�reversed)r�
format_key�side�	num_lines�text�markersr r!�key�begin�end�	change_res           �r�
_make_linez_mdiff.<locals>._make_linefsW���.	�$����1��������d�O�E�I�I�a�L�L����$4�5�5�����!�I�I�a�L�L�%�)�)�A�,�,�'�D��H�6>�
-�
-�
-�
-�
�M�M�/�'�2�2�2�$,�H�#5�#5�
N�
N���K�U�3��A�e�G�}�T�)�#�-�d�5��9�o�=�d�B�4����:�M�������8�D�D��9�9�Q�<�<����#�D��
����*�$�t�+�d�2�D��$���%�%rc3�|�K�g}d\}}	t|��dkr6|�t�d����t|��dk�6d�d�|D����}|�d��r|}�n�|�d��r�|dd	���|dd
��dfV���|�d��r|d
z}�|dd	��d
dfV���|�d��r�|dd	��d
}}|d
z
d	}}�nZ|�d��r�|d
d	���|dd
��dfV���C|�d��r�|dd	���|d
d
��dfV���w|�d��r|d
z}�|dd	��d
dfV����|�d��r|d
z
}d
�|dd
��dfV����|�d��rd
�|dd
��}}|d
zd	}}nj|�d��r|d
z
}d
�|dd
��dfV���-|�d��r'�|d
d
�d
d	���|d
d
��dfV���i|d	kr|d
z
}dV�|d	k�|d	kr|d
z}dV�|d	k�|�d��rd
S||dfV����)a�Yields from/to lines of text with a change indication.

        This function is an iterator.  It itself pulls lines from a
        differencing iterator, processes them and yields them.  When it can
        it yields both a "from" and a "to" line, otherwise it will yield one
        or the other.  In addition to yielding the lines of from/to text, a
        boolean flag is yielded to indicate if the text line(s) have
        differences in them.

        Note, this function is purposefully not defined at the module scope so
        that data it needs from its parent function (within whose context it
        is defined) does not need to be of module scope.
        )rrTr��Xrc��g|]
}|d��S)rr)r�r�s  rr�z2_mdiff.<locals>._line_iterator.<locals>.<listcomp>�s��3�3�3�T��a��3�3�3rz-?+?rrr0z--++r�N)z--?+z--+r�z-+?z-?+z+--r�)r�z+-r�F)N�rr�T)r3NT)r:r4�nextr��
startswith)r�num_blanks_pending�num_blanks_to_yieldr��	from_line�to_liner/�diff_lines_iterators      ��r�_line_iteratorz_mdiff.<locals>._line_iterator�s��������26�/��/�F	-��e�*�*�q�.�.����T�"5�s�;�;�<�<�<��e�*�*�q�.�.����3�3�U�3�3�3�4�4�A��|�|�C� � �3
�'9�#�#����f�%�%�.
� �j��s�1�-�-�z�z�%��A�/F�/F��L�L�L�L�����f�%�%�*
�#�a�'�"� �j��s�1�-�-�t�T�9�9�9�9�����3�4�4�$
�%/�J�u�S��$;�$;�T�'�	�9K�A�9M�a�$6�#�#����e�$�$�
� �j��t�A�.�.�
�
�5��Q�0G�0G��M�M�M�M�����e�$�$�
� �j��s�1�-�-�z�z�%��Q�/G�/G��M�M�M�M�����c�"�"�
�"�a�'�"� �j��s�1�-�-�t�T�9�9�9�9�����e�$�$�
�#�a�'�"��J�J�u�S��3�3�T�9�9�9�9�����l�+�+�
�%)�:�:�e�C��+B�+B�7�	�9K�A�9M�a�$6�#�#����c�"�"�
�"�a�'�"��J�J�u�S��3�3�T�9�9�9�9�����c�"�"�
� �j��q�q�q��$�q�1�1�*�*�U�4��2J�2J�5�P�P�P�P��&��)�)�#�q�(�#�)�)�)�)�&��)�)�&��)�)�#�q�(�#�)�)�)�)�&��)�)��|�|�C� � �
-������,�,�,�,�MF	-rc3���K����}gg}}	t|��dkst|��dkr~	t|��\}}}n#t$rYdSwxYw|�|�||f��|�|�||f��t|��dk�kt|��dk�~|�d��\}}|�d��\}}|||p|fV���)atYields from/to lines of text with a change indication.

        This function is an iterator.  It itself pulls lines from the line
        iterator.  Its difference from that iterator is that this function
        always yields a pair of from/to text lines (with the change
        indication).  If necessary it will collect single from/to lines
        until it has a matching pair from/to pair to yield.

        Note, this function is purposefully not defined at the module scope so
        that data it needs from its parent function (within whose context it
        is defined) does not need to be of module scope.
        TrN)r:r4�
StopIterationr4rY)	�
line_iterator�	fromlines�tolinesr8r9�
found_diff�fromDiff�to_diffr;s	        �r�_line_pair_iteratorz#_mdiff.<locals>._line_pair_iterator�s&�����'��(�(�
��R�'�	�	:��y�>�>�1�$�$��G���a����59�-�5H�5H�2�I�w�
�
��$�����F�F������(��$�$�i�
�%;�<�<�<��&��N�N�G�J�#7�8�8�8��y�>�>�1�$�$��G���a���#,�-�-��"2�"2��I�x�&�{�{�1�~�~��G�W��W�X�%8��9�9�9�9�	:s�A�
A�Ar0TF)NNN)�re�compilerr4r=)r?r@�contextr�r�rErD�line_pair_iterator�lines_to_write�index�contextLinesrAr8r9r<r;r/r.r:s               @@@@r�_mdiffrL<su��������D�I�I�I���
�+�,�,�I� �	�'�(�8�D�D��78��e�6&�6&�6&�6&�6&�6&�pV-�V-�V-�V-�V-�V-�p:�:�:�:�:�B-�,�.�.����%�%�%�%�%�%�%�%�%�%�	�1�����(	�#$�d�V�W�%5�<�E��J���%�%��59�:L�5M�5M�2�I�w�
�
��$�����F�F������G�O��#,�g�z�"B��Q����
����%�%��w���&�&�&�&�!(���!&���� �
$��G�O����
��"�1�o�%�%�%��!�#��	!�
$�%�Q�Y�N�
�$�9�59�:L�5M�5M�2�I�w�
�!�,�)0�����&�!�+��#�W�j�8�8�8�8�%�9���!�
�
�
����
����M(	s$�.B�
B�B�+D	�	
D�Dan
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

<head>
    <meta http-equiv="Content-Type"
          content="text/html; charset=%(charset)s" />
    <title></title>
    <style type="text/css">%(styles)s
    </style>
</head>

<body>
    %(table)s%(legend)s
</body>

</html>aH
        table.diff {font-family:Courier; border:medium;}
        .diff_header {background-color:#e0e0e0}
        td.diff_header {text-align:right}
        .diff_next {background-color:#c0c0c0}
        .diff_add {background-color:#aaffaa}
        .diff_chg {background-color:#ffff77}
        .diff_sub {background-color:#ffaaaa}aZ
    <table class="diff" id="difflib_chg_%(prefix)s_top"
           cellspacing="0" cellpadding="0" rules="groups" >
        <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup>
        <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup>
        %(header_row)s
        <tbody>
%(data_rows)s        </tbody>
    </table>a�
    <table class="diff" summary="Legends">
        <tr> <th colspan="2"> Legends </th> </tr>
        <tr> <td> <table border="" summary="Colors">
                      <tr><th> Colors </th> </tr>
                      <tr><td class="diff_add">&nbsp;Added&nbsp;</td></tr>
                      <tr><td class="diff_chg">Changed</td> </tr>
                      <tr><td class="diff_sub">Deleted</td> </tr>
                  </table></td>
             <td> <table border="" summary="Links">
                      <tr><th colspan="2"> Links </th> </tr>
                      <tr><td>(f)irst change</td> </tr>
                      <tr><td>(n)ext change</td> </tr>
                      <tr><td>(t)op</td> </tr>
                  </table></td> </tr>
    </table>c�~�eZdZdZeZeZeZeZdZddde	fd�Z
		dd	d
�d�Zd�Zd
�Z
d�Zd�Zd�Zd�Zd�Z		dd�ZdS)ra{For producing HTML side by side comparison with change highlights.

    This class can be used to create an HTML table (or a complete HTML file
    containing the table) showing a side by side, line by line comparison
    of text with inter-line and intra-line change highlights.  The table can
    be generated in either full or contextual difference mode.

    The following methods are provided for HTML generation:

    make_table -- generates HTML for a single side by side table
    make_file -- generates complete HTML file with a single side by side table

    See tools/scripts/diff.py for an example usage of this class.
    r�Nc�>�||_||_||_||_dS)a�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 by
            HtmlDiff() to generate the side by side HTML differences).  See
            ndiff() documentation for argument default values and descriptions.
        N)�_tabsize�_wrapcolumn�	_linejunk�	_charjunk)r"�tabsize�
wrapcolumnr�r�s     rr#zHtmlDiff.__init__�s%�� ��
�%���!���!����rrF�zutf-8)�charsetc
���|jt|j|j|�||||||���|���z�|d���|��S)aReturns 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).
        charset -- charset of the HTML document
        )rG�numlines)�styles�legend�tablerW�xmlcharrefreplace)�_file_templater�_styles�_legend�
make_tablerr)r"r?r@�fromdesc�todescrGrYrWs        r�	make_filezHtmlDiff.make_file�st��&�#�d��<��<��/�/�)�W�h��*1�H�"�F�F��'
�'
�'
�
��6�'�.�/�/���w���
	@rc�P����fd���fd�|D��}�fd�|D��}||fS)aReturns 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.
        c����|�dd��}|��j��}|�dd��}|�dd���d��S)Nr�r"�	r�)rk�
expandtabsrPr�)r�r"s �r�expand_tabsz2HtmlDiff._tab_newline_replace.<locals>.expand_tabs�s`����<�<��D�)�)�D��?�?�4�=�1�1�D��<�<��D�)�)�D��<�<��S�)�)�0�0��6�6�6rc�&��g|]
}�|����Srr�r�r�ris  �rr�z1HtmlDiff._tab_newline_replace.<locals>.<listcomp>�s#���=�=�=�4�[�[��&�&�=�=�=rc�&��g|]
}�|����Srrrks  �rr�z1HtmlDiff._tab_newline_replace.<locals>.<listcomp>�s#���9�9�9��;�;�t�$�$�9�9�9rr)r"r?r@ris`  @r�_tab_newline_replacezHtmlDiff._tab_newline_replace�s\����	7�	7�	7�	7�	7�>�=�=�=�9�=�=�=�	�9�9�9�9��9�9�9���� � rc�<�|s|�||f��dSt|��}|j}||ks||�d��dzz
|kr|�||f��dSd}d}d}||krO||krI||dkr|dz
}||}|dz
}n||dkr|dz
}d}n
|dz
}|dz
}||kr||k�I|d|�}	||d�}
|r
|	dz}	d|z|
z}
|�||	f��|�|d|
��dS)	a�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.
        Nr"rurrr0r#�>)r4r:rQ�count�_split_line)r"�	data_list�line_numr)rrrxr<rA�mark�line1�line2s           rrqzHtmlDiff._split_line�s����	����h�t�_�-�-�-��F��4�y�y������C�K�K�d�T�Z�Z��%5�%5�a�%7�8�S�@�@����h�t�_�-�-�-��F�
��
�����#�g�g�!�d�(�(��A�w�$����Q����A�w���Q�����a��D����Q�������Q����Q����#�g�g�!�d�(�(��R�a�R����Q�R�R���
�	(��D�L�E��4�K�%�'�E�	���(�5�)�*�*�*�	
����3�u�-�-�-�-�-rc#�0K�|D]�\}}}|�|||fV��||c\}}\}}gg}
}	|�|	||��|�|
||��|	s|
r?|	r|	�d��}nd}|
r|
�d��}nd}|||fV�|	�=|
�?��dS)z5Returns iterator that splits (wraps) mdiff text linesNr)rr�)rqrY)r"�diffs�fromdata�todata�flag�fromline�fromtext�toline�totext�fromlist�tolists           r�
_line_wrapperzHtmlDiff._line_wrappers����%*�	+�	+� �H�V�D��|��v�d�*�*�*�*��2:�6�/��X�h����!��V�H����X�h�x�8�8�8����V�F�6�2�2�2��	
+�f�	
+��(�'�|�|�A���H�H�'�H��&�#�Z�Z��]�]�F�F�%�F��v�d�*�*�*�*��	
+�f�	
+��	+�	+rc�T�ggg}}}|D]�\}}}	|�|jd|g|�R���|�|jd|g|�R���n:#t$r-|�d��|�d��YnwxYw|�|����|||fS)z�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.
        rr0N)r4�_format_liner	)r"rxr�r��flaglistryrzr{s        r�_collect_lineszHtmlDiff._collect_lines.s���$&�b�����$)�		"�		"� �H�V�D�
$���� 1�� 1�!�D� C�(� C� C� C�D�D�D��
�
�/�d�/��$�?��?�?�?�@�@�@�@���
$�
$�
$�����%�%�%��
�
�d�#�#�#�#�#�
$����
�O�O�D�!�!�!�!���x�'�'s�AA�4B�Bc�>�	d|z}d|j|�|�d�}n#t$rd}YnwxYw|�dd���dd���d	d
��}|�dd�����}d
|�d|�d|�d�S)aReturns 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
        z%dz id="�"r�&z&amp;roz&gt;�<z&lt;r��&nbsp;z<td class="diff_header"z</td><td nowrap="nowrap">z</td>)�_prefixr	rkr�)r"r'r{�linenumr)�ids      rr�zHtmlDiff._format_lineCs���	��W�n�G�G�!%��d�!3�!3�G�G�G�<�B�B���	�	�	��B�B�B�	�����\�\�#�g�
&�
&�
.�
.�s�6�
:�
:�
B�
B�3�v�
N�
N���|�|�C��)�)�0�0�2�2����"�"�W�W�W�T�T�T�#�	#s��*�*c�~�dtjz}dtjz}txjdz
c_||g|_dS)zCreate unique anchor prefixeszfrom%d_zto%d_r0N)r�_default_prefixr�)r"�
fromprefix�toprefixs   r�_make_prefixzHtmlDiff._make_prefixZsB��
��!9�9�
��X�5�5��� � �A�%� � �"�8�,����rc��|jd}dgt|��z}dgt|��z}d\}	}
d}t|��D]=\}}
|
r4|
s1d}
|}td||z
g��}d||	fz||<|	dz
}	d||	fz||<�;d}
�>|sdg}dg}dg}d}|rd	g}|}nd
gx}}|dsd|z|d<d|z||<|||||fS)
zMakes list of "next" linksr0r)rFrTz id="difflib_chg_%s_%d"z"<a href="#difflib_chg_%s_%d">n</a>Fz2<td></td><td>&nbsp;No Differences Found&nbsp;</td>z(<td></td><td>&nbsp;Empty File&nbsp;</td>z!<a href="#difflib_chg_%s_0">f</a>z#<a href="#difflib_chg_%s_top">t</a>)r�r:r2rx)r"r�r�r�rGrYr��next_id�	next_href�num_chg�	in_changer�r<r{s              r�_convert_flagszHtmlDiff._convert_flagsesS���<��?���$�s�8�}�}�$���D��X���&�	�%��������)�)�	"�	"�F�A�d��
"� �+� $�I��D��Q�q��z�N�+�+�A�!:�h�w�=O�!O�G�A�J��q�L�G�&J�!�'�N+�'+�I�d�O��"�	�	��		Q��w�H��d�G���I��D��
Q�P�Q��!���%O�$P�P��6���{�	J�>��I�I�a�L�?�8�L�	�$����x�	�'�9�9rc
��|���|�||��\}}|r|}nd}t||||j|j���}|jr|�|��}|�|��\}	}
}|�|	|
|||��\}	}
}}}
g}d}tt|����D]a}||�|dkr|�d���&|�||
||||	||||
|fz���b|s|rdd�d|z�d�d|z�d	�}nd
}|jtd
�|��||jd���z}|�d
d���dd���dd���dd���dd��S)a�Returns HTML table 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).
        Nr�zV            <tr><td class="diff_next"%s>%s</td>%s<td class="diff_next">%s</td>%s</tr>
rz)        </tbody>        
        <tbody>
z<thead><tr>z!<th class="diff_next"><br /></th>z+<th colspan="2" class="diff_header">%s</th>z
</tr></thead>rr0)�	data_rows�
header_rowrz+z<span class="diff_add">z-z<span class="diff_sub">z^z<span class="diff_chg">r#z</span>rgr�)r�rmrLrRrSrQr�r�r�rGr:r4�_table_templaterr�r�rk)r"r?r@rbrcrGrY�
context_linesrxr�r�r�r�r�r��fmtr<r�r\s                   rrazHtmlDiff.make_table�sJ��(	
������!�5�5�i��H�H��	�'��	!�$�M�M� �M��y�����#�~�/�/�/����	.��&�&�u�-�-�E�$(�#6�#6�u�#=�#=� ����6:�5H�5H��V�H�W�X�67�67�2�����7�
��7���s�8�}�}�%�%�	D�	D�A���{�"��q�5�5��H�H�J�K�K�K�����#����I�a�L��!��+4�Q�<��q�	�!C�C�D�D�D�D��	�v�	��3�3�=��H�H�3�3�=��F�F�F�	H�J�J��J��$�t��g�g�a�j�j�!��<��?�($�($�($�$��
�}�}�U�#<�=�=��W�U�#<�=�=��W�U�#<�=�=��W�T�)�,�,��W�T�(�+�+�		,r)rrFrV)r�r�r�r�r^r_r�r`r�rr#rdrmrqr�r�r�r�r�rarrrrr�s������
�
�$�N��G�%�O��G��O��4��+�"�"�"�"�"AC�*+�@�8?�@�@�@�@�@�6!�!�!�.5.�5.�5.�n+�+�+�8(�(�(�*#�#�#�.	-�	-�	-�-:�-:�-:�^IN��K,�K,�K,�K,�K,�K,rrc#��K�	ddd�t|��}n!#t$rtd|z��d�wxYwd|f}|D]}|dd�|vr|dd�V��dS)a0
    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(keepends=True),
    ...              'ore\ntree\nemu\n'.splitlines(keepends=True))
    >>> diff = list(diff)
    >>> print(''.join(restore(diff, 1)), end="")
    one
    two
    three
    >>> print(''.join(restore(diff, 2)), end="")
    ore
    tree
    emu
    r�r�)r0r�z)unknown delta choice (must be 1 or 2): %rNr�r�)�int�KeyErrorr�)�delta�whichrs�prefixesr�s     rrr�s�����,.��4� � ��U���,�����.�.�.��D�"�#�$�$�)-�	.�.�����c�{�H���������8�x����q�r�r�(�N�N�N���s��;c�<�ddl}ddl}|�|��S)Nr)�doctest�difflib�testmod)r�r�s  r�_testr�s,�����������?�?�7�#�#�#r�__main__)rur�)r�)rrrrrur�)rrrrrur
)&r��__all__�heapqrr��collectionsr�_namedtuple�typesrr
rrrr�rrErF�matchrrr�r
r�r	r�rrrLr^r_r�r`�objectrrr�r�rrr�<module>r�s�����8>�>�>��(�'�'�'�'�'�1�1�1�1�1�1���������G�Z�(�(�����
k	2�k	2�k	2�k	2�k	2�k	2�k	2�k	2�\.&�.&�.&�.&�b���l!�l!�l!�l!�l!�l!�l!�l!�~	
�	�	�	�%�2�:�&6�7�7�=�!�!�!�!� ����.	-�	-�	-�=?�.2�B%�B%�B%�B%�R	=�	=�	=�,.�?C�J1�J1�J1�J1�XK�K�K�"25�?D�6�6�6�6�<�(9�#4�#4�#4�#4�J(,�d�%�K�K�K�K�\��(0������"],�],�],�],�],�v�],�],�],�~
����@$�$�$��z���	�E�G�G�G�G�G��r

ZeroDay Forums Mini