jsonpointer 3.8__tar.gz → 3.9__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jsonpointer
3
- Version: 3.8
3
+ Version: 3.9
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jsonpointer
3
- Version: 3.8
3
+ Version: 3.9
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
@@ -32,7 +32,7 @@
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.8'
35
+ __version__ = '3.9'
36
36
  __website__ = 'https://github.com/stefankoegl/python-json-pointer'
37
37
  __license__ = 'Modified BSD License'
38
38
 
@@ -275,8 +275,9 @@ class JsonPointer:
275
275
  elif isinstance(parent, Sequence) and part == '-':
276
276
  try:
277
277
  parent.append(value)
278
- except AttributeError as e:
279
- # immutable sequences, such as tuples, can't be appended to
278
+ except (AttributeError, TypeError) as e:
279
+ # Immutable sequences can't be appended to; typed sequences
280
+ # can reject the value just like an indexed assignment.
280
281
  raise JsonPointerException("Invalid assignment target: %s" % (e,))
281
282
  else:
282
283
  try:
@@ -83,6 +83,17 @@ class SpecificationTests(unittest.TestCase):
83
83
  new_ptr = JsonPointer.from_parts(parts)
84
84
  self.assertEqual(ptr, new_ptr)
85
85
 
86
+ def test_escaped_tilde_is_not_decoded_twice(self):
87
+ # RFC 6901 section 4: decode ~1 before ~0, so ~01 becomes ~1, not /.
88
+ pointer = JsonPointer('/~01')
89
+ self.assertEqual(pointer.parts, ['~1'])
90
+ self.assertEqual(JsonPointer.from_parts(pointer.parts).path, '/~01')
91
+
92
+ doc = {'~1': 'tilde member', '/': 'slash member'}
93
+ self.assertEqual(resolve_pointer(doc, '/~01'), 'tilde member')
94
+ set_pointer(doc, '/~01', 'updated')
95
+ self.assertEqual(doc, {'~1': 'updated', '/': 'slash member'})
96
+
86
97
  def test_str_and_repr(self):
87
98
  paths = [
88
99
  ("", "", "JsonPointer('')"),
@@ -456,6 +467,34 @@ class SetTests(unittest.TestCase):
456
467
  "/cat/name", "whiskers")
457
468
  self.assertEqual(doc, {})
458
469
 
470
+ def test_set_sequence_append_invalid_type(self):
471
+ for pointer, create in (("/items/0", False), ("/items/-", False),
472
+ ("/items/-", True), ("/items/1", True)):
473
+ for inplace in (False, True):
474
+ with self.subTest(pointer=pointer, create=create, inplace=inplace):
475
+ doc = {"items": bytearray([1])}
476
+ with self.assertRaisesRegex(JsonPointerException, "Invalid assignment target:"):
477
+ set_pointer(doc, pointer, "invalid", inplace=inplace, create=create)
478
+ self.assertEqual(doc, {"items": bytearray([1])})
479
+
480
+ def test_set_create_sequence_append_invalid_child(self):
481
+ for pointer in ("/items/-/leaf", "/items/1/leaf"):
482
+ with self.subTest(pointer=pointer):
483
+ doc = {"items": bytearray([1])}
484
+ with self.assertRaisesRegex(JsonPointerException, "Invalid assignment target:"):
485
+ set_pointer(doc, pointer, 7, create=True)
486
+ self.assertEqual(doc, {"items": bytearray([1])})
487
+
488
+ def test_set_sequence_append_valid_type(self):
489
+ for pointer, create in (("/items/-", False), ("/items/-", True),
490
+ ("/items/1", True)):
491
+ for inplace in (False, True):
492
+ with self.subTest(pointer=pointer, create=create, inplace=inplace):
493
+ doc = {"items": bytearray([1])}
494
+ result = set_pointer(doc, pointer, 2, inplace=inplace, create=create)
495
+ self.assertEqual(result, {"items": bytearray([1, 2])})
496
+ self.assertEqual(doc, result if inplace else {"items": bytearray([1])})
497
+
459
498
 
460
499
  class AltTypesTests(unittest.TestCase):
461
500
  class Node(object):
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes