File: //lib64/python3.6/site-packages/__pycache__/drv_libxml2.cpython-36.pyc
3
VW; @ s d Z dZdZddlZddlZejd dk rXejed ZeefZ ej
dd 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 )*) xmlreadersaxutils)
feature_namespacesfeature_namespace_prefixesfeature_string_interningfeature_validationfeature_external_gesfeature_external_pesproperty_lexical_handlerproperty_declaration_handlerproperty_dom_nodeproperty_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)selflocatorr 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 argmsgseverityr 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
fatalErrorerror)r Zfatalr2 Z exceptionr r r
_reportErrors~ s
zLibXml2Reader._reportErrorsc C sJ d| _ z4t|tr tj|}n&tj|}tj|j }|j |j
}|j| jd | j
r|jtjd |jtjd |jtjd |jtj| j n|jtjd | jrtji i }n
tji }g }| jj xJ|j }|dkr| jd k r| jd nN|dkr| jd k r| jd P n*| jd k r6| jd n| jjtd P |j }|dkr| jrt!|j"