ok

Mini Shell

Direktori : /opt/cloudlinux/venv/lib64/python3.11/site-packages/lxml/html/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/lxml/html/__pycache__/diff.cpython-311.pyc

�

�܋fYw����ddlmZddlZddlmZddlmZddlZddgZ	ddl	m
Zn#e$r	ddl
m
ZYnwxYw	eZn
#e$reZYnwxYw	en
#e$reZYnwxYwd�Zefd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�ZdGd�Zd�ZGd�d��ZGd�d��Z Gd�de!��Z"d�Z#d�Z$d�Z%d�Z&d�Z'd �Z(Gd!�d"e��Z)Gd#�d$e)��Z*Gd%�d&e)��Z+dHd(�Z,dHd)�Z-ej.d*ej/ej0z��Z1ej.d+ej/ej0z��Z2ej.d,ej/ej0z��Z3d-�Z4ej.d.��Z5d/�Z6d0�Z7d1Z8d2Z9d3Z:dGd4�Z;ej.d5ej<��Z=d6�Z>ej.d7��Z?d8�Z@d9�ZAd:�ZBd;�ZCd<�ZDd=�ZEdGd>�ZFd?�ZGd@�ZHdA�ZIdB�ZJGdC�dDejK��ZLeMdEkrddFlmNZNeNjO��dSdS)I�)�absolute_importN)�etree)�fragment_fromstring�
html_annotate�htmldiff)�escapec�J�dtt|��d���d|�d�S)Nz
<span title="�z">z</span>)�html_escape�_unicode)�text�versions  �a/builddir/build/BUILD/cloudlinux-venv-1.0.6/venv/lib64/python3.11/site-packages/lxml/html/diff.py�default_markuprs/����H�W�%�%�q�)�)�)�)�4�4�4�1�1�c���d�|D��}|d}|dd�D]}t||��|}�t|��}t||��}d�|�����S)a
    doclist should be ordered from oldest to newest, like::

        >>> version1 = 'Hello World'
        >>> version2 = 'Goodbye World'
        >>> print(html_annotate([(version1, 'version 1'),
        ...                      (version2, 'version 2')]))
        <span title="version 2">Goodbye</span> <span title="version 1">World</span>

    The documents must be *fragments* (str/UTF8 or unicode), not
    complete documents

    The markup argument is a function to markup the spans of words.
    This function is called like markup('Hello', 'version 2'), and
    returns HTML.  The first argument is text and never includes any
    markup.  The default uses a span with a title:

        >>> print(default_markup('Some Text', 'by Joe'))
        <span title="by Joe">Some Text</span>
    c�4�g|]\}}t||����S�)�tokenize_annotated)�.0�docrs   r�
<listcomp>z!html_annotate.<locals>.<listcomp>=s6��.�.�.�!�S�'�$�C��1�1�.�.�.rrr
N�)�html_annotate_merge_annotations�compress_tokens�markup_serialize_tokens�join�strip)�doclist�markup�	tokenlist�
cur_tokens�tokens�results      rrr#s���4.�.�%,�.�.�.�I��1��J��A�B�B�-����'�
�F�;�;�;��
�
�!��,�,�J�
$�Z��
8�
8�F�
�7�7�6�?�?� � �"�"�"rc�@�t|d���}|D]	}||_�
|S)zFTokenize a document and add an annotation attribute to each token
    F��
include_hrefs)�tokenize�
annotation)rr)r#�toks    rrrKs3���c��
/�
/�
/�F��$�$��#�����Mrc��t||���}|���}|D]2\}}}}}|dkr$|||�}	|||�}
t|	|
���3dS)z�Merge the annotations from tokens_old into tokens_new, when the
    tokens in the new document already existed in the old document.
    ��a�b�equalN)�InsensitiveSequenceMatcher�get_opcodes�copy_annotations)�
