GRAYBYTE WORDPRESS FILE MANAGER5927

Server IP : 198.54.121.189 / Your IP : 216.73.216.140
System : Linux premium69.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
PHP Version : 7.4.33
Disable Function : NONE
cURL : ON | WGET : ON | Sudo : OFF | Pkexec : OFF
Directory : /opt/hc_python/lib/python3.12/site-packages/lxml/
Upload Files :
Current_dir [ Not Writeable ] Document_root [ Writeable ]

Command :


Current File : /opt/hc_python/lib/python3.12/site-packages/lxml//relaxng.pxi
# support for RelaxNG validation
from lxml.includes cimport relaxng

cdef object _rnc2rng
try:
    import rnc2rng as _rnc2rng
except ImportError:
    _rnc2rng = None


cdef int _require_rnc2rng() except -1:
    if _rnc2rng is None:
        raise RelaxNGParseError(
            'compact syntax not supported (please install rnc2rng)')
    return 0


cdef class RelaxNGError(LxmlError):
    """Base class for RelaxNG errors.
    """

cdef class RelaxNGParseError(RelaxNGError):
    """Error while parsing an XML document as RelaxNG.
    """

cdef class RelaxNGValidateError(RelaxNGError):
    """Error while validating an XML document with a RelaxNG schema.
    """


################################################################################
# RelaxNG

