U
    H4f                     @   s   d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZm	Z	m
Z
 d dl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 e eZG d
d dZG dd dZdd ZdS )    N)etree)XMLParseError)absolute_locationload_externalnormalize_location)as_qname
qname_attr)elements)types)AUTO_IMPORT_NAMESPACESxsd_ns)UnresolvedCustomTypeUnresolvedTypec                   @   s   e Zd ZedZedZedZedZedZedZ	edZ
edZed	Zed
ZedZedZedZedZedZedZedZedZedZedZedZedZdS )tagsschemaimportinclude
annotationelement
simpleTypecomplexTypesimpleContentcomplexContentsequencegroupchoicealllistunion	attributeanyanyAttributeattributeGrouprestriction	extensionZ	notationsN)__name__
__module____qualname__r   r   import_r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   notation r*   r*   4/tmp/pip-unpacked-wheel-04z2hmy8/zeep/xsd/visitor.pyr      s,   r   c                "   @   s0  e Zd ZdZdd ZejejdddZ	ejej
ddd	d
ZejddddZejejdddZejejddddZdd Zdd Zd]ddZdd Zdd Zdd Zdd  Zd!d" Zejejejej
ejf d#d$d%Zd&d' Zd(d) Zd*d+ Z d,d- Z!d.d/ Z"d0d1 Z#d2d3 Z$d4d5 Z%d6d7 Z&d8d9 Z'd:d; Z(d<d= Z)d>d? Z*d@dA Z+dBdC Z,dDdE Z-dFdG Z.dHdI Z/dJdK Z0dLdM Z1dNdO Z2d^ej3dPdQdRZ4dSdT Z5dUdV Z6dWdX Z7dYdZ Z8d[d\ Z9e:j;e(e:j<ee:j=e-e:j>ee:j?e1e:j@ee:jAde:jBde:jCe)e:jDe*e:jEe+e:jFee:jGee:jHee:jIe'e:jJe0e:jKe2iZLdS )_SchemaVisitorap  Visitor which processes XSD files and registers global elements and
    types in the given schema.

    Notes:

    TODO: include and import statements can reference other nodes. We need
    to load these first. Always global.




    :param schema:
    :type schema: zeep.xsd.schema.Schema
    :param document:
    :type document: zeep.xsd.schema.SchemaDocument

    c                 C   s   || _ || _t | _d S N)documentr   set	_includes)selfr   r.   r*   r*   r+   __init__>   s    zSchemaVisitor.__init__)qnameinstancec                 C   s   | j || d S r-   )r.   register_elementr1   r3   r4   r*   r*   r+   r5   C   s    zSchemaVisitor.register_elementN)namer4   returnc                 C   s   | j || d S r-   )r.   register_attribute)r1   r7   r4   r*   r*   r+   r9   F   s    z SchemaVisitor.register_attribute)r3   r8   c                 C   s   | j || d S r-   )r.   register_typer6   r*   r*   r+   r:   K   s    zSchemaVisitor.register_typec                 C   s   | j || d S r-   )r.   register_groupr6   r*   r*   r+   r;   N   s    zSchemaVisitor.register_group)r3   r4   r8   c                 C   s   | j || d S r-   )r.   register_attribute_groupr6   r*   r*   r+   r<   Q   s    z&SchemaVisitor.register_attribute_groupc                 C   s   | j || d S r-   )r.   register_import)r1   	namespacer.   r*   r*   r+   r=   V   s    zSchemaVisitor.register_importc                 C   s0   | j |j}|s td|j || ||}|S )NzNo visitor defined for %r)visitorsgettag
ValueError)r1   nodeparentZ
visit_funcresultr*   r*   r+   processY   s
    zSchemaVisitor.processc                 C   s@   t |d}|r<| |}|jdkr&d S tj|j|| j|dS d S )Nrefz http://www.w3.org/2001/XMLSchema
