
    Ii                         S r SSKJr  SS/rSrSrSrSrS	r\\-  r	\\-  r
\\-  r\\-  rS
 rS rS rS rS rS rSS jrS rSS jrSS jrSS jrSS jrSS jr " S S\5      rSS jrg)zThe **splunklib.data** module reads the responses from splunkd in Atom Feed
format, which is the format used by most of the REST API.
    )XMLloadrecorddictitemkeylistz!{http://dev.splunk.com/ns/rest}%sc                      U [         [        4;   $ N)
XNAME_DICT
LNAME_DICTnames    4/venv/lib/python3.13/site-packages/splunklib/data.pyisdictr   )       J
+++    c                      U [         [        4;   $ r   )
XNAME_ITEM
LNAME_ITEMr   s    r   isitemr   -   r   r   c                      U [         [        4;   $ r   )	XNAME_KEY	LNAME_KEYr   s    r   iskeyr   1   s    Iy)))r   c                      U [         [        4;   $ r   )
XNAME_LIST
LNAME_LISTr   s    r   islistr   5   r   r   c                 2    [        U R                  5      S:  $ )Nr   )lenattrib)elements    r   hasattrsr$   9   s    w~~""r   c                 B    U R                  S5      nUS:X  a  U $ XS-   S  $ )N}   )find)xnamercurlys     r   	localnamer,   =   s)    ZZ_FbL58eQJK&88r   Nc                 (   U c  gU R                  5       n [        U 5      S:X  a  g/ 0 S.n[        U 5      nUc  U/OUR                  U5      n[        U5      nUS:X  a  gUS:X  a  [	        US   U5      $ U Vs/ s H  n[	        Xb5      PM     sn$ s  snf )av  This function reads a string that contains the XML of an Atom Feed, then
returns the
data in a native Python structure (a ``dict`` or ``list``). If you also
provide a tag name or path to match, only the matching sub-elements are
loaded.

:param text: The XML text to load.
:type text: ``string``
:param match: A tag name or path to match (optional).
:type match: ``string``
Nr   )
namespacesnamesr(   )stripr!   r   findall	load_root)textmatch	nametablerootitemscountr   s          r   r   r   B   s     |D::<D
4yA~dI
 t9DmTFe)<EJEzzq9--38954Id&5999s   7Bc                     [        U 5      (       d  g [        5       nU R                  R                  5        H	  u  p#X1U'   M     U$ r   )r$   r   r"   r7   )r#   attrsr   values       r   
load_attrsr<   a   s;    GTHEnn**,
c
 -Lr   c                     [        5       n[        U 5      nU H;  n[        UR                  5      (       d   eUR                  S   n[        XA5      X%'   M=     U$ )Nr   )r   r	   r   tagr"   
load_value)r#   r5   r;   childrenchildr   s         r   	load_dictrB   j   sR    HEG}HUYY||F# 2  Lr   c                 t   [        U R                  5      n[        U 5      n[        X5      nUc  X$4$ Uc  X#4$ [	        U[
        5      (       a  XCS'   X#4$ / nUR                  5        HM  u  pgXd;   a  Xe;   a  XF   R                  U5        M$  Xd;   a   Xe;  a  XF   U/XF'   UR                  U5        MI  XtU'   MO     X$4$ )Nz$text)r,   r>   r<   r?   
isinstancestrr7   append)r#   r5   r   r:   r;   collision_keysr   vals           r   	load_elemrI   u   s    W[[!DwEw*E}T[(}T[(%g{NKKM<C1Jc"\c7*c*EJ!!#&#J " ;r   c                     [        U R                  5      (       d   e/ n[        U 5      nU H9  n[        UR                  5      (       d   eUR	                  [        XA5      5        M;     U$ r   )r   r>   r	   r   rF   r?   )r#   r5   r;   r@   rA   s        r   	load_listrK      s\    '++EG}Heii    Z12  Lr   c                     U R                   n[        U5      (       a  [        X5      $ [        U5      (       a  [	        X5      $ [        X5      u  p4[        R                  X45      $ r   )r>   r   rB   r   rK   rI   Recordfromkv)r#   r5   r>   kvs        r   r2   r2      sL    
++Cc{{9W88c{{9W88W(DA==r   c                    [        U 5      n[        U5      nUS:X  a0  U R                  nUc  g [        UR                  5       5      S:X  a  g U$ US:X  aG  US   nUR                  n[        U5      (       a  [        XQ5      $ [        U5      (       a  [        XQ5      $ [        5       nU HL  n[        XQ5      u  pX;   a3  Xx   n
[        U
[         5      (       d  U
/Xx'   Xx   R                  U	5        MH  XU'   MN     U$ )Nr   r(   )r	   r!   r3   r0   r>   r   rB   r   rK   r   rI   rD   rF   )r#   r5   r@   r8   r3   rA   r>   r;   r   r   currents              r   r?   r?      s    G}HME z||<tzz|! zii#;;y::#;;y::HEu0
=kGgt,,&iKt$$K  Lr   c                   J    \ rS rSrSrSrS rS rS rS r	\
S 5       rS	 rS
rg)rM      aj  This generic utility class enables dot access to members of a Python
dictionary.

Any key that is also a valid Python identifier can be retrieved as a field.
So, for an instance of ``Record`` called ``r``, ``r.key`` is equivalent to
``r['key']``. A key such as ``invalid-key`` or ``invalid.key`` cannot be
retrieved as a field, because ``-`` and ``.`` are not allowed in
identifiers.

Keys of the form ``a.b.c`` are very natural to write in Python as fields. If
a group of keys shares a prefix ending in ``.``, you can retrieve keys as a
nested dictionary by calling only the prefix. For example, if ``r`` contains
keys ``'foo'``, ``'bar.baz'``, and ``'bar.qux'``, ``r.bar`` returns a record
with the keys ``baz`` and ``qux``. If a key contains multiple ``.``, each
one is placed into a nested dictionary, so you can write ``r.bar.qux`` or
``r['bar.qux']`` interchangeably.
.c                 P   ^  [        U5      S:X  a  T $ [        U 4S jU 5       5      $ )Nr   c              3   0   >#    U  H  oTU   4v   M     g 7fr    ).0r   selfs     r   	<genexpr>"Record.__call__.<locals>.<genexpr>   s     7$3DI&$s   )r!   rM   )rZ   argss   ` r   __call__Record.__call__   s#    t9>$;7$777r   c                 >     X   $ ! [          a    [        U5      ef = fr   )KeyErrorAttributeErrorrZ   r   s     r   __getattr__Record.__getattr__   s)    	': 	' &&	's    c                     X	 g r   rX   rc   s     r   __delattr__Record.__delattr__   s    Jr   c                     X U'   g r   rX   )rZ   r   r;   s      r   __setattr__Record.__setattr__   s	    T
r   c                 "    [        5       nXU '   U$ r   )r   )rO   rP   results      r   rN   Record.fromkv   s    q	r   c                    X;   a  [         R                  X5      $ XR                  -  n[        5       nU R	                  5        H|  u  p4UR                  U5      (       d  M  U[        U5      S  nSU;   aG  UR                  U R                  5      nUnUS S  H  nX;  a  [        5       Xx'   Xx   nM     XGUS   '   Mx  XBU'   M~     [        U5      S:X  a  [        SU 35      eU$ )NrU   r'   r   zNo key or prefix: )	r   __getitem__sepr   r7   
startswithr!   splitra   )	rZ   r   rm   rO   rP   suffixkszxs	            r   rp   Record.__getitem__   s    ;##D..xxJJLDA<<$$s3xy\Ff}\\$((+CRAz%xA ! "R&	!"v ! v;!/u566r   rX   N)__name__
__module____qualname____firstlineno____doc__rq   r^   rd   rg   rj   staticmethodrN   rp   __static_attributes__rX   r   r   rM   rM      s;    " C8'  
r   rM   c                 "    U c  0 n [        U 5      $ )zThis function returns a :class:`Record` instance constructed with an
initial value that you provide.

:param value: An initial record value.
:type value: ``dict``
)rM   )r;   s    r   r   r     s     }be%=r   r   )r}   xml.etree.ElementTreer   __all__r   r   r   r   XNAMEF_RESTr   r   r   r   r   r   r   r   r$   r,   r   r<   rB   rI   rK   r2   r?   r   rM   r   rX   r   r   <module>r      s    &8
 

	
1:%
:%
)#	:%
,,*,#9
:>0!J?T ?Dr   