def get(self, key): ret = self._collection.find_one({'_id': key}) if ret is None: raise exceptions.NotFound(key) ret = unescape(ret) ret['_id'] = key return ret
def get(self, key): assert not key.startswith('_'), 'Elasticsearch keys may not being with _' res = self._connection.get(index=self._index, doc_type=self._doc_type, id=key, ignore=404) if res.get('status') == 404 or not res['found']: raise exceptions.NotFound(key) return res['_source']
def get_namespace(self, name): try: return Namespace(self.read(name)) except exceptions.NotFound: raise exceptions.NotFound( code='N404', title='Namespace not found', detail='Namespace "{}" was not found'.format(name))
def get_collection(self, name): try: return Collection(self.read(name)) except exceptions.NotFound: raise exceptions.NotFound( code='C404', title='Collection not found', detail='Collection "{}" was not found in namespace "{}"'. format(name, self.ref))
def read(self, key): try: doc = self._state.get(key) if doc.data is None and doc.data_ref: doc.data = self._storage.get(doc.data_ref) return doc except exceptions.NotFound: raise exceptions.NotFound( code='D404', title='Document not found', detail='Document "{}" was not found'.format(key))
def get_collection(self, name): try: col = Collection.from_dict(self.read(name).data) col.ref = name # TODO Fix me, this just makes life much easier col.name = name return col except exceptions.NotFound: raise exceptions.NotFound( code='C404', title='Collection not found', detail='Collection "{}" was not found in namespace "{}"'.format(name, self.name) )
def get(self, key): try: return self._cache[key] except KeyError: raise exceptions.NotFound(key)
def first(self, query, order=None): try: return next(self.query(query, order=order)) except StopIteration: raise exceptions.NotFound(query)