Skip to content

Commit

Permalink
wip; fixed bug on first node of each tree not propagating the no_conf…
Browse files Browse the repository at this point in the history
…lict parameter
  • Loading branch information
vltr committed Oct 9, 2018
1 parent 9dd39bd commit f4f1b28
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Changelog
=========

v0.2.1 on 2018-10-09
--------------------

* Fixed bug where the ``no_conflict`` flag where not being propagated to the ``add_method`` if a "non-conflicting method" was the first node being created in that tree.


v0.2.0 on 2018-10-03
--------------------

Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ clean: cleanpycache
rm -rf ./src/*.egg-info
rm -rf ./src/*.c
rm -rf ./src/*.so
rm -rf ./wheelhouse

test: clean
python setup.py build_ext --force --inplace
Expand All @@ -46,6 +47,7 @@ requirements-dev:
pip-sync requirements-dev.txt

docker-build: clean
mkdir ./wheelhouse
python setup.py clean --all sdist
docker pull quay.io/pypa/manylinux1_x86_64:latest
docker pull quay.io/pypa/manylinux1_i686:latest
Expand Down
16 changes: 7 additions & 9 deletions src/xrtr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ cdef class RadixTreeNode:
readonly bint index_zero_is_variable
readonly bint index_zero_is_glob

def __cinit__(self, str path=None, object handler=None, list methods=None):
def __cinit__(self, str path=None, object handler=None, list methods=None, bint no_conflict=False):
if path is None:
self.path_len = 0
else:
Expand All @@ -49,7 +49,8 @@ cdef class RadixTreeNode:
self.index_zero_is_variable = 0
self.index_zero_is_glob = 0

self.add_methods(methods, handler)
if handler is not None and methods is not None:
self.add_methods(methods, handler, no_conflict)

def __repr__(self):
return (
Expand Down Expand Up @@ -225,11 +226,8 @@ cdef class RadixTree:
int i = 0
int n = len(path)
int code = 0
int j
int p
int m
RadixTreeNode root
RadixTreeNode child
int j, p, m
RadixTreeNode root, child

root = self.root

Expand All @@ -251,11 +249,11 @@ cdef class RadixTree:
if p == n:
p = _get_position(path.find(GLOB, i), n)
if p == n:
root.insert_child(path[i], RadixTreeNode(path[i:], handler, methods))
root.insert_child(path[i], RadixTreeNode(path[i:], handler, methods, no_conflict))
return code, None

root = root.insert_child(path[i], RadixTreeNode(path[i:p]))
root.insert_child(GLOB, RadixTreeNode(path[p + 1:], handler, methods))
root.insert_child(GLOB, RadixTreeNode(path[p + 1:], handler, methods, no_conflict))
return code, None

root = root.insert_child(path[i], RadixTreeNode(path[i:p]))
Expand Down
20 changes: 20 additions & 0 deletions tests/test_xrtr.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,23 @@ def test_duplicate_parameters(endpoint_factory):

with pytest.raises(ValueError):
another_tree.insert("|hello|.bar|world|*bar", endpoint_1, ["BAR"])


def test_tree_middleware_first(endpoint_factory, middleware_factory):
endpoint_1 = endpoint_factory(1)
middleware_1 = middleware_factory(1)

tree = RadixTree()

tree.insert("/hello", middleware_1, ["BAR"], no_conflict=True)
tree.insert("/hello/world", endpoint_1, ["BAR"])

r = tree.get("/hello", "BAR")
assert r[0] is None
assert r[1] == []
assert r[2] == {}

r = tree.get("/hello/world", "BAR")
assert r[0] == endpoint_1
assert r[1] == [middleware_1]
assert r[2] == {}

0 comments on commit f4f1b28

Please sign in to comment.