[ Avaa Bypassed ]




Upload:

Command:

hmhc3928@3.17.166.233: ~ $
# module-level API for namespace implementations

cdef class LxmlRegistryError(LxmlError):
    """Base class of lxml registry errors.
    """

cdef class NamespaceRegistryError(LxmlRegistryError):
    """Error registering a namespace extension.
    """


@cython.internal
cdef class _NamespaceRegistry:
    u"Dictionary-like namespace registry"
    cdef object _ns_uri
    cdef bytes _ns_uri_utf
    cdef dict _entries
    cdef char* _c_ns_uri_utf
    def __cinit__(self, ns_uri):
        self._ns_uri = ns_uri
        if ns_uri is None:
            self._ns_uri_utf = None
            self._c_ns_uri_utf = NULL
        else:
            self._ns_uri_utf = _utf8(ns_uri)
            self._c_ns_uri_utf = _cstr(self._ns_uri_utf)
        self._entries = {}

    def update(self, class_dict_iterable):
        u"""update(self, class_dict_iterable)

        Forgivingly update the registry.

        ``class_dict_iterable`` may be a dict or some other iterable
        that yields (name, value) pairs.

        If a value does not match the required type for this registry,
        or if the name starts with '_', it will be silently discarded.
        This allows registrations at the module or class level using
        vars(), globals() etc."""
        if hasattr(class_dict_iterable, u'items'):
            class_dict_iterable = class_dict_iterable.items()
        for name, item in class_dict_iterable:
            if (name is None or name[:1] != '_') and callable(item):
                self[name] = item

    def __getitem__(self, name):
        if name is not None:
            name = _utf8(name)
        return self._get(name)

    def __delitem__(self, name):
        if name is not None:
            name = _utf8(name)
        del self._entries[name]

    cdef object _get(self, object name):
        cdef python.PyObject* dict_result
        dict_result = python.PyDict_GetItem(self._entries, name)
        if dict_result is NULL:
            raise KeyError, u"Name not registered."
        return <object>dict_result

    cdef object _getForString(self, char* name):
        cdef python.PyObject* dict_result
        dict_result = python.PyDict_GetItem(self._entries, name)
        if dict_result is NULL:
            raise KeyError, u"Name not registered."
        return <object>dict_result

    def __iter__(self):
        return iter(self._entries)

    def items(self):
        return list(self._entries.items())

    def iteritems(self):
        return iter(self._entries.items())

    def clear(self):
        self._entries.clear()

    def __call__(self, obj):
        # Usage as decorator:
        #   ns = lookup.get_namespace("...")
        #   @ns('abc')
        #   class element(ElementBase): pass
        #
        #   @ns
        #   class elementname(ElementBase): pass

        if obj is None or python._isString(obj):
            # @ns(None) or @ns('tag')
            return partial(self.__deco, obj)
        # plain @ns decorator
        self[obj.__name__] = obj
        return obj

    def __deco(self, name, obj):
        self[name] = obj
        return obj


@cython.final
@cython.internal
cdef class _ClassNamespaceRegistry(_NamespaceRegistry):
    u"Dictionary-like registry for namespace implementation classes"
    def __setitem__(self, name, item):
        if not isinstance(item, type) or not issubclass(item, ElementBase):
            raise NamespaceRegistryError, \
                u"Registered element classes must be subtypes of ElementBase"
        if name is not None:
            name = _utf8(name)
        self._entries[name] = item

    def __repr__(self):
        return u"Namespace(%r)" % self._ns_uri


cdef class ElementNamespaceClassLookup(FallbackElementClassLookup):
    u"""ElementNamespaceClassLookup(self, fallback=None)

    Element class lookup scheme that searches the Element class in the
    Namespace registry.

    Usage:

    >>> lookup = ElementNamespaceClassLookup()
    >>> ns_elements = lookup.get_namespace("http://schema.org/Movie")

    >>> @ns_elements
    ... class movie(ElementBase):
    ...     "Element implementation for 'movie' tag (using class name) in schema namespace."

    >>> @ns_elements("movie")
    ... class MovieElement(ElementBase):
    ...     "Element implementation for 'movie' tag (explicit tag name) in schema namespace."
    """
    cdef dict _namespace_registries
    def __cinit__(self):
        self._namespace_registries = {}

    def __init__(self, ElementClassLookup fallback=None):
        FallbackElementClassLookup.__init__(self, fallback)
        self._lookup_function = _find_nselement_class

    def get_namespace(self, ns_uri):
        u"""get_namespace(self, ns_uri)

        Retrieve the namespace object associated with the given URI.
        Pass None for the empty namespace.

        Creates a new namespace object if it does not yet exist."""
        if ns_uri:
            ns_utf = _utf8(ns_uri)
        else:
            ns_utf = None
        try:
            return self._namespace_registries[ns_utf]
        except KeyError:
            registry = self._namespace_registries[ns_utf] = \
                       _ClassNamespaceRegistry(ns_uri)
            return registry

cdef object _find_nselement_class(state, _Document doc, xmlNode* c_node):
    cdef python.PyObject* dict_result
    cdef ElementNamespaceClassLookup lookup
    cdef _NamespaceRegistry registry
    if state is None:
        return _lookupDefaultElementClass(None, doc, c_node)

    lookup = <ElementNamespaceClassLookup>state
    if c_node.type != tree.XML_ELEMENT_NODE:
        return _callLookupFallback(lookup, doc, c_node)

    c_namespace_utf = _getNs(c_node)
    if c_namespace_utf is not NULL:
        dict_result = python.PyDict_GetItem(
            lookup._namespace_registries, <unsigned char*>c_namespace_utf)
    else:
        dict_result = python.PyDict_GetItem(
            lookup._namespace_registries, None)
    if dict_result is not NULL:
        registry = <_NamespaceRegistry>dict_result
        classes = registry._entries

        if c_node.name is not NULL:
            dict_result = python.PyDict_GetItem(
                classes, <unsigned char*>c_node.name)
        else:
            dict_result = NULL

        if dict_result is NULL:
            dict_result = python.PyDict_GetItem(classes, None)

        if dict_result is not NULL:
            return <object>dict_result
    return _callLookupFallback(lookup, doc, c_node)


