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


Python SimpleCookie.output方法代码示例

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


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

示例1: set_cookie

# 需要导入模块: from six.moves.http_cookies import SimpleCookie [as 别名]
# 或者: from six.moves.http_cookies.SimpleCookie import output [as 别名]
def set_cookie(name, _, *args):
    cookie = SimpleCookie()
    cookie[name] = base64.b64encode(":".join(args))
    cookie[name]['path'] = "/"
    cookie[name]["expires"] = _expiration(5)  # 5 minutes from now
    logger.debug("Cookie expires: %s", cookie[name]["expires"])
    return tuple(cookie.output().split(": ", 1))
开发者ID:jkakavas,项目名称:pysaml2,代码行数:9,代码来源:idp.py

示例2: make_cookie

# 需要导入模块: from six.moves.http_cookies import SimpleCookie [as 别名]
# 或者: from six.moves.http_cookies.SimpleCookie import output [as 别名]
def make_cookie(name, load, seed, expire=0, domain="", path="",
                timestamp=""):
    """
    Create and return a cookie

    :param name: Cookie name
    :param load: Cookie load
    :param seed: A seed for the HMAC function
    :param expire: Number of minutes before this cookie goes stale
    :param domain: The domain of the cookie
    :param path: The path specification for the cookie
    :return: A tuple to be added to headers
    """
    cookie = SimpleCookie()
    if not timestamp:
        timestamp = str(int(time.mktime(time.gmtime())))
    signature = cookie_signature(seed, load, timestamp)
    cookie[name] = "|".join([load, timestamp, signature])
    if path:
        cookie[name]["path"] = path
    if domain:
        cookie[name]["domain"] = domain
    if expire:
        cookie[name]["expires"] = _expiration(expire,
                                              "%a, %d-%b-%Y %H:%M:%S GMT")

    return tuple(cookie.output().split(": ", 1))
开发者ID:HaToHo,项目名称:pysaml2,代码行数:29,代码来源:httputil.py

示例3: set_cookie

# 需要导入模块: from six.moves.http_cookies import SimpleCookie [as 别名]
# 或者: from six.moves.http_cookies.SimpleCookie import output [as 别名]
 def set_cookie(self, user):
     uid = rndstr(32)
     self.uid2user[uid] = user
     cookie = SimpleCookie()
     cookie[self.cookie_name] = uid
     cookie[self.cookie_name]['path'] = "/"
     cookie[self.cookie_name]["expires"] = _expiration(480)
     logger.debug("Cookie expires: %s", cookie[self.cookie_name]["expires"])
     return cookie.output().encode("UTF-8").split(": ", 1)
开发者ID:Lefford,项目名称:pysaml2,代码行数:11,代码来源:sp.py

示例4: delete_cookie

# 需要导入模块: from six.moves.http_cookies import SimpleCookie [as 别名]
# 或者: from six.moves.http_cookies.SimpleCookie import output [as 别名]
def delete_cookie(environ, name):
    kaka = environ.get("HTTP_COOKIE", "")
    logger.debug("delete KAKA: %s", kaka)
    if kaka:
        cookie_obj = SimpleCookie(kaka)
        morsel = cookie_obj.get(name, None)
        cookie = SimpleCookie()
        cookie[name] = ""
        cookie[name]["path"] = "/"
        logger.debug("Expire: %s", morsel)
        cookie[name]["expires"] = _expiration("dawn")
        return tuple(cookie.output().split(": ", 1))
    return None
开发者ID:tophatmonocle,项目名称:pysaml2,代码行数:15,代码来源:idp.py

示例5: delete_cookie

# 需要导入模块: from six.moves.http_cookies import SimpleCookie [as 别名]
# 或者: from six.moves.http_cookies.SimpleCookie import output [as 别名]
 def delete_cookie(self, environ):
     cookie = environ.get("HTTP_COOKIE", '')
     logger.debug("delete cookie: %s", cookie)
     if cookie:
         _name = self.cookie_name
         cookie_obj = SimpleCookie(cookie)
         morsel = cookie_obj.get(_name, None)
         cookie = SimpleCookie()
         cookie[_name] = ""
         cookie[_name]['path'] = "/"
         logger.debug("Expire: %s", morsel)
         cookie[_name]["expires"] = _expiration("now")
         return cookie.output().split(": ", 1)
     return None
开发者ID:Lefford,项目名称:pysaml2,代码行数:16,代码来源:sp.py

示例6: set_cookie

