Mercurial > jpath
changeset 22:4b25553183cc
Change the semantics of the slice operator to be more intuitive
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Fri, 16 Aug 2013 10:20:29 +0200 |
| parents | a2fd02b812ca |
| children | 4703a3021427 |
| files | jpath.py |
| diffstat | 1 files changed, 7 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/jpath.py Fri Aug 16 10:04:25 2013 +0200 +++ b/jpath.py Fri Aug 16 10:20:29 2013 +0200 @@ -193,7 +193,10 @@ self.step = int(slice_step) if slice_step is not None else None def parse(self, tokens, data): - return Token.apply(tokens, data[self.start:self.end:self.step]) + for item in data[self.start:self.end:self.step]: + for value in Token.apply(list(tokens), item): + yield value + @Tokenizer.token class FilterToken(Token): @@ -379,11 +382,11 @@ >>> get_all('a..b', {'a': {'b': 3, 'c': {'b': 4}}}) [3, 4] >>> get_all('[1:]', [1, 2, 3]) - [[2, 3]] + [2, 3] >>> get_all('[:-1]', [1, 2, 3]) - [[1, 2]] + [1, 2] >>> get_all('[::2]', [1, 2, 3, 4]) - [[1, 3]] + [1, 3] >>> get_all('(x=1).y', [{'x':1, 'y':2}, {'x':0, 'y':3}, {'x':1, 'y':4}]) [2, 4] >>> get_all('(x>0).y', [{'x':1, 'y':2}, {'x':0, 'y':3}, {'x':1, 'y':4}])
