Exemple #1
0
 def test_2(self):
     state = TalosPolicyDB("./talos-virtualchain.db")
     policyA = state.get_policy("mtr5ENEQ73HZMeZvUEjXdWRJvMhQJMHzcJ", 1)
     policyA_str = policyA.to_json()
     polcyB = create_policy_from_json_str(policyA_str)
     self.assertEquals(policyA_str, polcyB.to_json())
     print policyA_str
Exemple #2
0
    def get_policy_with_txid(self, txid, do_cache=True):
        if do_cache:
            cache_polciy = self._get_policy_txid_cache(txid)
            if cache_polciy is not None:
                return cache_polciy

        req = requests.get("http://%s:%d/policy?txid=%s" % (self.ip, self.port, txid))
        self._check_code(req.status_code, req.reason)
        policy = create_policy_from_json_str(req.text)
        self._put_policy_txid_cache(txid, policy)
        return policy
Exemple #3
0
    def get_policy(self, owner, streamid, do_cache=True):
        if do_cache:
            cache_polciy = self._get_policy_cache(owner, streamid)
            if cache_polciy is not None:
                return cache_polciy

        req = requests.get("http://%s:%d/policy?owner=%s&stream-id=%d" % (self.ip, self.port, owner, int(streamid)))
        self._check_code(req.status_code, req.reason)
        policy = create_policy_from_json_str(req.text)
        self._put_policy_cache(owner, streamid, policy)
        return policy
 def handle_body(body):
     if body is None:
         raise TalosVCRestClientError("Received reuqest without body")
     policy = create_policy_from_json_str(body)
     self._put_policy_cache(owner, streamid, policy)
     return defer.succeed(policy)