o
    i7J                     @   s  d dl Z d dl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 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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% G dd dej&Z'G dd dej&Z(G dd dej&Z)G dd  d ej&Z*e+d!kre,  dS dS )"    N)pprintetree)Application)rpc)xml)NS_XSD)	ByteArray)ComplexModel)XmlAttribute)XmlData)AnyXml)Integer)	Mandatory)Unicode)Uuid)Boolean)Soap11Soap12)Serviceget_schema_documents)parse_schema_element)parse_schema_string)	XmlSchema)CodeGeneratorc                   @   s|   e Z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dd Zdd Zdd Zdd ZdS )TestXmlSchemac                    s   G dd dt  G  fdddt}t|gdtddt d t g}|d	 }ttj|d
d t|j	ddt
iddks@J t|j	ddt
iddksOJ d S )Nc                   @   s(   e Zd ZdZeddZeddZeZdS )z1TestXmlSchema.test_choice_tag.<locals>.SomeObject	badass_nsnumbers)xml_choice_groupN)	__name__
__module____qualname____namespace__r   onetwor   punk r'   r'   d/var/www/html/LicenciasMIG/venv/lib/python3.10/site-packages/spyne/test/interface/test_xml_schema.py
SomeObject4   
    

r)   c                       "   e Zd Ze d fddZdS )z5TestXmlSchema.test_choice_tag.<locals>.KickassService_returnsc                         S Nr'   ctxr)   r'   r(   wooo<      z:TestXmlSchema.test_choice_tag.<locals>.KickassService.woooN)r    r!   r"   r   r3   r'   r2   r'   r(   KickassService;       r5   
kickass.nslxml	validatortnsin_protocolout_protocolr<   Tpretty_printzR/xs:schema/xs:complexType[@name="SomeObject"]/xs:sequence/xs:element[@name="punk"]xs
namespacesr   z[/xs:schema/xs:complexType[@name="SomeObject"]/xs:sequence/xs:choice/xs:element[@name="one"])r
   r   r   r   r   printr   tostringlenxpathr   )selfr5   docsdocr'   r2   r(   test_choice_tag3   s(   
