Skip to content

Commit 2c48ca5

Browse files
committed
Merge tag '0.0.19' into develop
Version 0.0.19 + Replaces all noseOfYeti tests with py.test tests + Fixes #37 (h/t @lockie) + Resolves #34 by enabling deletion of properties.
2 parents e8c30ec + 695ae17 commit 2c48ca5

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

python_jsonschema_objects/classbuilder.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import logging
1010
logger = logging.getLogger(__name__)
1111

12+
13+
1214
# Long is no longer a thing in python3.x
1315
if sys.version_info > (3,):
1416
long = int
@@ -130,7 +132,8 @@ def __new__(cls, **props):
130132
obj = None
131133
validation_errors = []
132134
for klass in valid_types:
133-
logger.debug("Attempting to instantiate {0} as {1}".format(
135+
logger.debug(util.lazy_format(
136+
"Attempting to instantiate {0} as {1}",
134137
cls, klass))
135138
try:
136139
obj = klass(**props)
@@ -156,7 +159,7 @@ def __init__(self, **props):
156159
for prop in props:
157160

158161
try:
159-
logger.debug("Setting value for %s' to %s", prop, props[prop])
162+
logger.debug(util.lazy_format("Setting value for '{0}' to {1}", prop, props[prop]))
160163
setattr(self, prop, props[prop])
161164
except validators.ValidationError as e:
162165
import sys
@@ -380,9 +383,9 @@ def resolve_classes(self, iterable):
380383

381384
def construct(self, uri, *args, **kw):
382385
""" Wrapper to debug things """
383-
logger.debug("Constructing {0}".format(uri))
386+
logger.debug(util.lazy_format("Constructing {0}", uri))
384387
ret = self._construct(uri, *args, **kw)
385-
logger.debug("Constructed {0}".format(ret))
388+
logger.debug(util.lazy_format("Constructed {0}", ret))
386389
return ret
387390

388391
def _construct(self, uri, clsdata, parent=(ProtocolBase,)):
@@ -413,13 +416,13 @@ def _construct(self, uri, clsdata, parent=(ProtocolBase,)):
413416
clsdata['type'], (ProtocolBase, LiteralValue)):
414417
# It's possible that this reference was already resolved, in which
415418
# case it will have its type parameter set
416-
logger.debug("Using previously resolved type "
417-
"(with different URI) for %s", uri)
419+
logger.debug(util.lazy_format("Using previously resolved type "
420+
"(with different URI) for {0}", uri))
418421
self.resolved[uri] = clsdata['type']
419422
elif uri in self.resolved:
420-
logger.debug("Using previously resolved object for %s", uri)
423+
logger.debug(util.lazy_format("Using previously resolved object for {0}", uri))
421424
else:
422-
logger.debug("Resolving object for %s", uri)
425+
logger.debug(util.lazy_format("Resolving object for {0}", uri))
423426

424427
with self.resolver.resolving(uri) as resolved:
425428
self.resolved[uri] = None # Set incase there is a circular reference in schema definition
@@ -477,7 +480,7 @@ def _build_literal(self, nm, clsdata):
477480
return cls
478481

479482
def _build_object(self, nm, clsdata, parents):
480-
logger.debug("Building object {0}".format(nm))
483+
logger.debug(util.lazy_format("Building object {0}", nm))
481484

482485
props = {}
483486

@@ -526,7 +529,7 @@ def _build_object(self, nm, clsdata, parents):
526529

527530
elif 'oneOf' in detail:
528531
potential = self.resolve_classes(detail['oneOf'])
529-
logger.debug("Designating {0} as oneOf {1}".format(prop, potential))
532+
logger.debug(util.lazy_format("Designating {0} as oneOf {1}", prop, potential))
530533
desc = detail[
531534
'description'] if 'description' in detail else ""
532535
props[prop] = make_property(prop,

python_jsonschema_objects/util.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
import copy
33
import json
44

5+
6+
class lazy_format(object):
7+
__slots__ = ('fmt', 'args', 'kwargs')
8+
9+
def __init__(self, fmt, *args, **kwargs):
10+
self.fmt = fmt
11+
self.args = args
12+
self.kwargs = kwargs
13+
14+
def __str__(self):
15+
self.fmt.format(*self.args, **self.kwargs)
16+
17+
518
def safe_issubclass(x, y):
619
"""Safe version of issubclass() that will not throw TypeErrors.
720

0 commit comments

Comments
 (0)