+
    h<                        R t RtRt^ RIt^ RIt]P
                  ^ ,          ^8  d;   ]P                  ! ]4      ^ ,          t]]3t	]P                  ! R4      ^,          tR tM]t	R t^ RI5 ^ RIHtHt ^ R	IHtHtHtHtHtHtHtHtHtHt  ^ RIt ! R R]P@                  4      t  ! R R]PB                  4      t"R t#R#   ] d'    ]! R
]P>                  ! 4       ^,          ,          4      hi ; i)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.3Nutf8c                 2    V f   V # \        V 4      ^ ,          # N)_decoderss   &0/usr/lib/python3.14/site-packages/drv_libxml2.py_dr	   1   s    9HA;q>!    c                     V # r    r   s   &r   r	   r	   9   s    r
   )*)	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                   B   a  ] tR t^Pt o RtR tR tR tR tR t	Rt
V tR# )	Locatorz4SAX Locator adapter for libxml2.xmlTextReaderLocatorc                    Wn         R # r   )_Locator__locator)selflocators   &&r   __init__Locator.__init__S   s     r
   c                    R# )z6Return the column number where the current event ends.r   r   s   &r   getColumnNumberLocator.getColumnNumberV   s    	r
   c                6    V P                   P                  4       # )z4Return the line number where the current event ends.)r   
LineNumberr$   s   &r   getLineNumberLocator.getLineNumberZ   s    ~~((**r
   c                    R# )z3Return the public identifier for the current event.Nr   r$   s   &r   getPublicIdLocator.getPublicId^   s    r
   c                6    V P                   P                  4       # )z3Return the system identifier for the current event.)r   BaseURIr$   s   &r   getSystemIdLocator.getSystemIdb   s    ~~%%''r
   )	__locatorN)__name__
__module____qualname____firstlineno____doc__r    r%   r)   r,   r0   __static_attributes____classdictcell____classdict__s   @r   r   r   P   s&     >!+( (r
   r   c                   \   a  ] tR t^ft o R tR tR tR tR tR t	R t
R tR	 tR
 tRtV tR# )LibXml2Readerc                    \         P                  P                  V 4       ^ V n        ^ V n        ^ V n        ^V n        ^ V n        RV n        RV n	        RV n
        R# )    N)r   	XMLReaderr    _LibXml2Reader__ns_LibXml2Reader__nspfx_LibXml2Reader__validate_LibXml2Reader__extparams_LibXml2Reader__parsing_LibXml2Reader__lex_handler_LibXml2Reader__decl_handler_LibXml2Reader__errorsr$   s   &r   r    LibXml2Reader.__init__h   sQ    $$T*	!"r
   c           
         V P                   f   . V n         V P                   P                  V\        VR \        V4      4      34       R # r   )rH   appendSAXParseExceptionr   )r   argmsgseverityr   s   &&&&&r   _errorHandlerLibXml2Reader._errorHandlerw   sC    == DMh/D070@BC 	Dr
   c                |   V P                    F  w  r#V\        P                  \        P                  39   d   V P                  P                  V4       KG  V'       d;   W0P                   R,          ^,          J d   V P                  P                  V4       K  V P                  P                  V4       K  	  RV n         R# )   Nr#   )rH   libxml2 PARSER_SEVERITY_VALIDITY_WARNINGPARSER_SEVERITY_WARNING_err_handlerwarning
fatalErrorerror)r   fatalrO   	exceptions   &&  r   _reportErrorsLibXml2Reader._reportErrors~   s    "&--HGDD#;;= =!!)))4
 Y--*;A*>>%%00;%%++I6 #0 r
   c                   ^V n          \        V\        4      '       d   \        P                  ! V4      pMo\
        P                  ! V4      pVP                  4       pVf   VP                  4       p\        P                  ! V4      pVP                  VP                  4       4      pVP                  V P                  R4       V P                  '       d   VP                  \        P                   ^4       VP                  \        P"                  ^4       VP                  \        P$                  ^4       VP                  \        P&                  V P(                  4       M VP                  \        P                   ^ 4       V P*                  '       d   \,        P.                  ! / / 4      pM\,        P0                  ! / 4      p. pV P2                  P5                  4         VP7                  4       pV^8X  d!   V P8                  e   V P;                  ^ 4       MnV^ 8X  d"   V P8                  e   V P;                  ^ 4       EMV P8                  e   V P;                  ^4       M$V P<                  P?                  \A        R4      4       EMVPC                  4       p	V	^8X  Ed   V P*                  '       Ed   \E        VPG                  4       4      \E        VPI                  4       4      3p
