AlkantarClanX12

Your IP : 18.189.186.247


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/lxml/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/lxml/__pycache__/sax.cpython-37.pyc

B

�|/\�$�@s�dZddlmZddlmZddlmZddlmZm	Z	ddlm
Z
mZGdd�dej�Z
d	d
�ZGdd�de�ZGd
d�de�Zdd�ZdS)aI
SAX-based adapter to copy trees from/to the Python standard library.

Use the `ElementTreeContentHandler` class to build an ElementTree from
SAX events.

Use the `ElementTreeProducer` class or the `saxify()` function to fire
the SAX events of an ElementTree against a SAX ContentHandler.

See http://codespeak.net/lxml/sax.html
�)�absolute_import)�ContentHandler)�etree)�ElementTree�
SubElement)�Comment�ProcessingInstructionc@seZdZdZdS)�SaxErrorzGeneral SAX error.
    N)�__name__�
__module__�__qualname__�__doc__�rr�;/opt/alt/python37/lib64/python3.7/site-packages/lxml/sax.pyr	sr	cCs0|ddkr$t|dd��dd��Sd|fSdS)Nr�{��})�tuple�split)�tagrrr�	_getNsTagsrc@s�eZdZdZd dd�Zdd�Zeeejd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
d!dd�Zdd�Zdd�Zd"dd�Zdd�Zdd�ZeZdS)#�ElementTreeContentHandlerz/Build an lxml ElementTree from SAX events.
    NcCsLt�|�d|_g|_g|_d|_ddgi|_i|_|dkrBtj	}||_
dS)N)r�__init__�_root�_root_siblings�_element_stack�_default_ns�_ns_mapping�
_new_mappingsrZElement�_makeelement)�selfZmakeelementrrrr&s
z"ElementTreeContentHandler.__init__cCs
t|j�S)z=Contains the generated ElementTree after parsing is finished.)rr)r rrr�
_get_etree2sz$ElementTreeContentHandler._get_etree)�doccCsdS)Nr)r �locatorrrr�setDocumentLocator8sz,ElementTreeContentHandler.setDocumentLocatorcCsdS)Nr)r rrr�
startDocument;sz'ElementTreeContentHandler.startDocumentcCsdS)Nr)r rrr�endDocument>sz%ElementTreeContentHandler.endDocumentcCsR||j|<y|j|�|�Wn tk
r>|g|j|<YnX|dkrN||_dS)N)rr�append�KeyErrorr)r �prefix�urirrr�startPrefixMappingAs
z,ElementTreeContentHandler.startPrefixMappingcCs(|j|}|��|dkr$|d|_dS)N���)r�popr)r r)Zns_uri_listrrr�endPrefixMappingJs
z*ElementTreeContentHandler.endPrefixMappingcCs4|\}}|rd|}n|jr,d|j|f}n|}|S)Nz{%s}%s)r)r Z
ns_name_tuple�ns_uri�
local_name�el_tagrrr�	_buildTagPs
z#ElementTreeContentHandler._buildTagc
Cs|�|�}|rri}y|��}Wntk
r:|��}YnXx8|D]*\}}|dr\d|}	n|d}	|||	<qBWnd}|j}
|jdkr�|�|||j�}|_|jr�t	|d�r�x|jD]}|�
|�q�W|jdd�=nt|
d|||j�}|
�|�|j�
�dS)Nrz{%s}%sr�addpreviousr,)r2�	iteritems�AttributeError�itemsrrrrr�hasattrr3rr'�clear)
r �ns_name�qname�
attributesZel_name�attrsZiter_attributesZ
name_tuple�value�	attr_nameZ
element_stack�element�siblingrrr�startElementNSZs0





z(ElementTreeContentHandler.startElementNScCs6t||�}|jdkr"|j�|�n|jd�|�dS)Nr,)rrrr'r)r �target�data�pirrr�processingInstruction{s