tokens_old�
tokens_new�s�commands�command�i1�i2�j1�j2�eq_old�eq_news           rrrSs��	#�Z�:�>�>�>�A��}�}���H�#+�-�-����R��R��g�����2��&�F���2��&�F��V�V�,�,�,��	-�-rc��t|��t|��ksJ�t||��D]\}}|j|_�dS)zN
    Copy annotations from the tokens listed in src to the tokens in dest
    N)�len�zipr))�src�dest�src_tok�dest_toks    rr2r2`sU���s�8�8�s�4�y�y� � � � � ��d�^�^�1�1����%�0����1�1rc���|dg}|dd�D]R}|djs.|js'|dj|jkrt||���=|�|���S|S)zm
    Combine adjacent tokens when there is no HTML between the tokens, 
    and they share an annotation
    rr
N���)�	post_tags�pre_tagsr)�compress_merge_back�append)r#r$r*s   rrrhs���
�Q�i�[�F��a�b�b�z�����r�
�$�	���	��2�J�!�S�^�3�3����,�,�,�,��M�M�#������Mrc�L�|d}t|��tust|��tur|�|��dSt|��}|jr
||jz
}||z
}t||j|j|j���}|j|_||d<dS)zY Merge tok into the last element of tokens (modifying the list of
    tokens in-place).  rF�rHrG�trailing_whitespaceN)�type�tokenrJrrMrHrGr))r#r*�lastr
�mergeds     rrIrIws����"�:�D��D�z�z����$�s�)�)�5�"8�"8��
�
�c��������~�~���#�	-��D�,�,�D������t� $�
�!$��+.�+B�D�D�D��!�O�����r�
�
�
rc#�K�|D]X}|jD]}|V��|���}|||j��}|jr
||jz
}|V�|jD]}|V���YdS)zz
    Serialize the list of tokens into a list of text chunks, calling
    markup_func around text to add annotations.
    N)rH�htmlr)rMrG)r#�markup_funcrO�prerS�posts      rrr�s�����
�	�	���>�	�	�C��I�I�I�I��z�z�|�|���{�4��!1�2�2���$�	.��E�-�-�D��
�
�
��O�	�	�D��J�J�J�J�	�	�	rc���t|��}t|��}t||��}d�|�����}t	|��S)a� Do a diff of the old and new document.  The documents are HTML
    *fragments* (str/UTF8 or unicode), they are not complete documents
    (i.e., no <html> tag).

    Returns HTML with <ins> and <del> tags added around the
    appropriate text.  

    Markup is generally ignored, with the markup from new_html
    preserved, and possibly some markup from old_html (though it is
    considered acceptable to lose some of the old markup).  Only the
    words in the HTML are diffed.  The exception is <img> tags, which
    are treated like words, and the href attribute of <a> tags, which
    are noted inside the tag itself when there are changes.
    r)r(�htmldiff_tokensrr�fixup_ins_del_tags)�old_html�new_html�old_html_tokens�new_html_tokensr$s     rrr�sV��"�x�(�(�O��x�(�(�O�
�_�o�
>�
>�F�
�W�W�V�_�_�
"�
"�
$�
$�F��f�%�%�%rc��t||���}|���}g}|D]�\}}}}}	|dkr-|�t|||	�d������;|dks|dkr't|||	���}
t	|
|��|dks|dkr't|||���}t||����t
|��}|S)z] Does a diff on the tokens themselves, returning a list of text
    chunks (not tokens).
    r,r/T)r/�insert�replace�delete)r0r1�extend�
expand_tokens�merge_insert�merge_delete�cleanup_delete)�html1_tokens�html2_tokensr5r6r$r7r8r9r:r;�
ins_tokens�
del_tokenss            rrXrX�s��"	#�\�\�B�B�B�A��}�}���H�
�F�#+�	-�	-����R��R��g����M�M�-��R��U�(;�4�H�H�H�I�I�I���h���'�Y�"6�"6�&�|�B�r�E�':�;�;�J���V�,�,�,��h���'�Y�"6�"6�&�|�B�r�E�':�;�;�J���V�,�,�,��
�F�
#�
#�F��MrFc#��K�|D]c}|jD]}|V��|r|js<|jr|���|jzV�n|���V�|jD]}|V���ddS)zeGiven a list of tokens, return a generator of the chunks of
    text for the data in the tokens.
    N)rH�hide_when_equalrMrSrG)r#r/rOrUrVs     rrcrc�s������	�	���>�	�	�C��I�I�I�I��	#�E�1�	#��(�
#��j�j�l�l�U�%>�>�>�>�>�>��j�j�l�l�"�"�"��O�	�	�D��J�J�J�J�	�	�	rc��t|��\}}}|�|��|r+|d�d��s|dxxdz
cc<|�d��|r.|d�d��r|ddd�|d<|�|��|�d��|�|��dS)z| doc is the already-handled document (as a list of text chunks);
    here we add <ins>ins_chunks</ins> to the end of that.  rF� z<ins>Nz</ins> )�split_unbalancedrb�endswithrJ)�
ins_chunksr�unbalanced_start�balanced�unbalanced_ends     rrdrd�s���2B�*�1M�1M�.��h���J�J�� � � �
��3�r�7�#�#�C�(�(��	�B����3������J�J�w�����)�H�R�L�)�)�#�.�.�)���|�C�R�C�(�����J�J�x�����J�J�y�����J�J�~�����rc��eZdZdS)�	DEL_STARTN��__name__�
__module__�__qualname__rrrrvrv��������Drrvc��eZdZdS)�DEL_ENDNrwrrrr}r}r{rr}c��eZdZdZdS)�	NoDeleteszY Raised when the document no longer contains any pending deletes
    (DEL_START/DEL_END) N)rxryrz�__doc__rrrrrs���������rrc��|�t��|�|��|�t��dS)z� Adds the text chunks in del_chunks to the document doc (another
    list of text chunks) with marker to show it is a delete.
    cleanup_delete later resolves these markers into <del> tags.N)rJrvrbr})�
del_chunksrs  rrere
s@���J�J�y�����J�J�z�����J�J�w�����rc�*�		t|��\}}}n#t$rYn�wxYwt|��\}}}t|||��t	|||��|}|r+|d�d��s|dxxdz
cc<|�d��|r.|d�d��r|ddd�|d<|�|��|�d��|�|��|}��|S)a� Cleans up any DEL_START/DEL_END markers in the document, replacing
    them with <del></del>.  To do this while keeping the document
    valid, it may need to drop some tags (either start or end tags).

    It may also move the del into adjacent tags to try to move it to a
    similar location where it was originally located (e.g., moving a
    delete into preceding <div> tag, if the del looks like (DEL_START,
    'Text</div>', DEL_END)r
rFrnz<del>Nz</del> )�split_deleterro�locate_unbalanced_start�locate_unbalanced_endrprJrb)�chunks�
pre_deletera�post_deleterrrsrtrs        rrfrfsL���	�.:�6�.B�.B�+�J������	�	�	��E�	����
6F�f�5M�5M�2��(�N�	 � 0�*�k�J�J�J��n�j�+�F�F�F����	�s�2�w�'�'��,�,�	���G�G�G�s�N�G�G�G��
�
�7�����	-����-�-�c�2�2�	-�#�B�<����,�H�R�L��
�
�8�����
�
�9�����
�
�;������7�8�Ms��
$�$c�.�g}g}g}g}|D�]Z}|�d��s|�|���.|ddk}|���d�d��}|tvr|�|����|r�|rE|dd|kr3|�|��|���\}}}	|	||<��|r8|�d�|D����g}|�|����	|�|���� |�|t|��|f��|�d����\|�d	�|D����d
�|D��}|||fS)a]Return (unbalanced_start, balanced, unbalanced_end), where each is
    a list of text and tag chunks.

    unbalanced_start is a list of all the tags that are opened, but
    not closed in this span.  Similarly, unbalanced_end is a list of
    tags that are closed but were not opened.  Extracting these might
    mean some reordering of the chunks.�<r
�/r�<>/rFc��g|]\}}}|��	Srr)r�name�pos�tags    rrz$split_unbalanced.<locals>.<listcomp>Ts��B�B�B�n�d�C��c�B�B�BrNc��g|]\}}}|��	Srr)rr�r��chunks    rrz$split_unbalanced.<locals>.<listcomp>]s��1�1�1�#�4��e��1�1�1rc��g|]}|�|��S�Nr)rr�s  rrz$split_unbalanced.<locals>.<listcomp>^s��A�A�A�%�u�/@��/@�/@�/@r)�
startswithrJ�splitr�
empty_tags�poprbr?)
r��start�end�	tag_stackrsr��endtagr�r�r�s
          rroro9s���
�E�
�C��I��H��"�"������$�$�	��O�O�E�"�"�"���q��S����{�{�}�}�Q��%�%�e�,�,���:����O�O�E�"�"�"���
	"��	
"�Y�r�]�1�-��5�5�����&�&�&�!*�������c�3� #���
�
��
"����B�B�	�B�B�B�C�C�C��	��
�
�5�!�!�!�!��
�
�5�!�!�!�!����d�C��M�M�5�9�:�:�:��O�O�D�!�!�!�!�	�L�L�1�1�y�1�1�1�3�3�3�A�A�8�A�A�A�H��(�C��rc���	|�t��}n#t$rt�wxYw|�t��}|d|�||dz|�||dzd�fS)z� Returns (stuff_before_DEL_START, stuff_inside_DEL_START_END,
    stuff_after_DEL_END).  Returns the first case found (there may be
    more DEL_STARTs in stuff_after_DEL_END).  Raises NoDeletes if
    there's no DEL_START found. Nr
)�indexrv�
ValueErrorrr})r�r��pos2s   rr�r�asy��
��l�l�9�%�%���������������<�<�� � �D��$�3�$�<���A��d�
�+�V�D��F�G�G�_�<�<s��/c�
�	|sd	S|d}|���d�d��}|sd	S|d}|tus|�d��sd	S|ddkrd	S|���d�d��}|dkrd	S|dks
Jd|z���||kr>|�d��|�|�d����nd	S��)
a� pre_delete and post_delete implicitly point to a place in the
    document (where the two were split).  This moves that point (by
    popping items from one and pushing them onto the other).  It moves
    the point to try to find a place where unbalanced_start applies.

    As an example::

        >>> unbalanced_start = ['<div>']
        >>> doc = ['<p>', 'Text', '</p>', '<div>', 'More Text', '</div>']
        >>> pre, post = doc[:3], doc[3:]
        >>> pre, post
        (['<p>', 'Text', '</p>'], ['<div>', 'More Text', '</div>'])
        >>> locate_unbalanced_start(unbalanced_start, pre, post)
        >>> pre, post
        (['<p>', 'Text', '</p>', '<div>'], ['More Text', '</div>'])

    As you can see, we moved the point so that the dangling <div> that
    we found will be effectively replaced by the div in the original
    document.  If this doesn't work out, we just throw away
    unbalanced_start without doing anything.
    r
rz<>r�r��ins�delzUnexpected delete tag: %rN)r�rrvr�r�rJ)rrr�r��finding�finding_name�nextr�s       rr�r�ms��,��	��E�"�1�%���}�}���q�)�/�/��5�5���	��E��1�~���9���D�O�O�C�$8�$8���E���7�c�>�>��E��z�z�|�|�A��$�$�T�*�*���5�=�=��E��u�}�}�}�'�$�.��}�}��<���� � ��#�#�#����k�o�o�a�0�0�1�1�1�1�
�E�5rc���	|sdS|d}|���d�d��}|sdS|d}|tus|�d��sdS|���d�d��}|dks|dkrdS||kr=|���|�d|�����ndS��)	zt like locate_unbalanced_start, except handling end tags and
    possibly moving the point earlier in the document.  r
rFrr��</r�r�N)r�rr}r�r�r_)rtr�r�r�r�r�r�s       rr�r��s�����	��E� ��$���}�}���q�)�/�/��6�6���	��E��"�~���7�?�?�$�/�/�$�"7�"7�?��E��z�z�|�|�A��$�$�U�+�+���5�=�=�D�E�M�M��E��<������ � � ����q�*�.�.�"2�"2�3�3�3�3�
�E�+rc�*�eZdZdZdZdd�Zd�Zd�ZdS)	rOa8 Represents a diffable token, generally a word that is displayed to
    the user.  Opening tags are attached to this token when they are
    adjacent (pre_tags) and closing tags that follow the word
    (post_tags).  Some exceptions occur when there are empty tags
    adjacent to a word, so there may be close tags in pre_tags, or
    open tags in post_tags.

    We also keep track of whether the word was originally followed by
    whitespace, even though we do not want to treat the word as
    equivalent to a similar word that does not have a trailing
    space.FNrc��t�||��}|�||_ng|_|�||_ng|_||_|Sr�)r�__new__rHrGrM)�clsr
rHrGrM�objs      rr�z
token.__new__�sP�����s�D�)�)����#�C�L�L��C�L�� �%�C�M�M��C�M�"5����
rc	�n�dt�|���d|j�d|j�d|j�d�	S)Nztoken(�, �))r�__repr__rHrGrM��selfs rr�ztoken.__repr__�sC���*2�*;�*;�D�*A�*A�*A�*A�4�=�=�=�*.�.�.�.�$�:R�:R�:R�T�	Trc� �t|��Sr�)rr�s rrSz
token.html�s����~�~�r�NNr)rxryrzr�rlr�r�rSrrrrOrO�sZ������
�
��O�����"T�T�T�����rrOc�*�eZdZdZ		dd�Zd�Zd�ZdS)�	tag_tokenz� Represents a token that is actually a tag.  Currently this is just
    the <img> tag, which takes up visible space just like a word but
    is only represented in a document by a tag.  Nrc��t�|t�d|��|||���}||_||_||_|S)Nz: rL)rOr�rNr��data�	html_repr)r�r�r�r�rHrGrMr�s        rr�ztag_token.__new__�sP���m�m�C�T�T�T�4�4�!8�%-�&/�0C��E�E��������!��
��
rc
�h�d|j�d|j�d|j�d|j�d|j�d|j�d�
S)Nz
tag_token(r�z, html_repr=z, post_tags=z, pre_tags=z, trailing_whitespace=r�)r�r�r�rHrGrMr�s rr�ztag_token.__repr__�sG����H�H�H��I�I�I��N�N�N��M�M�M��N�N�N��$�$�$�
&�	&rc��|jSr�)r�r�s rrSztag_token.html�s
���~�rr�)rxryrzr�r�r�rSrrrr�r��sX������5�5�59�46�	�	�	�	�&�&�&�����rr�c��eZdZdZdZd�ZdS)�
href_tokenzh Represents the href in an anchor tag.  Unlike other words, we only
    show the href when it changes.  Tc��d|zS)Nz	 Link: %srr�s rrSzhref_token.htmls
���T�!�!rN)rxryrzr�rlrSrrrr�r��s4������(�(��O�"�"�"�"�"rr�Tc��tj|��r|}nt|d���}t|d|���}t	|��S)ak
    Parse the given HTML and returns token objects (words with attached tags).

    This parses only the content of a page; anything in the head is
    ignored, and the <head> and <body> elements are themselves
    optional.  The content is then parsed by lxml, which ensures the
    validity of the resulting parsed document (though lxml may make
    incorrect guesses when the markup is particular bad).

    <ins> and <del> tags are also eliminated from the document, as
    that gets confusing.

    If include_hrefs is true, then the href attribute of <a> tags is
    included as a special kind of diffable token.T��cleanup)�skip_tagr')r�	iselement�
parse_html�
flatten_el�fixup_chunks)rSr'�body_elr�s    rr(r(sQ��
��t���1�����T�4�0�0�0��
��$�m�
L�
L�
L�F�����rc�F�|rt|��}t|d���S)a
    Parses an HTML fragment, returning an lxml element.  Note that the HTML will be
    wrapped in a <div> tag that was not in the original document.

    If cleanup is true, make sure there's no <head> or <body>, and get
    rid of any <ins> and <del> tags.
    T)�
create_parent)�cleanup_htmlr)rSr�s  rr�r� s,���"��D�!�!���t�4�8�8�8�8rz	<body.*?>z
</body.*?>z</?(ins|del).*?>c��t�|��}|r||���d�}t�|��}|r|d|����}t
�d|��}|S)z� This 'cleans' the HTML, meaning that any page structure is removed
    (only the contents of <body> are used, if there is any <body).
    Also <ins> and <del> tags are removed.  Nr)�_body_re�searchr��_end_body_rer��_ins_del_re�sub)rS�matchs  rr�r�1s|��
�O�O�D�!�!�E��"��E�I�I�K�K�L�L�!������%�%�E��$��N�U�[�[�]�]�N�#���?�?�2�t�$�$�D��Krz
[ \t\n\r]$c�l�t|�����}|d|�||d�fS)zP
    This function takes a word, such as 'test

' and returns ('test','

')
    rN)r?�rstrip)�word�stripped_lengths  r�split_trailing_whitespacer�As9���$�+�+�-�-�(�(�O���/�!�"�D��)9�)9�$:�:�:rc
�x�g}d}g}|D�]{}t|t��r�|ddkrL|d}t|d��\}}td||||���}g}|�|��n=|ddkr1|d}t||d�	��}g}|�|����t
|��r<t|��\}}t|||�	��}g}|�|����t|��r|�|����t|��rM|r|�|����G|sJd
|�d|�d|�d
|�����|j
�|����{J�|std|���gS|dj
�|��|S)zM
    This function takes a list of chunks and produces a list of tokens.
    Nr�imgr
�)r�rHrM�hrefrn)rHrMzWeird state, cur_word=z	, result=z	, chunks=z of Fr)rHrF)�
isinstance�tupler�r�rJr��is_wordrO�is_start_tag�
is_end_tagrGrb)	r��	tag_accum�cur_wordr$r�rAr�rMr�s	         rr�r�Is(���I��H�
�F��$�$���e�U�#�#�	��Q�x�5� � ��A�h��+D�U�1�X�+N�+N�(��(�$�U�C�3�.7�9L�N�N�N���	��
�
�h�'�'�'�'��q��V�#�#��Q�x��%�d�Y�TW�X�X�X���	��
�
�h�'�'�'���5�>�>�	�)B�5�)I�)I�&�E�&��U�Y�L_�`�`�`�H��I��M�M�(�#�#�#�#�
�%�
 �
 �	����U�#�#�#�#�
��
�
�		��
1�� � ��'�'�'�'��9�9�9��x�x���������8�9�9�x��"�)�)�%�0�0�0�0��5��/��b�9�-�-�-�.�.��r�
��#�#�I�.�.�.��Mr)
�paramr��area�br�basefont�input�base�meta�link�col)�address�
blockquote�center�dir�div�dl�fieldset�form�h1�h2�h3�h4�h5�h6�hr�isindex�menu�noframes�noscript�ol�prU�table�ul)
�dd�dt�frameset�li�tbody�td�tfoot�th�thead�trc#�rK�|sD|jdkr(d|�d��t|��fV�nt|��V�|jtvr|jst|��s	|jsdSt|j��}|D]}t|��V��|D]}t||���D]}|V���|jdkr0|�d��r|rd|�d��fV�|s;t|��V�t|j��}|D]}t|��V��dSdS)a Takes an lxml element el, and generates all the text chunks for
    that tag.  Each start tag is a chunk, each word is a chunk, and each
    end tag is a chunk.

    If skip_tag is true, then the outermost container tag is
    not returned (just its contents).r�rANr&r-r�)r��get�	start_tagr�r
