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


Python Cookie.SimpleCookie方法代码示例

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


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

示例1: get_user_info

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import SimpleCookie [as 别名]
def get_user_info(http_cookie, cookie_name=_COOKIE_NAME):
  """Gets the requestor's user info from an HTTP Cookie header.

  Args:
    http_cookie: The value of the 'Cookie' HTTP request header.
    cookie_name: The name of the cookie that stores the user info.

  Returns:
    A tuple (email, admin, user_id) where:
      email: The user's email address, if any.
      admin: True if the user is an admin; False otherwise.
      user_id: The user ID, if any.
  """
  try:
    cookie = Cookie.SimpleCookie(http_cookie)
  except Cookie.CookieError:
    return '', False, ''

  cookie_dict = dict((k, v.value) for k, v in cookie.iteritems())
  return _get_user_info_from_dict(cookie_dict, cookie_name) 
开发者ID:elsigh,项目名称:browserscope,代码行数:22,代码来源:login.py

示例2: _set_user_info_cookie

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import SimpleCookie [as 别名]
def _set_user_info_cookie(email, admin, cookie_name=_COOKIE_NAME):
  """Creates a cookie to set the user information for the requestor.

  Args:
    email: The email to set for the user.
    admin: True if the user should be admin; False otherwise.
    cookie_name: The name of the cookie that stores the user info.

  Returns:
    Set-Cookie value for setting the user info of the requestor.
  """
  cookie_value = _create_cookie_data(email, admin)
  cookie = Cookie.SimpleCookie()
  cookie[cookie_name] = cookie_value
  cookie[cookie_name]['path'] = '/'
  return cookie[cookie_name].OutputString() 
开发者ID:elsigh,项目名称:browserscope,代码行数:18,代码来源:login.py

示例3: GetUserInfo

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import SimpleCookie [as 别名]
def GetUserInfo(http_cookie, cookie_name=COOKIE_NAME):
  """Get the requestor's user info from the HTTP cookie in the CGI environment.

  Args:
    http_cookie: Value of the HTTP_COOKIE environment variable.
    cookie_name: Name of the cookie that stores the user info.

  Returns:
    Tuple (email, admin, user_id) where:
      email: The user's email address, if any.
      admin: True if the user is an admin; False otherwise.
      user_id: The user ID, if any.
  """
  try:
    cookie = Cookie.SimpleCookie(http_cookie)
  except Cookie.CookieError:
    return '', False, ''

  cookie_value = ''
  if cookie_name in cookie:
    cookie_value = cookie[cookie_name].value

  email, admin, user_id = (cookie_value.split(':') + ['', '', ''])[:3]
  return email, (admin == 'True'), user_id 
开发者ID:elsigh,项目名称:browserscope,代码行数:26,代码来源:dev_appserver_login.py

示例4: __init__

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import SimpleCookie [as 别名]
def __init__(self, content='', mimetype=None, code=200):
        self._iter = None
        self._is_str_iter = True

        self.content = content
        self.headers = HeaderDict()
        self.cookies = SimpleCookie()
        self.status_code = code

        defaults = self.defaults._current_obj()
        if not mimetype:
            mimetype = defaults.get('content_type', 'text/html')
            charset = defaults.get('charset')
            if charset:
                mimetype = '%s; charset=%s' % (mimetype, charset)
        self.headers.update(defaults.get('headers', {}))
        self.headers['Content-Type'] = mimetype
        self.errors = defaults.get('errors', 'strict') 
开发者ID:linuxscout,项目名称:mishkal,代码行数:20,代码来源:wsgiwrappers.py

示例5: get_cookies

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import SimpleCookie [as 别名]
def get_cookies(environ):
    """
    Gets a cookie object (which is a dictionary-like object) from the
    request environment; caches this value in case get_cookies is
    called again for the same request.

    """
    header = environ.get('HTTP_COOKIE', '')
    if environ.has_key('paste.cookies'):
        cookies, check_header = environ['paste.cookies']
        if check_header == header:
            return cookies
    cookies = SimpleCookie()
    cookies.load(header)
    environ['paste.cookies'] = (cookies, header)
    return cookies 
开发者ID:linuxscout,项目名称:mishkal,代码行数:18,代码来源:request.py

示例6: get_cookie_dict

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import SimpleCookie [as 别名]
def get_cookie_dict(environ):
    """Return a *plain* dictionary of cookies as found in the request.

    Unlike ``get_cookies`` this returns a dictionary, not a
    ``SimpleCookie`` object.  For incoming cookies a dictionary fully
    represents the information.  Like ``get_cookies`` this caches and
    checks the cache.
    """
    header = environ.get('HTTP_COOKIE')
    if not header:
        return {}
    if environ.has_key('paste.cookies.dict'):
        cookies, check_header = environ['paste.cookies.dict']
        if check_header == header:
            return cookies
    cookies = SimpleCookie()
    cookies.load(header)
    result = {}
    for name in cookies:
        result[name] = cookies[name].value
    environ['paste.cookies.dict'] = (result, header)
    return result 
开发者ID:linuxscout,项目名称:mishkal,代码行数:24,代码来源:request.py

示例7: _parse_cookies

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import SimpleCookie [as 别名]
def _parse_cookies(cookie_str, dictionary):
    """Tries to parse any key-value pairs of cookies in a string,
    then updates the the dictionary with any key-value pairs found.

    **Example**::
        dictionary = {}
        _parse_cookies('my=value', dictionary)
        # Now the following is True
        dictionary['my'] == 'value'

    :param cookie_str: A string containing "key=value" pairs from an HTTP "Set-Cookie" header.
    :type cookie_str: ``str``
    :param dictionary: A dictionary to update with any found key-value pairs.
    :type dictionary: ``dict``
    """
    parsed_cookie = Cookie.SimpleCookie(cookie_str)
    for cookie in parsed_cookie.values():
        dictionary[cookie.key] = cookie.coded_value 
