[Lxml-checkins] r35185 - in lxml/trunk: . src/lxml
scoder at codespeak.net
scoder at codespeak.net
Fri Dec 1 09:48:13 CET 2006
Author: scoder
Date: Fri Dec 1 09:47:54 2006
New Revision: 35185
Modified:
lxml/trunk/CHANGES.txt
lxml/trunk/src/lxml/etree.pyx
Log:
accept QName objects in Element.find*()
Modified: lxml/trunk/CHANGES.txt
==============================================================================
--- lxml/trunk/CHANGES.txt (original)
+++ lxml/trunk/CHANGES.txt Fri Dec 1 09:47:54 2006
@@ -15,6 +15,12 @@
possible to pass an --rpath directly to distutils; previously this was being
shadowed.
+Bugs fixed
+----------
+
+* Element.find*() did not accept QName objects as path
+
+
1.1.2 (2006-10-30)
==================
Modified: lxml/trunk/src/lxml/etree.pyx
==============================================================================
--- lxml/trunk/src/lxml/etree.pyx (original)
+++ lxml/trunk/src/lxml/etree.pyx Fri Dec 1 09:47:54 2006
@@ -202,6 +202,22 @@
raise type, value, traceback
+cdef class QName:
+ """QName wrapper.
+ """
+ cdef readonly object text
+ def __init__(self, text_or_uri, tag=None):
+ if tag is not None:
+ text_or_uri = "{%s}%s" % (text_or_uri, tag)
+ elif not _isString(text_or_uri):
+ text_or_uri = str(text_or_uri)
+ self.text = text_or_uri
+ def __str__(self):
+ return self.text
+ def __hash__(self):
+ return self.text.__hash__()
+
+
# forward declaration of _BaseParser, see parser.pxi
cdef class _BaseParser
@@ -1176,16 +1192,22 @@
def find(self, path):
"""Finds the first matching subelement, by tag name or path.
"""
+ if isinstance(path, QName):
+ path = (<QName>path).text
return _elementpath.find(self, path)
def findtext(self, path, default=None):
"""Finds text for the first matching subelement, by tag name or path.
"""
+ if isinstance(path, QName):
+ path = (<QName>path).text
return _elementpath.findtext(self, path, default)
def findall(self, path):
"""Finds all matching subelements, by tag name or path.
"""
+ if isinstance(path, QName):
+ path = (<QName>path).text
return _elementpath.findall(self, path)
def xpath(self, _path, namespaces=None, extensions=None, **_variables):
@@ -1699,21 +1721,6 @@
fromstring = XML
-cdef class QName:
- """QName wrapper.
- """
- cdef readonly object text
- def __init__(self, text_or_uri, tag=None):
- if tag is not None:
- text_or_uri = "{%s}%s" % (text_or_uri, tag)
- elif not _isString(text_or_uri):
- text_or_uri = str(text_or_uri)
- self.text = text_or_uri
- def __str__(self):
- return self.text
- def __hash__(self):
- return self.text.__hash__()
-
def iselement(element):
"""Checks if an object appears to be a valid element object.
"""
More information about the lxml-checkins
mailing list