r?�tail�split_wordsrr��end_tag)�elr'r��start_wordsr��child�item�	end_wordss        rr�r��s������ �
�6�U�?�?��"�&�&��-�-��2���7�7�7�7�7��B�-�-����	�v����B�G��C��G�G��B�G�����b�g�&�&�K�� � ���$������������u�M�B�B�B�	�	�D��J�J�J�J�	�	�v��}�}�������}�M�}��r�v�v�f�~�~�&�&�&�&��$��b�k�k�������(�(�	��	$�	$�D��d�#�#�#�#�#�#�	$�$�	$�	$rz\S+(?:\s+|$)c�j�|r|���sgSt�|��}|S)z_ Splits some text into words. Includes trailing whitespace
    on each word when appropriate.  )r�split_words_re�findall)r
�wordss  rrr�s8����t�z�z�|�|���	��"�"�4�(�(�E��Lrz
^[ \t\n\r]c��d|j�d�d�|j���D�����d�S)z=
    The text representation of the start tag for a tag.
    r�rc	�B�g|]\}}d|�dt|d���d���S)rnz="T�")r)rr��values   rrzstart_tag.<locals>.<listcomp>�sG��?�?�?�(�T�5�5�(,�t�t�[���-E�-E�-E�-E�F�?�?�?r�>)r�r�attrib�items)rs rrr�s_���
	������?�?�,.�I�O�O�,=�,=�?�?�?�@�@�@�@�A�Arc�r�|jr"t�|j��rd}nd}d|j�d|��S)zg The text representation of an end tag for a tag.  Includes
    trailing whitespace when appropriate.  rnrr�r!)r�start_whitespace_rer�r�)r�extras  rrr�sF��
