https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/genshi/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/genshi/__pycache__/output.cpython-310.pyc
o

!�b�z�@s8dZddlmZddlZddlZddlmZmZmZm	Z	m
Z
ddlmZmZm
Z
mZmZmZmZmZmZmZmZmZgd�ZdZd"d	d
�Zd#dd�Zd$dd�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Z Gdd�de�Z!Gdd�de�Z"e"j#Z#Gdd�de�Z$Gdd�de�Z%Gd d!�d!e�Z&dS)%zUThis module provides different kinds of serialization methods for XML event
streams.
�)�chainN)�escape�Attrs�Markup�QName�StreamEventKind)�START�END�TEXT�XML_DECL�DOCTYPE�START_NS�END_NS�START_CDATA�	END_CDATA�PI�COMMENT�
XML_NAMESPACE)�encode�get_serializer�DocType�
XMLSerializer�XHTMLSerializer�HTMLSerializer�TextSerializerzrestructuredtext en�xmlcsp�durd�|dkrt|t�sd���fdd�}ndd�}|dur*|d�t|���S|D]	}|�||��q,dS)	a�Encode serializer output into a string.
    
    :param iterator: the iterator returned from serializing a stream (basically
                     any iterator that yields unicode objects)
    :param method: the serialization method; determines how characters not
                   representable in the specified encoding are treated
    :param encoding: how the output string should be encoded; if set to `None`,
                     this method returns a `unicode` object
    :param out: a file-like object that the output should be written to
                instead of being returned as one big string; note that if
                this is a file or socket (or similar), the `encoding` must
                not be `None` (that is, the output must be encoded)
    :return: a `str` or `unicode` object (depending on the `encoding`
             parameter), or `None` if the `out` parameter is provided
    
    :since: version 0.4.1
    :note: Changed in 0.5: added the `out` parameter
    N�replace�text�xmlcharrefreplacecs|����S�N)r��string��encoding�errors��//usr/lib/python3/dist-packages/genshi/output.py�<lambda>7szencode.<locals>.<lambda>cSs|Srr%r r%r%r&r'9s�)�
