3 Pfa7@sddlmZmZmZddlmZddlZddlmZm Z ddl m Z m Z m Z ddl mZmZmZddlmZmZdd lmZd je d Zejd ed Zejd edZiZeddkZxeejD]p\Z Z!eree!dkse ree!dkrqe!dkree!dkrej"e!Z!ne#e!Z!e!eks4e j$re ee!<qWddZ%ede%dddZ&Gddde'Z(Gddde)Z*dS))absolute_importdivisionunicode_literals) text_typeN)register_errorxmlcharrefreplace_errors) voidElementsbooleanAttributesspaceCharacters)rcdataElementsentities xmlEntities) treewalkers_utils)escapez"'=<>`[]u_  /`  ᠎᠏           

   ]u􏿿&c Cs"t|ttfrg}g}d}xt|j|j|jD]n\}}|rFd}q4||j}tj|j|t |j|dgrtj |j||d}d}nt |}|j |q4Wx^|D]V}t j|} | r|j d|j | | jds|j dq|j dt|ddqWdj||jfSt|SdS)NFrTr;z&#x%s;r) isinstanceUnicodeEncodeErrorUnicodeTranslateError enumerateobjectstartendrZisSurrogatePairminsurrogatePairToCodepointordappend_encode_entity_mapgetendswithhexjoinr) excresZ codepointsskipicindexZ codepointZcper/ /usr/lib/python3.6/serializer.pyhtmlentityreplace_errors*s0  "      r1htmlentityreplaceetreecKs$tj|}tf|}|j|||S)N)rZ getTreeWalkerHTMLSerializerrender)inputZtreeencodingZserializer_optsZwalkersr/r/r0 serializeJs  r9c@s~eZdZdZdZdZdZdZdZdZ dZ dZ dZ dZ dZdZdZd!ZddZddZddZd"ddZd#ddZd$dd ZdS)%r4legacy"TFquote_attr_values quote_charuse_best_quote_charomit_optional_tagsminimize_boolean_attributesuse_trailing_solidusspace_before_trailing_solidusescape_lt_in_attrs escape_rcdataresolve_entitiesalphabetical_attributesinject_meta_charsetstrip_whitespacesanitizec Kszt|t|j}t|dkr2tdtt|d|kr@d|_x(|jD]}t|||j|t ||qHWg|_ d|_ dS)a6 Initialize HTMLSerializer. Keyword options (default given first unless specified) include: inject_meta_charset=True|False Whether it insert a meta element to define the character set of the document. quote_attr_values="legacy"|"spec"|"always" Whether to quote attribute values that don't require quoting per legacy browser behaviour, when required by the standard, or always. quote_char=u'"'|u"'" Use given quote character for attribute quoting. Default is to use double quote unless attribute value contains a double quote, in which case single quotes are used instead. escape_lt_in_attrs=False|True Whether to escape < in attribute values. escape_rcdata=False|True Whether to escape characters that need to be escaped within normal elements within rcdata elements such as style. resolve_entities=True|False Whether to resolve named character entities that appear in the source tree. The XML predefined entities < > & " ' are unaffected by this setting. strip_whitespace=False|True Whether to remove semantically meaningless whitespace. (This compresses all whitespace to a single space except within pre.) minimize_boolean_attributes=True|False Shortens boolean attributes to give just the attribute value, for example becomes . use_trailing_solidus=False|True Includes a close-tag slash at the end of the start tag of void elements (empty elements whose end tag is forbidden). E.g.
. space_before_trailing_solidus=True|False Places a space immediately before the closing slash in a tag using a trailing solidus. E.g.
. Requires use_trailing_solidus. sanitize=False|True Strip all unsafe or unknown constructs from output. See `html5lib user documentation`_ omit_optional_tags=True|False Omit start/end tags that are optional. alphabetical_attributes=False|True Reorder attributes to be in alphabetical order. .. _html5lib user documentation: http://code.google.com/p/html5lib/wiki/UserDocumentation rz2__init__() got an unexpected keyword argument '%s'r=FN) frozensetoptionslen TypeErrornextiterr>setattrr$getattrerrorsstrict)selfkwargsZunexpected_argsattrr/r/r0__init__ps.  zHTMLSerializer.__init__cCs*t|tst|jr"|j|jdS|SdS)Nr2)rrAssertionErrorr7encode)rTstringr/r/r0rYszHTMLSerializer.encodecCs*t|tst|jr"|j|jdS|SdS)NrS)rrrXr7rY)rTrZr/r/r0 encodeStrictszHTMLSerializer.encodeStrictNccs||_d}g|_|r0|jr0ddlm}|||}|jrJddlm}||}|jrdddlm}||}|j r~ddl m}||}|j rddl m}||}xR|D]H}|d}|dkr`d|d}|dr|d |d7}n|d r|d 7}|d rJ|d j d d kr0|d j dd kr*|jdd}nd }|d||d |f7}|d7}|j|Vq|d5kr|dksz|r|r|dj dd kr|jd|j|dVn|jt|dVq|d6kr|d} |jd| V| tkr|j rd}n|r|jdx|djD]\\} } } | } | }|jdV|j| V|j s| tj| tkr"| tjdtkr"|jdV|jdkst|d krd}n@|jd krtj|dk }n$|jd!krtj|dk }ntd"|jd#d$}|j r|jd%d&}|r|j!}|j"rTd|kr CharactersSpaceCharactersdatazCommentz--zComment contains --z ZEntityrzEntity %s not recognizedz&%s;)rarb)rdre))r7rRrGZfilters.inject_meta_charsetr\rFZfilters.alphabeticalattributesrHZfilters.whitespacerIZfilters.sanitizerr?Zfilters.optionaltagsfindserializeErrorr[rYrr rDitemsr@r r$tupler<rL_quoteAttributeSpecsearch_quoteAttributeLegacy ValueErrorreplacerCr=r>r rArBr rEr)rT treewalkerr7Zin_cdatar\tokenr]Zdoctyper=r^_Z attr_nameZ attr_valuekvZ quote_attrrckeyr/r/r0r9s                                    zHTMLSerializer.serializecCs2|rdjt|j||Sdjt|j|SdS)Nr)r'listr9)rTrvr7r/r/r0r5?szHTMLSerializer.renderXXX ERROR MESSAGE NEEDEDcCs|jj||jrtdS)N)rRr"rSSerializeError)rTrcr/r/r0rnEs zHTMLSerializer.serializeError)r<r=r>r?r@rArBrCrDrErFrGrHrI)N)N)r~)__name__ __module__ __qualname__r<r=r>r?r@rArBrCrDrErFrGrHrIrKrWrYr[r9r5rnr/r/r/r0r4Qs68  r4c@seZdZdZdS)rzError in serialized treeN)rrr__doc__r/r/r/r0rLsr)r3N)+Z __future__rrrZpip._vendor.sixrrecodecsrrZ constantsr r r r r rrrrZxml.sax.saxutilsrr'Z_quoteAttributeSpecCharscompilerqrsr#rLZ_is_ucs4r}roryrzr r!islowerr1r9rr4 Exceptionrr/r/r/r0s:         |