[Lxml-checkins] r47326 - lxml/trunk/src/lxml
scoder at codespeak.net
scoder at codespeak.net
Tue Oct 9 11:20:55 CEST 2007
Author: scoder
Date: Tue Oct 9 11:20:53 2007
New Revision: 47326
Modified:
lxml/trunk/src/lxml/apihelpers.pxi
lxml/trunk/src/lxml/config.pxd
lxml/trunk/src/lxml/etree.pyx
lxml/trunk/src/lxml/etreepublic.pxd
lxml/trunk/src/lxml/iterparse.pxi
lxml/trunk/src/lxml/objectify.pyx
lxml/trunk/src/lxml/objectpath.pxi
lxml/trunk/src/lxml/parser.pxi
lxml/trunk/src/lxml/public-api.pxi
lxml/trunk/src/lxml/serializer.pxi
lxml/trunk/src/lxml/tree.pxd
lxml/trunk/src/lxml/xmlerror.pxi
Log:
use 'bint' instead of 'int' Pyrex type where appropriate
Modified: lxml/trunk/src/lxml/apihelpers.pxi
==============================================================================
--- lxml/trunk/src/lxml/apihelpers.pxi (original)
+++ lxml/trunk/src/lxml/apihelpers.pxi Tue Oct 9 11:20:53 2007
@@ -448,7 +448,7 @@
element._c_node, _cstr(ns), NULL)
return '%s:%s' % (c_ns.prefix, tag)
-cdef int _hasChild(xmlNode* c_node):
+cdef bint _hasChild(xmlNode* c_node):
return c_node is not NULL and _findChildForwards(c_node, 0) is not NULL
cdef xmlNode* _findChild(xmlNode* c_node, Py_ssize_t index):
@@ -534,7 +534,7 @@
return NULL
return c_node
-cdef int _tagMatches(xmlNode* c_node, char* c_href, char* c_name):
+cdef bint _tagMatches(xmlNode* c_node, char* c_href, char* c_name):
"""Tests if the node matches namespace URI and tag name.
A node matches if it matches both c_href and c_name.
@@ -697,7 +697,7 @@
cdef char* s
cdef char* c_end
cdef char c
- cdef int is_non_ascii
+ cdef bint is_non_ascii
s = _cstr(pystring)
c_end = s + python.PyString_GET_SIZE(pystring)
is_non_ascii = 0
Modified: lxml/trunk/src/lxml/config.pxd
==============================================================================
--- lxml/trunk/src/lxml/config.pxd (original)
+++ lxml/trunk/src/lxml/config.pxd Tue Oct 9 11:20:53 2007
@@ -1,3 +1,3 @@
cdef extern from "etree_defs.h":
- cdef int ENABLE_THREADING
- cdef int ENABLE_SCHEMATRON
+ cdef bint ENABLE_THREADING
+ cdef bint ENABLE_SCHEMATRON
Modified: lxml/trunk/src/lxml/etree.pyx
==============================================================================
--- lxml/trunk/src/lxml/etree.pyx (original)
+++ lxml/trunk/src/lxml/etree.pyx Tue Oct 9 11:20:53 2007
@@ -853,7 +853,6 @@
return c
def __nonzero__(self):
- cdef xmlNode* c_node
import warnings
warnings.warn(
"The behavior of this method will change in future versions. "
@@ -861,7 +860,7 @@
FutureWarning
)
# emulate old behaviour
- return bool(_hasChild(self._c_node))
+ return _hasChild(self._c_node)
def __contains__(self, element):
cdef xmlNode* c_node
@@ -1384,22 +1383,22 @@
The keyword argument 'method' selects the output method: 'xml' or
'html'.
"""
- cdef int c_write_declaration
+ cdef bint write_declaration
self._assertHasRoot()
# suppress decl. in default case (purely for ElementTree compatibility)
if xml_declaration is not None:
- c_write_declaration = bool(xml_declaration)
+ write_declaration = xml_declaration
if encoding is None:
encoding = 'ASCII'
elif encoding is None:
encoding = 'ASCII'
- c_write_declaration = 0
+ write_declaration = 0
else:
encoding = encoding.upper()
- c_write_declaration = encoding not in \
+ write_declaration = encoding not in \
('US-ASCII', 'ASCII', 'UTF8', 'UTF-8')
_tofilelike(file, self._context_node, encoding, method,
- c_write_declaration, 1, bool(pretty_print))
+ write_declaration, 1, pretty_print)
def getpath(self, _Element element not None):
"""Returns a structural, absolute XPath expression to find that element.
@@ -2164,7 +2163,7 @@
"""Writes an element tree or element structure to sys.stdout. This function
should be used for debugging only.
"""
- _dumpToFile(sys.stdout, elem._c_node, bool(pretty_print))
+ _dumpToFile(sys.stdout, elem._c_node, pretty_print)
def tostring(element_or_tree, encoding=None, method="xml",
xml_declaration=None, pretty_print=False):
@@ -2178,26 +2177,25 @@
The keyword argument 'pretty_print' (bool) enables formatted XML.
- The keyword argument 'method' selects the output method: 'xml' or 'html'.
+ The keyword argument 'method' selects the output method: 'xml',
+ 'html' or plain 'text'.
"""
- cdef int write_declaration
- cdef int c_pretty_print
- c_pretty_print = bool(pretty_print)
+ cdef bint write_declaration
if xml_declaration is None:
# by default, write an XML declaration only for non-standard encodings
write_declaration = encoding is not None and encoding.upper() not in \
('ASCII', 'UTF-8', 'UTF8', 'US-ASCII')
else:
- write_declaration = bool(xml_declaration)
+ write_declaration = xml_declaration
if encoding is None:
encoding = 'ASCII'
if isinstance(element_or_tree, _Element):
return _tostring(<_Element>element_or_tree, encoding, method,
- write_declaration, 0, c_pretty_print)
+ write_declaration, 0, pretty_print)
elif isinstance(element_or_tree, _ElementTree):
return _tostring((<_ElementTree>element_or_tree)._context_node,
- encoding, method, write_declaration, 1, c_pretty_print)
+ encoding, method, write_declaration, 1, pretty_print)
else:
raise TypeError, "Type '%s' cannot be serialized." % type(element_or_tree)
@@ -2218,17 +2216,16 @@
therefore not necessarily suited for serialization to byte streams without
further treatment.
- The keyword argument 'pretty_print' (bool) enables formatted XML.
+ The boolean keyword argument 'pretty_print' enables formatted XML.
- The keyword argument 'method' selects the output method: 'xml' or 'html'.
+ The keyword argument 'method' selects the output method: 'xml',
+ 'html' or plain 'text'.
"""
- cdef int c_pretty_print
- c_pretty_print = bool(pretty_print)
if isinstance(element_or_tree, _Element):
- return _tounicode(<_Element>element_or_tree, method, 0, c_pretty_print)
+ return _tounicode(<_Element>element_or_tree, method, 0, pretty_print)
elif isinstance(element_or_tree, _ElementTree):
return _tounicode((<_ElementTree>element_or_tree)._context_node,
- method, 1, c_pretty_print)
+ method, 1, pretty_print)
else:
raise TypeError, "Type '%s' cannot be serialized." % type(element_or_tree)
Modified: lxml/trunk/src/lxml/etreepublic.pxd
==============================================================================
--- lxml/trunk/src/lxml/etreepublic.pxd (original)
+++ lxml/trunk/src/lxml/etreepublic.pxd Tue Oct 9 11:20:53 2007
@@ -5,7 +5,7 @@
cdef extern from "etree_defs.h":
# test if c_node is considered an Element (i.e. Element, Comment, etc.)
- cdef int _isElement(tree.xmlNode* c_node)
+ cdef bint _isElement(tree.xmlNode* c_node)
# return the namespace URI of the node or NULL
cdef char* _getNs(tree.xmlNode* node)
@@ -129,7 +129,7 @@
# XML node helper functions
# check if the element has at least one child
- cdef int hasChild(tree.xmlNode* c_node)
+ cdef bint hasChild(tree.xmlNode* c_node)
# find child element number 'index' (supports negative indexes)
cdef tree.xmlNode* findChild(tree.xmlNode* c_node,
@@ -191,10 +191,10 @@
cdef object namespacedNameFromNsName(char* c_ns, char* c_tag)
# check if the node has a text value (which may be '')
- cdef int hasText(tree.xmlNode* c_node)
+ cdef bint hasText(tree.xmlNode* c_node)
# check if the node has a tail value (which may be '')
- cdef int hasTail(tree.xmlNode* c_node)
+ cdef bint hasTail(tree.xmlNode* c_node)
# get the text content of an element (or None)
cdef object textOf(tree.xmlNode* c_node)
Modified: lxml/trunk/src/lxml/iterparse.pxi
==============================================================================
--- lxml/trunk/src/lxml/iterparse.pxi (original)
+++ lxml/trunk/src/lxml/iterparse.pxi Tue Oct 9 11:20:53 2007
@@ -292,7 +292,6 @@
filename = _encodeFilename(filename)
self._source = source
- html = bool(html)
if html:
# make sure we're not looking for namespaces
if 'start' in events:
Modified: lxml/trunk/src/lxml/objectify.pyx
==============================================================================
--- lxml/trunk/src/lxml/objectify.pyx (original)
+++ lxml/trunk/src/lxml/objectify.pyx Tue Oct 9 11:20:53 2007
@@ -1045,7 +1045,7 @@
cdef object _makeelement
cdef object _namespace
cdef object _nsmap
- cdef int _annotate
+ cdef bint _annotate
def __init__(self, namespace=None, nsmap=None, annotate=True,
makeelement=None):
if nsmap is None:
@@ -1055,7 +1055,7 @@
self._namespace = None
else:
self._namespace = "{%s}" % namespace
- self._annotate = bool(annotate)
+ self._annotate = annotate
if makeelement is not None:
assert callable(makeelement)
self._makeelement = makeelement
@@ -1077,15 +1077,15 @@
cdef object _tag
cdef object _nsmap
cdef object _element_factory
- cdef int _annotate
+ cdef bint _annotate
def __call__(self, *children, **attrib):
cdef _ObjectifyElementMakerCaller elementMaker
cdef python.PyObject* pytype
cdef _Element element
cdef _Element childElement
- cdef int has_children
- cdef int has_string_value
+ cdef bint has_children
+ cdef bint has_string_value
if self._element_factory is None:
element = _makeElement(self._tag, None, attrib, self._nsmap)
else:
@@ -1153,7 +1153,7 @@
################################################################################
# Recursive element dumping
-cdef int __RECURSIVE_STR
+cdef bint __RECURSIVE_STR
__RECURSIVE_STR = 0 # default: off
def enableRecursiveStr(on=True):
@@ -1161,7 +1161,7 @@
based on objectify.dump(element).
"""
global __RECURSIVE_STR
- __RECURSIVE_STR = bool(on)
+ __RECURSIVE_STR = on
def dump(_Element element not None):
"""Return a recursively generated string representation of an element.
@@ -1323,8 +1323,7 @@
"""
cdef _Element element
element = cetree.rootNodeOrRaise(element_or_tree)
- _annotate(element, 0, 1, bool(ignore_xsi), bool(ignore_old),
- None, empty_pytype)
+ _annotate(element, 0, 1, ignore_xsi, ignore_old, None, empty_pytype)
def xsiannotate(element_or_tree, ignore_old=False, ignore_pytype=False,
empty_type=None):
@@ -1350,8 +1349,7 @@
"""
cdef _Element element
element = cetree.rootNodeOrRaise(element_or_tree)
- _annotate(element, 1, 0, bool(ignore_old), bool(ignore_pytype),
- empty_type, None)
+ _annotate(element, 1, 0, ignore_old, ignore_pytype, empty_type, None)
def annotate(element_or_tree, ignore_old=True, ignore_xsi=False,
empty_pytype=None, empty_type=None, annotate_xsi=0,
@@ -1386,12 +1384,12 @@
"""
cdef _Element element
element = cetree.rootNodeOrRaise(element_or_tree)
- _annotate(element, annotate_xsi, annotate_pytype, bool(ignore_xsi),
- bool(ignore_old), empty_type, empty_pytype)
+ _annotate(element, annotate_xsi, annotate_pytype, ignore_xsi,
+ ignore_old, empty_type, empty_pytype)
-cdef _annotate(_Element element, int annotate_xsi, int annotate_pytype,
- int ignore_xsi, int ignore_pytype,
+cdef _annotate(_Element element, bint annotate_xsi, bint annotate_pytype,
+ bint ignore_xsi, bint ignore_pytype,
empty_type_name, empty_pytype_name):
cdef _Document doc
cdef tree.xmlNode* c_node
Modified: lxml/trunk/src/lxml/objectpath.pxi
==============================================================================
--- lxml/trunk/src/lxml/objectpath.pxi (original)
+++ lxml/trunk/src/lxml/objectpath.pxi Tue Oct 9 11:20:53 2007
@@ -86,7 +86,7 @@
"""Parse object path string into a 'hrefOnameOhrefOnameOOO' string and an
index list. The index list is None if no index was used in the path.
"""
- cdef int has_dot
+ cdef bint has_dot
new_path = []
path = cetree.utf8(path.strip())
if path == '.':
Modified: lxml/trunk/src/lxml/parser.pxi
==============================================================================
--- lxml/trunk/src/lxml/parser.pxi (original)
+++ lxml/trunk/src/lxml/parser.pxi Tue Oct 9 11:20:53 2007
@@ -431,7 +431,7 @@
cdef object _handleParseResult(self, _BaseParser parser,
xmlDoc* result, filename):
cdef xmlDoc* c_doc
- cdef int recover
+ cdef bint recover
recover = parser._parse_options & xmlparser.XML_PARSE_RECOVER
c_doc = _handleParseResult(self, self._c_ctxt, result,
filename, recover)
@@ -439,7 +439,7 @@
cdef xmlDoc* _handleParseResultDoc(self, _BaseParser parser,
xmlDoc* result, filename) except NULL:
- cdef int recover
+ cdef bint recover
recover = parser._parse_options & xmlparser.XML_PARSE_RECOVER
return _handleParseResult(self, self._c_ctxt, result,
filename, recover)
@@ -481,8 +481,8 @@
cdef xmlDoc* _handleParseResult(_ParserContext context,
xmlparser.xmlParserCtxt* c_ctxt,
xmlDoc* result, filename,
- int recover) except NULL:
- cdef int well_formed
+ bint recover) except NULL:
+ cdef bint well_formed
if c_ctxt.myDoc is not NULL:
if c_ctxt.myDoc != result:
tree.xmlFreeDoc(c_ctxt.myDoc)
@@ -556,8 +556,8 @@
self._filename = filename
self._target = target
self._for_html = for_html
- self._remove_comments = bool(remove_comments)
- self._remove_pis = bool(remove_pis)
+ self._remove_comments = remove_comments
+ self._remove_pis = remove_pis
self._resolvers = _ResolverRegistry()
@@ -711,7 +711,6 @@
cdef python.PyThreadState* state
cdef xmlDoc* result
cdef xmlparser.xmlParserCtxt* pctxt
- cdef int recover
cdef Py_ssize_t py_buffer_len
cdef int buffer_len
cdef char* c_text
@@ -752,7 +751,6 @@
cdef python.PyThreadState* state
cdef xmlDoc* result
cdef xmlparser.xmlParserCtxt* pctxt
- cdef int recover
cdef char* c_encoding
if c_len > python.INT_MAX:
raise ParserError, "string is too long to parse it with libxml2"
@@ -788,7 +786,6 @@
cdef python.PyThreadState* state
cdef xmlDoc* result
cdef xmlparser.xmlParserCtxt* pctxt
- cdef int recover
cdef int orig_options
cdef char* c_encoding
result = NULL
@@ -825,7 +822,6 @@
cdef xmlDoc* result
cdef xmlparser.xmlParserCtxt* pctxt
cdef char* c_filename
- cdef int recover
if not filename:
filename = None
@@ -884,7 +880,6 @@
cdef char* c_encoding
cdef int buffer_len
cdef int error
- cdef int recover
if python.PyString_Check(data):
c_encoding = NULL
c_data = _cstr(data)
Modified: lxml/trunk/src/lxml/public-api.pxi
==============================================================================
--- lxml/trunk/src/lxml/public-api.pxi (original)
+++ lxml/trunk/src/lxml/public-api.pxi Tue Oct 9 11:20:53 2007
@@ -54,10 +54,10 @@
cdef public _Element rootNodeOrRaise(object input):
return _rootNodeOrRaise(input)
-cdef public int hasText(xmlNode* c_node):
+cdef public bint hasText(xmlNode* c_node):
return _hasText(c_node)
-cdef public int hasTail(xmlNode* c_node):
+cdef public bint hasTail(xmlNode* c_node):
return _hasTail(c_node)
cdef public object textOf(xmlNode* c_node):
@@ -106,7 +106,7 @@
char* c_href, char* c_name):
return _delAttributeFromNsName(c_element, c_href, c_name)
-cdef public int hasChild(xmlNode* c_node):
+cdef public bint hasChild(xmlNode* c_node):
return _hasChild(c_node)
cdef public xmlNode* findChild(xmlNode* c_node, Py_ssize_t index):
Modified: lxml/trunk/src/lxml/serializer.pxi
==============================================================================
--- lxml/trunk/src/lxml/serializer.pxi (original)
+++ lxml/trunk/src/lxml/serializer.pxi Tue Oct 9 11:20:53 2007
@@ -44,8 +44,8 @@
return python.PyUnicode_AsEncodedString(text, encoding, 'strict')
cdef _tostring(_Element element, encoding, method,
- int write_xml_declaration, int write_complete_document,
- int pretty_print):
+ bint write_xml_declaration, bint write_complete_document,
+ bint pretty_print):
"""Serialize an element to an encoded string representation of its XML
tree.
"""
@@ -96,7 +96,7 @@
return result
cdef _tounicode(_Element element, method,
- int write_complete_document, int pretty_print):
+ bint write_complete_document, bint pretty_print):
"""Serialize an element to the Python unicode representation of its XML
tree.
"""
@@ -133,9 +133,9 @@
cdef void _writeNodeToBuffer(tree.xmlOutputBuffer* c_buffer,
xmlNode* c_node, char* encoding, int c_method,
- int write_xml_declaration,
- int write_complete_document,
- int pretty_print):
+ bint write_xml_declaration,
+ bint write_complete_document,
+ bint pretty_print):
cdef xmlDoc* c_doc
cdef xmlNode* c_nsdecl_node
c_doc = c_node.doc
@@ -222,7 +222,7 @@
tree.xmlOutputBufferWrite(c_buffer, 3, "]>\n")
cdef void _writeTail(tree.xmlOutputBuffer* c_buffer, xmlNode* c_node,
- char* encoding, int pretty_print):
+ char* encoding, bint pretty_print):
"Write the element tail."
c_node = c_node.next
while c_node is not NULL and c_node.type == tree.XML_TEXT_NODE:
@@ -231,7 +231,7 @@
c_node = c_node.next
cdef void _writePrevSiblings(tree.xmlOutputBuffer* c_buffer, xmlNode* c_node,
- char* encoding, int pretty_print):
+ char* encoding, bint pretty_print):
cdef xmlNode* c_sibling
if c_node.parent is not NULL and _isElement(c_node.parent):
return
@@ -247,7 +247,7 @@
c_sibling = c_sibling.next
cdef void _writeNextSiblings(tree.xmlOutputBuffer* c_buffer, xmlNode* c_node,
- char* encoding, int pretty_print):
+ char* encoding, bint pretty_print):
cdef xmlNode* c_sibling
if c_node.parent is not NULL and _isElement(c_node.parent):
return
@@ -307,8 +307,8 @@
return (<_FilelikeWriter>ctxt).close()
cdef _tofilelike(f, _Element element, encoding, method,
- int write_xml_declaration, int write_doctype,
- int pretty_print):
+ bint write_xml_declaration, bint write_doctype,
+ bint pretty_print):
cdef python.PyThreadState* state
cdef _FilelikeWriter writer
cdef tree.xmlOutputBuffer* c_buffer
@@ -400,7 +400,7 @@
# dump node to file (mainly for debug)
-cdef _dumpToFile(f, xmlNode* c_node, int pretty_print):
+cdef _dumpToFile(f, xmlNode* c_node, bint pretty_print):
cdef tree.xmlOutputBuffer* c_buffer
if not python.PyFile_Check(f):
raise ValueError, "Not a file"
Modified: lxml/trunk/src/lxml/tree.pxd
==============================================================================
--- lxml/trunk/src/lxml/tree.pxd (original)
+++ lxml/trunk/src/lxml/tree.pxd Tue Oct 9 11:20:53 2007
@@ -300,9 +300,9 @@
cdef void* xmlMalloc(size_t size)
cdef extern from "etree_defs.h":
- cdef int _isElement(xmlNode* node)
- cdef int _isElementOrXInclude(xmlNode* node)
+ cdef bint _isElement(xmlNode* node)
+ cdef bint _isElementOrXInclude(xmlNode* node)
cdef char* _getNs(xmlNode* node)
cdef void BEGIN_FOR_EACH_ELEMENT_FROM(xmlNode* tree_top,
- xmlNode* start_node, int inclusive)
+ xmlNode* start_node, bint inclusive)
cdef void END_FOR_EACH_ELEMENT_FROM(xmlNode* start_node)
Modified: lxml/trunk/src/lxml/xmlerror.pxi
==============================================================================
--- lxml/trunk/src/lxml/xmlerror.pxi (original)
+++ lxml/trunk/src/lxml/xmlerror.pxi Tue Oct 9 11:20:53 2007
@@ -98,7 +98,7 @@
return ''
cdef void _receive(self, xmlerror.xmlError* error):
- cdef int is_error
+ cdef bint is_error
cdef _LogEntry entry
entry = _LogEntry()
entry._setError(error)
@@ -114,6 +114,7 @@
cdef void _receiveGeneric(self, int domain, int type, int level, int line,
message, filename):
+ cdef bint is_error
cdef _LogEntry entry
entry = _LogEntry()
entry._setGeneric(domain, type, level, line, message, filename)
@@ -184,7 +185,9 @@
return False
def __nonzero__(self):
- return bool(self._entries)
+ cdef bint result
+ result = self._entries
+ return result
def filter_domains(self, domains):
"""Filter the errors by the given domains and return a new error log
More information about the lxml-checkins
mailing list