zTestXmlSchema.test_choice_tagc                    sf   G dd dt }G dd d|G fdddt  G  fdddt}t|gd	td
dt d d S )Nc                   @   s:   e Zd ZdeeddfdeeddfdeeddfgZdS )zUTestXmlSchema.test_customized_class_with_empty_subclass.<locals>.SummaryStatsOfDoubleMinrequireduseMaxAvgN)r    r!   r"   r   r   
_type_infor'   r'   r'   r(   SummaryStatsOfDoubleQ   s
    rS   c                   @   s   e Zd ZdZdS )zMTestXmlSchema.test_customized_class_with_empty_subclass.<locals>.SummaryStatsz this is an empty base class N)r    r!   r"   __doc__r'   r'   r'   r(   SummaryStatsV   s    rU   c                       s0   e Zd Zd jddfd fd fdefgZdS )zHTestXmlSchema.test_customized_class_with_empty_subclass.<locals>.PayloadStat1F)nillableStat2Stat3DummyN)r    r!   r"   	customizer   rR   r'   )rU   r'   r(   PayloadY   s    r\   c                       r+   )zPTestXmlSchema.test_customized_class_with_empty_subclass.<locals>.JackedUpServicer,   c                    r.   r/   r'   r0   r\   r'   r(   
GetPayload`   r4   z[TestXmlSchema.test_customized_class_with_empty_subclass.<locals>.JackedUpService.GetPayloadN)r    r!   r"   r   r^   r'   r]   r'   r(   JackedUpService_   r6   r_   r7   r8   r9   r;   r
   r   r   r   )rH   rS   r_   r'   )r\   rU   r(   )test_customized_class_with_empty_subclassP   s   
z7TestXmlSchema.test_customized_class_with_empty_subclassc                    sV   G dd dt G fdddt  G  fdddt}t|gdtdd	t d
 d S )Nc                   @   s"   e Zd ZdZdeeddfgZdS )z<TestXmlSchema.test_namespaced_xml_attribute.<locals>.Releasehttp://usefulinc.com/ns/doap#about+http://www.w3.org/1999/02/22-rdf-syntax-ns#nsN)r    r!   r"   r#   r   r   rR   r'   r'   r'   r(   Releaseo   s    rg   c                       s4   e Zd ZdZdeeddfd jeddfgZdS )	z<TestXmlSchema.test_namespaced_xml_attribute.<locals>.Projectrb   rc   rd   re   releaseinf)
max_occursN)	r    r!   r"   r#   r   r   r[   floatrR   r'   )rg   r'   r(   Projectw   s    rl   c                       s"   e Zd Zeee ddd ZdS )z?TestXmlSchema.test_namespaced_xml_attribute.<locals>.RdfServicer,   c                 S      d S r/   r'   )r1   abr'   r'   r(   	some_call      zITestXmlSchema.test_namespaced_xml_attribute.<locals>.RdfService.some_callN)r    r!   r"   r   r   rp   r'   )rl   r'   r(   
RdfService   s    rr   spynepir8   r9   r;   r`   )rH   rr   r'   )rl   rg   r(   test_namespaced_xml_attributen   s   	
z+TestXmlSchema.test_namespaced_xml_attributec                    sB   G dd dt  G  fdddt}t|gdtddt d d S )	Nc                   @   s   e Zd ZdZeeZeZdS )zKTestXmlSchema.test_customized_simple_type_in_xml_attribute.<locals>.Productsome_nsN)	r    r!   r"   r#   r   r   idr   editionr'   r'   r'   r(   Product   s    rx   c                           e Zd Ze  ddd ZdS )zOTestXmlSchema.test_customized_simple_type_in_xml_attribute.<locals>.SomeServicer,   c                 S      t d|j |S Nzedition_id: %rlogginginfo
edition_idr1   productr'   r'   r(   echo_product      z\TestXmlSchema.test_customized_simple_type_in_xml_attribute.<locals>.SomeService.echo_productNr    r!   r"   r   r   r'   rx   r'   r(   SomeService       
r   ru   r8   r9   r;   r`   )rH   r   r'   r   r(   ,test_customized_simple_type_in_xml_attribute   s   
z:TestXmlSchema.test_customized_simple_type_in_xml_attributec                    s   G dd dt  G  fdddt}t|gdtddt d}d	ti}tjt }t|j}|	  |
 d
 jd|dd }|jd|dd d| ksMJ |jd|dd d| ks\J |jd|dd d| kskJ d S )Nc                   @   s(   e Zd ZdZeddZeddZeZdS )z4TestXmlSchema.test_binary_encodings.<locals>.Productru   hex)encodingbase64N)r    r!   r"   r#   r	   r   base64_1base64_2r'   r'   r'   r(   rx      r*   rx   c                       ry   )z8TestXmlSchema.test_binary_encodings.<locals>.SomeServicer,   c                 S   rz   r{   r|   r   r'   r'   r(   r      r   zETestXmlSchema.test_binary_encodings.<locals>.SomeService.echo_productNr   r'   r   r'   r(   r      r   r   ru   r8   r9   r;   rA   r<   z!//xs:complexType[@name="Product"]rB   r   z$//xs:element[@name="base64_1"]/@typez%s:base64Binaryz$//xs:element[@name="base64_2"]/@typez//xs:element[@name="hex"]/@typez%s:hexBinary)r
   r   r   r   r   rf   PREFMAPr   	interfacebuild_interface_documentget_interface_documentrG   )rH   r   app_nspref_xsrA   eltr'   r   r(   test_binary_encodings   sL   

z#TestXmlSchema.test_binary_encodingsc                 C   s.   G dd dt }t|gdtddt d d S )Nc                   @   s(   e Zd ZdZeeeeddd ZdS )zLTestXmlSchema.test_multilevel_customized_simple_type.<locals>.ExampleServicez"http://xml.company.com/ns/example/r,   c                 S   s   d| S )NzYour UUID: %sr'   )r1   uuidr'   r'   r(   say_my_uuid   s   zXTestXmlSchema.test_multilevel_customized_simple_type.<locals>.ExampleService.say_my_uuidN)	r    r!   r"   __tns__r   Mr   r   r   r'   r'   r'   r(   ExampleService   s    r   r7   r8   r9   r;   )r   r   r   )rH   r   r'   r'   r(   &test_multilevel_customized_simple_type   s   
z4TestXmlSchema.test_multilevel_customized_simple_typec                 C   s   t jt jd G dd dt}t|g}ttj|d dd |d jddt	id	}t
|d
ks2J |d jd dks=J |d jd dksHJ d S )N)levelc                   @   s"   e Zd ZdZede dddZdS )z,TestXmlSchema.test_any_tag.<locals>.SomeTypezoz{%s}any##otherlax)
schema_tag	namespaceprocess_contentsN)r    r!   r"   r#   r   r   anythingr'   r'   r'   r(   SomeType   s
    

r   r<   Tr?   z	//xsd:anyxsdrB      r   r   r   processContentsr   )r}   basicConfigDEBUGr
   r   rD   r   rE   rG   r   rF   attrib)rH   r   rI   _anyr'   r'   r(   test_any_tag   s   
zTestXmlSchema.test_any_tagc                    s   dG fdddt G fdddt  G  fdddt}t|gdtdd	t d
}t|j}|  |  | d }t	t
j|dd |S )Nr7   c                       s0   e Zd ZZeeZ reeZdS ee	ZdS )zATestXmlSchema._build_xml_data_test_schema.<locals>.ProductEditionN)
r    r!   r"   r#   r   r   rv   r   namer   r'   )custom_rootr<   r'   r(   ProductEdition   s    r   c                       s   e Zd ZZeeZ ZdS )z:TestXmlSchema._build_xml_data_test_schema.<locals>.ProductN)r    r!   r"   r#   r   r   rv   rw   r'   )r   r<   r'   r(   rx      s    rx   c                       ry   )zATestXmlSchema._build_xml_data_test_schema.<locals>.ExampleServicer,   c                 S   rm   r/   r'   r   r'   r'   r(   r      rq   zMTestXmlSchema._build_xml_data_test_schema.<locals>.ExampleService.say_my_uuidN)r    r!   r"   r   r   r'   r   r'   r(   r      r   r   r8   r9   r;   r<   Tr?   )r
   r   r   r   r   r   r   build_validation_schemar   rD   r   rE   )rH   r   r   r   schemarJ   r'   )rx   r   r   r<   r(   _build_xml_data_test_schema   s   
z)TestXmlSchema._build_xml_data_test_schemac                 C   s6   | j dd}t| d jddtiddksJ d S )NFr   r<   zh/xs:schema/xs:complexType[@name="ProductEdition"]/xs:simpleContent/xs:extension/xs:attribute[@name="id"]rA   rB   r   )r   rF   r   rG   r   rH   r   r'   r'   r(   test_xml_data_schema_doc	  s   z&TestXmlSchema.test_xml_data_schema_docc                 C   0   | j dd}|jtdsJ |jjjd S )NFr   z
            <Product id="00000000-0000-0000-0000-000000000000" xmlns="kickass.ns">
                <edition id="00000000-0000-0000-0000-000000000001">punk</edition>
            </Product>
        r   validation_schemavalidater   
fromstring	error_log
last_errorr   r'   r'   r(   _test_xml_data_validation  s   z'TestXmlSchema._test_xml_data_validationc                 C   r   )NTr   a  
            <Product id="00000000-0000-0000-0000-000000000000" xmlns="kickass.ns">
                <edition id="00000000-0000-0000-0000-000000000001">
                    00000000-0000-0000-0000-000000000002
                </edition>
            </Product>
        r   r   r'   r'   r(   %_test_xml_data_validation_custom_root  s   z3TestXmlSchema._test_xml_data_validation_custom_rootc                 C   s   ddl m} ddlm} dd }dddd	}G d
d dt}||gdd }t|j|dd ||d\}t|dks=J t||ddksHJ t||ddksSJ d S )Nr   r   r   c                 S      | j |dtidS NrA   rB   rG   r   oxr'   r'   r(   <lambda>)      z)TestXmlSchema.test_subs.<locals>.<lambda>aaccdd)s0s2s3c                   @   s4   e Zd ZdZeZeddZeddZedddZdS )	z"TestXmlSchema.test_subs.<locals>.Cr   bb)sub_namer   )sub_nsr   )r   r   N)	r    r!   r"   r#   r   rn   ro   cdr'   r'   r'   r(   C1  s    

r   r<   Tr?   zxs:complexType/xs:sequence   zxs:element[@name="a"]r   zxs:element[@name="bb"])r8   r   spyne.util.xmlr   r
   rD   rE   rF   )rH   r   r   rG   mr   r   seqr'   r'   r(   	test_subs&  s   zTestXmlSchema.test_subsc                 C   sf   dd }G dd dt }t|gd }ttj|dd ||d\}|j}d	|v r/|d	 d
ks1J d S )Nc                 S   r   r   r   r   r'   r'   r(   r   H  r   z.TestXmlSchema.test_mandatory.<locals>.<lambda>c                   @   s   e Zd ZdZeeeZdS )z'TestXmlSchema.test_mandatory.<locals>.Cr   N)r    r!   r"   r#   r   r   r   foor'   r'   r'   r(   r   J  s    r   r<   Tr?   z(xs:complexType/xs:attribute[@name="foo"]rO   rM   )r
   r   rD   r   rE   r   )rH   rG   r   r   r   attrsr'   r'   r(   test_mandatoryG  s   zTestXmlSchema.test_mandatoryc                    s`   dd G  fdddt }t|gd }ttj|dd |jdd	tid
 gks.J d S )Nru   zSome Docc                       s   e Zd ZZe dZdS )z0TestXmlSchema.test_annotation.<locals>.SomeClass)rJ   N)r    r!   r"   r#   r   	some_attrr'   rJ   r<   r'   r(   	SomeClassX      r   r<   Tr?   z//xs:documentation/text()rA   rB   )r
   r   rD   r   rE   rG   r   )rH   r   r   r'   r   r(   test_annotationT  s   zTestXmlSchema.test_annotationN)r    r!   r"   rK   ra   rt   r   r   r   r   r   r   r   r   r   r   r   r'   r'   r'   r(   r   2   s    ##	!r   c                   @   sL   e Z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S )TestParseOwnXmlSchemac                 C   s   d}G dd dt }t|g|d }ttj|dd t|}t|| j || jd }| | ks7J |	 |	 ksAJ t
|jt
|jksMJ d S )Nru   c                   @   s   e Zd ZdZeZdS )z2TestParseOwnXmlSchema.test_simple.<locals>.SomeGuyru   N)r    r!   r"   r#   r   rv   r'   r'   r'   r(   SomeGuye  s    r   r<   Tr?   )r
   r   rD   r   rE   r   r   typesget_type_nameget_namespacedictrR   )rH   r<   r   r   objectsNewGuyr'   r'   r(   test_simplec  s   z!TestParseOwnXmlSchema.test_simplec                    s   d G  fdddt }t|g d }ttj|dd t|}t|  j |d jd }|jd j	j
