U
    H4fs  ã                   @   sŽ   d dl Z d dlZd dlmZ d dlmZ ejrFd dlmZ d dl	m
Z
 ddgZG dd„ dƒZd	d
„ ZG dd„ deƒZG dd„ dƒZdd„ ZdS )é    N)ÚOrderedDict)ÚPrettyPrinter)ÚElement)ÚComplexTypeÚ	AnyObjectÚCompoundValuec                   @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zedd	„ ƒZed
d„ ƒZ	dS )r   z[Create an any object

    :param xsd_object: the xsd type
    :param value: The value

    c                 C   s   || _ || _d S ©N)Úxsd_objÚvalue)ÚselfZ
xsd_objectr
   © r   ú9/tmp/pip-unpacked-wheel-04z2hmy8/zeep/xsd/valueobjects.pyÚ__init__   s    zAnyObject.__init__c                 C   s   d| j j| j| jf S )Nz<%s(type=%r, value=%r)>)Ú	__class__Ú__name__Úxsd_elmr
   ©r   r   r   r   Ú__repr__   s
    ýzAnyObject.__repr__c                 C   s   t | ƒ| jt | j¡ƒS r   )Útyper   ÚcopyÚdeepcopyr
   )r   Úmemor   r   r   Ú__deepcopy__!   s    zAnyObject.__deepcopy__c                 C   s   | j S r   ©r	   r   r   r   r   Úxsd_type$   s    zAnyObject.xsd_typec                 C   s   | j S r   r   r   r   r   r   r   (   s    zAnyObject.xsd_elmN)
r   Ú
__module__Ú__qualname__Ú__doc__r   r   r   Úpropertyr   r   r   r   r   r   r      s   
c                 C   s$   t | tfdddœƒ}|ƒ }||_|S )zZHelper function to recreate pickled CompoundValue.

    See CompoundValue.__reduce__

    Núzeep.objects©Ú	_xsd_typer   )r   r   Ú
__values__)ÚnameÚvaluesÚclsÚobjr   r   r   Ú_unpickle_compound_value-   s      ÿr'   c                       s:   e Zd ZejrdZ‡ fdd„Zdd„ Zedd„ ƒZ	‡  Z
S )Ú
ArrayValueNc                    s   t ƒ  |¡ d S r   )Úsuperr   )r   Úitems©r   r   r   r   ?   s    zArrayValue.__init__c                 C   s&   t | jjtf| jddœƒ}|t| ƒƒS )Nr   r    )r   r   r   r   r!   Úlist)r   Z	anon_typer   r   r   Úas_value_objectB   s    
ýzArrayValue.as_value_objectc                 C   s   t t|j ¡ ƒƒ}| |pg ƒS r   )ÚnextÚiterr"   r$   )r%   r&   r*   r   r   r   Úfrom_value_objectJ   s    zArrayValue.from_value_object)r   r   r   ÚtypingÚTYPE_CHECKINGr!   r   r-   Úclassmethodr0   Ú__classcell__r   r   r+   r   r(   ;   s   r(   c                       s¦   e Zd ZU dZded< ded< dd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡ fdd„Z‡ fdd„Zd d!„ Zd"d#„ Z‡  ZS )$r   z8Represents a data object for a specific xsd:complexType.r   r!   r   Ú_xsd_elmc                 O   s˜   t ƒ }| jd krd S | jjD ],\}}|j}t|tƒr@| |¡ q|||< q| jjD ]\}}|j||< qRt| j||ƒ}	|	 	¡ D ]\}
}|||
< q||| _
d S r   )r   r!   Úelements_nestedÚdefault_valueÚ
isinstanceÚdictÚupdateÚ
attributesÚ_process_signaturer*   r"   )r   ÚargsÚkwargsr$   Zcontainer_nameÚ	containerZ
elm_valuesÚattribute_nameÚ	attributer*   Úkeyr
   r   r   r   r   V   s    



