GRAYBYTE WORDPRESS FILE MANAGER2604

Server IP : 198.54.121.189 / Your IP : 216.73.216.224
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/cloudlinux/venv/lib/python3.11/site-packages/lxml/
Upload Files :
Current_dir [ Not Writeable ] Document_root [ Writeable ]

Command :


Current File : /opt/cloudlinux/venv/lib/python3.11/site-packages/lxml//xsltext.pxi
# XSLT extension elements

cdef class XSLTExtension:
    u"""Base class of an XSLT extension element.
    """
    def execute(self, context, self_node, input_node, output_parent):
        u"""execute(self, context, self_node, input_node, output_parent)
        Execute this extension element.

        Subclasses must override this method.  They may append
        elements to the `output_parent` element here, or set its text
        content.  To this end, the `input_node` provides read-only
        access to the current node in the input document, and the
        `self_node` points to the extension element in the stylesheet.

        Note that the `output_parent` parameter may be `None` if there
        is no parent element in the current context (e.g. no content
        was added to the output tree yet).
        """
        pass

    def apply_templates(self, _XSLTContext context not None, node, output_parent=None,
                        *, elements_only=False, remove_blank_text=False):
        u"""apply_templates(self, context, node, output_parent=None, elements_only=False, remove_blank_text=False)

        Call this method to retrieve the result of applying templates
        to an element.

        The return value is a list of elements or text strings that
        were generated by the XSLT processor.  If you pass
        ``elements_only=True``, strings will be discarded from the result
        list.  The option ``remove_blank_text=True`` will only discard
        strings that consist entirely of whitespace (e.g. formatting).
        These options do not apply to Elements, only to bare string results.

        If you pass an Element as `output_parent` parameter, the result
        will instead be appended to the element (including attributes
        etc.) and the return value will be `None`.  This is a safe way
        to generate content into the output document directly, without
        having to take care of special values like text or attributes.
        Note that the string discarding options will be ignored in this
        case.
        """
        cdef xmlNode* c_parent
        cdef xmlNode* c_node
        cdef xmlNode* c_context_node
        assert context._xsltCtxt is not NULL, "XSLT context not initialised"
        c_context_node = _roNodeOf(node)
        #assert c_context_node.doc is context._xsltContext.node.doc, \
        #    "switching input documents during transformation is not currently supported"

        if output_parent is not None:
            c_parent = _nonRoNodeOf(output_parent)
        else:
            c_parent = tree.xmlNewDocNode(
                context._xsltCtxt.output, NULL, <unsigned char*>"fake-parent", NULL)

        c_node = context._xsltCtxt.insert
        context._xsltCtxt.insert = c_parent
        xslt.xsltProcessOneNode(
            context._xsltCtxt, c_context_node, NULL)
        context._xsltCtxt.insert = c_node

        if output_parent is not None:
            return None

        try:
            return self._collectXSLTResultContent(
                context, c_parent, elements_only, remove_blank_text)
        finally:
            # free all intermediate nodes that will not be freed by proxies
            tree.xmlFreeNode(c_parent)

    def process_children(self, _XSLTContext context not None, output_parent=None,
                         *, elements_only=False, remove_blank_text=False):
        u"""process_children(self, context, output_parent=None, elements_only=False, remove_blank_text=False)

        Call this method to process the XSLT content of the extension
        element itself.

        The return value is a list of elements or text strings that
        were generated by the XSLT processor.  If you pass
        ``elements_only=True``, strings will be discarded from the result
        list.  The option ``remove_blank_text=True`` will only discard
        strings that consist entirely of whitespace (e.g. formatting).
        These options do not apply to Elements, only to bare string results.

        If you pass an Element as `output_parent` parameter, the result
        will instead be appended to the element (including attributes
        etc.) and the return value will be `None`.  This is a safe way
        to generate content into the output document directly, without
        having to take care of special values like text or attributes.
        Note that the string discarding options will be ignored in this
        case.
        """
        cdef xmlNode* c_parent
        cdef xslt.xsltTransformContext* c_ctxt = context._xsltCtxt
        cdef xmlNode* c_old_output_parent = c_ctxt.insert
        assert context._xsltCtxt is not NULL, "XSLT context not initialised"

        # output_parent node is used for adding results instead of
        # elements list used in apply_templates, that's easier and allows to
        # use attributes added to extension element with <xsl:attribute>.

        if output_parent is not None:
            c_parent = _nonRoNodeOf(output_parent)
        else:
            c_parent = tree.xmlNewDocNode(
                context._xsltCtxt.output, NULL, <unsigned char*>"fake-parent", NULL)

        c_ctxt.insert = c_parent
        xslt.xsltApplyOneTemplate(c_ctxt,
            c_ctxt.node, c_ctxt.inst.children, NULL, NULL)
        c_ctxt.insert = c_old_output_parent

        if output_parent is not None:
            return None

        try:
            return self._collectXSLTResultContent(
                context, c_parent, elements_only, remove_blank_text)
        finally:
            # free all intermediate nodes that will not be freed by proxies
            tree.xmlFreeNode(c_parent)

    cdef _collectXSLTResultContent(self, _XSLTContext context, xmlNode* c_parent,
                                   bint elements_only, bint remove_blank_text):
        cdef xmlNode* c_node
        cdef xmlNode* c_next
        cdef _ReadOnlyProxy proxy
        cdef list results = [] # or maybe _collectAttributes(c_parent, 2) ?
        c_node = c_parent.children
        while c_node is not NULL:
            c_next = c_node.next
            if c_node.type == tree.XML_TEXT_NODE:
                if not elements_only:
                    s = funicode(c_node.content)
                    if not remove_blank_text or s.strip():
                        results.append(s)
                    s = None
            elif c_node.type == tree.XML_ELEMENT_NODE:
                proxy = _newReadOnlyProxy(
                    context._extension_element_proxy, c_node)
                results.append(proxy)
                # unlink node and make sure it will be freed later on
                tree.xmlUnlinkNode(c_node)
                proxy.free_after_use()
            else:
                raise TypeError, \
                    f"unsupported XSLT result type: {c_node.type}"
            c_node = c_next
        return results


