Skip to content

Commit

Permalink
Add XPath nodes iterator method to XPathContext
Browse files Browse the repository at this point in the history
  • Loading branch information
brunato committed Jun 15, 2020
1 parent 7af09cc commit 70e2684
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
CHANGELOG
*********

`v1.4.6`_ (2020-06-15)
======================
* Fix XPathContext to let the subclasses replace the XPath nodes iterator function

`v1.4.5`_ (2020-05-22)
======================
* Fix tokenizer and parsers for ambiguities between symbols and names
Expand Down Expand Up @@ -220,3 +224,4 @@ CHANGELOG
.. _v1.4.3: https://github.com/sissaschool/elementpath/compare/v1.4.2...v1.4.3
.. _v1.4.4: https://github.com/sissaschool/elementpath/compare/v1.4.3...v1.4.4
.. _v1.4.5: https://github.com/sissaschool/elementpath/compare/v1.4.4...v1.4.5
.. _v1.4.6: https://github.com/sissaschool/elementpath/compare/v1.4.5...v1.4.6
5 changes: 4 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# The short X.Y version
version = '1.4'
# The full version, including alpha/beta/rc tags
release = '1.4.5'
release = '1.4.6'


# -- General configuration ---------------------------------------------------
Expand All @@ -48,6 +48,9 @@
'sphinx.ext.doctest',
]

# Option for autodoc: do not add module name as prefix to classes or functions.
add_module_names = False

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

Expand Down
2 changes: 1 addition & 1 deletion elementpath/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
# @author Davide Brunato <brunato@sissa.it>
#
__version__ = '1.4.5'
__version__ = '1.4.6'
__author__ = "Davide Brunato"
__contact__ = "brunato@sissa.it"
__copyright__ = "Copyright 2018-2020, SISSA"
Expand Down
14 changes: 8 additions & 6 deletions elementpath/xpath_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class XPathContext(object):
:param timezone: implicit timezone to be used when a date, time, or dateTime value does \
not have a timezone.
"""
_iter_nodes = staticmethod(etree_iter_nodes)

def __init__(self, root, item=None, position=1, size=1, axis=None,
variables=None, current_dt=None, timezone=None,
documents=None, collections=None, default_collection=None):
Expand Down Expand Up @@ -153,7 +155,7 @@ def iter(self):
if is_document_node(root):
yield root
root = root.getroot()
yield from etree_iter_nodes(root, with_attributes=True)
yield from self._iter_nodes(root, with_attributes=True)

def iter_results(self, results):
"""
Expand All @@ -166,7 +168,7 @@ def iter_results(self, results):

self.size = len(results)
for self.position, self.item in \
enumerate(etree_iter_nodes(root, with_attributes=True), start=1):
enumerate(self._iter_nodes(root, with_attributes=True), start=1):
if self.item in results:
yield self.item
elif isinstance(self.item, AttributeNode):
Expand Down Expand Up @@ -343,9 +345,9 @@ def iter_descendants(self, item=None, axis=None):
return

if axis == 'descendant':
descendants = [x for x in etree_iter_nodes(self.item, with_root=False)]
descendants = [x for x in self._iter_nodes(self.item, with_root=False)]
else:
descendants = [x for x in etree_iter_nodes(self.item)]
descendants = [x for x in self._iter_nodes(self.item)]

self.size = len(descendants)
for self.position, self.item in enumerate(descendants, start=1):
Expand Down Expand Up @@ -422,10 +424,10 @@ def iter_followings(self):
elif not is_etree_element(self.item) or callable(self.item.tag):
return

descendants = set(etree_iter_nodes(self.item))
descendants = set(self._iter_nodes(self.item))
followings = []
follows = False
for elem in etree_iter_nodes(self.root):
for elem in self._iter_nodes(self.root):
if follows:
if elem not in descendants:
followings.append(elem)
Expand Down
4 changes: 2 additions & 2 deletions publiccode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ publiccodeYmlVersion: '0.2'
name: elementpath
url: 'https://github.com/sissaschool/elementpath'
landingURL: 'https://github.com/sissaschool/elementpath'
releaseDate: '2020-05-22'
softwareVersion: v1.4.5
releaseDate: '2020-06-15'
softwareVersion: v1.4.6
developmentStatus: stable
platforms:
- linux
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setup(
name='elementpath',
version='1.4.5',
version='1.4.6',
packages=['elementpath'],
author='Davide Brunato',
author_email='brunato@sissa.it',
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ toxworkdir = {homedir}/.tox/elementpath
[testenv]
deps =
lxml
xmlschema~=1.1.0
xmlschema~=1.2.0
docs: Sphinx
flake8: flake8
coverage: coverage
Expand All @@ -33,7 +33,7 @@ commands =

[testenv:coverage]
commands =
coverage run -p setup.py test -q
coverage run -p -m unittest
coverage combine
coverage report -m

Expand Down

0 comments on commit 70e2684

Please sign in to comment.