Beispiel #1
0
 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
Beispiel #2
0
    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']
Beispiel #3
0
 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))
Beispiel #4
0
 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))
Beispiel #5
0
 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))
Beispiel #6
0
 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)
         )
Beispiel #7
0
 def get(self, key):
     try:
         return self._cache[key]
     except KeyError:
         raise exceptions.NotFound(key)
Beispiel #8
0
 def first(self, query, order=None):
     try:
         return next(self.query(query, order=order))
     except StopIteration:
         raise exceptions.NotFound(query)