コード例 #1
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)
コード例 #2
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)
コード例 #3
0
ファイル: __init__.py プロジェクト: jctank/python-yql
 def __init__(self, query):
     self.query = clean_query(query)
コード例 #4
0
ファイル: __init__.py プロジェクト: StremorCorp/python-yql
 def __init__(self, query):
     self.query = clean_query(query)