cdef _registerXSLTExtensions(xslt.xsltTransformContext* c_ctxt,
                             extension_dict):
    for ns_utf, name_utf in extension_dict:
        xslt.xsltRegisterExtElement(
            c_ctxt, _xcstr(name_utf), _xcstr(ns_utf),
            <xslt.xsltTransformFunction>_callExtensionElement)

cdef void _callExtensionElement(xslt.xsltTransformContext* c_ctxt,
                                xmlNode* c_context_node,
                                xmlNode* c_inst_node,
                                void* dummy) with gil:
    cdef _XSLTContext context
    cdef XSLTExtension extension
    cdef python.PyObject* dict_result
    cdef xmlNode* c_node
    cdef _ReadOnlyProxy context_node = None, self_node = None
    cdef object output_parent # not restricted to ro-nodes
    c_uri = _getNs(c_inst_node)
    if c_uri is NULL:
        # not allowed, and should never happen
        return
    if c_ctxt.xpathCtxt.userData is NULL:
        # just for safety, should never happen
        return
    context = <_XSLTContext>c_ctxt.xpathCtxt.userData
    try:
        try:
            dict_result = python.PyDict_GetItem(
                context._extension_elements, (c_uri, c_inst_node.name))
            if dict_result is NULL:
                raise KeyError, f"extension element {funicode(c_inst_node.name)} not found"
            extension = <object>dict_result

            try:
                # build the context proxy nodes
                self_node = _newReadOnlyProxy(None, c_inst_node)
                if _isElement(c_ctxt.insert):
                    output_parent = _newAppendOnlyProxy(self_node, c_ctxt.insert)
                else:
                    # may be the document node or other stuff
                    output_parent = _newOpaqueAppendOnlyNodeWrapper(c_ctxt.insert)
                if c_context_node.type in (tree.XML_DOCUMENT_NODE,
                                           tree.XML_HTML_DOCUMENT_NODE):
                    c_node = tree.xmlDocGetRootElement(<xmlDoc*>c_context_node)
                    if c_node is not NULL:
                        context_node = _newReadOnlyProxy(self_node, c_node)
                    else:
                        context_node = None
                elif c_context_node.type in (tree.XML_ATTRIBUTE_NODE,
                                             tree.XML_TEXT_NODE,
                                             tree.XML_CDATA_SECTION_NODE):
                    # this isn't easy to support using read-only
                    # nodes, as the smart-string factory must
                    # instantiate the parent proxy somehow...
                    raise TypeError(f"Unsupported element type: {c_context_node.type}")
                else:
                    context_node  = _newReadOnlyProxy(self_node, c_context_node)

                # run the XSLT extension
                context._extension_element_proxy = self_node
                extension.execute(context, self_node, context_node, output_parent)
            finally:
                context._extension_element_proxy = None
                if self_node is not None:
                    _freeReadOnlyProxies(self_node)
        except Exception as e:
            try:
                e = unicode(e).encode(u"UTF-8")
            except:
                e = repr(e).encode(u"UTF-8")
            message = python.PyBytes_FromFormat(
                "Error executing extension element '%s': %s",
                c_inst_node.name, _cstr(e))
            xslt.xsltTransformError(c_ctxt, NULL, c_inst_node, "%s", message)
            context._exc._store_raised()
        except:
            # just in case
            message = python.PyBytes_FromFormat(
                "Error executing extension element '%s'", c_inst_node.name)
            xslt.xsltTransformError(c_ctxt, NULL, c_inst_node, "%s", message)
            context._exc._store_raised()
    except:
        # no Python functions here - everything can fail...
        xslt.xsltTransformError(c_ctxt, NULL, c_inst_node,
                                "Error during XSLT extension element evaluation")
        context._exc._store_raised()
    finally:
        return  # swallow any further exceptions

