o
    tBhc                     @   s
  d Z ddlZddlZddlZddlmZmZmZ ddlm	Z	 ddl
mZ ddlmZmZ ddlmZmZ ddlmZmZ dd	lmZ dd
lmZmZmZmZ g dZG dd deZG dd deeZG dd deZ G dd deZ!G dd deZ"G dd deZ#dS )a@  
zeep.xsd.elements.indicators
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Indicators are a collection of elements. There are four available, these are
All, Choice, Group and Sequence.

    Indicator -> OrderIndicator -> All
                                -> Choice
                                -> Sequence
              -> Group

    N)OrderedDictdefaultdictdeque)threaded_cached_property)etree)UnexpectedElementErrorValidationError)NotSet	SkipValue)AnyElement)Base)NamePrefixGeneratorUniqueNameGeneratorcreate_prefixed_namemax_occurs_iter)AllChoiceGroupSequencec                       sB   e Zd ZdZ fddZedd Zedd Zdd	d
Z  Z	S )	Indicatorz#Base class for the other indicatorsc                    s   d| j jt  f S )Nz<%s(%s)>)	__class____name__super__repr__selfr    s/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/zeep/xsd/elements/indicators.pyr   '   s   zIndicator.__repr__c                 C   s&   t dd | jD }| jrd|iS |S )Nc                 S   s   g | ]	\}}||j fqS r   )default_value).0nameelementr   r   r   
<listcomp>-   s    z+Indicator.default_value.<locals>.<listcomp>_value_1)r   elementsaccepts_multipler   valuesr   r   r   r    *   s   zIndicator.default_valuec                 C      t  NNotImplementedErrorr   r   r   r   r&   4      zIndicator.elements   c                 C   r*   r+   r,   r   r"   
min_occurs
max_occursr   r   r   clone8   s   zIndicator.cloner/   r/   )
r   
__module____qualname____doc__r   propertyr    r&   r3   __classcell__r   r   r   r   r   $   s    
	
r   c                       s   e Zd ZdZdZd fdd	ZdddZedd	 Zed
d Z	dd Z
dddZdd Zdd Zdd Zdd ZdddZ  ZS ) OrderIndicatorz0Base class for All, Choice and Sequence classes.Nr/   c                    s0   || _ || _t   |d ur| | d S d S r+   )r1   r2   r   __init__extend)r   r&   r1   r2   r   r   r   r;   A   s   
zOrderIndicator.__init__c                 C   s   | j t| ||dS )N)r&   r1   r2   )r   listr0   r   r   r   r3   H      
zOrderIndicator.clonec                 C   s<   g }| j D ]\}}|du r||j q|||f q|S z:List of tuples containing the element name and the elementN)elements_nestedr<   r&   append)r   resultr"   elmr   r   r   r&   M   s   zOrderIndicator.elementsc                 C   s   g }t  }t }| D ]K}t|ttttfr7|jr"||	 |f q
|j
D ]	\}}||}q%|d|f q
t|ttfrH||	 |f q
||j}|||f q
|S r?   )r   r   
isinstancer   r   r   r   r'   rA   get_namer&   create_namer   	attr_name)r   rB   	generatorgenerator_2rC   sub_namesub_elmr"   r   r   r   r@   X   s   zOrderIndicator.elements_nestedc                 C   s|   | j s|g}t }|D ].}d}| jD ]!\}}t|tr,|j|v r+||j dur+|d7 }q|||7 }q|| qt|S )Return the number of values which are accepted by this choice.

        If not all required elements are available then 0 is returned.

        r   Nr/   )	r'   setr@   rD   r   r"   acceptaddmax)r   r)   resultsvaluenumr"   r#   r   r   r   rN   n   s   
zOrderIndicator.acceptr   c                 C   sd   | j D ]\}}t|trtdqi }| jD ]\}}|t|kr" n|| ||< |d7 }q|||fS )N0Choice elements only work with keyword argumentsr/   )r@   rD   r   	TypeErrorr&   len)r   argsindexr"   rC   rB   r#   r   r   r   
parse_args   s   


zOrderIndicator.parse_argsc              	   C   s@  | j r|sJ |r||vri S | j sJ ||}t|ts!|g}g }t| j|D ]D}zt| }W n ty>   t	dw t
 }| jD ]\}}	|	|||}