\E        VPK                  4       4      p/ ;Xn&        p/ ;Vn'        p. pVPQ                  4       '       d   \E        VPK                  4       4      p\E        VPS                  4       4      pVPU                  R4      '       d^   \W        V4      ^8  d   VR,          pMRpVPY                  V4       V P2                  P[                  VV4       V P\                  '       g   K  \E        VPG                  4       4      \E        VPI                  4       4      3pWV&   VVV&   K  VP_                  4        V P2                  Pa                  WV4       VPc                  4       '       dC   V P2                  Pe                  W4       V F  pV P2                  Pg                  V4       K   	  EK  VPY                  V4       EK  \E        VPK                  4       4      p
/ ;Xn&        pVPQ                  4       '       d8   \E        VPK                  4       4      p\E        VPS                  4       4      VV&   KM  VP_                  4        V P2                  Pi                  W4       VPc                  4       '       d   V P2                  Pk                  V
4       EK  EK  V	^8X  d   V P*                  '       d   V P2                  Pe                  \E        VPG                  4       4      \E        VPI                  4       4      3\E        VPK                  4       4      4       VPm                  4        F  pV P2                  Pg                  V4       K   	  EKC  V P2                  Pk                  \E        VPK                  4       4      4       EKx  V	^8X  d6   V P2                  Po                  \E        VPS                  4       4      4       EK  V	^8X  d6   V P2                  Pq                  \E        VPS                  4       4      4       EK  V	^8X  d6   V P2                  Po                  \E        VPS                  4       4      4       EK,  V	^8X  d   V Pr                  e   V Pr                  Pu                  4        V P2                  Po                  \E        VPS                  4       4      4       V Pr                  e   V Pr                  Pw                  4        EK  EK  V	^8X  dJ   V Pr                  e)   V Py                  \E        VPK                  4       4      4       VP{                  4        EK  V	^8X  d=   V Pr                  e,   V P}                  \E        VPK                  4       4      4       EKK  EKN  V	^8X  dN   V P2                  P                  \E        VPK                  4       4      \E        VPS                  4       4      4       EK  V	^8X  dG   V Pr                  e6   V Pr                  P                  \E        VPS                  4       4      4       EK  EK  V	^
8X  d   EK  V	^8X  d   EK  V	^8X  d   EK  V	^8X  d   EK  \A        RV	,          4      hV^ 8X  d   V P2                  P                  4        VP                  4        ^ V n         R#   ^ T n         i ; i)rS   Nz"Read failed (no details available)xmlns:   NNzUnexpected node type %d)CrE   
isinstanceStringTypesrT   newTextReaderFilenamer   prepare_input_sourcegetCharacterStreamgetByteStreaminputBuffernewTextReaderr0   SetErrorHandlerrP   rD   SetParserPropPARSER_LOADDTDPARSER_DEFAULTATTRSPARSER_SUBST_ENTITIESPARSER_VALIDATErC   rA   r   AttributesNSImplAttributesImpl_cont_handlerstartDocumentReadrH   r]   rW   rY   SAXExceptionNodeTyper	   NamespaceUri	LocalNameName_attrs_qnamesMoveToNextAttributeValue
startswithlenrK   startPrefixMappingrB   MoveToElementstartElementNSIsEmptyElementendElementNSendPrefixMappingstartElement
endElementpop
charactersignorableWhitespacerF   
startCDATAendCDATAstartEntityResolveEntity	endEntityprocessingInstructioncommentendDocumentClose)r   sourcereaderstreaminputattributesNSImplattributesImplprefixesrnodeTypeeltNameeltQNameattrsqnamesnewPrefixesqnamevalue	newPrefixattNameprefixs   &&                  r   parseLibXml2Reader.parse   s   j	&+.. 66v>!66v>224>#113F++F3,,V-?-?-AB""4#5#5d;$$W%;%;A>$$W%@%@C$$W%B%B1E$$W%<%<T__M$$W%;%;Q?yyy#,#=#=b#D !*!9!9"!=H,,.KKM6==0**1-!V==0**1-==0**1-))44()MNP!??,q=yyy#%f&9&9&;#<#%f&6&6&8#9#;#%fkkm#4:<<(/%<>>(06&($88::$&v{{}$5E$&v||~$6E$//88#&u:>05b	I04I + 2 29 = $ 2 2 E E$-e!5'+|||$,')&*=*=*?'@')&*:*:*<'='?G.37O-2E'N,,.**99#-=?!0022 ..;;GM-8	 $ 2 2 C CI N .9 %OOK8"$V[[]"38::-$88::&(&7G-/-?E'N,,.**77#4!0022 ..99'B 3 ^yyy**77 !4!4!676;K;K;M8NO.0 '/llnF ..??G '5 **55b6GH]&&11"V\\^2DE^&&::2flln;MN^&&11"V\\^2DE]--5**557&&11"V\\^2DE--5**335 6 ]--5((FKKM):;((*^--5r&++-'89 6 ]&&<<6;;=)"V\\^*<> ]--5**222flln3EF 6 ^ ^]^ ''@8'KLLAv""..0LLNDNQDNs=   C	d= B<d= Dd= +A4d=  B#d= Dd= B1d= N/d= =	ec                    \        R 4      h)zDTDHandler not supportedSAXNotSupportedException)r   handlers   &&r   setDTDHandlerLibXml2Reader.setDTDHandler;  s    &'ABBr
   c                    \        R 4      h)zEntityResolver not supportedr   )r   resolvers   &&r   setEntityResolverLibXml2Reader.setEntityResolver?  s    &'EFFr
   c                    V\         8X  d   V P                  # V\        8X  d   V P                  # V\        8X  d   V P
                  # V\        8X  d   ^# V\        8X  d   V P                  # \        RV,          4      h)rS   Feature '%s' not recognized)
