o
    i)                     @   sr  d 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 ddlm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 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"Z#d-ddZ$d-ddZ%dd Z&e Z'd.ddZ(		d.ddZ)dd  Z*d/d"d#Z+d$d% Z,i edd&dfd'd(Z-i edd&dfd)d*Z.dedd&dfd+d,Z/dS )0z[The `spyne.util.xml` module contains various Xml and Xml Schema related
utility functions.
    )isgenerator)etree)dirname)abspath)ServiceBaseApplicationsrpc)FakeContext)	Interface)	XmlSchema)XmlSchemaParser
Thier_reprPARSER)ProtocolMixin)XmlCloth)XmlDocument)unregister_application)BytesIO)tlistc                   @   s   e Zd Zdd ZdS )FakeApplicationc                 C   s   || _ d| _d| _d S )N )tnsservicesclasses)selfdefault_namespacer   r   N/var/www/html/LicenciasMIG/venv/lib/python3.10/site-packages/spyne/util/xml.py__init__.   s   
zFakeApplication.__init__N)__name__
__module____qualname__r   r   r   r   r   r   -   s    r   Nc                 C   sf   |du r
| d   }t|}t|}| D ]}||| || q|| t|}|  | S )zReturns the schema documents in a dict whose keys are namespace prefixes
    and values are Element objects.

    :param models: A list of spyne.model classes that will be represented in
                   the schema.
    Nr   )	get_namespacer   r
   resolve_namespace	add_classpopulate_interfacer   build_interface_documentget_interface_document)modelsr   fake_app	interfacemdocumentr   r   r   get_schema_documents4   s   
r,   c                 C   sZ   |du r
| d   }t|}t|}| D ]}||| || qt|}|  |jS )zReturns the validation schema object for the given models.

    :param models: A list of spyne.model classes that will be represented in
                   the schema.
    Nr   )r!   r   r
   r"   r#   r   build_validation_schemavalidation_schema)r'   r   r(   r)   r*   schemar   r   r   get_validation_schemaM   s   r0   c                 C   s(   | D ]}|j dd |_ t| qd S )N})tagsplit_dig)pareltr   r   r   r5   d   s   
r5   Fc                 C   sN   |du r| j }td}td|| || | |r#t| t| |d S )  Returns an ElementTree representation of a
    :class:`spyne.model.complex.ComplexModel` subclass.

    :param inst: The instance of the class to be serialized.
    :param cls: The class to be serialized. Optional.
    :param root_tag_name: The root tag string to use. Defaults to the output of
        ``value.__class__.get_type_name_ns()``.
    :param no_namespace: When true, namespace information is discarded.
    Nparentr   )	__class__r   Element_xml_object	to_parentr!   r5   cleanup_namespaces)instclsroot_tag_nameno_namespacer9   r   r   r   get_object_as_xmlm   s   

rC   c                    s    du r| j  |rttgdtddd}n$  }|du r$td f G  fdddt}t|g|tddd}t| tjd	|j	j
d
}|jd | |  | |rYt| t| |d S )r8   N Tpolymorphic)r   out_protocolz7Either set a namespace for %r or pass no_namespace=Truec                          e Zd Ze dd ZdS )z4get_object_as_xml_polymorphic.<locals>._DummyServicec                 S      d S Nr   _r   r   r   f      z6get_object_as_xml_polymorphic.<locals>._DummyService.fNr   r   r    r   rM   r   r@   r   r   _DummyService       rQ   r9   )nsmapr   )r:   r   r   r   r!   
ValueErrorr   r   r;   r)   rS   rG   r=   r5   r>   )r?   r@   rA   rB   appr   rQ   r9   r   rP   r   get_object_as_xml_polymorphic   s4   
rV   c                    sf      }|du rtd f G  fdddt}t|g|tddd}t| |jt|d | S )	Returns a native :class:`spyne.model.complex.ComplexModel` child from an
    ElementTree representation of the same class.

    :param elt: The xml document to be deserialized.
    :param cls: The class the xml document represents.
    NzPlease set a namespace for %rc                       rH   )z4get_xml_as_object_polymorphic.<locals>._DummyServicec                 S   rI   rJ   r   rK   r   r   r   rM      rN   z6get_xml_as_object_polymorphic.<locals>._DummyService.fNrO   r   rP   r   r   rQ      rR   rQ   TrE   )r   in_protocol)rU   )	r!   rT   r   r   r   r   rX   from_elementr	   )r7   r@   r   rQ   rU   r   rP   r   get_xml_as_object_polymorphic   s   rZ   utf8c           
      C   s   |du r| j }| du r|du rd}|du rd}t }t| d}t }tj||d)}d|j_t	g t