�w��&�-�-�b�g�6�6��������������&�&rc�.�|�d��S)Nr��r��r*s rr�r��s���~�~�c�"�"�"�"rc�,�|�d��S)Nr�r(r)s rr�r��s���>�>�$���rc�X�|�d��o|�d��S)Nr�r�r(r)s rr�r��s(���>�>�#���;�s�~�~�d�';�';�#;�;rc�h�t|d���}t|��t|d���}|S)z� Given an html string, move any <ins> or <del> tags inside of any
    block-level elements, e.g. transform <ins><p>word</p></ins> to
    <p><ins>word</ins></p> Fr�T)�
skip_outer)r��_fixup_ins_del_tags�serialize_html_fragment)rSrs  rrYrY�s;���T�5�
)�
)�
)�C������"�3�4�8�8�8�D��Krc�(�t|t��r
Jd|z���tj|dt���}|rQ||�d��dzd�}|d|�d���}|���S|S)z� Serialize a single lxml element as HTML.  The serialized form
    includes the elements tail.  

    If skip_outer is true, then don't serialize the outermost tag
    z3You should pass in an element, not a string like %rrS)�method�encodingr!r
Nr�)r��
basestringr�tostringr�find�rfindr)rr-rSs   rr/r/�s����"�j�)�)�D�D�=��B�D�D�)��>�"�V�h�?�?�?�D����D�I�I�c�N�N�1�$�%�%�&���$�T�Z�Z��_�_�$�%���z�z�|�|���rc��dD]R}|�d|z��D]7}t|��s�t||���|����8�SdS)z?fixup_ins_del_tags that works on an lxml document in-place
    )r�r�zdescendant-or-self::%s)r�N)�xpath�_contains_block_level_tag�_move_el_inside_block�drop_tag)rr�rs   rr.r.
