
    `i\                        S r SSKJr  SSKJrJr  SSKJr  SSKJ	r	  SSK
Jr  SSKr " S S	\5      r " S
 S5      rS\SSSS4S jrSS jrS rS rSS jr              SS jr " S S\5      r  SS jr\S:X  ak  SSKrSSKr\R6                  R8                  r\R:                  R8                  r\R<                  SS u  r\ " \5      rS r! \" \\\!\"S9r#\S:X  a
  \!" / \#5        ggg! \$ a     gf = f) z:Makes working with XML feel like you are working with JSON    )expat)XMLGeneratorescape)AttributesImpl)StringIO)isgeneratorNc                       \ rS rSrSrg)ParsingInterrupted    N)__name__
__module____qualname____firstlineno____static_attributes__r       H/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/xmltodict.pyr
   r
      s    r   r
   c                   x    \ rS rSrSS SSSSSS	\SS
S	S	S4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g	)_DictSAXHandler   r   c                      gNTr   )argss    r   <lambda>_DictSAXHandler.<lambda>   s    Dr   T@#textF N:#commentc                     / U l         / U l        / U l        S U l        Xl        X0l        X l        X@l        XPl        X`l	        Xpl
        Xl        Xl        Xl        Xl        Xl        U	" 5       U l        Xl        Xl        g N)pathstackdataitem
