<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
3
VW;                 @   s  d Z dZdZddlZddlZejd dk rXejed ZeefZ	ej
dd Zdd	 ZneZ	d
d	 ZddlT ddlmZmZ ddlmZmZmZmZmZmZmZmZmZmZ yddlZW n( ek
r   edej d  Y nX G dd dej Z G dd dej!Z"dd Z#dS )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>z0.3    N   utf8   c             C   s   | d kr| 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 Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )Locatorz4SAX Locator adapter for libxml2.xmlTextReaderLocatorc             C   s
   || _ d S )N)_Locator__locator)selflocatorr   r   r   __init__S   s    zLocator.__init__c             C   s   dS )z6Return the column number where the current event ends.r   r   )r   r   r   r   getColumnNumberV   s    zLocator.getColumnNumberc             C   s
   | j j S )z4Return the line number where the current event ends.)r   Z
LineNumber)r   r   r   r   getLineNumberZ   s    zLocator.getLineNumberc             C   s   dS )z3Return the public identifier for the current event.Nr   )r   r   r   r   getPublicId^   s    zLocator.getPublicIdc             C   s
   | j j S )z3Return the system identifier for the current event.)r   ZBaseURI)r   r   r   r   getSystemIdb   s    zLocator.getSystemIdN)	__name__
__module____qualname____doc__r   r   r   r   r    r   r   r   r   r   P   s   r   c               @   s\   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd ZdS )LibXml2Readerc             C   s@   t jj|  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    zLibXml2Reader.__init__c             C   s0   | j d krg | _ | j j|t|d t|f d S )N)r.   appendZSAXParseExceptionr   )r   argmsgseverityr   r   r   r   _errorHandlerw   s
    
zLibXml2Reader._errorHandlerc             C   sl   x`| j D ]V\}}|tjtjfkr.| jj| q|rR|| j d d krR| jj| q| jj| qW d | _ d S )Nr   r   )r.   libxml2Z PARSER_SEVERITY_VALIDITY_WARNINGZPARSER_SEVERITY_WARNING_err_handlerZwarning
fatalErrorerror)r   Zfatalr2   Z	exceptionr   r   r   _reportErrors~   s    
zLibXml2Reader._reportErrorsc             C   sJ  d| _ z4t|tr tj|}n&tj|}tj|j }|j	|j
 }|j| jd  | jr|jtjd |jtjd |jtjd |jtj| j n|jtjd | jrtji i }n
tji }g }| jj  xJ|j }|dkr| jd k	r| jd nN|dkr| jd k	r| jd P n*| jd k	r6| jd n| jjtd P |j  }|dkr| jrt!|j" t!|j# f}	t!|j$ }
i  |_%}i  |_&}g }x|j' r>t!|j$ }t!|j( }|j)drt*|dkr|dd  }nd }|j+| | jj,|| | j-sqt!|j" t!|j# f}|||< |||< qW |j.  | jj/|	|
| |j0 r| jj1|	|
 x&|D ]}| jj2| qvW n
|j+| npt!|j$ }	i  |_%}x,|j' rt!|j$ }t!|j( ||< qW |j.  | jj3|	| |j0 r| jj4|	 q|dkr| jrj| jj1t!|j" t!|j# ft!|j$  x4|j5 D ]}| jj2| qRW n| jj4t!|j$  q|dkr| jj6t!|j(  q|d	kr| jj7t!|j(  q|d
kr| jj6t!|j(  q|dkr,| j8d k	r | j8j9  | jj6t!|j(  | j8d k	r| j8j:  q|dkr^| j8d k	rT| j;t!|j$  |j<  q|dkr| j8d k	r| j=t!|j$  q|dkr| jj>t!|j$ t!|j(  q|dkr| j8d k	r| j8j?t!|j(  q|dkrq|dkrq|dkrq|dkrqtd| qW |dkr2| jj@  |jA  W d d| _ X d S )Nr   r   z"Read failed (no details available)Zxmlns         r                     
         zUnexpected node type %d)Br+   
isinstanceStringTypesr4   ZnewTextReaderFilenamer   Zprepare_input_sourceZinputBufferZgetByteStreamZnewTextReaderr    ZSetErrorHandlerr3   r*   ZSetParserPropZPARSER_LOADDTDZPARSER_DEFAULTATTRSZPARSER_SUBST_ENTITIESZPARSER_VALIDATEr)   r'   r   ZAttributesNSImplZAttributesImplZ_cont_handlerZstartDocumentZReadr.   r8   r5   r6   ZSAXExceptionZNodeTyper	   ZNamespaceUriZ	LocalNameNameZ_attrsZ_qnamesZMoveToNextAttributeZValue
startswithlenr/   ZstartPrefixMappingr(   ZMoveToElementZstartElementNSZIsEmptyElementZendElementNSZendPrefixMappingZstartElementZ
endElementpopZ
charactersZignorableWhitespacer,   Z
startCDATAZendCDATAZstartEntityZResolveEntityZ	endEntityZprocessingInstructionZcommentZendDocumentZClose)r   sourcereaderinputZattributesNSImplZattributesImplprefixesrZnodeTypeZeltNameZeltQNameZattrsZqnamesZnewPrefixesZqnamevalueZ	newPrefixZattNameprefixr   r   r   parse   s    



































zLibXml2Reader.parsec             C   s   t dd S )NzDTDHandler not supported)SAXNotSupportedException)r   Zhandlerr   r   r   setDTDHandler8  s    zLibXml2Reader.setDTDHandlerc             C   s   t dd S )NzEntityResolver not supported)rS   )r   Zresolverr   r   r   setEntityResolver<  s    zLibXml2Reader.setEntityResolverc             C   sT   |t kr| jS |tkr| jS |tkr*| jS |tkr6dS |tkrD| jS t	d| d S )Nr   zFeature '%s' not recognized)
r   r'   r   r(   r   r)   r   r   r*   SAXNotRecognizedException)r   namer   r   r   
getFeature@  s    zLibXml2Reader.getFeaturec             C   s   | j rtd| |tkr"|| _nZ|tkr2|| _nJ|tkrB|| _n:|tkr`|dkr|td| n|t	krp|| _
ntd| d S )Nz#Cannot set feature %s while parsingr   zFeature '%s' not supportedzFeature '%s' not recognized)r+   rS   r   r'   r   r(   r   r)   r   r   r*   rV   )r   rW   stater   r   r   
setFeatureO  s"    
zLibXml2Reader.setFeaturec             C   s,   |t kr| jS |tkr| jS td| d S )NzProperty '%s' not recognized)r   r,   r   r-   rV   )r   rW   r   r   r   getPropertyd  s    zLibXml2Reader.getPropertyc             C   s<   |t kr|| _n(|tkr,td| || _ntd| d S )NzProperty '%s' not supportedzProperty '%s' not recognized)r   r,   r   rS   r-   rV   )r   rW   rP   r   r   r   setPropertym  s    zLibXml2Reader.setPropertyN)r!   r"   r#   r   r3   r8   rR   rT   rU   rX   rZ   r[   r\   r   r   r   r   r%   f   s    ,	r%   c               C   s   t  S )N)r%   r   r   r   r   create_parsery  s    r]   )$r$   
__author____version__syscodecsversion_infounicode_escape_decodestrZunicoderF   lookupr   r	   Zxml.sax._exceptionsZxml.saxr   r   Zxml.sax.handlerr   r   r   r   r   r   r   r   r   r   r4   ImportErrorZSAXReaderNotAvailableexc_infor   r&   r%   r]   r   r   r   r   <module>#   s0   
0  