t_=@sddlmZmZmZddlmZddlZddlmZm Z ddl m Z m Z m Z ddl mZmZmZddlmZmZdd lmZd je d Zejd ed Zejd edZiZeddkZxeejD]\Z Z!eo9ee!dkpRe oRee!dkrXqe!dkree!dkrej"e!Z!n e#e!Z!e!ekpe j$re ee!`[]u_  /`  ᠎᠏           

   ]u􏿿&c Cst|ttfrzg}g}d}xt|j|j|jD]\}}|rbd}qG||j}tj|j|t |j|dgrtj |j||d}d}n t |}|j |qGWx}|D]u}t j|} | r?|j d|j | | jds`|j dq|j dt|ddqWdj||jfSt|SdS)NFrTr;z&#x%s;r) isinstanceUnicodeEncodeErrorUnicodeTranslateError enumerateobjectstartendrisSurrogatePairminsurrogatePairToCodepointordappend_encode_entity_mapgetendswithhexjoinr) excres codepointsskipicindex codepointcper3/builddir/build/BUILDROOT/alt-python35-pip-20.2.4-1.el7.x86_64/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/html5lib/serializer.pyhtmlentityreplace_errors*s0, /      %r5htmlentityreplaceetreecKs1tj|}t|}|j|||S)aSerializes the input token stream using the specified treewalker :arg input: the token stream to serialize :arg tree: the treewalker to use :arg encoding: the encoding to use :arg serializer_opts: any options to pass to the :py:class:`html5lib.serializer.HTMLSerializer` that gets created :returns: the tree serialized as a string Example: >>> from html5lib.html5parser import parse >>> from html5lib.serializer import serialize >>> token_stream = parse('

Hi!

') >>> serialize(token_stream, omit_optional_tags=False) '

Hi!

' )r getTreeWalkerHTMLSerializerrender)inputtreeencodingserializer_optswalkersr3r3r4 serializeKs rAc@seZdZdZdZdZdZdZdZdZ dZ dZ dZ dZ dZdZdZd!ZddZddZddZdddZdddZddd ZdS)"r9legacy"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 Kst|t|j}t|dkrGtdtt|d|kr\d|_x6|jD]+}t|||j|t ||qfWg|_ d|_ dS)aB Initialize HTMLSerializer :arg inject_meta_charset: Whether or not to inject the meta charset. Defaults to ``True``. :arg quote_attr_values: Whether to quote attribute values that don't require quoting per legacy browser behavior (``"legacy"``), when required by the standard (``"spec"``), or always (``"always"``). Defaults to ``"legacy"``. :arg quote_char: Use given quote character for attribute quoting. Defaults to ``"`` which will use double quotes unless attribute value contains a double quote, in which case single quotes are used. :arg escape_lt_in_attrs: Whether or not to escape ``<`` in attribute values. Defaults to ``False``. :arg escape_rcdata: Whether to escape characters that need to be escaped within normal elements within rcdata elements such as style. Defaults to ``False``. :arg resolve_entities: Whether to resolve named character entities that appear in the source tree. The XML predefined entities < > & " ' are unaffected by this setting. Defaults to ``True``. :arg strip_whitespace: Whether to remove semantically meaningless whitespace. (This compresses all whitespace to a single space except within ``pre``.) Defaults to ``False``. :arg minimize_boolean_attributes: Shortens boolean attributes to give just the attribute value, for example:: becomes:: Defaults to ``True``. :arg use_trailing_solidus: Includes a close-tag slash at the end of the start tag of void elements (empty elements whose end tag is forbidden). E.g. ``
``. Defaults to ``False``. :arg space_before_trailing_solidus: Places a space immediately before the closing slash in a tag using a trailing solidus. E.g. ``
``. Requires ``use_trailing_solidus=True``. Defaults to ``True``. :arg sanitize: Strip all unsafe or unknown constructs from output. See :py:class:`html5lib.filters.sanitizer.Filter`. Defaults to ``False``. :arg omit_optional_tags: Omit start/end tags that are optional. Defaults to ``True``. :arg alphabetical_attributes: Reorder attributes to be in alphabetical order. Defaults to ``False``. rz2__init__() got an unexpected keyword argument '%s'rEFN) frozensetoptionslen TypeErrornextiterrFsetattrr%getattrerrorsstrict)selfkwargsunexpected_argsattrr3r3r4__init__sO  ) zHTMLSerializer.__init__cCs9t|tst|jr1|j|jdS|SdS)Nr6)rrAssertionErrorr=encode)r\stringr3r3r4rbs zHTMLSerializer.encodecCs9t|tst|jr1|j|jdS|SdS)Nr[)rrrar=rb)r\rcr3r3r4 encodeStricts zHTMLSerializer.encodeStrictNccs8||_d}g|_|rF|jrFddlm}|||}|jrkddlm}||}|jrddlm}||}|j rddl m}||}|j rddl m}||}xW|D]O}|d}|dkrd|d}|dr*|d |d7}n|d r>|d 7}|d r|d j d d kr|d j dd kr|jdd}nd }|d||d |f7}|d7}|j|Vq|d5krF|dks|r+|r|dj dd kr|jd|j|dVq0|jt|dVq|d6kr|d} |jd| V| tkr|j rd}n|r|jdx|djD]\\} } } | } | }|jdV|j| V|j s+| tj| tkr| tjdtkr|jdV|jdksZt|d krcd}nZ|jd krtj|dk }n3|jd!krtj|dk }n td"|jd#d$}|j r|jd%d&}|r|j!}|j"rAd|kr#d |kr#d }nd |krAd|krAd}|dkrb|jdd'}n|jd d(}|j|V|j|V|j|Vq|j|VqW| t#kr|j$r|j%r|jd)Vn|jd*V|jdVq|d+krT|d} | tkr,d}n|r?|jd|jd,| Vq|d-kr|d}|j d.d kr|jd/|jd0|dVq|d1kr|d} | d2}|t&kr|jd3| |j'r|t(krt&|}n d4| }|j|Vq|j|dqWdS)7NFr)FiltertypeDoctypez CharactersSpaceCharactersdatazCommentz--zComment contains --z EntityrzEntity %s not recognizedz&%s;)rmrn)rprq))r=rZrOfilters.inject_meta_charsetrerNfilters.alphabeticalattributesrPfilters.whitespacerQfilters.sanitizerrGfilters.optionaltagsfindserializeErrorrdrbrr rLitemsrHr r%tuplerDrT_quoteAttributeSpecsearch_quoteAttributeLegacy ValueErrorreplacerKrErFr rIrJr rMr)r\ treewalkerr=in_cdataretokenrfdoctyperErh_ attr_name attr_valuekv quote_attrrokeyr3r3r4rAs                          # !                      zHTMLSerializer.serializecCsE|r%djt|j||Sdjt|j|SdS)anSerializes the stream from the treewalker into a string :arg treewalker: the treewalker to serialize :arg encoding: the string encoding to use :returns: the serialized tree Example: >>> from html5lib import parse, getTreeWalker >>> from html5lib.serializer import HTMLSerializer >>> token_stream = parse('Hi!') >>> walker = getTreeWalker('etree') >>> serializer = HTMLSerializer(omit_optional_tags=False) >>> serializer.render(walker(token_stream)) 'Hi!' rN)r(listrA)r\rr=r3r3r4r:wszHTMLSerializer.renderzXXX ERROR MESSAGE NEEDEDcCs#|jj||jrtdS)N)rZr#r[SerializeError)r\ror3r3r4rs zHTMLSerializer.serializeError)rDrErFrGrHrIrJrKrLrMrNrOrPrQ)__name__ __module__ __qualname__rDrErFrGrHrIrJrKrLrMrNrOrPrQrSr`rbrdrAr:rr3r3r3r4r9hs4  Y  r9c@seZdZdZdS)rzError in serialized treeN)rrr__doc__r3r3r3r4rs r)+ __future__rrrZpip._vendor.sixrrecodecsrr constantsr r r r r rrrrxml.sax.saxutilsrr(_quoteAttributeSpecCharscompilerrr$rT_is_ucs4rrrrr!r"islowerr5rArr9 Exceptionrr3r3r3r4s:       0