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


Python StackInABox.call_into方法代码示例

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


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

示例1: httpretty_callback

# 需要导入模块: from stackinabox.stack import StackInABox [as 别名]
# 或者: from stackinabox.stack.StackInABox import call_into [as 别名]
def httpretty_callback(request, uri, headers):
    """httpretty request handler.

    converts a call intercepted by httpretty to
    the stack-in-a-box infrastructure

    :param request: request object
    :param uri: the uri of the request
    :param headers: headers for the response

    :returns: tuple - (int, dict, string) containing:
                      int - the http response status code
                      dict - the headers for the http response
                      string - http string response

    """
    method = request.method
    response_headers = CaseInsensitiveDict()
    response_headers.update(headers)
    request_headers = CaseInsensitiveDict()
    request_headers.update(request.headers)
    request.headers = request_headers
    return StackInABox.call_into(method,
                                 request,
                                 uri,
                                 response_headers)
开发者ID:BenjamenMeyer,项目名称:stackInABox,代码行数:28,代码来源:core.py

示例2: handle

# 需要导入模块: from stackinabox.stack import StackInABox [as 别名]
# 或者: from stackinabox.stack.StackInABox import call_into [as 别名]
    def handle(self, request, uri):
        """Request handler interface.

        :param request: Python requests Request object
        :param uri: URI of the request
        """

        # Convert the call over to Stack-In-A-Box
        method = request.method
        headers = CaseInsensitiveDict()
        request_headers = CaseInsensitiveDict()
        request_headers.update(request.headers)
        request.headers = request_headers
        stackinabox_result = StackInABox.call_into(method,
                                                   request,
                                                   uri,
                                                   headers)

        # reformat the result for easier use
        status_code, output_headers, body = stackinabox_result

        json_data = None
        text_data = None
        content_data = None
        body_data = None

        # if the body is a string-type...
        if isinstance(body, six.string_types):
            # Try to convert it to JSON
            text_data = body
            try:
                json_data = json.dumps(text_data)
                text_data = json_data
            except Exception:
                json_data = None
                text_data = body

        # if the body is binary, then it's the content
        elif isinstance(body, six.binary_type):
            content_data = body

        # by default, it's just body data
        else:
            # default to body data
            body_data = body

        # build the Python requests' Response object
        return requests_mock.response.create_response(
            request,
            headers=output_headers,
            status_code=status_code,
            body=body_data,
            json=json_data,
            text=text_data,
            content=content_data
        )
开发者ID:BenjamenMeyer,项目名称:stackInABox,代码行数:58,代码来源:core.py

示例3: httpretty_callback

# 需要导入模块: from stackinabox.stack import StackInABox [as 别名]
# 或者: from stackinabox.stack.StackInABox import call_into [as 别名]
def httpretty_callback(request, uri, headers):
    method = request.method
    response_headers = CaseInsensitiveDict()
    response_headers.update(headers)
    request_headers = CaseInsensitiveDict()
    request_headers.update(request.headers)
    request.headers = request_headers
    return StackInABox.call_into(method,
                                 request,
                                 uri,
                                 response_headers)
开发者ID:kidster,项目名称:stackInABox,代码行数:13,代码来源:util_httpretty.py

示例4: responses_callback

# 需要导入模块: from stackinabox.stack import StackInABox [as 别名]
# 或者: from stackinabox.stack.StackInABox import call_into [as 别名]
def responses_callback(request):
    method = request.method
    headers = CaseInsensitiveDict()
    request_headers = CaseInsensitiveDict()
    request_headers.update(request.headers)
    request.headers = request_headers
    uri = request.url
    return StackInABox.call_into(method,
                                 request,
                                 uri,
                                 headers)
开发者ID:kidster,项目名称:stackInABox,代码行数:13,代码来源:util_responses.py

示例5: handle

# 需要导入模块: from stackinabox.stack import StackInABox [as 别名]
# 或者: from stackinabox.stack.StackInABox import call_into [as 别名]
    def handle(self, request, uri):
        method = request.method
        headers = CaseInsensitiveDict()
        request_headers = CaseInsensitiveDict()
        request_headers.update(request.headers)
        request.headers = request_headers
        stackinabox_result = StackInABox.call_into(method,
                                                   request,
                                                   uri,
                                                   headers)

        status_code, output_headers, body = stackinabox_result

        json_data = None
        text_data = None
        content_data = None
        body_data = None

        if isinstance(body, six.string_types):
            text_data = body
            try:
                json_data = json.dumps(text_data)
                text_data = json_data
            except:
                json_data = None
                text_data = body

        elif isinstance(body, six.binary_type):
            content_data = body

        else:
            # default to body data
            body_data = body

        return requests_mock.response.create_response(
            request,
            headers=output_headers,
            status_code=status_code,
            body=body_data,
            json=json_data,
            text=text_data,
            content=content_data
        )
开发者ID:kidster,项目名称:stackInABox,代码行数:45,代码来源:util_requests_mock.py

示例6: responses_callback

# 需要导入模块: from stackinabox.stack import StackInABox [as 别名]
# 或者: from stackinabox.stack.StackInABox import call_into [as 别名]
def responses_callback(request):
    """Responses Request Handler.

    Converts a call intercepted by Responses to
    the Stack-In-A-Box infrastructure

    :param request: request object

    :returns: tuple - (int, dict, string) containing:
                      int - the HTTP response status code
                      dict - the headers for the HTTP response
                      string - HTTP string response
    """
    method = request.method
    headers = CaseInsensitiveDict()
    request_headers = CaseInsensitiveDict()
    request_headers.update(request.headers)
    request.headers = request_headers
    uri = request.url
    return StackInABox.call_into(method,
                                 request,
                                 uri,
                                 headers)
开发者ID:BenjamenMeyer,项目名称:stackInABox,代码行数:25,代码来源:core.py


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