本文整理匯總了Python中httplib2.DEFAULT_MAX_REDIRECTS屬性的典型用法代碼示例。如果您正苦於以下問題:Python httplib2.DEFAULT_MAX_REDIRECTS屬性的具體用法?Python httplib2.DEFAULT_MAX_REDIRECTS怎麽用?Python httplib2.DEFAULT_MAX_REDIRECTS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類httplib2
的用法示例。
在下文中一共展示了httplib2.DEFAULT_MAX_REDIRECTS屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: request
# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import DEFAULT_MAX_REDIRECTS [as 別名]
def request(self, uri, method='GET', body=None, headers=None,
redirections=httplib2.DEFAULT_MAX_REDIRECTS,
connection_type=None):
scheme = urlparse.urlparse(uri).scheme
request = (uri, method, body, headers)
if scheme == 'http':
self.throttle_handler.http_request(request)
elif scheme == 'https':
self.throttle_handler.https_request(request)
response = super(_ThrottledHttp, self).request(
uri, method, body, headers, redirections, connection_type)
if scheme == 'http':
self.throttle_handler.http_response(request, response)
elif scheme == 'https':
self.throttle_handler.https_response(request, response)
return response
示例2: set_user_agent
# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import DEFAULT_MAX_REDIRECTS [as 別名]
def set_user_agent(http, user_agent):
"""Set the user-agent on every request.
Args:
http - An instance of httplib2.Http
or something that acts like it.
user_agent: string, the value for the user-agent header.
Returns:
A modified instance of http that was passed in.
Example:
h = httplib2.Http()
h = set_user_agent(h, "my-app-name/6.0")
Most of the time the user-agent will be set doing auth, this is for the rare
cases where you are accessing an unauthenticated endpoint.
"""
request_orig = http.request
# The closure that will replace 'httplib2.Http.request'.
def new_request(uri, method='GET', body=None, headers=None,
redirections=httplib2.DEFAULT_MAX_REDIRECTS,
connection_type=None):
"""Modify the request headers to add the user-agent."""
if headers is None:
headers = {}
if 'user-agent' in headers:
headers['user-agent'] = user_agent + ' ' + headers['user-agent']
else:
headers['user-agent'] = user_agent
resp, content = request_orig(uri, method, body, headers,
redirections, connection_type)
return resp, content
http.request = new_request
return http
示例3: tunnel_patch
# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import DEFAULT_MAX_REDIRECTS [as 別名]
def tunnel_patch(http):
"""Tunnel PATCH requests over POST.
Args:
http - An instance of httplib2.Http
or something that acts like it.
Returns:
A modified instance of http that was passed in.
Example:
h = httplib2.Http()
h = tunnel_patch(h, "my-app-name/6.0")
Useful if you are running on a platform that doesn't support PATCH.
Apply this last if you are using OAuth 1.0, as changing the method
will result in a different signature.
"""
request_orig = http.request
# The closure that will replace 'httplib2.Http.request'.
def new_request(uri, method='GET', body=None, headers=None,
redirections=httplib2.DEFAULT_MAX_REDIRECTS,
connection_type=None):
"""Modify the request headers to add the user-agent."""
if headers is None:
headers = {}
if method == 'PATCH':
if 'oauth_token' in headers.get('authorization', ''):
logging.warning(
'OAuth 1.0 request made with Credentials after tunnel_patch.')
headers['x-http-method-override'] = "PATCH"
method = 'POST'
resp, content = request_orig(uri, method, body, headers,
redirections, connection_type)
return resp, content
http.request = new_request
return http
示例4: request
# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import DEFAULT_MAX_REDIRECTS [as 別名]
def request(http, uri, method='GET', body=None, headers=None,
redirections=httplib2.DEFAULT_MAX_REDIRECTS,
connection_type=None):
"""Make an HTTP request with an HTTP object and arguments.
Args:
http: httplib2.Http, an http object to be used to make requests.
uri: string, The URI to be requested.
method: string, The HTTP method to use for the request. Defaults
to 'GET'.
body: string, The payload / body in HTTP request. By default
there is no payload.
headers: dict, Key-value pairs of request headers. By default
there are no headers.
redirections: int, The number of allowed 203 redirects for
the request. Defaults to 5.
connection_type: httplib.HTTPConnection, a subclass to be used for
establishing connection. If not set, the type
will be determined from the ``uri``.
Returns:
tuple, a pair of a httplib2.Response with the status code and other
headers and the bytes of the content returned.
"""
# NOTE: Allowing http or http.request is temporary (See Issue 601).
http_callable = getattr(http, 'request', http)
return http_callable(uri, method=method, body=body, headers=headers,
redirections=redirections,
connection_type=connection_type)
示例5: tunnel_patch
# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import DEFAULT_MAX_REDIRECTS [as 別名]
def tunnel_patch(http):
"""Tunnel PATCH requests over POST.
Args:
http - An instance of httplib2.Http
or something that acts like it.
Returns:
A modified instance of http that was passed in.
Example:
h = httplib2.Http()
h = tunnel_patch(h, "my-app-name/6.0")
Useful if you are running on a platform that doesn't support PATCH.
Apply this last if you are using OAuth 1.0, as changing the method
will result in a different signature.
"""
request_orig = http.request
# The closure that will replace 'httplib2.Http.request'.
def new_request(uri, method='GET', body=None, headers=None,
redirections=httplib2.DEFAULT_MAX_REDIRECTS,
connection_type=None):
"""Modify the request headers to add the user-agent."""
if headers is None:
headers = {}
if method == 'PATCH':
if 'oauth_token' in headers.get('authorization', ''):
LOGGER.warning(
'OAuth 1.0 request made with Credentials after tunnel_patch.')
headers['x-http-method-override'] = "PATCH"
method = 'POST'
resp, content = request_orig(uri, method, body, headers,
redirections, connection_type)
return resp, content
http.request = new_request
return http
示例6: request
# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import DEFAULT_MAX_REDIRECTS [as 別名]
def request(self, uri, method='GET', body=None, headers=None,
redirections=httplib2.DEFAULT_MAX_REDIRECTS,
connection_type=None):
self.headers = headers
return MockResponse()
示例7: _set_user_agent
# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import DEFAULT_MAX_REDIRECTS [as 別名]
def _set_user_agent(http, user_agent):
"""Set the user-agent on every request.
Args:
http (object): An instance of httplib2.Http
or something that acts like it.
user_agent (string): The value for the user-agent header.
Returns:
httplib2.Http: A modified instance of http that was passed in.
"""
if getattr(http, '_user_agent_set', False):
return http
setattr(http, '_user_agent_set', True)
request_orig = http.request
# pylint: disable=missing-param-doc, missing-type-doc
# The closure that will replace 'httplib2.Http.request'.
def new_request(uri, method='GET', body=None, headers=None,
redirections=httplib2.DEFAULT_MAX_REDIRECTS,
connection_type=None):
"""Modify the request headers to add the user-agent.
Returns:
tuple: (httplib2.Response, string) the Response object and the
response content.
"""
if headers is None:
headers = {}
headers['user-agent'] = user_agent
resp, content = request_orig(uri, method, body, headers,
redirections, connection_type)
return resp, content
# pylint: enable=missing-param-doc, missing-type-doc
http.request = new_request
return http