Exemplo n.º 1
0
 def _save(self, action):
     if r.zscore('requests', action.id):
         raise ValueError('Duplicated request: {}'.format(action.id))
     submitted_by_ts = calendar.timegm(action.request.submitted_on.timetuple())
     self._pipe.zadd('requests', submitted_by_ts, action.id)
     self._request_key = 'requests:{}'.format(self._request_id)
     self._pipe.hmset(self._request_key, {'submitted_by': action.request.submitted_by,
                                          'submitted_on': action.request.submitted_on,
                                          'message_id': action.request.message_id,
                                          'id': self._request_id,
                                          '__response_class': _fullname(action.response_class)(),
                                          'type': action.__class__.__module__,
                                          '__hash': action.id})
Exemplo n.º 2
0
            else:
                return Literal(elm.replace('"', ''), datatype=XSD.string)

        c, s, p, o = eval(x)
        return c, __term(s), __term(p), __term(o)

    for x in r.zrangebyscore('fragments:{}:stream'.format(fid), '-inf', '{}'.format(float(until))):
        yield __triplify(x)


def add_stream_triple(fid, tp, (s, p, o), timestamp=None):
    if timestamp is None:
        timestamp = calendar.timegm(dt.utcnow().timetuple())
    quad = (tp, s.n3(), p.n3(), o.n3())
    stream_key = 'fragments:{}:stream'.format(fid)
    not_found = not bool(r.zscore(stream_key, quad))
    if not_found:
        with r.pipeline() as pipe:
            pipe.zadd(stream_key, timestamp, quad)
            pipe.execute()
    return not_found


class GraphProvider(object):
    def __init__(self):
        self.__graph_dict = {}

    @staticmethod
    def __clean(name):
        shutil.rmtree('store/query/{}'.format(name))