zCompoundValue.__init__c                 C   s   t | jj| jffS r   )r'   r   r   r"   r   r   r   r   Ú
__reduce__o   s    zCompoundValue.__reduce__c                 C   s   | j  |¡S r   )r"   Ú__contains__©r   rB   r   r   r   rD   r   s    zCompoundValue.__contains__c                    s,   | j ˆ j krdS ‡ fdd„ˆ D ƒ}|| jkS )NFc                    s   i | ]}|ˆ | “qS r   r   )Ú.0rB   ©Úotherr   r   Ú
<dictcomp>y   s      z(CompoundValue.__eq__.<locals>.<dictcomp>)r   r"   )r   rH   Zother_valuesr   rG   r   Ú__eq__u   s    zCompoundValue.__eq__c                 C   s
   | j  ¡ S r   )r"   Ú__len__r   r   r   r   rK   |   s    zCompoundValue.__len__c                 C   s
   | j  ¡ S r   )r"   Ú__iter__r   r   r   r   rL      s    zCompoundValue.__iter__c                 C   s   t | j ¡ ƒS r   )r,   r"   Úkeysr   r   r   r   Ú__dir__‚   s    zCompoundValue.__dir__c                 C   s   t ƒ  | j¡S r   )r   Úpformatr"   r   r   r   r   r   …   s    zCompoundValue.__repr__c                 C   s   | j  |¡S r   )r"   Ú__delitem__rE   r   r   r   rP   ˆ   s    zCompoundValue.__delitem__c                 C   s
   | j | S r   ©r"   rE   r   r   r   Ú__getitem__‹   s    zCompoundValue.__getitem__c                 C   s   || j |< d S r   rQ   ©r   rB   r
   r   r   r   Ú__setitem__Ž   s    zCompoundValue.__setitem__c                    s.   |  d¡s|dkr tƒ  ||¡S || j|< d S )NÚ__©r!   r5   )Ú
startswithr)   Ú__setattr__r"   rS   r+   r   r   rX   ‘   s    zCompoundValue.__setattr__c                    sX   |  d¡s|dkrtƒ  |¡S z| j| W S  tk
rR   td| jj|f ƒ‚Y nX d S )NrU   rV   z!%s instance has no attribute '%s')rW   r)   Ú__getattribute__r"   ÚKeyErrorÚAttributeErrorr   r   rE   r+   r   r   rY   –   s    ÿzCompoundValue.__getattribute__c                 C   sD   t | ƒƒ }t | j¡|_| j ¡ D ]\}}|dkr"t|||ƒ q"|S )Nr"   )r   r   r   r"   Ú__dict__r*   Úsetattr)r   r   ÚnewÚattrr
   r   r   r   r       s    
zCompoundValue.__deepcopy__c                 C   s   | j S r   rQ   r   r   r   r   Ú__json__¨   s    zCompoundValue.__json__)r   r   r   r   Ú__annotations__r   rC   rD   rJ   rK   rL   rN   r   rP   rR   rT   rX   rY   r   r`   r4   r   r   r+   r   r   P   s$   

c                 C   sž  t ƒ }|ržt|ƒ}t|ƒ}d}| jD ],\}}| ||¡\}}}|sF qR| |¡ q$| jD ](\}	}
||krl q‚|| ||	< |d7 }qX||kržtdt|ƒ|f ƒ‚t| 	¡ ƒ}| jD ]V\}}|j
rÎ| |||¡}n| |d|¡}|dk	r°| ¡ D ]\}}||krì|||< qìq°|r@| jD ]*\}	}
|	|kr| |	¡ ||	 ||	< qd|krj|d rj|d |d< | d¡ |rštd| jp~dtt|ƒƒ| jdd	f ƒ‚|S )
ae  Return a dict with the args/kwargs mapped to the field name.

    Special handling is done for Choice elements since we need to record which
    element the user intends to use.

    :param fields: List of tuples (name, element)
    :type fields: list
    :param args: arg tuples
    :type args: tuple
    :param kwargs: kwargs
    :type kwargs: dict


    r   é   z;__init__() takes at most %s positional arguments (%s given)NZ_raw_elementsz;%s() got an unexpected keyword argument %r. Signature: `%s`r   F)Ú
standalone)r   r,   Úlenr6   Ú
parse_argsr:   r;   Ú	TypeErrorÚsetrM   Zaccepts_multipleZparse_kwargsr*   ÚremoveÚqnamer.   r/   Ú	signature)r   r=   r>   ÚresultÚnum_argsÚindexZelement_nameÚelementr$   r@   rA   Zavailable_kwargsrB   r
   r   r   r   r<   ¬   s`    

ÿÿ





ýÿÿ	r<   )r   r1   Úcollectionsr   Zzeep.xsd.printerr   r2   Zzeep.xsd.elementsr   Zzeep.xsd.typesr   Ú__all__r   r'   r,   r(   r   r<   r   r   r   r   Ú<module>   s   \