示例#1
0
文件: rest.py 项目: ignatov/localbox
    def __init__(self, http_resp):
        self.http_response = http_resp
        self.status = http_resp.status
        self.reason = http_resp.reason
        self.body = http_resp.read()
        self.headers = dict(http_resp.getheaders())

        try:
            self.data = json.loads(self.body)
        except ValueError:
            # looks like this isn't json, data is None
            self.data = None
示例#2
0
文件: auth.py 项目: ignatov/localbox
    def fetch_access_token(self, oauth_request, trusted_url=None):
        """Used to get a access token from Drobpox using the headers.  Returns an OauthToken."""
        url = trusted_url if trusted_url else self.access_token_url

        self.connection.request(oauth_request.http_method, url,
                                headers=oauth_request.to_header()) 

        response = self.connection.getresponse()
        assert response.status == 200, "Invalid response code %d" % response.status
        if trusted_url:
            token = json.loads(response.read())
            token['token'] = str(token['token'])
            token['secret'] = str(token['secret'])
            return oauth.OAuthToken(token['token'], token['secret'])
        else:
            return oauth.OAuthToken.from_string(response.read())