Exemplo n.º 1
0
    def create_auth(self, access_info):
        """
        @param access_info: {user_id, access_token, action, zone, expires}
        @return {"payload":..., "signature": ...}
        """

        if "expires" not in access_info or not access_info["expires"]:
            raise Exception("expires must exist in access_info")

        payload = base64_url_encode(json_dump(access_info))
        signature = self.sign_string(payload)
        return {"payload": payload, "signature": signature}
Exemplo n.º 2
0
    def create_auth(self, access_info):
        """
        @param access_info: {user_id, access_token, action, zone, expires}
        @return {"payload":..., "signature": ...}
        """

        if "expires" not in access_info or not access_info["expires"]:
            raise Exception("expires must exist in access_info")

        payload = base64_url_encode(json_dump(access_info))
        signature = self.sign_string(payload)
        return {"payload": payload,
                "signature": signature}
Exemplo n.º 3
0
    def _build_http_request(self, url, base_params, verb):
        params = {}
        for key, values in base_params.items():
            if values is None:
                continue
            if isinstance(values, list):
                for i in range(1, len(values) + 1):
                    if isinstance(values[i - 1], dict):
                        for sk, sv in values[i - 1].items():
                            if isinstance(sv, dict) or isinstance(sv, list):
                                sv = json_dump(sv)
                            params['%s.%d.%s' % (key, i, sk)] = sv
                    else:
                        params['%s.%d' % (key, i)] = values[i - 1]
            else:
                params[key] = values

        return HTTPRequest(verb, self.protocol, "", self.host, self.port, url,
                 params)
Exemplo n.º 4
0
 def test_json_dump_list(self):
     obj = [1, 4, '3']
     expected = '[1,4,"3"]'
     self.assertEqual(json_dump(obj), expected)
Exemplo n.º 5
0
 def test_json_dump_invalid_obj(self):
     obj = {unittest: 'invalid key'}
     expected = None
     self.assertEqual(json_dump(obj), expected)
Exemplo n.º 6
0
 def test_json_dump_dict(self):
     obj = {'1': 1, 'str': 'string', 'none': None}
     expected = '{"1":1,"none":null,"str":"string"}'
     self.assertEqual(json_dump(obj), expected)