o
    g                     @   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	extensionnotationN)__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$   r%    r*   r*   I/home/ubuntu/webapp/venv/lib/python3.10/site-packages/zeep/xsd/visitor.pyr      s.    r   c                   @   sd  e Zd ZdZdd ZdejdejfddZ	dejdej
d	d
fddZdejd	d
fddZdejdejfddZdejdejd	d
f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d#ejd$ejd	ejej
ejf fd%d&Zd'd( Zd)d* Zd+d, Z d-d. Z!d/d0 Z"d1d2 Z#d3d4 Z$d5d6 Z%d7d8 Z&d9d: Z'd;d< Z(d=d> Z)d?d@ Z*dAdB Z+dCdD Z,dEdF Z-dGdH Z.dIdJ Z/dKdL Z0dMdN Z1dOdP Z2d^dQej3fdRdSZ4dTdU Z5dVdW Z6dXdY Z7dZd[ Z8d\d] Z9i e:j;e(e:j<ee:j=e-e:j>ee:j?e1e:j@ee:jAd
e:jBd
e:jCe)e:jDe*e:jEe+e:jFee:jGee:jHee:jIe'e:jJe0e:jKe2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      | j || d S r-   )r.   register_elementr1   r3   r4   r*   r*   r+   r6   C      zSchemaVisitor.register_elementnamereturnNc                 C   r5   r-   )r.   register_attribute)r1   r9   r4   r*   r*   r+   r;   F      z SchemaVisitor.register_attributec                 C   r5   r-   )r.   register_typer7   r*   r*   r+   r=   K   r8   zSchemaVisitor.register_typec                 C   r5   r-   )r.   register_groupr7   r*   r*   r+   r>   N   r8   zSchemaVisitor.register_groupc                 C   r5   r-   )r.   register_attribute_groupr7   r*   r*   r+   r?   Q   r<   z&SchemaVisitor.register_attribute_groupc                 C   r5   r-   )r.   register_import)r1   	namespacer.   r*   r*   r+   r@   V   r8   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parent
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_qnamerA   xsd_elementsRefAttributerD   r   )r1   rF   rM   rK   r*   r*   r+   process_ref_attribute`   s   


z#SchemaVisitor.process_ref_attributec                 K   s   t |d}|s	d S | |}|jtjkrtj}n|jtjkr"tj}n|jtj	kr,tj
}n	|jtjkr5tj}||j|| jfi |S )NrK   )r   rN   rD   r   r   rO   
RefElementr   rP   r   RefGroupr"   RefAttributeGroupr   )r1   rF   kwargsrK   clsr*   r*   r+   process_referencen   s   

zSchemaVisitor.process_referencec                 C   s^   |dusJ | d}|r|| j_| dd| j_| dd| j_|D ]	}| j||d q#d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rG   )rC   r.   _target_namespace_element_form_attribute_formrJ   )r1   rF   tnschildr*   r*   r+   visit_schema   s   
zSchemaVisitor.visit_schemac           	      C   s*  d}| d}| d}|rt| jj|| jj}|s(| jjs(td| jj|j	d|s0|s0d| j_
| jj||}|rHtd| | || |S |sP|dkrPd	}|sZtd
| dS | j|| jjd}| d}|r||r|||kr|td| | jj|j	d|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

        NrA   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_urlrX   zaThe namespace defined on the xsd:import doesn't match the imported targetNamespace located at %r )target_namespace)rC   r   r   settingsr.   	_base_urlr]   r   locationrf   _has_empty_import	documentsget_by_namespace_and_locationloggerdebugr@   _retrieve_data	_locationcreate_new_document)	r1   rF   rG   schema_noderA   rm   r.   
schema_tnsr   r*   r*   r+   visit_import   s^   


zSchemaVisitor.visit_importc                 C   st  | ds	td| d}|| jv rdS | j|| jjd}| j| |j ds{|j ds6|j dr{d|j dpA|jd i}|	|j t
j|j|d}|D ]}|| qS|j D ]
\}}	|||	 q`|j dsy|jd |jd< |}| jj}
| jj}| jj}| dd| j_| d	d| j_t|| jj| j_|D ]	}| j||d
 q|
| 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

        rc   zschemaLocation is requiredNrh   rX   )nsmaprY   rZ   r[   r\   )rC   NotImplementedErrorr0   rs   r.   rl   addry   attribupdater   ElementrD   appenditemsr/   r^   r_   r   rJ   )r1   rF   rG   rm   rv   ry   newra   keyvalueelement_form_defaultattribute_form_defaultri   r*   r*   r+   visit_include  sJ   




