Skip to content

Commit 99450fa

Browse files
author
Matthias Brehler
committed
Merge remote-tracking branch 'upstream/master'
Change-Id: Ifb2eab1ebf9151c14b533cf13ef20707bb3ada19
2 parents 4e5e14b + 59e6b72 commit 99450fa

19 files changed

+610
-110
lines changed

.github/workflows/ci.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- '*'
6+
tags:
7+
- 'v*'
8+
pull_request:
9+
branches:
10+
- main
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
17+
steps:
18+
- uses: actions/checkout@v3
19+
- uses: actions/setup-python@v4
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install -r requirements.txt
26+
pip install -r requirements-dev.txt
27+
- name: Run tests
28+
run: make test

History.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11

2+
1.5.3 / 2021-07-05
3+
==================
4+
5+
* Update __init__.py
6+
* Update setup.py
7+
* Merge pull request #72 from kaapstorm/find_or_create
8+
* Tests
9+
* Add `update_or_create()` method
10+
* Merge pull request #68 from kaapstorm/example_tests
11+
* Merge pull request #70 from kaapstorm/exceptions
12+
* Add/fix `__eq__()`
13+
* Add tests based on Stefan Goessner's examples
14+
* Tests
15+
* Allow callers to catch JSONPathErrors
16+
217
v1.5.2 / 2020-09-07
318
===================
419

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
recursive-include tests *.json *.py
2+
include LICENSE

README.rst

+44-33
Original file line numberDiff line numberDiff line change
@@ -187,30 +187,43 @@ Extras
187187
Extensions
188188
----------
189189

190-
+--------------+----------------------------------------------+
191-
| name | Example |
192-
+==============+==============================================+
193-
| len | - $.objects.`len` |
194-
+--------------+----------------------------------------------+
195-
| sub | - $.field.`sub(/foo\\\\+(.*)/, \\\\1)` |
196-
+--------------+----------------------------------------------+
197-
| split | - $.field.`split(+, 2, -1)` |
198-
| | - $.field.`split(sep, segement, maxsplit)` |
199-
+--------------+----------------------------------------------+
200-
| sorted | - $.objects.`sorted` |
201-
| | - $.objects[\\some_field] |
202-
| | - $.objects[\\some_field,/other_field] |
203-
+--------------+----------------------------------------------+
204-
| filter | - $.objects[?(@some_field > 5)] |
205-
| | - $.objects[?some_field = "foobar")] |
206-
| | - $.objects[?some_field =~ "foobar")] |
207-
| | - $.objects[?some_field > 5 & other < 2)] |
208-
+--------------+----------------------------------------------+
209-
| arithmetic | - $.foo + "_" + $.bar |
210-
| (-+*/) | - $.foo * 12 |
211-
| | - $.objects[*].cow + $.objects[*].cat |
212-
+--------------+----------------------------------------------+
213-
190+
To use the extensions below you must import from `jsonpath_ng.ext`.
191+
192+
+--------------+-----------------------------------------------+
193+
| name | Example |
194+
+==============+===============================================+
195+
| len | - ``$.objects.`len``` |
196+
+--------------+-----------------------------------------------+
197+
| sub | - ``$.field.`sub(/foo\\\\+(.*)/, \\\\1)``` |
198+
| | - ``$.field.`sub(/regex/, replacement)``` |
199+
+--------------+-----------------------------------------------+
200+
| split | - ``$.field.`split(+, 2, -1)``` |
201+
| | - ``$.field.`split(sep, segement, maxsplit)```|
202+
+--------------+-----------------------------------------------+
203+
| sorted | - ``$.objects.`sorted``` |
204+
| | - ``$.objects[\\some_field]`` |
205+
| | - ``$.objects[\\some_field,/other_field]`` |
206+
+--------------+-----------------------------------------------+
207+
| filter | - ``$.objects[?(@some_field > 5)]`` |
208+
| | - ``$.objects[?some_field = "foobar"]`` |
209+
| | - ``$.objects[?some_field =~ "foobar"]`` |
210+
| | - ``$.objects[?some_field > 5 & other < 2]`` |
211+
| | |
212+
| | Supported operators: |
213+
| | - Equality: ==, =, != |
214+
| | - Comparison: >, >=, <, <= |
215+
| | - Regex match: =~ |
216+
| | |
217+
| | Combine multiple criteria with '&'. |
218+
| | |
219+
| | Properties can only be compared to static |
220+
| | values. |
221+
+--------------+-----------------------------------------------+
222+
| arithmetic | - ``$.foo + "_" + $.bar`` |
223+
| (-+*/) | - ``$.foo * 12`` |
224+
| | - ``$.objects[*].cow + $.objects[*].cat`` |
225+
+--------------+-----------------------------------------------+
226+
-
214227
About arithmetic and string
215228
---------------------------
216229

