summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2019-02-23 11:52:55 +0100
committerStefan Behnel <stefan_ml@behnel.de>2019-02-23 11:52:55 +0100
commitfd971a56dd5fe68dbafc8048ebaf9d712b2dfc21 (patch)
treef19f64c46a2709661307482c41d68838e9310939
parentc6facd83a633e0c91fbb52159bc27fa49bd5bec3 (diff)
downloadpython-lxml-fd971a56dd5fe68dbafc8048ebaf9d712b2dfc21.tar.gz
Replace old Pyrex property syntax with @property decorators for read-only properties, and resolve some Cython warnings.
-rw-r--r--src/lxml/dtd.pxi372
-rw-r--r--src/lxml/etree.pyx242
-rw-r--r--src/lxml/extensions.pxi42
-rw-r--r--src/lxml/iterparse.pxi24
-rw-r--r--src/lxml/objectify.pyx67
-rw-r--r--src/lxml/parser.pxi38
-rw-r--r--src/lxml/readonlytree.pxi138
-rw-r--r--src/lxml/xinclude.pxi8
-rw-r--r--src/lxml/xmlerror.pxi102
-rw-r--r--src/lxml/xpath.pxi16
-rw-r--r--src/lxml/xslt.pxi30
11 files changed, 542 insertions, 537 deletions
diff --git a/src/lxml/dtd.pxi b/src/lxml/dtd.pxi
index 6ea9e696..ca4df709 100644
--- a/src/lxml/dtd.pxi
+++ b/src/lxml/dtd.pxi
@@ -28,64 +28,64 @@ cdef class _DTDElementContentDecl:
def __repr__(self):
return "<%s.%s object name=%r type=%r occur=%r at 0x%x>" % (self.__class__.__module__, self.__class__.__name__, self.name, self.type, self.occur, id(self))
- property name:
- def __get__(self):
- _assertValidDTDNode(self, self._c_node)
- return funicode(self._c_node.name) if self._c_node.name is not NULL else None
-
- property type:
- def __get__(self):
- _assertValidDTDNode(self, self._c_node)
- cdef int type = self._c_node.type
- if type == tree.XML_ELEMENT_CONTENT_PCDATA:
- return "pcdata"
- elif type == tree.XML_ELEMENT_CONTENT_ELEMENT:
- return "element"
- elif type == tree.XML_ELEMENT_CONTENT_SEQ:
- return "seq"
- elif type == tree.XML_ELEMENT_CONTENT_OR:
- return "or"
- else:
- return None
-
- property occur:
- def __get__(self):
- _assertValidDTDNode(self, self._c_node)
- cdef int occur = self._c_node.ocur
- if occur == tree.XML_ELEMENT_CONTENT_ONCE:
- return "once"
- elif occur == tree.XML_ELEMENT_CONTENT_OPT:
- return "opt"
- elif occur == tree.XML_ELEMENT_CONTENT_MULT:
- return "mult"
- elif occur == tree.XML_ELEMENT_CONTENT_PLUS:
- return "plus"
- else:
- return None
-
- property left:
- def __get__(self):
- _assertValidDTDNode(self, self._c_node)
- c1 = self._c_node.c1
- if c1:
- node = <_DTDElementContentDecl>_DTDElementContentDecl.__new__(_DTDElementContentDecl)
- node._dtd = self._dtd
- node._c_node = <tree.xmlElementContent*>c1
- return node
- else:
- return None
-
- property right:
- def __get__(self):
- _assertValidDTDNode(self, self._c_node)
- c2 = self._c_node.c2
- if c2:
- node = <_DTDElementContentDecl>_DTDElementContentDecl.__new__(_DTDElementContentDecl)
- node._dtd = self._dtd
- node._c_node = <tree.xmlElementContent*>c2
- return node
- else:
- return None
+ @property
+ def name(self):
+ _assertValidDTDNode(self, self._c_node)
+ return funicode(self._c_node.name) if self._c_node.name is not NULL else None
+
+ @property
+ def type(self):
+ _assertValidDTDNode(self, self._c_node)
+ cdef int type = self._c_node.type
+ if type == tree.XML_ELEMENT_CONTENT_PCDATA:
+ return "pcdata"
+ elif type == tree.XML_ELEMENT_CONTENT_ELEMENT:
+ return "element"
+ elif type == tree.XML_ELEMENT_CONTENT_SEQ:
+ return "seq"
+ elif type == tree.XML_ELEMENT_CONTENT_OR:
+ return "or"
+ else:
+ return None
+
+ @property
+ def occur(self):
+ _assertValidDTDNode(self, self._c_node)
+ cdef int occur = self._c_node.ocur
+ if occur == tree.XML_ELEMENT_CONTENT_ONCE:
+ return "once"
+ elif occur == tree.XML_ELEMENT_CONTENT_OPT:
+ return "opt"
+ elif occur == tree.XML_ELEMENT_CONTENT_MULT:
+ return "mult"
+ elif occur == tree.XML_ELEMENT_CONTENT_PLUS:
+ return "plus"
+ else:
+ return None
+
+ @property
+ def left(self):
+ _assertValidDTDNode(self, self._c_node)
+ c1 = self._c_node.c1
+ if c1:
+ node = <_DTDElementContentDecl>_DTDElementContentDecl.__new__(_DTDElementContentDecl)
+ node._dtd = self._dtd
+ node._c_node = <tree.xmlElementContent*>c1
+ return node
+ else:
+ return None
+
+ @property
+ def right(self):
+ _assertValidDTDNode(self, self._c_node)
+ c2 = self._c_node.c2
+ if c2:
+ node = <_DTDElementContentDecl>_DTDElementContentDecl.__new__(_DTDElementContentDecl)
+ node._dtd = self._dtd
+ node._c_node = <tree.xmlElementContent*>c2
+ return node
+ else:
+ return None
@cython.final
@@ -98,67 +98,67 @@ cdef class _DTDAttributeDecl:
def __repr__(self):
return "<%s.%s object name=%r elemname=%r prefix=%r type=%r default=%r default_value=%r at 0x%x>" % (self.__class__.__module__, self.__class__.__name__, self.name, self.elemname, self.prefix, self.type, self.default, self.default_value, id(self))
- property name:
- def __get__(self):
- _assertValidDTDNode(self, self._c_node)
- return funicode(self._c_node.name) if self._c_node.name is not NULL else None
-
- property elemname:
- def __get__(self):
- _assertValidDTDNode(self, self._c_node)
- return funicode(self._c_node.elem) if self._c_node.elem is not NULL else None
-
- property prefix:
- def __get__(self):
- _assertValidDTDNode(self, self._c_node)
- return funicode(self._c_node.prefix) if self._c_node.prefix is not NULL else None
-
- property type:
- def __get__(self):
- _assertValidDTDNode(self, self._c_node)
- cdef int type = self._c_node.atype
- if type == tree.XML_ATTRIBUTE_CDATA:
- return "cdata"
- elif type == tree.XML_ATTRIBUTE_ID:
- return "id"
- elif type == tree.XML_ATTRIBUTE_IDREF:
- return "idref"
- elif type == tree.XML_ATTRIBUTE_IDREFS:
- return "idrefs"
- elif type == tree.XML_ATTRIBUTE_ENTITY:
- return "entity"
- elif type == tree.XML_ATTRIBUTE_ENTITIES:
- return "entities"
- elif type == tree.XML_ATTRIBUTE_NMTOKEN:
- return "nmtoken"
- elif type == tree.XML_ATTRIBUTE_NMTOKENS:
- return "nmtokens"
- elif type == tree.XML_ATTRIBUTE_ENUMERATION:
- return "enumeration"
- elif type == tree.XML_ATTRIBUTE_NOTATION:
- return "notation"
- else:
- return None
-
- property default:
- def __get__(self):
- _assertValidDTDNode(self, self._c_node)
- cdef int default = self._c_node.def_
- if default == tree.XML_ATTRIBUTE_NONE:
- return "none"
- elif default == tree.XML_ATTRIBUTE_REQUIRED:
- return "required"
- elif default == tree.XML_ATTRIBUTE_IMPLIED:
- return "implied"
- elif default == tree.XML_ATTRIBUTE_FIXED:
- return "fixed"
- else:
- return None
-
- property default_value:
- def __get__(self):
- _assertValidDTDNode(self, self._c_node)
- return funicode(self._c_node.defaultValue) if self._c_node.defaultValue is not NULL else None
+ @property
+ def name(self):
+ _assertValidDTDNode(self, self._c_node)
+ return funicode(self._c_node.name) if self._c_node.name is not NULL else None
+
+ @property
+ def elemname(self):
+ _assertValidDTDNode(self, self._c_node)
+ return funicode(self._c_node.elem) if self._c_node.elem is not NULL else None
+
+ @property
+ def prefix(self):
+ _assertValidDTDNode(self, self._c_node)
+ return funicode(self._c_node.prefix) if self._c_node.prefix is not NULL else None
+
+ @property
+ def type(self):
+ _assertValidDTDNode(self, self._c_node)
+ cdef int type = self._c_node.atype
+ if type == tree.XML_ATTRIBUTE_CDATA:
+ return "cdata"
+ elif type == tree.XML_ATTRIBUTE_ID:
+ return "id"
+ elif type == tree.XML_ATTRIBUTE_IDREF:
+ return "idref"
+ elif type == tree.XML_ATTRIBUTE_IDREFS:
+ return "idrefs"
+ elif type == tree.XML_ATTRIBUTE_ENTITY:
+ return "entity"
+ elif type == tree.XML_ATTRIBUTE_ENTITIES:
+ return "entities"
+ elif type == tree.XML_ATTRIBUTE_NMTOKEN:
+ return "nmtoken"
+ elif type == tree.XML_ATTRIBUTE_NMTOKENS:
+ return "nmtokens"
+ elif type == tree.XML_ATTRIBUTE_ENUMERATION:
+ return "enumeration"
+ elif type == tree.XML_ATTRIBUTE_NOTATION:
+ return "notation"
+ else:
+ return None
+
+ @property
+ def default(self):
+ _assertValidDTDNode(self, self._c_node)
+ cdef int default = self._c_node.def_
+ if default == tree.XML_ATTRIBUTE_NONE:
+ return "none"
+ elif default == tree.XML_ATTRIBUTE_REQUIRED:
+ return "required"
+ elif default == tree.XML_ATTRIBUTE_IMPLIED:
+ return "implied"
+ elif default == tree.XML_ATTRIBUTE_FIXED:
+ return "fixed"
+ else:
+ return None
+
+ @property
+ def default_value(self):
+ _assertValidDTDNode(self, self._c_node)
+ return funicode(self._c_node.defaultValue) if self._c_node.defaultValue is not NULL else None
def itervalues(self):
_assertValidDTDNode(self, self._c_node)
@@ -181,44 +181,44 @@ cdef class _DTDElementDecl:
def __repr__(self):
return "<%s.%s object name=%r prefix=%r type=%r at 0x%x>" % (self.__class__.__module__, self.__class__.__name__, self.name, self.prefix, self.type, id(self))
- property name:
- def __get__(self):
- _assertValidDTDNode(self, self._c_node)
- return funicode(self._c_node.name) if self._c_node.name is not NULL else None
-
- property prefix:
- def __get__(self):
- _assertValidDTDNode(self, self._c_node)
- return funicode(self._c_node.prefix) if self._c_node.prefix is not NULL else None
-
- property type:
- def __get__(self):
- _assertValidDTDNode(self, self._c_node)
- cdef int type = self._c_node.etype
- if type == tree.XML_ELEMENT_TYPE_UNDEFINED:
- return "undefined"
- elif type == tree.XML_ELEMENT_TYPE_EMPTY:
- return "empty"
- elif type == tree.XML_ELEMENT_TYPE_ANY:
- return "any"
- elif type == tree.XML_ELEMENT_TYPE_MIXED:
- return "mixed"
- elif type == tree.XML_ELEMENT_TYPE_ELEMENT:
- return "element"
- else:
- return None
-
- property content:
- def __get__(self):
- _assertValidDTDNode(self, self._c_node)
- cdef tree.xmlElementContent *content = self._c_node.content
- if content:
- node = <_DTDElementContentDecl>_DTDElementContentDecl.__new__(_DTDElementContentDecl)
- node._dtd = self._dtd
- node._c_node = content
- return node
- else:
- return None
+ @property
+ def name(self):
+ _assertValidDTDNode(self, self._c_node)
+ return funicode(self._c_node.name) if self._c_node.name is not NULL else None
+
+ @property
+ def prefix(self):
+ _assertValidDTDNode(self, self._c_node)
+ return funicode(self._c_node.prefix) if self._c_node.prefix is not NULL else None
+
+ @property
+ def type(self):
+ _assertValidDTDNode(self, self._c_node)
+ cdef int type = self._c_node.etype
+ if type == tree.XML_ELEMENT_TYPE_UNDEFINED:
+ return "undefined"
+ elif type == tree.XML_ELEMENT_TYPE_EMPTY:
+ return "empty"
+ elif type == tree.XML_ELEMENT_TYPE_ANY:
+ return "any"
+ elif type == tree.XML_ELEMENT_TYPE_MIXED:
+ return "mixed"
+ elif type == tree.XML_ELEMENT_TYPE_ELEMENT:
+ return "element"
+ else:
+ return None
+
+ @property
+ def content(self):
+ _assertValidDTDNode(self, self._c_node)
+ cdef tree.xmlElementContent *content = self._c_node.content
+ if content:
+ node = <_DTDElementContentDecl>_DTDElementContentDecl.__new__(_DTDElementContentDecl)
+ node._dtd = self._dtd
+ node._c_node = content
+ return node
+ else:
+ return None
def iterattributes(self):
_assertValidDTDNode(self, self._c_node)
@@ -243,20 +243,20 @@ cdef class _DTDEntityDecl:
def __repr__(self):
return "<%s.%s object name=%r at 0x%x>" % (self.__class__.__module__, self.__class__.__name__, self.name, id(self))
- property name:
- def __get__(self):
- _assertValidDTDNode(self, self._c_node)
- return funicode(self._c_node.name) if self._c_node.name is not NULL else None
+ @property
+ def name(self):
+ _assertValidDTDNode(self, self._c_node)
+ return funicode(self._c_node.name) if self._c_node.name is not NULL else None
- property orig:
- def __get__(self):
- _assertValidDTDNode(self, self._c_node)
- return funicode(self._c_node.orig) if self._c_node.orig is not NULL else None
+ @property
+ def orig(self):
+ _assertValidDTDNode(self, self._c_node)
+ return funicode(self._c_node.orig) if self._c_node.orig is not NULL else None
- property content:
- def __get__(self):
- _assertValidDTDNode(self, self._c_node)
- return funicode(self._c_node.content) if self._c_node.content is not NULL else None
+ @property
+ def content(self):
+ _assertValidDTDNode(self, self._c_node)
+ return funicode(self._c_node.content) if self._c_node.content is not NULL else None
################################################################################
@@ -293,23 +293,23 @@ cdef class DTD(_Validator):
self._error_log._buildExceptionMessage(u"error parsing DTD"),
self._error_log)
- property name:
- def __get__(self):
- if self._c_dtd is NULL:
- return None
- return funicodeOrNone(self._c_dtd.name)
-
- property external_id:
- def __get__(self):
- if self._c_dtd is NULL:
- return None
- return funicodeOrNone(self._c_dtd.ExternalID)
-
- property system_url:
- def __get__(self):
- if self._c_dtd is NULL:
- return None
- return funicodeOrNone(self._c_dtd.SystemID)
+ @property
+ def name(self):
+ if self._c_dtd is NULL:
+ return None
+ return funicodeOrNone(self._c_dtd.name)
+
+ @property
+ def external_id(self):
+ if self._c_dtd is NULL:
+ return None
+ return funicodeOrNone(self._c_dtd.ExternalID)
+
+ @property
+ def system_url(self):
+ if self._c_dtd is NULL:
+ return None
+ return funicodeOrNone(self._c_dtd.SystemID)
def iterelements(self):
cdef tree.xmlNode *c_node = self._c_dtd.children if self._c_dtd is not NULL else NULL
diff --git a/src/lxml/etree.pyx b/src/lxml/etree.pyx
index 3ba50798..3f4bf390 100644
--- a/src/lxml/etree.pyx
+++ b/src/lxml/etree.pyx
@@ -515,15 +515,15 @@ cdef class DocInfo:
if not root_name and (public_id or system_url):
raise ValueError, u"Could not find root node"
- property root_name:
- u"Returns the name of the root node as defined by the DOCTYPE."
- def __get__(self):
- root_name, public_id, system_url = self._doc.getdoctype()
- return root_name
+ @property
+ def root_name(self):
+ """Returns the name of the root node as defined by the DOCTYPE."""
+ root_name, public_id, system_url = self._doc.getdoctype()
+ return root_name
@cython.final
cdef tree.xmlDtd* _get_c_dtd(self):
- u"""Return the DTD. Create it if it does not yet exist."""
+ """"Return the DTD. Create it if it does not yet exist."""
cdef xmlDoc* c_doc = self._doc._c_doc
cdef xmlNode* c_root_node
cdef const_xmlChar* c_name
@@ -604,28 +604,28 @@ cdef class DocInfo:
tree.xmlFree(<void*>c_dtd.SystemID)
c_dtd.SystemID = c_value
- property xml_version:
- u"Returns the XML version as declared by the document."
- def __get__(self):
- xml_version, encoding = self._doc.getxmlinfo()
- return xml_version
-
- property encoding:
- u"Returns the encoding name as declared by the document."
- def __get__(self):
- xml_version, encoding = self._doc.getxmlinfo()
- return encoding
-
- property standalone:
- u"""Returns the standalone flag as declared by the document. The possible
+ @property
+ def xml_version(self):
+ """Returns the XML version as declared by the document."""
+ xml_version, encoding = self._doc.getxmlinfo()
+ return xml_version
+
+ @property
+ def encoding(self):
+ """Returns the encoding name as declared by the document."""
+ xml_version, encoding = self._doc.getxmlinfo()
+ return encoding
+
+ @property
+ def standalone(self):
+ """Returns the standalone flag as declared by the document. The possible
values are True (``standalone='yes'``), False
(``standalone='no'`` or flag not provided in the declaration),
and None (unknown or no declaration found). Note that a
normal truth test on this value will always tell if the
``standalone`` flag was set to ``'yes'`` or not.
"""
- def __get__(self):
- return self._doc.isstandalone()
+ return self._doc.isstandalone()
property URL:
u"The source URL of the document (or None if unknown)."
@@ -643,40 +643,40 @@ cdef class DocInfo:
if c_oldurl is not NULL:
tree.xmlFree(<void*>c_oldurl)
- property doctype:
- u"Returns a DOCTYPE declaration string for the document."
- def __get__(self):
- root_name, public_id, system_url = self._doc.getdoctype()
+ @property
+ def doctype(self):
+ """Returns a DOCTYPE declaration string for the document."""
+ root_name, public_id, system_url = self._doc.getdoctype()
+ if system_url:
+ # If '"' in system_url, we must escape it with single
+ # quotes, otherwise escape with double quotes. If url
+ # contains both a single quote and a double quote, XML
+ # standard is being violated.
+ if '"' in system_url:
+ quoted_system_url = f"'{system_url}'"
+ else:
+ quoted_system_url = f'"{system_url}"'
+ if public_id:
if system_url:
- # If '"' in system_url, we must escape it with single
- # quotes, otherwise escape with double quotes. If url
- # contains both a single quote and a double quote, XML
- # standard is being violated.
- if '"' in system_url:
- quoted_system_url = f"'{system_url}'"
- else:
- quoted_system_url = f'"{system_url}"'
- if public_id:
- if system_url:
- return f'<!DOCTYPE {root_name} PUBLIC "{public_id}" {quoted_system_url}>'
- else:
- return f'<!DOCTYPE {root_name} PUBLIC "{public_id}">'
- elif system_url:
- return f'<!DOCTYPE {root_name} SYSTEM {quoted_system_url}>'
- elif self._doc.hasdoctype():
- return f'<!DOCTYPE {root_name}>'
+ return f'<!DOCTYPE {root_name} PUBLIC "{public_id}" {quoted_system_url}>'
else:
- return u''
+ return f'<!DOCTYPE {root_name} PUBLIC "{public_id}">'
+ elif system_url:
+ return f'<!DOCTYPE {root_name} SYSTEM {quoted_system_url}>'
+ elif self._doc.hasdoctype():
+ return f'<!DOCTYPE {root_name}>'
+ else:
+ return u''
- property internalDTD:
- u"Returns a DTD validator based on the internal subset of the document."
- def __get__(self):
- return _dtdFactory(self._doc._c_doc.intSubset)
+ @property
+ def internalDTD(self):
+ """Returns a DTD validator based on the internal subset of the document."""
+ return _dtdFactory(self._doc._c_doc.intSubset)
- property externalDTD:
- u"Returns a DTD validator based on the external subset of the document."
- def __get__(self):
- return _dtdFactory(self._doc._c_doc.extSubset)
+ @property
+ def externalDTD(self):
+ """Returns a DTD validator based on the external subset of the document."""
+ return _dtdFactory(self._doc._c_doc.extSubset)
@cython.no_gc_clear
@@ -996,12 +996,12 @@ cdef public class _Element [ type LxmlElementType, object LxmlElement ]:
else:
self._doc._setNodeNs(self._c_node, _xcstr(ns))
- property attrib:
- u"""Element attribute dictionary. Where possible, use get(), set(),
+ @property
+ def attrib(self):
+ """Element attribute dictionary. Where possible, use get(), set(),
keys(), values() and items() to access element attributes.
"""
- def __get__(self):
- return _Attrib.__new__(_Attrib, self)
+ return _Attrib.__new__(_Attrib, self)
property text:
u"""Text before the first subelement. This is either a string or
@@ -1039,14 +1039,14 @@ cdef public class _Element [ type LxmlElementType, object LxmlElement ]:
# _setTailText(self._c_node, None)
# not in ElementTree, read-only
- property prefix:
- u"""Namespace prefix or None.
+ @property
+ def prefix(self):
+ """Namespace prefix or None.
"""
- def __get__(self):
- if self._c_node.ns is not NULL:
- if self._c_node.ns.prefix is not NULL:
- return funicode(self._c_node.ns.prefix)
- return None
+ if self._c_node.ns is not NULL:
+ if self._c_node.ns.prefix is not NULL:
+ return funicode(self._c_node.ns.prefix)
+ return None
# not in ElementTree, read-only
property sourceline:
@@ -1066,28 +1066,28 @@ cdef public class _Element [ type LxmlElementType, object LxmlElement ]:
self._c_node.line = line
# not in ElementTree, read-only
- property nsmap:
- u"""Namespace prefix->URI mapping known in the context of this
+ @property
+ def nsmap(self):
+ """Namespace prefix->URI mapping known in the context of this
Element. This includes all namespace declarations of the
parents.
Note that changing the returned dict has no effect on the Element.
"""
- def __get__(self):
- cdef xmlNode* c_node
- cdef xmlNs* c_ns
- _assertValidNode(self)
- nsmap = {}
- c_node = self._c_node
- while c_node is not NULL and c_node.type == tree.XML_ELEMENT_NODE:
- c_ns = c_node.nsDef
- while c_ns is not NULL:
- prefix = funicodeOrNone(c_ns.prefix)
- if prefix not in nsmap:
- nsmap[prefix] = funicodeOrNone(c_ns.href)
- c_ns = c_ns.next
- c_node = c_node.parent
- return nsmap
+ cdef xmlNode* c_node
+ cdef xmlNs* c_ns
+ _assertValidNode(self)
+ nsmap = {}
+ c_node = self._c_node
+ while c_node is not NULL and c_node.type == tree.XML_ELEMENT_NODE:
+ c_ns = c_node.nsDef
+ while c_ns is not NULL:
+ prefix = funicodeOrNone(c_ns.prefix)
+ if prefix not in nsmap:
+ nsmap[prefix] = funicodeOrNone(c_ns.href)
+ c_ns = c_ns.next
+ c_node = c_node.parent
+ return nsmap
# not in ElementTree, read-only
property base:
@@ -1640,9 +1640,9 @@ cdef class __ContentOnlyElement(_Element):
u"__setitem__(self, index, value)"
self._raiseImmutable()
- property attrib:
- def __get__(self):
- return IMMUTABLE_EMPTY_MAPPING
+ @property
+ def attrib(self):
+ return IMMUTABLE_EMPTY_MAPPING
property text:
def __get__(self):
@@ -1688,17 +1688,17 @@ cdef class __ContentOnlyElement(_Element):
return []
cdef class _Comment(__ContentOnlyElement):
- property tag:
- def __get__(self):
- return Comment
+ @property
+ def tag(self):
+ return Comment
def __repr__(self):
return "<!--%s-->" % strrepr(self.text)
cdef class _ProcessingInstruction(__ContentOnlyElement):
- property tag:
- def __get__(self):
- return ProcessingInstruction
+ @property
+ def tag(self):
+ return ProcessingInstruction
property target:
# not in ElementTree
@@ -1734,22 +1734,22 @@ cdef class _ProcessingInstruction(__ContentOnlyElement):
"""
return self.attrib.get(key, default)
- property attrib:
- u"""Returns a dict containing all pseudo-attributes that can be
+ @property
+ def attrib(self):
+ """Returns a dict containing all pseudo-attributes that can be
parsed from the text content of this processing instruction.
Note that modifying the dict currently has no effect on the
XML node, although this is not guaranteed to stay this way.
"""
- def __get__(self):
- return { attr : (value1 or value2)
- for attr, value1, value2 in _FIND_PI_ATTRIBUTES(u' ' + self.text) }
+ return { attr : (value1 or value2)
+ for attr, value1, value2 in _FIND_PI_ATTRIBUTES(u' ' + self.text) }
cdef object _FIND_PI_ATTRIBUTES = re.compile(ur'\s+(\w+)\s*=\s*(?:\'([^\']*)\'|"([^"]*)")', re.U).findall
cdef class _Entity(__ContentOnlyElement):
- property tag:
- def __get__(self):
- return Entity
+ @property
+ def tag(self):
+ return Entity
property name:
# not in ElementTree
@@ -1764,12 +1764,12 @@ cdef class _Entity(__ContentOnlyElement):
raise ValueError, f"Invalid entity name '{value}'"
tree.xmlNodeSetName(self._c_node, _xcstr(value_utf))
- property text:
+ @property
+ def text(self):
# FIXME: should this be None or '&[VALUE];' or the resolved
# entity value ?
- def __get__(self):
- _assertValidNode(self)
- return f'&{funicode(self._c_node.name)};'
+ _assertValidNode(self)
+ return f'&{funicode(self._c_node.name)};'
def __repr__(self):
return "&%s;" % strrepr(self.name)
@@ -1923,23 +1923,23 @@ cdef public class _ElementTree [ type LxmlElementTreeType,
return self
# not in ElementTree
- property docinfo:
- u"""Information about the document provided by parser and DTD."""
- def __get__(self):
- self._assertHasRoot()
- return DocInfo(self._context_node._doc)
+ @property
+ def docinfo(self):
+ """Information about the document provided by parser and DTD."""
+ self._assertHasRoot()
+ return DocInfo(self._context_node._doc)
# not in ElementTree, read-only
- property parser:
- u"""The parser that was used to parse the document in this ElementTree.
- """
- def __get__(self):
- if self._context_node is not None and \
- self._context_node._doc is not None:
- return self._context_node._doc._parser
- if self._doc is not None:
- return self._doc._parser
- return None
+ @property
+ def parser(self):
+ """The parser that was used to parse the document in this ElementTree.
+ """
+ if self._context_node is not None and \
+ self._context_node._doc is not None:
+ return self._context_node._doc._parser
+ if self._doc is not None:
+ return self._doc._parser
+ return None
def write(self, file, *, encoding=None, method=u"xml",
pretty_print=False, xml_declaration=None, with_tail=True,
@@ -3544,11 +3544,11 @@ cdef class _Validator:
cpdef _clear_error_log(self):
self._error_log.clear()
- property error_log:
- u"The log of validation errors and warnings."
- def __get__(self):
- assert self._error_log is not None, "XPath evaluator not initialised"
- return self._error_log.copy()
+ @property
+ def error_log(self):
+ """The log of validation errors and warnings."""
+ assert self._error_log is not None, "XPath evaluator not initialised"
+ return self._error_log.copy()
include "dtd.pxi" # DTD
include "relaxng.pxi" # RelaxNG
diff --git a/src/lxml/extensions.pxi b/src/lxml/extensions.pxi
index d2d059c4..35a321b7 100644
--- a/src/lxml/extensions.pxi
+++ b/src/lxml/extensions.pxi
@@ -295,27 +295,27 @@ cdef class _BaseContext:
# Python access to the XPath context for extension functions
- property context_node:
- def __get__(self):
- cdef xmlNode* c_node
- if self._xpathCtxt is NULL:
- raise XPathError, \
- u"XPath context is only usable during the evaluation"
- c_node = self._xpathCtxt.node
- if c_node is NULL:
- raise XPathError, u"no context node"
- if c_node.doc != self._xpathCtxt.doc:
- raise XPathError, \
- u"document-external context nodes are not supported"
- if self._doc is None:
- raise XPathError, u"document context is missing"
- return _elementFactory(self._doc, c_node)
-
- property eval_context:
- def __get__(self):
- if self._eval_context_dict is None:
- self._eval_context_dict = {}
- return self._eval_context_dict
+ @property
+ def context_node(self):
+ cdef xmlNode* c_node
+ if self._xpathCtxt is NULL:
+ raise XPathError, \
+ u"XPath context is only usable during the evaluation"
+ c_node = self._xpathCtxt.node
+ if c_node is NULL:
+ raise XPathError, u"no context node"
+ if c_node.doc != self._xpathCtxt.doc:
+ raise XPathError, \
+ u"document-external context nodes are not supported"
+ if self._doc is None:
+ raise XPathError, u"document context is missing"
+ return _elementFactory(self._doc, c_node)
+
+ @property
+ def eval_context(self):
+ if self._eval_context_dict is None:
+ self._eval_context_dict = {}
+ return self._eval_context_dict
# Python reference keeping during XPath function evaluation
diff --git a/src/lxml/iterparse.pxi b/src/lxml/iterparse.pxi
index 3a64a276..f0502e66 100644
--- a/src/lxml/iterparse.pxi
+++ b/src/lxml/iterparse.pxi
@@ -128,22 +128,22 @@ cdef class iterparse:
self._parser = parser
self._source = source
- property error_log:
- u"""The error log of the last (or current) parser run.
+ @property
+ def error_log(self):
+ """The error log of the last (or current) parser run.
"""
- def __get__(self):
- return self._parser.feed_error_log
+ return self._parser.feed_error_log
- property resolvers:
- u"""The custom resolver registry of the last (or current) parser run.
+ @property
+ def resolvers(self):
+ """The custom resolver registry of the last (or current) parser run.
"""
- def __get__(self):
- return self._parser.resolvers
+ return self._parser.resolvers
- property version:
- u"""The version of the underlying XML parser."""
- def __get__(self):
- return self._parser.version
+ @property
+ def version(self):
+ """The version of the underlying XML parser."""
+ return self._parser.version
def set_element_class_lookup(self, ElementClassLookup lookup = None):
u"""set_element_class_lookup(self, lookup = None)
diff --git a/src/lxml/objectify.pyx b/src/lxml/objectify.pyx
index f5204e6c..f5fe7b51 100644
--- a/src/lxml/objectify.pyx
+++ b/src/lxml/objectify.pyx
@@ -162,28 +162,28 @@ cdef class ObjectifiedElement(ElementBase):
def __reduce__(self):
return fromstring, (etree.tostring(self),)
- property text:
- def __get__(self):
- return textOf(self._c_node)
+ @property
+ def text(self):
+ return textOf(self._c_node)
- property __dict__:
- u"""A fake implementation for __dict__ to support dir() etc.
+ @property
+ def __dict__(self):
+ """A fake implementation for __dict__ to support dir() etc.
Note that this only considers the first child with a given name.
"""
- def __get__(self):
- cdef _Element child
- cdef dict children
- c_ns = tree._getNs(self._c_node)
- tag = u"{%s}*" % pyunicode(c_ns) if c_ns is not NULL else None
- children = {}
- for child in etree.ElementChildIterator(self, tag=tag):
- if c_ns is NULL and tree._getNs(child._c_node) is not NULL:
- continue
- name = pyunicode(child._c_node.name)
- if name not in children:
- children[name] = child
- return children
+ cdef _Element child
+ cdef dict children
+ c_ns = tree._getNs(self._c_node)
+ tag = u"{%s}*" % pyunicode(c_ns) if c_ns is not NULL else None
+ children = {}
+ for child in etree.ElementChildIterator(self, tag=tag):
+ if c_ns is NULL and tree._getNs(child._c_node) is not NULL:
+ continue
+ name = pyunicode(child._c_node.name)
+ if name not in children:
+ children[name] = child
+ return children
def __len__(self):
u"""Count self and siblings with the same tag.
@@ -594,9 +594,9 @@ cdef class ObjectifiedDataElement(ObjectifiedElement):
u"""This is the base class for all data type Elements. Subclasses should
override the 'pyval' property and possibly the __str__ method.
"""
- property pyval:
- def __get__(self):
- return textOf(self._c_node)
+ @property
+ def pyval(self):
+ return textOf(self._c_node)
def __str__(self):
return textOf(self._c_node) or ''
@@ -619,9 +619,9 @@ cdef class NumberElement(ObjectifiedDataElement):
"""
self._parse_value = function
- property pyval:
- def __get__(self):
- return _parseNumber(self)
+ @property
+ def pyval(self):
+ return _parseNumber(self)
def __int__(self):
return int(_parseNumber(self))
@@ -726,9 +726,9 @@ cdef class StringElement(ObjectifiedDataElement):
len(), iter(), str_attr[0], str_attr[0:1], etc. are *not* supported.
Instead, use the .text attribute to get a 'real' string.
"""
- property pyval:
- def __get__(self):
- return textOf(self._c_node) or u''
+ @property
+ def pyval(self):
+ return textOf(self._c_node) or u''
def __repr__(self):
return repr(textOf(self._c_node) or u'')
@@ -802,9 +802,10 @@ cdef class NoneElement(ObjectifiedDataElement):
def __hash__(self):
return hash(None)
- property pyval:
- def __get__(self):
- return None
+ @property
+ def pyval(self):
+ return None
+
cdef class BoolElement(IntElement):
u"""Boolean type base on string values: 'true' or 'false'.
@@ -830,9 +831,9 @@ cdef class BoolElement(IntElement):
def __repr__(self):
return repr(__parseBool(textOf(self._c_node)))
- property pyval:
- def __get__(self):
- return __parseBool(textOf(self._c_node))
+ @property
+ def pyval(self):
+ return __parseBool(textOf(self._c_node))
def __checkBool(s):
cdef int value = -1
diff --git a/src/lxml/parser.pxi b/src/lxml/parser.pxi
index f6f4fe6d..ded2fd35 100644
--- a/src/lxml/parser.pxi
+++ b/src/lxml/parser.pxi
@@ -620,7 +620,7 @@ cdef void _receiveParserError(void* c_context, xmlerror.xmlError* error) nogil:
_forwardParserError(<xmlparser.xmlParserCtxt*>c_context, error)
cdef int _raiseParseError(xmlparser.xmlParserCtxt* ctxt, filename,
- _ErrorLog error_log) except 0:
+ _ErrorLog error_log) except -1:
if filename is not None and \
ctxt.lastError.domain == xmlerror.XML_FROM_IO:
if isinstance(filename, bytes):
@@ -940,23 +940,23 @@ cdef class _BaseParser:
c_ctxt.sax.startDocument = _initSaxDocument
return c_ctxt
- property error_log:
- u"""The error log of the last parser run.
+ @property
+ def error_log(self):
+ """The error log of the last parser run.
"""
- def __get__(self):
- cdef _ParserContext context
- context = self._getParserContext()
- return context._error_log.copy()
+ cdef _ParserContext context
+ context = self._getParserContext()
+ return context._error_log.copy()
- property resolvers:
- u"The custom resolver registry of this parser."
- def __get__(self):
- return self._resolvers
+ @property
+ def resolvers(self):
+ """The custom resolver registry of this parser."""
+ return self._resolvers
- property version:
- u"The version of the underlying XML parser."
- def __get__(self):
- return u"libxml2 %d.%d.%d" % LIBXML_VERSION
+ @property
+ def version(self):
+ """The version of the underlying XML parser."""
+ return u"libxml2 %d.%d.%d" % LIBXML_VERSION
def setElementClassLookup(self, ElementClassLookup lookup = None):
u":deprecated: use ``parser.set_element_class_lookup(lookup)`` instead."
@@ -1230,14 +1230,14 @@ cdef void _initSaxDocument(void* ctxt) with gil:
cdef class _FeedParser(_BaseParser):
cdef bint _feed_parser_running
- property feed_error_log:
- u"""The error log of the last (or current) run of the feed parser.
+ @property
+ def feed_error_log(self):
+ """The error log of the last (or current) run of the feed parser.
Note that this is local to the feed parser and thus is
different from what the ``error_log`` property returns.
"""
- def __get__(self):
- return self._getPushParserContext()._error_log.copy()
+ return self._getPushParserContext()._error_log.copy()
cpdef feed(self, data):
u"""feed(self, data)
diff --git a/src/lxml/readonlytree.pxi b/src/lxml/readonlytree.pxi
index e532895c..41e2d0c6 100644
--- a/src/lxml/readonlytree.pxi
+++ b/src/lxml/readonlytree.pxi
@@ -26,61 +26,61 @@ cdef class _ReadOnlyProxy:
"""
self._free_after_use = 1
- property tag:
- u"""Element tag
+ @property
+ def tag(self):
+ """Element tag
"""
- def __get__(self):
- 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()
+ 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 text:
- u"""Text before the first subelement. This is either a string or
+ @property
+ def text(self):
+ """Text before the first subelement. This is either a string or
the value None, if there was no text.
"""
- def __get__(self):
- 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)};'
+ 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:
- self._raise_unsupported_type()
+ 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 tail:
- u"""Text after this element's end tag, but before the next sibling
+ @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.
"""
- def __get__(self):
- self._assertNode()
- return _collectText(self._c_node.next)
+ self._assertNode()
+ return _collectText(self._c_node.next)
- property sourceline:
- u"""Original line number as found by the parser or None if unknown.
+ @property
+ def sourceline(self):
+ """Original line number as found by the parser or None if unknown.
"""
- def __get__(self):
- cdef long line
- self._assertNode()
- line = tree.xmlGetLineNo(self._c_node)
- if line > 0:
- return line
- else:
- return None
+ cdef long line
+ self._assertNode()
+ line = tree.xmlGetLineNo(self._c_node)
+ if line > 0:
+ return line
+ else:
+ return None
def __repr__(self):
self._assertNode()
@@ -246,16 +246,16 @@ cdef class _ReadOnlyProxy:
@cython.final
@cython.internal
cdef class _ReadOnlyPIProxy(_ReadOnlyProxy):
- u"A read-only proxy for processing instructions (for internal use only!)"
- property target:
- def __get__(self):
- self._assertNode()
- return funicode(self._c_node.name)
+ """A read-only proxy for processing instructions (for internal use only!)"""
+ @property
+ def target(self):
+ self._assertNode()
+ return funicode(self._c_node.name)
@cython.final
@cython.internal
cdef class _ReadOnlyEntityProxy(_ReadOnlyProxy):
- u"A read-only proxy for entity references (for internal use only!)"
+ """A read-only proxy for entity references (for internal use only!)"""
property name:
def __get__(self):
return funicode(self._c_node.name)
@@ -266,29 +266,29 @@ cdef class _ReadOnlyEntityProxy(_ReadOnlyProxy):
raise ValueError(f"Invalid entity name '{value}'")
tree.xmlNodeSetName(self._c_node, _xcstr(value_utf))
- property text:
- def __get__(self):
- return f'&{funicode(self._c_node.name)};'
+ @property
+ def text(self):
+ return f'&{funicode(self._c_node.name)};'
@cython.internal
cdef class _ReadOnlyElementProxy(_ReadOnlyProxy):
- u"The main read-only Element proxy class (for internal use only!)."
+ """The main read-only Element proxy class (for internal use only!)."""
- property attrib:
- def __get__(self):
- self._assertNode()
- return dict(_collectAttributes(self._c_node, 3))
+ @property
+ def attrib(self):
+ self._assertNode()
+ return dict(_collectAttributes(self._c_node, 3))
- property prefix:
- u"""Namespace prefix or None.
+ @property
+ def prefix(self):
+ """Namespace prefix or None.
"""
- def __get__(self):
- self._assertNode()
- if self._c_node.ns is not NULL:
- if self._c_node.ns.prefix is not NULL:
- return funicode(self._c_node.ns.prefix)
- return None
+ self._assertNode()
+ if self._c_node.ns is not NULL:
+ if self._c_node.ns.prefix is not NULL:
+ return funicode(self._c_node.ns.prefix)
+ return None
def get(self, key, default=None):
u"""Gets an element attribute.
@@ -437,7 +437,7 @@ cdef class _ModifyContentOnlyProxy(_ReadOnlyProxy):
@cython.final
@cython.internal
cdef class _ModifyContentOnlyPIProxy(_ModifyContentOnlyProxy):
- u"""A read-only proxy that allows changing the text/target content of a
+ """A read-only proxy that allows changing the text/target content of a
processing instruction.
"""
property target:
@@ -454,7 +454,7 @@ cdef class _ModifyContentOnlyPIProxy(_ModifyContentOnlyProxy):
@cython.final
@cython.internal
cdef class _ModifyContentOnlyEntityProxy(_ModifyContentOnlyProxy):
- u"A read-only proxy for entity references (for internal use only!)"
+ "A read-only proxy for entity references (for internal use only!)"
property name:
def __get__(self):
return funicode(self._c_node.name)
@@ -494,7 +494,7 @@ cdef class _AppendOnlyElementProxy(_ReadOnlyElementProxy):
self.append(element)
property text:
- u"""Text before the first subelement. This is either a string or the
+ """Text before the first subelement. This is either a string or the
value None, if there was no text.
"""
def __get__(self):
diff --git a/src/lxml/xinclude.pxi b/src/lxml/xinclude.pxi
index 77fdb41e..f73afee6 100644
--- a/src/lxml/xinclude.pxi
+++ b/src/lxml/xinclude.pxi
@@ -19,10 +19,10 @@ cdef class XInclude:
def __init__(self):
self._error_log = _ErrorLog()
- property error_log:
- def __get__(self):
- assert self._error_log is not None, "XInclude instance not initialised"
- return self._error_log.copy()
+ @property
+ def error_log(self):
+ assert self._error_log is not None, "XInclude instance not initialised"
+ return self._error_log.copy()
def __call__(self, _Element node not None):
u"__call__(self, node)"
diff --git a/src/lxml/xmlerror.pxi b/src/lxml/xmlerror.pxi
index 3a7cacc8..ff314372 100644
--- a/src/lxml/xmlerror.pxi
+++ b/src/lxml/xmlerror.pxi
@@ -112,69 +112,73 @@ cdef class _LogEntry:
self.filename, self.line, self.column, self.level_name,
self.domain_name, self.type_name, self.message)
- property domain_name:
+ @property
+ def domain_name(self):
"""The name of the error domain. See lxml.etree.ErrorDomains
"""
- def __get__(self):
- return ErrorDomains._getName(self.domain, u"unknown")
+ return ErrorDomains._getName(self.domain, u"unknown")
- property type_name:
+ @property
+ def type_name(self):
"""The name of the error type. See lxml.etree.ErrorTypes
"""
- def __get__(self):
- if self.domain == ErrorDomains.RELAXNGV:
- getName = RelaxNGErrorTypes._getName
- else:
- getName = ErrorTypes._getName
- return getName(self.type, u"unknown")
+ if self.domain == ErrorDomains.RELAXNGV:
+ getName = RelaxNGErrorTypes._getName
+ else:
+ getName = ErrorTypes._getName
+ return getName(self.type, u"unknown")
- property level_name:
+ @property
+ def level_name(self):
"""The name of the error level. See lxml.etree.ErrorLevels
"""
- def __get__(self):
- return ErrorLevels._getName(self.level, u"unknown")
-
- property message:
- def __get__(self):
- cdef size_t size
- if self._message is not None:
- return self._message
- if self._c_message is NULL:
- return None
- size = cstring_h.strlen(self._c_message)
- if size > 0 and self._c_message[size-1] == '\n':
- size -= 1 # strip EOL
- # cannot use funicode() here because the message may contain
- # byte encoded file paths etc.
+ return ErrorLevels._getName(self.level, u"unknown")
+
+ @property
+ def message(self):
+ """The log message string.
+ """
+ cdef size_t size
+ if self._message is not None:
+ return self._message
+ if self._c_message is NULL:
+ return None
+ size = cstring_h.strlen(self._c_message)
+ if size > 0 and self._c_message[size-1] == '\n':
+ size -= 1 # strip EOL
+ # cannot use funicode() here because the message may contain
+ # byte encoded file paths etc.
+ try:
+ self._message = self._c_message[:size].decode('utf8')
+ except UnicodeDecodeError:
try:
- self._message = self._c_message[:size].decode('utf8')
+ self._message = self._c_message[:size].decode(
+ 'ascii', 'backslashreplace')
except UnicodeDecodeError:
- try:
- self._message = self._c_message[:size].decode(
- 'ascii', 'backslashreplace')
- except UnicodeDecodeError:
- self._message = u'<undecodable error message>'
- if self._c_message:
+ self._message = u'<undecodable error message>'
+ if self._c_message:
+ # clean up early
+ tree.xmlFree(self._c_message)
+ self._c_message = NULL
+ return self._message
+
+ @property
+ def filename(self):
+ """The file path where the report originated, if any.
+ """
+ if self._filename is None:
+ if self._c_filename is not NULL:
+ self._filename = _decodeFilename(self._c_filename)
# clean up early
- tree.xmlFree(self._c_message)
- self._c_message = NULL
- return self._message
+ tree.xmlFree(self._c_filename)
+ self._c_filename = NULL
+ return self._filename
- property filename:
- def __get__(self):
- if self._filename is None:
- if self._c_filename is not NULL:
- self._filename = _decodeFilename(self._c_filename)
- # clean up early
- tree.xmlFree(self._c_filename)
- self._c_filename = NULL
- return self._filename
-
- property path:
+ @property
+ def path(self):
"""The XPath for the node where the error was detected.
"""
- def __get__(self):
- return funicode(self._c_path) if self._c_path is not NULL else None
+ return funicode(self._c_path) if self._c_path is not NULL else None
cdef class _BaseErrorLog:
diff --git a/src/lxml/xpath.pxi b/src/lxml/xpath.pxi
index 784987d4..b926d553 100644
--- a/src/lxml/xpath.pxi
+++ b/src/lxml/xpath.pxi
@@ -133,10 +133,10 @@ cdef class _XPathEvaluatorBase:
self._context = _XPathContext(namespaces, extensions, self._error_log,
enable_regexp, None, smart_strings)
- property error_log:
- def __get__(self):
- assert self._error_log is not None, "XPath evaluator not initialised"
- return self._error_log.copy()
+ @property
+ def error_log(self):
+ assert self._error_log is not None, "XPath evaluator not initialised"
+ return self._error_log.copy()
def __dealloc__(self):
if self._xpathCtxt is not NULL:
@@ -448,11 +448,11 @@ cdef class XPath(_XPathEvaluatorBase):
self._unlock()
return result
- property path:
- u"""The literal XPath expression.
+ @property
+ def path(self):
+ """The literal XPath expression.
"""
- def __get__(self):
- return self._path.decode(u'UTF-8')
+ return self._path.decode(u'UTF-8')
def __dealloc__(self):
if self._xpath is not NULL:
diff --git a/src/lxml/xslt.pxi b/src/lxml/xslt.pxi
index 54e56550..d63a65ea 100644
--- a/src/lxml/xslt.pxi
+++ b/src/lxml/xslt.pxi
@@ -226,16 +226,16 @@ cdef class XSLTAccessControl:
cdef void _register_in_context(self, xslt.xsltTransformContext* ctxt):
xslt.xsltSetCtxtSecurityPrefs(self._prefs, ctxt)
- property options:
- u"The access control configuration as a map of options."
- def __get__(self):
- return {
- u'read_file': self._optval(xslt.XSLT_SECPREF_READ_FILE),
- u'write_file': self._optval(xslt.XSLT_SECPREF_WRITE_FILE),
- u'create_dir': self._optval(xslt.XSLT_SECPREF_CREATE_DIRECTORY),
- u'read_network': self._optval(xslt.XSLT_SECPREF_READ_NETWORK),
- u'write_network': self._optval(xslt.XSLT_SECPREF_WRITE_NETWORK),
- }
+ @property
+ def options(self):
+ """The access control configuration as a map of options."""
+ return {
+ u'read_file': self._optval(xslt.XSLT_SECPREF_READ_FILE),
+ u'write_file': self._optval(xslt.XSLT_SECPREF_WRITE_FILE),
+ u'create_dir': self._optval(xslt.XSLT_SECPREF_CREATE_DIRECTORY),
+ u'read_network': self._optval(xslt.XSLT_SECPREF_READ_NETWORK),
+ u'write_network': self._optval(xslt.XSLT_SECPREF_WRITE_NETWORK),
+ }
@cython.final
cdef _optval(self, xslt.xsltSecurityOption option):
@@ -427,10 +427,10 @@ cdef class XSLT:
if self._c_style is not NULL:
xslt.xsltFreeStylesheet(self._c_style)
- property error_log:
- u"The log of errors and warnings of an XSLT execution."
- def __get__(self):
- return self._error_log.copy()
+ @property
+ def error_log(self):
+ """The log of errors and warnings of an XSLT execution."""
+ return self._error_log.copy()
@staticmethod
def strparam(strval):
@@ -847,7 +847,7 @@ cdef class _XSLTResultTree(_ElementTree):
buffer.buf = NULL
property xslt_profile:
- u"""Return an ElementTree with profiling data for the stylesheet run.
+ """Return an ElementTree with profiling data for the stylesheet run.
"""
def __get__(self):
cdef object root