Mercurial > jpath
changeset 20:5c844a14d835
Fix the error with parsing get_all('a[*].b.c', {'a': [{'b': {'c': 0}}, {'b': {'c': 1}}]})
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Fri, 16 Aug 2013 10:01:34 +0200 |
| parents | b21203132ef6 |
| children | a2fd02b812ca |
| files | jpath.py |
| diffstat | 1 files changed, 9 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/jpath.py Fri Aug 16 09:43:25 2013 +0200 +++ b/jpath.py Fri Aug 16 10:01:34 2013 +0200 @@ -67,8 +67,8 @@ def _pop_token(tokens): try: - token = next(tokens) - except StopIteration: + token = tokens.pop() + except IndexError: token = NoneToken() return token @@ -267,7 +267,7 @@ pass for item in data: try: - for value in token.parse(tokens, item): + for value in token.parse(list(tokens), item): yield value except (TypeError, IndexError, KeyError): # Ignore errors inside branches, because some @@ -318,7 +318,7 @@ token = _pop_token(tokens) for item in dive(data): try: - for value in token.parse(tokens, item): + for value in token.parse(list(tokens), item): yield value except (TypeError, IndexError, KeyError): # Ignore errors inside branches, because some @@ -394,7 +394,11 @@ [0, 1] """ - return list(Token.apply(TOKENIZER.tokenize(jpath), data)) + tokens = list(TOKENIZER.tokenize(jpath)) + # Popping from the end of the list is faster. + tokens.reverse() + return list(Token.apply(tokens, data)) + def get(jpath, data): """
