Viewing File: /opt/hc_python/lib/python3.12/site-packages/lxml/isoschematron/__pycache__/__init__.cpython-312.pyc

�

_��g�3�
�^�dZddlZddlZddlmZ	e	e
gd�ZdZdZ
dZdZd	ezZd	ezZej$j'ej$j)e�d
�Zej.ej0ej$j'edd���Zej.ej0ej$j'edd
���Zej.ej0ej$j'eddd���Zej.ej0ej$j'eddd���Zej.ej0ej$j'eddd���Zej<ddei��ZdZ 	ejBej$j'edd���Z"dZ d�Z$d�Z%Gd�dejL�Z'y#e$re	ZY���wxYw#e$re	Z
Y���wxYw#ejF$rd�Z"Y�LwxYw)zxThe ``lxml.isoschematron`` package implements ISO Schematron support on top
of the pure-xslt 'skeleton' implementation.
�N)�etree)	�extract_xsd�extract_rng�iso_dsdl_include�iso_abstract_expand�iso_svrl_for_xslt1�svrl_validation_errors�schematron_schema_valid�stylesheet_params�
Schematronz http://www.w3.org/2001/XMLSchemaz#http://relaxng.org/ns/structure/1.0z$http://purl.oclc.org/dsdl/schematronzhttp://purl.oclc.org/dsdl/svrlz
{%s}schema�	resources�xslzXSD2Schtrn.xslzRNG2Schtrn.xslziso-schematron-xslt1ziso_dsdl_include.xslziso_abstract_expand.xslziso_svrl_for_xslt1.xslz//svrl:failed-assert�svrl��
namespacesF�rngziso-schematron.rng)�fileTc��td��)Nz9Validating the ISO schematron requires iso-schematron.rng)�NotImplementedError)�args �L/opt/hc_python/lib64/python3.12/site-packages/lxml/isoschematron/__init__.pyr
r
Hs��!�"]�^�^�c��i}|j�D]l\}}t|t�r tjj|�}n2|�t
d��t|tj�st|�}|||<�n|S)a(Convert keyword args to a dictionary of stylesheet parameters.
    XSL stylesheet parameters must be XPath expressions, i.e.:

    * string expressions, like "'5'"
    * simple (number) expressions, like "5"
    * valid XPath expressions, like "/a/b/text()"

    This function converts native Python keyword arguments to stylesheet
    parameters following these rules:
    If an arg is a string wrap it with XSLT.strparam().
    If an arg is an XPath object use its path string.
    If arg is None raise TypeError.
    Else convert arg to string.
    z*None not allowed as a stylesheet parameter)	�items�
isinstance�
basestring�_etree�XSLT�strparam�	TypeError�XPath�unicode)�kwargs�result�key�vals    rrrLss���F��L�L�N���S��c�:�&��+�+�&�&�s�+�C�
�[��H�I�I��C����.��#�,�C���s��#��Mrc�r�t|�}|j�D]
\}}|��	|||<�tdi|��}|S)z�Return a copy of paramsDict, updated with kwargsDict entries, wrapped as
    stylesheet arguments.
    kwargsDict entries with a value of None are ignored.
    �)�dictrr)�
