o
    ÝîiJ  ã                   @   s˜   d Z zddlmZ W n ey   ddlmZ Y nw ddlmZ ddlmZ ddl	m
Z
 dd„ Zdd	„ Zeejffd
d„Zeejffdd„Zdd„ ZdS )zoThis module contains the utility methods that convert an ElementTree
hierarchy to python dicts and vice versa.
é    )ÚSized)Úetree)Úsix)Úodictc                 C   s¤   t | ƒdksJ d|  ƒ‚|  ¡ \}t |¡}|  ¡ D ]} |du r#|S t|tƒs-t|tƒr4t||ƒ |S t|t	ƒr?t|t
jƒrFt|ƒ|_|S |D ]}t||ƒ qH|S )zÌConverts a dictionary to an xml hiearchy. Just like a valid xml document,
    the dictionary must have a single element. The format of the child
    dictionaries is the same as :func:`dict_to_etree`.
    é   z-Incoming dict len must be exactly 1. Data: %rN)ÚlenÚkeysr   ÚElementÚvaluesÚ
isinstanceÚdictr   Údict_to_etreer   r   Ústring_typesÚstrÚtext)ÚdÚkeyÚretvalÚvalÚa© r   úT/var/www/html/LicenciasMIG/venv/lib/python3.10/site-packages/spyne/util/etreeconv.pyÚroot_dict_to_etree"   s    


ú
ýr   c                 C   sì   |   ¡ D ]o\}}|du rt ||¡ qt|tjƒr!|t ||¡_qt|tƒs+t|tƒr7t ||¡}t	||ƒ qt|t
ƒsFt|ƒt ||¡_qt|ƒdkrSt ||¡ q|D ]}t ||¡}t|tƒsgt|tƒrmt	||ƒ qUt|ƒ|_qUqdS )z´Takes a the dict whose value is either None or an instance of dict, odict
    or an iterable. The iterables can contain either other dicts/odicts or
    str/unicode instances.
    Nr   )Úitemsr   Ú
SubElementr   r   r   r   r   r   r   r   r   r   )r   ÚparentÚkÚvÚchildÚer   r   r   r   =   s&   
ûîr   c                 C   s   | j |d t| |ƒgƒiS )úÐTakes an xml root element and returns the corresponding dict. The second
    argument is a pair of iterable type and the function used to add elements to
    the iterable. The xml attributes are ignored.
    r   )ÚtagÚetree_to_dict)ÚelementÚiterabler   r   r   Úroot_etree_to_dict]   s   r%   c                 C   sf   | j du s
| j  ¡ r.tƒ }| D ]}|j|vr|d ƒ ||j< |d ||j t||ƒƒ q|S | j }|S )r    Nr   r   )r   Úisspacer   r!   r"   )r#   r$   r   Úeltr   r   r   r"   f   s   
þr"   c                 C   s`   t  | j d¡d ¡}| j|_| jD ]}| j| |j| d¡d < q| D ]	}| t|ƒ¡ q$|S )zERemoves any namespace information form the given element recursively.Ú}éÿÿÿÿ)r   r	   r!   Ú
rpartitionr   ÚattribÚappendÚetree_strip_namespaces)r#   r   r   r   r   r   r   r-   y   s   
r-   N)Ú__doc__Úcollections.abcr   ÚImportErrorÚcollectionsÚlxmlr   Ú
spyne.utilr   Úspyne.util.odictr   r   r   Úlistr,   r%   r"   r-   r   r   r   r   Ú<module>   s   ÿ 	