1
     ˆÆÅË498Ä¾È ò    ‹      µ”[�Ó0Fß÷W?ð–Lo ½8AKS‰Šn[u‹B(r7±šØ‘=Ýlùõ¸MÑV¨ ÁSâøÄßœ‰ö*™—_æ#òaù0!óOï'ã!¡Àçþ Y&íÄ ìtFSJh�Xß4M6ýÐØ–(°*àÐ*�a†�¯ØþY|EX!yæ¯„¡ÂRÆc�ÉgbÖÌ�Êä jk8Y®Áƒ°uJµ‚z‡…Ñ}È”Ã æbÃsé |®JPÎ8QÈŠ£5Ò´Þ	îÇiÊ Mñ¹pf+“íöõtÿ{¶�8ˆòÕ¡„ý­�ä‰—*×ESÓ˜©*'ÎŠˆ‚F;X•\oÂ\­)á%Fôëx8ûæ9ÀbÿvÌ8)¬\GôÝ0šÞÍ¢„ÆS^Iü<óà™{O¸CR™L­•Ì.Â�-ü¨¾_^0i™D:aU�Êè¼â©ª0¥«¹w}ã
{JµHö»nønŸ6c~¿M—ÉxÑ¶$Û/ñRÝ¿û’4žs+5’DY)ÐØÝQ²M|­W®¾û9$G«òiLH@Î’á½Õm}ªîÛzV:M•V˜¦¡hí‚~·ú}HãK3§*¿ÔÞëôÞ�› wC:×·�kB.Ivû/Kþá€ãá`p8–ÚßÄõÊ¾‰       ˆÆÅË490Ä¾È ê    ‹      ½”]oÚ0†ïû+<_ì.9„�I´Ž§Ž ‰¢™¶iÚ…‰qâÈ>Œv¿~•V°©ÛUœäÉ9ïc;f¯’é ý<’÷éÍ˜Ì>¼�„ ;€$MšÝ°'”Ð±ºØn·á¶»‚t9®‹.8´:ÃP¢¤ü‚ÕÏøa¹Ò_	C�…â£Rª{b–Ì�–ª•5`n=8U,Áƒ°q\.¬‚ÒHuç@»`c§„ÍòJX±vPèƒ¦®ïûVlaäC� úÝ|Ñ�ŒXìšÖCËæä»(ôªŒ)šŠr¦×+âlSÐ™),
Q~WzI‰(0¦_FƒéWÏù$õ×œ	â#-cúvO®¦qBùD¬qš¹ñÌ5åcá�¬�ÔK­äYø¶�oõ�ó“†I”Ë¬®P›ò¯x¬š™ÂUÂ»ö¼An�©‘¿›‘=™ŒÙõ|8I“Ñ¼™Y—xL÷kGùÌ%’D[•¡±{½¦×ëráª«Ã-Ù‡·z•#å„ä$ùÆ¨îñØ8ý”žtÕõ†ïå‡ÑqÎgÁÚ­vDQÐj“¨wÙyCÈ°ßéÿ7¿F•ÛF/aÐî÷~að‡{ö-ƒÝ	Á 9£~IH6    8   ˆl–ßi~”*_)%‚~àYS�ÿ�þY’¬ÙeŽ7_�¼Ð?ŸÍ„™}ÿÌÁ¿É 0o    """The ``lxml.isoschematron`` package implements ISO Schematron support on top
of the pure-xslt 'skeleton' implementation.
"""

import sys
import os.path
from lxml import etree as _etree # due to validator __init__ signature


# some compat stuff, borrowed from lxml.html
try:
    unicode
except NameError:
    # Python 3
    unicode = str
try:
    basestring
except NameError:
    # Python 3
    basestring = str


__all__ = ['extract_xsd', 'extract_rng', 'iso_dsdl_include',
           'iso_abstract_expand', 'iso_svrl_for_xslt1',
           'svrl_validation_errors', 'schematron_schema_valid',
           'stylesheet_params', 'Schematron']


# some namespaces
#FIXME: Maybe lxml should provide a dedicated place for common namespace
#FIXME: definitions?
XML_SCHEMA_NS = "http://www.w3.org/2001/XMLSchema"
RELAXNG_NS = "http://relaxng.org/ns/structure/1.0"
SCHEMATRON_NS = "http://purl.oclc.org/dsdl/schematron"
SVRL_NS = "http://purl.oclc.org/dsdl/svrl"


# some helpers
_schematron_root = '{%s}schema' % SCHEMATRON_NS
_xml_schema_root = '{%s}schema' % XML_SCHEMA_NS
_resources_dir = os.path.join(os.path.dirname(__file__), 'resources')


# the iso-schematron skeleton implementation steps aka xsl transformations
extract_xsd = _etree.XSLT(_etree.parse(
    os.path.join(_resources_dir, 'xsl', 'XSD2Schtrn.xsl')))
extract_rng = _etree.XSLT(_etree.parse(
    os.path.join(_resources_dir, 'xsl', 'RNG2Schtrn.xsl')))
iso_dsdl_include = _etree.XSLT(_etree.parse(
    os.path.join(_resources_dir, 'xsl', 'iso-schematron-xslt1',
                 'iso_dsdl_include.xsl')))
iso_abstract_expand = _etree.XSLT(_etree.parse(
    os.path.join(_resources_dir, 'xsl', 'iso-schematron-xslt1',
                 'iso_abstract_expand.xsl')))
iso_svrl_for_xslt1 = _etree.XSLT(_etree.parse(
    os.path.join(_resources_dir,
                 'xsl', 'iso-schematron-xslt1', 'iso_svrl_for_xslt1.xsl')))


# svrl result accessors
svrl_validation_errors = _etree.XPath(
    '//svrl:failed-assert', namespaces={'svrl': SVRL_NS})


# RelaxNG validator for schematron schemas
schematron_schema_valid = _etree.RelaxNG(
    file=os.path.join(_resources_dir, 'rng', 'iso-schematron.rng'))


def stylesheet_params(**kwargs):
    """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.
    """
    result = {}
    for key, val in kwargs.items():
        if isinstance(val, basestring):
            val = _etree.XSLT.strparam(val)
        elif val is None:
            raise TypeError('None not allowed as 