|
durY||
 qE|rht	d| t|d f || q)||i}ttd|s~|| |S | j rJ t
 }| jD ]\}}	|	|||}|r|| q|S )a  Apply the given kwarg to the element.

        The available_kwargs is modified in-place. Returns a dict with the
        result.

        :param kwargs: The kwargs
        :type kwargs: dict
        :param name: The name as which this type is registered in the parent
        :type name: str
        :param available_kwargs: The kwargs keys which are still available,
         modified in place
        :type available_kwargs: set
        :rtype: dict

        z3A list of dicts is expected for unbounded SequencesN+%s() got an unexpected keyword argument %r.r   )r'   getrD   r=   r   r2   rM   keysAttributeErrorrU   r   r&   parse_kwargsupdaterA   anyfilterremover@   )r   kwargsr"   available_kwargsitem_kwargsrB   
item_value	subresult	item_namer#   rR   elm_name
sub_resultr   r   r   r^      sV   






zOrderIndicator.parse_kwargsc                 C   s"   t | D ]
\}}| | |< q| S r+   )	enumerateresolve)r   irC   r   r   r   rl      s   zOrderIndicator.resolvec           	      C   s   t |ts	|g}n|}| || t| j|D ]6}| jD ]0\}}|r5||v r0|| }||g }n	t}|}n|}|}|tu r>q|dusE|jsL|	||| qqdS )z.Create subelements in the given parent object.N)
rD   r=   validater   r2   r@   r	   r
   is_optionalrender)	r   parentrR   render_pathr)   r"   r#   element_value
child_pathr   r   r   rp      s*   
zOrderIndicator.renderc                 C   s"   |D ]}|t u rtd|dqd S )NzNo value setpath)r	   r   )r   rR   rr   itemr   r   r   rn      s
   zOrderIndicator.validateTc                 C   sr   g }| j D ]$\}}t|tr||j|dd q|j|dd}|d||f  qd|}| jr7d|f S |S )NF
standalonez%s: %sz, z[%s])r@   rD   r   rA   	signaturejoinr'   )r   schemary   partsr"   r#   rR   partr   r   r   rz     s   


zOrderIndicator.signature)Nr/   r/   r4   r   NT)r   r5   r6   r7   r"   r;   r3   r   r&   r@   rN   rY   r^   rl   rp   rn   rz   r9   r   r   r   r   r:   <   s     




Gr:   c                       s,   e Zd ZdZd	 fdd	Zd
ddZ  ZS )r   zlAllows the elements in the group to appear (or not appear) in any order
    in the containing element.

    Nr/   Fc                    s   t  ||| || _d S r+   )r   r;   _consume_other)r   r&   r1   r2   consume_otherr   r   r   r;     s   
zAll.__init__c                 C   s   t  }dd | jD }t }tt}t|D ]\}	}
|
j|v r,||	 ||
j |
 qt	|ddD ]}	||	= q3| jD ]\}}|
|j}|rR|j|||d||< q<| jrb|rbt||d< |  |S )  Consume matching xmlelements

        :param xmlelements: Dequeue of XML element objects
        :type xmlelements: collections.deque of lxml.etree._Element
        :param schema: The parent XML schema
        :type schema: zeep.xsd.Schema
        :param name: The name of the parent element
        :type name: str
        :param context: Optional parsing context (for inline schemas)
        :type context: zeep.xsd.context.XmlParserContext
        :rtype: dict or None

        c                 S   s   h | ]\}}|j qS r   )qname)r!   __r#   r   r   r   	<setcomp>+  s    z(All.parse_xmlelements.<locals>.<setcomp>T)reversecontext_raw_elements)r   r&   rM   r   r   rk   tagrO   rA   sortedr[   r   parse_xmlelementsr   r=   clear)r   xmlelementsr|   r"   r   rB   expected_tagsconsumed_tagsr)   rm   rC   r#   sub_elementsr   r   r   r     s,   



zAll.parse_xmlelements)Nr/   r/   FNN)r   r5   r6   r7   r;   r   r9   r   r   r   r   r     s    r   c                   @   sn   e Zd ZdZdddZedd Zedd Zdd
dZdd Z	dd Z
dd Zdd Zdd ZdddZd	S )r   z@Permits one and only one of the elements contained in the group.r   c                 C   s   |rt dd S )NrT   )rU   r   rW   rX   r   r   r   rY   H  s   zChoice.parse_argsc                 C   s   dS r   r   r   r   r   r   ro   L  s   zChoice.is_optionalc                 C   s   t  S r+   )r   r   r   r   r   r    P  r.   zChoice.default_valueNc              
   C   s  g }t | jD ]o}|s njg }| jD ]8\}}	t|}
