
    F\h/                         S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJ	r	  S r
0 4S jr0 4S jr0 4S	 jrS
 r " S S\R                  5      r " S S\	R"                  5      rSS jrg)znA library of useful helper classes to the SAX classes, for the
convenience of application and driver writers.
    N   )handler)	xmlreaderc                 Z    UR                  5        H  u  p#U R                  X#5      n M     U $ )z2Replace substrings of a string using a dictionary.)itemsreplace)sdkeyvalues       '/usr/lib/python3.13/xml/sax/saxutils.py__dict_replacer      s'    ggi
IIc!  H    c                     U R                  SS5      n U R                  SS5      n U R                  SS5      n U(       a  [        X5      n U $ )zEscape &, <, and > in a string of data.

You can escape other strings of data by passing a dictionary as
the optional entities parameter.  The keys and values must all be
strings; each key will be replaced with its corresponding value.
&&amp;>&gt;<&lt;r   r   dataentitiess     r   escaper      sF     <<W%D<<V$D<<V$Dd-Kr   c                     U R                  SS5      n U R                  SS5      n U(       a  [        X5      n U R                  SS5      $ )zUnescape &amp;, &lt;, and &gt; in a string of data.

You can unescape other strings of data by passing a dictionary as
the optional entities parameter.  The keys and values must all be
strings; each key will be replaced with its corresponding value.
r   r   r   r   r   r   r   r   s     r   unescaper   "   sB     <<$D<<$Dd-<<%%r   c                     0 UESSSS.En[        X5      n SU ;   a%  SU ;   a  SU R                  SS5      -  n U $ S	U -  n  U $ SU -  n U $ )
aw  Escape and quote an attribute value.

Escape &, <, and > in a string of data, then quote it for use as
an attribute value.  The " character will be escaped as well, if
necessary.

You can escape other strings of data by passing a dictionary as
the optional entities parameter.  The keys and values must all be
strings; each key will be replaced with its corresponding value.
z&#10;z&#13;z&#9;)
	"'z"%s"z&quot;z'%s')r   r   r   s     r   	quoteattrr$   0   sn     G(F'vFH$!D
d{$;DLLh77D
 K D=D K }Kr   c                 6  ^  T c  SS K nUR                  $ [        T [        R                  5      (       a  T $ [        T [
        R                  [
        R                  45      (       a  T $ [        T [        R                  5      (       a   " U 4S jS5      nU" 5       nS Ul	        OQ[        R                  " 5       nS Ul        T R                  Ul         T R                  Ul        T R                  Ul        [        R                   " XASSSS	9$ ! [         a     N#f = f)
Nr   c                   <   > \ rS rSr Y R                  rU 4S jrSrg) _gettextwriter.<locals>._wrapperX   c                    > [        TU5      $ N)getattr)selfnameouts     r   __getattr__,_gettextwriter.<locals>._wrapper.__getattr__Z   s    sD))r    N)__name__
__module____qualname____firstlineno__	__class__r/   __static_attributes__)r.   s   r   _wrapperr'   X   s    I* *r   r8   c                      g r*   r1   r1   r   r   <lambda> _gettextwriter.<locals>.<lambda>]   s    tr   c                      g)NTr1   r1   r   r   r:   r;   b   s    $r   xmlcharrefreplacer   T)encodingerrorsnewlinewrite_through)sysstdout
isinstanceio
TextIOBasecodecsStreamWriterStreamReaderWriter	RawIOBasecloseBufferedIOBasewritablewriteseekabletellAttributeErrorTextIOWrapper)r.   r>   rB   r8   buffers   `    r   _gettextwriterrT   G   s    
{zz#r}}%%
#++V-F-FGHH
 #r||$$	* 	* # ""$&yy	 "llFO((FK F#6$(*.0 0  		s   "D 
DDc                   p    \ rS rSrSS jrS rSS jrS rS rS r	S	 r
S
 rS rS rS rS rS rS rSrg)XMLGeneratorp   Nc                    [         R                  R                  U 5        [        X5      nUR                  U l        UR                  U l        0 /U l        U R                  S   U l	        / U l
        X l        X0l        SU l        g )NF)r   ContentHandler__init__rT   rN   _writeflush_flush_ns_contexts_current_context_undeclared_ns_maps	_encoding_short_empty_elements_pending_start_element)r,   r.   r>   short_empty_elementss       r   r[   XMLGenerator.__init__r   sn    ''-S+iiiiD $ 1 1" 5#% !%9"&+#r   c                     US   (       a5  SUS   :X  a  SUS   -   $ U R                   US      nU(       a  US-   US   -   $ US   $ )z7Builds a qualified name from a (ns_url, localname) pairr   z$http://www.w3.org/XML/1998/namespacezxml:r   :)r`   )r,   r-   prefixs      r   _qnameXMLGenerator._qname~   sY    7
 6a@Q''**473F|d1g--Awr   c                 X    U R                   (       a  U R                  S5        SU l         g g )Nr   Frd   r\   )r,   
endElements     r   _finish_pending_start_element*XMLGenerator._finish_pending_start_element   s$    &&KK*/D' 'r   c                 @    U R                  SU R                  -  5        g )Nz$<?xml version="1.0" encoding="%s"?>
)r\   rb   r,   s    r   startDocumentXMLGenerator.startDocument   s    ;' 	(r   c                 $    U R                  5         g r*   )r^   rr   s    r   endDocumentXMLGenerator.endDocument   s    r   c                     U R                   R                  U R                  R                  5       5        XR                  U'   U R                  R                  X45        g r*   )r_   appendr`   copyra   r,   ri   uris      r   startPrefixMappingXMLGenerator.startPrefixMapping   sI      !6!6!;!;!=>%+c"  ''6r   c                 F    U R                   S   U l        U R                   S	 g )NrY   )r_   r`   r,   ri   s     r   endPrefixMappingXMLGenerator.endPrefixMapping   s#     $ 1 1" 5b!r   c           	         U R                  5         U R                  SU-   5        UR                  5        H'  u  pU R                  SU< S[        U5      < 35        M)     U R                  (       a  SU l        g U R                  S5        g )Nr    =Tr   )ro   r\   r   r$   rc   rd   )r,   r-   attrsr   s       r   startElementXMLGenerator.startElement   sc    **,C$J"[[]MTKKD)E*:;< +%%*.D'KKr   c                     U R                   (       a  U R                  S5        SU l         g U R                  SU-  5        g Nz/>Fz</%s>rm   r,   r-   s     r   rn   XMLGenerator.endElement   s/    &&KK*/D'KK$'r   c           	         U R                  5         U R                  SU R                  U5      -   5        U R                   H<  u  pEU(       a  U R                  SU< SU< S35        M(  U R                  SU-  5        M>     / U l        UR	                  5        H6  u  pU R                  SU R                  U5      < S[        U5      < 35        M8     U R                  (       a  SU l        g U R                  S	5        g )
Nr   z xmlns:z="r"   z xmlns="%s"r   r   Tr   )ro   r\   rj   ra   r   r$   rc   rd   )r,   r-   qnamer   ri   r|   r   s          r   startElementNSXMLGenerator.startElementNS   s    **,C$++d++,33KF<=MC/0	 4
 $& "[[]MTKKDKK$5y7GHI +%%*.D'KKr   c                     U R                   (       a  U R                  S5        SU l         g U R                  SU R                  U5      -  5        g r   )rd   r\   rj   r,   r-   r   s      r   endElementNSXMLGenerator.endElementNS   s9    &&KK*/D'KK$++d"334r   c                     U(       aU  U R                  5         [        U[        5      (       d  [        XR                  5      nU R	                  [        U5      5        g g r*   )ro   rD   strrb   r\   r   r,   contents     r   
charactersXMLGenerator.characters   sA    ..0gs++g~~6KKw(	 r   c                     U(       aL  U R                  5         [        U[        5      (       d  [        XR                  5      nU R	                  U5        g g r*   )ro   rD   r   rb   r\   r   s     r   ignorableWhitespace XMLGenerator.ignorableWhitespace   s=    ..0gs++g~~6KK 	 r   c                 X    U R                  5         U R                  SU< SU< S35        g )Nz<?r   z?>)ro   r\   r,   targetr   s      r   processingInstruction"XMLGenerator.processingInstruction   s    **,6401r   )r`   rb   r^   r_   rd   rc   ra   r\   )Nz
iso-8859-1F)F)r2   r3   r4   r5   r[   rj   ro   rs   rv   r}   r   r   rn   r   r   r   r   r   r7   r1   r   r   rV   rV   p   sH    
,"0(7
"($5)!2r   rV   c                       \ rS rSrSrS!S jrS rS rS rS r	S	 r
S
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r S r!g)"XMLFilterBase   aE  This class is designed to sit between an XMLReader and the
client application's event handlers.  By default, it does nothing
but pass requests up to the reader and events on to the handlers
unmodified, but subclasses can override specific methods to modify
the event stream or the configuration requests as they pass
through.Nc                 N    [         R                  R                  U 5        Xl        g r*   )r   	XMLReaderr[   _parentr,   parents     r   r[   XMLFilterBase.__init__   s    $$T*r   c                 :    U R                   R                  U5        g r*   )_err_handlererrorr,   	exceptions     r   r   XMLFilterBase.error   s    	*r   c                 :    U R                   R                  U5        g r*   )r   
fatalErrorr   s     r   r   XMLFilterBase.fatalError   s    $$Y/r   c                 :    U R                   R                  U5        g r*   )r   warningr   s     r   r   XMLFilterBase.warning   s    !!),r   c                 :    U R                   R                  U5        g r*   )_cont_handlersetDocumentLocator)r,   locators     r   r    XMLFilterBase.setDocumentLocator   s    --g6r   c                 8    U R                   R                  5         g r*   )r   rs   rr   s    r   rs   XMLFilterBase.startDocument   s    ((*r   c                 8    U R                   R                  5         g r*   )r   rv   rr   s    r   rv   XMLFilterBase.endDocument  s    &&(r   c                 :    U R                   R                  X5        g r*   )r   r}   r{   s      r   r}    XMLFilterBase.startPrefixMapping  s    --f:r   c                 :    U R                   R                  U5        g r*   )r   r   r   s     r   r   XMLFilterBase.endPrefixMapping  s    ++F3r   c                 :    U R                   R                  X5        g r*   )r   r   )r,   r-   r   s      r   r   XMLFilterBase.startElement      ''4r   c                 :    U R                   R                  U5        g r*   )r   rn   r   s     r   rn   XMLFilterBase.endElement  s    %%d+r   c                 <    U R                   R                  XU5        g r*   )r   r   )r,   r-   r   r   s       r   r   XMLFilterBase.startElementNS  s    ))$u=r   c                 :    U R                   R                  X5        g r*   )r   r   r   s      r   r   XMLFilterBase.endElementNS  r   r   c                 :    U R                   R                  U5        g r*   )r   r   r   s     r   r   XMLFilterBase.characters  s    %%g.r   c                 :    U R                   R                  U5        g r*   )r   r   )r,   charss     r   r   !XMLFilterBase.ignorableWhitespace  s    ..u5r   c                 :    U R                   R                  X5        g r*   )r   r   r   s      r   r   #XMLFilterBase.processingInstruction  s    00>r   c                 :    U R                   R                  U5        g r*   )r   skippedEntityr   s     r   r   XMLFilterBase.skippedEntity   s    ((.r   c                 <    U R                   R                  XU5        g r*   )_dtd_handlernotationDecl)r,   r-   publicIdsystemIds       r   r   XMLFilterBase.notationDecl%  s    &&tx@r   c                 <    U R                   R                  XX45        g r*   )r   unparsedEntityDecl)r,   r-   r   r   ndatas        r   r    XMLFilterBase.unparsedEntityDecl(  s    ,,TXMr   c                 8    U R                   R                  X5      $ r*   )_ent_handlerresolveEntity)r,   r   r   s      r   r   XMLFilterBase.resolveEntity-  s      ..xBBr   c                    U R                   R                  U 5        U R                   R                  U 5        U R                   R                  U 5        U R                   R	                  U 5        U R                   R                  U5        g r*   )r   setContentHandlersetErrorHandlersetEntityResolversetDTDHandlerparse)r,   sources     r   r   XMLFilterBase.parse2  s\    &&t,$$T*&&t,""4(6"r   c                 :    U R                   R                  U5        g r*   )r   	setLocale)r,   locales     r   r   XMLFilterBase.setLocale9  s    v&r   c                 8    U R                   R                  U5      $ r*   )r   
getFeaturer   s     r   r   XMLFilterBase.getFeature<  s    ||&&t,,r   c                 :    U R                   R                  X5        g r*   )r   
setFeature)r,   r-   states      r   r   XMLFilterBase.setFeature?  s    ,r   c                 8    U R                   R                  U5      $ r*   )r   getPropertyr   s     r   r   XMLFilterBase.getPropertyB  s    ||''--r   c                 :    U R                   R                  X5        g r*   )r   setProperty)r,   r-   r   s      r   r   XMLFilterBase.setPropertyE  s      -r   c                     U R                   $ r*   r   rr   s    r   	getParentXMLFilterBase.getParentJ  s    ||r   c                     Xl         g r*   r   r   s     r   	setParentXMLFilterBase.setParentM  s    r   r   r*   )"r2   r3   r4   r5   __doc__r[   r   r   r   r   rs   rv   r}   r   r   rn   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r7   r1   r   r   r   r      s    +0-
7+);45,>5/6?/
AN
C
#'--..
r   r   c                    [        U [        R                  5      (       a  [        R                  " U 5      n [        U [        5      (       a  [
        R                  " U 5      n O[        U S5      (       a  U n[
        R                  " 5       n [        UR                  S5      [        5      (       a  U R                  U5        OU R                  U5        [        US5      (       a:  [        UR                  [        5      (       a  U R                  UR                  5        U R                  5       Gc+  U R                  5       Gc  U R                  5       n[        R                   R#                  [        R                   R%                  U5      5      n[        R                   R'                  XC5      n[        R                   R)                  U5      (       a  U R                  U5        [+        US5      nO[U R                  [,        R.                  R1                  X5      5        [,        R2                  R5                  U R                  5       5      nU R                  U5        U $ )z~This function takes an InputSource and an optional base URL and
returns a fully resolved InputSource object ready for reading.readr   r-   rb)rD   osPathLikefspathr   r   InputSourcehasattrr  setCharacterStreamsetByteStreamr-   setSystemIdgetCharacterStreamgetByteStreamgetSystemIdpathdirnamenormpathjoinisfileopenurllibr   urljoinrequesturlopen)r   basefsysidbaseheadsysidfilenames         r   prepare_input_sourcer$  R  s    &"++&&6"&#&&v.		 	 &&(affQi%%%%a(  #1f*QVVS"9"9qvv&  "*v/C/C/E/M""$77??277#3#3D#9:X577>>-((}-]D)Av||33D@A&&v'9'9';<AQMr   ) )r  r
  urllib.parser  urllib.requestrE   rG   r%  r   r   r   r   r   r$   rT   rZ   rV   r   r   r$  r1   r   r   <module>r(     sv   
 ( ' 	        &   .'0Rp27)) p2fkI'' k^r   