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', '~')
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")
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)
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', '~')
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)
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())
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
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)
def test_finds_post_method_for_lowercase_delete_query(self): self.assertEqual(get_http_method("delete from"), "POST")
def test_finds_post_method_for_delete_query(self): self.assertEqual(get_http_method("DELETE from"), "POST")
def test_finds_put_method_for_update_query(self): self.assertEqual(get_http_method("update foo"), "PUT")
def test_finds_post_method_for_insert_query(self): self.assertEqual(get_http_method("INSERT into"), "POST")
def test_finds_get_method_for_select_query(self): self.assertEqual(get_http_method("SELECT foo"), "GET")
def get_http_method(self): """Return the HTTP method associated with the type of this query""" return get_http_method(self.query)
def find_verb_from_query(query, verb): assert get_http_method(query) == verb
def test_finds_get_method_for_show_query(self): self.assertEqual(get_http_method("SHOW tables"), "GET")
def test_finds_get_method_for_describe_query(self): self.assertEqual(get_http_method("DESC tablename"), "GET")
def test_finds_get_method_for_select_query_with_leading_space(self): self.assertEqual(get_http_method(" SELECT foo"), "GET")
def test_finds_get_method_for_lowercase_select_query(self): self.assertEqual(get_http_method("select foo"), "GET")