dks:J |jd j	jd	ksEJ |jd j	jd
ksPJ |jd j	jdks[J d S )Nru   c                       s    e Zd Z ZedddddZdS )z>TestParseOwnXmlSchema.test_customized_unicode.<locals>.SomeGuy
   rn      r   )max_lenpatternmin_lendefaultN)r    r!   r"   r#   r   r   r'   r<   r'   r(   r   w  s    r   r<   Tr?   r   r   r   rn   r   )r
   r   rD   r   rE   r   r   r   rR   
Attributesr   r   r   r   rH   r   r   r   r   r'   r   r(   test_customized_unicodeu  s   z-TestParseOwnXmlSchema.test_customized_unicodec                    x   d G  fdddt }t|g d }ttj|dd t|}t|  j |d jd }|jd j	j
dks:J d S )Nru   c                       s   e Zd Z ZeddZdS )z;TestParseOwnXmlSchema.test_boolean_default.<locals>.SomeGuyTr   N)r    r!   r"   r#   r   baldr'   r   r'   r(   r     r   r   r<   Tr?   r   r
   r   rD   r   rE   r   r   r   rR   r   r   r   r'   r   r(   test_boolean_default  s   z*TestParseOwnXmlSchema.test_boolean_defaultc                    r   )Nru   c                          e Zd Z ZeeddZdS )zETestParseOwnXmlSchema.test_boolean_attribute_default.<locals>.SomeGuyTr   N)r    r!   r"   r#   r   r   r   r'   r   r'   r(   r         r   r<   Tr?   r   r   r   r'   r   r(   test_boolean_attribute_default  s   z4TestParseOwnXmlSchema.test_boolean_attribute_defaultc                    s~   d G  fdddt }t|g d }ttj|dd t|}t| t|  j |d jd }|jd j	t
