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


Python SimpleCookie.values方法代码示例

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


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

示例1: test_cookies

# 需要导入模块: from pulsar.utils.httpurl import SimpleCookie [as 别名]
# 或者: from pulsar.utils.httpurl.SimpleCookie import values [as 别名]
 def test_cookies(self):
     h = Headers()
     cookies = SimpleCookie({'bla': 'foo', 'pippo': 'pluto'})
     self.assertEqual(len(cookies), 2)
     for c in cookies.values():
         v = c.OutputString()
         h.add_header('Set-Cookie', v)
     h = str(h)
     self.assertTrue(
         h in ('Set-Cookie: bla=foo\r\nSet-Cookie: pippo=pluto\r\n\r\n',
               'Set-Cookie: pippo=pluto\r\nSet-Cookie: bla=foo\r\n\r\n'))
开发者ID:Danzeer,项目名称:pulsar,代码行数:13,代码来源:headers.py

示例2: WsgiResponse

# 需要导入模块: from pulsar.utils.httpurl import SimpleCookie [as 别名]
# 或者: from pulsar.utils.httpurl.SimpleCookie import values [as 别名]

#.........这里部分代码省略.........
    def is_streamed(self):
        """Check if the response is streamed.

        A streamed response is an iterable with no length information.
        In this case streamed means that there is no information about
        the number of iterations.

        This is usually `True` if a generator is passed to the response object.
        """
        try:
            len(self.content)
        except TypeError:
            return True
        return False

    def can_set_cookies(self):
        if self.status_code < 400:
            return self._can_store_cookies

    def length(self):
        if not self.is_streamed:
            return reduce(lambda x, y: x+len(y), self.content, 0)

    def start(self, start_response):
        assert not self._started
        self._started = True
        return start_response(self.status, self.get_headers())

    def __iter__(self):
        if self._iterated:
            raise RuntimeError('WsgiResponse can be iterated once only')
        self._started = True
        self._iterated = True
        if self.is_streamed:
            return wsgi_encoder(self.content, self.encoding or 'utf-8')
        else:
            return iter(self.content)

    def close(self):
        """Close this response, required by WSGI
        """
        if self.is_streamed:
            if hasattr(self.content, 'close'):
                self.content.close()

    def set_cookie(self, key, **kwargs):
        """
        Sets a cookie.

        ``expires`` can be a string in the correct format or a
        ``datetime.datetime`` object in UTC. If ``expires`` is a datetime
        object then ``max_age`` will be calculated.
        """
        set_cookie(self.cookies, key, **kwargs)

    def delete_cookie(self, key, path='/', domain=None):
        set_cookie(self.cookies, key, max_age=0, path=path, domain=domain,
                   expires='Thu, 01-Jan-1970 00:00:00 GMT')

    def get_headers(self):
        """The list of headers for this response
        """
        headers = self.headers
        if has_empty_content(self.status_code):
            headers.pop('content-type', None)
            headers.pop('content-length', None)
            self._content = ()
        else:
            if not self.is_streamed:
                cl = 0
                for c in self.content:
                    cl += len(c)
                if cl == 0 and self.content_type in JSON_CONTENT_TYPES:
                    self._content = (b'{}',)
                    cl = len(self._content[0])
                headers['Content-Length'] = str(cl)
            ct = self.content_type
            # content type encoding available
            if self.encoding:
                ct = ct or 'text/plain'
                if 'charset=' not in ct:
                    ct = '%s; charset=%s' % (ct, self.encoding)
            if ct:
                headers['Content-Type'] = ct
            if self.method == HEAD:
                self._content = ()
        if self.can_set_cookies():
            for c in self.cookies.values():
                headers.add_header('Set-Cookie', c.OutputString())
        return list(headers)

    def has_header(self, header):
        return header in self.headers
    __contains__ = has_header

    def __setitem__(self, header, value):
        self.headers[header] = value

    def __getitem__(self, header):
        return self.headers[header]
开发者ID:yl849646685,项目名称:pulsar,代码行数:104,代码来源:wrappers.py

示例3: WsgiResponse

# 需要导入模块: from pulsar.utils.httpurl import SimpleCookie [as 别名]
# 或者: from pulsar.utils.httpurl.SimpleCookie import values [as 别名]

