B þ|/\o0ã @s’dZddlZddlZddlmZyeWnek r@e ZYnXye Wnek rbe Z YnXdddddd d d d g Z d Z dZ dZdZdeZde Zej ej e¡d¡Ze e ej edd¡¡¡Ze e ej edd¡¡¡Ze e ej eddd¡¡¡Ze e ej eddd¡¡¡Ze e ej eddd¡¡¡ZejddeidZej ej edd¡dZ!d d „Z"d!d"„Z#Gd#d „d ej$ƒZ%dS)$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}schemaZ resourcesZxslzXSD2Schtrn.xslzRNG2Schtrn.xslziso-schematron-xslt1ziso_dsdl_include.xslziso_abstract_expand.xslziso_svrl_for_xslt1.xslz//svrl:failed-assertÚsvrl)Ú namespacesÚrngziso-schematron.rng)ÚfilecKsdi}xZ| ¡D]N\}}t|tƒr.tj |¡}n&|dkr@tdƒ‚nt|tjƒsTt|ƒ}|||<qW|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Ú_etreeÚXSLTZstrparamÚ TypeErrorÚXPathÚunicode)ÚkwargsÚresultÚkeyÚval©rúN/opt/alt/python37/lib64/python3.7/site-packages/lxml/isoschematron/__init__.pyr Fs    cCs<t|ƒ}x$| ¡D]\}}|dk r|||<qWtf|Ž}|S)z Return 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 kwargsDictÚkÚvrrrÚ_stylesheet_param_dictbs   r!c s´eZdZdZejjZejj Z ej j Z eZejddeidZdd„ZeZeZeZeZeZeZddddiiid d d def ‡fd d „ Zd d „Z e!dd„ƒZ"e!dd„ƒZ#e!dd„ƒZ$‡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_xsdZnsmapÚprefixÚ RELAXNG_NSÚ _extract_rng)ÚselfZelementÚ schematronrrrÚ_extractÎs    zSchematron._extractNTFc sftt|ƒ ¡| |_d|_d|_d|_| |jk r6| |_d} y<|dk r^t   |¡rT|} qt|  ¡} n|dk rtt   |¡  ¡} Wn*t k r t  dt ¡d¡‚YnX| dkr²tdƒ‚| jtkrÂ| }n | | ¡}|dkrÞt  d¡‚|rð|j|f|Ž}|r|j|f|Ž}t|ƒst  dtj¡‚|r*||_d| i}t||ƒ}|j|f|Ž}| rV||_t  |¡|_dS)NzNo tree or file given: %séz Empty treez=Document is not a schematron schema or schematron-extractablezinvalid schematron schema: %sÚphase)Úsuperr Ú__init__Ú _store_reportÚ _schematronÚ_validator_xsltÚ_validation_reportÚ ASSERTS_ONLYÚ_validation_errorsrÚ iselementZgetrootÚparseÚ ExceptionZSchematronParseErrorÚsysÚexc_infoÚ ValueErrorr"Ú_schematron_rootr*Ú_includeÚ_expandr Z error_logr!Ú_compilerÚ _validator)r(rrZincludeÚexpandZinclude_paramsZ expand_paramsZcompile_paramsZstore_schematronZ store_xsltZ store_reportr,Z error_finderÚrootr)Zcompile_kwargsÚvalidator_xslt)Ú __class__rrr.êsT        zSchematron.__init__c Cs| ¡| |¡}|jr||_| |¡}|rŒt |¡rH| ¡jj pDd}n |jj pRd}x2|D]*}|j |j |j |j dtj|dd|dqZWdSdS)zaValidate doc using Schematron. Returns true if document is valid, false if not. zrr)Úencoding)ZdomainÚtypeÚlevelÚlineÚmessageÚfilenameFT)Z_clear_error_logr?r/r2r4rr5Z getroottreeZdocinfoZURLZ_append_log_messageÚ_domainÚ _error_typeÚ_levelZtostring)r(rrÚerrorsZfnameÚerrorrrrÚ__call__"s"       zSchematron.__call__cCs|jS)zrISO-schematron schema document (None if object has been initialized with store_schematron=False). )r0)r(rrrr);szSchematron.schematroncCs|jS)zŒISO-schematron skeleton implementation XSLT validator document (None if object has been initialized with store_xslt=False). )r1)r(rrrrBBszSchematron.validator_xsltcCs|jS)zfISO-schematron validation result report (None if result-storing has been turned off). )r2)r(rrrÚvalidation_reportIszSchematron.validation_report)&Ú__name__Ú __module__Ú __qualname__Ú__doc__rZ ErrorDomainsZ SCHEMATRONVrJZ ErrorLevelsZERRORrLZ ErrorTypesZSCHEMATRONV_ASSERTrKrr3rÚSVRL_NSZASSERTS_AND_REPORTSr*rr$rr'rr<rr=rr>r4r.rOÚpropertyr)rBrPÚ __classcell__rr)rCrr ps.Q 5  )&rTr8Zos.pathÚosZlxmlrrrÚ NameErrorÚstrrÚ__all__Z XML_SCHEMA_NSr&Z SCHEMATRON_NSrUr;r#ÚpathÚjoinÚdirnameÚ__file__Z_resources_dirrr6rrrrrrrZRelaxNGr r r!Z _Validatorr rrrrÚsT