array_type)r   _create_qnamer>   xsd_elementsRefAttributerA   r   )r1   rC   rI   rG   r*   r*   r+   process_ref_attribute`   s    


   z#SchemaVisitor.process_ref_attributec                 K   s~   t |d}|sd S | |}|jtjkr0tj}n:|jtjkrDtj}n&|jtj	krXtj
}n|jtjkrjtj}||j|| jf|S )NrG   )r   rJ   rA   r   r   rK   Z
RefElementr   rL   r   ZRefGroupr"   ZRefAttributeGroupr   )r1   rC   kwargsrG   clsr*   r*   r+   process_referencen   s    

zSchemaVisitor.process_referencec                 C   s^   |dk	st |d}|r"|| j_|dd| j_|dd| j_|D ]}| j||d qFdS )a  Visit the xsd:schema element and process all the child elements

        Definition::

            <schema
              attributeFormDefault = (qualified | unqualified): unqualified
              blockDefault = (#all | List of (extension | restriction | substitution) : ''
              elementFormDefault = (qualified | unqualified): unqualified
              finalDefault = (#all | List of (extension | restriction | list | union): ''
              id = ID
              targetNamespace = anyURI
              version = token
              xml:lang = language
              {any attributes with non-schema Namespace}...>
            Content: (
                (include | import | redefine | annotation)*,
                (((simpleType | complexType | group | attributeGroup) |
                  element | attribute | notation),
                 annotation*)*)
            </schema>

        :param node: The XML node
        :type node: lxml.etree._Element

        NtargetNamespaceelementFormDefaultunqualifiedattributeFormDefaultrD   )AssertionErrorr@   r.   _target_namespace_element_form_attribute_formrF   )r1   rC   Ztnschildr*   r*   r+   visit_schema   s    
zSchemaVisitor.visit_schemac           	      C   s0  d}| d}| d}|r0t| jj|| jj}|sP| jjsPtd| jj|j	d|s`|s`d| j_
| jj||}|rtd| | || |S |s|dkrd	}|std
| dS | j|| jjd}| d}|r|r||krtd| | jj|j	dn|s|s| jj}| jj|||d}| || |S )a  

        Definition::

            <import
              id = ID
              namespace = anyURI
              schemaLocation = anyURI
              {any attributes with non-schema Namespace}...>
            Content: (annotation?)
            </import>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        Nr>   schemaLocationz[The attribute 'namespace' must be existent if the importing schema has no target namespace.filename
sourcelineTzReturning existing schema: %r$http://www.w3.org/XML/1998/namespacezhttps://www.w3.org/2001/xml.xsdzCIgnoring import statement for namespace %r (missing schemaLocation)base_urlrQ   zaThe namespace defined on the xsd:import doesn't match the imported targetNamespace located at %r )Ztarget_namespace)r@   r   r   settingsr.   	_base_urlrW   r   locationr_   _has_empty_importZ	documentsZget_by_namespace_and_locationloggerdebugr=   _retrieve_data	_locationZcreate_new_document)	r1   rC   rD   schema_noder>   re   r.   Z
schema_tnsr   r*   r*   r+   visit_import   sh    

   
  zSchemaVisitor.visit_importc                 C   sv  | dstd| d}|| jkr*dS | j|| jjd}| j| |j ds|j dsl|j drd|j dp|jd i}|	|j t
j|j|d}|D ]}|| q|j D ]\}}	|||	 q|j ds|jd |jd< |}| jj}
| jj}| jj}| dd| j_| d	d| j_t|| jj| j_|D ]}| j||d
 qD|
| j_|| j_|| j_dS )a  

        Definition::

            <include
              id = ID
              schemaLocation = anyURI
              {any attributes with non-schema Namespace}...>
            Content: (annotation?)
            </include>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        r\   zschemaLocation is requiredNra   rQ   )nsmaprR   rS   rT   rU   )r@   NotImplementedErrorr0   ri   r.   rd   addrm   attribupdater   ElementrA   appenditemsr/   rX   rY   r   rF   )r1   rC   rD   re   rk   rm   newrZ   keyvalueZelement_form_defaultZattribute_form_defaultrb   r*   r*   r+   visit_include  sN    




  zSchemaVisitor.visit_includec              	   C   sZ  |j tjk}|st|\}}nd}d}|sR|j tjkr:d}| j|||d}|rR|S |d| jj}|dksn|rt	|d| jj
}nt|d }t|}	d}
|	rd}|	D ]:}|j tjkrqq|j tjtjfkr|rt| ||}
q|
st	|d}|r| |j}
nt }
|d	d
k}|d}tj||
|||||d}|rV| || |S )a  

        Definition::

            <element
              abstract = Boolean : false
              block = (#all | List of (extension | restriction | substitution))
              default = string
              final = (#all | List of (extension | restriction))
              fixed = string
              form = (qualified | unqualified)
              id = ID
              maxOccurs = (nonNegativeInteger | unbounded) : 1
              minOccurs = nonNegativeInteger : 1
              name = NCName
              nillable = Boolean : false
              ref = QName
              substitutionGroup = QName
              type = QName
              {any attributes with non-schema Namespace}...>
            Content: (annotation?, (
                      (simpleType | complexType)?, (unique | key | keyref)*))
            </element>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

           r   
min_occurs
max_occursform	qualifiedr7   Ntypenillabletruedefault)r7   type_r{   r|   r   r   	is_global)rA   r   r   _process_occurs_attrsr   rP   r@   r.   rX   r   rW   r   QNamestripr   r   r   r   rV   rF   	_get_typetext	xsd_typesAnyTyperK   rr   r5   )r1   rC   rD   r   r{   r|   rE   Zelement_formr3   childrenxsd_typerw   rZ   	node_typer   r   r   r*   r*   r+   visit_elementT  s`      

