Skip to content

Commit 6b2c95d

Browse files
committed
!feat:remove python 2.7 support
1 parent 4c47628 commit 6b2c95d

File tree

6 files changed

+36
-53
lines changed

6 files changed

+36
-53
lines changed

.github/workflows/test.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Python package
22

3-
on: [push]
3+
on: [ push ]
44

55
jobs:
66
build:
@@ -9,12 +9,12 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
python-version: ["2.7", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
12+
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11", "3.12" ]
1313

1414
steps:
1515
- uses: actions/checkout@v4
1616
- name: Set up Python ${{ matrix.python-version }}
17-
uses: actions/setup-python@v4
17+
uses: actions/setup-python@v5
1818
with:
1919
python-version: ${{ matrix.python-version }}
2020
allow-prereleases: true
@@ -23,12 +23,12 @@ jobs:
2323
python -m pip install --upgrade pip
2424
pip install flake8 pytest
2525
pip install coveralls
26-
# - name: Lint with flake8
27-
# run: |
26+
# - name: Lint with flake8
27+
# run: |
2828
# stop the build if there are Python syntax errors or undefined names
2929
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
3030
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
31-
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
31+
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
3232
- name: Test
3333
run: |
3434
make coverage

bin/jsonpointer

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
from __future__ import print_function
54

6-
import sys
7-
import os.path
8-
import json
9-
import jsonpointer
105
import argparse
6+
import json
7+
import sys
118

9+
import jsonpointer
1210

1311
parser = argparse.ArgumentParser(
1412
description='Resolve a JSON pointer on JSON files')
@@ -20,7 +18,7 @@ ptr_group.add_argument('-f', '--pointer-file', type=argparse.FileType('r'),
2018
nargs='?',
2119
help='File containing a JSON pointer expression')
2220

23-
ptr_group.add_argument('POINTER', type=str, nargs='?',
21+
ptr_group.add_argument('POINTER', type=str, nargs='?',
2422
help='A JSON pointer expression')
2523

2624
parser.add_argument('FILE', type=argparse.FileType('r'), nargs='+',

jsonpointer.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,14 @@
3232

3333
""" Identify specific nodes in a JSON document (RFC 6901) """
3434

35-
from __future__ import unicode_literals
3635

3736
# Will be parsed by setup.py to determine package metadata
3837
__author__ = 'Stefan Kögl <[email protected]>'
39-
__version__ = '2.4'
38+
__version__ = '3.0.0'
4039
__website__ = 'https://github.com/stefankoegl/python-json-pointer'
4140
__license__ = 'Modified BSD License'
4241

4342

44-
try:
45-
from itertools import izip
46-
str = unicode
47-
encode_str = lambda u: u.encode("raw_unicode_escape")
48-
except ImportError: # Python 3
49-
izip = zip
50-
encode_str = lambda u: u
5143

5244
try:
5345
from collections.abc import Mapping, Sequence
@@ -58,7 +50,6 @@
5850
import re
5951
import copy
6052

61-
6253
_nothing = object()
6354

6455

@@ -145,7 +136,7 @@ def pairwise(iterable):
145136
a, b = tee(iterable)
146137
for _ in b:
147138
break
148-
return izip(a, b)
139+
return zip(a, b)
149140

150141

151142
class JsonPointerException(Exception):
@@ -259,12 +250,11 @@ def get_part(cls, doc, part):
259250
else:
260251
raise JsonPointerException("Document '%s' does not support indexing, "
261252
"must be mapping/sequence or support __getitem__" % type(doc))
262-
253+
263254
def get_parts(self):
264255
"""Returns the list of the parts. For example, JsonPointer('/a/b').get_parts() == ['a', 'b']"""
265-
266-
return self.parts
267256

257+
return self.parts
268258

269259
def walk(self, doc, part):
270260
""" Walks one step in doc and returns the referenced part """
@@ -281,7 +271,7 @@ def walk(self, doc, part):
281271
return doc[part]
282272

283273
except IndexError:
284-
raise JsonPointerException("index '%s' is out of bounds" % (part, ))
274+
raise JsonPointerException("index '%s' is out of bounds" % (part,))
285275

286276
# Else the object is a mapping or supports __getitem__(so assume custom indexing)
287277
try:
@@ -290,7 +280,6 @@ def walk(self, doc, part):
290280
except KeyError:
291281
raise JsonPointerException("member '%s' not found in %s" % (part, doc))
292282

293-
294283
def contains(self, ptr):
295284
""" Returns True if self contains the given ptr """
296285
return self.parts[:len(ptr.parts)] == ptr.parts
@@ -312,9 +301,10 @@ def join(self, suffix):
312301
except:
313302
raise JsonPointerException("Invalid suffix")
314303

315-
def __truediv__(self, suffix): # Python 3
304+
def __truediv__(self, suffix): # Python 3
316305
return self.join(suffix)
317-
__div__ = __truediv__ # Python 2
306+
307+
__div__ = __truediv__ # Python 2
318308

319309
@property
320310
def path(self):
@@ -342,10 +332,10 @@ def __hash__(self):
342332
return hash(tuple(self.parts))
343333

344334
def __str__(self):
345-
return encode_str(self.path)
335+
return self.path
346336

347337
def __repr__(self):
348-
return "JsonPointer(" + repr(self.path) + ")"
338+
return type(self).__name__ + "(" + repr(self.path) + ")"
349339

350340
@classmethod
351341
def from_parts(cls, parts):
@@ -362,5 +352,6 @@ def from_parts(cls, parts):
362352
def escape(s):
363353
return s.replace('~', '~0').replace('/', '~1')
364354

355+
365356
def unescape(s):
366357
return s.replace('~1', '/').replace('~0', '~')

requirements-dev.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
wheel
2-
twine>=1.11.0
3-
setuptools>=38.6.0
2+
twine>=5.1.0
3+
setuptools>=70
4+
coverage

setup.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
'License :: OSI Approved :: BSD License',
3939
'Operating System :: OS Independent',
4040
'Programming Language :: Python',
41-
'Programming Language :: Python :: 2',
42-
'Programming Language :: Python :: 2.7',
4341
'Programming Language :: Python :: 3',
4442
'Programming Language :: Python :: 3.7',
4543
'Programming Language :: Python :: 3.8',
@@ -65,5 +63,5 @@
6563
py_modules=MODULES,
6664
scripts=['bin/jsonpointer'],
6765
classifiers=CLASSIFIERS,
68-
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, !=3.6.*',
66+
python_requires='>=3.7',
6967
)

tests.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33

44
from __future__ import unicode_literals
55

6+
import copy
67
import doctest
7-
import unittest
88
import sys
9-
import copy
9+
import unittest
10+
1011
import jsonpointer
1112
from jsonpointer import resolve_pointer, EndOfList, JsonPointerException, \
12-
JsonPointer, set_pointer
13+
JsonPointer, set_pointer
1314

1415

1516
class SpecificationTests(unittest.TestCase):
1617
""" Tests all examples from the JSON Pointer specification """
1718

1819
def test_example(self):
19-
doc = {
20+
doc = {
2021
"foo": ["bar", "baz"],
2122
"": 0,
2223
"a/b": 1,
@@ -42,7 +43,6 @@ def test_example(self):
4243
self.assertEqual(resolve_pointer(doc, "/ "), 7)
4344
self.assertEqual(resolve_pointer(doc, "/m~0n"), 8)
4445

45-
4646
def test_eol(self):
4747
doc = {
4848
"foo": ["bar", "baz"]
@@ -165,19 +165,16 @@ def test_eq_hash(self):
165165
self.assertFalse(p1 == "/something/1/b")
166166

167167
def test_contains(self):
168-
169168
self.assertTrue(self.ptr1.contains(self.ptr2))
170169
self.assertTrue(self.ptr1.contains(self.ptr1))
171170
self.assertFalse(self.ptr1.contains(self.ptr3))
172171

173172
def test_contains_magic(self):
174-
175173
self.assertTrue(self.ptr2 in self.ptr1)
176174
self.assertTrue(self.ptr1 in self.ptr1)
177175
self.assertFalse(self.ptr3 in self.ptr1)
178176

179177
def test_join(self):
180-
181178
ptr12a = self.ptr1.join(self.ptr2)
182179
self.assertEqual(ptr12a.path, "/a/b/c/a/b")
183180

@@ -196,7 +193,6 @@ def test_join(self):
196193
self.assertRaises(JsonPointerException, self.ptr1.join, 0)
197194

198195
def test_join_magic(self):
199-
200196
ptr12a = self.ptr1 / self.ptr2
201197
self.assertEqual(ptr12a.path, "/a/b/c/a/b")
202198

@@ -212,6 +208,7 @@ def test_join_magic(self):
212208
ptr12e = self.ptr1 / ["a", "b"]
213209
self.assertEqual(ptr12e.path, "/a/b/c/a/b")
214210

211+
215212
class WrongInputTests(unittest.TestCase):
216213

217214
def test_no_start_slash(self):
@@ -244,7 +241,6 @@ def test_empty_path(self):
244241
self.assertEqual(doc, last)
245242
self.assertTrue(nxt is None)
246243

247-
248244
def test_path(self):
249245
doc = {'a': [{'b': 1, 'c': 2}, 5]}
250246
ptr = JsonPointer('/a/0/b')
@@ -256,7 +252,7 @@ def test_path(self):
256252
class SetTests(unittest.TestCase):
257253

258254
def test_set(self):
259-
doc = {
255+
doc = {
260256
"foo": ["bar", "baz"],
261257
"": 0,
262258
"a/b": 1,
@@ -285,7 +281,7 @@ def test_set(self):
285281

286282
newdoc = set_pointer(doc, "/fud", {}, inplace=False)
287283
newdoc = set_pointer(newdoc, "/fud/gaw", [1, 2, 3], inplace=False)
288-
self.assertEqual(resolve_pointer(newdoc, "/fud"), {'gaw' : [1, 2, 3]})
284+
self.assertEqual(resolve_pointer(newdoc, "/fud"), {'gaw': [1, 2, 3]})
289285

290286
newdoc = set_pointer(doc, "", 9, inplace=False)
291287
self.assertEqual(newdoc, 9)
@@ -307,14 +303,13 @@ def test_set(self):
307303
self.assertRaises(JsonPointerException, set_pointer, doc, "/fud/gaw", 9)
308304

309305
set_pointer(doc, "/fud", {})
310-
set_pointer(doc, "/fud/gaw", [1, 2, 3] )
311-
self.assertEqual(resolve_pointer(doc, "/fud"), {'gaw' : [1, 2, 3]})
306+
set_pointer(doc, "/fud/gaw", [1, 2, 3])
307+
self.assertEqual(resolve_pointer(doc, "/fud"), {'gaw': [1, 2, 3]})
312308

313309
self.assertRaises(JsonPointerException, set_pointer, doc, "", 9)
314310

315311

316312
class AltTypesTests(unittest.TestCase):
317-
318313
class Node(object):
319314
def __init__(self, name, parent=None):
320315
self.name = name
@@ -349,13 +344,13 @@ def __setitem__(self, key, val):
349344
class mdict(object):
350345
def __init__(self, d):
351346
self._d = d
347+
352348
def __getitem__(self, item):
353349
return self._d[item]
354350

355351
mdict = mdict({'root': {'1': {'2': '3'}}})
356352
Node = Node
357353

358-
359354
def test_alttypes(self):
360355
Node = self.Node
361356

0 commit comments

Comments
 (0)