item_depthxml_attribsitem_callbackattr_prefix	cdata_keyforce_cdatacdata_separatorpostprocessordict_constructorstrip_whitespacenamespace_separator
namespacesnamespace_declarations
force_listcomment_key)selfr'   r)   r(   r*   r+   r,   r-   r.   r/   r0   r1   r2   r4   r5   s                  r   __init___DictSAXHandler.__init__   s{    " 	
		$&*&"&.* 0 0#6 $&6&8#$&r   c                 
   U R                   c  U$ UR                  U R                  5      nUS:X  a  U$ US U XS-   S  pC U R                   U   nU(       d  U$ U R                  R	                  XT45      $ ! [         a    Un N3f = f)N   )r2   rfindr1   KeyErrorjoin)r6   	full_namei	namespacenameshort_namespaces         r   _build_name_DictSAXHandler._build_name5   s    ??"OOD4457#BQ-Q344	("ooi8O K++00/1HII  	('O	(s   A3 3BBc           	      ~    [        U[        5      (       a  U$ U R                  [        USS S2   USS S2   5      5      $ )Nr      r;   )
isinstancedictr/   zip)r6   attrss     r   _attrs_to_dict_DictSAXHandler._attrs_to_dictE   s@    eT""L$$Sqt!teADqDk%BCCr   c                 2    X R                   U=(       d    S'   g )Nr   )r3   )r6   prefixuris      r   startNamespaceDecl"_DictSAXHandler.startNamespaceDeclJ   s    47##FLb1r   c                 T   U R                  U5      nU R                  U5      nU R                  (       a;  U(       d  U R                  5       nU R                  US'   U R                  5       U l        U R                  R                  X2=(       d    S 45        [        U R                  5      U R                  :  a  U R                  R                  U R                  U R                  45        U R                  (       a  / nUR                  5        Hn  u  pVU R                  U R                  U5      -   nU R                  (       a  U R                  U R                  XV5      nOXV4nU(       d  M]  UR                  U5        Mp     U R                  U5      nOS nU=(       d    S U l	        / U l
        g g )Nxmlns)rD   rL   r3   r/   r#   appendlenr'   r$   r&   r%   r(   itemsr*   r.   )r6   r?   rK   rB   attr_entrieskeyvalueentrys           r   startElement_DictSAXHandler.startElementM   sJ   	*##E*&&--/!88E'N*.*?*?*AD'		$./tyy>T__,JJtyy$))45!"'++-JC**4+;+;C+@@C)) $ 2 2499c I!$u$++E2 #0 --l;DIDI! -r   c                    U R                  U5      n[        U R                  5      U R                  :X  a  U R                  nUc8  U R
                  (       d  S O$U R                  R                  U R
                  5      nU R                  U R                  U5      nU(       d  [        eU R                  (       a(  U R                  R                  5       u  U l        U l        OS U l        / U l        U R                  R                  5         g U R                  (       Ga6  U R
                  (       d  S O$U R                  R                  U R
                  5      nU R                  nU R                  R                  5       u  U l        U l        U R                  (       a   U(       a  UR                  5       =(       d    S nU(       a)  U R                  X%5      (       a  Uc  U R                  5       nUbE  U(       a  U R!                  X0R"                  U5        U R!                  U R                  X#5      U l        O0U R!                  U R                  X%5      U l        OS U l        / U l        U R                  R                  5         g r"   )rD   rV   r#   r'   r&   r%   r-   r>   r)   r
   r$   popr0   strip_should_force_cdatar/   	push_datar+   )r6   r?   rB   r&   should_continuer%   s         r   
endElement_DictSAXHandler.endElementh   s   	* tyy>T__,99D|$(II!1166tyyA  #00DAO"(( zz'+zz~~'7$	49 		IIMMO::: $		D--22499= 99D#'::>>#3 DIty$$zz|+t00<<,,.NN4> NN499dA	 NN499dA	DIDI		r   c                 n    U R                   (       d	  U/U l         g U R                   R                  U5        g r"   )r%   rU   r6   r%   s     r   
characters_DictSAXHandler.characters   s$    yyDIIIT"r   c                     U R                   (       a  UR                  5       nU R                  U R                  U R                  U5      U l        g r"   )r0   r`   rb   r&   r5   rg   s     r   comments_DictSAXHandler.comments   s4      ::<DNN499d.>.>E	r   c                 \   U R                   b%  U R                  U R                  X#5      nUc  U$ Uu  p#Uc  U R                  5       n X   n[        U[        5      (       a  UR                  U5        U$ XS/X'    U$ ! [         a&    U R                  X#5      (       a  U/X'    U$ X1U'    U$ f = fr"   )r.   r#   r/   rH   listrU   r=   _should_force_list)r6   r&   rY   r%   resultrZ   s         r   rb   _DictSAXHandler.push_data   s    )''		3=F~IC<((*D
	!IE%&&T"  #M	   	!&&s11!F	  !S		!s   *A; 3A; ;%B+#B+*B+c                     U R                   (       d  g[        U R                   [        5      (       a  U R                   $  XR                   ;   $ ! [         a"    U R                  U R                  S S X5      s $ f = fNFr:   )r4   rH   bool	TypeErrorr#   r6   rY   rZ   s      r   ro   "_DictSAXHandler._should_force_list   sc    doot,,??"	?//)) 	???499Sb>3>>	?   A )A98A9c                     U R                   (       d  g[        U R                   [        5      (       a  U R                   $  XR                   ;   $ ! [         a"    U R                  U R                  S S X5      s $ f = frs   )r,   rH   rt   ru   r#   rv   s      r   ra   #_DictSAXHandler._should_force_cdata   sp    d&&--###	@**** 	@##DIIcrNC??	@rx   )r*   r+   r-   r5   r%   r/   r,   r4   r&   r)   r'   r3   r1   r2   r#   r.   r$   r0   r(   )r   r   r   r   rI   r7   rD   rL   rQ   r\   rd   rh   rk   rb   ro   ra   r   r   r   r   r   r      sk     (#'JJ D
86)V#F
*?@r   r   Fr   Tc                    [        S	SU0UD6n[        U [        5      (       a  U=(       d    SnU R                  U5      n U(       d  SnUR                  " UU5      n	SU	l        UR                  U	l        UR                  U	l	        UR                  U	l        UR                  U	l        U(       a  UR                  U	l        SU	l        U(       a	  S n
Xl        [%        U S5      (       a  U	R'                  U 5        UR,                  $ [)        U 5      (       a9  U  H  nU	R+                  US5        M     U	R+                  SS5        UR,                  $ U	R+                  U S5        UR,                  $ )
aS  Parse the given XML input and convert it into a dictionary.

`xml_input` can either be a `string`, a file-like object, or a generator of strings.

If `xml_attribs` is `True`, element attributes are put in the dictionary
among regular child elements, using `@` as a prefix to avoid collisions. If
set to `False`, they are just ignored.

Simple example::

    >>> import xmltodict
    >>> doc = xmltodict.parse("""
    ... <a prop="x">
    ...   <b>1</b>
    ...   <b>2</b>
    ... </a>
    ... """)
    >>> doc['a']['@prop']
    'x'
    >>> doc['a']['b']
    ['1', '2']

If `item_depth` is `0`, the function returns a dictionary for the root
element (default behavior). Otherwise, it calls `item_callback` every time
an item at the specified depth is found and returns `None` in the end
(streaming mode).

The callback function receives two parameters: the `path` from the document
root to the item (name-attribs pairs), and the `item` (dict). If the
callback's return value is false-ish, parsing will be stopped with the
:class:`ParsingInterrupted` exception.

Streaming example::

    >>> def handle(path, item):
    ...     print('path:%s item:%s' % (path, item))
    ...     return True
    ...
    >>> xmltodict.parse("""
    ... <a prop="x">
    ...   <b>1</b>
    ...   <b>2</b>
    ... </a>""", item_depth=2, item_callback=handle)
    path:[('a', {'prop': 'x'}), ('b', None)] item:1
    path:[('a', {'prop': 'x'}), ('b', None)] item:2

The optional argument `postprocessor` is a function that takes `path`,
`key` and `value` as positional arguments and returns a new `(key, value)`
pair where both `key` and `value` may have changed. Usage example::

    >>> def postprocessor(path, key, value):
    ...     try:
    ...         return key + ':int', int(value)
    ...     except (ValueError, TypeError):
    ...         return key, value
    >>> xmltodict.parse('<a><b>1</b><b>2</b><b>x</b></a>',
    ...                 postprocessor=postprocessor)
    {'a': {'b:int': [1, 2], 'b': 'x'}}

You can pass an alternate version of `expat` (such as `defusedexpat`) by
using the `expat` parameter. E.g:

    >>> import defusedexpat
    >>> xmltodict.parse('<a>hello</a>', expat=defusedexpat.pyexpat)
    {'a': 'hello'}

You can use the force_list argument to force lists to be created even
when there is only a single child of a given level of hierarchy. The
force_list argument is a tuple of keys. If the key for a given level
of hierarchy is in the force_list argument, that level of hierarchy
will have a list as a child (even if there is only one sub-element).
The index_keys operation takes precedence over this. This is applied
after any user-supplied postprocessor has already run.

    For example, given this input:
    <servers>
      <server>
        <name>host1</name>
        <os>Linux</os>
        <interfaces>
          <interface>
            <name>em0</name>
            <ip_address>10.0.0.1</ip_address>
          </interface>
        </interfaces>
      </server>
    </servers>

    If called with force_list=('interface',), it will produce
    this dictionary:
    {'servers':
      {'server':
        {'name': 'host1',
         'os': 'Linux'},
         'interfaces':
          {'interface':
            [ {'name': 'em0', 'ip_address': '10.0.0.1' } ] } } }

    `force_list` can also be a callable that receives `path`, `key` and
    `value`. This is helpful in cases where the logic that decides whether
    a list should be forced is more complex.


    If `process_comments` is `True`, comments will be added using `comment_key`
    (default=`'#comment'`) to the tag that contains the comment.

        For example, given this input:
        <a>
          <b>
            <!-- b comment -->
            <c>
                <!-- c comment -->
                1
            </c>
            <d>2</d>
          </b>
        </a>

        If called with `process_comments=True`, it will produce
        this dictionary:
        'a': {
            'b': {
                '#comment': 'b comment',
                'c': {

                    '#comment': 'c comment',
                    '#text': '1',
                },
                'd': '2',
            },
        }
    Comment text is subject to the `strip_whitespace` flag: when it is left
    at the default `True`, comments will have leading and trailing
    whitespace removed. Disable `strip_whitespace` to keep comment
    indentation or padding intact.
r1   utf-8NTc                      [        S5      e)Nzentities are disabled)
ValueError)_args_kwargss     r   _forbid_entitiesparse.<locals>._forbid_entitiesf  s    455r   readFr   r   )r   rH   strencodeParserCreateordered_attributesrQ   StartNamespaceDeclHandlerr\   StartElementHandlerrd   EndElementHandlerrh   CharacterDataHandlerrk   CommentHandlerbuffer_textEntityDeclHandlerhasattr	ParseFiler   Parser&   )	xml_inputencodingr   process_namespacesr1   disable_entitiesprocess_commentskwargshandlerparserr   chunks               r   parser      sP   T  (2E ( &(G)S!!&w$$X.	"F !%F'.'A'AF$!(!5!5F&11F")"4"4F ' 0 0F	6 $4 y&!!# << 
Y		ELL& S$ << 	Y%<<r   c                     [        U [        5      (       a  U $ [        U [        5      (       a  U (       a  S$ S$ [        U [        [        [
        45      (       a  [        U 5      R                  XS9$ [        U 5      $ )zConvert a value to its string representation for XML output.

Handles boolean values consistently by converting them to lowercase.
truefalse)errors)rH   r   rt   bytes	bytearray
memoryviewdecode)rZ   r   bytes_errorss      r   _convert_value_to_stringr   u  sf    
 %%v+G+%%J788U|""8"AAu:r   c                    [        U [        5      (       d  [        U S35      eU R                  S5      (       d  U R                  S5      (       a  [        SU S35      eSU ;   d  SU ;   a  [        SU S35      eS	U ;   a  [        SU S
35      eSU ;   d  SU ;   a  [        SU S35      eSU ;   a  [        SU S35      e[	        S U  5       5      (       a  [        SU S35      eg)zValidate an element/attribute name for XML safety.

Raises ValueError with a specific reason when invalid.

kind: 'element' or 'attribute' (used in error messages)
z name must be a string?!zInvalid z# name: cannot start with "?" or "!"<>z name: "<" or ">" not allowed/z name: "/" not allowed"'z name: quotes not allowed=z name: "=" not allowedc              3   @   #    U  H  oR                  5       v   M     g 7fr"   )isspace).0chs     r   	<genexpr>!_validate_name.<locals>.<genexpr>  s     
(%B::<<%s   z name: whitespace not allowedN)rH   r   r~   
startswithany)rZ   kinds     r   _validate_namer     s    eS!!D6!7899 0 0 5 58D6)LMNN
e|se|8D6)FGHH
e|8D6)?@AA
e|se|8D6)BCDD
e|8D6)?@AA

(%
(((8D6)FGHH )r   c                 4   [        U [        5      (       a   U R                  S5      n [        U [
        5      (       d  [	        S5      eSU ;   a  [	        S5      eU R                  S5      (       a  [	        S5      eU $ ! [         a  n[	        S5      UeS nAff = f)Nr|   z Comment text must be valid UTF-8zComment text must be a stringz--z Comment text cannot contain '--'-z Comment text cannot end with '-')rH   r   r   UnicodeDecodeErrorr~   r   endswith)rZ   excs     r   _validate_commentr     s    %	JLL)E eS!!899u};<<~~c;<<L " 	J?@cI	Js   A< <
BBBc                 >   [        U [        5      (       d  U $ U(       d  U $  U R                  US5      u  p@UR                  UR	                  U5      5      nU(       a-  SR                  UR                  U5      (       a  UOSXRU 5      n U $ U n U $ ! [         a     U $ f = f)Nr;   z{}{}{}{}r   )rH   r   rsplitgetr`   formatr   r~   )rB   r2   ns_sepr*   nsns_ress         r   _process_namespacer     s    dC  6;;vq)  56 &,   ==55K2D" K 26 	 K   Ks   B 
BBc                 `   [        U [        5      (       a  U U:X  a  [        U[        5      (       a  UOU/n[        U	[        5      (       a  SU	-  n	U H`  nUc  M  [	        UXS9nU(       d  M  U(       a  UR                  XY-  5        UR                  U5        U(       d  MO  UR                  U5        Mb     g [        XX5      n Ub  U" X5      nUc  g Uu  p[        U S5        [        US5      (       a*  [        U[        [        [        [        [        45      (       a  U/n[        U5       GH  u  nnU(       a  US:X  a  US:  a  [        S5      eUc  0 nOb[        U[        [        45      (       dG  U(       a6  [        US5      (       a%  [        U[        [        [        45      (       d  UU0nO
[	        UXS9n[        U[        5      (       a  UU0nS n0 n/ nUR!                  5        GHB  u  nnUU:X  a  Uc  S nO
[	        UXS9nM  [        U[        5      (       a  UR#                  U5      (       a  [        UXU5      nUS:X  al  [        U[        5      (       aW  UR!                  5        HA  u  nn[        US5        S	R%                  U(       a  S
U 3OS5      nUc  SO	[	        UXS9UU'   MC     M  Uc  SnO[        U[        5      (       d
  [	        UXS9nU['        U5      S  n[        US5        UUU'   GM  [        U[        5      (       a
  U(       d  GM/  UR)                  UU45        GME     [        U	[        5      (       a  SU	-  n	U(       a  UR                  XY-  5        UR+                  U [-        U5      5        U(       a  U(       a  UR                  U5        U H  u  nn[/        UUUX4US-   UXxXU
XUUS9  M     Ub  UR1                  U5        U(       a  U(       a  UR                  XY-  5        UR3                  U 5        U(       d  GM  U(       d  GM  UR                  U5        GM     g )N )r   r   element__iter__r   zdocument with multiple rootsz@xmlns	attributezxmlns{}r   r   r;   )r2   r1   expand_iterr   r   r5   )rH   r   rn   intr   ignorableWhitespacecommentr   r   r   r   r   r   rI   	enumerater~   rW   r   r   rV   rU   r\   r   _emitrh   rd   ) rY   rZ   content_handlerr*   r+   depthpreprocessorprettynewlindentr1   r2   full_documentr   r   r   r5   comments_listcomment_textrp   indexvcdatarK   childrenikivkattr	attr_name	child_keychild_values                                    r   r   r     s    #s{ 2!+E4!8!8ugfc""6\F)L#3xL  33ENC##L1v33D9 * 	
S.A
OCc)>
3	"5*%%EC	S]_c;d)e)ee$qUaZEAI;<<9AAc{++wq*55jUT]_iLj>k>k !$,Q]aAAggiFBY: E4R(fE"c""r}}['A'A'J(35>jT&:&: "
1&q+6(//1!A3"E,-Ib;S<d !+ :B#B,,1"xcBs;/12	y+6#%i "d##BOORH%9  : fc""6\F//?$$S.*?@h//5&."I{)[/%'<&9)+F '/ &&u-h//?""3'6ee//5A %r   c                       \ rS rSrS rSrg)_XMLGeneratori)  c                 V    [        U5      nU R                  S[        U5       S35        g )Nz<!--z-->)r   _writer   )r6   texts     r   r   _XMLGenerator.comment*  s%     &d6$<.,-r   r   N)r   r   r   r   r   r   r   r   r   r   r   )  s    .r   r   c           	         UR                  SS5      n [        R                  " U5        Sn	Uc  [        5       nSn	U(       a  [        XS5      n
O[        X5      n
U(       a  U
R                  5         SnU R                  5        H?  u  pX:w  a  U(       a  U(       a  [	        S5      e[        UUU
4UUUUS.UD6  X:w  d  M=  SnMA     U(       a  U(       d  [	        S5      eU(       a  U
R                  5         U	(       a$  UR                  5       n UR                  U5      nU$ g! [         a  n[	        SU 35      UeSnAff = f! [         a     U$ f = f)	a  Emit an XML document for the given `input_dict` (reverse of `parse`).

    The resulting XML document is returned as a string, but if `output` (a
    file-like object) is specified, it is written there instead.

    Dictionary keys prefixed with `attr_prefix` (default=`'@'`) are interpreted
    as XML node attributes, whereas keys equal to `cdata_key`
    (default=`'#text'`) are treated as character data.

    Empty lists are omitted entirely: ``{"a": []}`` produces no ``<a>`` element.
    Provide a placeholder entry (for example ``{"a": [""]}``) when an explicit
    empty container element must be emitted.

    The `pretty` parameter (default=`False`) enables pretty-printing. In this
    mode, lines are terminated with `'
'` and indented with `' '`, but this
    can be customized with the `newl` and `indent` parameters.
    The `bytes_errors` parameter controls decoding errors for byte values and
    defaults to `'replace'`.

    r   replacezInvalid bytes_errors handler: NFTz$Document must have exactly one root.)r   r   r   r5   )r_   codecslookup_errorLookupErrorr~   r   r   startDocumentrW   r   endDocumentgetvaluer   AttributeError)
input_dictoutputr   r   short_empty_elementsr5   r   r   r   must_returnr   	seen_rootrY   rZ   s                 r   unparser   /  sf   . ::ni8LSL) K~'$?'9%%'I &&(
-ICDD		
 (%#		
 		
 I ) Y?@@##%!	LL*E  C  S9,HIsRSJ  		s)   D" E "
E ,D;;E 
EE__main__r;   c                 <    [         R                  " X4[        5        gr   )marshaldumpstdout)r#   r&   s     r   handle_itemr   }  s    d\6*r   )r'   r)   r/   )r|   r   )r   r   )r   r   r   NF
	r   NTNr|   r   r    )Nr|   TFr    )%__doc__xml.parsersr   xml.sax.saxutilsr   r   xml.sax.xmlreaderr   ior   inspectr   r   	Exceptionr
   r   r   r   r   r   r   r   r   r   r   r   sysstdinbufferr   argvr'   r   r   rI   rootKeyboardInterruptr   r   r   <module>r     sI   <  1 ,   	 	v@ v@r #%E!D5jZI.$ !  l6^.L . FJ4>AH zIIEZZFHHQRLMZZJU *#.&*, ?D! ' *  s   C. .C76C7