@@ -228,10 +241,10 @@ Example with data::
228241
'fish': 'bar'
229242
}
230243

231-
| **cow + fish** returns **cowfish**
232-
| **$.cow + $.fish** returns **foobar**
233-
| **$.cow + "_" + $.fish** returns **foo_bar**
234-
| **$.cow + "_" + fish** returns **foo_fish**
244+
| ``cow + fish`` returns ``cowfish``
245+
| ``$.cow + $.fish`` returns ``foobar``
246+
| ``$.cow + "_" + $.fish`` returns ``foo_bar``
247+
| ``$.cow + "_" + fish`` returns ``foo_fish``
235248
236249
About arithmetic and list
237250
-------------------------
@@ -245,7 +258,7 @@ Example with data::
245258
{'cow': 4, 'cat': 6}
246259
]}
247260

248-
| **$.objects[\*].cow + $.objects[\*].cat** returns **[6, 9]**
261+
| ``$.objects[\*].cow + $.objects[\*].cat`` returns ``[6, 9]``
249262
250263
More to explore
251264
---------------
@@ -322,9 +335,7 @@ limitations under the License.
322335

323336
.. |PyPi downloads| image:: https://pypip.in/d/jsonpath-ng/badge.png
324337
:target: https://pypi.python.org/pypi/jsonpath-ng
325-
.. |Build Status| image:: https://travis-ci.org/h2non/jsonpath-ng.svg?branch=master
326-
:target: https://travis-ci.org/h2non/jsonpath-ng
338+
.. |Build Status| image:: https://github.com/h2non/jsonpath-ng/actions/workflows/ci.yml/badge.svg
339+
:target: https://github.com/h2non/jsonpath-ng/actions/workflows/ci.yml
327340
.. |PyPI| image:: https://img.shields.io/pypi/v/jsonpath-ng.svg?maxAge=2592000?style=flat-square
328341
:target: https://pypi.python.org/pypi/jsonpath-ng
329-
.. |Documentation Status| image:: https://img.shields.io/badge/docs-latest-green.svg?style=flat
330-
:target: http://jsonpath-ng.readthedocs.io/en/latest/?badge=latest

jsonpath_ng/__init__.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from .jsonpath import * # noqa
2-
from .parser import parse # noqa
3-
4-
5-
# Current package version
6-
__version__ = '1.5.2.1'
1+
from .jsonpath import * # noqa
2+
from .parser import parse # noqa
3+
4+
5+
# Current package version
6+
__version__ = '1.5.3.1'

jsonpath_ng/exceptions.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class JSONPathError(Exception):
2+
pass
3+
4+
5+
class JsonPathLexerError(JSONPathError):
6+
pass
7+
8+
9+
class JsonPathParserError(JSONPathError):
10+
pass

jsonpath_ng/ext/filter.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import operator
1515
import re
16-
from six import moves
1716

1817
from .. import JSONPath, DatumInContext, Index
1918

@@ -49,7 +48,7 @@ def find(self, datum):
4948
return []
5049

5150
return [DatumInContext(datum.value[i], path=Index(i), context=datum)
52-
for i in moves.range(0, len(datum.value))
51+
for i in range(0, len(datum.value))
5352
if (len(self.expressions) ==
5453
len(list(filter(lambda x: x.find(datum.value[i]),
5554
self.expressions))))]
@@ -71,6 +70,10 @@ def __repr__(self):
7170
def __str__(self):
7271
return '[?%s]' % self.expressions
7372

73+
def __eq__(self, other):
74+
return (isinstance(other, Filter)
75+
and self.expressions == other.expressions)
76+
7477

7578
class Expression(JSONPath):
7679
"""The JSONQuery expression"""
@@ -108,7 +111,7 @@ def find(self, datum):
108111
return found
109112

110113
def __eq__(self, other):
111-
return (isinstance(other, Filter) and
114+
return (isinstance(other, Expression) and
112115
self.target == other.target and
113116
self.op == other.op and
114117
self.value == other.value)

jsonpath_ng/ext/string.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
from .. import DatumInContext, This
1616

1717

18-
SUB = re.compile("sub\(/(.*)/,\s+(.*)\)")
19-
SPLIT = re.compile("split\((.),\s+(\d+),\s+(\d+|-1)\)")
20-
STR = re.compile("str\(\)")
18+
SUB = re.compile(r"sub\(/(.*)/,\s+(.*)\)")
19+
SPLIT = re.compile(r"split\((.),\s+(\d+),\s+(\d+|-1)\)")
20+
STR = re.compile(r"str\(\)")
2121

2222

2323
class DefintionInvalid(Exception):

0 commit comments

Comments
 (0)