ok

Mini Shell

Direktori : /usr/lib64/python2.7/site-packages/lxml/html/
Upload File :
Current File : //usr/lib64/python2.7/site-packages/lxml/html/diff.pyo

�
���Pc@sWddlZddlmZddlmZddlZddgZyddlmZ	Wn!e
k
r{ddlmZ	nXy
eZ
Wnek
r�eZ
nXyeWnek
r�eZnXd�Zed�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zed�Zd�Zddkd��YZddld��YZde fd��YZ!d�Z"d�Z#d�Z$d�Z%d�Z&d�Z'de
fd ��YZ(d!e(fd"��YZ)d#e(fd$��YZ*e+d%�Z,e+d&�Z-ej.d'ej/ej0B�Z1ej.d(ej/ej0B�Z2ej.d)ej/ej0B�Z3d*�Z4ej.d+�Z5d,�Z6dmZ7dnZ8doZ9edY�Z:dZ�Z;ej.d[�Z<d\�Z=d]�Z>d^�Z?d_�Z@d`�ZAda�ZBedb�ZCdc�ZDdd�ZEde�ZFdf�ZGdgejHfdh��YZIeJdikrSddjlmKZKeKjL�ndS(pi����N(tetree(tfragment_fromstringt
html_annotatethtmldiff(tescapecCsdtt|�d�|fS(Ns<span title="%s">%s</span>i(thtml_escapet_unicode(ttexttversion((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pytdefault_markupscCs�g|D]\}}t||�^q}|d}x%|dD]}t||�|}q=Wt|�}t||�}dj|�j�S(s
    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>
    iit(ttokenize_annotatedthtml_annotate_merge_annotationstcompress_tokenstmarkup_serialize_tokenstjointstrip(tdoclisttmarkuptdocRt	tokenlistt
cur_tokensttokenstresult((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyRs%


cCs0t|dt�}x|D]}||_qW|S(sFTokenize a document and add an annotation attribute to each token
    t
include_hrefs(ttokenizetFalset
annotation(RRRttok((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyRGs

cCs{td|d|�}|j�}xS|D]K\}}}}}|dkr(|||!}	|||!}
t|	|
�q(q(WdS(s�Merge the annotations from tokens_old into tokens_new, when the
    tokens in the new document already existed in the old document.
    tatbtequalN(tInsensitiveSequenceMatchertget_opcodestcopy_annotations(t
tokens_oldt
tokens_newtstcommandstcommandti1ti2tj1tj2teq_oldteq_new((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyROs

cCs0x)t||�D]\}}|j|_qWdS(sN
    Copy annotations from the tokens listed in src to the tokens in dest
    N(tzipR(tsrctdesttsrc_toktdest_tok((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR"\scCsq|dg}x]|dD]Q}|djr\|jr\|dj|jkr\t||�q|j|�qW|S(sm
    Combine adjacent tokens when there is no HTML between the tokens, 
    and they share an annotation
    iii����(t	post_tagstpre_tagsRtcompress_merge_backtappend(RRR((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR
ds

c	Cs�|d}t|�tk	s.t|�tk	r>|j|�nit|�}|jr`|d7}n||7}t|d|jd|jd|j�}|j|_||d<dS(sY Merge tok into the last element of tokens (modifying the list of
    tokens in-place).  i����t R4R3ttrailing_whitespaceN(ttypettokenR6RR8R4R3R(RRtlastRtmerged((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR5ss
$	

			ccs�xy|D]q}x|jD]}|VqW|j�}|||j�}|jrZ|d7}n|Vx|jD]}|VqiWqWdS(sz
    Serialize the list of tokens into a list of text chunks, calling
    markup_func around text to add annotations.
    R7N(R4thtmlRR8R3(Rtmarkup_funcR:tpreR=tpost((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR�s
		
cCsFt|�}t|�}t||�}dj|�j�}t|�S(s� 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
(Rthtmldiff_tokensRRtfixup_ins_del_tags(told_htmltnew_htmltold_html_tokenstnew_html_tokensR((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR�s
cCs�td|d|�}|j�}g}x�|D]�\}}}}}	|dkru|jt|||	!dt��q.n|dks�|dkr�t|||	!�}
t|
|�n|dks�|dkr.t|||!�}t||�q.q.Wt|�}|S(s] Does a diff on the tokens themselves, returning a list of text
    chunks (not tokens).
    RRRtinserttreplacetdelete(R R!textendt
expand_tokenstTruetmerge_inserttmerge_deletetcleanup_delete(thtml1_tokensthtml2_tokensR%R&RR'R(R)R*R+t
ins_tokenst
del_tokens((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyRA�s ccs�xz|D]r}x|jD]}|VqW|s7|jr`|jrR|j�dVq`|j�Vnx|jD]}|VqjWqWdS(seGiven a list of tokens, return a generator of the chunks of
    text for the data in the tokens.
    R7N(R4thide_when_equalR8R=R3(RRR:R?R@((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyRK�s
		cCs�t|�\}}}|j|�|rO|djd�rO|dcd7<n|jd�|r�|djd�r�|dd |d<n|j|�|jd�|j|�dS(s| doc is the already-handled document (as a list of text chunks);
    here we add <ins>ins_chunks</ins> to the end of that.  i����R7s<ins>s</ins> N(tsplit_unbalancedRJtendswithR6(t
ins_chunksRtunbalanced_starttbalancedtunbalanced_end((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyRM�s



t	DEL_STARTcBseZRS((t__name__t
__module__(((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR[�stDEL_ENDcBseZRS((R\R](((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR^�st	NoDeletescBseZdZRS(sY Raised when the document no longer contains any pending deletes
    (DEL_START/DEL_END) (R\R]t__doc__(((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR_scCs+|jt�|j|�|jt�dS(s� 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(R6R[RJR^(t
del_chunksR((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyRNs

cCsxyt|�\}}}Wntk
r0PnXt|�\}}}t|||�t|||�|}|r�|djd�r�|dcd7<n|jd�|r�|djd�r�|dd |d<n|j|�|jd�|j|�|}q|S(s� 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)i����R7s<del>s</del> (tsplit_deleteR_RUtlocate_unbalanced_starttlocate_unbalanced_endRVR6RJ(tchunkst
pre_deleteRItpost_deleteRXRYRZR((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyROs&	




	c
Cs�g}g}g}g}xE|D]=}|jd�sG|j|�qn|ddk}|j�djd�}|tkr�|j|�qn|r3|r�|dd|kr�|j|�|j�\}}}	|	||<q\|r#|jg|D]\}}}	|	^q��g}|j|�q\|j|�q|j|t|�|f�|jd�qW|jg|D]\}}}|^qm�g|D]}|dk	r�|^q�}|||fS(s]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.t<it/is<>/i����N(	t
startswithR6tsplitRt
empty_tagstpopRJtlentNone(
Retstarttendt	tag_stackRYtchunktendtagtnametposttag((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyRU5s:




)#%cCs`y|jt�}Wntk
r,t�nX|jt�}|| ||d|!||dfS(s� 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. i(tindexR[t
ValueErrorR_R^(ReRvtpos2((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyRb]s

cCs�x�|s
Pn|d}|j�djd�}|s:Pn|d}|tks`|jd�rdPn|ddkrxPn|j�djd�}|dkr�Pn||kr�|jd�|j|jd��qPqdS(s� 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.
    is<>RhiRitinsN(RkRR[RjRmR6(RXRfRgtfindingtfinding_nametnextRu((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyRcis&


cCs�x�|s
Pn|d}|j�djd�}|s:Pn|d}|tks`|jd�rdPn|j�djd�}|dks�|dkr�Pn||kr�|j�|jd|j��qPqdS(st like locate_unbalanced_start, except handling end tags and
    possibly moving the point earlier in the document.  i����is<>/s</R{tdelN(RkRR^RjRmRG(RZRfRgR|R}R~Ru((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyRd�s"


R:cBs8eZdZeZdded�Zd�Zd�ZRS(s8 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.cCsatj||�}|dk	r*||_n	g|_|dk	rK||_n	g|_||_|S(N(Rt__new__RoR4R3R8(tclsRR4R3R8tobj((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR��s			cCs dtj|�|j|jfS(Nstoken(%s, %r, %r)(Rt__repr__R4R3(tself((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR��scCs
t|�S(N(R(R�((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR=�sN(	R\R]R`RRTRoR�R�R=(((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR:�s
	t	tag_tokencBs2eZdZdded�Zd�Zd�ZRS(s� 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.  c	CsMtj|dt|fd|d|d|�}||_||_||_|S(Ns%s: %sR4R3R8(R:R�R9Rwtdatat	html_repr(R�RwR�R�R4R3R8R�((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR��s				cCs,d|j|j|j|j|j|jfS(NsRtag_token(%s, %s, html_repr=%s, post_tags=%r, pre_tags=%r, trailing_whitespace=%s)(RwR�R�R4R3R8(R�((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR��scCs|jS(N(R�(R�((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR=�sN(R\R]R`RoRR�R�R=(((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR��s

	t
href_tokencBseZdZeZd�ZRS(sh Represents the href in an anchor tag.  Unlike other words, we only
    show the href when it changes.  cCsd|S(Ns	 Link: %s((R�((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR=s(R\R]R`RLRTR=(((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR��scCsLtj|�r|}nt|dt�}t|dtd|�}t|�S(sk
    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.tcleanuptskip_tagR(Rt	iselementt
parse_htmlRLt
flatten_eltfixup_chunks(R=Rtbody_elRe((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyRs
	cCs%|rt|�}nt|dt�S(s
    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(tcleanup_htmlRRL(R=R�((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR�ss	<body.*?>s
</body.*?>s</?(ins|del).*?>cCsftj|�}|r(||j�}ntj|�}|rP||j� }ntjd|�}|S(s� 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.  R
(t_body_retsearchRqt_end_body_reRpt_ins_del_retsub(R=tmatch((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR�,ss
[ \t\n\r]$c	
Cs�g}d}g}x�|D]�}t|t�r�|ddkr�|d}|d}|jd�rt|d }t}nt}td|d|d|d	|�}g}|j|�q|dd
kr|d}t|d|d	t�}g}|j|�qqnt	|�ra|jd�r-|d }t}nt}t
|d|d	|�}g}|j|�qt|�r}|j|�qt|�r|r�|j|�q�|j
j|�qqW|s�t
dd|�gS|dj
j|�|S(
sM
    This function takes a list of chunks and produces a list of tokens.
    itimgiiR7i����R�R4R8threfR
N(Rot
isinstancettupleRVRLRR�R6R�tis_wordR:tis_start_tagt
is_end_tagR3RJ(	Ret	tag_accumtcur_wordRRsR/RwR8R�((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR�<sT



		

	tparamR�tareatbrtbasefonttinputtbasetmetatlinktcoltaddresst
blockquotetcentertdirtdivtdltfieldsettformth1th2th3th4th5th6thrtisindextmenutnoframestnoscripttoltpR?ttabletultddtdttframesettlittbodyttdttfoottthttheadttrccsS|sC|jdkr5d|jd�t|�fVqCt|�Vn|jtkrw|jrwt|�rw|jrwdSt|j�}x|D]}t|�Vq�Wx0|D](}xt	|d|�D]}|Vq�Wq�W|jdkr|jd�r|rd|jd�fVn|sOt
|�Vt|j�}x|D]}t|�Vq7WndS(s 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�R/NRRR�(Rwtgett	start_tagRlRRnttailtsplit_wordsRR�tend_tag(telRR�tstart_wordstwordtchildtitemt	end_words((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR��s& 0


$
cCsi|s|j�rgSg|j�j�D]}|d^q+}tj|�se|dd |d<n|S(sk Splits some text into words. Includes trailing whitespace (one
    space) on each word when appropriate.  R7i����(RRktend_whitespace_reR�(Rtwtwords((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR��s)s
^[ \t\n\r]c
CsOd|jdjg|jj�D]%\}}d|t|t�f^q�fS(s=
    The text representation of the start tag for a tag.
    s<%s%s>R
s %s="%s"(RwRtattribtitemsRRL(R�Rutvalue((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR��scCs;|jr$tj|j�r$d}nd}d|j|fS(sg The text representation of an end tag for a tag.  Includes
    trailing whitespace when appropriate.  R7R
s</%s>%s(R�tstart_whitespace_reR�Rw(R�textra((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR��s	cCs|jd�S(NRh(Rj(R((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR��scCs
|jd�S(Ns</(Rj(R((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR��scCs|jd�o|jd�S(NRhs</(Rj(R((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR��scCs2t|dt�}t|�t|dt�}|S(s� 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> R�t
skip_outer(R�Rt_fixup_ins_del_tagstserialize_html_fragmentRL(R=R((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyRB�s
cCs]tj|dddt�}|rU||jd�d}||jd� }|j�S|SdS(s� 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
    tmethodR=tencodingt>iRhN(RttostringRtfindtrfindR(R�R�R=((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR��s
cCsex^ddgD]P}xG|jd|�D]2}t|�s?q'nt|d|�|j�q'Wq
WdS(s?fixup_ins_del_tags that works on an lxml document in-place
    R{Rsdescendant-or-self::%sRwN(txpatht_contains_block_level_tagt_move_el_inside_blocktdrop_tag(RRwR�((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR�scCsG|jtks|jtkr"tSx|D]}t|�r)tSq)WtS(sPTrue if the element contains any block-level elements, like <p>, <td>, etc.
    (Rwtblock_level_tagstblock_level_container_tagsRLR�R(R�R�((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR�s
cCsbxo|D]}t|�rPqqWddl}tj|�}|j|_d|_|jt|��|g|(dSx�t|�D]�}t|�r�t||�|j	rtj|�}|j	|_d|_	|j
|j|�d|�qqtj|�}|j||�|j
|�qW|jr^tj|�}|j|_d|_|j
d|�ndS(st helper for _fixup_ins_del_tags; actually takes the <ins> etc tags
    and moves them inside any block-level tags.  i����Nii(R�tsysRtElementRRoRJtlistR�R�RGRxRHR6(R�RwR�R�tchildren_tagttail_tagt	child_tagttext_tag((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR�s4
	

		#		cCs&|j�}|jpd}|jryt|�s@||j7}qy|djrf|dj|j7_qy|j|d_n|j|�}|r|dkr�d}n||d}|dkr�|jr�|j|7_q||_q|jr�|j|7_q||_n|j�|||d+dS(s�
    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>
    R
i����iiN(t	getparentRR�RnRxRotgetchildren(R�tparentRRxtprevious((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyt_merge_element_contents7s*	
			R cBseZdZdZd�ZRS(st
    Acts like SequenceMatcher, but tries not to find very small equal
    blocks amidst large spans of changes
    icCs{tt|j�t|j��}t|j|d�}tjj|�}g|D]'}|d|ksq|drP|^qPS(Nii(tminRnRt	thresholdtdifflibtSequenceMatchertget_matching_blocks(R�tsizeR�tactualR�((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR�as!
(R\R]R`R�R�(((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyR Yst__main__(t_diffcommand(((
R�simgR�R�R�sinputsbaseR�slinkR�(R�R�scentersdirR�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�sprestableR�(
R�R�R�R�R�R�R�R�R�R�(MR�tlxmlRt	lxml.htmlRtret__all__R=RRtImportErrortcgitunicodeRt	NameErrortstrt
basestringR	RRRR"R
R5RRRARRKRMR[R^t	ExceptionR_RNRORURbRcRdR:R�R�RLRR�tcompiletItSR�R�R�R�R�R�RlR�R�R�R�R�R�R�R�R�R�RBR�R�R�R�R�R�R R\Rtmain(((s4/usr/lib64/python2.7/site-packages/lxml/html/diff.pyt<module>s�





	(		
						&			'	(		2	(

		<	
										
	!	"

Zerion Mini Shell 1.0