Skip to content

Commit 1d77117

Browse files
committed
Kill jsonschema.compat as well.
1 parent 1b20554 commit 1d77117

15 files changed

+70
-185
lines changed

jsonschema/_format.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import socket
44
import struct
55

6-
from jsonschema.compat import str_types
76
from jsonschema.exceptions import FormatError
87

98

@@ -179,7 +178,7 @@ def wrap(func):
179178
@_checks_drafts(name="idn-email")
180179
@_checks_drafts(name="email")
181180
def is_email(instance):
182-
if not isinstance(instance, str_types):
181+
if not isinstance(instance, str):
183182
return True
184183
return "@" in instance
185184

@@ -191,7 +190,7 @@ def is_email(instance):
191190
draft3="ip-address", draft4="ipv4", draft6="ipv4", draft7="ipv4",
192191
)
193192
def is_ipv4(instance):
194-
if not isinstance(instance, str_types):
193+
if not isinstance(instance, str):
195194
return True
196195
if not _ipv4_re.match(instance):
197196
return False
@@ -205,7 +204,7 @@ def is_ipv4(instance):
205204
name="ipv6", raises=(socket.error, struct.error, ValueError),
206205
)
207206
def is_ipv6(instance):
208-
if not isinstance(instance, str_types):
207+
if not isinstance(instance, str):
209208
return True
210209
return socket.inet_pton(socket.AF_INET6, instance)
211210

@@ -220,7 +219,7 @@ def is_ipv6(instance):
220219
draft7="hostname",
221220
)
222221
def is_host_name(instance):
223-
if not isinstance(instance, str_types):
222+
if not isinstance(instance, str):
224223
return True
225224
if not _host_name_re.match(instance):
226225
return False
@@ -242,7 +241,7 @@ def is_host_name(instance):
242241
raises=(idna.IDNAError, UnicodeError),
243242
)
244243
def is_idn_host_name(instance):
245-
if not isinstance(instance, str_types):
244+
if not isinstance(instance, str):
246245
return True
247246
idna.encode(instance)
248247
return True
@@ -258,7 +257,7 @@ def is_idn_host_name(instance):
258257
else:
259258
@_checks_drafts(name="uri")
260259
def is_uri(instance):
261-
if not isinstance(instance, str_types):
260+
if not isinstance(instance, str):
262261
return True
263262
return validate_rfc3986(instance, rule="URI")
264263

@@ -268,26 +267,26 @@ def is_uri(instance):
268267
raises=ValueError,
269268
)
270269
def is_uri_reference(instance):
271-
if not isinstance(instance, str_types):
270+
if not isinstance(instance, str):
272271
return True
273272
return validate_rfc3986(instance, rule="URI_reference")
274273

275274
else:
276275
@_checks_drafts(draft7="iri", raises=ValueError)
277276
def is_iri(instance):
278-
if not isinstance(instance, str_types):
277+
if not isinstance(instance, str):
279278
return True
280279
return rfc3987.parse(instance, rule="IRI")
281280

282281
@_checks_drafts(draft7="iri-reference", raises=ValueError)
283282
def is_iri_reference(instance):
284-
if not isinstance(instance, str_types):
283+
if not isinstance(instance, str):
285284
return True
286285
return rfc3987.parse(instance, rule="IRI_reference")
287286

288287
@_checks_drafts(name="uri", raises=ValueError)
289288
def is_uri(instance):
290-
if not isinstance(instance, str_types):
289+
if not isinstance(instance, str):
291290
return True
292291
return rfc3987.parse(instance, rule="URI")
293292

@@ -297,7 +296,7 @@ def is_uri(instance):
297296
raises=ValueError,
298297
)
299298
def is_uri_reference(instance):
300-
if not isinstance(instance, str_types):
299+
if not isinstance(instance, str):
301300
return True
302301
return rfc3987.parse(instance, rule="URI_reference")
303302

@@ -313,34 +312,34 @@ def is_uri_reference(instance):
313312
if validate_rfc3339:
314313
@_checks_drafts(name="date-time")
315314
def is_datetime(instance):
316-
if not isinstance(instance, str_types):
315+
if not isinstance(instance, str):
317316
return True
318317
return validate_rfc3339(instance)
319318

320319
@_checks_drafts(draft7="time")
321320
def is_time(instance):
322-
if not isinstance(instance, str_types):
321+
if not isinstance(instance, str):
323322
return True
324323
return is_datetime("1970-01-01T" + instance)
325324

326325

327326
@_checks_drafts(name="regex", raises=re.error)
328327
def is_regex(instance):
329-
if not isinstance(instance, str_types):
328+
if not isinstance(instance, str):
330329
return True
331330
return re.compile(instance)
332331

333332

334333
@_checks_drafts(draft3="date", draft7="date", raises=ValueError)
335334
def is_date(instance):
336-
if not isinstance(instance, str_types):
335+
if not isinstance(instance, str):
337336
return True
338337
return datetime.datetime.strptime(instance, "%Y-%m-%d")
339338

340339

341340
@_checks_drafts(draft3="time", raises=ValueError)
342341
def is_draft3_time(instance):
343-
if not isinstance(instance, str_types):
342+
if not isinstance(instance, str):
344343
return True
345344
return datetime.datetime.strptime(instance, "%H:%M:%S")
346345