u s=J d S )Nru   c                       s   e Zd Z ZeeZdS )z5TestParseOwnXmlSchema.test_attribute.<locals>.SomeGuyNr    r!   r"   r#   r   r   r   r'   r   r'   r(   r     s    r   r<   Tr?   r   )r
   r   rD   r   rE   r   r   r   rR   typer   r   r'   r   r(   test_attribute  s   z$TestParseOwnXmlSchema.test_attributec                    s   d G  fdddt }t|g d }ttj|dd t|}t|  j |d jd }|jd j	j
tu s:J |jd j	jjdksFJ d S )	Nru   c                       r   )zJTestParseOwnXmlSchema.test_attribute_with_customized_type.<locals>.SomeGuyr   r   Nr   r'   r   r'   r(   r     r   r   r<   Tr?   r   r   )r
   r   rD   r   rE   r   r   r   rR   r   __orig__r   r   r   r   r'   r   r(   #test_attribute_with_customized_type  s   z9TestParseOwnXmlSchema.test_attribute_with_customized_typec                    sR   G dd dt }G dd d| G  fdddt}t|gdtdd	t d
 d S )Nc                   @   s   e Zd ZeeddZdS )zDTestParseOwnXmlSchema.test_inherited_attribute.<locals>.DeviceEntityrM   rN   N)r    r!   r"   r   r   tokenr'   r'   r'   r(   DeviceEntity  s    r  c                   @   s   e Zd ZeeZdS )zDTestParseOwnXmlSchema.test_inherited_attribute.<locals>.DigitalInputN)r    r!   r"   r   r   	IdleStater'   r'   r'   r(   DigitalInput      r  c                       s$   e Zd Ze dd fddZdS )zCTestParseOwnXmlSchema.test_inherited_attribute.<locals>.SomeServicebare)r-   _body_stylec                    r.   r/   r'   r0   r  r'   r(   GetDigitalInput  r4   zSTestParseOwnXmlSchema.test_inherited_attribute.<locals>.SomeService.GetDigitalInputN)r    r!   r"   r   r	  r'   r  r'   r(   r     s    
