Your IP : 3.139.86.58


Current Path : /usr/lib64/python3.6/site-packages/__pycache__/
Upload File :
Current File : //usr/lib64/python3.6/site-packages/__pycache__/drv_libxml2.cpython-36.pyc

3

�VW�;�@sdZdZdZddlZddlZejddkrXeje�dZeefZ	ej
d�dZdd	�ZneZ	d
d	�Zddl
TddlmZmZdd
lmZmZmZmZmZmZmZmZmZmZyddlZWn(ek
r�edej�d��YnXGdd�dej �Z Gdd�dej!�Z"dd�Z#dS)a� A SAX2 driver for libxml2, on top of it's XmlReader API

USAGE
    # put this file (drv_libxml2.py) in PYTHONPATH
    import xml.sax
    reader = xml.sax.make_parser(["drv_libxml2"])
    # ...and the rest is standard python sax.

CAVEATS
    - Lexical handlers are supported, except for start/endEntity
      (waiting for XmlReader.ResolveEntity) and start/endDTD
    - Error callbacks are not exactly synchronous, they tend
      to be invoked before the corresponding content callback,
      because the underlying reader interface parses
      data by chunks of 512 bytes
    
TODO
    - search for TODO
    - some ErrorHandler events (warning)
    - some ContentHandler events (setDocumentLocator, skippedEntity)
    - EntityResolver (using libxml2.?)
    - DTDHandler (if/when libxml2 exposes such node types)
    - DeclHandler (if/when libxml2 exposes such node types)
    - property_xml_string?
    - feature_string_interning?
    - Incremental parser
    - additional performance tuning:
      - one might cache callbacks to avoid some name lookups
      - one might implement a smarter way to pass attributes to startElement
        (some kind of lazy evaluation?)
      - there might be room for improvement in start/endPrefixMapping
      - other?

u Stéphane Bidoul <sbi@skynet.be>z0.3�N��utf8�cCs|dkr|St|�dSdS)Nr)�_decoder)�s�r�#/usr/lib64/python3.6/drv_libxml2.py�_d1sr	cCs|S)Nr)rrrrr	9s)�*)�	xmlreader�saxutils)
�feature_namespaces�feature_namespace_prefixes�feature_string_interning�feature_validation�feature_external_ges�feature_external_pes�property_lexical_handler�property_declaration_handler�property_dom_node�property_xml_stringz+libxml2 not available: import error was: %sc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�Locatorz4SAX Locator adapter for libxml2.xmlTextReaderLocatorcCs
||_dS)N)�_Locator__locator)�self�locatorrrr�__init__SszLocator.__init__cCsdS)z6Return the column number where the current event ends.r���r)rrrr�getColumnNumberVszLocator.getColumnNumbercCs
|jj�S)z4Return the line number where the current event ends.)rZ
LineNumber)rrrr�
getLineNumberZszLocator.getLineNumbercCsdS)z3Return the public identifier for the current event.Nr)rrrr�getPublicId^szLocator.getPublicIdcCs
|jj�S)z3Return the system identifier for the current event.)rZBaseURI)rrrr�getSystemIdbszLocator.getSystemIdN)	�__name__�
__module__�__qualname__�__doc__rrrrr rrrrrPsrc@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�
LibXml2ReadercCs@tjj|�d|_d|_d|_d|_d|_d|_d|_	d|_
dS)Nrr)r�	XMLReaderr�_LibXml2Reader__ns�_LibXml2Reader__nspfx�_LibXml2Reader__validate�_LibXml2Reader__extparams�_LibXml2Reader__parsing�_LibXml2Reader__lex_handler�_LibXml2Reader__decl_handler�_LibXml2Reader__errors)rrrrrhszLibXml2Reader.__init__cCs0|jdkrg|_|jj|t|dt|��f�dS)N)r.�appendZSAXParseExceptionr)r�arg�msg�severityrrrr�
_errorHandlerws