zSchemaVisitor.visit_element)rC   rD   r8   c                 C   s>  |j tjk}|d}|rNtd|}|rN| d }t||j}t	|| j}|sh| j
||d}|rh|S |d| jj}|dks|rt|d| jj}	nt|d}	| t|\}
}|r| |d |}n"t|d}|r| |}nt }|d	d
k}|d}tj|	|||d}|r:|	dk	s.t| |	| |S )a  Declares an attribute.

        Definition::

            <attribute
              default = string
              fixed = string
              form = (qualified | unqualified)
              id = ID
              name = NCName
              ref = QName
              type = QName
              use = (optional | prohibited | required): optional
              {any attributes with non-schema Namespace...}>
            Content: (annotation?, (simpleType?))
            </attribute>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        z+{http://schemas.xmlsoap.org/wsdl/}arrayTypez([^\[]+)r   rH   r}   r~   r7   r   Zuserequiredr   )r   r   r   N)rA   r   r   r@   rematchgroupsr   rm   r   rM   r.   rY   r   rW   r   r   _pop_annotationr   visit_simple_typer   r   r   rK   	AttributerV   r9   )r1   rC   rD   r   rI   r   r3   rE   Zattribute_formr7   r   rt   r   r   r   r   attrr*   r*   r+   visit_attribute  sF    


   zSchemaVisitor.visit_attributec                 C   s   |j tjkr|d}d}n|dd}d}d}t||j| jj}| t	|\}}|d }	|	j tj
kr| |	|}t||| j}
nB|	j tj	kr| |	|}
n(|	j tjkr| |	|}
ntd|	j  |
dk	st|r| ||
 |
