summaryrefslogtreecommitdiff
path: root/src/lxml
diff options
context:
space:
mode:
authorscoder <none@none>2008-05-31 17:02:30 +0200
committerscoder <none@none>2008-05-31 17:02:30 +0200
commit72b7cc943961017681304b6ad20dc3f9bf5fdb50 (patch)
tree85c4eae81d27955b783356556ca0ceff4a078883 /src/lxml
parent9b43d83cca56fd4d4cbf808f01f26ef57a2054a6 (diff)
downloadpython-lxml-72b7cc943961017681304b6ad20dc3f9bf5fdb50.tar.gz
[svn r3783] r4428@delle: sbehnel | 2008-05-31 16:31:40 +0200
fixes for str/bytes handling in Py3 --HG-- branch : trunk
Diffstat (limited to 'src/lxml')
-rw-r--r--src/lxml/etree_defs.h7
-rw-r--r--src/lxml/lxml.etree.pyx32
-rw-r--r--src/lxml/lxml.objectify.pyx6
3 files changed, 35 insertions, 10 deletions
diff --git a/src/lxml/etree_defs.h b/src/lxml/etree_defs.h
index 480a5f23..8f68a5d3 100644
--- a/src/lxml/etree_defs.h
+++ b/src/lxml/etree_defs.h
@@ -131,9 +131,16 @@ long _ftol2( double dblSource ) { return _ftol( dblSource ); }
#define _fqtypename(o) ((Py_TYPE(o))->tp_name)
+#if PY_MAJOR_VERSION < 3
#define _isString(obj) (PyString_CheckExact(obj) || \
PyUnicode_CheckExact(obj) || \
PyObject_TypeCheck(obj, &PyBaseString_Type))
+#else
+#define _isString(obj) (PyUnicode_CheckExact(obj) || \
+ PyBytes_CheckExact(obj) || \
+ PyUnicode_Check(obj) || \
+ PyBytes_Check(obj))
+#endif
#define _isElement(c_node) \
(((c_node)->type == XML_ELEMENT_NODE) || \
diff --git a/src/lxml/lxml.etree.pyx b/src/lxml/lxml.etree.pyx
index 913e4433..fdcfa14e 100644
--- a/src/lxml/lxml.etree.pyx
+++ b/src/lxml/lxml.etree.pyx
@@ -1650,8 +1650,12 @@ cdef public class _ElementTree [ type LxmlElementTreeType,
"""
self._assertHasRoot()
root = self.getroot()
- if _isString(path) and path[:1] == u"/":
- path = u"." + path
+ if _isString(path):
+ start = path[:1]
+ if start == u"/":
+ path = u"." + path
+ elif start == "/":
+ path = "." + path
return root.find(path)
def findtext(self, path, default=None):
@@ -1662,8 +1666,12 @@ cdef public class _ElementTree [ type LxmlElementTreeType,
"""
self._assertHasRoot()
root = self.getroot()
- if _isString(path) and path[:1] == "/":
- path = "." + path
+ if _isString(path):
+ start = path[:1]
+ if start == u"/":
+ path = u"." + path
+ elif start == "/":
+ path = "." + path
return root.findtext(path, default)
def findall(self, path):
@@ -1674,8 +1682,12 @@ cdef public class _ElementTree [ type LxmlElementTreeType,
"""
self._assertHasRoot()
root = self.getroot()
- if _isString(path) and path[:1] == u"/":
- path = u"." + path
+ if _isString(path):
+ start = path[:1]
+ if start == u"/":
+ path = u"." + path
+ elif start == "/":
+ path = "." + path
return root.findall(path)
def iterfind(self, path):
@@ -1686,8 +1698,12 @@ cdef public class _ElementTree [ type LxmlElementTreeType,
"""
self._assertHasRoot()
root = self.getroot()
- if _isString(path) and path[:1] == "/":
- path = "." + path
+ if _isString(path):
+ start = path[:1]
+ if start == u"/":
+ path = u"." + path
+ elif start == "/":
+ path = "." + path
return root.iterfind(path)
def xpath(self, _path, *, namespaces=None, extensions=None, **_variables):
diff --git a/src/lxml/lxml.objectify.pyx b/src/lxml/lxml.objectify.pyx
index c942ce36..96ab8de8 100644
--- a/src/lxml/lxml.objectify.pyx
+++ b/src/lxml/lxml.objectify.pyx
@@ -949,7 +949,9 @@ cdef class PyType:
cdef object _type
cdef object _schema_types
def __init__(self, name, type_check, type_class, stringify=None):
- if not python._isString(name):
+ if python.PyString_Check(name):
+ name = python.PyUnicode_FromEncodedObject(name, 'ASCII', NULL)
+ elif not python.PyUnicode_Check(name):
raise TypeError, u"Type name must be a string"
if type_check is not None and not callable(type_check):
raise TypeError, u"Type check function must be callable (or None)"
@@ -1031,7 +1033,7 @@ cdef class PyType:
def __get__(self):
return self._schema_types
def __set__(self, types):
- self._schema_types = list(types)
+ self._schema_types = list(map(unicode, types))
cdef object _PYTYPE_DICT