[ Back ]
Name
Size
Last Modified
Owner / Group
Permissions
Options
..
--
June 25 2025 08:31:36
root / root
0755
__pycache__
--
May 15 2025 08:30:35
root / root
0755
html
--
May 15 2025 08:30:33
root / root
0755
includes
--
May 15 2025 08:30:33
root / root
0755
isoschematron
--
May 15 2025 08:30:33
root / root
0755
ElementInclude.py
8.359 KB
April 17 2025 13:10:58
root / root
0644
__init__.py
0.562 KB
April 17 2025 13:10:58
root / root
0644
_elementpath.cpython-311-x86_64-linux-gnu.so
225.273 KB
April 17 2025 13:11:30
root / root
0755
_elementpath.py
10.49 KB
April 17 2025 13:10:58
root / root
0644
apihelpers.pxi
62.941 KB
April 17 2025 13:10:58
root / root
0644
builder.cpython-311-x86_64-linux-gnu.so
120.727 KB
April 17 2025 13:11:30
root / root
0755
builder.py
7.956 KB
April 17 2025 13:10:58
root / root
0644
classlookup.pxi
21.936 KB
April 17 2025 13:10:58
root / root
0644
cleanup.pxi
8.26 KB
April 17 2025 13:10:58
root / root
0644
cssselect.py
3.287 KB
April 17 2025 13:10:58
root / root
0644
debug.pxi
3.206 KB
April 17 2025 13:10:58
root / root
0644
docloader.pxi
5.647 KB
April 17 2025 13:10:58
root / root
0644
doctestcompare.py
17.909 KB
April 17 2025 13:10:58
root / root
0644
dtd.pxi
14.862 KB
April 17 2025 13:10:58
root / root
0644
etree.cpython-311-x86_64-linux-gnu.so
5.53 MB
April 17 2025 13:11:30
root / root
0755
etree.h
8.374 KB
April 17 2025 13:10:58
root / root
0644
etree.pyx
129.312 KB
April 17 2025 13:10:58
root / root
0644
etree_api.h
17.058 KB
April 17 2025 13:10:58
root / root
0644
extensions.pxi
32.462 KB
April 17 2025 13:10:58
root / root
0644
iterparse.pxi
16.218 KB
April 17 2025 13:10:58
root / root
0644
lxml.etree.h
8.374 KB
April 17 2025 13:10:58
root / root
0644
lxml.etree_api.h
17.063 KB
April 17 2025 13:10:58
root / root
0644
nsclasses.pxi
8.931 KB
April 17 2025 13:10:58
root / root
0644
objectify.cpython-311-x86_64-linux-gnu.so
3.2 MB
April 17 2025 13:11:30
root / root
0755
objectify.pyx
75.293 KB
April 17 2025 13:10:58
root / root
0644
objectpath.pxi
11.21 KB
April 17 2025 13:10:58
root / root
0644
parser.pxi
76.413 KB
April 17 2025 13:10:58
root / root
0644
parsertarget.pxi
6.698 KB
April 17 2025 13:10:58
root / root
0644
proxy.pxi
23.01 KB
April 17 2025 13:10:58
root / root
0644
public-api.pxi
6.504 KB
April 17 2025 13:10:58
root / root
0644
pyclasslookup.py
0.09 KB
April 17 2025 13:10:58
root / root
0644
readonlytree.pxi
18.602 KB
April 17 2025 13:10:58
root / root
0644
relaxng.pxi
5.942 KB
April 17 2025 13:10:58
root / root
0644
sax.cpython-311-x86_64-linux-gnu.so
196.953 KB
April 17 2025 13:11:30
root / root
0755
sax.py
9.176 KB
April 17 2025 13:10:58
root / root
0644
saxparser.pxi
31.779 KB
April 17 2025 13:10:58
root / root
0644
schematron.pxi
5.646 KB
April 17 2025 13:10:58
root / root
0644
serializer.pxi
66.405 KB
April 17 2025 13:10:58
root / root
0644
usedoctest.py
0.225 KB
April 17 2025 13:10:58
root / root
0644
xinclude.pxi
2.402 KB
April 17 2025 13:10:58
root / root
0644
xmlerror.pxi
48.37 KB
April 17 2025 13:10:58
root / root
0644
xmlid.pxi
5.922 KB
April 17 2025 13:10:58
root / root
0644
xmlschema.pxi
7.89 KB
April 17 2025 13:10:58
root / root
0644
xpath.pxi
19.112 KB
April 17 2025 13:10:58
root / root
0644
xslt.pxi
35.834 KB
April 17 2025 13:10:58
root / root
0644
xsltext.pxi
10.825 KB
April 17 2025 13:10:58
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025
CONTACT ME
Static GIF