U ÀÒ.eŽ=ã@szddlmZmZmZddlmZddlZddlmZm Z ddl m Z m Z m Z ddl mZmZmZddlmZmZdd lmZd  e ¡d Ze d ed ¡Ze d ed¡ZiZedƒdkZee ¡ƒD]n\Z Z!erâee!ƒdksÊesôee!ƒdkrôqÊe!dkrÊee!ƒdkre "e!¡Z!ne#e!ƒZ!e!eks0e  $¡rÊe ee!<qÊdd„Z%ede%ƒddd„Z&Gdd„de'ƒZ(Gdd„de)ƒZ*dS)é)Úabsolute_importÚdivisionÚunicode_literals)Ú text_typeN)Úregister_errorÚxmlcharrefreplace_errorsé)Ú voidElementsÚbooleanAttributesÚspaceCharacters)ÚrcdataElementsÚentitiesÚ xmlEntities)Ú treewalkersÚ_utils)ÚescapeÚz"'=<>`ú[ú]u_  /`  ᠎á â€€â€â€‚        

 âŸã€€]uô¿¿éú&c Cst|ttfƒrg}g}d}t|j|j|j…ƒD]n\}}|rDd}q2||j}t |j|t |j|dgƒ…¡rŽt  |j||d…¡}d}nt |ƒ}|  |¡q2|D]V}t  |¡} | râ|  d¡|  | ¡|  d¡sü|  d¡q¦|  dt|ƒdd…¡q¦d |¡|jfSt|ƒSdS)NFrTrú;z&#x%s;r)Ú isinstanceÚUnicodeEncodeErrorÚUnicodeTranslateErrorÚ enumerateÚobjectÚstartÚendrZisSurrogatePairÚminÚsurrogatePairToCodepointÚordÚappendÚ_encode_entity_mapÚgetÚendswithÚhexÚjoinr) ÚexcÚresZ codepointsÚskipÚiÚcÚindexZ codepointZcpÚe©r/úC/usr/lib/python3.8/site-packages/pip/_vendor/html5lib/serializer.pyÚhtmlentityreplace_errors*s0 "      r1ÚhtmlentityreplaceÚetreecKs$t |¡}tf|Ž}| ||ƒ|¡S)a˜Serializes 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!

' )rZ getTreeWalkerÚHTMLSerializerÚrender)ÚinputZtreeÚencodingZserializer_optsZwalkerÚsr/r/r0Ú serializeKs  r9c@s~eZdZdZdZdZdZdZdZdZ dZ dZ dZ dZ dZdZdZdZdd„Zdd „Zd d „Zdd d„Zddd„Zddd„Zd S)r4Úlegacyú"TF)Úquote_attr_valuesÚ quote_charÚuse_best_quote_charÚomit_optional_tagsÚminimize_boolean_attributesÚuse_trailing_solidusÚspace_before_trailing_solidusÚescape_lt_in_attrsÚ escape_rcdataÚresolve_entitiesÚalphabetical_attributesÚinject_meta_charsetÚstrip_whitespaceÚsanitizec Ksvt|ƒt|jƒ}t|ƒdkr2tdtt|ƒƒƒ‚d|kr@d|_|jD]}t||| |t ||ƒ¡ƒqFg|_ 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'r=FN) Ú frozensetÚoptionsÚlenÚ TypeErrorÚnextÚiterr>Úsetattrr$ÚgetattrÚerrorsÚstrict)ÚselfÚkwargsZunexpected_argsÚattrr/r/r0Ú__init__‡sO  zHTMLSerializer.__init__cCs|jr| |jd¡S|SdS)Nr2©r7Úencode©rTÚstringr/r/r0rYàszHTMLSerializer.encodecCs|jr| |jd¡S|SdS)NrSrXrZr/r/r0Ú encodeStrictçszHTMLSerializer.encodeStrictNccsâ||_d}g|_|r0|jr0ddlm}|||ƒ}|jrJddlm}||ƒ}|jrdddlm}||ƒ}|j r~ddl m}||ƒ}|j r˜ddl m}||ƒ}|D]>}|d}|dkr\d|d}|drÚ|d |d7}n|d rê|d 7}|d rF|d   d ¡d kr,|d   d¡d kr&| d¡d}nd }|d||d |f7}|d7}| |¡Vqœ|dkrÂ|dksv|r¬|rš|d  d¡d krš| d¡| |d¡Vn| t|dƒ¡Vqœ|dkrä|d} | d| ¡V| tkrü|jsüd}n|r | d¡|d ¡D]†\\} } } | } | }| d¡V| | ¡V|jrv| t | tƒ¡kr| t dtƒ¡kr| d¡V|jdksœt|ƒd kr¢d}n@|jdkr¾t |¡dk }n$|jd krÚt |¡dk }ntd!ƒ‚| d"d#¡}|j r| d$d%¡}|r’|j!}|j"rHd|kr0d |kr0d }nd |krHd|krHd}|dkr`| dd&¡}n | d d'¡}| |¡V| |¡V| |¡Vn | |¡Vq| t#krÖ|j$rÖ|j%rÊ| d(¡Vn | d)¡V| d¡Vqœ|d*kr(|d} | tkrd}n|r| d¡| d+| ¡Vqœ|d,krj|d}|  d-¡d krT| d.¡| d/|d¡Vqœ|d0krÎ|d} | d1}|t&krœ| d2| ¡|j'r¸|t(kr¸t&|}nd3| }| |¡Vqœ| |d¡qœdS)4NFr)ÚFilterÚtypeZDoctypez )Z CharactersÚSpaceCharactersrbÚdatazÚCommentz--zComment contains --z ZEntityrzEntity %s not recognizedz&%s;))r7rRrGZfilters.inject_meta_charsetr]rFZfilters.alphabeticalattributesrHZfilters.whitespacerIZfilters.sanitizerr?Zfilters.optionaltagsÚfindÚserializeErrorr\rYrr rDÚitemsr@r r$Útupler<rLÚ_quoteAttributeSpecÚsearchÚ_quoteAttributeLegacyÚ ValueErrorÚreplacerCr=r>r rArBr rEr)rTÚ treewalkerr7Zin_cdatar]Útokenr^Zdoctyper=r_Ú_Z attr_nameZ attr_valueÚkÚvZ quote_attrrcÚkeyr/r/r0r9îsÜ                  ÿþ                  zHTMLSerializer.serializecCs2|rd t| ||¡ƒ¡Sd t| |¡ƒ¡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'Úlistr9)rTrtr7r/r/r0r5wszHTMLSerializer.renderúXXX ERROR MESSAGE NEEDEDcCs|j |¡|jrt‚dS)N)rRr"rSÚSerializeError)rTrcr/r/r0rls zHTMLSerializer.serializeError)N)N)r|)Ú__name__Ú __module__Ú __qualname__r<r=r>r?r@rArBrCrDrErFrGrHrIrKrWrYr\r9r5rlr/r/r/r0r4hs,Y  r4c@seZdZdZdS)r}zError in serialized treeN)r~rr€Ú__doc__r/r/r/r0r}—sr})r3N)+Z __future__rrrZpip._vendor.sixrÚreÚcodecsrrZ constantsr r r r r rrrrZxml.sax.saxutilsrr'Z_quoteAttributeSpecCharsÚcompilerorqr#rLZ_is_ucs4r{rmrwrxr r!Úislowerr1r9rr4Ú Exceptionr}r/r/r/r0ÚsD   ÿ  ÿ ÿ    1