3 h>`C@sddddgZddlZddlZejdkrLddlZddlZddlZddlmZnddl Z ddlmZddl Z ddl Z ddl TGd d d e jZejdkrGd d d ejjZnGd d d e jZddZddZdddZddZdS) escape_html unescape_html html_to_text html_documentN)StringIO)*c@s6eZdZdddZddZdd Zd d Zd d ZdS) TextWriterNPcCs(tjj|||d|_||_|jdS)Nr) Formatter DumbWriter__init__ indent_level indent_width _set_indent)selffilemaxcolrr/usr/lib/python3.6/html_util.pyr0szTextWriter.__init__cCs|j|j|_d|j|_dS)N )rr indent_colindent)rrrrr6szTextWriter._set_indentcCs||_|jdS)N)rr)rZmarginlevelrrr new_margin:szTextWriter.new_margincCsF|d}t||jkr"|j|n |jt|}|jd||dS)Nr)lenrZsend_literal_data)rdataoffsetrrrsend_label_data>s  zTextWriter.send_label_datacCs|sdS|jp|dtjk}|j}|j}|jj}|j}|dkrN||j|j}xb|j D]V}|r|t ||kr|d|j|j}n|d|d}|||t |}d}qXW||_|dtjk|_dS)Nr r) atbreakstringZ whitespacecolrrwriterrsplitr)rrr#r%rr&Zwordrrrsend_flowing_dataFs,  zTextWriter.send_flowing_data)Nr r )__name__ __module__ __qualname__rrrrr(rrrrr .s  r cs6eZdZd fdd ZddZddZdd ZZS) HTMLParserAnchorFcstt|j||_d|_dS)N)superr,r formatter anchor_href)rr.strictZconvert_charrefs) __class__rrrbszHTMLParserAnchor.__init__cCs,|dkr(x|D]\}}|dkr||_qWdS)Nahref)r/)rtagZattrskeyvaluerrrhandle_starttaggsz HTMLParserAnchor.handle_starttagcCs4|dkr0|jdkr*|jjjd|jdd|_dS)Nr2())r/r.writerr()rr4rrr handle_endtagms zHTMLParserAnchor.handle_endtagcCs|jjj|dS)N)r.r:r()rrrrr handle_datasszHTMLParserAnchor.handle_data)FF)r)r*r+rr7r;r< __classcell__rr)r1rr,`sr,c@s&eZdZd ddZddZddZdS) r,rcCstjj|||dS)N)htmllib HTMLParserr)rr.verboserrrryszHTMLParserAnchor.__init__cCs ||_dS)N)anchor)rr3nametyperrr anchor_bgn|szHTMLParserAnchor.anchor_bgncCs |jr|jd|jd|_dS)Nz (%s) )rAr<)rrrr anchor_endszHTMLParserAnchor.anchor_endN)r)r)r*r+rrDrErrrrr,ws c Cs^|dkr dSy@|jdd}|jdd}|jdd}|jdd}|jd d }Wn YnX|S) N&z&z>'z'"z")replace)srrrrs    cCsX|dkr dSd|kr|S|jdd}|jdd}|jdd}|jdd }|jd d}|S) NrFz<rGz>rHz'rIz"rJz&)rK)rLrrrrs     r cCs|yDt}tjt||}t|}|j||j|j}|j|Stk rv}zt j t j d|dSd}~XnXdS)Nzcannot convert html to text: %s) rr ZAbstractFormatterr r,Zfeedclosegetvalue ExceptionsyslogZLOG_ERR)htmlrbufferr.parsertexterrrrs cGsd}d}|}x|D]}t|tjr,||7}qt|ttfrRx\|D] }||7}q@Wqt|r|}t|ttfrx|D] }||7}qtWq||7}q||7}qW||7}|S)a&Wrap the body components in a HTML document structure with a valid header. Accepts a variable number of arguments of of which canb be: * string * a sequences of strings (tuple or list). * a callable object taking no parameters and returning a string or sequence of strings. zl z ) isinstanceZsixZ string_typestuplelistcallable)Zbody_componentsheadtaildocZbody_componentitemresultrrrrs$       )r)r)r )__all__rPsys version_inforQZ html.parserZ html.entitiesiorr>r.r r$typesr r rSr?r,rrrrrrrrs.  1