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__/input.cpython-310.pyc
o

!�b�@�@s�dZddlmZddlZddlmZddlZddlmZ	m
Zddlm
Z
mZmZmZddlmZmZmZmZmZmZmZmZmZmZmZddlmZmZgd	�Zd
Z dd�Z!Gd
d�de"�Z#Gdd�de$�Z%dd�Z&Gdd�dej'e$�Z'ddd�Z(dd�Z)dS)zOSupport for constructing markup streams from files, strings, or other
sources.
�)�chainN)�expat)�
html_entities�html_parser)�Attrs�QName�Stream�
stripentities)�START�END�XML_DECL�DOCTYPE�TEXT�START_NS�END_NS�START_CDATA�	END_CDATA�PI�COMMENT)�StringIO�BytesIO)�ET�
ParseError�	XMLParser�XML�
HTMLParser�HTMLzrestructuredtext enccs��t|j�d��}tdd�|��D��}t||fdfV|jr&t|jdfV|D]}t|�D]}|Vq.q(t	|dfV|j
rGt|j
dfVdSdS)z�Convert a given ElementTree element to a markup stream.
    
    :param element: an ElementTree element
    :return: a markup stream
    �{cSs"g|]
\}}t|�d��|f�qS)r)r�lstrip)�.0�attr�value�r"�./usr/lib/python3/dist-packages/genshi/input.py�
<listcomp>*s�zET.<locals>.<listcomp>�N���r&N)r�tagrr�itemsr
�textrrr�tail)�element�tag_name�attrs�child�itemr"r"r#r#s ����rc@seZdZdZddd�ZdS)rzWException raised when fatal syntax errors are found in the input being
    parsed.
    Nr&cCs<||_|r|d|7}t�||�|pd|_||_||_dS)a:Exception initializer.
        
        :param message: the error message from the parser
        :param filename: the path to the file that was parsed
        :param lineno: the number of the line on which the error was encountered
        :param offset: the column number where the error was encountered
        z, in z<string>N)�msg�	Exception�__init__�filename�lineno�offset)�self�messager3r4r5r"r"r#r2=s

zParseError.__init__r%)�__name__�
__module__�__qualname__�__doc__r2r"r"r"r#r8src@s�eZdZdZdd�ej��D�Zd�e��	d�Z
d-dd�Zd	d
�Zdd�Z
d
d�Zd-dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�ZdS).ra�Generator-based XML parser based on roughly equivalent code in
    Kid/ElementTree.
    
    The parsing is initiated by iterating over the parser object:
    
    >>> parser = XMLParser(StringIO('<root id="2"><child>Foo</child></root>'))
    >>> for kind, data, pos in parser:
    ...     print('%s %s' % (kind, data))
    START (QName('root'), Attrs([(QName('id'), '2')]))
    START (QName('child'), Attrs())
    TEXT Foo
    END child
    END root
    cCsg|]
\}}d||f�qS)z<!ENTITY %s "&#%d;">r"�r�namer!r"r"r#r$^�zXMLParser.<listcomp>�
�utf-8NcCs�||_||_t�|d�}d|_t|d�rd|_d|_|j|_	|j
|_|j|_
|j|_|j|_|j|_|j|_|j|_|j|_|j|_|j|_|j|_|� tj!�|�"�|j#|_$||_g|_%dS)a�Initialize the parser for the given XML input.
        
        :param source: the XML text as a file-like object
        :param filename: the name of the file, if appropriate
        :param encoding: the encoding of the file; if not specified, the
                         encoding is assumed to be ASCII, UTF-8, or UTF-16, or
                         whatever the encoding specified in the XML declaration
                         (if any)
        �}T�returns_unicodeN)&�sourcer3r�ParserCreate�buffer_text�hasattrrB�ordered_attributes�
_handle_start�StartElementHandler�_handle_end�EndElementHandler�_handle_data�CharacterDataHandler�_handle_doctype�StartDoctypeDeclHandler�_handle_start_ns�StartNamespaceDeclHandler�_handle_end_ns�EndNamespaceDeclHandler�_handle_start_cdata�StartCdataSectionHandler�_handle_end_cdata�EndCdataSectionHandler�
_handle_pi�ProcessingInstructionHandler�_handle_xml_decl�XmlDeclHandler�_handle_comment�CommentHandler�
_handle_other�DefaultHandler�SetParamEntityParsing�XML_PARAM_ENTITY_PARSING_ALWAYS�
UseForeignDTD�_build_foreign�ExternalEntityRefHandler�_queue)r6rCr3�encoding�parserr"r"r#r2bs0


zXMLParser.__init__c��fdd�}t|���t�S)z�Generator that parses the XML source, yielding markup events.
        
        :return: a markup event stream
        :raises ParseError: if the XML text is not well formed
        c