r   some_tnsr8   r9   )r=   r>   r`   )rH   r  r   r'   r  r(   test_inherited_attribute  s   
z.TestParseOwnXmlSchema.test_inherited_attributec                    sX   G dd dt  G  fdddt G fdddt}t|gddtdd	t d
 d S )Nc                   @   s(   e Zd ZedddZejddddZdS )zMTestParseOwnXmlSchema.test_simple_type_explicit_customization.<locals>.Headerr   F)
min_occursrW      )r  rW   r   N)r    r!   r"   r   testr   r[   pwr'   r'   r'   r(   Header  s    r  c                       s   e Zd Z jdddZdS )zMTestParseOwnXmlSchema.test_simple_type_explicit_customization.<locals>.ParamsFr   )rW   r  N)r    r!   r"   r[   
sendHeaderr'   )r  r'   r(   Params  s    r  c                       s    e Zd Ze eddd ZdS )zSTestParseOwnXmlSchema.test_simple_type_explicit_customization.<locals>.DummyServicer,   c                 S   s   dS )N42r'   )r1   serviceParamsr'   r'   r(   loadServices  rq   z`TestParseOwnXmlSchema.test_simple_type_explicit_customization.<locals>.DummyService.loadServicesN)r    r!   r"   r   r   r  r'   )r  r'   r(   DummyService  r   r  dummyr8   r9   )r<   r   r=   r>   r`   )rH   r  r'   )r  r  r(   'test_simple_type_explicit_customization  s   
z=TestParseOwnXmlSchema.test_simple_type_explicit_customizationN)r    r!   r"   r   r   r   r   r   r   r  r  r'   r'   r'   r(   r   b  s    r   c                   @   s   e Zd Zdd ZdS )TestParseForeignXmlSchemac                 C   s   d}d}t |}t|| j || jd }|j}tt| t|d ts(J |d jtu s1J t|d t	s:J |d jtu sCJ d S )Nru   a  <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="some_ns"
            elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xsd:complexType name="SomeGuy">
        <xsd:simpleContent>
            <xsd:extension base="xsd:string">
                <xsd:attribute name="attr" type="xsd:string" use="optional"/>
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>
</xsd:schema>r   _dataattr)
r   r   r   rR   r   
issubclassr   r   r   r   )rH   r<   r   r   r   tir'   r'   r(   test_simple_content  s   z-TestParseForeignXmlSchema.test_simple_contentN)r    r!   r"   r  r'   r'   r'   r(   r    r  r  c                   @   s   e Zd Zdd Zdd ZdS )TestCodeGenerationc                 G   s   t |d }t|S )Nr<   )r   r   )rH   args
schema_docr'   r'   r(   _get_schema  s   zTestCodeGeneration._get_schemac                    sD   d G  fdddt }| |  }t  |}d|v s J d S )Nru   c                       s    e Zd Z ZdefdefgZdS )z2TestCodeGeneration.test_simple.<locals>.SomeObjectisN)r    r!   r"   r#   r   r   rR   r'   re   r'   r(   r)     s
    r)   zhclass SomeObject(_ComplexBase):
    _type_info = [
        ('i', Integer),
        ('s', Unicode),
    ])r
   r"  r   genpy)rH   r)   r$  coder'   re   r(   r     s   zTestCodeGeneration.test_simpleN)r    r!   r"   r"  r   r'   r'   r'   r(   r    s    r  __main__)-r}   unittestr   r8   r   spyner   r   spyne.constr   rf   spyne.const.xmlr   spyne.modelr	   r
   r   r   r   r   r   r   r   r   r   spyne.protocol.soapr   r   spyne.servicer   r   r   r   r   spyne.interface.xml_schemar    spyne.interface.xml_schema.genpyr   TestCaser   r   r  r  r    mainr'   r'   r'   r(   <module>   sF     2 