cdef class RelaxNG(_Validator):
    """RelaxNG(self, etree=None, file=None)
    Turn a document into a Relax NG validator.

    Either pass a schema as Element or ElementTree, or pass a file or
    filename through the ``file`` keyword argument.
    """
    cdef relaxng.xmlRelaxNG* _c_schema
    def __cinit__(self):
        self._c_schema = NULL

    def __init__(self, etree=None, *, file=None):
        cdef _Document doc
        cdef _Element root_node
        cdef xmlDoc* fake_c_doc = NULL
        cdef relaxng.xmlRelaxNGParserCtxt* parser_ctxt = NULL
        _Validator.__init__(self)
        if etree is not None:
            doc = _documentOrRaise(etree)
            root_node = _rootNodeOrRaise(etree)
            fake_c_doc = _fakeRootDoc(doc._c_doc, root_node._c_node)
            parser_ctxt = relaxng.xmlRelaxNGNewDocParserCtxt(fake_c_doc)
        elif file is not None:
            if _isString(file):
                if file[-4:].lower() == '.rnc':
                    _require_rnc2rng()
                    rng_data_utf8 = _utf8(_rnc2rng.dumps(_rnc2rng.load(file)))
                    doc = _parseMemoryDocument(rng_data_utf8, parser=None, url=file)
                    parser_ctxt = relaxng.xmlRelaxNGNewDocParserCtxt(doc._c_doc)
                else:
                    doc = None
                    filename = _encodeFilename(file)
                    with self._error_log:
                        orig_loader = _register_document_loader()
                        parser_ctxt = relaxng.xmlRelaxNGNewParserCtxt(_cstr(filename))
                        _reset_document_loader(orig_loader)
            elif (_getFilenameForFile(file) or '')[-4:].lower() == '.rnc':
                _require_rnc2rng()
                rng_data_utf8 = _utf8(_rnc2rng.dumps(_rnc2rng.load(file)))
                doc = _parseMemoryDocument(
                    rng_data_utf8, parser=None, url=_getFilenameForFile(file))
                parser_ctxt = relaxng.xmlRelaxNGNewDocParserCtxt(doc._c_doc)
            else:
                doc = _parseDocument(file, parser=None, base_url=None)
                parser_ctxt = relaxng.xmlRelaxNGNewDocParserCtxt(doc._c_doc)
        else:
            raise RelaxNGParseError, "No tree or file given"

        if parser_ctxt is NULL:
            if fake_c_doc is not NULL:
                _destroyFakeDoc(doc._c_doc, fake_c_doc)
            raise RelaxNGParseError(
                self._error_log._buildExceptionMessage(
                    "Document is not parsable as Relax NG"),
                self._error_log)

        # Need a cast here because older libxml2 releases do not use 'const' in the functype.
        relaxng.xmlRelaxNGSetParserStructuredErrors(
            parser_ctxt, <xmlerror.xmlStructuredErrorFunc> _receiveError, <void*>self._error_log)
        _connectGenericErrorLog(self._error_log, xmlerror.XML_FROM_RELAXNGP)
        self._c_schema = relaxng.xmlRelaxNGParse(parser_ctxt)
        _connectGenericErrorLog(None)

        relaxng.xmlRelaxNGFreeParserCtxt(parser_ctxt)
        if self._c_schema is NULL:
            if fake_c_doc is not NULL:
                _destroyFakeDoc(doc._c_doc, fake_c_doc)
            raise RelaxNGParseError(
                self._error_log._buildExceptionMessage(
                    "Document is not valid Relax NG"),
                self._error_log)
        if fake_c_doc is not NULL:
            _destroyFakeDoc(doc._c_doc, fake_c_doc)

    def __dealloc__(self):
        relaxng.xmlRelaxNGFree(self._c_schema)

    def __call__(self, etree):
        """__call__(self, etree)

        Validate doc using Relax NG.

        Returns true if document is valid, false if not."""
        cdef _Document doc
        cdef _Element root_node
        cdef xmlDoc* c_doc
        cdef relaxng.xmlRelaxNGValidCtxt* valid_ctxt
        cdef int ret

        assert self._c_schema is not NULL, "RelaxNG instance not initialised"
        doc = _documentOrRaise(etree)
        root_node = _rootNodeOrRaise(etree)

        valid_ctxt = relaxng.xmlRelaxNGNewValidCtxt(self._c_schema)
        if valid_ctxt is NULL:
            raise MemoryError()

        try:
            self._error_log.clear()
            # Need a cast here because older libxml2 releases do not use 'const' in the functype.
            relaxng.xmlRelaxNGSetValidStructuredErrors(
                valid_ctxt, <xmlerror.xmlStructuredErrorFunc> _receiveError, <void*>self._error_log)
            _connectGenericErrorLog(self._error_log, xmlerror.XML_FROM_RELAXNGV)
            c_doc = _fakeRootDoc(doc._c_doc, root_node._c_node)
            with nogil:
                ret = relaxng.xmlRelaxNGValidateDoc(valid_ctxt, c_doc)
            _destroyFakeDoc(doc._c_doc, c_doc)
        finally:
            _connectGenericErrorLog(None)
            relaxng.xmlRelaxNGFreeValidCtxt(valid_ctxt)

        if ret == -1:
            raise RelaxNGValidateError(
                "Internal error in Relax NG validation",
                self._error_log)
        if ret == 0:
            return True
        else:
            return False

    @classmethod
    def from_rnc_string(cls, src, base_url=None):
        """Parse a RelaxNG schema in compact syntax from a text string

        Requires the rnc2rng package to be installed.

        Passing the source URL or file path of the source as 'base_url'
        will enable resolving resource references relative to the source.
        """
        _require_rnc2rng()
        rng_str = utf8(_rnc2rng.dumps(_rnc2rng.loads(src)))
        return cls(_parseMemoryDocument(rng_str, parser=None, url=base_url))