z|	j|
|||d}W n	 ty/   Y qw t|	tr9||i}t|t|
 }|rJ|	||f q|sQg } n&t
|tddd}|rv|	|d d  t|d d D ]}|  qnq | jr||i}|S |r|d ni }|S )r   )r   r|   r"   r   r   Tkeyr   r/   )r   r2   r@   copyr   r   rD   r   rV   rA   r   operator
itemgetterrangepopleftr'   )r   r   r|   r"   r   rB   _unusedoptionselement_namer#   local_xmlelementsrj   num_consumedrm   r   r   r   r   T  sL   



zChoice.parse_xmlelementsc                 C   s  |r}||v r}| j sJ || pg }|| g }t|tr |g}|D ]N}| D ]?}t|trD||v r5|| n|}||rC||  n-q&t|trP||  n |j|v re|	|j}||j|i  nq&t
d||  f q"| j s||rz|d nd}nQ| j ri S i }d}	| jD ]1\}}
t|}|
|||}|rt| s|| || q|	s|| || d}	q|	r| jD ]
\}}
||d qni }|r| j r||i}|S )a  Processes the kwargs for this choice element.

        Returns a dict containing the values found.

        This handles two distinct initialization methods:

        1. Passing the choice elements directly to the kwargs (unnested)
        2. Passing the choice elements into the `name` kwarg (_value_1) (nested).
           This case is required when multiple choice elements are given.

        :param name: Name of the choice element (_value_1)
        :type name: str
        :param element: Choice element object
        :type element: zeep.xsd.Choice
        :param kwargs: dict (or list of dicts) of kwargs for initialization
        :type kwargs: list / dict

        zJNo complete xsd:Sequence found for the xsd:Choice %r.
The signature is: %sr   NFT)r'   rb   rD   dictr:   rN   rA   r   r"   r[   rU   rz   r@   r   r^   r`   r)   intersection_updater_   r&   
setdefault)r   rc   r"   rd   r)   rB   rR   r#   choice_valuefoundchoicetemp_kwargsrg   choice_namer   r   r   r^     sp   














zChoice.parse_kwargsc                 C   sJ   | j s|g}| || |D ]}| |}|r"|\}}|||| qdS )zRender the value to the parent element tree node.

        This is a bit more complex then the order render methods since we need
        to search for the best matching choice element.

        N)r'   rn   _find_element_to_renderrp   )r   rq   rR   rr   rw   rB   r#   r   r   r   r   rp     s   
zChoice.renderc                 C   sB   d}|D ]}|  |}|r|d7 }q|s| jstd|dd S d S )Nr   r/   zMissing choice valuesru   )r   ro   r   )r   rR   rr   r   rw   rB   r   r   r   rn     s   

zChoice.validatec                    s   t  }| jD ]5\ }t|tr1| jr#t fdd|D r"|d q |v r0|  r0|d q||}|| q|rBt|S dS )rL   c                 3   s     | ]} |v o|  V  qd S r+   r   )r!   rw   r"   r   r   	<genexpr>  s    z Choice.accept.<locals>.<genexpr>r/   r   )	rM   r@   rD   r   r'   allrO   rN   rP   )r   r)   numsr#   rS   r   r   r   rN     s   



zChoice.acceptc              
   C   s   g }| j D ]W\}}t|tr3|j|v r2z||j }W n ty%   |}Y nw |dur2|d||f q|durKz|| }W n ttfyJ   |}Y nw |}||}|r\||||f q|rqt|t	
ddd}|d dd S dS )zReturn a tuple (element, value) for the best matching choice.

        This is used to decide which choice child is best suitable for
        rendering the available data.

        Nr/   r   Tr   )r@   rD   r   r"   KeyErrorrA   rU   rN   r   r   r   )r   rR   matchesr"   r#   r   scorer   r   r   r     s6   