zSchemaVisitor.visit_includec              	   C   sR  |j tjk}|st|\}}nd}d}|s)|j tjkrd}| j|||d}|r)|S |d| jj}|dks7|r@t	|d| jj
}n
t|d }t|}	d}
|	rsd}|	D ]}|j tjkr_qV|j tjtjfv rr|rlJ | ||}
qV|
st	|d}|r| |j}
nt }
|d	d
k}|d}tj||
|||||d}|r| || |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	qualifiedr9   Ntypenillabletruedefault)r9   type_r   r   r   r   	is_global)rD   r   r   _process_occurs_attrsr   rW   rC   r.   r^   r   r]   r   QNamestripr   r   r   r   rJ   	_get_typetext	xsd_typesAnyTyperO   r~   r6   )r1   rF   rG   r   r   r   rI   element_formr3   childrenxsd_typer   ra   	node_typer   r   r   r*   r*   r+   visit_elementT  s^   

zSchemaVisitor.visit_elementrF   rG   c                 C   s:  |j tjk}|d}|r'td|}|r'| d }t||j}t	|| j}|s4| j
||d}|r4|S |d| jj}|dksB|rKt|d| jj}	nt|d}	| t|\}
}|rg| |d |}nt|d}|rt| |}nt }|d	d
k}|d}tj|	|||d}|r|	dusJ | |	| |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   rL   r   r   r9   r   userequiredr   )r   r   r   N)rD   r   r   rC   rematchgroupsr   ry   r   rQ   r.   r_   r   r]   r   r   _pop_annotationr   visit_simple_typer   r   r   rO   	Attributer;   )r1   rF   rG   r   rM   r   r3   rI   attribute_formr9   r   r   r   r   r   r   attrr*   r*   r+   visit_attribute  s@   


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rB| |	|}t||| j}
n!|	j tj	krO| |	|}
n|	j tjkr\| |	|}
ntd|	j  |
dusiJ |rq| ||
 |
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

        r9   T	AnonymousFz({http://www.w3.org/2001/XMLSchema}stringr   zUnexpected child: %rN)rD   r   r   rC   r   ry   r.   r]   r   r   r#   visit_restriction_simple_typer   
visit_listr   visit_unionAssertionErrorr=   )r1   rF   rG   r9   r   	base_typer3   r   r   ra   r   r*   r*   r+   r     s*   
zSchemaVisitor.visit_simple_typec                 C   sZ  g }d}|j tjkr|d}d}n|d}d}t||j| jj}d|d}t|t	j
f|}	d}
| t|\}}|rA|d j nd}|tjkr[| |d |\}}|	||||d	}
nH|tjkrs| |d |}|	d||d
|}
n0|rd}|tjtjtjtjfv 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}anyTyper9   TFzzeep.xsd.dynamic_types)r'   	_xsd_nameNr   )
attributesr$   r3   r   )r3   r   )r   r   r3   r   r*   )rD   r   r   rC   r   ry   r.   r]   r   r   ComplexTyper   r   r   visit_simple_contentr   visit_complex_contentr   r   r   r   poprJ   _process_attributesr=   )r1   rF   rG   r   r   r9   r   r3   cls_attributesxsd_clsr   r   	first_tagr   rU   r   ra   r*   r*   r+   visit_complex_type0  sJ   





z SchemaVisitor.visit_complex_typec                 C   sh   t |}|d }|jtjkr| ||\}}}|||dS |jtjkr2| ||\}}}|||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   rD   r   r#   !visit_restriction_complex_contentr$   visit_extension_complex_content)r1   rF   rG   r   ra   baser   r   r*   r*   r+   r   |  s   

z#SchemaVisitor.visit_complex_contentc                 C   sH   t |}|d }|jtjkr| ||S |jtjkr | ||S td)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 extension)r   rD   r   r#    visit_restriction_simple_contentr$   visit_extension_simple_contentr   )r1   rF   rG   r   ra   r*   r*   r+   r     s   z"SchemaVisitor.visit_simple_contentc                 C   sN   t |d}|r| |S | t|\}}|d jtjkr%| |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   rD   r   r   r   )r1   rF   rG   	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   rF   rG   r   r   r*   r*   r+   r     s   

z.SchemaVisitor.visit_restriction_simple_contentc           
      C      t |d}| |}| t|\}}d}g }|r;|d }	|	jtjtjtjtj	fv r5|
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   rD   r   r   r   r   r   r   rJ   r   
r1   rF   rG   r   r   r   r   r   r   ra   r*   r*   r+   r     s   



z/SchemaVisitor.visit_restriction_complex_contentc           
      C   r   )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   rF   rG   r   r   r   r   r   r*   r*   r+   r   7  s
   

