
    h3              
       X   S r SSKrSSKrSSKJr   \   \
  / SQrSrSrSrSrS	\-  rS	\-  r\R$                  R'                  \R$                  R)                  \5      S
5      r\R.                  " \R0                  " \R$                  R'                  \SS5      5      5      r\R.                  " \R0                  " \R$                  R'                  \SS5      5      5      r\R.                  " \R0                  " \R$                  R'                  \SSS5      5      5      r\R.                  " \R0                  " \R$                  R'                  \SSS5      5      5      r\R.                  " \R0                  " \R$                  R'                  \SSS5      5      5      r\R<                  " SS\0S9rSr  \RB                  " \R$                  R'                  \SS5      S9r"Sr S r$S r% " S S\RL                  5      r'g! \ a    \	r GNf = f! \ a    \	r
 GNf = f! \RF                   a    S r" NOf = f)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/schematronzhttp://purl.oclc.org/dsdl/svrlz
{%s}schema	resourcesxslzXSD2Schtrn.xslzRNG2Schtrn.xslziso-schematron-xslt1ziso_dsdl_include.xslziso_abstract_expand.xslziso_svrl_for_xslt1.xslz//svrl:failed-assertsvrl
namespacesFrngziso-schematron.rng)fileTc                     [        S5      e)Nz9Validating the ISO schematron requires iso-schematron.rng)NotImplementedError)args    M/var/www/html/env/lib/python3.13/site-packages/lxml/isoschematron/__init__.pyr
   r
   H   s    !"]^^    c                     0 nU R                  5        Hv  u  p#[        U[        5      (       a   [        R                  R                  U5      nO8Uc  [        S5      e[        U[        R                  5      (       d  [        U5      nX1U'   Mx     U$ )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       r   r   r   L   su     FLLNc:&&++&&s+C[HIIC..#,Cs # Mr   c                 v    [        U 5      n UR                  5        H  u  p#Uc  M
  X0U'   M     [        S0 U D6n U $ )zReturn a copy of paramsDict, updated with kwargsDict entries, wrapped as
stylesheet arguments.
kwargsDict entries with a value of None are ignored.
 )dictr   r   )
paramsDict
kwargsDictkvs       r   _stylesheet_param_dictr.   h   sD     j!J  "=qM # #0Z0Jr   c                   L  ^  \ rS rSrSr\R                  R                  r\R                  R                  r\R                  R                  r\r\R"                  " SS\0S9rS r\r\r\r\r\r\rSSSS0 0 0 S	S	S	S\\ 4U 4S
 jjr!S r"\#S 5       r$\#S 5       r%\#S 5       r&Sr'U =r($ )r   v   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-reportr   r   c                     SnUR                   [        :X  a  U R                  U5      nU$ UR                  R	                  UR
                  5      [        :X  a  U R                  U5      nU$ )zExtract 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   _extractSchematron._extract   sa     
;;****73J  ]]w~~.*<**73Jr   NTFc                   > [         TU ]  5         Xl        S U l        S U l        S U l        XR                  La  Xl        S n Ub/  [        R                  " U5      (       a  UnO8UR                  5       nO'Ub$  [        R                  " U5      R                  5       nUc  [!        S5      eUR"                  [$        :X  a  UnOU R'                  U5      nUc  [        R                  " S5      eU(       a  U R(                  " U40 UD6nU(       a  U R*                  " U40 UD6nU(       a7  [-        U5      (       d'  [        R                  " S[,        R.                  -  5      eU(       a  Xl        SU0n[1        UU5      nU R2                  " U40 UD6nU	(       a  UU l        [        R4                  " U5      U l        g ! [         a0    [        R                  " S[        R                  " 5       S   -  5      ef = f)NzNo tree or file given: %s   z
Empty treez=Document is not a schematron schema or schematron-extractablezinvalid 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
ValueErrorr2   _schematron_rootr=   _include_expandr
   	error_logr.   _compiler   
_validator)r:   r   r   includeexpandinclude_paramsexpand_paramscompile_paramsstore_schematron
store_xsltstore_reportrA   error_findervalidate_schemarootr<   compile_kwargsvalidator_xslt	__class__s                     r   rC   Schematron.__init__   s   
 	)#"&000&2# 
	A ##E** D ==?D!||D)113 <\**88''Jt,J--OQ Q zD^DJjBMBJ#::#F#F--/'1123 3 )!5)/OzD^D#1D  ++n5=  	A--+cllnQ.??A A	As    F6 #F6 4'F6 6:G0c                    U R                  5         U R                  U5      nU R                  (       a  X l        U R	                  U5      nU(       a  [
        R                  " U5      (       a.  UR                  5       R                  R                  =(       d    SnOUR                  R                  =(       d    SnU HH  nU R                  U R                  U R                  U R                  S[
        R                  " USS9US9  MJ     gg)zQValidate doc using Schematron.

Returns true if document is valid, false if not.
z<file>r   r"   )encoding)domaintypelevellinemessagefilenameFT)_clear_error_logrW   rD   rG   rI   r   rJ   getroottreedocinfoURL_append_log_message_domain_error_type_leveltostring)r:   r   r$   errorsfnameerrors         r   __call__Schematron.__call__0  s    
 	'&,#((0&&))+3377C8))5X((<<d.>.>++A"OOEIF"	 ) $   r   c                     U R                   $ )zbISO-schematron schema document (None if object has been initialized
with store_schematron=False).
)rE   r:   s    r   r<   Schematron.schematronI  s    
 r   c                     U R                   $ )z|ISO-schematron skeleton implementation XSLT validator document (None
if object has been initialized with store_xslt=False).
)rF   r~   s    r   rd   Schematron.validator_xsltP  s    
 ###r   c                     U R                   $ )zVISO-schematron validation result report (None if result-storing has
been turned off).
)rG   r~   s    r   validation_reportSchematron.validation_reportW  s    
 &&&r   )rE   rD   rI   rG   rW   rF   ))__name__
__module____qualname____firstlineno____doc__r   ErrorDomainsSCHEMATRONVrt   ErrorLevelsERRORrv   
ErrorTypesSCHEMATRONV_ASSERTru   r	   rH   r!   SVRL_NSASSERTS_AND_REPORTSr=   r   r4   r   r9   r   rS   r   rT   r   rV   rI   !schematron_schema_valid_supportedrC   r{   propertyr<   rd   r   __static_attributes____classcell__)re   s   @r   r   r   v   s    Wt !!--G%%F##66K *L ,,9G$&" LLH!G!H
 &!d4 ""R"'E,!B	76r2     $ $ ' 'r   r   )(r   rO   os.pathoslxmlr   r   r"   	NameErrorstrr   __all__XML_SCHEMA_NSr8   SCHEMATRON_NSr   rR   r3   pathjoindirname__file___resources_dirr   rL   r   r   r   r   r   r!   r	   r   RelaxNGr
   RelaxNGParseErrorr   r.   
_Validatorr   r(   r   r   <module>r      s:      . 32
6
*  -/ -/ bggooh7E kk&,,GGLL(89; <kk&,,GGLL(89; <;;v||GGLL(>') * +  kk&,,GGLL(>*,#- .  [[GGLL.0HJ"K L   '8:  %* !_$nnWW\\.%1EFH(,%8f'"" f'S  G
  Jh  ___s4   G5 H ,-H 5H HHHH)(H)