def sprint(obj, indent=4, bullet='* '): ''' Display JSON-like objects in a compact way. Differently to pretty print, it does not format objects using a valid dict/list syntax. Examples -------- >>> obj = {'foo': {'foobar': 1, 'bar': 'null'}, 'bar': ['null', 1, 2, 3]} >>> print(sprint(obj)) bar: * null * 1 * 2 * 3 foo: bar: null foobar: 1 ''' if is_object(obj): if obj: items = [] obj_items = obj.items() obj_items.sort() for key, value in obj_items: if is_object(value) or is_array(value): value = '\n' + _indent_f(sprint(value), indent) else: value = ' ' + sprint(value) items.append('%s:%s' % (key, value)) return '\n'.join(items) return '<empty>' elif is_array(obj): if obj: return itemize(map(sprint, obj)) else: return '<empty>' else: data = unicode(obj) if '\n' in data: data = '\n' + _indent_f(data, indent) return data
def validate(self, obj, lazy=True, path=[]): if not pyson_t.is_array(obj): raise self.ValidationError(" %s object is not an Array" % type(obj)) for idx, x in enumerate(obj): self.array_t.validate(x, lazy, path + [idx])