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


Python Headers.to_list方法代码示例

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


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

示例1: HTTPHandler

# 需要导入模块: from werkzeug import Headers [as 别名]
# 或者: from werkzeug.Headers import to_list [as 别名]
class HTTPHandler(URLHandler):
    """Opens HTTP connections."""
    default_port = 80
    http_version = '1.1'

    STATE_IDLE, STATE_SENDING, STATE_SENT = range(3)

    def __init__(self, parsed_url, timeout=30, method=None):
        URLHandler.__init__(self, parsed_url, timeout)
        self.headers = Headers()
        self._state = self.STATE_IDLE
        self._method = method

    @property
    def method(self):
        return self._method or 'GET'

    def send(self, data):
        if self._state == self.STATE_IDLE:
            self._state = self.STATE_SENDING
        return URLHandler.send(self, data)

    def send_request(self, data):
        path = self.parsed_url.path or '/'
        if self.parsed_url.query:
            path += '?' + self.parsed_url.query
        self.send_buffered('%s %s HTTP/%s\r\n' % (self._method, str(path),
                                                  self.http_version))
        self.send_buffered('\r\n'.join('%s: %s' % item for item in
                           self.headers.to_list()) + '\r\n\r\n')
        if isinstance(data, basestring):
            self.send_buffered(data)
            data = None
        self.send(data)
        self._state = self.STATE_SENT

    def open(self, data=None):
        # if no method is set switch between GET and POST based on
        # the data.  This is for example the case if the URL was
        # opened with open_url().
        if self._method is None:
            if data is not None:
                self._method = 'POST'
            else:
                self._method = 'GET'

        if self._state != self.STATE_IDLE:
            raise CannotSendRequest()

        if self.http_version == '1.1':
            if 'host' not in self.headers:
                self.headers['Host'] = self.host_string
            if 'accept-encoding' not in self.headers:
                self.headers['Accept-Encoding'] = 'identity'

        if 'content-length' not in self.headers:
            content_length = get_content_length(data)
            if content_length is not None:
                self.headers['Content-Length'] = content_length

        self.send_request(data)
        return HTTPResponse(self)
开发者ID:rockyburt,项目名称:Rezine,代码行数:64,代码来源:net.py

示例2: HTTPHandler

# 需要导入模块: from werkzeug import Headers [as 别名]
# 或者: from werkzeug.Headers import to_list [as 别名]
class HTTPHandler(URLHandler):
    """Opens HTTP connections."""

    default_port = 80
    http_version = "1.1"

    STATE_IDLE, STATE_SENDING, STATE_SENT = range(3)

    def __init__(self, parsed_url, timeout=30, method=None):
        URLHandler.__init__(self, parsed_url, timeout)
        self.headers = Headers()
        self._state = self.STATE_IDLE
        self._method = method

    @property
    def method(self):
        return self._method or "GET"

    def send(self, data):
        if self._state == self.STATE_IDLE:
            self._state = self.STATE_SENDING
        return URLHandler.send(self, data)

    def send_request(self, data):
        path = self.parsed_url.path or "/"
        if self.parsed_url.query:
            path += "?" + self.parsed_url.query
        self.send_buffered("%s %s HTTP/%s\r\n" % (self._method, str(path), self.http_version))
        self.send_buffered("\r\n".join("%s: %s" % item for item in self.headers.to_list()) + "\r\n\r\n")
        if isinstance(data, basestring):
            self.send_buffered(data)
            data = None
        self.send(data)
        self._state = self.STATE_SENT

    def open(self, data=None):
        # if no method is set switch between GET and POST based on
        # the data.  This is for example the case if the URL was
        # opened with open_url().
        if self._method is None:
            if data is not None:
                self._method = "POST"
            else:
                self._method = "GET"

        if self._state != self.STATE_IDLE:
            raise CannotSendRequest()

        if self.http_version == "1.1":
            if "host" not in self.headers:
                self.headers["Host"] = self.host_string
            if "accept-encoding" not in self.headers:
                self.headers["Accept-Encoding"] = "identity"

        if "content-length" not in self.headers:
            content_length = get_content_length(data)
            if content_length is not None:
                self.headers["Content-Length"] = content_length

        self.send_request(data)
        return HTTPResponse(self)
开发者ID:jokey2k,项目名称:pyClanSphere,代码行数:63,代码来源:net.py


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