sx�������)�)�4�s�:�;�;�	�	�B�,�R�0�0�
��!�"�#�.�.�.�.��K�K�M�M�M�M�		��rc�p�|jtvs|jtvrdS|D]}t|��rdS�dS)zPTrue if the element contains any block-level elements, like <p>, <td>, etc.
    TF)r��block_level_tags�block_level_container_tagsr9)rrs  rr9r9sT��
�v�!�!�!�R�V�/I�%I�%I��t�����$�U�+�+�	��4�4�	��5rc��|D]}t|��rnT�tj|��}|j|_d|_|�t|����|g|dd�<dSt|��D]�}t|��rkt
||��|jrStj|��}|j|_d|_|�|�	|��dz|���|tj|��}|�
||��|�|����|jr?tj|��}|j|_d|_|�d|��dSdS)zt helper for _fixup_ins_del_tags; actually takes the <ins> etc tags
    and moves them inside any block-level tags.  Nr
r)r9r�Elementr
rb�listr:rr_r�r`rJ)rr�r�children_tag�tail_tag�	child_tag�text_tags       rr:r:s����
�
��$�U�+�+�	��E�	��}�S�)�)���G���������D��H�H�%�%�%����1�1�1�����b���$�$��$�U�+�+�
	$�!�%��-�-�-��z�
7� �=��-�-�� %�
��
�!��
��	�	�"�(�(�5�/�/�!�+�X�6�6�6���
�c�*�*�I��J�J�u�i�(�(�(����U�#�#�#�#�	�w���=��%�%�����
����
�	�	�!�X������	�rc��|���}|jpd}|jrUt|��s||jz
}n;|djr|dxj|jz
c_n|j|d_|�|��}|rU|dkrd}n||dz
}|� |jr|xj|z
c_n'||_n|jr|xj|z
c_n||_|���|||dz�<dS)z�
    Removes an element, but merges its contents into its place, e.g.,
    given <p>Hi <i>there!</i></p>, if you remove the <i> element you get
    <p>Hi there!</p>
    rrFrNr
)�	getparentr
rr?r��getchildren)r�parentr
r��previouss     r�_merge_element_contentsrK?s���\�\�^�^�F�
�7�=�b�D�	�w�&��2�w�w�	&��B�G�O�D�D��"�v�{�
&��2����r�w�&���� �g��2����L�L����E��%��A�:�:��H�H��e�A�g��H����{�
#����t�#����"�����}�
%��
�
��%�
�
�
� $��
��N�N�,�,�F�5��q��=���rc��eZdZdZdZd�ZdS)r0zt
    Acts like SequenceMatcher, but tries not to find very small equal
    blocks amidst large spans of changes
    r�c���tt|j��t|j����}t|j|dz���tj�|��}�fd�|D��S)N�c�<��g|]}|d�ks|d�|��S)r�r)rr�	thresholds  �rrzBInsensitiveSequenceMatcher.get_matching_blocks.<locals>.<listcomp>ms=��� � � ����7�Y�&�&��A�w�'��&�&�&r)�minr?r.rP�difflib�SequenceMatcher�get_matching_blocks)r��size�actualrPs   @rrTz.InsensitiveSequenceMatcher.get_matching_blocksisw����3�t�v�;�;��D�F���,�,������q��1�1�	��(�<�<�T�B�B�� � � � �� � � �	 rN)rxryrzr�rPrTrrrr0r0as4��������
�I� � � � � rr0�__main__)�_diffcommand)F)T)P�
__future__rrR�lxmlr�	lxml.htmlr�re�__all__rSrr�ImportError�cgi�unicoder�	NameError�strr3rrrrr2rrIrrrXrcrdrvr}�	Exceptionrrerfror�r�r�rOr�r�r(r��compile�I�Sr�r�r�r��end_whitespace_rer�r�r�r=r>r��Urrr%rrr�r�r�rYr/r.r9r:rKrSr0rxrX�mainrrr�<module>rjs^��'�&�&�&�&�&�����������)�)�)�)�)�)�	�	�	�	��J�
'��*�*�*�*�*�*�*�*���*�*�*�)�)�)�)�)�)�)�)�*������H�H�������H�H�H�������J�J�������J�J�J�����1�1�1�#1�&#�&#�&#�&#�P���-�-�-�1�1�1�
�
�
����$���*&�&�&�.$�$�$�L
�
�
�
����.	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	������	�������%�%�%�N& �& �& �P
=�
=�
=�0�0�0�d���4'�'�'�'�'�H�'�'�'�R���������8"�"�"�"�"��"�"�"� � � � �09�9�9�9��2�:�l�B�D���I�.�.���r�z�-���b�d��3�3���b�j�,�b�d�2�4�i�8�8������B�J�}�-�-��;�;�;�2�2�2�l#�
���6��$�$�$�$�8���O�R�T�2�2�����!�b�j��/�/��A�A�A�'�'�'�#�#�#� � � �<�<�<��������$���������@ -� -� -�D � � � � ��!8� � � � �z���&�&�&�&�&�&��L��������s-�'�5�5�<�A�A�
A
�
A�A

Zerion Mini Shell 1.0