Warning: session_start(): Session cannot be started after headers have already been sent in /home/tvrreohg/public_html/manga.php on line 13
3 BY%w0@sddlZddlmZddlmZddlZddgZyddlmZ Wn e k r`ddl mZ YnXye Z Wnek reZ YnXyeWnek reZYnXddZefd dZd d Zd d ZddZddZddZddZddZddZdddZddZGdddZGd d!d!ZGd"d#d#eZ d$d%Z!d&d'Z"d(d)Z#d*d+Z$d,d-Z%d.d/Z&Gd0d1d1e Z'Gd2d3d3e'Z(Gd4d5d5e'Z)dd7d8Z*dd9d:Z+ej,d;ej-ej.BZ/ej,dd?Z2ej,d@Z3dAdBZ4dCdDZ5dZ6dZ7dZ8ddqdrZ9ej,dsej:Z;dtduZdydzZ?d{d|Z@d}d~ZAddZBddZCdddZDddZEddZFddZGddZHGdddejIZJeKdkrddlmLZLeLjMdS)N)etree)fragment_fromstring html_annotatehtmldiff)escapecCsdtt|d|fS)Nz%s) html_escape_unicode)textversionr /usr/lib64/python3.6/diff.pydefault_markupsrcCsZdd|D}|d}x"|ddD]}t|||}q$Wt|}t||}dj|jS)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')])) Goodbye World 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')) Some Text cSsg|]\}}t||qSr )tokenize_annotated).0docr r r r 9sz!html_annotate..rrN)html_annotate_merge_annotationscompress_tokensmarkup_serialize_tokensjoinstrip)ZdoclistZmarkupZ tokenlistZ cur_tokenstokensresultr r r rs  cCs$t|dd}x|D] }||_qW|S)zFTokenize a document and add an annotation attribute to each token F) include_hrefs)tokenize annotation)rrrtokr r r rGs   rc CsZt||d}|j}x@|D]8\}}}}}|dkr|||} |||} t| | qWdS)zMerge the annotations from tokens_old into tokens_new, when the tokens in the new document already existed in the old document. )abequalN)InsensitiveSequenceMatcher get_opcodescopy_annotations) Z tokens_oldZ tokens_newscommandscommandi1i2j1j2Zeq_oldZeq_newr r r rOs   rcCs$xt||D]\}}|j|_q WdS)zN Copy annotations from the tokens listed in src to the tokens in dest N)zipr)srcdestZsrc_tokZdest_tokr r r r$\sr$cCs^|dg}xN|ddD]>}|dj rL|j rL|dj|jkrLt||q|j|qW|S)zm Combine adjacent tokens when there is no HTML between the tokens, and they share an annotation rrNr/) post_tagspre_tagsrcompress_merge_backappend)rrrr r r rds   rcCsv|d}t|tk s t|tk r,|j|nFt|}|jrD||j7}||7}t||j|j|jd}|j|_||d<dS)zY Merge tok into the last element of tokens (modifying the list of tokens in-place). r)r1r0trailing_whitespaceNr/r/)typetokenr3r r4r1r0r)rrZlastr Zmergedr r r r2ss   r2ccshxb|D]Z}x|jD] }|VqW|j}|||j}|jrD||j7}|Vx|jD] }|VqRWqWdS)zz Serialize the list of tokens into a list of text chunks, calling markup_func around text to add annotations. N)r1htmlrr4r0)rZ markup_funcr6prer7postr r r rs      rcCs0t|}t|}t||}dj|j}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 tag). Returns HTML with and 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 tags, which are treated like words, and the href attribute of tags, which are noted inside the tag itself when there are changes. r)rhtmldiff_tokensrrfixup_ins_del_tags)Zold_htmlZnew_htmlZold_html_tokensZnew_html_tokensrr r r rs  c Cst||d}|j}g}x|D]\}}}}} |dkrP|jt||| ddq|dks`|dkrzt||| } t| ||dks|dkrt|||} t| |qWt|}|S)z] Does a diff on the tokens themselves, returning a list of text chunks (not tokens). )rr r!T)r!insertreplacedelete)r"r#extend expand_tokens merge_insert merge_deletecleanup_delete) Z html1_tokensZ html2_tokensr%r&rr'r(r)r*r+Z ins_tokensZ del_tokensr r r r:s  r:Fccsnxh|D]`}x|jD] }|VqW| s.|j rP|jrF|j|jVn |jVx|jD] }|VqXWqWdS)zeGiven a list of tokens, return a generator of the chunks of text for the data in the tokens. N)r1hide_when_equalr4r7r0)rr!r6r8r9r r r r@s     r@cCst|\}}}|j||r<|djd r<|dd7<|jd|rl|djdrl|d dd |d <|j||jd|j|dS) z| doc is the already-handled document (as a list of text chunks); here we add ins_chunks to the end of that. r zNz r/r/r/r/r/r/)split_unbalancedr?endswithr3)Z ins_chunksrunbalanced_startbalancedunbalanced_endr r r rAs    rAc@s eZdZdS) DEL_STARTN)__name__ __module__ __qualname__r r r r rKsrKc@s eZdZdS)DEL_ENDN)rLrMrNr r r r rOsrOc@seZdZdZdS) NoDeleteszY Raised when the document no longer contains any pending deletes (DEL_START/DEL_END) N)rLrMrN__doc__r r r r rPsrPcCs"|jt|j||jtdS)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 tags.N)r3rKr?rO)Z del_chunksrr r r rBs  rBc Csxyt|\}}}Wntk r*PYnXt|\}}}t|||t||||}|rz|djd rz|dd7<|jd|r|djdr|d dd |d <|j||jd|j||}qW|S) a Cleans up any DEL_START/DEL_END markers in the document, replacing them with . 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
tag, if the del looks like (DEL_START, 'Text
', DEL_END)rrEzNz r/r/r/r/r/r/) split_deleterPrFlocate_unbalanced_startlocate_unbalanced_endrGr3r?)chunks pre_deleter> post_deleterHrIrJrr r r rCs&       rCc Csg}g}g}g}x|D]}|jds0|j|q|ddk}|jdjd}|tkrb|j|q|r|r|d d|kr|j||j\}}} | ||<q|r|jdd|Dg}|j|q|j|q|j|t||f|jdqW|jd d|Dd 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./cSsg|]\}}}|qSr r )rnamepostagr r r rPsz$split_unbalanced..NcSsg|]\}}}|qSr r )rrZr[chunkr r r rYscSsg|]}|dk r|qS)Nr )rr]r r r rZsr/) startswithr3splitr empty_tagspopr?len) rUstartendZ tag_stackrIr]ZendtagrZr[r\r r r rF5s:         rFc Cs\y|jt}Wntk r&tYnX|jt}|d|||d|||ddfS)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)indexrK ValueErrorrPrO)rUr[Zpos2r r r rR]s   rRcCsx|sP|d}|jdjd}|s(P|d}|tksD|jd rFP|ddkrTP|jdjd}|dkrpP||kr|jd|j|jdqPqWdS)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 = ['
'] >>> doc = ['

', 'Text', '

', '
', 'More Text', '
'] >>> pre, post = doc[:3], doc[3:] >>> pre, post (['

', 'Text', '

'], ['
', 'More Text', '
']) >>> locate_unbalanced_start(unbalanced_start, pre, post) >>> pre, post (['

', 'Text', '

', '
'], ['More Text', '
']) As you can see, we moved the point so that the dangling
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. rz<>rXrrYinsN)r_rrKr^rar3)rHrVrWfinding finding_namenextrZr r r rSis&  rScCsx|sP|d}|jdjd}|s(P|d }|tksD|jd rFP|jdjd}|dksh|dkrjP||kr|j|jd|jqPqWdS) zt like locate_unbalanced_start, except handling end tags and possibly moving the point earlier in the document. rrz<>/z tag, which takes up visible space just like a word but is only represented in a document by a tag. NrcCs2tj|dt|f|||d}||_||_||_|S)Nz%s: %s)r1r0r4)r6rlr5r\data html_repr)rmr\rrrsr1r0r4rnr r r rlsztag_token.__new__cCs d|j|j|j|j|j|jfS)NzRtag_token(%s, %s, html_repr=%s, post_tags=%r, pre_tags=%r, trailing_whitespace=%r))r\rrrsr1r0r4)rpr r r rosztag_token.__repr__cCs|jS)N)rs)rpr r r r7sztag_token.html)NNr)rLrMrNrQrlror7r r r r rqs  rqc@seZdZdZdZddZdS) href_tokenzh Represents the href in an anchor tag. Unlike other words, we only show the href when it changes. TcCsd|S)Nz Link: %sr )rpr r r r7szhref_token.htmlN)rLrMrNrQrDr7r r r r rtsrtTcCs2tj|r|}n t|dd}t|d|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 and 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). and tags are also eliminated from the document, as that gets confusing. If include_hrefs is true, then the href attribute of tags is included as a special kind of diffable token.T)cleanup)skip_tagr)rZ iselement parse_html flatten_el fixup_chunks)r7rZbody_elrUr r r rs   rcCs|r t|}t|ddS)a Parses an HTML fragment, returning an lxml element. Note that the HTML will be wrapped in a
tag that was not in the original document. If cleanup is true, make sure there's no or , and get rid of any and tags. T)Z create_parent) cleanup_htmlr)r7rur r r rwsrwz z zcCsLtj|}|r||jd}tj|}|r<|d|j}tjd|}|S)z This 'cleans' the HTML, meaning that any page structure is removed (only the contents of are used, if there is any and tags are removed. Nr)_body_researchrd _end_body_rerc _ins_del_resub)r7matchr r r rz-s   rzz [ \t\n\r]$cCs$t|j}|d|||dfS)zP This function takes a word, such as 'test ' and returns ('test',' ') rN)rbrstrip)wordZstripped_lengthr r r split_trailing_whitespace=s rc Cs0g}d}g}x|D]}t|tr|ddkrf|d}t|d\}}td||||d}g}|j|q|ddkr|d}t||dd }g}|j|qt|rt|\}}t|||d }g}|j|qt|r|j|qt |r|r|j|n |j j|qqW|std |d gS|d j j ||S) zM This function takes a list of chunks and produces a list of tokens. Nrimgr)rsr1r4hrefrE)r1r4r)r1r/) isinstancetuplerrqr3rtis_wordr6 is_start_tag is_end_tagr0r?) rUZ tag_accumZcur_wordrr]r-r\r4rr r r ryEsF          ryparamrareabrbasefontinputbasemetalinkcoladdress blockquotecenterdirdivdlfieldsetformh1h2h3h4h5h6hrisindexmenunoframesnoscriptolpr8tableuldddtframesetlitbodytdtfootththeadtrccs|s0|jdkr&d|jdt|fVn t|V|jtkrX|j rXt| rX|j rXdSt|j}x|D]}t|VqhWx(|D] }xt ||dD] }|VqWqW|jdkr|jdr|rd|jdfV|st |Vt|j}x|D]}t|VqWdS)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).rr-N)rrr) r\get start_tagr`r rbtail split_wordsrrxend_tag)elrrvZ start_wordsrchilditemZ end_wordsr r r rxs&  $      rxz \S+(?:\s+|$)cCs"| s|j rgStj|}|S)z_ Splits some text into words. Includes trailing whitespace on each word when appropriate. )rsplit_words_refindall)r Zwordsr r r rs rz ^[ \t\n\r]cCs$d|jdjdd|jjDfS)z= The text representation of the start tag for a tag. z<%s%s>rcSs"g|]\}}d|t|dfqS)z %s="%s"T)r)rrZvaluer r r rszstart_tag..)r\rZattribitems)rr r r rsrcCs*|jrtj|jrd}nd}d|j|fS)zg The text representation of an end tag for a tag. Includes trailing whitespace when appropriate. rErz%s)rstart_whitespace_rer|r\)rZextrar r r rsrcCs |jd S)NrX)r^)rr r r rsrcCs |jdS)Nz or tags inside of any block-level elements, e.g. transform

