[Lxml-checkins] r49927 - in lxml/trunk: . src/lxml

scoder at codespeak.net scoder at codespeak.net
Wed Dec 19 12:13:14 CET 2007


Author: scoder
Date: Wed Dec 19 12:13:14 2007
New Revision: 49927

Modified:
   lxml/trunk/   (props changed)
   lxml/trunk/CHANGES.txt
   lxml/trunk/src/lxml/lxml.etree.pyx
   lxml/trunk/src/lxml/xpath.pxi
Log:
 r3143 at delle:  sbehnel | 2007-12-19 12:13:06 +0100
 proposed keyword-only API for XPath and iteration methods


Modified: lxml/trunk/CHANGES.txt
==============================================================================
--- lxml/trunk/CHANGES.txt	(original)
+++ lxml/trunk/CHANGES.txt	Wed Dec 19 12:13:14 2007
@@ -23,7 +23,12 @@
 Other changes
 -------------
 
-* Parts of the XSLT API now require keyword-only arguments.
+* Various places in the XPath, XSLT and iteration APIs now require
+  keyword-only arguments.
+
+* The argument order in ``element.itersiblings()`` was changed to
+  match the order used in all other iteration methods.  The second
+  argument ('preceding') is now a keyword-only argument.
 
 * The ``getiterator()`` method on Elements and ElementTrees was
   reverted to return an iterator as it did in lxml 1.x.  The ET API

Modified: lxml/trunk/src/lxml/lxml.etree.pyx
==============================================================================
--- lxml/trunk/src/lxml/lxml.etree.pyx	(original)
+++ lxml/trunk/src/lxml/lxml.etree.pyx	Wed Dec 19 12:13:14 2007
@@ -1065,7 +1065,7 @@
             return _elementFactory(self._doc, c_node)
         return None
 
-    def itersiblings(self, preceding=False, tag=None):
+    def itersiblings(self, tag=None, *, preceding=False):
         """Iterate over the following or preceding siblings of this element.
 
         The direction is determined by the 'preceding' keyword which defaults
@@ -1073,7 +1073,7 @@
         generated elements can be restricted to a specific tag name with the
         'tag' keyword.
         """
-        return SiblingsIterator(self, preceding, tag)
+        return SiblingsIterator(self, tag, preceding=preceding)
 
     def iterancestors(self, tag=None):
         """Iterate over the ancestors of this element (from parent to parent).
@@ -1090,16 +1090,16 @@
         itself.  The generated elements can be restricted to a specific tag
         name with the 'tag' keyword.
         """
-        return ElementDepthFirstIterator(self, tag, False)
+        return ElementDepthFirstIterator(self, tag, inclusive=False)
 
-    def iterchildren(self, reversed=False, tag=None):
+    def iterchildren(self, tag=None, *, reversed=False):
         """Iterate over the children of this element.
 
         As opposed to using normal iteration on this element, the generated
         elements can be restricted to a specific tag name with the 'tag'
         keyword and reversed with the 'reversed' keyword.
         """
-        return ElementChildIterator(self, reversed, tag)
+        return ElementChildIterator(self, tag, reversed=reversed)
 
     def getroottree(self):
         """Return an ElementTree for the root node of the document that
@@ -1143,7 +1143,7 @@
         """
         return ElementDepthFirstIterator(self, tag)
 
-    def itertext(self, tag=None, with_tail=True):
+    def itertext(self, tag=None, *, with_tail=True):
         """Iterates over the text content of a subtree.
 
         You can pass the ``tag`` keyword argument to restrict text content to
@@ -1152,7 +1152,7 @@
         You can set the ``with_tail`` keyword argument to ``False`` to skip
         over tail text.
         """
-        return ElementTextIterator(self, tag, with_tail)
+        return ElementTextIterator(self, tag, with_tail=with_tail)
 
     def makeelement(self, _tag, attrib=None, nsmap=None, **_extra):
         """Creates a new element associated with the same document.
@@ -1188,10 +1188,11 @@
             path = (<QName>path).text
         return _elementpath.iterfind(self, path)
 
-    def xpath(self, _path, namespaces=None, extensions=None, **_variables):
+    def xpath(self, _path, *, namespaces=None, extensions=None, **_variables):
         """Evaluate an xpath expression using the element as context node.
         """
-        evaluator = XPathElementEvaluator(self, namespaces, extensions)
+        evaluator = XPathElementEvaluator(self, namespaces=namespaces,
+                                          extensions=extensions)
         return evaluator.evaluate(_path, **_variables)
 
 
@@ -1545,7 +1546,7 @@
             path = "." + path
         return root.iterfind(path)
 
-    def xpath(self, _path, namespaces=None, extensions=None, **_variables):
+    def xpath(self, _path, *, namespaces=None, extensions=None, **_variables):
         """XPath evaluate in context of document.
 
         ``namespaces`` is an optional dictionary with prefix to namespace URI
