def validate(self, data): # TODO Translate to custom exceptions try: jsonschema.validate(data, self._schema) except jsonschema.ValidationError as e: raise exceptions.SchemaValidationFailed( 'Validation error "{}" at "{}" against schema "{}"'.format( e.message, '/'.join(e.absolute_path), json.dumps(order_dictionary(e.schema))))
def validate(self, data): # TODO Translate to custom exceptions try: jsonschema.validate(data, self._schema) except jsonschema.ValidationError as e: raise exceptions.SchemaValidationFailed( 'Validation error "{}" at "{}" against schema "{}"'.format( e.message, '/'.join(e.absolute_path), json.dumps(order_dictionary(e.schema)) ) )
def create(self, data): if isinstance(data, dict): data = order_dictionary(data) hasher = hashlib.new('sha1') hasher.update(json.dumps(data).encode('utf-8')) # Optimistic check to see if this data object already exists try: # TODO Decide what happens when a key is not found data_obj = self._backend.get(hasher.hexdigest()) if data_obj is not None: return data_obj except Exception: pass data_obj = DataObject(ref=hasher.hexdigest(), data=data) self._backend.set(data_obj.ref, data_obj) return data_obj