开发者ID:DanielSchwartz1,项目名称:SplunkForPCAP,代码行数:20,代码来源:binding.py

示例8: _inject_cookie_message

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import SimpleCookie [as 别名]
def _inject_cookie_message(self, msg):
        """Inject the first message, which is the document cookie,
        for authentication."""
        if not PY3 and isinstance(msg, unicode):
            # Cookie constructor doesn't accept unicode strings
            # under Python 2.x for some reason
            msg = msg.encode('utf8', 'replace')
        try:
            identity, msg = msg.split(':', 1)
            self.session.session = cast_unicode(identity, 'ascii')
        except Exception:
            logging.error("First ws message didn't have the form 'identity:[cookie]' - %r", msg)
        
        try:
            self.request._cookies = Cookie.SimpleCookie(msg)
        except:
            self.log.warn("couldn't parse cookie string: %s",msg, exc_info=True) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:zmqhandlers.py

示例9: start_response_decorated

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import SimpleCookie [as 别名]
def start_response_decorated(start_response_decorated):
    def inner(status, headers):
        headers_obj = IOrderedDict(headers)
        if 'Set-Cookie' in headers_obj and ', ' in headers_obj['Set-Cookie']:
            cookie = SimpleCookie()
            cookie.load(headers_obj['Set-Cookie'])
            del headers_obj['Set-Cookie']
            headers_list = headers_obj.items()
            for key in ("auctions_loggedin", "auction_session"):
                if key in cookie:
                    headers_list += [
                        ('Set-Cookie', cookie[key].output(header="").lstrip().rstrip(','))
                    ]
            headers = headers_list
        return start_response_decorated(status, headers)
    return inner 
开发者ID:openprocurement,项目名称:openprocurement.auction,代码行数:18,代码来源:proxy.py

示例10: cookies

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import SimpleCookie [as 别名]
def cookies(self):
        """A dictionary of Cookie.Morsel objects."""
        if not hasattr(self, "_cookies"):
            self._cookies = Cookie.SimpleCookie()
            if "Cookie" in self.headers:
                try:
                    parsed = parse_cookie(self.headers["Cookie"])
                except Exception:
                    pass
                else:
                    for k, v in parsed.items():
                        try:
                            self._cookies[k] = v
                        except Exception:
                            # SimpleCookie imposes some restrictions on keys;
                            # parse_cookie does not. Discard any cookies
                            # with disallowed keys.
                            pass
        return self._cookies 
开发者ID:tp4a,项目名称:teleport,代码行数:21,代码来源:httputil.py

示例11: _clear_user_info_cookie

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import SimpleCookie [as 别名]
def _clear_user_info_cookie(cookie_name=_COOKIE_NAME):
  """Clears the user info cookie from the requestor, logging them out.

  Args:
    cookie_name: The name of the cookie that stores the user info.

  Returns:
    A Set-Cookie value for clearing the user info of the requestor.
  """
  cookie = Cookie.SimpleCookie()
  cookie[cookie_name] = ''
  cookie[cookie_name]['path'] = '/'
  cookie[cookie_name]['max-age'] = '0'
  return cookie[cookie_name].OutputString() 
开发者ID:elsigh,项目名称:browserscope,代码行数:16,代码来源:login.py

示例12: ClearUserInfoCookie

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import SimpleCookie [as 别名]
def ClearUserInfoCookie(cookie_name=COOKIE_NAME):
  """Clears the user info cookie from the requestor, logging them out.

  Args:
    cookie_name: Name of the cookie that stores the user info.

  Returns:
    'Set-Cookie' header for clearing the user info of the requestor.
  """
  set_cookie = Cookie.SimpleCookie()
  set_cookie[cookie_name] = ''
  set_cookie[cookie_name]['path'] = '/'
  set_cookie[cookie_name]['max-age'] = '0'
  return '%s\r\n' % set_cookie 
开发者ID:elsigh,项目名称:browserscope,代码行数:16,代码来源:dev_appserver_login.py

示例13: cookie

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import SimpleCookie [as 别名]
def cookie(self):
        c = Cookie.SimpleCookie()
        c[self.cookie_name] = self.cookie_value().encode('base64').strip().replace('\n', '')
        c[self.cookie_name]['path'] = '/'
        if self.secure:
            c[self.cookie_name]['secure'] = 'true'
        return c 
开发者ID:linuxscout,项目名称:mishkal,代码行数:9,代码来源:auth_tkt.py

示例14: set_cookie_header

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import SimpleCookie [as 别名]
def set_cookie_header(self):
        c = SimpleCookie()
        c[self.cookie_name] = self.sid
        c[self.cookie_name]['path'] = '/'

        gmt_expiration_time = time.gmtime(time.time() + (self.expiration * 60))
        c[self.cookie_name]['expires'] = time.strftime("%a, %d-%b-%Y %H:%M:%S GMT", gmt_expiration_time)

        name, value = str(c).split(': ', 1)
        return (name, value) 
开发者ID:linuxscout,项目名称:mishkal,代码行数:12,代码来源:session.py

示例15: cookies

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import SimpleCookie [as 别名]
def cookies(self):
        """ Cookies parsed into a :class:`FormsDict`. Signed cookies are NOT
            decoded. Use :meth:`get_cookie` if you expect signed cookies. """
        cookies = SimpleCookie(self.environ.get('HTTP_COOKIE','')).values()
        return FormsDict((c.key, c.value) for c in cookies) 
开发者ID:Autodesk,项目名称:arnold-usd,代码行数:7,代码来源:__init__.py


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