• File: serializer.cpython-37.opt-1.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib/python3.7/site-packages/html5lib/__pycache__/serializer.cpython-37.opt-1.pyc
  • Date Modified: 07/08/2021 11:01 AM
  • File size: 10.45 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

63)Z=@s~ddlmZmZmZddlmZddlZddlmZm	Z	ddl
mZmZm
Z
ddl
mZmZmZddlmZmZdd	lmZd
e
dZeded
ZededZiZeddkZx~eeD]n\Z Z!eree!dksesee!dkrqe!dkree!dkre"e!Z!ne#e!Z!e!eks2e $re ee!<qWddZ%ede%dddZ&Gddde'Z(Gddde)Z*dS))absolute_importdivisionunicode_literals)	text_typeN)register_errorxmlcharrefreplace_errors)voidElementsbooleanAttributesspaceCharacters)rcdataElementsentitiesxmlEntities)treewalkers_utils)escapez"'=<>`[]u_	

 /`  ᠎᠏           

   ]u􏿿&c
	Cs"t|ttfrg}g}d}xt|j|j|jD]n\}}|rFd}q4||j}t|j|t	|j|dgrt
|j||d}d}nt|}||q4Wx^|D]V}t
|}	|	r|d||	|	ds|dq|dt|ddqWd||jfSt|SdS)NFrTr;z&#x%s;r)
isinstanceUnicodeEncodeErrorUnicodeTranslateError	enumerateobjectstartendrZisSurrogatePairminsurrogatePairToCodepointordappend_encode_entity_mapgetendswithhexjoinr)
excZresZ
codepointsskipicindexZ	codepointZcper.D/opt/alt/python37/lib/python3.7/site-packages/html5lib/serializer.pyhtmlentityreplace_errors*s0 
"




r0htmlentityreplaceetreecKs$t|}tf|}||||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('<html><body><p>Hi!</p></body></html>')
    >>> serialize(token_stream, omit_optional_tags=False)
    '<html><head></head><body><p>Hi!</p></body></html>'

    )rZ
getTreeWalkerHTMLSerializerrender)inputZtreeencodingZserializer_optsZwalkersr.r.r/	serializeKs

r8c@s~eZdZdZdZdZdZdZdZdZ	dZ
dZdZdZ
dZdZdZdZddZdd	Zd
dZdd
dZdddZdddZdS)r3legacy"TF)quote_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||||t	||qHWg|_
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 &lt; &gt;
            &amp; &quot; &apos; 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::

              <input disabled="disabled">

            becomes::

              <input disabled>

            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. ``<hr/>``.

            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.
            ``<hr />``. 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)	frozensetoptionslen	TypeErrornextiterr=setattrr$getattrerrorsstrict)selfkwargsZunexpected_argsattrr.r.r/__init__sOzHTMLSerializer.__init__cCs|jr||jdS|SdS)Nr1)r6encode)rSstringr.r.r/rWszHTMLSerializer.encodecCs|jr||jdS|SdS)NrR)r6rW)rSrXr.r.r/encodeStrictszHTMLSerializer.encodeStrictNccs||_d}g|_|r0|jr0ddlm}|||}|jrJddlm}||}|jrdddlm}||}|j	r~ddl
m}||}|jrddlm}||}xN|D]D}|d}|dkr`d|d}|dr|d	|d7}n|d
r|d7}|d
rJ|d

dd
kr0|d

dd
kr*|dd}nd}|d||d
|f7}|d7}||Vq|dkr|dksz|r|r|d
dd
kr|d||dVn|t|dVq|dkr|d}	|d|	V|	tkr|jsd}n|r|dx|dD]\\}
}}|}
|}|dV||
V|jr~|
t|	tkr |
tdtkr |dV|jdkst|d
krd}n@|jdkrt|dk	}n$|jd krt|dk	}ntd!|d"d#}|j r
|d$d%}|r|j!}|j"rPd|kr8d|kr8d}nd|krPd|krPd}|dkrh|dd&}n|dd'}||V||V||Vn||Vq W|	t#kr|j$r|j%r|d(Vn|d)V|dVq|d*kr2|d}	|	tkrd}n|r |d|d+|	Vq|d,krt|d}|
d-d
kr^|d.|d/|dVq|d0kr|d}	|	d1}|t&kr|d2|	|j'r|t(krt&|}nd3|	}||Vq||dqWdS)4NFr)FiltertypeZDoctypez<!DOCTYPE %snameZpublicIdz PUBLIC "%s"ZsystemIdz SYSTEMr:r'zASystem identifer contains both single and double quote charactersz %s%s%s>)Z
CharactersSpaceCharactersr_dataz</zUnexpected </ in CDATA)ZStartTagZEmptyTagz<%sTz+Unexpected child element of a CDATA element r=alwaysspecr9z?quote_attr_values must be one of: 'always', 'spec', or 'legacy'rz&amp;<z&lt;z&#39;z&quot;z //ZEndTagz</%s>Commentz--zComment contains --z	<!--%s-->ZEntityrzEntity %s not recognizedz&%s;))r6rQrFZfilters.inject_meta_charsetrZrEZfilters.alphabeticalattributesrGZfilters.whitespacerHZfilters.sanitizerr>Zfilters.optionaltagsfindserializeErrorrYrWrrrCitemsr?r
r$tupler;rK_quoteAttributeSpecsearch_quoteAttributeLegacy
ValueErrorreplacerBr<r=r	r@rAr
rDr)rS
treewalkerr6Zin_cdatarZtokenr[Zdoctyper<r\_Z	attr_nameZ
attr_valuekvZ
quote_attrr`keyr.r.r/r8s

















zHTMLSerializer.serializecCs2|rdt|||Sdt||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('<html><body>Hi!</body></html>')
        >>> walker = getTreeWalker('etree')
        >>> serializer = HTMLSerializer(omit_optional_tags=False)
        >>> serializer.render(walker(token_stream))
        '<html><head></head><body>Hi!</body></html>'

        rN)r'listr8)rSrqr6r.r.r/r4wszHTMLSerializer.renderXXX ERROR MESSAGE NEEDEDcCs|j||jrtdS)N)rQr"rRSerializeError)rSr`r.r.r/riszHTMLSerializer.serializeError)N)N)ry)__name__
__module____qualname__r;r<r=r>r?r@rArBrCrDrErFrGrHrJrVrWrYr8r4rir.r.r.r/r3hs,Y


r3c@seZdZdZdS)rzzError in serialized treeN)r{r|r}__doc__r.r.r.r/rzsrz)r2N)+Z
__future__rrrZsixrrecodecsrrZ	constantsr	r
rrr
rrrrZxml.sax.saxutilsrr'Z_quoteAttributeSpecCharscompilerlrnr#rKZ_is_ucs4rxrjrtrur r!islowerr0r8rr3	Exceptionrzr.r.r.r/<module>s<
	

1