o
    j*                     @   s  d dl Z e deddd Zd dlZd dlZd dlZd dl	m
  mZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZmZmZmZmZmZmZmZm Z  d d
l!m"Z" d dl#m$Z$ d dl%m&Z& d dl%m'Z' d dl%m(Z( d dl%m)Z) d dl%m*Z* d dl%m+Z+ d dl%m,Z, d dl%m-Z- ee.dd ee&ee'ee(ee)e"e*iZ/ee.dd ee+e e,ee-eee-eee-eee-eiZ0ej1Z2ej3Z4ej5Z6ej7Z8ej9e4 Z:G dd de.Z;G dd de$Z<dS )    N.)etree)chain)cdict)odict)	toposort2)	SimpleModel	ByteArrayComplexModelBaseFaultDecimalDateTimeDateTimeUnicode)EnumBase)InterfaceDocumentBase)byte_array_add)
simple_add)complex_add)	fault_add)enum_add)simple_get_restriction_tag)unicode_get_restriction_tag)Tget_range_restriction_tagc                 C      d S N )	interfaceclstagsr   r   `/var/www/html/LicenciasMiG/venv/lib/python3.10/site-packages/spyne/interface/xml_schema/_base.py<lambda>5       r#   c                 C   r   r   r   )selfr    r   r   r"   r#   >   r$   c                   @   s   e Zd Zdd ZdS )
SchemaInfoc                 C   s   t  | _t  | _d S r   )r   elementstypesr%   r   r   r"   __init__O   s   zSchemaInfo.__init__N)__name__
__module____qualname__r*   r   r   r   r"   r&   N   s    r&   c                       s   e Zd ZdZ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d Zdd Zdd Zdd Z  ZS ) 	XmlSchemaa  The implementation of a subset of the Xml Schema 1.0 object definition
    document standard.

    The standard is available in three parts as follows:
    http://www.w3.org/TR/xmlschema-0/
    http://www.w3.org/TR/xmlschema-1/
    http://www.w3.org/TR/xmlschema-2/

    :param interface: A :class:`spyne.interface.InterfaceBase` instance.

    Supported events:
        * document_built:
            Called right after the document is built. The handler gets the
            ``XmlSchema`` instance as the only argument.

        * xml_document_built:
            Called right after the document is built. The handler gets the
            ``XmlSchema`` instance as the only argument. Only called from this
            class.
    	qualifiedc                    s\   t t| | || _|dv sJ i | _d | _| jj| jjj	 }t
|t i| _t | _d S )N)r/   unqualified)superr.   r*   element_form_defaultschema_dictvalidation_schemar   prefmapapptnsr   r&   
namespacessetcomplex_types)r%   r   r2   pref	__class__r   r"   r*   j   s   zXmlSchema.__init__c                 C   s.   ||vr| | t| }|| || d S d S r   )add_add_handlers)r%   r    r!   handlerr   r   r"   r>   x   s
   
zXmlSchema.addc                 C   s   t | }|| |S r   )_get_restriction_tag_handlers)r%   r    r@   r   r   r"   get_restriction_tag   s   
zXmlSchema.get_restriction_tagFc                 C   s6  i | _ t }tt| jjD ]}| || q| jD ]k}| 	|}| jj
| jj|  D ]9}t|td}|d| | j|}|rT| j|drT|dd|  tj|d }	|	d ure|d|	 q,| j| j D ]}
||
 qn| j| j D ]}
||
 q~q|   | jd|  | jd|  d S )Nimport	namespaceFschemaLocation%s.xsddocument_builtxml_document_built)r3   r9   r   from_iterabler   r   depsr>   r8   get_schema_nodeimportsnsmapr   
SubElementnsXSDget_namespace_prefixgetschema_locationr(   valuesappendr'    add_missing_elements_for_methodsevent_manager
fire_event)r%   with_schema_locationr!   r    r;   schemarD   import_import_prefslnoder   r   r"   build_schema_nodes   s4   

zXmlSchema.build_schema_nodesc                    s   fdd} j j j j } |j} j| }| D ]o}|jjj}|d u r,|j	 }||vrRt
td}|d| |d|j j  |||< || |jd ur|jjj}|d u re|j	 }||vrt
td}|d| |d|j j  |||< || qd S )Nc                  3   s4     j jD ]} | j D ]
}|jd u r|V  qqd S r   )r   servicespublic_methodsrT   aux)servicemethodr)   r   r"   missing_methods   s   
zCXmlSchema.add_missing_elements_for_methods.<locals>.missing_methodselementnametype)r   r5   r7   get_schema_infor'   r3   
in_message
Attributessub_nameget_type_namer   ElementrO   rP   r9   get_type_name_nsrU   out_message)r%   re   pref_tnsr'   schema_rootrd   rg   rf   r   r)   r"   rV      s<   









z*XmlSchema.add_missing_elements_for_methodsc              
   C   s  | j dd | j| jj}tjdd}td| jj||f  z| j	 D ]9\}}t
j|d| }t|d}t|j|dd W d	   n1 sMw   Y  td
|| jj| f  q&tt
j|d| d&}ztt|| _W n ty   |d td  w W d	   n1 sw   Y  t| td|  W d	S  ty } zt| td|   d	}~ww )zBBuild application schema specifically for xml validation purposes.T)rY   spyne)prefixz>generating schema for targetNamespace=%r, prefix: %r in dir %rrF   wb)pretty_printNzwriting %r for ns %srr   zThis could be a Spyne error. Unless you're sure the reason for this error is outside Spyne, please open a new issue with a minimal test case that reproduces it.zSchema built. Removed %rz The schema files are left at: %r)r_   r   rQ   r7   tempfilemkdtemploggerdebugr3   itemsospathjoinopenr   ElementTreewriterM   	XMLSchemaparser4   	Exceptionseekerrorshutilrmtree	exception)r%   rq   tmp_dir_namekv	file_namefer   r   r"   build_validation_schema   sB   



z!XmlSchema.build_validation_schemac                 C   s`   || j vr)tjtd| jjd}|d| jj|  |d| j || j |< |S | j | }|S )z2Return schema node for the given namespace prefix.rZ   )rM   targetNamespaceelementFormDefault)	r3   r   rn   rO   rP   r   rM   r9   r2   )r%   r;   rZ   r   r   r"   rK      s   


