def dump(self, dump_path): """Dump serialized schema to a file. """ with open(dump_path, 'w') as dump_file: json_dump = pretty_json(self.serialize()) dump_file.write(json_dump) log.info('Dumped: %s\n' % dump_path)
def dump(self): builder = JSONSchemaBuilder() for portal_type in GEVER_TYPES + GEVER_SQL_TYPES: schema = builder.build_schema(portal_type) filename = '%s.schema.json' % portal_type dump_path = pjoin(self.schema_dumps_dir, filename) with open(dump_path, 'w') as dump_file: json_dump = pretty_json(schema) dump_file.write(json_dump) log.info('Dumped: %s\n' % dump_path)
def dump(self): builder = OGGBundleJSONSchemaBuilder() dump_dir = pjoin(resource_filename('opengever.bundle', 'schemas/')) mkdir_p(dump_dir) for portal_type, short_name in GEVER_TYPES_TO_OGGBUNDLE_TYPES.items(): schema = builder.build_schema(portal_type) filename = '%ss.schema.json' % short_name dump_path = pjoin(dump_dir, filename) with open(dump_path, 'w') as dump_file: json_dump = pretty_json(schema) dump_file.write(json_dump) log.info('Dumped: %s\n' % dump_path)
def json_dumps(data): """Dump a data structure as json string while adding information about the setring type (unicode, binary). """ def prepare(thing): if isinstance(thing, unicode): return u'u:{}'.format(thing) if isinstance(thing, str): return u'b:{}'.format(thing.decode('utf-8')) elif isinstance(thing, (int, long, float, bool, NoneType)): return thing elif isinstance(thing, (list, tuple)): return map(prepare, thing) elif isinstance(thing, dict): return dict(map(lambda pair: map(prepare, pair), thing.items())) else: raise TypeError('Not supported: {!r} ({!r})'.format( thing, type(thing))) return pretty_json(prepare(data))