当前位置: 首页>>代码示例>>Python>>正文


Python httplib2.DEFAULT_MAX_REDIRECTS属性代码示例

本文整理汇总了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 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:21,代码来源:throttle.py

示例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 
开发者ID:splunk,项目名称:splunk-ref-pas-code,代码行数:40,代码来源:http.py

示例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 
开发者ID:splunk,项目名称:splunk-ref-pas-code,代码行数:41,代码来源:http.py

示例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) 
开发者ID:Deltares,项目名称:aqua-monitor,代码行数:31,代码来源:transport.py

示例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 
开发者ID:fniephaus,项目名称:alfred-gmail,代码行数:41,代码来源:http.py

示例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() 
开发者ID:forseti-security,项目名称:forseti-security,代码行数:7,代码来源:http_helpers_test.py

示例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 
开发者ID:forseti-security,项目名称:forseti-security,代码行数:40,代码来源:http_helpers.py


注:本文中的httplib2.DEFAULT_MAX_REDIRECTS属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。