zXmlSchema.get_schema_nodec                 C   s   | j S r   )r3   r)   r   r   r"   get_interface_document  s   z XmlSchema.get_interface_documentc                 C   s   |    d S r   )r_   r)   r   r   r"   build_interface_document  s   z"XmlSchema.build_interface_documentc                 C   s>   | | jdd }| |}|jjp| }||j|< d S )N:r   )get_element_name_nsr   splitri   rk   rl   rm   r'   )r%   r    r^   r;   schema_inforg   r   r   r"   add_element  s   
zXmlSchema.add_elementc                 C   ,   |  }|| j}| |}||j|< d S r   rm   rQ   r   ri   r(   r%   r    r^   tnr;   r   r   r   r"   add_simple_type     
zXmlSchema.add_simple_typec                 C   r   r   r   r   r   r   r"   add_complex_type  r   zXmlSchema.add_complex_typec                 C   s,   || j v r| j | }|S t  }| j |< |S )zReturns the SchemaInfo object for the corresponding namespace. It
        creates it if it doesn't exist.

        The SchemaInfo object holds the simple and complex type definitions
        for a given namespace.)r8   r&   )r%   rt   rZ   r   r   r"   ri      s
   

zXmlSchema.get_schema_info)r/   )F)r+   r,   r-   __doc__r*   r>   rB   r_   rV   r   rK   r   r   r   r   r   ri   __classcell__r   r   r<   r"   r.   T   s    
%$(r.   )=logging	getLoggerr   r+   r   rz   r}   r   rx   spyne.const.xmlconstxmlrO   lxmlr   	itertoolsr   spyne.util.cdictr   spyne.util.odictr   spyne.util.toposortr   spyne.modelr	   r
   r   r   r   r   r   r   r   spyne.model.enumr   spyne.interfacer    spyne.interface.xml_schema.modelr   r   r   r   r   r   r   r   objectr?   rA   NS_XSD_ns_xsdNS_WSA_ns_wsa	NS_WSDL11_ns_wsdlNS_WSDL11_SOAP_ns_soapPREFMAP	_pref_wsar&   r.   r   r   r   r"   <module>   s\   ,	