# 需要导入模块: from six.moves.http_cookies import SimpleCookie [as 别名]
# 或者: from six.moves.http_cookies.SimpleCookie import output [as 别名]
def set_cookie(name, _, *args):
    cookie = SimpleCookie()

    data = ":".join(args)
    if not isinstance(data, six.binary_type):
        data = data.encode("ascii")

    data64 = base64.b64encode(data)
    if not isinstance(data64, six.string_types):
        data64 = data64.decode("ascii")

    cookie[name] = data64
    cookie[name]["path"] = "/"
    cookie[name]["expires"] = _expiration(5)  # 5 minutes from now
    logger.debug("Cookie expires: %s", cookie[name]["expires"])
    return tuple(cookie.output().split(": ", 1))
开发者ID:tophatmonocle,项目名称:pysaml2,代码行数:18,代码来源:idp.py

示例7: Response

# 需要导入模块: from six.moves.http_cookies import SimpleCookie [as 别名]
# 或者: from six.moves.http_cookies.SimpleCookie import output [as 别名]
class Response(object):

    """An HTTP Response, including status, headers, and body."""

    status = ''
    """The HTTP Status-Code and Reason-Phrase."""

    header_list = []
    """
    A list of the HTTP response headers as (name, value) tuples.
    In general, you should use response.headers (a dict) instead. This
    attribute is generated from response.headers and is not valid until
    after the finalize phase."""

    headers = httputil.HeaderMap()
    """
    A dict-like object containing the response headers. Keys are header
    names (in Title-Case format); however, you may get and set them in
    a case-insensitive manner. That is, headers['Content-Type'] and
    headers['content-type'] refer to the same value. Values are header
    values (decoded according to :rfc:`2047` if necessary).

    .. seealso:: classes :class:`HeaderMap`, :class:`HeaderElement`
    """

    cookie = SimpleCookie()
    """See help(Cookie)."""

    body = ResponseBody()
    """The body (entity) of the HTTP response."""

    time = None
    """The value of time.time() when created. Use in HTTP dates."""

    stream = False
    """If False, buffer the response body."""

    def __init__(self):
        self.status = None
        self.header_list = None
        self._body = []
        self.time = time.time()

        self.headers = httputil.HeaderMap()
        # Since we know all our keys are titled strings, we can
        # bypass HeaderMap.update and get a big speed boost.
        dict.update(self.headers, {
            'Content-Type': 'text/html',
            'Server': 'CherryPy/' + cherrypy.__version__,
            'Date': httputil.HTTPDate(self.time),
        })
        self.cookie = SimpleCookie()

    def collapse_body(self):
        """Collapse self.body to a single string; replace it and return it."""
        if isinstance(self.body, text_or_bytes):
            return self.body

        newbody = []
        for chunk in self.body:
            if six.PY3 and not isinstance(chunk, bytes):
                raise TypeError("Chunk %s is not of type 'bytes'." %
                                repr(chunk))
            newbody.append(chunk)
        newbody = b''.join(newbody)

        self.body = newbody
        return newbody

    def finalize(self):
        """Transform headers (and cookies) into self.header_list. (Core)"""
        try:
            code, reason, _ = httputil.valid_status(self.status)
        except ValueError:
            raise cherrypy.HTTPError(500, sys.exc_info()[1].args[0])

        headers = self.headers

        self.status = '%s %s' % (code, reason)
        self.output_status = ntob(str(code), 'ascii') + \
            b' ' + headers.encode(reason)

        if self.stream:
            # The upshot: wsgiserver will chunk the response if
            # you pop Content-Length (or set it explicitly to None).
            # Note that lib.static sets C-L to the file's st_size.
            if dict.get(headers, 'Content-Length') is None:
                dict.pop(headers, 'Content-Length', None)
        elif code < 200 or code in (204, 205, 304):
            # "All 1xx (informational), 204 (no content),
            # and 304 (not modified) responses MUST NOT
            # include a message-body."
            dict.pop(headers, 'Content-Length', None)
            self.body = b''
        else:
            # Responses which are not streamed should have a Content-Length,
            # but allow user code to set Content-Length if desired.
            if dict.get(headers, 'Content-Length') is None:
                content = self.collapse_body()
                dict.__setitem__(headers, 'Content-Length', len(content))
#.........这里部分代码省略.........
开发者ID:Southpaw-TACTIC,项目名称:TACTIC,代码行数:103,代码来源:_cprequest.py

示例8: update_cookies

# 需要导入模块: from six.moves.http_cookies import SimpleCookie [as 别名]
# 或者: from six.moves.http_cookies.SimpleCookie import output [as 别名]
def update_cookies(base_value, cookies):
    cookie = SimpleCookie(base_value)
    for k, v in cookies.items():
        cookie[k] = v
    return str(cookie.output(header='', sep=';').lstrip())
开发者ID:eliangcs,项目名称:http-prompt,代码行数:7,代码来源:cli.py


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