[ Back ]
Name
Size
Last Modified
Owner / Group
Permissions
Options
..
--
May 23 2025 08:31:29
root / root
0755
__pycache__
--
April 04 2025 08:00:21
root / root
0755
html
--
April 04 2025 08:00:21
root / root
0755
includes
--
April 04 2025 08:00:21
root / root
0755
isoschematron
--
April 04 2025 08:00:21
root / root
0755
ElementInclude.py
8.359 KB
April 04 2025 08:00:21
root / root
0644
__init__.py
0.561 KB
April 04 2025 08:00:21
root / root
0644
_elementpath.cpython-312-x86_64-linux-gnu.so
200.188 KB
April 04 2025 08:00:21
root / root
0755
_elementpath.py
10.633 KB
April 04 2025 08:00:21
root / root
0644
apihelpers.pxi
62.119 KB
April 04 2025 08:00:21
root / root
0644
builder.cpython-312-x86_64-linux-gnu.so
113.805 KB
April 04 2025 08:00:21
root / root
0755
builder.py
7.91 KB
April 04 2025 08:00:21
root / root
0644
classlookup.pxi
21.909 KB
April 04 2025 08:00:21
root / root
0644
cleanup.pxi
8.256 KB
April 04 2025 08:00:21
root / root
0644
cssselect.py
3.229 KB
April 04 2025 08:00:21
root / root
0644
debug.pxi
3.205 KB
April 04 2025 08:00:21
root / root
0644
docloader.pxi
5.637 KB
April 04 2025 08:00:21
root / root
0644
doctestcompare.py
17.315 KB
April 04 2025 08:00:21
root / root
0644
dtd.pxi
14.923 KB
April 04 2025 08:00:21
root / root
0644
etree.cpython-312-x86_64-linux-gnu.so
5.11 MB
April 04 2025 08:00:21
root / root
0755
etree.h
9.68 KB
April 04 2025 08:00:21
root / root
0644
etree.pyx
131.364 KB
April 04 2025 08:00:21
root / root
0644
etree_api.h
16.663 KB
April 04 2025 08:00:21
root / root
0644
extensions.pxi
31.336 KB
April 04 2025 08:00:21
root / root
0644
iterparse.pxi
16.134 KB
April 04 2025 08:00:21
root / root
0644
lxml.etree.h
9.68 KB
April 04 2025 08:00:21
root / root
0644
lxml.etree_api.h
16.668 KB
April 04 2025 08:00:21
root / root
0644
nsclasses.pxi
8.915 KB
April 04 2025 08:00:21
root / root
0644
objectify.cpython-312-x86_64-linux-gnu.so
2.94 MB
April 04 2025 08:00:21
root / root
0755
objectify.pyx
73.96 KB
April 04 2025 08:00:21
root / root
0644
objectpath.pxi
11.182 KB
April 04 2025 08:00:21
root / root
0644
parser.pxi
80.117 KB
April 04 2025 08:00:21
root / root
0644
parsertarget.pxi
6.178 KB
April 04 2025 08:00:21
root / root
0644
proxy.pxi
23.142 KB
April 04 2025 08:00:21
root / root
0644
public-api.pxi
6.51 KB
April 04 2025 08:00:21
root / root
0644
pyclasslookup.py
0.09 KB
April 04 2025 08:00:21
root / root
0644
readonlytree.pxi
18.531 KB
April 04 2025 08:00:21
root / root
0644
relaxng.pxi
6.19 KB
April 04 2025 08:00:21
root / root
0644
sax.cpython-312-x86_64-linux-gnu.so
181.68 KB
April 04 2025 08:00:21
root / root
0755
sax.py
9.085 KB
April 04 2025 08:00:21
root / root
0644
saxparser.pxi
32.541 KB
April 04 2025 08:00:21
root / root
0644
schematron.pxi
5.77 KB
April 04 2025 08:00:21
root / root
0644
serializer.pxi
64.212 KB
April 04 2025 08:00:21
root / root
0644
usedoctest.py
0.225 KB
April 04 2025 08:00:21
root / root
0644
xinclude.pxi
2.398 KB
April 04 2025 08:00:21
root / root
0644
xmlerror.pxi
48.686 KB
April 04 2025 08:00:21
root / root
0644
xmlid.pxi
5.931 KB
April 04 2025 08:00:21
root / root
0644
xmlschema.pxi
8.291 KB
April 04 2025 08:00:21
root / root
0644
xpath.pxi
18.684 KB
April 04 2025 08:00:21
root / root
0644
xslt.pxi
35.179 KB
April 04 2025 08:00:21
root / root
0644
xsltext.pxi
10.828 KB
April 04 2025 08:00:21
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025
CONTACT ME
Static GIF