Added slicing capability and unit tests.
This commit is contained in:
parent
35c5d5752c
commit
5f30af085e
@ -187,9 +187,10 @@ def method_matches_args(method, params, remainder, lax_params=False):
|
||||
class Path(collections.deque):
|
||||
def __init__(self, value='/', separator='/'):
|
||||
self.separator = separator
|
||||
self._assign(value)
|
||||
|
||||
|
||||
super(Path, self).__init__()
|
||||
|
||||
self._assign(value)
|
||||
|
||||
def _assign(self, value):
|
||||
separator = self.separator
|
||||
@ -212,3 +213,10 @@ class Path(collections.deque):
|
||||
|
||||
def __repr__(self):
|
||||
return "<Path %r>" % super(Path, self).__repr__()
|
||||
|
||||
def __getitem__(self, i):
|
||||
try:
|
||||
return super(Path, self).__getitem__(i)
|
||||
|
||||
except TypeError:
|
||||
return Path([self[i] for i in xrange(*i.indices(len(self)))])
|
||||
|
@ -237,3 +237,16 @@ def test_path_unicode():
|
||||
instance.path = case
|
||||
|
||||
yield assert_path, instance, expected, unicode
|
||||
|
||||
def test_path_slicing():
|
||||
class MockOb(object):
|
||||
path = Path()
|
||||
|
||||
instance = MockOb()
|
||||
|
||||
instance.path = '/foo/bar/baz'
|
||||
|
||||
assert str(instance.path[1:]) == 'foo/bar/baz'
|
||||
assert str(instance.path[2:]) == 'bar/baz'
|
||||
assert str(instance.path[0:2]) == '/foo'
|
||||
assert str(instance.path[::2]) == '/bar'
|
||||
|
Loading…
Reference in New Issue
Block a user