z/ElementTreeContentHandler.processingInstructioncCs.|j��}|�|�}||jkr*td|��dS)NzUnexpected element closed: )rr-r2rr	)r r9r:r?r1rrr�endElementNS�s


z&ElementTreeContentHandler.endElementNScCs0|rtdd�|��D��}|�d|f||�dS)NcSsg|]\}}d|f|f�qS)Nr)�.0�k�vrrr�
<listcomp>�sz:ElementTreeContentHandler.startElement.<locals>.<listcomp>)�dictr6rA)r �namer;rrr�startElement�sz&ElementTreeContentHandler.startElementcCs|�d|f|�dS)N)rF)r rLrrr�
endElement�sz$ElementTreeContentHandler.endElementcCsP|jd}y|d}|jpd||_Wn$tk
rJ|jp>d||_YnXdS)Nr,�)r�tail�
IndexError�text)r rCZlast_elementrrr�
characters�s
z$ElementTreeContentHandler.characters)N)N)N)r
rrr
rr!�propertyrr$r%r&r+r.r2rArErFrMrNrSZignorableWhitespacerrrrr#s"
	

!

rc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�ElementTreeProducerz5Produces SAX events for an element and children.
    cCsTy|��}Wntk
r$|}YnX||_||_ddlm}||_|ii�|_dS)Nr)�AttributesNSImpl)Zgetrootr5�_element�_content_handlerZxml.sax.xmlreaderrV�_attr_class�_empty_attributes)r �element_or_tree�content_handlerr?Z
attr_classrrrr�s
zElementTreeProducer.__init__cCs�|j��|j}t|d�rrg}|��}x&t|dd�tkrL|�|�|��}q(Wx"|ddd�D]}|�|i�q^W|�|i�t|d�r�|�	�}x(t|dd�tkr�|�|i�|�	�}q�W|j�
�dS)N�getpreviousrr,�getnext)rXr%rWr7r]�getattrrr'�_recursive_saxifyr^r&)r r?Zsiblingsr@rrr�saxify�s"



zElementTreeProducer.saxifycCs�|j}|j}|tks|tkrL|tkr4|�|j|j�|j}|rH|�|�dS|j	}g}||kr�x0|�
�D]$\}}	|�|�|	krh|�||	f�qhW|�
�}
|
r�i}i}x@|
D]8\}
}t
|
�}|||<|j|d|d|ddd�||<q�W|�||�}n|j}t
|�\}	}|j|	|||jdd�}x|D]\}}|�||��q"W|�|	|f||�|j}|�rd|�|�x|D]}|�||��qjW|�|	|f|�x|D]\}}|�|��q�W|j}|�r�|�|�dS)NrrT)�preferred_prefix�is_attributeF)rc)rXrrrrErBrRrPrS�nsmapr6�getr'r�_build_qnamerYrZr)r+rAr`rFr.)r r?Zparent_nsmapr\rrPZ
element_nsmapZnew_prefixesr)r/ZattribsZattr_valuesZattr_qnamesZattr_ns_namer=Z
attr_ns_tupleZsax_attributesr0r:r*rR�childrrrr`�s\


z%ElementTreeProducer._recursive_saxifycsv�dkr|S|s$|�|��kr$|}n:�fdd�|��D�}t|�dkrN|dn|rZt|�nd}|dkrj|S|d|S)Ncs$g|]\}}|dk	r|�kr|�qS)Nr)rG�pfxr*)r/rrrJsz4ElementTreeProducer._build_qname.<locals>.<listcomp>rr�:)rer6�len�min)r r/r0rdrbrcr)�
candidatesr)r/rrf�sz ElementTreeProducer._build_qnameN)r
rrr
rrar`rfrrrrrU�s
6rUcCst||���S)zlOne-shot helper to generate SAX events from an XML tree and fire
    them against a SAX ContentHandler.
    )rUra)r[r\rrrrasraN)r
�
__future__rZxml.sax.handlerr�lxmlrZ
lxml.etreerrrrZ	LxmlErrorr	rr�objectrUrarrrr�<module>
s|s