isinstancer�join�list�write)�iterator�methodr#�out�_encode�chunkr%r"r&r s�rcKs0t|tj�rttttd�|��}|di|��S)a�Return a serializer object for the given method.
    
    :param method: the serialization method; can be either "xml", "xhtml",
                   "html", "text", or a custom serializer class

    Any additional keyword arguments are passed to the serializer, and thus
    depend on the `method` parameter value.
    
    :see: `XMLSerializer`, `XHTMLSerializer`, `HTMLSerializer`, `TextSerializer`
    :since: version 0.4.1
    )r�xhtml�htmlrNr%)r)�six�string_typesrrrr�lower)r.�kwargsr%r%r&r@s��rTcs6i�|r�fdd�}�j}ndd�}dd�}||�fS)aNPrepare a private token serialization cache.

    :param use_cache: boolean indicating whether a real cache should
                      be used or not. If not, the returned functions
                      are no-ops.

    :return: emit and get functions, for storing and retrieving
             serialized values from the cache.
    cs|�||f<|Srr%��kind�input�output��cacher%r&�_emit`sz_prepare_cache.<locals>._emitcSs|Srr%r8r%r%r&r>e�cSsdSrr%)�keyr%r%r&�_getgr?z_prepare_cache.<locals>._get)�get)�	use_cacher>rAr%r<r&�_prepare_cacheTs

rDc@sTeZdZdZdZdZdZeZdZdZ	dZ
dZe	Zd	Z
d
ZdZdZeZed
d��ZdS)rzDDefines a number of commonly used DOCTYPE declarations as constants.)r3z-//W3C//DTD HTML 4.01//ENz%http://www.w3.org/TR/html4/strict.dtd)r3z&-//W3C//DTD HTML 4.01 Transitional//ENz$http://www.w3.org/TR/html4/loose.dtd)r3z"-//W3C//DTD HTML 4.01 Frameset//ENz'http://www.w3.org/TR/html4/frameset.dtd)r3NN)r3z -//W3C//DTD XHTML 1.0 Strict//ENz1http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd)r3z&-//W3C//DTD XHTML 1.0 Transitional//ENz7http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd)r3z"-//W3C//DTD XHTML 1.0 Frameset//ENz3http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd)r3z-//W3C//DTD XHTML 1.1//ENz,http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd)�svgz-//W3C//DTD SVG 1.1//ENz0http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd)rEz-//W3C//DTD SVG Basic 1.1//ENz6http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd)rEz-//W3C//DTD SVG Tiny 1.1//ENz5http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtdcCsH|j|jtjtj|j|j|j|j|j	|j
|j|j|j
|jd��|���S)aReturn the ``(name, pubid, sysid)`` tuple of the ``DOCTYPE``
        declaration for the specified name.
        
        The following names are recognized in this version:
         * "html" or "html-strict" for the HTML 4.01 strict DTD
         * "html-transitional" for the HTML 4.01 transitional DTD
         * "html-frameset" for the HTML 4.01 frameset DTD
         * "html5" for the ``DOCTYPE`` proposed for HTML5
         * "xhtml" or "xhtml-strict" for the XHTML 1.0 strict DTD
         * "xhtml-transitional" for the XHTML 1.0 transitional DTD
         * "xhtml-frameset" for the XHTML 1.0 frameset DTD
         * "xhtml11" for the XHTML 1.1 DTD
         * "svg" or "svg-full" for the SVG 1.1 DTD
         * "svg-basic" for the SVG Basic 1.1 DTD
         * "svg-tiny" for the SVG Tiny 1.1 DTD
        
        :param name: the name of the ``DOCTYPE``
        :return: the ``(name, pubid, sysid)`` tuple for the requested
                 ``DOCTYPE``, or ``None`` if the name is not recognized
        :since: version 0.4.1
        )r3zhtml-strictzhtml-transitionalz
html-frameset�html5r2zxhtml-strictzxhtml-transitionalzxhtml-frameset�xhtml11rEzsvg-fullz	svg-basiczsvg-tiny)�HTML�HTML_STRICTr�HTML_TRANSITIONAL�
HTML_FRAMESET�HTML5�XHTML�XHTML_STRICT�XHTML_TRANSITIONAL�XHTML_FRAMESET�XHTML11�SVG�SVG_FULL�	SVG_BASIC�SVG_TINYrBr6)�cls�namer%r%r&rB�s�
�zDocType.getN)�__name__�
__module__�__qualname__�__doc__rIrJrKrHrLrNrOrPrMrQrSrTrUrR�classmethodrBr%r%r%r&rls$rc@s4eZdZdZe�Z		d
dd�Zdd�Zdd	�ZdS)raProduces XML text from an event stream.
    
    >>> from genshi.builder import tag
    >>> elem = tag.div(tag.a(href='foo'), tag.br, tag.hr(noshade=True))
    >>> print(''.join(XMLSerializer()(elem.generate())))
    <div><a href="foo"/><br/><hr noshade="True"/></div>
    NTcCsRt�g|_|r|j�t|j��|j�t||d��|r$|j�t|��||_dS)a�Initialize the XML serializer.
        
        :param doctype: a ``(name, pubid, sysid)`` tuple that represents the
                        DOCTYPE declaration that should be included at the top
                        of the generated output, or the name of a DOCTYPE as
                        defined in `DocType.get`
        :param strip_whitespace: whether extraneous whitespace should be
                                 stripped from the output
        :param cache: whether to cache the text output per event, which
                      improves performance for repetitive markup
        :note: Changed in 0.4.2: The  `doctype` parameter can now be a string.
        :note: Changed in 0.6: The `cache` parameter was added
        ��prefixesr=N)�EmptyTagFilter�filters�append�WhitespaceFilter�_PRESERVE_SPACE�NamespaceFlattener�DocTypeInserterr=)�self�doctype�strip_whitespace�namespace_prefixesr=r%r%r&�__init__�s

�
zXMLSerializer.__init__cCst|j�dd�S)N�)rDr=)rfr%r%r&rD�szXMLSerializer._prepare_cacheccs��d}}d}|��\}}|jD]}||�}q|D�]:\}}	}
|tur,t|	t�r,|	Vq|||	f�}|dur:|Vq|tusB|turt|	\}}
d|g}|
D]\}}|d|dt|�dg7}qL|�|turddped�|||	td�	|���Vq|t
ur�|||	td	|	��Vq|tur�|r�|||	|	�Vq|||	t|	dd
��Vq|tur�|||	td|	��Vq|tur�|s�|	\}}}d|g}|r�|�d
|�|dkr�|r�dp�d}|�d|�|�d�td�	|��Vd}q|t
u�r*|�s*|	\}}}dg}|�r|�d�n|�r	|�d�|�r|�d�|�d�td�	|��tdd�|	D��Vd}q|tu�r7td�Vd}q|tu�rDtd�Vd}q|tu�rT|||	td|	��VqdS)NF�<� �="�"z/>�>r(�</%s>��quotes�	<!--%s-->�<?xml version="%s"� encoding="%s"����yes�no� standalone="%s"�?>
T�<!DOCTYPE %s� PUBLIC "%s"� SYSTEM� "%s"�>
cS�g|]}|r|�qSr%r%��.0�pr%r%r&�
<listcomp>$�z*XMLSerializer.__call__.<locals>.<listcomp>�	<![CDATA[�]]>�	<?%s %s?>)rDr`r
r)rr�EMPTYrrar*r	rrr�tuplerrr)rf�stream�	have_decl�have_doctype�in_cdatar>rA�filter_r9�data�pos�cached�tag�attrib�buf�attr�value�versionr#�
standalonerW�pubid�sysidr%r%r&�__call__�sz�








"




��zXMLSerializer.__call__)NTNT)	rXrYrZr[�	frozensetrcrjrDr�r%r%r%r&r�s
�rcsfeZdZdZegd��Zegd��Zeed�ed�ed�ed�g�Z				d�fd
d�	Z	dd
�Z
�ZS)raProduces XHTML text from an event stream.
    
    >>> from genshi.builder import tag
    >>> elem = tag.div(tag.a(href='foo'), tag.br, tag.hr(noshade=True))
    >>> print(''.join(XHTMLSerializer()(elem.generate())))
    <div><a href="foo"></a><br /><hr noshade="noshade" /></div>
    )
�area�base�basefont�br�col�frame�hr�imgr:�isindex�link�meta�param)�selected�checked�compact�declare�defer�disabled�ismap�multiple�nohref�noresize�noshade�nowrap�	autofocus�readonly�required�formnovalidate�prez http://www.w3.org/1999/xhtml}pre�textareaz%http://www.w3.org/1999/xhtml}textareaNTcsztt|��|d�t�g|_|r|j�t|j��|pi}d|d<|j�t||d��|r5|j�t	|��||_
||_dS)NFr(�http://www.w3.org/1999/xhtmlr])�superrrjr_r`rarbrcrdre�
drop_xml_declr=)rfrgrhrir�r=��	__class__r%r&rjIs

�
zXHTMLSerializer.__init__ccs,�|j}|j}|j}d}}d}|��\}}	|jD]}
|
|�}q|D�]p\}}}
|tur5t|t�r5|Vq"|	||f�}|durC|Vq"|tusK|t	ur�|\}}d|g}|D]-\}}||vr`|}n|dkrrd|vrr|dt
|�dg7}n|dkrwqU|d|d	t
|�dg7}qU|t	ur�||vr�|�d
�n
|�d|�n|�d�|||td
�|���Vq"|t
ur�|||td|��Vq"|tur�|r�||||�Vq"|||t
|dd��Vq"|tur�|||td|��Vq"|tu�r&|�s&|\}}}dg}|r�|�d�n|�r|�d�|�r
|�d�|�d�td
�|��tdd�|D��Vd}q"|tu�ri|�si|�si|\}}}d|g}|�rE|�d|�|dk�rY|�rPd�pQd}|�d|�|�d�td
�|��Vd}q"|tu�rvtd �Vd}q"|tu�r�td!�Vd}q"|tu�r�|||td"|��Vq"dS)#NFrl�xml:lang�lang� lang="roz	xml:spacermrnz />z></%s>rpr(rqrrrtr|r}r~rr�cSr�r%r%r�r%r%r&r��r�z,XHTMLSerializer.__call__.<locals>.<listcomp>Trurvrwrxryrzr{r�r�r�)�_BOOLEAN_ATTRS�_EMPTY_ELEMSr�rDr`r
r)rrr�rrar*r	rrr�rrrr)rfr��
boolean_attrs�empty_elemsr�r�r�r�r>rAr�r9r�r�r�r�r�r�r�r�rWr�r�r�r#r�r%r%r&r�Xs��






"








��zXHTMLSerializer.__call__)NTNTT)rXrYrZr[r�r�r�rrcrjr��
__classcell__r%r%r�r&r3s��rcsJeZdZdZeed�ed�ed�ed�g�Zd�fdd	�	Zd
d�Z�Z	S)
ra
Produces HTML text from an event stream.
    
    >>> from genshi.builder import tag
    >>> elem = tag.div(tag.a(href='foo'), tag.br, tag.hr(noshade=True))
    >>> print(''.join(HTMLSerializer()(elem.generate())))
    <div><a href="foo"></a><br><hr noshade></div>
    �scriptz#http://www.w3.org/1999/xhtml}script�stylez"http://www.w3.org/1999/xhtml}styleNTcsltt|��|d�t�g|_|r|j�t|j|j��|j�t	ddi|d��|r1|j�t
|��d|_dS)aHInitialize the HTML serializer.
        
        :param doctype: a ``(name, pubid, sysid)`` tuple that represents the
                        DOCTYPE declaration that should be included at the top
                        of the generated output
        :param strip_whitespace: whether extraneous whitespace should be
                                 stripped from the output
        :param cache: whether to cache the text output per event, which
                      improves performance for repetitive markup
        :note: Changed in 0.6: The `cache` parameter was added
        Fr�r(r]TN)r�rrjr_r`rarbrc�_NOESCAPE_ELEMSrdrer=)rfrgrhr=r�r%r&rj�s
���
zHTMLSerializer.__init__ccs��|j}|j}|j}d}d}|��\}}|jD]}	|	|�}q|D�]6\}
}}|
tur3t|t�r3|Vq ||
|f�}
|
durX|
V|
tusH|
t	urQ|d|vrQd}q |
t
urWd}q |
tus`|
t	ur�|\}}d|g}|D]6\}}||vr{|rz|d|g7}qjd|vr�|dkr�d|vr�|d	t|�d
g7}qj|dkr�|d|dt|�d
g7}qj|�d
�|
t	ur�||vr�|�d|�||
|td�
|���V||vr�d}q |
t
ur�||
|td|��Vd}q |
tur�|r�||
||�Vq ||
|t|dd��Vq |
tu�r||
|td|��Vq |
tu�rG|�sG|\}}}dg}|�r|�d�n|�r&|�d�|�r.|�d�|�d�td�
|��tdd�|D��Vd}q |
tu�rW||
|td|��Vq dS)NFrTrlrm�:r�r�r�ro�xmlnsrnrprqr(rrrtr|r}r~rr�cSr�r%r%r�r%r%r&r�r�z+HTMLSerializer.__call__.<locals>.<listcomp>r�)r�r�r�rDr`r
r)rrr�r	rrar*rrr�r)rfr�r�r��noescape_elemsr��noescaper>rAr�r9r��_r;r�r�r�r�r�rWr�r�r%r%r&r��s��

����
�




"
��zHTMLSerializer.__call__)NTT)
rXrYrZr[r�rr�rjr�r�r%r%r�r&r�s�rc@s"eZdZdZddd�Zdd�ZdS)	raDProduces plain text from an event stream.
    
    Only text events are included in the output. Unlike the other serializer,
    special XML characters are not escaped:
    
    >>> from genshi.builder import tag
    >>> elem = tag.div(tag.a('<Hello!>', href='foo'), tag.br)
    >>> print(elem)
    <div><a href="foo">&lt;Hello!&gt;</a><br/></div>
    >>> print(''.join(TextSerializer()(elem.generate())))
    <Hello!>

    If text events contain literal markup (instances of the `Markup` class),
    that markup is by default passed through unchanged:
    
    >>> elem = tag.div(Markup('<a href="foo">Hello &amp; Bye!</a><br/>'))
    >>> print(elem.generate().render(TextSerializer, encoding=None))
    <a href="foo">Hello &amp; Bye!</a><br/>
    
    You can use the ``strip_markup`` to change this behavior, so that tags and
    entities are stripped from the output (or in the case of entities,
    replaced with the equivalent character):

    >>> print(elem.generate().render(TextSerializer, strip_markup=True,
    ...                              encoding=None))
    Hello & Bye!
    FcCs
||_dS)z�Create the serializer.
        
        :param strip_markup: whether markup (tags and encoded characters) found
                             in the text should be removed
        N)�strip_markup)rfr�r%r%r&rj;s
zTextSerializer.__init__ccsR�|j}|D] }|dtur&|d}|r t|�tur |����}t�|�VqdS)Nr�)r�r
�typer�	striptags�
stripentitiesr4�	text_type)rfr�r��eventr�r%r%r&r�Cs���zTextSerializer.__call__N)F�rXrYrZr[rjr�r%r%r%r&rs
rc@s eZdZdZed�Zdd�ZdS)r_zcCombines `START` and `STOP` events into `EMPTY` events for elements that
    have no contents.
    r�ccsb�d}|D])}|dtur#|dtur t|d|df}|Vq|V|dtur,|V|}qdS)N�NNNrr�rk)rr	r�)rfr��prev�evr%r%r&r�Ts��zEmptyTagFilter.__call__N)rXrYrZr[rr�r�r%r%r%r&r_Msr_c@s"eZdZdZddd�Zdd�ZdS)	rdafOutput stream filter that removes namespace information from the stream,
    instead adding namespace attributes and prefixes as needed.
    
    :param prefixes: optional mapping of namespace URIs to prefixes
    
    >>> from genshi.input import XML
    >>> xml = XML('''<doc xmlns="NS1" xmlns:two="NS2">
    ...   <two:item/>
    ... </doc>''')
    >>> for kind, data, pos in NamespaceFlattener()(xml):
    ...     print('%s %r' % (kind, data))
    START ('doc', Attrs([('xmlns', 'NS1'), ('xmlns:two', 'NS2')]))
    TEXT '\n  '
    START ('two:item', Attrs())
    END 'two:item'
    TEXT '\n'
    END 'doc'
    NTcCs*tjdi|_|dur|j�|�||_dS)Nr)r�urir^�updater=)rfr^r=r%r%r&rjzs
zNamespaceFlattener.__init__c#s��tdd�|j��D���tjdgi�t|j�\}}����fdd�}���fdd�}g}|j}dd	�}d
d�}	|	���fdd
�}	|D�]\}
}}|
turYt	|t
�rY|
||fVqC||
|f�}
|
durj|
|
|fVqC|
tusr|
tur�|\}}|j
}|j}|r�|�vr��|d}|r�d||f}n|d|f�|d|�g}|D]6\}}|j
}|j}|r�|�vr�|	�}|||�|d||f�n�|d}|r�d||f}|�||f�q�||
||t||�f�}|
||fV|dd�=qC|
tu�r|j
}|j}|�r�|d}|�rd||f}|
||
||�|fVqC|
tu�r;|\}}|�v�r5��||g�d}||||��|||�qC|
tu�r\|�v�r[||�}|�r[|||�}||v�r[|�|�qC|
||fVqCdS)NcSsg|]	\}}||gf�qSr%r%)r��k�vr%r%r&r��sz/NamespaceFlattener.__call__.<locals>.<listcomp>rcs0��|g��|���|g��|����dSr)�
setdefaultra�clear��prefixr��r=�
namespacesr^r%r&�_push_ns�sz-NamespaceFlattener.__call__.<locals>._push_nscsV��|�}|��}|s�|=||vs||dkr%�|}|��|s%�|=���|S)Nrw)rB�popr�)r��urisr��uri_prefixesr�r%r&�_pop_ns�s
z,NamespaceFlattener.__call__.<locals>._pop_nscSsd|rd|pd|fS)Nzxmlns%sz:%sr(r%r�r%r%r&�
_make_ns_attr�sz2NamespaceFlattener.__call__.<locals>._make_ns_attrcss�d}	|d7}d|Vq)Nrr�zns%dr%)�valr%r%r&�_gen_prefix�s�
�z0NamespaceFlattener.__call__.<locals>._gen_prefixcst��Sr)�nextr%)�_prefix_generatorr%r&r'�sz-NamespaceFlattener.__call__.<locals>.<lambda>rwz%s:%sr�r(zxmlns:%s)�dictr^�itemsrr�rDr=rar
r)rrr��	localname�	namespacerr	r
rBr�remove)rfr�r>rAr�r��ns_attrs�
_push_ns_attrr�r�r9r�r�r;r��attrs�tagname�tagnsr��	new_attrsr�r��attrname�attrnsr�r%)r�r=r�r^r&r��s��
�









��zNamespaceFlattener.__call__)NTr�r%r%r%r&rdfs
rdc@s@eZdZdZd
dd�Zdede�d�je�d�jfdd	�Z	dS)rbzPA filter that removes extraneous ignorable white space from the
    stream.
    NcCs0|durg}t|�|_|durg}t|�|_dS)a�Initialize the filter.
        
        :param preserve: a set or sequence of tag names for which white-space
                         should be preserved
        :param noescape: a set or sequence of tag names for which text content
                         should not be escaped
        
        The `noescape` set is expected to refer to elements that cannot contain
        further child elements (such as ``<style>`` or ``<script>`` in HTML
        documents).
        N)r��preserver�)rfr�r�r%r%r&rj�s
zWhitespaceFilter.__init__�spacez
[ 	]+(?=
)z
{2,}ccsL�td�j}|j}d}|j}	d}
g}|j}|j}
t|dg�D]�\}}}|tur2|
r-t|�}||�q|r_t|�dkrF||dd�}|dd�=nt	|
�dd�}|sW|d|d|��}tt|�|fV|t
ur�|\}}|st||vst|�|�d	krx|d7}|
s�||	vr�d
}
n|tur�d}
|r�|d8}n
|t
ur�d
}
n|tur�d}
|r�|||fVqdS)Nr(rFr�r�)�
escape_quotesrr�
r�T)rr*r�r�rar�rr
�lenrrrBr	rr)rfr��ctxtr��trim_trailing_space�collapse_lines�mjoin�preserve_elemsr�r�r��textbuf�	push_text�pop_textr9r�r�rr�r�r%r%r&r��sV�

����zWhitespaceFilter.__call__)NN)
rXrYrZr[rjr�re�compile�subr�r%r%r%r&rb�s


�rbc@s eZdZdZdd�Zdd�ZdS)rezjA filter that inserts the DOCTYPE declaration in the correct location,
    after the XML declaration.
    cCs&t|tj�rt�|�}t|df|_dS)z_Initialize the filter.

        :param doctype: DOCTYPE as a string or DocType object.
        )NrwrwN)r)r4r5rrBr�
doctype_event)rfrgr%r%r&rj7s
zDocTypeInserter.__init__ccsd�d}|D]"\}}}|s!d}|tur|||fV|jVq|jV|||fVq|s0|jVdSdS)NFT)rr)rfr��doctype_insertedr9r�r�r%r%r&r�@s��zDocTypeInserter.__call__Nr�r%r%r%r&re3s	re)rNN)r)T)'r[�	itertoolsrrr4�genshi.corerrrrrrr	r
rrr
rrrrrr�__all__�
__docformat__rrrD�objectrrrrrr_r�rdrbrer%r%r%r&�<module>s,
8

 
Zm|o/L

https://t.me/RX1948 - 2025