@@ -1562,7 +1563,8 @@
         XPathEvaluator directly.
         """
         self._assertHasRoot()
-        evaluator = XPathDocumentEvaluator(self, namespaces, extensions)
+        evaluator = XPathDocumentEvaluator(self, namespaces=namespaces,
+                                           extensions=extensions)
         return evaluator.evaluate(_path, **_variables)
 
     def xslt(self, _xslt, extensions=None, access_control=None, **_kw):
@@ -1892,7 +1894,7 @@
 
 cdef class ElementChildIterator(_ElementIterator):
     "Iterates over the children of an element."
-    def __init__(self, _Element node not None, reversed=False, tag=None):
+    def __init__(self, _Element node not None, tag=None, *, reversed=False):
         cdef xmlNode* c_node
         self._initTagMatch(tag)
         if reversed:
@@ -1916,7 +1918,7 @@
 
     You can pass the boolean keyword ``preceding`` to specify the direction.
     """
-    def __init__(self, _Element node not None, preceding=False, tag=None):
+    def __init__(self, _Element node not None, tag=None, *, preceding=False):
         self._initTagMatch(tag)
         if preceding:
             self._next_element = _previousElement
@@ -1951,7 +1953,7 @@
     # keep next node to return and a depth counter in the tree
     cdef _Element _next_node
     cdef _Element _top_node
-    def __init__(self, _Element node not None, tag=None, inclusive=True):
+    def __init__(self, _Element node not None, tag=None, *, inclusive=True):
         self._top_node  = node
         self._next_node = node
         self._initTagMatch(tag)
@@ -2009,7 +2011,7 @@
     """
     cdef object _nextEvent
     cdef _Element _start_element
-    def __init__(self, _Element element not None, tag=None, with_tail=True):
+    def __init__(self, _Element element not None, tag=None, *, with_tail=True):
         if with_tail:
             events = ("start", "end")
         else:

Modified: lxml/trunk/src/lxml/xpath.pxi
==============================================================================
--- lxml/trunk/src/lxml/xpath.pxi	(original)
+++ lxml/trunk/src/lxml/xpath.pxi	Wed Dec 19 12:13:14 2007
@@ -215,7 +215,7 @@
     the 'regexp' boolean keyword (defaults to True).
     """
     cdef _Element _element
-    def __init__(self, _Element element not None, namespaces=None,
+    def __init__(self, _Element element not None, *, namespaces=None,
                  extensions=None, regexp=True):
         cdef xpath.xmlXPathContext* xpathCtxt
         cdef int ns_register_status
@@ -280,10 +280,11 @@
     keyword argument.  EXSLT regular expression support can be disabled with
     the 'regexp' boolean keyword (defaults to True).
     """
-    def __init__(self, _ElementTree etree not None, namespaces=None,
+    def __init__(self, _ElementTree etree not None, *, namespaces=None,
                  extensions=None, regexp=True):
         XPathElementEvaluator.__init__(
-            self, etree._context_node, namespaces, extensions, regexp)
+            self, etree._context_node, namespaces=namespaces, 
+            extensions=extensions, regexp=regexp)
 
     def __call__(self, _path, **_variables):
         """Evaluate an XPath expression on the document.
@@ -322,7 +323,7 @@
         return result
 
 
-def XPathEvaluator(etree_or_element, namespaces=None, extensions=None,
+def XPathEvaluator(etree_or_element, *, namespaces=None, extensions=None,
                    regexp=True):
     """Creates an XPath evaluator for an ElementTree or an Element.
 
@@ -334,11 +335,13 @@
     the 'regexp' boolean keyword (defaults to True).
     """
     if isinstance(etree_or_element, _ElementTree):
-        return XPathDocumentEvaluator(etree_or_element, namespaces,
-                                      extensions, regexp)
+        return XPathDocumentEvaluator(
+            etree_or_element, namespaces=namespaces,
+            extensions=extensions, regexp=regexp)
     else:
-        return XPathElementEvaluator(etree_or_element, namespaces,
-                                     extensions, regexp)
+        return XPathElementEvaluator(
+            etree_or_element, namespaces=namespaces,
+            extensions=extensions, regexp=regexp)
 
 
 cdef class XPath(_XPathEvaluatorBase):
@@ -353,7 +356,7 @@
     cdef xpath.xmlXPathCompExpr* _xpath
     cdef readonly object path
 
-    def __init__(self, path, namespaces=None, extensions=None, regexp=True):
+    def __init__(self, path, *, namespaces=None, extensions=None, regexp=True):
         cdef xpath.xmlXPathContext* xpathCtxt
         _XPathEvaluatorBase.__init__(self, namespaces, extensions, regexp)
         self.path = path
@@ -415,9 +418,10 @@
     Note that this class does not accept the ``namespace`` keyword
     argument. All namespaces must be passed as part of the path string.
     """
-    def __init__(self, path, extensions=None, regexp=True):
+    def __init__(self, path, *, extensions=None, regexp=True):
         path, namespaces = self._nsextract_path(path)
-        XPath.__init__(self, path, namespaces, extensions, regexp)
+        XPath.__init__(self, path, namespaces=namespaces,
+                       extensions=extensions, regexp=regexp)
 
     cdef _nsextract_path(self, path):
         # replace {namespaces} by new prefixes


More information about the lxml-checkins mailing list