def DELETE(self, name): site = get_site(name) if site is None: raise common.NotFound(error="db_notfound", name=name) else: site.delete() return {"ok": True}
def process_value(self, value, property, prefix=""): unique = property.get('unique', True) expected_type = property.expected_type.key at = {"key": self.key, "property": prefix + property.name} if isinstance(value, list): if unique is True: raise common.BadData( message='expected atom, found list', at=at, value=value ) p = web.storage(property.copy()) p.unique = True return [self.process_value(v, p) for v in value] if unique is False: raise common.BadData( message='expected list, found atom', at=at, value=value ) type_found = common.find_type(value) if expected_type in common.primitive_types: # string can be converted to any type and int can be converted to float try: if type_found == '/type/string' and expected_type != '/type/string': value = common.primitive_types[expected_type](value) elif type_found == '/type/int' and expected_type == '/type/float': value = float(value) except ValueError as e: raise common.BadData(message=str(e), at=at, value=value) elif property.expected_type.kind == 'embeddable': if isinstance(value, dict): return self.process_data( value, property.expected_type, prefix=at['property'] + "." ) else: raise common.TypeMismatch(expected_type, type_found, at=at, value=value) else: if type_found == '/type/string': value = common.Reference(value) type_found = common.find_type(value) if type_found == '/type/object': type_found = self.get_type(value) # type is not found only when the thing id not found. if type_found is None: raise common.NotFound(key=text_type(value), at=at) if expected_type != type_found: raise common.BadData( message='expected %s, found %s' % (property.expected_type.key, type_found), at=at, value=value, ) return value
def GET(self, sitename): i = input("key", revision=None, expand=False) site = get_site(sitename) revision = i.revision and to_int(i.revision, "revision") json_data = site.get(i.key, revision=revision) if not json_data: raise common.NotFound(key=i.key) return JSON(json_data)
def GET(self, sitename): i = input("key", revision=None, expand=False) site = get_site(sitename) if not site: logger.exception("get_site({}) failed".format(sitename)) revision = i.revision and to_int(i.revision, "revision") json_data = site.get(i.key, revision=revision) if not json_data: raise common.NotFound(key=i.key) return JSON(json_data)
def process(self, query): p = SaveProcessor(self.store, self.author) for q in serialize(query): q = common.parse_query(q) if not isinstance(q, dict) or q.get('key') is None: continue key = q['key'] thing = get_thing(self.store, key) create = q.pop('create', None) if thing is None: if create: q = self.remove_connects(q) else: raise common.NotFound(key=key) else: q = self.connect_all(thing._data, q) yield p.process(key, q)
def GET(self, sitename, path): store = get_site(sitename).get_store() json_data = store.get_json(path) if not json_data: raise common.NotFound(error="notfound", key=path) return JSON(json_data)
def GET(self, name): site = get_site(name) if site is None: raise common.NotFound(error="db_notfound", name=name) else: return {"name": site.sitename}