3s��zTd}d}	|sDt�j�dkrD�j�|�}|s)t�d�r&�j�dd��`d}nt|tj	�r4|�
d�}�j�|d�|sDt�j�dks�jD]}|VqGg�_|rUWdSqtjyp}zt|�}t
|�j|j|j��d}~ww)	N�F�rr�Tr@)�lenrerC�readrFr�Parse�
isinstance�six�	text_type�encode�
ExpatError�strrr3r4r5)�bufsize�done�data�event�er0�r6r"r#�	_generate�s6�

�
���z"XMLParser.parse.<locals>._generate�r�filter�	_coalesce�r6r{r"rzr#�parse�szXMLParser.parsecC�t|���S�N��iterr�rzr"r"r#�__iter__��zXMLParser.__iter__cCs |j�|�}|�t|j��dS)Nrj)r�ExternalEntityParserCreate�	ParseFiler�
_external_dtd)r6�context�base�sysid�pubidrgr"r"r#rc�szXMLParser._build_foreigncCs~|dur|��}|tur4d|vr!|��}|dt|�d}d}n|d}|dt|�}|d||f}|j�|||f�dS)Nr?rjr&�r)�_getposr�
splitlinesrlre�append)r6�kindrw�pos�linesr4r5r"r"r#�_enqueue�szXMLParser._enqueuecCs|jddfS)Nr&)r3rzr"r"r#�_getpos_unknown�r�zXMLParser._getpos_unknowncCs|j|jj|jjfSr�)r3r�CurrentLineNumber�CurrentColumnNumberrzr"r"r#r��s
�zXMLParser._getposcCs8tdd�tt|�gd�D��}|�tt|�|f�dS)NcSsg|]
\}}t|�|f�qSr")rr<r"r"r#r$�r>z+XMLParser._handle_start.<locals>.<listcomp>r�)r�zipr�r�r
r)r6r'�attribr-r"r"r#rH�s�zXMLParser._handle_startcCs|�tt|��dSr�)r�rr)r6r'r"r"r#rJ��zXMLParser._handle_endcC�|�t|�dSr��r�r�r6r)r"r"r#rL��zXMLParser._handle_datacCs|�t|||f�dSr�)r�r)r6�versionrf�
standaloner"r"r#rZ��zXMLParser._handle_xml_declcCs|�t|||f�dSr�)r�r
)r6r=r�r��has_internal_subsetr"r"r#rN�r�zXMLParser._handle_doctypecCs|�t|pd|f�dS�Nrk)r�r)r6�prefix�urir"r"r#rP�szXMLParser._handle_start_nscCs|�t|pd�dSr�)r�r)r6r�r"r"r#rR�r�zXMLParser._handle_end_nscC�|�t�dSr�)r�rrzr"r"r#rT��zXMLParser._handle_start_cdatacCr�r�)r�rrzr"r"r#rV�r�zXMLParser._handle_end_cdatacCs|�t||f�dSr�)r�r)r6�targetrwr"r"r#rX�r�zXMLParser._handle_picCr�r��r�rr�r"r"r#r\�r�zXMLParser._handle_commentc	Cs�|�d�r@zt�tj|dd��}|�t|�WdSty?|��\}}}t	�
d|||f�}t	jj|_
||_||_|�wdS)N�&rjr&z)undefined entity "%s": line %d, column %d)�
startswithrp�unichr�entities�name2codepointr�r�KeyErrorr�r�error�errors�XML_ERROR_UNDEFINED_ENTITY�coder4r5)r6r)r3r4r5r�r"r"r#r^�s
�
��zXMLParser._handle_other�NN)r8r9r:r;r�r�r(�_entitydefs�joinrrr�r2r�r�rcr�r�r�rHrJrLrZrNrPrRrTrVrXr\r^r"r"r"r#rNs2�
+ 
rcCstttt|����S)a?Parse the given XML source and return a markup stream.
    
    Unlike with `XMLParser`, the returned stream is reusable, meaning it can be
    iterated over multiple times:
    
    >>> xml = XML('<doc><elem>Foo</elem><elem>Bar</elem></doc>')
    >>> print(xml)
    <doc><elem>Foo</elem><elem>Bar</elem></doc>
    >>> print(xml.select('elem'))
    <elem>Foo</elem><elem>Bar</elem>
    >>> print(xml.select('elem/text()'))
    FooBar
    
    :param text: the XML source
    :return: the parsed XML event stream
    :raises ParseError: if the XML text is not well-formed
    )r�listrr)r)r"r"r#rsrc@s�eZdZdZegd��Zddd�Zdd�Zdd	�Zdd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)raUParser for HTML input based on the Python `HTMLParser` module.
    
    This class provides the same interface for generating stream events as
    `XMLParser`, and attempts to automatically balance tags.
    
    The parsing is initiated by iterating over the parser object:
    
    >>> parser = HTMLParser(BytesIO(u'<UL compact><LI>Foo</UL>'.encode('utf-8')), encoding='utf-8')
    >>> for kind, data, pos in parser:
    ...     print('%s %s' % (kind, data))
    START (QName('ul'), Attrs([(QName('compact'), 'compact')]))
    START (QName('li'), Attrs())
    TEXT Foo
    END li
    END ul
    )
�arear��basefont�br�col�frame�hr�img�input�isindex�link�meta�paramNcCs.tj�|�||_||_||_g|_g|_dS)aInitialize the parser for the given HTML input.
        
        :param source: the HTML text as a file-like object
        :param filename: the name of the file, if known
        :param filename: encoding of the file; ignored if the input is unicode
        N)�htmlrr2rCr3rfre�
_open_tags)r6rCr3rfr"r"r#r2-s
zHTMLParser.__init__crh)z�Generator that parses the HTML source, yielding markup events.
        
        :return: a markup event stream
        :raises ParseError: if the HTML text is not well formed
        c
3s*��jrt��j�}|�j�}n�j}z`d}d}	|sHt�j�dkrH|�|�}|s0���d}nt|t	j
�s:td����|�|sHt�j�dks"�jD]\}}}|||fVqKg�_|rs�j
}|��|D]
}tt|�|fVqeWdSqtjy�}	zd|	j|	j|	jf}
t|
�j|	j|	j��d}	~	ww)NriFrjrTz0source returned bytes, but no encoding specifiedz%s: line %d, column %d)rf�codecs�	getreaderrCrlrerm�closerorprq�UnicodeError�feedr��reverserrr��HTMLParseErrorr0r4r5rr3)�readerrCrurvrwr�r��	open_tagsr'ryr0rzr"r#r{AsB�

�	���z#HTMLParser.parse.<locals>._generater|rr"rzr#r�;szHTMLParser.parsecCr�r�r�rzr"r"r#r�br�zHTMLParser.__iter__cCs&|dur|��}|j�|||f�dSr�)r�rer�)r6r�rwr�r"r"r#r�eszHTMLParser._enqueuecCs|��\}}|j||fSr�)�getposr3)r6r4�columnr"r"r#r�jszHTMLParser._getposcCszg}|D]\}}|dur|}|�t|�t|�f�q|�tt|�t|�f�||jvr5|�tt|��dS|j�|�dSr�)	r�rr	r�r
r�_EMPTY_ELEMSrr�)r6r'r��fixed_attribr=r!r"r"r#�handle_starttagns
zHTMLParser.handle_starttagcCsP||jvr$|jr&|j��}|�tt|��|��|��krdS|jsdSdSdSr�)r�r��popr�rr�lower)r6r'�open_tagr"r"r#�
handle_endtag{s


��zHTMLParser.handle_endtagcCr�r�r�r�r"r"r#�handle_data�r�zHTMLParser.handle_datacCsF|���d�rt�t|dd�d��}nt�t|��}|�t|�dS)N�xrj�)r�r�rpr��intr�r�r6r=r)r"r"r#�handle_charref�szHTMLParser.handle_charrefcCs@z
t�tj|�}Wn
tyd|}Ynw|�t|�dS)Nz&%s;)rpr�r�r�r�r�rr�r"r"r#�handle_entityref�s�zHTMLParser.handle_entityrefcCsb|�d�r|dd�}z
|�dd�\}}Wn
ty"|}d}Ynw|�t|��|��f�dS)N�?r&rjrk)�endswith�split�
ValueErrorr�r�strip)r6rwr�r"r"r#�	handle_pi�s
�zHTMLParser.handle_picCr�r�r�r�r"r"r#�handle_comment�r�zHTMLParser.handle_commentr�r�)r8r9r:r;�	frozensetr�r2r�r�r�r�r�r�r�r�r�r�r�r"r"r"r#rs
'

rcCs<t|tj�rtttt|�dd���Stttt|�|d���S)aMParse the given HTML source and return a markup stream.
    
    Unlike with `HTMLParser`, the returned stream is reusable, meaning it can be
    iterated over multiple times:
    
    >>> html = HTML('<body><h1>Foo</h1></body>', encoding='utf-8')
    >>> print(html)
    <body><h1>Foo</h1></body>
    >>> print(html.select('h1'))
    <h1>Foo</h1>
    >>> print(html.select('h1/text()'))
    Foo
    
    :param text: the HTML source
    :return: the parsed XML event stream
    :raises ParseError: if the HTML text is not well-formed, and error recovery
                        fails
    N)rf)rorprqrr�rrr)r)rfr"r"r#r�srccsz�g}d}t|dg�D]/\}}}|tur |�|�|dur|}q|r2td�|�|fV|dd�=d}|r:|||fVqdS)z3Coalesces adjacent TEXT events into a single event.N)NNNrk)rrr�r�)�stream�textbuf�textposr�rwr�r"r"r#r~�s"�
�
��r~r�)*r;�	itertoolsrr��xml.parsersrrp�	six.movesrr�rr��genshi.corerrrr	r
rrr
rrrrrrr�
genshi.compatrr�__all__�
__docformat__rr1r�objectrrrrr~r"r"r"r#�<module>s(
45



https://t.me/RX1948 - 2025