S )	a  
        Definition::

            <simpleType
              final = (#all | (list | union | restriction))
              id = ID
              name = NCName
              {any attributes with non-schema Namespace}...>
            Content: (annotation?, (restriction | list | union))
            </simpleType>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        r7   TZ	AnonymousFz({http://www.w3.org/2001/XMLSchema}stringr   zUnexpected child: %rN)rA   r   r   r@   r   rm   r.   rW   r   r   r#   visit_restriction_simple_typer   
visit_listr   visit_unionrV   r:   )r1   rC   rD   r7   r   	base_typer3   r   rt   rZ   r   r*   r*   r+   r     s*    
zSchemaVisitor.visit_simple_typec                 C   s`  g }d}|j tjkr$|d}d}n|d}d}t||j| jj}d|d}t|t	j
f|}	d}
| t|\}}|r|d j nd}|tjkr| |d |\}}|	||||d	}
n|tjkr| |d |}|	f ||d
|}
nd|r>d}|tjtjtjtjfkr |d}| ||}| ||}|	||||d}
n|	||d
}
|r\| ||
 |
S )a  
        Definition::

            <complexType
              abstract = Boolean : false
              block = (#all | List of (extension | restriction))
              final = (#all | List of (extension | restriction))
              id = ID
              mixed = Boolean : false
              name = NCName
              {any attributes with non-schema Namespace...}>
            Content: (annotation?, (simpleContent | complexContent |
                      ((group | all | choice | sequence)?,
                      ((attribute | attributeGroup)*, anyAttribute?))))
            </complexType>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        z){http://www.w3.org/2001/XMLSchema}anyTyper7   TFzzeep.xsd.dynamic_types)r&   Z	_xsd_nameNr   )
attributesr$   r3   r   )r3   r   )r   r   r3   r   )rA   r   r   r@   r   rm   r.   rW   r   r   ZComplexTyper   r   r   visit_simple_contentr   visit_complex_contentr   r   r   r   poprF   _process_attributesr:   )r1   rC   rD   r   r   r7   r   r3   Zcls_attributesZxsd_clsr   r   Z	first_tagr   rN   r   rZ   r*   r*   r+   visit_complex_type0  sP    





   z SchemaVisitor.visit_complex_typec                 C   sh   t |}|d }|jtjkr:| ||\}}}|||dS |jtjkrd| ||\}}}|||dS dS )a0  The complexContent element defines extensions or restrictions on a
        complex type that contains mixed content or elements only.

        Definition::

            <complexContent
              id = ID
              mixed = Boolean
              {any attributes with non-schema Namespace}...>
            Content: (annotation?,  (restriction | extension))
            </complexContent>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        )r   r   r#   )r   r   r$   N)r   rA   r   r#   !visit_restriction_complex_contentr$   visit_extension_complex_content)r1   rC   rD   r   rZ   baser   r   r*   r*   r+   r   |  s     
 
z#SchemaVisitor.visit_complex_contentc                 C   sL   t |}|d }|jtjkr(| ||S |jtjkr@| ||S tddS )a'  Contains extensions or restrictions on a complexType element with
        character data or a simpleType element as content and contains no
        elements.

        Definition::

            <simpleContent
              id = ID
              {any attributes with non-schema Namespace}...>
            Content: (annotation?, (restriction | extension))
            </simpleContent>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        r   z!Expected restriction or extensionN)r   rA   r   r#    visit_restriction_simple_contentr$   visit_extension_simple_contentrV   )r1   rC   rD   r   rZ   r*   r*   r+   r     s    z"SchemaVisitor.visit_simple_contentc                 C   sN   t |d}|r| |S | t|\}}|d jtjkrJ| |d |S dS )a  
        Definition::

            <restriction
              base = QName
              id = ID
              {any attributes with non-schema Namespace}...>
            Content: (annotation?,
                (simpleType?, (
                    minExclusive | minInclusive | maxExclusive | maxInclusive |
                    totalDigits |fractionDigits | length | minLength |
                    maxLength | enumeration | whiteSpace | pattern)*))
            </restriction>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        r   r   N)r   r   r   r   rA   r   r   r   )r1   rC   rD   	base_namer   r   r*   r*   r+   r     s    

z+SchemaVisitor.visit_restriction_simple_typec                 C   s   t |d}| |}|g fS )a  
        Definition::

            <restriction
              base = QName
              id = ID
              {any attributes with non-schema Namespace}...>
            Content: (annotation?,
                (simpleType?, (
                    minExclusive | minInclusive | maxExclusive | maxInclusive |
                    totalDigits |fractionDigits | length | minLength |
                    maxLength | enumeration | whiteSpace | pattern)*
                )?, ((attribute | attributeGroup)*, anyAttribute?))
            </restriction>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        r   )r   r   )r1   rC   rD   r   r   r*   r*   r+   r     s    

z.SchemaVisitor.visit_restriction_simple_contentc           
      C   s   t |d}| |}| t|\}}d}g }|rv|d }	|	jtjtjtjtj	fkrj|
d | |	|}| ||}|||fS )a  

        Definition::

            <restriction
              base = QName
              id = ID
              {any attributes with non-schema Namespace}...>
            Content: (annotation?, (group | all | choice | sequence)?,
                    ((attribute | attributeGroup)*, anyAttribute?))
            </restriction>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        r   Nr   r   r   r   r   rA   r   r   r   r   r   r   rF   r   
r1   rC   rD   r   r   r   r   r   r   rZ   r*   r*   r+   r     s    


z/SchemaVisitor.visit_restriction_complex_contentc           
      C   s   t |d}| |}| t|\}}d}g }|rv|d }	|	jtjtjtjtj	fkrj|
d | |	|}| ||}|||fS )a	  

        Definition::

            <extension
              base = QName
              id = ID
              {any attributes with non-schema Namespace}...>
            Content: (annotation?, (
                        (group | all | choice | sequence)?,
                        ((attribute | attributeGroup)*, anyAttribute?)))
            </extension>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        r   Nr   r   r   r*   r*   r+   r     s    


z-SchemaVisitor.visit_extension_complex_contentc                 C   s:   t |d}| |}| t|\}}| ||}||fS )a  

        Definition::

            <extension
              base = QName
              id = ID
              {any attributes with non-schema Namespace}...>
            Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
            </extension>
        r   )r   r   r   r   r   )r1   rC   rD   r   r   r   r   r   r*   r*   r+   r   7  s
    

z,SchemaVisitor.visit_extension_simple_contentc                 C   s   dS )a  Defines an annotation.

        Definition::

            <annotation
              id = ID
              {any attributes with non-schema Namespace}...>
            Content: (appinfo | documentation)*
            </annotation>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        Nr*   r1   rC   rD   r*   r*   r+   visit_annotationJ  s    zSchemaVisitor.visit_annotationc                 C   s(   t |\}}|dd}tj|||dS )a  

        Definition::

            <any
              id = ID
              maxOccurs = (nonNegativeInteger | unbounded) : 1
              minOccurs = nonNegativeInteger : 1
              namespace = "(##any | ##other) |
                List of (anyURI | (##targetNamespace |  ##local))) : ##any
              processContents = (lax | skip | strict) : strict
              {any attributes with non-schema Namespace...}>
            Content: (annotation?)
            </any>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        processContentsstrict)r|   r{   process_contents)r   r@   rK   Any)r1   rC   rD   r{   r|   r   r*   r*   r+   	visit_any]  s    zSchemaVisitor.visit_anyc                 C   s   t jt jt jt jt jt jg}t|\}}tj	||d}| 
t|\}}|D ]B}	|	j|krl| d|	j |	| |	|}
|
dk	st||
 qLd|kst|S )a  
        Definition::

            <sequence
              id = ID
              maxOccurs = (nonNegativeInteger | unbounded) : 1
              minOccurs = nonNegativeInteger : 1
              {any attributes with non-schema Namespace}...>
            Content: (annotation?,
                      (element | group | choice | sequence | any)*)
            </sequence>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        rz   z%Unexpected element %s in xsd:sequenceN)r   r   r    r   r   r   r   r   rK   Sequencer   r   rA   _create_errorrF   rV   rs   )r1   rC   rD   	sub_typesr{   r|   rE   r   r   rZ   itemr*   r*   r+   visit_sequence{  s*    
 zSchemaVisitor.visit_sequencec           	      C   sh   t jt jg}t }| t|\}}|D ],}|j|ks@t|| 	||}|
| q*d|ksdt|S )a  Allows the elements in the group to appear (or not appear) in any
        order in the containing element.

        Definition::

            <all
              id = ID
              maxOccurs= 1: 1
              minOccurs= (0 | 1): 1
              {any attributes with non-schema Namespace...}>
            Content: (annotation?, element*)
            </all>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        N)r   r   r   rK   ZAllr   r   rA   rV   rF   rs   )	r1   rC   rD   r   rE   r   r   rZ   r   r*   r*   r+   	visit_all  s    zSchemaVisitor.visit_allc                 C   s   t |\}}| j|||d}|r$|S t|d| jj}| t|\}}|d }	| |	|}
tj	||
d}|j
tjkr| || |S )a  Groups a set of element declarations so that they can be
        incorporated as a group into complex type definitions.

        Definition::

            <group
              name= NCName
              id = ID
              maxOccurs = (nonNegativeInteger | unbounded) : 1
              minOccurs = nonNegativeInteger : 1
              name = NCName
              ref = QName
              {any attributes with non-schema Namespace}...>
            Content: (annotation?, (all | choice | sequence))
            </group>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        rz   r7   r   )r7   rZ   )r   rP   r   r.   rW   r   r   rF   rK   GrouprA   r   r   r;   )r1   rC   rD   r{   r|   rE   r3   r   r   rZ   r   elmr*   r*   r+   visit_group  s       zSchemaVisitor.visit_groupc                 C   sB   t |d}|r| |j}nt|}|d }| ||}t|S )a  
        Definition::

            <list
              id = ID
              itemType = QName
              {any attributes with non-schema Namespace}...>
            Content: (annotation?, (simpleType?))
            </list>

        The use of the simpleType element child and the itemType attribute is
        mutually exclusive.

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element


        ZitemTyper   )r   r   r   r   r   r   ZListType)r1   rC   rD   Z	item_typeZsub_typeZsubnodesrZ   r*   r*   r+   r     s    
zSchemaVisitor.visit_listc           
      C   sR   t |\}}| t|\}}g }|D ]}| ||}	||	 q&tj|||dS )a[  
        Definition::

            <choice
              id = ID
              maxOccurs= (nonNegativeInteger | unbounded) : 1
              minOccurs= nonNegativeInteger : 1
              {any attributes with non-schema Namespace}...>
            Content: (annotation?, (element | group | choice | sequence | any)*)
            </choice>
        rz   )r   r   r   rF   rs   rK   ZChoice)
r1   rC   rD   r{   r|   r   r   choicesrZ   r   r*   r*   r+   visit_choice  s      zSchemaVisitor.visit_choicec           	         sr     d}g }|rB| D ]$}t| j}|}|| qn&t \}} fdd|D }t	|S )a  Defines a collection of multiple simpleType definitions.

        Definition::

            <union
              id = ID
              memberTypes = List of QNames
              {any attributes with non-schema Namespace}...>
            Content: (annotation?, (simpleType*))
            </union>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        ZmemberTypesc                    s   g | ]} | qS r*   )r   ).0trC   r1   r*   r+   
<listcomp>G  s     z-SchemaVisitor.visit_union.<locals>.<listcomp>)
r@   splitr   rm   r   rs   r   r   r   Z	UnionType)	r1   rC   rD   membersr
   memberr3   r   r   r*   r   r+   r   +  s    

zSchemaVisitor.visit_unionc                 C   s   dS )aK  Specifies that an attribute or element value (or a combination of
        attribute or element values) must be unique within the specified scope.
        The value must be unique or nil.

        Definition::

            <unique
              id = ID
              name = NCName
              {any attributes with non-schema Namespace}...>
            Content: (annotation?, (selector, field+))
            </unique>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        Nr*   r   r*   r*   r+   visit_uniqueJ  s    zSchemaVisitor.visit_uniquec           	      C   s\   |  |}|r|S t|d| jj}| t|\}}| ||}t||}| 	|| dS )a  
        Definition::

            <attributeGroup
              id = ID
              name = NCName
              ref = QName
              {any attributes with non-schema Namespace...}>
            Content: (annotation?),
                     ((attribute | attributeGroup)*, anyAttribute?))
            </attributeGroup>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        r7   N)
rP   r   r.   rW   r   r   r   rK   AttributeGroupr<   )	r1   rC   rD   rG   r3   r   r   r   Zattribute_groupr*   r*   r+   visit_attribute_groupa  s    
z#SchemaVisitor.visit_attribute_groupc                 C   s   | dd}tj|dS )a#  
        Definition::

            <anyAttribute
              id = ID
              namespace = ((##any | ##other) |
                List of (anyURI | (##targetNamespace | ##local))) : ##any
              processContents = (lax | skip | strict): strict
              {any attributes with non-schema Namespace...}>
            Content: (annotation?)
            </anyAttribute>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        r   r   )r   )r@   rK   ZAnyAttribute)r1   rC   rD   r   r*   r*   r+   visit_any_attribute  s    z!SchemaVisitor.visit_any_attributec                 C   s   dS )a  Contains the definition of a notation to describe the format of
        non-XML data within an XML document. An XML Schema notation declaration
        is a reconstruction of XML 1.0 NOTATION declarations.

        Definition::

            <notation
              id = ID
              name = NCName
              public = Public identifier per ISO 8879
              system = anyURI
              {any attributes with non-schema Namespace}...>
            Content: (annotation?)
            </notation>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        Nr*   r   r*   r*   r+   visit_notation  s    zSchemaVisitor.visit_notation)urlc                 C   s   t || jj|| jjdS )N)rc   )r   r   Z
_transportrc   )r1   r   rb   r*   r*   r+   ri     s       zSchemaVisitor._retrieve_datac                 C   s"   |d k	st | |}t|| jS r-   )rV   rJ   r   r   )r1   r7   r*   r*   r+   r     s    
zSchemaVisitor._get_typec                 C   s   t |tjst|}|jdkr.td|j}|jtkrv| j|jsvt	d|j tj
tj|j|jd}| |d  |js| jjdkr| jjr| jjst| jj|j}|S )Nxmlr`   z'Auto importing missing known schema: %s)r>   r\   r~   )
isinstancer   r   r>   	localnamer   r.   Zis_importedrg   rh   rr   r   r(   rl   rX   rW   rf   )r1   r7   Zimport_noder*   r*   r+   rJ     s0    

  
zSchemaVisitor._create_qnamec                 C   sH   t |sd g fS |d jtjkr@| |d d }||dd  fS d |fS )Nr   ry   )lenrA   r   r   r   )r1   rt   r   r*   r*   r+   r     s    zSchemaVisitor._pop_annotationc                 C   sR   g }|D ]D}|j tjtjtjfkr:| ||}|| q| d|j  |q|S )NzUnexpected tag `%s`)rA   r   r   r"   r!   rF   rs   r   )r1   rC   rt   r   rZ   r   r*   r*   r+   r     s    z!SchemaVisitor._process_attributesc                 C   s   t || jj|jdS )Nr]   )r   r.   rj   r_   )r1   messagerC   r*   r*   r+   r     s
      zSchemaVisitor._create_error)N)N)Mr%   r&   r'   __doc__r2   r   r   rK   rr   r5   r   r9   r:   r   r;   r   r<   r=   rF   rM   rP   r[   rl   rx   r   Z_ElementtypingUnionrL   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   IOri   r   rJ   r   r   r   r   r    r   r   r   r!   r   r   r   r   r   r   r   r(   r   r   r"   r)   r?   r*   r*   r*   r+   r,   +   s     
(dIc K/L!"$-!,	
                 r,   c                 C   s:   |  dd}t|  dd}|dkr*d}nt|}||fS )z)Process the min/max occurrence indicatorsZ	maxOccurs1Z	minOccursZ	unbounded)r@   int)rC   r|   r{   r*   r*   r+   r     s    r   )loggingr   r   lxmlr   Zzeep.exceptionsr   Zzeep.loaderr   r   r   Z
zeep.utilsr   r   Zzeep.xsdr	   rK   r
   r   Zzeep.xsd.constr   r   Zzeep.xsd.types.unresolvedr   r   	getLoggerr%   rg   r   r,   r   r*   r*   r*   r+   <module>   s.   
         `