word

to

word

F)ruT) skip_outer)rw_fixup_ins_del_tagsserialize_html_fragment)r7rr r r r;s  r;cCsLtj|dtd}|rD||jddd}|d|jd}|jS|SdS)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 r7)methodencoding>rNrX)rZtostringr findrfindr)rrr7r r r rs rcCsHxBdD]:}x4|jd|D]"}t|s(qt||d|jqWqWdS)z?fixup_ins_del_tags that works on an lxml document in-place rgrkzdescendant-or-self::%s)r\N)rgrk)Zxpath_contains_block_level_tag_move_el_inside_blockZdrop_tag)rr\rr r r rs   rcCs6|jtks|jtkrdSx|D]}t|rdSqWdS)zPTrue if the element contains any block-level elements, like

, , etc. TF)r\block_level_tagsblock_level_container_tagsr)rrr r r rs  rcCsxV|D]}t|rPqWddl}tj|}|j|_d|_|jt||g|dd<dSxxt|D]l}t|rt|||jrtj|}|j|_d|_|j |j |d|qbtj|}|j |||j |qbW|jrtj|}|j|_d|_|j d|dS)zt helper for _fixup_ins_del_tags; actually takes the etc tags and moves them inside any block-level tags. rNr) rsysrZElementr r?listrrr<rer=r3)rr\rrZ children_tagZtail_tagZ child_tagZtext_tagr r r rs4       rcCs|j}|jpd}|jrXt|s,||j7}n,|djrL|dj|j7_n |j|d_|j|}|r|dkrtd}n ||d}|dkr|jr|j|7_q||_n|jr|j|7_n||_|j|||d<dS)z Removes an element, but merges its contents into its place, e.g., given

