コード例 #1
0
ファイル: __init__.py プロジェクト: allanice001/RJ45
    def get_uri(self, query, params=None, **kwargs):
        """Get the the request url"""
        query_params = self.get_query_params(query, params, **kwargs)

        token = kwargs.get("token")

        if hasattr(token, "yahoo_guid"):
            query_params["oauth_yahoo_guid"] = getattr(token, "yahoo_guid")

        if not token:
            raise ValueError, "Without a token three-legged-auth cannot be"\
                                                              " carried out"

        yql_logger.debug("query_params: %s", query_params)
        http_method = get_http_method(query)
        oauth_request = oauth.Request.from_consumer_and_token(
            self.consumer,
            http_url=self.uri,
            token=token,
            parameters=query_params,
            http_method=http_method)
        yql_logger.debug("oauth_request: %s", oauth_request)
        # Sign request
        oauth_request.sign_request(self.hmac_sha1_signature, self.consumer,
                                   token)

        yql_logger.debug("oauth_signed_request: %s", oauth_request)
        uri = "%s?%s" % (self.uri, oauth_request.to_postdata())
        return uri.replace('+', '%20').replace('%7E', '~')
コード例 #2
0
ファイル: test_utilities.py プロジェクト: allanice001/RJ45
 def test_finds_post_method_for_multiline_insert_query(self):
     query = """
     INSERT INTO yql.queries.query (name, query)
     VALUES ("weather", "SELECT * FROM weather.forecast
         WHERE location=90210")
         """
     self.assertEqual(get_http_method(query), "POST")
コード例 #3
0
ファイル: __init__.py プロジェクト: allanice001/RJ45
    def execute(self, query, params=None, **kwargs):
        """Execute YQL query"""
        query = clean_query(query)
        url = self.get_uri(query, params, **kwargs)
        # Just in time change to https avoids
        # invalid oauth sigs
        if self.scheme == HTTPS_SCHEME:
            url = url.replace(HTTP_SCHEME, HTTPS_SCHEME)
        yql_logger.debug("executed url: %s", url)
        http_method = get_http_method(query)
        if http_method in ["DELETE", "PUT", "POST"]:
            data = {"q": query}

            # Encode as json and set Content-Type header
            # to reflect we are sending JSON
            # Fixes LP: 629064
            data = json.dumps(data)
            headers = {"Content-Type": "application/json"}
            resp, content = self.http.request(url,
                                              http_method,
                                              headers=headers,
                                              body=data)
            yql_logger.debug("body: %s", data)
        else:
            resp, content = self.http.request(url, http_method)
        yql_logger.debug("http_method: %s", http_method)
        if resp.get('status') == '200':
            return YQLObj(json.loads(content))
        else:
            raise YQLError, (resp, content)
コード例 #4
0
    def get_uri(self, query, params=None, **kwargs):
        """Get the the request url"""
        query_params = self.get_query_params(query, params, **kwargs)

        token = kwargs.get("token")
        
        if hasattr(token, "yahoo_guid"):
            query_params["oauth_yahoo_guid"] = getattr(token, "yahoo_guid")

        if not token:
            raise ValueError, "Without a token three-legged-auth cannot be"\
                                                              " carried out"

        yql_logger.debug("query_params: %s", query_params)
        http_method = get_http_method(query)
        oauth_request = oauth.Request.from_consumer_and_token(
                                        self.consumer, http_url=self.uri, 
                                        token=token, parameters=query_params,
                                        http_method=http_method)
        yql_logger.debug("oauth_request: %s", oauth_request)
        # Sign request 
        oauth_request.sign_request(
                            self.hmac_sha1_signature, self.consumer, token)
        
        yql_logger.debug("oauth_signed_request: %s", oauth_request)
        uri = "%s?%s" % (self.uri,  oauth_request.to_postdata())
        return uri.replace('+', '%20').replace('%7E', '~')
コード例 #5
0
    def execute(self, query, params=None, **kwargs):
        """Execute YQL query"""    
        query = clean_query(query)
        url = self.get_uri(query, params, **kwargs)
        # Just in time change to https avoids 
        # invalid oauth sigs
        if self.scheme == HTTPS_SCHEME:
            url = url.replace(HTTP_SCHEME, HTTPS_SCHEME)
        yql_logger.debug("executed url: %s", url)
        http_method = get_http_method(query)
        if http_method in ["DELETE", "PUT", "POST"]:
            data = {"q": query}

            # Encode as json and set Content-Type header
            # to reflect we are sending JSON
            # Fixes LP: 629064
            data = json.dumps(data)
            headers = {"Content-Type": "application/json"}
            resp, content = self.http.request(
                            url, http_method, headers=headers, body=data)
            yql_logger.debug("body: %s", data)
        else:
            resp, content = self.http.request(url, http_method)
        yql_logger.debug("http_method: %s", http_method)
        if resp.get('status') == '200':
            return YQLObj(json.loads(content))
        else:
            raise YQLError, (resp, content)