zLibXml2Reader._errorHandlercCslx`|jD]V\}}|tjtjfkr.|jj|�q|rR||jddkrR|jj|�q|jj|�qWd|_dS)Nrr)r.�libxml2Z PARSER_SEVERITY_VALIDITY_WARNINGZPARSER_SEVERITY_WARNING�_err_handlerZwarning�
fatalError�error)rZfatalr2Z	exceptionrrr�
_reportErrors~s
zLibXml2Reader._reportErrorscCsJd|_�z4t|t�r tj|�}n&tj|�}tj|j��}|j	|j
��}|j|jd�|j
r�|jtjd�|jtjd�|jtjd�|jtj|j�n|jtjd�|jr�tjii�}n
tji�}g}|jj��xJ|j�}|dkr�|jdk	r�|jd�nN|dk�r|jdk	�r|jd�Pn*|jdk	�r6|jd�n|jjtd��P|j �}|dk�r|j�r�t!|j"��t!|j#��f}	t!|j$��}
i|_%}i|_&}g}
x�|j'��r>t!|j$��}t!|j(��}|j)d��rt*|�dk�r�|dd�}nd}|
j+|�|jj,||�|j-�s�q�t!|j"��t!|j#��f}|||<|||<�q�W|j.�|jj/|	|
|�|j0��r�|jj1|	|
�x&|
D]}|jj2|��qvWn
|j+|
�npt!|j$��}	i|_%}x,|j'��r�t!|j$��}t!|j(��||<�q�W|j.�|jj3|	|�|j0��r|jj4|	�q�|dk�r�|j�rj|jj1t!|j"��t!|j#��ft!|j$���x4|j5�D]}|jj2|��qRWn|jj4t!|j$���q�|dk�r�|jj6t!|j(���q�|d	k�r�|jj7t!|j(���q�|d
k�r�|jj6t!|j(���q�|dk�r,|j8dk	�r|j8j9�|jj6t!|j(���|j8dk	�r|j8j:�q�|dk�r^|j8dk	�rT|j;t!|j$���|j<�q�|dk�r�|j8dk	�r|j=t!|j$���q�|d
k�r�|jj>t!|j$��t!|j(���q�|dk�r�|j8dk	�r|j8j?t!|j(���q�|dk�r�q�|dk�r�q�|dk�rq�|dk�rq�td|��q�W|dk�r2|jj@�|jA�Wdd|_XdS)Nrrz"Read failed (no details available)Zxmlns���r�
������
��zUnexpected node type %d)Br+�
isinstance�StringTypesr4ZnewTextReaderFilenamerZprepare_input_sourceZinputBufferZ
getByteStreamZ
newTextReaderr ZSetErrorHandlerr3r*Z
SetParserPropZPARSER_LOADDTDZPARSER_DEFAULTATTRSZPARSER_SUBST_ENTITIESZPARSER_VALIDATEr)r'rZAttributesNSImplZAttributesImplZ
_cont_handlerZ
startDocumentZReadr.r8r5r6ZSAXExceptionZNodeTyper	ZNamespaceUriZ	LocalName�NameZ_attrsZ_qnamesZMoveToNextAttributeZValue�
startswith�lenr/ZstartPrefixMappingr(Z
MoveToElementZstartElementNSZIsEmptyElementZendElementNSZendPrefixMappingZstartElementZ
endElement�popZ
charactersZignorableWhitespacer,Z
startCDATAZendCDATAZstartEntityZ
ResolveEntityZ	endEntityZprocessingInstructionZcommentZendDocumentZClose)r�source�reader�inputZattributesNSImplZattributesImpl�prefixes�rZnodeTypeZeltNameZeltQNameZattrsZqnamesZnewPrefixesZqname�valueZ	newPrefixZattName�prefixrrr�parse�s�



































zLibXml2Reader.parsecCstd��dS)NzDTDHandler not supported)�SAXNotSupportedException)rZhandlerrrr�
setDTDHandler8szLibXml2Reader.setDTDHandlercCstd��dS)NzEntityResolver not supported)rS)rZresolverrrr�setEntityResolver<szLibXml2Reader.setEntityResolvercCsT|tkr|jS|tkr|jS|tkr*|jS|tkr6dS|tkrD|jSt	d|��dS)NrzFeature '%s' not recognized)
r
r'rr(rr)rrr*�SAXNotRecognizedException)r�namerrr�
getFeature@szLibXml2Reader.getFeaturecCs�|jrtd|��|tkr"||_nZ|tkr2||_nJ|tkrB||_n:|tkr`|dkr|td|��n|t	krp||_
ntd|��dS)Nz#Cannot set feature %s while parsingrzFeature '%s' not supportedzFeature '%s' not recognized)r+rSr
r'rr(rr)rrr*rV)rrW�staterrr�
setFeatureOs"
zLibXml2Reader.setFeaturecCs,|tkr|jS|tkr|jStd|��dS)NzProperty '%s' not recognized)rr,rr-rV)rrWrrr�getPropertydszLibXml2Reader.getPropertycCs<|tkr||_n(|tkr,td|��||_ntd|��dS)NzProperty '%s' not supportedzProperty '%s' not recognized)rr,rrSr-rV)rrWrPrrr�setPropertymszLibXml2Reader.setPropertyN)
r!r"r#rr3r8rRrTrUrXrZr[r\rrrrr%fs,	r%cCst�S)N)r%rrrr�
create_parserysr])$r$�
__author__�__version__�sys�codecs�version_info�unicode_escape_decode�strZunicoderF�lookuprr	Zxml.sax._exceptionsZxml.saxrrZxml.sax.handlerr
rrrrrrrrrr4�ImportErrorZSAXReaderNotAvailable�exc_inforr&r%r]rrrr�<module>#s0
0

?>