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


Python Headers.to_wsgi_list方法代码示例

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


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

示例1: Response

# 需要导入模块: from werkzeug.datastructures import Headers [as 别名]
# 或者: from werkzeug.datastructures.Headers import to_wsgi_list [as 别名]
class Response(Future):
    '''connect/express inspired response object'''

    default_status = 200
    default_mimetype = 'text/plain'

    @property
    def status_code(self):
        return self._status_code

    @status_code.setter
    def status_code(self, code):
        self._status_code = code
        try:
            self._status = '%d %s' % (code, HTTP_STATUS_CODES[code].upper())
        except KeyError:
            self._status = '%d UNKNOWN' % code

    def __init__(self, environ, start_response):
        super(Response, self).__init__()
        self.environ = environ
        self.start_response = start_response
        self.headers = Headers()
        self.status_code = self.default_status
        self.headers['Content-Type'] = self.default_status

    def status(self, code):
        self.status_code = code
        return self

    def end(self):
        headers = self.headers.to_wsgi_list()
        self.start_response(self._status, headers)
        return self

    def send(self, result):
        if isinstance(result, bytes):
            result = [result]

        headers = self.headers.to_wsgi_list()
        self.start_response(self._status, headers)

        self.set_result(result)
        return self
开发者ID:keis,项目名称:lera,代码行数:46,代码来源:verktyg.py

示例2: fixing_start_response

# 需要导入模块: from werkzeug.datastructures import Headers [as 别名]
# 或者: from werkzeug.datastructures.Headers import to_wsgi_list [as 别名]
 def fixing_start_response(status, headers, exc_info=None):
     headers = Headers(headers)
     self.fix_headers(environ, headers, status)
     return start_response(status, headers.to_wsgi_list(), exc_info)
开发者ID:gaoussoucamara,项目名称:simens-cerpad,代码行数:6,代码来源:fixers.py

示例3: Response

# 需要导入模块: from werkzeug.datastructures import Headers [as 别名]
# 或者: from werkzeug.datastructures.Headers import to_wsgi_list [as 别名]
class Response(object):
    """A response wrapper.

    :param body: Body of the response.
    :param headers: Headers to respond with.
    :param status_code: Status-code of the response [default 200].

    :type body: str
    :type headers: werkzeug.datastructures.Headers | list
    :type status_code: int

    .. code-block:: python

        import poort

        def application(environ, start_response):
            request = poort.Request(environ)
            response = poort.Response('Hallo world!')

            return response(request, start_response)

    """

    def __init__(self, body='', headers=None, status_code=200):
        self.status_code = status_code
        self.headers = Headers(headers)
        self.body = body

    def get_status(self):
        """Get the status of the response as HTTP code.

        :rtype: str

        """

        return '{:d} {:s}'.format(self.status_code,
                                  HTTP_STATUS_CODES[self.status_code])

    def get_body(self):
        """Retrieve the body of the response.

        You can override this method to serialize JSON, for example,
        and return this as the body.

        :rtype: str

        """
        return self.body

    def prepare_response(self, request=None):
        """Prepare the response.

        This prepares (encodes) the body, you can override this method
        to add/override headers when the response is being prepared.

        To yield other content, you should look at `get_body`.

        :param request: Request that was made, None is allowed.

        :type request: poort.Request

        :rtype: str

        """
        if PY2:
            return [self.get_body().encode('utf-8')]
        else:
            return [bytes(self.get_body(), 'UTF8')]

    def respond(self, request):
        """Prepare a tuple to respond with.

        :param request: Request that was made, None is allowed.

        :type request: poort.Request

        :rtype: tuple[str, list[str], str]

        """
        response = self.prepare_response(request)
        return (self.get_status(), self.headers.to_wsgi_list(), response)

    def __call__(self, request, start_response):
        """Respond to WSGI with the current settings.

        :param request: Request that was made, None is allowed.
        :param start_response: Handler provided by WSGI.

        :type request: poort.Request
        :type start_response: callable

        """
        status, headers, response = self.respond(request)
        start_response(status, headers)
        return response

    def set_cookie(self, name, value='', max_age=None,
                   path='/', domain=None, secure=False, httponly=True):
        """Add a cookie to the response.

#.........这里部分代码省略.........
开发者ID:CorverDevelopment,项目名称:Poort,代码行数:103,代码来源:response.py


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