コード例 #6
0
 def get_uri(self, query, params=None, **kwargs):
     """Get the the request url"""
     query_params = self.get_query_params(query, params, **kwargs)
 
     http_method = get_http_method(query)
     request = self.__two_legged_request(self.uri, 
                    parameters=query_params, method=http_method)
     return "%s?%s" % (self.uri, request.to_postdata()) 
コード例 #7
0
ファイル: __init__.py プロジェクト: allanice001/RJ45
    def get_uri(self, query, params=None, **kwargs):
        """Get the the request url"""
        query_params = self.get_query_params(query, params, **kwargs)

        http_method = get_http_method(query)
        request = self.__two_legged_request(self.uri,
                                            parameters=query_params,
                                            method=http_method)
        uri = "%s?%s" % (self.uri, request.to_postdata())
        uri = clean_url(uri)
        return uri
コード例 #8
0
    def execute(self, query, params=None, **kwargs):
        """Execute YQL query"""    
        url = self.get_uri(query, params, **kwargs)
        http_method = get_http_method(query)

        if http_method in ["DELETE", "PUT", "POST"]:
            data = {"q": query}
            data = urlencode(data)
            resp, content = self.http.request(
                            url, http_method, body=data)
        else:
            resp, content = self.http.request(url, http_method)

        if resp.get('status') == '200':
            return YQLObj(json.loads(content))
        else:
            raise YQLError, (resp, content)
コード例 #9
0
ファイル: test_utilities.py プロジェクト: allanice001/RJ45
 def test_finds_post_method_for_lowercase_delete_query(self):
     self.assertEqual(get_http_method("delete from"), "POST")
コード例 #10
0
ファイル: test_utilities.py プロジェクト: allanice001/RJ45
 def test_finds_post_method_for_delete_query(self):
     self.assertEqual(get_http_method("DELETE from"), "POST")
コード例 #11
0
ファイル: test_utilities.py プロジェクト: allanice001/RJ45
 def test_finds_put_method_for_update_query(self):
     self.assertEqual(get_http_method("update foo"), "PUT")
コード例 #12
0
ファイル: test_utilities.py プロジェクト: allanice001/RJ45
 def test_finds_post_method_for_insert_query(self):
     self.assertEqual(get_http_method("INSERT into"), "POST")
コード例 #13
0
ファイル: test_utilities.py プロジェクト: allanice001/RJ45
 def test_finds_get_method_for_select_query(self):
     self.assertEqual(get_http_method("SELECT foo"), "GET")
コード例 #14
0
ファイル: __init__.py プロジェクト: StremorCorp/python-yql
 def get_http_method(self):
     """Return the HTTP method associated with the type of this query"""
     return get_http_method(self.query)
コード例 #15
0
def find_verb_from_query(query, verb):
    assert get_http_method(query) == verb
コード例 #16
0
ファイル: test_utilities.py プロジェクト: allanice001/RJ45
 def test_finds_get_method_for_show_query(self):
     self.assertEqual(get_http_method("SHOW tables"), "GET")
コード例 #17
0
ファイル: test_utilities.py プロジェクト: allanice001/RJ45
 def test_finds_get_method_for_describe_query(self):
     self.assertEqual(get_http_method("DESC tablename"), "GET")
コード例 #18
0
ファイル: __init__.py プロジェクト: jctank/python-yql
 def get_http_method(self):
     """Return the HTTP method associated with the type of this query"""
     return get_http_method(self.query)
コード例 #19
0
ファイル: test_utilities.py プロジェクト: allanice001/RJ45
 def test_finds_get_method_for_select_query_with_leading_space(self):
     self.assertEqual(get_http_method(" SELECT foo"), "GET")
コード例 #20
0
ファイル: test_utilities.py プロジェクト: allanice001/RJ45
 def test_finds_get_method_for_lowercase_select_query(self):
     self.assertEqual(get_http_method("select foo"), "GET")