r   rA   r   rB   r   rC   r   r   rD   SAXNotRecognizedExceptionr   names   &&r   
getFeatureLibXml2Reader.getFeatureC  st    %%99//<<''??"))))###+,I,0-1 2 2r
   c                R   V P                   '       d   \        R V,          4      hV\        8X  d	   W n        R# V\        8X  d	   W n        R# V\        8X  d	   W n        R# V\        8X  d   V^ 8X  d   \        RV,          4      hR# V\        8X  d	   W n
        R# \        RV,          4      h)z#Cannot set feature %s while parsingzFeature '%s' not supportedr   N)rE   r   r   rA   r   rB   r   rC   r   r   rD   r   )r   r   states   &&&r   
setFeatureLibXml2Reader.setFeatureR  s    >>>* ,;=A,B C C%%I// L''#O))z./K/304 5 5  ))$+,I,0-1 2 2r
   c                    V\         8X  d   V P                  # V\        8X  d   V P                  # \	        R V,          4      h)Property '%s' not recognized)r   rF   r   rG   r   r   s   &&r   getPropertyLibXml2Reader.getPropertyg  sD    ++%%%11&&&+,J,0-1 2 2r
   c                    V\         8X  d	   W n        R# V\        8X  d   \        R V,          4      h\        RV,          4      h)zProperty '%s' not supportedr   N)r   rF   r   r   rG   r   )r   r   r   s   &&&r   setPropertyLibXml2Reader.setPropertyp  sL    ++!&11*+H+/,0 1 1 ,,J,0-1 2 2r
   )__decl_handler__errors__extparams__lex_handler__ns__nspfx	__parsing
__validateN)r3   r4   r5   r6   r    rP   r]   r   r   r   r   r   r   r   r8   r9   r:   s   @r   r=   r=   f   sA     Dl\CG22*2
2 
2r
   r=   c                      \        4       # r   )r=   r   r
   r   create_parserr   |  s
    ?r
   )$r7   
__author____version__syscodecsversion_infounicode_escape_decodestrunicoderc   lookupr   r	   xml.sax._exceptionsxml.saxr   r   xml.sax.handlerr   r   r   r   r   r   r   r   r   r   rT   ImportErrorSAXReaderNotAvailableexc_infor   r@   r=   r   r   r
   r   <module>r      s   !F 1
 
 A..z:1=J.K}}V$Q'H" K " '
 
 
L
(i (,T2I'' T2la	  L
 !79<9J!K L LLs   B? ?-C,