paramsDict�
kwargsDict�k�vs    r�_stylesheet_param_dictr.hsH���j�!�J�� � �"���1��=��J�q�M�#�#�0�Z�0�J��rc
�F��eZdZdZej
jZejjZ
ejjZ
eZej ddei��Zd�ZeZeZeZeZeZeZddddiiiddddeef
�fd	�	Z d
�Z!e"d��Z#e"d��Z$e"d
��Z%�xZ&S)ra�
An ISO Schematron validator.

    Pass a root Element or an ElementTree to turn it into a validator.
    Alternatively, pass a filename as keyword argument 'file' to parse from
    the file system.

    Schematron is a less well known, but very powerful schema language.
    The main idea is to use the capabilities of XPath to put restrictions on
    the structure and the content of XML documents.

    The standard behaviour is to fail on ``failed-assert`` findings only
    (``ASSERTS_ONLY``).  To change this, you can either pass a report filter
    function to the ``error_finder`` parameter (e.g. ``ASSERTS_AND_REPORTS``
    or a custom ``XPath`` object), or subclass isoschematron.Schematron for
    complete control of the validation process.

    Built on the Schematron language 'reference' skeleton pure-xslt
    implementation, the validator is created as an XSLT 1.0 stylesheet using
    these steps:

     0) (Extract from XML Schema or RelaxNG schema)
     1) Process inclusions
     2) Process abstract patterns
     3) Compile the schematron schema to XSLT

    The ``include`` and ``expand`` keyword arguments can be used to switch off
    steps 1) and 2).
    To set parameters for steps 1), 2) and 3) hand parameter dictionaries to the
    keyword arguments ``include_params``, ``expand_params`` or
    ``compile_params``.
    For convenience, the compile-step parameter ``phase`` is also exposed as a
    keyword argument ``phase``. This takes precedence if the parameter is also
    given in the parameter dictionary.

    If ``store_schematron`` is set to True, the (included-and-expanded)
    schematron document tree is stored and available through the ``schematron``
    property.
    If ``store_xslt`` is set to True, the validation XSLT document tree will be
    stored and can be retrieved through the ``validator_xslt`` property.
    With ``store_report`` set to True (default: False), the resulting validation
    report document gets stored and can be accessed as the ``validation_report``
    property.

    If ``validate_schema`` is set to False, the validation of the schema file
    itself is disabled.  Validation happens by default after building the full
    schema, unless the schema validation file cannot be found at import time,
    in which case the validation gets disabled.  Some lxml distributions exclude
    this file due to licensing issues.  ISO-Schematron validation can then still
    be used normally, but the schemas themselves cannot be validated.

    Here is a usage example::

      >>> from lxml import etree
      >>> from lxml.isoschematron import Schematron

      >>> schematron = Schematron(etree.XML('''
      ... <schema xmlns="http://purl.oclc.org/dsdl/schematron" >
      ...   <pattern id="id_only_attribute">
      ...     <title>id is the only permitted attribute name</title>
      ...     <rule context="*">
      ...       <report test="@*[not(name()='id')]">Attribute
      ...         <name path="@*[not(name()='id')]"/> is forbidden<name/>
      ...       </report>
      ...     </rule>
      ...   </pattern>
      ... </schema>'''),
      ... error_finder=Schematron.ASSERTS_AND_REPORTS)

      >>> xml = etree.XML('''
      ... <AAA name="aaa">
      ...   <BBB id="bbb"/>
      ...   <CCC color="ccc"/>
      ... </AAA>
      ... ''')

      >>> schematron.validate(xml)
      False

      >>> xml = etree.XML('''
      ... <AAA id="aaa">
      ...   <BBB id="bbb"/>
      ...   <CCC/>
      ... </AAA>
      ... ''')

      >>> schematron.validate(xml)
      True
    z///svrl:failed-assert | //svrl:successful-reportrrc���d}|jtk(r|j|�}|S|jj	|j
�tk(r|j|�}|S)a
Extract embedded schematron schema from non-schematron host schema.
        This method will only be called by __init__ if the given schema document
        is not a schematron schema by itself.
        Must return a schematron schema document tree or None.
        N)�tag�_xml_schema_root�_extract_xsd�nsmap�get�prefix�
RELAXNG_NS�_extract_rng)�self�element�
schematrons   r�_extractzSchematron._extract�sa���
��;�;�*�*��*�*�7�3�J����]�]�
�
�w�~�~�
.�*�
<��*�*�7�3�J��rNTFc���t�|��|
|_d|_d|_d|_||jur||_d}	|�)tj|�r|}n6|j�}n%|�#tj|�j�}|�t!d��|j"t$k(r|}n|j'|�}|�tjd��|r|j(|fi|��}|r|j*|fi|��}|
r1t-|�s&tjdt,j.z��|r||_d|i}t1||�}|j2|fi|��}|	r||_tj4|�|_y#t$r.tjdtj�dz��wxYw)NzNo tree or file given: %s�z
Empty treez=Document is not a schematron schema or schematron-extractablezinvalid schematron schema: %s�phase)�super�__init__�
_store_report�_schematron�_validator_xslt�_validation_report�ASSERTS_ONLY�_validation_errorsr�	iselement�getroot�parse�	Exception�SchematronParseError�sys�exc_info�
ValueErrorr1�_schematron_rootr<�_include�_expandr
�	error_logr.�_compiler�
_validator)r9rr�include�expand�include_params�
expand_params�compile_params�store_schematron�
store_xslt�store_reportr?�error_finder�validate_schema�rootr;�compile_kwargs�validator_xslt�	__class__s                  �rrAzSchematron.__init__�s����
	����)������#���"&����t�0�0�0�&2�D�#���
	A�� ��#�#�E�*� �D� �=�=�?�D��!��|�|�D�)�1�1�3���<��\�*�*��8�8�'�'��J����t�,�J����-�-�O�Q�
