Your IP : 3.139.86.58
3
�VW�; � @ s d Z dZdZddlZddlZejd dk rXeje�d ZeefZ ej
d�d Zdd � ZneZ d
d � Zddl
T ddlmZmZ dd
lmZmZmZmZmZmZmZmZmZmZ yddlZW n( ek
r� edej� d ��Y nX G dd� dej �Z G dd� 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� c C s | d kr| S t | �d S d S )Nr )�_decoder)�s� r �#/usr/lib64/python3.6/drv_libxml2.py�_d1 s r c C s | S )Nr )r r r r r 9 s )�*)� 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 @ s8 e Zd ZdZdd� Zdd� Zdd� Zdd � Zd
d� ZdS )
�Locatorz4SAX Locator adapter for libxml2.xmlTextReaderLocatorc C s
|| _ d S )N)�_Locator__locator)�self�locatorr r r �__init__S s zLocator.__init__c C s dS )z6Return the column number where the current event ends.r ���r )r r r r �getColumnNumberV s zLocator.getColumnNumberc C s
| j j� S )z4Return the line number where the current event ends.)r Z
LineNumber)r r r r �
getLineNumberZ s zLocator.getLineNumberc C s dS )z3Return the public identifier for the current event.Nr )r r r r �getPublicId^ s zLocator.getPublicIdc C s
| j j� S )z3Return the system identifier for the current event.)r ZBaseURI)r r r r �getSystemIdb s zLocator.getSystemIdN) �__name__�
__module__�__qualname__�__doc__r r r r r r r r r r P s r c @ s\ e Zd Zdd� Zdd� Zdd� Zdd� Zd d
� Zdd� Zd
d� Z dd� Z
dd� Zdd� ZdS )�
LibXml2Readerc C s@ t jj| � d| _d| _d| _d| _d| _d | _d | _ d | _
d S )Nr r )r � XMLReaderr �_LibXml2Reader__ns�_LibXml2Reader__nspfx�_LibXml2Reader__validate�_LibXml2Reader__extparams�_LibXml2Reader__parsing�_LibXml2Reader__lex_handler�_LibXml2Reader__decl_handler�_LibXml2Reader__errors)r r r r r h s zLibXml2Reader.__init__c C s0 | j d krg | _ | j j|t|d t|��f� d S )N)r. �appendZSAXParseExceptionr )r �arg�msg�severityr r r r �
_errorHandlerw s
zLibXml2Reader._errorHandlerc C sl x`| j D ]V\}}|tjtjfkr.| jj|� q|rR|| j d d krR| jj|� q| jj|� qW d | _ d S )Nr r )r. �libxml2Z PARSER_SEVERITY_VALIDITY_WARNINGZPARSER_SEVERITY_WARNING�_err_handlerZwarning�
fatalError�error)r Zfatalr2 Z exceptionr r r �
_reportErrors~ s
zLibXml2Reader._reportErrorsc C sJ d| _ �z4t|t�r tj|�}n&tj|�}tj|j� �}|j |j
� �}|j| jd � | j
r�|jtjd� |jtjd� |jtjd� |jtj| j� n|jtjd� | jr�tji i �}n
tji �}g }| jj� �xJ|j� }|dkr�| jd k r�| jd� nN|dk�r| jd k �r| jd� P n*| jd k �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}|||<