a ao0 @sdZddlZddlZddlmZzeWney>e ZYn0ze Wney^e Z Yn0gdZ dZ dZ dZdZd eZd e Zejejed Zeeejed d Zeeejed d Zeeejed ddZeeejed ddZeeejed ddZejddeidZej ejedddZ!ddZ"ddZ#Gdddej$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}schemaZ resourcesZxslzXSD2Schtrn.xslzRNG2Schtrn.xslziso-schematron-xslt1ziso_dsdl_include.xslziso_abstract_expand.xslziso_svrl_for_xslt1.xslz//svrl:failed-assertsvrlZ namespacesrngziso-schematron.rng)filecKs`i}|D]N\}}t|tr,tj|}n&|dur>tdnt|tjsRt|}|||<q |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_etreeXSLTZstrparam TypeErrorXPathunicode)kwargsresultkeyvalrA/usr/lib64/python3.9/site-packages/lxml/isoschematron/__init__.pyr Fs    r cCs<t|}|D]\}}|dur|||<qtfi|}|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 )Z paramsDictZ kwargsDictkvrrr_stylesheet_param_dictbs  r!c seZdZdZejjZejj Z ej j Z eZejddeidZddZeZeZeZeZeZeZddddiiid d d def fd d Zd d Z e!ddZ"e!ddZ#e!ddZ$Z%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-reportr r cCs8d}|jtkr||}n|j|jtkr4||}|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_xsdZnsmapprefix RELAXNG_NS _extract_rng)selfelement schematronrrr_extracts    zSchematron._extractNTFc sptt|| |_d|_d|_d|_| |jur6| |_d} z<|dur^t |rT|} qt| } n|durtt | } Wn(t yt dtdYn0| durtd| jtkr| }n || }|durt d|r|j|fi|}|r |j|fi|}t|s$t dtj|r0||_d| i}t||}|j|fi|}| r`||_t ||_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 iselementZgetrootparse ExceptionZSchematronParseErrorsysexc_info ValueErrorr"_schematron_rootr+_include_expandr Z error_logr!_compiler _validator)r(rrZincludeexpandZinclude_paramsZ expand_paramsZcompile_paramsZstore_schematronZ store_xsltZ store_reportr-Z error_finderrootr*Zcompile_kwargsvalidator_xslt __class__rrr/s\         zSchematron.__init__c Cs|||}|jr||_||}|rt|rH|jj pDd}n |jj pRd}|D]*}|j |j |j |j dtj|dd|dqXdSdS)zaValidate doc using Schematron. Returns true if document is valid, false if not. zrr)encoding)domaintypelevellinemessagefilenameFT)Z_clear_error_logr@r0r3r5rr6Z getroottreeZdocinfoZURLZ_append_log_message_domain _error_type_levelZtostring)r(rrerrorsfnameerrorrrr__call__"s$     zSchematron.__call__cCs|jS)zrISO-schematron schema document (None if object has been initialized with store_schematron=False). )r1r(rrrr*;szSchematron.schematroncCs|jS)zISO-schematron skeleton implementation XSLT validator document (None if object has been initialized with store_xslt=False). )r2rTrrrrCBszSchematron.validator_xsltcCs|jS)zfISO-schematron validation result report (None if result-storing has been turned off). )r3rTrrrvalidation_reportIszSchematron.validation_report)&__name__ __module__ __qualname____doc__rZ ErrorDomainsZ SCHEMATRONVrMZ ErrorLevelsZERRORrOZ ErrorTypesZSCHEMATRONV_ASSERTrNrr4rSVRL_NSZASSERTS_AND_REPORTSr+rr$rr'rr=rr>rr?r5r/rSpropertyr*rCrU __classcell__rrrDrr ps8S8  r )&rYr9Zos.pathosZlxmlrrr NameErrorstrr__all__Z XML_SCHEMA_NSr&Z SCHEMATRON_NSrZr<r#pathjoindirname__file__Z_resources_dirrr7rrrrrrrZRelaxNGr r r!Z _Validatorr rrrrsb