jsonpointer 3.10__py3-none-any.whl → 3.12__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,7 @@ parser = argparse.ArgumentParser(
13
13
  # Accept pointer as option, as file or as first positional argument
14
14
  ptr_group = parser.add_mutually_exclusive_group()
15
15
 
16
- ptr_group.add_argument('-f', '--pointer-file', type=argparse.FileType('r', encoding='utf-8'),
16
+ ptr_group.add_argument('-f', '--pointer-file', type=str,
17
17
  help='File containing a JSON pointer expression')
18
18
 
19
19
  ptr_group.add_argument('-p', '--pointer', type=str,
@@ -37,14 +37,28 @@ def main():
37
37
  try:
38
38
  ok = resolve_files()
39
39
  except KeyboardInterrupt:
40
- sys.exit(1)
40
+ # Conventional status for termination by SIGINT (128 + 2)
41
+ sys.exit(130)
41
42
 
42
43
  if not ok:
43
44
  sys.exit(1)
44
45
 
45
46
 
47
+ def open_input(name):
48
+ """ Open a UTF-8 input file, or return stdin for "-"
49
+
50
+ Exits with a usage error if the file cannot be opened. """
51
+ if name == '-':
52
+ return sys.stdin
53
+
54
+ try:
55
+ return open(name, encoding='utf-8')
56
+ except OSError as e:
57
+ parser.error("can't open '%s': %s" % (name, e))
58
+
59
+
46
60
  def parse_pointer(args):
47
- """ Return the pointer and the list of files to resolve it on
61
+ """ Return the parsed pointer and the list of files to resolve it on
48
62
 
49
63
  If the pointer is given via -f or -p, a POINTER positional argument is
50
64
  actually the first file. """
@@ -57,14 +71,16 @@ def parse_pointer(args):
57
71
  if args.pointer is not None:
58
72
  ptr = args.pointer
59
73
  else:
60
- # 2026-10-11: Trim file line endings without changing member names.
74
+ # Strip only the trailing line ending; other whitespace may be
75
+ # part of a member name.
76
+ pointer_file = open_input(args.pointer_file)
61
77
  try:
62
- ptr = args.pointer_file.read().rstrip("\r\n")
78
+ ptr = pointer_file.read().rstrip("\r\n")
63
79
  except UnicodeDecodeError as e:
64
80
  parser.error('could not decode pointer file: %s' % e)
65
81
  finally:
66
- if args.pointer_file is not sys.stdin:
67
- args.pointer_file.close()
82
+ if pointer_file is not sys.stdin:
83
+ pointer_file.close()
68
84
 
69
85
  elif args.POINTER is not None:
70
86
  ptr = args.POINTER
@@ -75,11 +91,11 @@ def parse_pointer(args):
75
91
  # Catches e.g. `jsonpointer a.json b.json`, where the pointer was omitted
76
92
  # and the first file would otherwise be used as the pointer
77
93
  try:
78
- jsonpointer.JsonPointer(ptr)
94
+ pointer = jsonpointer.JsonPointer(ptr)
79
95
  except jsonpointer.JsonPointerException as e:
80
96
  parser.error('invalid JSON pointer %r: %s' % (ptr, e))
81
97
 
82
- return ptr, files
98
+ return pointer, files
83
99
 
84
100
 
85
101
  def resolve_files():
@@ -89,14 +105,11 @@ def resolve_files():
89
105
  or if --continue-on-error skipped a JSON or text decoding error. """
90
106
  args = parser.parse_args()
91
107
 
92
- ptr, files = parse_pointer(args)
108
+ pointer, files = parse_pointer(args)
93
109
  ok = True
94
110
 
95
111
  for name in files:
96
- try:
97
- f = argparse.FileType('r', encoding='utf-8')(name)
98
- except argparse.ArgumentTypeError as e:
99
- parser.error(str(e))
112
+ f = open_input(name)
100
113
 
101
114
  try:
102
115
  doc = json.load(f)
@@ -112,7 +125,7 @@ def resolve_files():
112
125
  f.close()
113
126
 
114
127
  try:
115
- result = jsonpointer.resolve_pointer(doc, ptr)
128
+ result = pointer.resolve(doc)
116
129
  if isinstance(result, jsonpointer.EndOfList):
117
130
  raise jsonpointer.JsonPointerException(
118
131
  "'-' does not reference an existing array element")
@@ -1,15 +1,14 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jsonpointer
3
- Version: 3.10
3
+ Version: 3.12
4
4
  Summary: Identify specific nodes in a JSON document (RFC 6901)
5
5
  Home-page: https://github.com/stefankoegl/python-json-pointer
6
6
  Author: Stefan Kögl
7
7
  Author-email: stefan@skoegl.net
8
- License: Modified BSD License
8
+ License-Expression: BSD-3-Clause
9
9
  Classifier: Development Status :: 5 - Production/Stable
10
10
  Classifier: Environment :: Console
11
11
  Classifier: Intended Audience :: Developers
12
- Classifier: License :: OSI Approved :: BSD License
13
12
  Classifier: Operating System :: OS Independent
14
13
  Classifier: Programming Language :: Python
15
14
  Classifier: Programming Language :: Python :: 3
@@ -18,6 +17,7 @@ Classifier: Programming Language :: Python :: 3.11
18
17
  Classifier: Programming Language :: Python :: 3.12
19
18
  Classifier: Programming Language :: Python :: 3.13
20
19
  Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Programming Language :: Python :: 3.15
21
21
  Classifier: Programming Language :: Python :: Implementation :: CPython
22
22
  Classifier: Programming Language :: Python :: Implementation :: PyPy
23
23
  Classifier: Topic :: Software Development :: Libraries
@@ -33,16 +33,16 @@ Dynamic: classifier
33
33
  Dynamic: description
34
34
  Dynamic: description-content-type
35
35
  Dynamic: home-page
36
- Dynamic: license
37
36
  Dynamic: license-file
37
+ Dynamic: license-expression
38
38
  Dynamic: requires-python
39
39
  Dynamic: summary
40
40
 
41
41
  python-json-pointer
42
42
  ===================
43
43
 
44
- [![PyPI version](https://img.shields.io/pypi/v/jsonpointer.svg)](https://pypi.python.org/pypi/jsonpointer/)
45
- [![Supported Python versions](https://img.shields.io/pypi/pyversions/jsonpointer.svg)](https://pypi.python.org/pypi/jsonpointer/)
44
+ [![PyPI version](https://img.shields.io/pypi/v/jsonpointer.svg)](https://pypi.org/project/jsonpointer/)
45
+ [![Supported Python versions](https://img.shields.io/pypi/pyversions/jsonpointer.svg)](https://pypi.org/project/jsonpointer/)
46
46
  [![Tests](https://github.com/stefankoegl/python-json-pointer/actions/workflows/test.yaml/badge.svg?branch=master)](https://github.com/stefankoegl/python-json-pointer/actions/workflows/test.yaml)
47
47
  [![Coverage Status](https://coveralls.io/repos/github/stefankoegl/python-json-pointer/badge.svg?branch=master)](https://coveralls.io/github/stefankoegl/python-json-pointer?branch=master)
48
48
 
@@ -51,12 +51,13 @@ Resolve JSON Pointers in Python
51
51
  -------------------------------
52
52
 
53
53
  Library to resolve JSON Pointers according to
54
- [RFC 6901](http://tools.ietf.org/html/rfc6901)
54
+ [RFC 6901](https://datatracker.ietf.org/doc/html/rfc6901)
55
+
56
+ See the documentation for examples.
55
57
 
56
- See source code for examples
57
58
  * Website: https://github.com/stefankoegl/python-json-pointer
58
59
  * Repository: https://github.com/stefankoegl/python-json-pointer.git
59
- * Documentation: https://python-json-pointer.readthedocs.org/
60
- * PyPI: https://pypi.python.org/pypi/jsonpointer
60
+ * Documentation: https://python-json-pointer.readthedocs.io/
61
+ * PyPI: https://pypi.org/project/jsonpointer/
61
62
  * GitHub Actions: https://github.com/stefankoegl/python-json-pointer/actions
62
63
  * Coveralls: https://coveralls.io/github/stefankoegl/python-json-pointer
@@ -0,0 +1,9 @@
1
+ jsonpointer.py,sha256=4392xm70wi1l38FrP_Gp0pF7bQtRzs9lUY1Kfj1CHDI,14890
2
+ jsonpointer-3.12.data/scripts/jsonpointer,sha256=JUJNbQce0UfI29qe07rUhWnT5gfL9Y-s42RFMaKKm-E,4412
3
+ jsonpointer-3.12.dist-info/licenses/AUTHORS,sha256=TVgxnQ9ZyHvvWwez_k2w8ZwtfVVFsDTGv3tXyJu-9X8,113
4
+ jsonpointer-3.12.dist-info/licenses/LICENSE.txt,sha256=2LJPFdRyiF94ii1umFhQ8mRie4YBKhe7JCyD8xDZB-U,1413
5
+ jsonpointer-stubs/__init__.pyi,sha256=RA9A66yg8HCBK1zZM8efW7TpB0yz808ox6FUWu47fjg,1980
6
+ jsonpointer-3.12.dist-info/METADATA,sha256=oWS8MEzwassyV0RS6UVEXcaXygqQCOlWppDmgnFTn_s,2688
7
+ jsonpointer-3.12.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
8
+ jsonpointer-3.12.dist-info/top_level.txt,sha256=qkC_MNB0W-Hw6fCuc2X4V_xpd0WzjwHRObTmphI1SkM,30
9
+ jsonpointer-3.12.dist-info/RECORD,,
@@ -2,7 +2,7 @@ from collections.abc import Iterable, Iterator
2
2
  from re import Pattern
3
3
  from typing import Any, Final, TypeVar
4
4
 
5
- from typing_extensions import Self
5
+ from typing_extensions import Self, deprecated
6
6
 
7
7
  _T = TypeVar("_T")
8
8
 
@@ -21,6 +21,7 @@ def set_pointer(
21
21
  create: bool = False,
22
22
  ) -> Any: ...
23
23
  def resolve_pointer(doc: Any, pointer: str, default: Any = ...) -> Any: ...
24
+ @deprecated("Use itertools.pairwise() instead")
24
25
  def pairwise(iterable: Iterable[_T]) -> Iterator[tuple[_T, _T]]: ...
25
26
 
26
27
  class JsonPointerException(Exception): ...
jsonpointer.py CHANGED
@@ -32,14 +32,16 @@
32
32
 
33
33
  # Will be parsed by setup.py to determine package metadata
34
34
  __author__ = 'Stefan Kögl <stefan@skoegl.net>'
35
- __version__ = '3.10'
35
+ __version__ = '3.12'
36
36
  __website__ = 'https://github.com/stefankoegl/python-json-pointer'
37
- __license__ = 'Modified BSD License'
37
+ __license__ = 'BSD-3-Clause'
38
38
 
39
39
  import copy
40
+ import itertools
40
41
  import re
42
+ import warnings
41
43
  from collections.abc import Mapping, Sequence
42
- from itertools import tee, chain
44
+ from itertools import chain
43
45
 
44
46
  _nothing = object()
45
47
 
@@ -128,19 +130,13 @@ def pairwise(iterable):
128
130
 
129
131
  s -> (s0,s1), (s1,s2), (s2, s3), ...
130
132
 
131
- >>> list(pairwise([]))
132
- []
133
-
134
- >>> list(pairwise([1]))
135
- []
136
-
137
- >>> list(pairwise([1, 2, 3, 4]))
138
- [(1, 2), (2, 3), (3, 4)]
133
+ .. deprecated:: 3.12
134
+ Use :func:`itertools.pairwise` instead.
139
135
  """
140
- a, b = tee(iterable)
141
- for _ in b:
142
- break
143
- return zip(a, b)
136
+ warnings.warn('jsonpointer.pairwise() is deprecated, '
137
+ 'use itertools.pairwise() instead',
138
+ DeprecationWarning, stacklevel=2)
139
+ return itertools.pairwise(iterable)
144
140
 
145
141
 
146
142
  class JsonPointerException(Exception):
@@ -163,7 +159,7 @@ class JsonPointer:
163
159
 
164
160
  # Array indices must not contain:
165
161
  # leading zeros, signs, spaces, decimals, etc
166
- _RE_ARRAY_INDEX = re.compile('0|[1-9][0-9]*$')
162
+ _RE_ARRAY_INDEX = re.compile('0|[1-9][0-9]*')
167
163
  _RE_INVALID_ESCAPE = re.compile('(~[^01]|~$)')
168
164
 
169
165
  def __init__(self, pointer):
@@ -327,8 +323,6 @@ class JsonPointer:
327
323
 
328
324
  part = JsonPointer.get_part(doc, part)
329
325
 
330
- assert hasattr(doc, '__getitem__'), "invalid document type %s" % (type(doc),)
331
-
332
326
  if isinstance(doc, Sequence):
333
327
  if part == '-':
334
328
  return EndOfList(doc)
@@ -387,7 +381,7 @@ class JsonPointer:
387
381
  return self.contains(item)
388
382
 
389
383
  def join(self, suffix):
390
- """ Returns a new JsonPointer with the given suffix append to this ptr """
384
+ """ Returns a new JsonPointer with the given suffix appended to this ptr """
391
385
  if isinstance(suffix, JsonPointer):
392
386
  suffix_parts = suffix.parts
393
387
  elif isinstance(suffix, str):
@@ -396,8 +390,8 @@ class JsonPointer:
396
390
  suffix_parts = suffix
397
391
  try:
398
392
  return self.__class__.from_parts(chain(self.parts, suffix_parts))
399
- except Exception:
400
- raise JsonPointerException("Invalid suffix")
393
+ except Exception as e:
394
+ raise JsonPointerException("Invalid suffix") from e
401
395
 
402
396
  def __truediv__(self, suffix):
403
397
  return self.join(suffix)
@@ -406,7 +400,8 @@ class JsonPointer:
406
400
  def path(self):
407
401
  """Returns the string representation of the pointer
408
402
 
409
- >>> ptr = JsonPointer('/~0/0/~1').path == '/~0/0/~1'
403
+ >>> JsonPointer('/~0/0/~1').path == '/~0/0/~1'
404
+ True
410
405
  """
411
406
  parts = [escape(part) for part in self.parts]
412
407
  return ''.join('/' + part for part in parts)
@@ -414,13 +409,13 @@ class JsonPointer:
414
409
  def __eq__(self, other):
415
410
  """Compares a pointer to another object
416
411
 
417
- Pointers can be compared by comparing their strings (or splitted
412
+ Pointers can be compared by comparing their strings (or split
418
413
  strings), because no two different parts can point to the same
419
414
  structure in an object (eg no different number representations)
420
415
  """
421
416
 
422
417
  if not isinstance(other, JsonPointer):
423
- return False
418
+ return NotImplemented
424
419
 
425
420
  return self.parts == other.parts
426
421
 
@@ -435,7 +430,7 @@ class JsonPointer:
435
430
 
436
431
  @classmethod
437
432
  def from_parts(cls, parts):
438
- """Constructs a JsonPointer from a list of (unescaped) paths
433
+ """Constructs a JsonPointer from a list of (unescaped) parts
439
434
 
440
435
  >>> JsonPointer.from_parts(['a', '~', '/', 0]).path == '/a/~0/~1/0'
441
436
  True
@@ -1,9 +0,0 @@
1
- jsonpointer.py,sha256=xoJ4lmbQby_xAse2zBP2BQMKdPtPxZFy0df2TMEMiOM,14867
2
- jsonpointer-3.10.data/scripts/jsonpointer,sha256=XYDDaXnhkb3nANXqdn9OUKtVwSqsOZ8TDgXeawe_O7Y,4102
3
- jsonpointer-3.10.dist-info/licenses/AUTHORS,sha256=TVgxnQ9ZyHvvWwez_k2w8ZwtfVVFsDTGv3tXyJu-9X8,113
4
- jsonpointer-3.10.dist-info/licenses/LICENSE.txt,sha256=2LJPFdRyiF94ii1umFhQ8mRie4YBKhe7JCyD8xDZB-U,1413
5
- jsonpointer-stubs/__init__.pyi,sha256=gHlnw0_btYmRw5m0UutGmAjNdvzS_E_yumlvm8rMX48,1920
6
- jsonpointer-3.10.dist-info/METADATA,sha256=6cyh4D1qGDoLNVNfllzDLn2h6c41w7D8Fpc3GhbRFic,2667
7
- jsonpointer-3.10.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
8
- jsonpointer-3.10.dist-info/top_level.txt,sha256=qkC_MNB0W-Hw6fCuc2X4V_xpd0WzjwHRObTmphI1SkM,30
9
- jsonpointer-3.10.dist-info/RECORD,,