################################################################################
# XPath extension functions

cdef dict __FUNCTION_NAMESPACE_REGISTRIES
__FUNCTION_NAMESPACE_REGISTRIES = {}

def FunctionNamespace(ns_uri):
    u"""FunctionNamespace(ns_uri)

    Retrieve the function namespace object associated with the given
    URI.

    Creates a new one if it does not yet exist. A function namespace
    can only be used to register extension functions.

    Usage:

    >>> ns_functions = FunctionNamespace("http://schema.org/Movie")

    >>> @ns_functions  # uses function name
    ... def add2(x):
    ...     return x + 2

    >>> @ns_functions("add3")  # uses explicit name
    ... def add_three(x):
    ...     return x + 3
    """
    ns_utf = _utf8(ns_uri) if ns_uri else None
    try:
        return __FUNCTION_NAMESPACE_REGISTRIES[ns_utf]
    except KeyError:
        registry = __FUNCTION_NAMESPACE_REGISTRIES[ns_utf] = \
                   _XPathFunctionNamespaceRegistry(ns_uri)
        return registry

@cython.internal
cdef class _FunctionNamespaceRegistry(_NamespaceRegistry):
    def __setitem__(self, name, item):
        if not callable(item):
            raise NamespaceRegistryError, \
                u"Registered functions must be callable."
        if not name:
            raise ValueError, \
                u"extensions must have non empty names"
        self._entries[_utf8(name)] = item

    def __repr__(self):
        return u"FunctionNamespace(%r)" % self._ns_uri

@cython.final
@cython.internal
cdef class _XPathFunctionNamespaceRegistry(_FunctionNamespaceRegistry):
    cdef object _prefix
    cdef bytes _prefix_utf

    property prefix:
        u"Namespace prefix for extension functions."
        def __del__(self):
            self._prefix = None # no prefix configured
            self._prefix_utf = None
        def __get__(self):
            if self._prefix is None:
                return ''
            else:
                return self._prefix
        def __set__(self, prefix):
            if prefix == '':
                prefix = None # empty prefix
            self._prefix_utf = _utf8(prefix) if prefix is not None else None
            self._prefix = prefix

cdef list _find_all_extension_prefixes():
    u"Internal lookup function to find all function prefixes for XSLT/XPath."
    cdef _XPathFunctionNamespaceRegistry registry
    cdef list ns_prefixes = []
    for registry in __FUNCTION_NAMESPACE_REGISTRIES.itervalues():
        if registry._prefix_utf is not None:
            if registry._ns_uri_utf is not None:
                ns_prefixes.append(
                    (registry._prefix_utf, registry._ns_uri_utf))
    return ns_prefixes

Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
html Folder 0755
includes Folder 0755
isoschematron Folder 0755
ElementInclude.py File 8.36 KB 0644
__init__.py File 575 B 0644
_elementpath.cpython-311-x86_64-linux-gnu.so File 419.42 KB 0755
_elementpath.py File 10.49 KB 0644
apihelpers.pxi File 62.94 KB 0644
builder.cpython-311-x86_64-linux-gnu.so File 222.23 KB 0755
builder.py File 7.96 KB 0644
classlookup.pxi File 21.94 KB 0644
cleanup.pxi File 8.26 KB 0644
cssselect.py File 3.29 KB 0644
debug.pxi File 3.21 KB 0644
docloader.pxi File 5.65 KB 0644
doctestcompare.py File 17.91 KB 0644
dtd.pxi File 14.86 KB 0644
etree.cpython-311-x86_64-linux-gnu.so File 8.46 MB 0755
etree.h File 8.37 KB 0644
etree.pyx File 129.31 KB 0644
etree_api.h File 17.06 KB 0644
extensions.pxi File 32.46 KB 0644
iterparse.pxi File 16.22 KB 0644
lxml.etree.h File 8.37 KB 0644
lxml.etree_api.h File 17.06 KB 0644
nsclasses.pxi File 8.93 KB 0644
objectify.cpython-311-x86_64-linux-gnu.so File 4.25 MB 0755
objectify.pyx File 75.29 KB 0644
objectpath.pxi File 11.21 KB 0644
parser.pxi File 76.41 KB 0644
parsertarget.pxi File 6.7 KB 0644
proxy.pxi File 23.01 KB 0644
public-api.pxi File 6.5 KB 0644
pyclasslookup.py File 92 B 0644
readonlytree.pxi File 18.6 KB 0644
relaxng.pxi File 5.94 KB 0644
sax.cpython-311-x86_64-linux-gnu.so File 366.73 KB 0755
sax.py File 9.18 KB 0644
saxparser.pxi File 31.78 KB 0644
schematron.pxi File 5.65 KB 0644
serializer.pxi File 66.41 KB 0644
usedoctest.py File 230 B 0644
xinclude.pxi File 2.4 KB 0644
xmlerror.pxi File 48.37 KB 0644
xmlid.pxi File 5.92 KB 0644
xmlschema.pxi File 7.89 KB 0644
xpath.pxi File 19.11 KB 0644
xslt.pxi File 35.83 KB 0644
xsltext.pxi File 10.83 KB 0644