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


Python httplib2.debuglevel方法代码示例

本文整理汇总了Python中httplib2.debuglevel方法的典型用法代码示例。如果您正苦于以下问题:Python httplib2.debuglevel方法的具体用法?Python httplib2.debuglevel怎么用?Python httplib2.debuglevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在httplib2的用法示例。


在下文中一共展示了httplib2.debuglevel方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _Httplib2Debuglevel

# 需要导入模块: import httplib2 [as 别名]
# 或者: from httplib2 import debuglevel [as 别名]
def _Httplib2Debuglevel(http_request, level, http=None):
    """Temporarily change the value of httplib2.debuglevel, if necessary.

    If http_request has a `loggable_body` distinct from `body`, then we
    need to prevent httplib2 from logging the full body. This sets
    httplib2.debuglevel for the duration of the `with` block; however,
    that alone won't change the value of existing HTTP connections. If
    an httplib2.Http object is provided, we'll also change the level on
    any cached connections attached to it.

    Args:
      http_request: a Request we're logging.
      level: (int) the debuglevel for logging.
      http: (optional) an httplib2.Http whose connections we should
        set the debuglevel on.

    Yields:
      None.
    """
    if http_request.loggable_body is None:
        yield
        return
    old_level = httplib2.debuglevel
    http_levels = {}
    httplib2.debuglevel = level
    if http is not None:
        for connection_key, connection in http.connections.items():
            # httplib2 stores two kinds of values in this dict, connection
            # classes and instances. Since the connection types are all
            # old-style classes, we can't easily distinguish by connection
            # type -- so instead we use the key pattern.
            if ':' not in connection_key:
                continue
            http_levels[connection_key] = connection.debuglevel
            connection.set_debuglevel(level)
    yield
    httplib2.debuglevel = old_level
    if http is not None:
        for connection_key, old_level in http_levels.items():
            if connection_key in http.connections:
                http.connections[connection_key].set_debuglevel(old_level) 
开发者ID:google,项目名称:apitools,代码行数:43,代码来源:http_wrapper.py

示例2: __init__

# 需要导入模块: import httplib2 [as 别名]
# 或者: from httplib2 import debuglevel [as 别名]
def __init__(self, timeout, proxy=None, cacert=None, sessions=False):
            ##httplib2.debuglevel=4
            kwargs = {}
            if proxy:
                import socks
                kwargs['proxy_info'] = httplib2.ProxyInfo(proxy_type=socks.PROXY_TYPE_HTTP, **proxy)
                print "using proxy", proxy

            # set optional parameters according supported httplib2 version
            if httplib2.__version__ >= '0.3.0':
                kwargs['timeout'] = timeout
            if httplib2.__version__ >= '0.7.0':
                kwargs['disable_ssl_certificate_validation'] = cacert is None
                kwargs['ca_certs'] = cacert    
            httplib2.Http.__init__(self, **kwargs) 
开发者ID:uwdata,项目名称:termite-visualizations,代码行数:17,代码来源:transport.py

示例3: test_dataproc_resource

# 需要导入模块: import httplib2 [as 别名]
# 或者: from httplib2 import debuglevel [as 别名]
def test_dataproc_resource():
    '''Tests dataproc cluster creation/deletion. Requests are captured by the responses library, so
    no actual HTTP requests are made here.

    Note that inspecting the HTTP requests can be useful for debugging, which can be done by adding:

    import httplib2
    httplib2.debuglevel = 4
    '''
    with mock.patch('httplib2.Http', new=HttpSnooper):

        pipeline = PipelineDefinition(
            name='test_dataproc_resource',
            solid_defs=[dataproc_solid],
            mode_defs=[ModeDefinition(resource_defs={'dataproc': dataproc_resource})],
        )

        result = execute_pipeline(
            pipeline,
            {
                'solids': {
                    'dataproc_solid': {
                        'config': {
                            'job_config': {
                                'projectId': PROJECT_ID,
                                'region': REGION,
                                'job': {
                                    'reference': {'projectId': PROJECT_ID},
                                    'placement': {'clusterName': CLUSTER_NAME},
                                    'hiveJob': {'queryList': {'queries': ['SHOW DATABASES']}},
                                },
                            },
                            'job_scoped_cluster': True,
                        }
                    }
                },
                'resources': {
                    'dataproc': {
                        'config': {
                            'projectId': PROJECT_ID,
                            'clusterName': CLUSTER_NAME,
                            'region': REGION,
                            'cluster_config': {
                                'softwareConfig': {
                                    'properties': {
                                        # Create a single-node cluster
                                        # This needs to be the string "true" when
                                        # serialized, not a boolean true
                                        'dataproc:dataproc.allow.zero.workers': 'true'
                                    }
                                }
                            },
                        }
                    }
                },
            },
        )
        assert result.success 
开发者ID:dagster-io,项目名称:dagster,代码行数:60,代码来源:test_resources.py

示例4: _MakeRequestNoRetry

# 需要导入模块: import httplib2 [as 别名]
# 或者: from httplib2 import debuglevel [as 别名]
def _MakeRequestNoRetry(http, http_request, redirections=5,
                        check_response_func=CheckResponse):
    """Send http_request via the given http.

    This wrapper exists to handle translation between the plain httplib2
    request/response types and the Request and Response types above.

    Args:
      http: An httplib2.Http instance, or a http multiplexer that delegates to
          an underlying http, for example, HTTPMultiplexer.
      http_request: A Request to send.
      redirections: (int, default 5) Number of redirects to follow.
      check_response_func: Function to validate the HTTP response.
          Arguments are (Response, response content, url).

    Returns:
      A Response object.

    Raises:
      RequestError if no response could be parsed.

    """
    connection_type = None
    # Handle overrides for connection types.  This is used if the caller
    # wants control over the underlying connection for managing callbacks
    # or hash digestion.
    if getattr(http, 'connections', None):
        url_scheme = parse.urlsplit(http_request.url).scheme
        if url_scheme and url_scheme in http.connections:
            connection_type = http.connections[url_scheme]

    # Custom printing only at debuglevel 4
    new_debuglevel = 4 if httplib2.debuglevel == 4 else 0
    with _Httplib2Debuglevel(http_request, new_debuglevel, http=http):
        info, content = http.request(
            str(http_request.url), method=str(http_request.http_method),
            body=http_request.body, headers=http_request.headers,
            redirections=redirections, connection_type=connection_type)

    if info is None:
        raise exceptions.RequestError()

    response = Response(info, content, http_request.url)
    check_response_func(response)
    return response 
开发者ID:google,项目名称:apitools,代码行数:47,代码来源:http_wrapper.py


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