z,SchemaVisitor.visit_extension_simple_contentc                 C      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   rF   rG   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   rC   rO   Any)r1   rF   rG   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 ]!}	|	j|vr6| d|	j |	| |	|}
|
dusBJ ||
 q&d|vsNJ |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

        r   z%Unexpected element %s in xsd:sequenceN)r   r   r    r   r   r   r   r   rO   Sequencer   r   rD   _create_errorrJ   r   )r1   rF   rG   	sub_typesr   r   rI   r   r   ra   itemr*   r*   r+   visit_sequence{  s(   

zSchemaVisitor.visit_sequencec           	      C   sh   t jt jg}t }| t|\}}|D ]}|j|v s J || ||}|	| qd|vs2J |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   rO   Allr   r   rD   rJ   r   )	r1   rF   rG   r   rI   r   r   ra   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

        r   r9   r   )r9   ra   )r   rW   r   r.   r]   r   r   rJ   rO   GrouprD   r   r   r>   )r1   rF   rG   r   r   rI   r3   r   r   ra   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


        itemTyper   )r   r   r   r   r   r   ListType)r1   rF   rG   	item_typesub_typesubnodesra   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>
        r   )r   r   r   rJ   r   rO   Choice)
r1   rF   rG   r   r   r   r   choicesra   r   r*   r*   r+   visit_choice  s   zSchemaVisitor.visit_choicec           	         sr     d}g }|r!| 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

        memberTypesc                    s   g | ]} | qS r*   )r   ).0trF   r1   r*   r+   
<listcomp>G  s    z-SchemaVisitor.visit_union.<locals>.<listcomp>)
rC   splitr   ry   r   r   r   r   r   	UnionType)	r1   rF   rG   membersr
   memberr3   r   r   r*   r   r+   r   +  s   


zSchemaVisitor.visit_unionc                 C   r   )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

        r9   N)
rW   r   r.   r]   r   r   r   rO   AttributeGroupr?   )	r1   rF   rG   rK   r3   r   r   r   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   )rC   rO   AnyAttribute)r1   rF   rG   r   r*   r*   r+   visit_any_attribute  s   z!SchemaVisitor.visit_any_attributec                 C   r   )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)rk   )r   r   
_transportrk   )r1   r   ri   r*   r*   r+   rs     s   zSchemaVisitor._retrieve_datac                 C   s"   |d usJ |  |}t|| jS r-   )rN   r   r   )r1   r9   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v r;| j|js;t	d|j tj
tj|j|jd}| |d  |jsU| jjdkrU| jjrU| jjsUt| jj|j}|S )Nxmlrg   z'Auto importing missing known schema: %s)rA   rc   r   )
isinstancer   r   rA   	localnamer   r.   is_importedrq   rr   r~   r   r)   rx   r^   r]   rn   )r1   r9   import_noder*   r*   r+   rN     s*   

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   r   )lenrD   r   r   r   )r1   r   r   r*   r*   r+   r     s   zSchemaVisitor._pop_annotationc                 C   sP   g }|D ]!}|j tjtjtjfv r| ||}|| q| d|j  ||S )NzUnexpected tag `%s`)rD   r   r   r"   r!   rJ   r   r   )r1   rF   r   r   ra   r   r*   r*   r+   r     s   z!SchemaVisitor._process_attributesc                 C   s   t || jj|jdS )Nrd   )r   r.   rt   rf   )r1   messagerF   r*   r*   r+   r     s   zSchemaVisitor._create_errorr-   )Mr&   r'   r(   __doc__r2   r   r   rO   r~   r6   r   r;   r=   r   r>   r   r?   r@   rJ   rQ   rW   rb   rx   r   r   _ElementtypingUnionrP   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   IOrs   r   rN   r   r   r   r   r    r   r   r   r!   r   r   r   r   r   r   r   r)   r   r   r"   r%   rB   r*   r*   r*   r+   r,   +   s    


(dIb
K/L!"$-!,	
	
r,   c                 C   s@   |  dd}t|  dd}|dkrd}||fS t|}||fS )z)Process the min/max occurrence indicators	maxOccurs1	minOccurs	unbounded)rC   int)rF   r   r   r*   r*   r+   r     s   r   )loggingr   r   lxmlr   zeep.exceptionsr   zeep.loaderr   r   r   
zeep.utilsr   r   zeep.xsdr	   rO   r
   r   zeep.xsd.constr   r   zeep.xsd.types.unresolvedr   r   	getLoggerr&   rq   r   r,   r   r*   r*   r*   r+   <module>   s0    
         `