zChoice._find_element_to_renderTc              	   C   sv   g }| j D ]$\}}t|tr|d|j|dd  q|d||j|ddf  qdd| }| jr9d|f S |S )Nz{%s}Frx   z{%s: %s}z(%s)z | z%s[])r@   rD   r:   rA   rz   r{   r'   )r   r|   ry   r}   r"   r#   r~   r   r   r   rz   :  s   

zChoice.signaturer   r   r   )r   r5   r6   r7   rY   r8   ro   r    r   r^   rp   rn   rN   r   rz   r   r   r   r   r   E  s    



>T
$r   c                   @   s   e Zd ZdZdddZdS )r   zoRequires the elements in the group to appear in the specified sequence
    within the containing element.

    Nc              
   C   s   g }| j r	|s	J t| jD ]G}|s nBt }| jD ]3\}}	z|	j||||d}
W n ty9   |jjr5 d}
Y nw t	|	t
rE||
 n|
||< |sM nq|rU|| q| j sa|r_|d S dS ||iS )r   r   Nr   )r'   r   r2   r   r&   r   r   settingsstrictrD   r:   r_   rA   )r   r   r|   r"   r   rB   r   item_resultri   r#   item_subresultr   r   r   r   O  s:   


zSequence.parse_xmlelementsr   )r   r5   r6   r7   r   r   r   r   r   r   I  s    r   c                       s   e Zd ZdZd fdd	Zdd Zdd Zed	d
 ZdddZ	dd Z
dddZdd Zd ddZdd Zdd Zd!ddZ  ZS )"r   zyGroups a set of element declarations so that they can be incorporated as
    a group into complex type definitions.

    r/   c                    s6   t    || _|| _|r|jnd | _|| _|| _d S r+   )r   r;   childr   	localnamer"   r2   r1   )r   r"   r   r2   r1   r   r   r   r;     s   

zGroup.__init__c                 C   s   |   S r+   )rz   r   r   r   r   __str__  s   zGroup.__str__c                 o   s    | j D ]}|V  qd S r+   )r   )r   rW   rc   rw   r   r   r   __iter__  s   
zGroup.__iter__c                 C   s   | j r	d| jfgS | jjS )Nr%   )r'   r   r&   r   r   r   r   r&     s   zGroup.elementsc                 C   s   | j d | j||dS )N)r"   r   r1   r2   )r   r   r0   r   r   r   r3     r>   zGroup.clonec                 C   s   | j |S )rL   )r   rN   r(   r   r   r   rN     s   zGroup.acceptr   c                 C   s   | j ||S r+   )r   rY   r   r   r   r   rY     s   zGroup.parse_argsc           
      C   s   | j rP||vr	i S || || }g }| jj rdnd }t| j|D ]%}t| }| j|||}	|r@td| t	|d f |	rG|
|	 q"|rN||i}|S | j|||}|S )Nr%   rZ   r   )r'   rb   r   r   r2   rM   r\   r^   rU   r=   rA   )
r   rc   r"   rd   re   rB   rJ   
sub_kwargsavailable_sub_kwargsrg   r   r   r   r^     s4   

zGroup.parse_kwargsNc              	   C   sP   g }t | jD ]}|| jj||||d |s nq| js$|r$|d S ||iS )r   r   r   )r   r2   rA   r   r   r'   )r   r   r|   r"   r   rB   r   r   r   r   r     s   
zGroup.parse_xmlelementsc                 C   s4   t |ts	|g}n|}|D ]
}| j||| qd S r+   )rD   r=   r   rp   )r   rq   rR   rr   r)   r   r   r   rp     s   
zGroup.renderc                 C   s   | j  | _ | S r+   )r   rl   r   r   r   r   rl     s   zGroup.resolveTc                 C   s8   t | j|}|rd|| jj|ddf S | jj|ddS )Nz%s(%s)Frx   )r   r   r   rz   )r   r|   ry   r"   r   r   r   rz     s   zGroup.signaturer4   r   r   r   )r   r5   r6   r7   r;   r   r   r   r&   r3   rN   rY   r^   r   rp   rl   rz   r9   r   r   r   r   r     s    



	r   )$r7   r   r   typingcollectionsr   r   r   cached_propertyr   lxmlr   zeep.exceptionsr   r   zeep.xsd.constr	   r
   zeep.xsd.elementsr   r   zeep.xsd.elements.baser   zeep.xsd.utilsr   r   r   r   __all__r   r=   r:   r   r   r   r   r   r   r   r   <module>   s,     W3  8