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


Python http_client.responses方法代码示例

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


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

示例1: send_response

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import responses [as 别名]
def send_response(cls, resource, url, response_content):
        if url == cls.DUMMY_RESPONSE_URL_SILENT:
            return
        elif url == cls.DUMMY_RESPONSE_URL_PRINT:
            six.print_(json.dumps(response_content, indent=2))
        else:
            put_response = requests.put(url,
                                        data=json.dumps(response_content))
            status_code = put_response.status_code
            response_text = put_response.text
            
            body_text = ""
            if status_code // 100 != 2:
                body_text = "\n" + response_text
            resource._base_logger.debug("Status code: {} {}{}".format(put_response.status_code, http_client.responses[put_response.status_code], body_text))

        return put_response 
开发者ID:iRobotCorporation,项目名称:cfn-custom-resource,代码行数:19,代码来源:cfn_custom_resource.py

示例2: __init__

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import responses [as 别名]
def __init__(self, logfunc=None, response=None, err=None):
        """Initialize a RestResult containing the results from a REST call.

        :param logfunc: debug log function.
        :param response: HTTP response.
        :param err: HTTP error.
        """
        self.response = response
        self.log_function = logfunc
        self.error = err
        self.data = ""
        self.status = 0
        if self.response:
            self.status = self.response.getcode()
            result = self.response.read()
            while result:
                self.data += result
                result = self.response.read()

        if self.error:
            self.status = self.error.code
            self.data = http_client.responses[self.status]

        log_debug_msg(self, 'Response code: %s' % self.status)
        log_debug_msg(self, 'Response data: %s' % self.data) 
开发者ID:openstack,项目名称:manila,代码行数:27,代码来源:restclient.py

示例3: error_handler

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import responses [as 别名]
def error_handler(e):
    try:
        if isinstance(e, HTTPException):
            status_code = e.code
            message = e.description if e.description != type(e).description else None
            tb = None
        else:
            status_code = httplib.INTERNAL_SERVER_ERROR
            message = None
            tb = traceback.format_exc() if current_user.admin else None

        if request.is_xhr or request.accept_mimetypes.best in ['application/json', 'text/javascript']:
            response = {
                'message': message,
                'traceback': tb
            }
        else:
            response = render_template('errors/error.html',
                                       title=httplib.responses[status_code],
                                       status_code=status_code,
                                       message=message,
                                       traceback=tb)
    except HTTPException as e2:
        return error_handler(e2)

    return response, status_code 
开发者ID:scragg0x,项目名称:realms-wiki,代码行数:28,代码来源:__init__.py

示例4: check_status_code

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import responses [as 别名]
def check_status_code(response):
    """Returns a signal with info about a response's HTTP status code

    :param response: A `Response` object
    :type response: :class:`requests.Response`
    :returns: Signal with status code details
    :rtype: :class:`syntribos.signal.SynSignal`
    """
    check_name = "HTTP_STATUS_CODE"
    codes = httplib.responses

    data = {
        "response": response,
        "status_code": response.status_code,
        "reason": response.reason,
    }
    if codes.get(response.status_code, None):
        data["details"] = codes[response.status_code]
    else:
        data["details"] = "Unknown"

    text = ("A {code} HTTP status code was returned by the server, with reason"
            " '{reason}'. This status code usually means '{details}'.").format(
                code=data["status_code"],
                reason=data["reason"],
                details=data["details"])

    slug = "HTTP_STATUS_CODE_{range}"
    tags = []

    if data["status_code"] in range(200, 300):
        slug = slug.format(range="2XX")

    elif data["status_code"] in range(300, 400):
        slug = slug.format(range="3XX")

        # CCNEILL: 304 == use local cache; not really a redirect
        if data["status_code"] != 304:
            tags.append("SERVER_REDIRECT")

    elif data["status_code"] in range(400, 500):
        slug = slug.format(range="4XX")
        tags.append("CLIENT_FAIL")

    elif data["status_code"] in range(500, 600):
        slug = slug.format(range="5XX")
        tags.append("SERVER_FAIL")

    slug = (slug + "_{code}").format(code=data["status_code"])

    return syntribos.signal.SynSignal(
        text=text,
        slug=slug,
        strength=1,
        tags=tags,
        data=data,
        check_name=check_name) 
开发者ID:openstack-archive,项目名称:syntribos,代码行数:59,代码来源:http.py


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