|j_| }|||| ||}	t|	rKJ W d   | S 1 sXw   Y  | S )r8   NTF)use_ns)encoding)r:   r!   r   r   r	   r   xmlfileoutprot_ctxdoctype_writtenr   r   protocol
prot_stackget_type_namesubserializer   getvalue)
r?   r@   rB   r]   ostr	xml_clothctxxftnretr   r   r   get_object_as_xml_cloth   s&   
rl   c                 C   s   t d|| S )rW   N)r<   rY   )r7   r@   r   r   r   get_xml_as_object   s   rm   )with_nsc                 C   s"   t j| td}t|||d|S )a  Parses a schema string and returns a _Schema object.

    :param s: The string or bytes object that contains the schema document.
    :param files: A dict that maps namespaces to path to schema files that
        contain the schema document for those namespaces.
    :param repr_: A callable that functions as `repr`.
    :param skip_errors: Skip parsing errors and return a partial schema.
        See debug log for details.

    :return: :class:`spyne.interface.xml_schema.parser._Schema` instance.
    parserrepr_skip_errors)r   
fromstringr   r   parse_schema)sfilesrr   rs   r7   r   r   r   parse_schema_string   s   rx   c                 C   s   t |||d| S )a  Parses a `<xs:schema>` element and returns a _Schema object.

    :param elt: The `<xs:schema>` element, an lxml.etree._Element instance.
    :param files: A dict that maps namespaces to path to schema files that
        contain the schema document for those namespaces.
    :param repr_: A callable that functions as `repr`.
    :param skip_errors: Skip parsing errors and return a partial schema.
        See debug log for details.

    :return: :class:`spyne.interface.xml_schema.parser._Schema` instance.
    rq   )r   ru   )r7   rw   rr   rs   r   r   r   parse_schema_element  s
   ry   c                 C   sH   |du rt  }tjt| d td}tt| }t||||d	|S )aE  Parses a schema file and returns a _Schema object. Schema files typically
    have the `*.xsd` extension.

    :param file_name: The path to the file that contains the schema document
        to be parsed.
    :param files: A dict that maps namespaces to path to schema files that
        contain the schema document for those namespaces.
    :param repr_: A callable that functions as `repr`.
    :param skip_errors: Skip parsing errors and return a partial schema.
        See debug log for details.

    :return: :class:`spyne.interface.xml_schema.parser._Schema` instance.
    Nrbro   rq   )
dictr   rt   openreadr   r   r   r   ru   )	file_namerw   rr   rs   r7   wdr   r   r   parse_schema_file  s   r   rJ   )NNF)NFr[   )0__doc__inspectr   lxmlr   os.pathr   r   spyner   r   r   spyne.contextr	   spyne.interfacer
   spyne.interface.xml_schemar   !spyne.interface.xml_schema.parserr   r   r   spyne.protocolr   spyne.protocol.clothr   spyne.protocol.xmlr   spyne.util.appregr   spyne.util.sixr   spyne.util.tlistr   objectr   r,   r0   r5   r<   rC   rV   rZ   rl   rm   rx   ry   r   r   r   r   r   <module>   sJ   



0
"