#.........这里部分代码省略.........
            else:  # pragma    nocover
                if isinstance(content, unicode):
                    content = bytes(content, "latin-1")
            if isinstance(content, bytes):
                content = (content,)
            self._content = content
        else:
            raise RuntimeError("Cannot set content. Already iterated")

    content = property(_get_content, _set_content)

    def _get_content_type(self):
        return self.headers.get("content-type")

    def _set_content_type(self, typ):
        if typ:
            self.headers["content-type"] = typ
        else:
            self.headers.pop("content-type", None)

    content_type = property(_get_content_type, _set_content_type)

    def __call__(self, environ, start_response, exc_info=None):
        """Make sure the headers are set."""
        if not exc_info:
            for rm in self.middleware:
                try:
                    rm(environ, self)
                except:
                    LOGGER.error("Exception in response middleware", exc_info=True)
        start_response(self.status, self.get_headers(), exc_info=exc_info)
        return self

    def start(self):
        self.__call__(self.environ, self.start_response)

    def length(self):
        if not self.is_streamed:
            return reduce(lambda x, y: x + len(y), self.content, 0)

    @property
    def response(self):
        return responses.get(self.status_code)

    @property
    def status(self):
        return "%s %s" % (self.status_code, self.response)

    def __str__(self):
        return self.status

    def __repr__(self):
        return "%s(%s)" % (self.__class__.__name__, self)

    @property
    def is_streamed(self):
        """If the response is streamed (the response is not an iterable with
length information) this property is `True`.  In this case streamed
means that there is no information about the number of iterations.
This is usually `True` if a generator is passed to the response object."""
        return is_streamed(self.content)

    def __iter__(self):
        if self._started:
            raise RuntimeError("WsgiResponse can be iterated only once")
        self._started = True
        if self.is_streamed:
            return wsgi_iterator(self.content, self.encoding)
        else:
            return iter(self.content)

    def __len__(self):
        return len(self.content)

    def set_cookie(self, key, **kwargs):
        """
        Sets a cookie.

        ``expires`` can be a string in the correct format or a
        ``datetime.datetime`` object in UTC. If ``expires`` is a datetime
        object then ``max_age`` will be calculated.
        """
        set_cookie(self.cookies, key, **kwargs)

    def delete_cookie(self, key, path="/", domain=None):
        set_cookie(self.cookies, key, max_age=0, path=path, domain=domain, expires="Thu, 01-Jan-1970 00:00:00 GMT")

    def get_headers(self):
        headers = self.headers
        if has_empty_content(self.status_code, self.method):
            headers.pop("content-type", None)
            headers.pop("content-length", None)
        elif not self.is_streamed:
            cl = 0
            for c in self.content:
                cl += len(c)
            headers["Content-Length"] = str(cl)
        for c in self.cookies.values():
            headers["Set-Cookie"] = c.OutputString()
        return list(headers)
开发者ID:ilmiacs,项目名称:pulsar,代码行数:104,代码来源:wsgi.py

示例4: WsgiResponse

# 需要导入模块: from pulsar.utils.httpurl import SimpleCookie [as 别名]
# 或者: from pulsar.utils.httpurl.SimpleCookie import values [as 别名]

#.........这里部分代码省略.........
                    content = content.encode(self.encoding or 'utf-8')
            if isinstance(content, bytes):
                content = (content,)
            self._content = content
        else:
            raise RuntimeError('Cannot set content. Already iterated')
    content = property(_get_content, _set_content)

    def _get_content_type(self):
        return self.headers.get('content-type')

    def _set_content_type(self, typ):
        if typ:
            self.headers['content-type'] = typ
        else:
            self.headers.pop('content-type', None)
    content_type = property(_get_content_type, _set_content_type)

    def length(self):
        if not self.is_streamed:
            return reduce(lambda x, y: x+len(y), self.content, 0)

    @property
    def response(self):
        return responses.get(self.status_code)

    @property
    def status(self):
        return '%s %s' % (self.status_code, self.response)

    def __str__(self):
        return self.status

    def __repr__(self):
        return '%s(%s)' % (self.__class__.__name__, self)

    @property
    def is_streamed(self):
        """If the response is streamed (the response is not an iterable with
length information) this property is `True`.  In this case streamed
means that there is no information about the number of iterations.
This is usually `True` if a generator is passed to the response object."""
        return is_streamed(self.content)

    def __iter__(self):
        if self._started:
            raise RuntimeError('WsgiResponse can be iterated once only')
        self._started = True
        if is_streamed(self.content):
            return wsgi_encoder(self.content, self.encoding or 'utf-8')
        else:
            return iter(self.content)

    def __len__(self):
        return len(self.content)

    def set_cookie(self, key, **kwargs):
        """
        Sets a cookie.

        ``expires`` can be a string in the correct format or a
        ``datetime.datetime`` object in UTC. If ``expires`` is a datetime
        object then ``max_age`` will be calculated.
        """
        set_cookie(self.cookies, key, **kwargs)

    def delete_cookie(self, key, path='/', domain=None):
        set_cookie(self.cookies, key, max_age=0, path=path, domain=domain,
                   expires='Thu, 01-Jan-1970 00:00:00 GMT')

    def get_headers(self):
        headers = self.headers
        if has_empty_content(self.status_code, self.method):
            headers.pop('content-type', None)
            headers.pop('content-length', None)
            self._content = ()
        else:
            if not self.is_streamed:
                cl = 0
                for c in self.content:
                    cl += len(c)
                if cl == 0 and self.content_type in JSON_CONTENT_TYPES:
                    self._content = (b'{}',)
                    cl = len(self._content[0])
                headers['Content-Length'] = str(cl)
            if not self.content_type:
                headers['Content-Type'] = 'text/plain'
        for c in self.cookies.values():
            headers['Set-Cookie'] = c.OutputString()
        return list(headers)

    def has_header(self, header):
        return header in self.headers
    __contains__ = has_header

    def __setitem__(self, header, value):
        self.headers[header] = value

    def __getitem__(self, header):
        return self.headers[header]
开发者ID:elimisteve,项目名称:pulsar,代码行数:104,代码来源:wrappers.py


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