@@ -361,7 +360,7 @@ def is_css_color_code(instance):
361360
@_checks_drafts(draft3="color", raises=(ValueError, TypeError))
362361
def is_css21_color(instance):
363362
if (
364-
not isinstance(instance, str_types) or
363+
not isinstance(instance, str) or
365364
instance.lower() in CSS21_NAMES_TO_HEX
366365
):
367366
return True
@@ -384,7 +383,7 @@ def is_css3_color(instance):
384383
raises=jsonpointer.JsonPointerException,
385384
)
386385
def is_json_pointer(instance):
387-
if not isinstance(instance, str_types):
386+
if not isinstance(instance, str):
388387
return True
389388
return jsonpointer.JsonPointer(instance)
390389

@@ -399,7 +398,7 @@ def is_json_pointer(instance):
399398
def is_relative_json_pointer(instance):
400399
# Definition taken from:
401400
# https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01#section-3
402-
if not isinstance(instance, str_types):
401+
if not isinstance(instance, str):
403402
return True
404403
non_negative_integer, rest = [], ""
405404
for i, character in enumerate(instance):

jsonschema/_legacy_validators.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from jsonschema import _utils
2-
from jsonschema.compat import iteritems
32
from jsonschema.exceptions import ValidationError
43

54

65
def dependencies_draft3(validator, dependencies, instance, schema):
76
if not validator.is_type(instance, "object"):
87
return
98

10-
for property, dependency in iteritems(dependencies):
9+
for property, dependency in dependencies.items():
1110
if property not in instance:
1211
continue
1312

@@ -100,7 +99,7 @@ def properties_draft3(validator, properties, instance, schema):
10099
if not validator.is_type(instance, "object"):
101100
return
102101

103-
for property, subschema in iteritems(properties):
102+
for property, subschema in properties.items():
104103
if property in instance:
105104
for error in validator.descend(
106105
instance[property],

jsonschema/_reflect.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
import sys
1111

12-
from jsonschema.compat import PY3
13-
1412

1513
class _NoModuleFound(Exception):
1614
"""
@@ -42,12 +40,8 @@ class ObjectNotFound(InvalidName):
4240

4341

4442

45-
if PY3:
46-
def reraise(exception, traceback):
47-
raise exception.with_traceback(traceback)
48-
else:
49-
exec("""def reraise(exception, traceback):
50-
raise exception.__class__, exception, traceback""")
43+
def reraise(exception, traceback):
44+
raise exception.with_traceback(traceback)
5145

5246
reraise.__doc__ = """
5347
Re-raise an exception, with an optional traceback, in a way that is compatible

jsonschema/_types.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from pyrsistent import pmap
44
import attr
55

6-
from jsonschema.compat import int_types, str_types
76
from jsonschema.exceptions import UndefinedTypeCheck
87

98

@@ -19,7 +18,7 @@ def is_integer(checker, instance):
1918
# bool inherits from int, so ensure bools aren't reported as ints
2019
if isinstance(instance, bool):
2120
return False
22-
return isinstance(instance, int_types)
21+
return isinstance(instance, int)
2322

2423

2524
def is_null(checker, instance):
@@ -38,7 +37,7 @@ def is_object(checker, instance):
3837

3938

4039
def is_string(checker, instance):
41-
return isinstance(instance, str_types)
40+
return isinstance(instance, str)
4241

4342

4443
def is_any(checker, instance):

jsonschema/_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
from collections.abc import MutableMapping
2+
from urllib.parse import urlsplit
13
import itertools
24
import json
35
import pkgutil
46
import re
57

6-
from jsonschema.compat import MutableMapping, str_types, urlsplit
7-
88

99
class URIDict(MutableMapping):
1010
"""
@@ -160,7 +160,7 @@ def ensure_list(thing):
160160
Otherwise, return it unchanged.
161161
"""
162162

163-
if isinstance(thing, str_types):
163+
if isinstance(thing, str):
164164
return [thing]
165165
return thing
166166

jsonschema/_validators.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010
uniq,
1111
)
1212
from jsonschema.exceptions import FormatError, ValidationError
13-
from jsonschema.compat import iteritems
1413

1514

1615
def patternProperties(validator, patternProperties, instance, schema):
1716
if not validator.is_type(instance, "object"):
1817
return
1918

20-
for pattern, subschema in iteritems(patternProperties):
21-
for k, v in iteritems(instance):
19+
for pattern, subschema in patternProperties.items():
20+
for k, v in instance.items():
2221
if re.search(pattern, k):
2322
for error in validator.descend(
2423
v, subschema, path=k, schema_path=pattern,
@@ -224,7 +223,7 @@ def dependencies(validator, dependencies, instance, schema):
224223
if not validator.is_type(instance, "object"):
225224
return
226225

227-
for property, dependency in iteritems(dependencies):
226+
for property, dependency in dependencies.items():
228227
if property not in instance:
229228
continue
230229

@@ -277,7 +276,7 @@ def properties(validator, properties, instance, schema):
277276
if not validator.is_type(instance, "object"):
278277
return
279278

280-
for property, subschema in iteritems(properties):
279+
for property, subschema in properties.items():
281280
if property in instance:
282281
for error in validator.descend(
283282
instance[property],

jsonschema/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
The ``jsonschema`` command line.
33
"""
44

5+
from json import JSONDecodeError
56
from textwrap import dedent
67
import argparse
78
import errno
@@ -13,7 +14,6 @@
1314

1415
from jsonschema import __version__
1516
from jsonschema._reflect import namedAny
16-
from jsonschema.compat import JSONDecodeError
1717
from jsonschema.exceptions import SchemaError
1818
from jsonschema.validators import validator_for
1919

jsonschema/compat.py

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)