17
17
18
18
from proxytypes import LazyProxy
19
19
20
- __version__ = "1.0.0b2 "
20
+ __version__ = "1.0.0b3 "
21
21
22
22
23
23
class JsonRefError (Exception ):
@@ -87,7 +87,7 @@ def __init__(
87
87
loader = None ,
88
88
jsonschema = False ,
89
89
load_on_repr = True ,
90
- merge_extra_properties = False ,
90
+ merge_props = False ,
91
91
_path = (),
92
92
_store = None ,
93
93
):
@@ -98,7 +98,7 @@ def __init__(
98
98
self .loader = loader or jsonloader
99
99
self .jsonschema = jsonschema
100
100
self .load_on_repr = load_on_repr
101
- self .merge_extra_properties = merge_extra_properties
101
+ self .merge_props = merge_props
102
102
self .path = _path
103
103
self .store = _store # Use the same object to be shared with children
104
104
if self .store is None :
@@ -111,7 +111,7 @@ def _ref_kwargs(self):
111
111
loader = self .loader ,
112
112
jsonschema = self .jsonschema ,
113
113
load_on_repr = self .load_on_repr ,
114
- merge_extra_properties = self .merge_extra_properties ,
114
+ merge_props = self .merge_props ,
115
115
path = self .path ,
116
116
store = self .store ,
117
117
)
@@ -145,7 +145,7 @@ def callback(self):
145
145
if hasattr (result , "__subject__" ):
146
146
result = result .__subject__
147
147
if (
148
- self .merge_extra_properties
148
+ self .merge_props
149
149
and isinstance (result , Mapping )
150
150
and len (self .__reference__ ) > 1
151
151
):
@@ -278,13 +278,13 @@ def walk_refs(obj, func, replace=False):
278
278
279
279
def replace_refs (
280
280
obj ,
281
- proxies = True ,
282
- lazy_load = True ,
283
281
base_uri = "" ,
284
282
loader = jsonloader ,
285
283
jsonschema = False ,
286
284
load_on_repr = True ,
287
- merge_extra_properties = False ,
285
+ merge_props = False ,
286
+ proxies = True ,
287
+ lazy_load = True ,
288
288
):
289
289
"""
290
290
Returns a deep copy of `obj` with all contained JSON reference objects
@@ -294,12 +294,6 @@ def replace_refs(
294
294
instance will be created. If `obj` is not a JSON reference object,
295
295
a deep copy of it will be created with all contained JSON
296
296
reference objects replaced by :class:`JsonRef` instances
297
- :param proxies: If `True`, references will be replaced with transparent
298
- proxy objects. Otherwise, they will be replaced directly with the
299
- referred data. (defaults to ``True``)
300
- :param lazy_load: When proxy objects are used, and this is `True`, the
301
- references will not be resolved until that section of the JSON
302
- document is accessed. (defaults to ``True``)
303
297
:param base_uri: URI to resolve relative references against
304
298
:param loader: Callable that takes a URI and returns the parsed JSON
305
299
(defaults to global ``jsonloader``, a :class:`JsonLoader` instance)
@@ -310,11 +304,17 @@ def replace_refs(
310
304
:param load_on_repr: If set to ``False``, :func:`repr` call on a
311
305
:class:`JsonRef` object will not cause the reference to be loaded
312
306
if it hasn't already. (defaults to ``True``)
313
- :param merge_extra_properties : When ``True``, JSON reference objects that
307
+ :param merge_props : When ``True``, JSON reference objects that
314
308
have extra keys other than '$ref' in them will be merged into the
315
309
document resolved by the reference (if it is a dictionary.) NOTE: This
316
310
is not part of the JSON Reference spec, and may not behave the same as
317
311
other libraries.
312
+ :param proxies: If `True`, references will be replaced with transparent
313
+ proxy objects. Otherwise, they will be replaced directly with the
314
+ referred data. (defaults to ``True``)
315
+ :param lazy_load: When proxy objects are used, and this is `True`, the
316
+ references will not be resolved until that section of the JSON
317
+ document is accessed. (defaults to ``True``)
318
318
319
319
"""
320
320
result = _replace_refs (
@@ -323,7 +323,7 @@ def replace_refs(
323
323
loader = loader ,
324
324
jsonschema = jsonschema ,
325
325
load_on_repr = load_on_repr ,
326
- merge_extra_properties = merge_extra_properties ,
326
+ merge_props = merge_props ,
327
327
store = URIDict (),
328
328
path = (),
329
329
recursing = False ,
@@ -342,7 +342,7 @@ def _replace_refs(
342
342
loader ,
343
343
jsonschema ,
344
344
load_on_repr ,
345
- merge_extra_properties ,
345
+ merge_props ,
346
346
store ,
347
347
path ,
348
348
recursing
@@ -370,7 +370,7 @@ def _replace_refs(
370
370
loader = loader ,
371
371
jsonschema = jsonschema ,
372
372
load_on_repr = load_on_repr ,
373
- merge_extra_properties = merge_extra_properties ,
373
+ merge_props = merge_props ,
374
374
_path = path ,
375
375
_store = store ,
376
376
)
@@ -385,7 +385,7 @@ def _replace_refs(
385
385
loader = loader ,
386
386
jsonschema = jsonschema ,
387
387
load_on_repr = load_on_repr ,
388
- merge_extra_properties = merge_extra_properties ,
388
+ merge_props = merge_props ,
389
389
store = store ,
390
390
path = path + (k ,),
391
391
recursing = True ,
@@ -400,7 +400,7 @@ def _replace_refs(
400
400
loader = loader ,
401
401
jsonschema = jsonschema ,
402
402
load_on_repr = load_on_repr ,
403
- merge_extra_properties = merge_extra_properties ,
403
+ merge_props = merge_props ,
404
404
store = store ,
405
405
path = path + (i ,),
406
406
recursing = True ,
@@ -412,14 +412,24 @@ def _replace_refs(
412
412
return obj
413
413
414
414
415
- def load (fp , base_uri = "" , loader = None , jsonschema = False , load_on_repr = True , ** kwargs ):
415
+ def load (
416
+ fp ,
417
+ base_uri = "" ,
418
+ loader = None ,
419
+ jsonschema = False ,
420
+ load_on_repr = True ,
421
+ merge_props = False ,
422
+ proxies = True ,
423
+ lazy_load = True ,
424
+ ** kwargs
425
+ ):
416
426
"""
417
427
Drop in replacement for :func:`json.load`, where JSON references are
418
428
proxied to their referent data.
419
429
420
430
:param fp: File-like object containing JSON document
421
431
:param kwargs: This function takes any of the keyword arguments from
422
- :meth:`JsonRef. replace_refs`. Any other keyword arguments will be passed to
432
+ :func:` replace_refs`. Any other keyword arguments will be passed to
423
433
:func:`json.load`
424
434
425
435
"""
@@ -433,17 +443,30 @@ def load(fp, base_uri="", loader=None, jsonschema=False, load_on_repr=True, **kw
433
443
loader = loader ,
434
444
jsonschema = jsonschema ,
435
445
load_on_repr = load_on_repr ,
446
+ merge_props = merge_props ,
447
+ proxies = proxies ,
448
+ lazy_load = lazy_load ,
436
449
)
437
450
438
451
439
- def loads (s , base_uri = "" , loader = None , jsonschema = False , load_on_repr = True , ** kwargs ):
452
+ def loads (
453
+ s ,
454
+ base_uri = "" ,
455
+ loader = None ,
456
+ jsonschema = False ,
457
+ load_on_repr = True ,
458
+ merge_props = False ,
459
+ proxies = True ,
460
+ lazy_load = True ,
461
+ ** kwargs
462
+ ):
440
463
"""
441
464
Drop in replacement for :func:`json.loads`, where JSON references are
442
465
proxied to their referent data.
443
466
444
467
:param s: String containing JSON document
445
468
:param kwargs: This function takes any of the keyword arguments from
446
- :meth:`JsonRef. replace_refs`. Any other keyword arguments will be passed to
469
+ :func:` replace_refs`. Any other keyword arguments will be passed to
447
470
:func:`json.loads`
448
471
449
472
"""
@@ -457,17 +480,29 @@ def loads(s, base_uri="", loader=None, jsonschema=False, load_on_repr=True, **kw
457
480
loader = loader ,
458
481
jsonschema = jsonschema ,
459
482
load_on_repr = load_on_repr ,
483
+ merge_props = merge_props ,
484
+ proxies = proxies ,
485
+ lazy_load = lazy_load ,
460
486
)
461
487
462
488
463
- def load_uri (uri , base_uri = None , loader = None , jsonschema = False , load_on_repr = True ):
489
+ def load_uri (
490
+ uri ,
491
+ base_uri = None ,
492
+ loader = None ,
493
+ jsonschema = False ,
494
+ load_on_repr = True ,
495
+ merge_props = False ,
496
+ proxies = True ,
497
+ lazy_load = True ,
498
+ ):
464
499
"""
465
500
Load JSON data from ``uri`` with JSON references proxied to their referent
466
501
data.
467
502
468
503
:param uri: URI to fetch the JSON from
469
504
:param kwargs: This function takes any of the keyword arguments from
470
- :meth:`JsonRef. replace_refs`
505
+ :func:` replace_refs`
471
506
472
507
"""
473
508
@@ -482,6 +517,9 @@ def load_uri(uri, base_uri=None, loader=None, jsonschema=False, load_on_repr=Tru
482
517
loader = loader ,
483
518
jsonschema = jsonschema ,
484
519
load_on_repr = load_on_repr ,
520
+ merge_props = merge_props ,
521
+ proxies = proxies ,
522
+ lazy_load = lazy_load ,
485
523
)
486
524
487
525
0 commit comments