511
  7   	ˆl–ßi~”*_)%‚~àYS�ÿ�þZ�,ÙeŽ7_�¼Ð?ŸÆ„àiïÅÄÃ ?÷     	# read-only tree implementation

@cython.internal
cdef class _ReadOnlyProxy:
    u"A read-only proxy class suitable for PIs/Comments (for internal use only!)."
    cdef bint _free_after_use
    cdef xmlNode* _c_node
    cdef _ReadOnlyProxy _source_proxy
    cdef list _dependent_proxies
    def __cinit__(self):
        self._c_node = NULL
        self._free_after_use = 0

    cdef int _assertNode(self) except -1:
        u"""This is our way of saying: this proxy is invalid!
        """
        if not self._c_node:
            raise ReferenceError("Proxy invalidated!")
        return 0

    cdef int _raise_unsupported_type(self) except -1:
        raise TypeError(f"Unsupported node type: {self._c_node.type}")

    cdef void free_after_use(self):
        u"""Should the xmlNode* be freed when releasing the proxy?
        """
        self._free_after_use = 1

    @property
    def tag(self):
        """Element tag
        """
        self._assertNode()
        if self._c_node.type == tree.XML_ELEMENT_NODE:
            return _namespacedName(self._c_node)
        elif self._c_node.type == tree.XML_PI_NODE:
            return ProcessingInstruction
        elif self._c_node.type == tree.XML_COMMENT_NODE:
            return Comment
        elif self._c_node.type == tree.XML_ENTITY_REF_NODE:
            return Entity
        else:
            self._raise_unsupported_type()

    @property
    def text(self):
        """Text before the first subelement. This is either a string or
        the value None, if there was no text.
        """
        self._assertNode()
        if self._c_node.type == tree.XML_ELEMENT_NODE:
            return _collectText(self._c_node.children)
        elif self._c_node.type in (tree.XML_PI_NODE,
                                   tree.XML_COMMENT_NODE):
            if self._c_node.content is NULL:
                return ''
            else:
                return funicode(self._c_node.content)
        elif self._c_node.type == tree.XML_ENTITY_REF_NODE:
            return f'&{funicode(self._c_node.name)};'
        else:
            self._raise_unsupported_type()
        
    @property
    def tail(self):
        """Text after this element's end tag, but before the next sibling
        element's start tag. This is either a string or the value None, if
        there was no text.
        """
        self._assertNode()
        return _collectText(self._c_node.next)

    @property
    def sourceline(self):
        """Original line number as found by the parser or None if unknown.
        """
        cdef long line
        self._assertNode()
        line = tree.xmlGetLineNo(self._c_node)
        if line > 0:
            return line
        else:
            return None

    def __repr__(self):
        self._assertNode()
        if self._c_node.type == tree.XML_ELEMENT_NODE:
            return "<Element %s at 0x%x>" % (strrepr(self.tag), id(self))
        elif self._c_node.type == tree.XML_COMMENT_NODE:
            return "<!--%s-->" % strrepr(self.text)
        elif self._c_node.type == tree.XML_ENTITY_NODE:
            return "&%s;" % strrepr(funicode(self._c_node.name))
        elif self._c_node.type == tree.XML_PI_NODE:
            text = self.text
            if text:
                return "<?%s %s?>" % (strrepr(self.target), text)
            else:
                return "<?%s?>" % strrepr(self.target)
        else:
            self._raise_unsupported_type()

    def __getitem__(self, x):
        u"""Returns the subelement at the given position or the requested
        slice.
        """
        cdef xmlNode* c_node = NULL
        cdef Py_ssize_t step = 0, slicelength = 0
        cdef Py_ssize_t c, i
        cdef _node_to_node_function next_element
        cdef list result
        self._assertNode()
        if isinstance(x, slice):
            # slicing
            if _isFullSlice(<slice>x):
                return _collectChildren(self)
            _findChildSlice(<slice>x, self._c_node, &c_node, &step, &slicelength)
            i