Q��&����z�D�^�D�J��%����j�B�M�B�J��#:�:�#F��-�-�/�'�1�1�2�3�
3��)�D��!�5�)��/���O��&����z�D�^�D���#1�D� � �+�+�n�5����=�	A��-�-�+�c�l�l�n�Q�.?�?�A�
A�	A�s
�AF�7Gc���|j�|j|�}|jr||_|j	|�}|r�tj|�r)|j�jjxsd}n|jjxsd}|D]L}|j|j|j|jdtj|d��|���Nyy)zaValidate doc using Schematron.

        Returns true if document is valid, false if not.
        z<file>rr")�encoding)�domain�type�level�line�message�filenameFT)�_clear_error_logrUrBrErGrrH�getroottree�docinfo�URL�_append_log_message�_domain�_error_type�_level�tostring)r9rr$�errors�fname�errors      r�__call__zSchematron.__call__0s���
	
��������'�����&,�D�#��(�(��0�������&��)�)�+�3�3�7�7�C�8���
�
�)�)�5�X�����(�(��<�<�d�.>�.>��+�+�A�"�O�O�E�I�F�"�	)�$� ��rc��|jS)zrISO-schematron schema document (None if object has been initialized
        with store_schematron=False).
        )rC�r9s rr;zSchematron.schematronIs��
���rc��|jS)z�ISO-schematron skeleton implementation XSLT validator document (None
        if object has been initialized with store_xslt=False).
        )rDrzs rrbzSchematron.validator_xsltPs��
�#�#�#rc��|jS)zfISO-schematron validation result report (None if result-storing has
        been turned off).
        )rErzs r�validation_reportzSchematron.validation_reportWs��
�&�&�&r)'�__name__�
__module__�__qualname__�__doc__r�ErrorDomains�SCHEMATRONVrq�ErrorLevels�ERRORrs�
ErrorTypes�SCHEMATRONV_ASSERTrrr	rFr!�SVRL_NS�ASSERTS_AND_REPORTSr<rr3rr8rrQrrRrrTrG�!schematron_schema_valid_supportedrArx�propertyr;rbr}�
__classcell__)rcs@rrrvs����W�t�!�!�-�-�G�
�
�
�
%�
%�F��#�#�6�6�K�*�L�&�&�,�,�9��G�$�&���"�L��L��H�!�G�!�H�
&��!��d�4� "�"�R�"'�E���,�!B�	76�r�2� �� ��$��$��'��'rr)(r�rM�os.path�os�lxmlrrr"�	NameError�strr�__all__�
XML_SCHEMA_NSr7�
SCHEMATRON_NSr�rPr2�path�join�dirname�__file__�_resources_dirrrJrrrrrr!r	r��RelaxNGr
�RelaxNGParseErrorrr.�
_Validatorrr(rr�<module>r�sR����� �����.��3�
�
2�
�6�
�
*�� �-�/���-�/�������b�g�g�o�o�h�7��E���f�k�k�,�&�,�,��G�G�L�L���(8�9�;�<���f�k�k�,�&�,�,��G�G�L�L���(8�9�;�<���6�;�;�|�v�|�|��G�G�L�L���(>�'�)� *�+��"�f�k�k�,�&�,�,��G�G�L�L���(>�*�,�#-�.��!�V�[�[������G�G�L�L���.�0H�J�"K�L��&�������'8�:��%*�!�_�,�f�n�n�
�W�W�\�\�.�%�1E�
F�H��(,�%��8�f'��"�"�f'��S���G���
���J���h���_�_�_�s4�G;�H	�/0H�;H�H�	H�H�H,�+H,
Back to Directory File Manager