bgo0 dZddlZddlZddlmZ en #e$re ZYnwxYw e n #e$re Z YnwxYwgdZ dZ dZ dZdZd ezZd e zZejejed Zejejejed d Zejejejed d Zejejejed ddZejejejed ddZejejejed ddZejddeiZej ejeddZ!dZ"dZ#Gddej$Z%dS)zxThe ``lxml.isoschematron`` package implements ISO Schematron support on top of the pure-xslt 'skeleton' implementation. N)etree) extract_xsd extract_rngiso_dsdl_includeiso_abstract_expandiso_svrl_for_xslt1svrl_validation_errorsschematron_schema_validstylesheet_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 resourcesxslzXSD2Schtrn.xslzRNG2Schtrn.xslziso-schematron-xslt1ziso_dsdl_include.xslziso_abstract_expand.xslziso_svrl_for_xslt1.xslz//svrl:failed-assertsvrl namespacesrngziso-schematron.rng)filec &i}|D]y\}}t|tr tj|}n:|t dt|tjst|}|||<z|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. Nz*None not allowed as a stylesheet parameter) items isinstance basestring_etreeXSLTstrparam TypeErrorXPathunicode)kwargsresultkeyvals n/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib64/python3.11/site-packages/lxml/isoschematron/__init__.pyr r FsFLLNNS c: & & +&&s++CC [HII IC.. #,,Cs Mc~t|}|D] \}}||||< tdi|}|S)zReturn a copy of paramsDict, updated with kwargsDict entries, wrapped as stylesheet arguments. kwargsDict entries with a value of None are ignored. N)dictrr ) paramsDict kwargsDictkvs r"_stylesheet_param_dictr+bsX j!!J  ""1 =JqM"00Z00J r#c eZdZdZejjZejj Z ej j Z eZejddeiZdZeZeZeZeZeZeZddddiiiddddef fd Zd 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. Here is a usage example:: >>> from lxml import etree >>> from lxml.isoschematron import Schematron >>> schematron = Schematron(etree.XML(''' ... ... ... id is the only permitted attribute name ... ... Attribute ... is forbidden ... ... ... ... '''), ... error_finder=Schematron.ASSERTS_AND_REPORTS) >>> xml = etree.XML(''' ... ... ... ... ... ''') >>> schematron.validate(xml) False >>> xml = etree.XML(''' ... ... ... ... ... ''') >>> schematron.validate(xml) True z///svrl:failed-assert | //svrl:successful-reportrrcd}|jtkr||}n0|j|jt kr||}|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_xsdnsmapprefix RELAXNG_NS _extract_rng)selfelement schematrons r"_extractzSchematron._extractsY  ;* * ***733JJ ]7> *j 8 8**733Jr#NTFc tt|| |_d|_d|_d|_| |jur| |_d} |,tj |r|} n=| } n(|&tj | } n<#t$r/tjdtjdzwxYw| t#d| jt&kr| }n|| }|tjd|r|j|fi|}|r|j|fi|}t/|s!tjdt.jz|r||_d| i}t3||}|j|fi|}| r||_tj||_dS)NzNo tree or file given: %sz Empty treez=Document is not a schematron schema or schematron-extractablezinvalid schematron schema: %sphase)superr __init__ _store_report _schematron_validator_xslt_validation_report ASSERTS_ONLY_validation_errorsr iselementgetrootparse ExceptionSchematronParseErrorsysexc_info ValueErrorr._schematron_rootr8_include_expandr error_logr+_compiler _validator)r5rrincludeexpandinclude_params expand_paramscompile_paramsstore_schematron store_xslt store_reportr; error_finderrootr7compile_kwargsvalidator_xslt __class__s r"r=zSchematron.__init__s= j$((***)#"& t0 0 0&2D # A #E**+ DD ==??DD!|D))1133 A A A-+clnnQ.??AA A A <\** * 8' ' 'JJt,,J  -OQQ Q  E&zDD^DDJ  C%jBBMBBJ&z22 3-/'1233 3  *)D !5)/OO&zDD^DD  2#1D  +n55s AB//9C(c |||}|jr||_||}|rt j|r!|jj pd}n|jj pd}|D]@}| |j |j |j dt j|d|AdSdS)zaValidate doc using Schematron. Returns true if document is valid, false if not. zrr)encoding)domaintypelevellinemessagefilenameFT)_clear_error_logrQr>rArCrrD getroottreedocinfoURL_append_log_message_domain _error_type_leveltostring)r5rrerrorsfnameerrors r"__call__zSchematron.__call__"s ''   -&,D #((00  && 6))++37C8 )5X $ $((+A"OEIFFF" )$$$$ 5tr#c|jS)zrISO-schematron schema document (None if object has been initialized with store_schematron=False). )r?r5s r"r7zSchematron.schematron;s r#c|jS)zISO-schematron skeleton implementation XSLT validator document (None if object has been initialized with store_xslt=False). )r@rus r"r]zSchematron.validator_xsltBs ##r#c|jS)zfISO-schematron validation result report (None if result-storing has been turned off). )rArus r"validation_reportzSchematron.validation_reportIs &&r#)&__name__ __module__ __qualname____doc__r ErrorDomains SCHEMATRONVrl ErrorLevelsERRORrn ErrorTypesSCHEMATRONV_ASSERTrmr rBrSVRL_NSASSERTS_AND_REPORTSr8rr0rr4rrMrrNrrPrCr=rspropertyr7r]rx __classcell__)r^s@r"r r psGPPf!-G   %F#6K*L&&,9G$&&&   "LLH!G!H &!d4 ""R"'E,666666666666p2  X $$X$ ''X'''''r#r )&r|rIos.pathoslxmlrrr NameErrorstrr__all__ XML_SCHEMA_NSr3 SCHEMATRON_NSrrLr/pathjoindirname__file___resources_dirrrFrrrrrrr RelaxNGr r r+ _Validatorr r%r#r"rs   GGGGGJJJJJ  . . .3 2 6 * -/-/bgooh77EEfk,&,GLL(899;;<< fk,&,GLL(899;;<< 6;|v|GLL(>')) * *++"fk,&,GLL(>*,,#-#-..!V[GLL.0HJJ"K"KLL &'8::: )&. ne-A B BDDD8   ^'^'^'^'^'"^'^'^'^'^'s&00