Hi there!

, if you remove the element you get

Hi there!

rrrNr/r/r/)Z getparentr rrbreZ getchildren)rparentr reZpreviousr r r _merge_element_contents<s*      rc@seZdZdZdZddZdS)r"zt Acts like SequenceMatcher, but tries not to find very small equal blocks amidst large spans of changes rcsDtt|jt|j}t|j|dtjj|}fdd|DS)Ncs&g|]}|dks|d r|qS)rr )rr) thresholdr r rjs zBInsensitiveSequenceMatcher.get_matching_blocks..)minrbr rdifflibSequenceMatcherget_matching_blocks)rpsizeactualr )rr rfs z.InsensitiveSequenceMatcher.get_matching_blocksN)rLrMrNrQrrr r r r r"^sr"__main__) _diffcommand)F)T)T) rrrrrrrrrr)rrrrrrrrrrrrrrrrrrrrrr8rr) rrrrrrrrrr)F)F)NrZlxmlrZ lxml.htmlrre__all__r7rr ImportErrorZcgiZunicoder NameErrorstrZ basestringrrrrr$rr2rrr:r@rArKrO ExceptionrPrBrCrFrRrSrTr6rqrtrrwcompileISr{r}r~rzZend_whitespace_rerryr`rrrxUrrrrrrrrr;rrrrrrr"rLrmainr r r r s     ( & '( 2)   7      !"