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


Python Cookie.BaseCookie方法代码示例

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


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

示例1: cookies

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import BaseCookie [as 别名]
def cookies(self):
        """A dictionary of Cookie.Morsel objects."""
        if not hasattr(self, "_cookies"):
            self._cookies = Cookie.BaseCookie()
            if "Cookie" in self.request.headers:
                try:
                    self._cookies.load(self.request.headers["Cookie"])
                except:
                    self.clear_all_cookies()
        return self._cookies 
开发者ID:omererdem,项目名称:honeything,代码行数:12,代码来源:web.py

示例2: set_cookie

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import BaseCookie [as 别名]
def set_cookie(self, name, value, domain=None, expires=None, path="/",
                   expires_days=None, **kwargs):
        """Sets the given cookie name/value with the given options.

        Additional keyword arguments are set on the Cookie.Morsel
        directly.
        See http://docs.python.org/library/cookie.html#morsel-objects
        for available attributes.
        """
        name = _utf8(name)
        value = _utf8(value)
        if re.search(r"[\x00-\x20]", name + value):
            # Don't let us accidentally inject bad stuff
            raise ValueError("Invalid cookie %r: %r" % (name, value))
        if not hasattr(self, "_new_cookies"):
            self._new_cookies = []
        new_cookie = Cookie.BaseCookie()
        self._new_cookies.append(new_cookie)
        new_cookie[name] = value
        if domain:
            new_cookie[name]["domain"] = domain
        if expires_days is not None and not expires:
            expires = datetime.datetime.utcnow() + datetime.timedelta(
                days=expires_days)
        if expires:
            timestamp = calendar.timegm(expires.utctimetuple())
            new_cookie[name]["expires"] = email.utils.formatdate(
                timestamp, localtime=False, usegmt=True)
        if path:
            new_cookie[name]["path"] = path
        for k, v in kwargs.iteritems():
            new_cookie[name][k] = v 
开发者ID:omererdem,项目名称:honeything,代码行数:34,代码来源:web.py

示例3: __init__

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import BaseCookie [as 别名]
def __init__(self, secret, input=None):
        self.secret = secret.encode('UTF-8')
        Cookie.BaseCookie.__init__(self, input) 
开发者ID:abdesslem,项目名称:malwareHunter,代码行数:5,代码来源:session.py

示例4: cookies

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import BaseCookie [as 别名]
def cookies(self):
        try:
            cookie = hcookies.BaseCookie()
            cookie.load(self.headers.get("cookie"))
            return cookie
        except Exception as e:
            return hcookies.BaseCookie() 
开发者ID:roglew,项目名称:pappy-proxy,代码行数:9,代码来源:repeater.py

示例5: set_cookies

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import BaseCookie [as 别名]
def set_cookies(self, c):
        cookie_pairs = []
        if isinstance(c, hcookies.BaseCookie()):
            # it's a basecookie
            for k in c:
                cookie_pairs.append('{}={}'.format(k, c[k].value))
        else:
            # it's a dictionary
            for k, v in c.items():
                cookie_pairs.append('{}={}'.format(k, v))
        header_str = '; '.join(cookie_pairs)
        self.headers.set("Cookie", header_str) 
开发者ID:roglew,项目名称:pappy-proxy,代码行数:14,代码来源:repeater.py

示例6: InfoPage

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import BaseCookie [as 别名]
def InfoPage(self, uri):
    """ Renders an information page with the POST endpoint and cookie flag.

    Args:
      uri: a string containing the request URI
    Returns:
      A string with the contents of the info page to be displayed
    """
    page = """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head>
<title>Bulk Loader</title>
</head><body>"""

    page += ('The bulk load endpoint is: <a href="%s">%s</a><br />\n' %
            (uri, uri))


    cookies = os.environ.get('HTTP_COOKIE', None)
    if cookies:
      cookie = Cookie.BaseCookie(cookies)




      for param in ['ACSID', 'dev_appserver_login']:
        value = cookie.get(param)
        if value:
          page += ("Pass this flag to the client: --cookie='%s=%s'\n" %
                   (param, value.value))
          break

    else:
      page += 'No cookie found!\n'

    page += '</body></html>'
    return page 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:40,代码来源:bulkload_deprecated.py

示例7: get_sid

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import BaseCookie [as 别名]
def get_sid(self, response):
        cookie = Cookie.BaseCookie(response.headers['Set-Cookie'])
        return cookie['sid'].value 
开发者ID:MLTSHP,项目名称:mltshp,代码行数:5,代码来源:base.py

示例8: get_cookie

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import BaseCookie [as 别名]
def get_cookie(self, name):
        cookies = self.headers.get('Cookie')
        if cookies:
            authcookie = BaseCookie(cookies).get(name)
            if authcookie:
                return authcookie.value
            else:
                return None
        else:
            return None


    # Log the error and complete the request with appropriate status 
开发者ID:linuxserver,项目名称:docker-ldap-auth,代码行数:15,代码来源:nginx-ldap-auth-daemon.py

示例9: do_request

# 需要导入模块: import Cookie [as 别名]
# 或者: from Cookie import BaseCookie [as 别名]
def do_request(self, req, status):
        """
        Executes the given request (``req``), with the expected
        ``status``.  Generally ``.get()`` and ``.post()`` are used
        instead.
        """
        if self.pre_request_hook:
            self.pre_request_hook(self)
        __tracebackhide__ = True
        if self.cookies:
            c = BaseCookie()
            for name, value in self.cookies.items():
                c[name] = value
            hc = '; '.join(['='.join([m.key, m.value]) for m in c.values()])
            req.environ['HTTP_COOKIE'] = hc
        req.environ['paste.testing'] = True
        req.environ['paste.testing_variables'] = {}
        app = lint.middleware(self.app)
        old_stdout = sys.stdout
        out = CaptureStdout(old_stdout)
        try:
            sys.stdout = out
            start_time = time.time()
            raise_on_wsgi_error = not req.expect_errors
            raw_res = wsgilib.raw_interactive(
                app, req.url,
                raise_on_wsgi_error=raise_on_wsgi_error,
                **req.environ)
            end_time = time.time()
        finally:
            sys.stdout = old_stdout
            sys.stderr.write(out.getvalue())
        res = self._make_response(raw_res, end_time - start_time)
        res.request = req
        for name, value in req.environ['paste.testing_variables'].items():
            if hasattr(res, name):
                raise ValueError(
                    "paste.testing_variables contains the variable %r, but "
                    "the response object already has an attribute by that "
                    "name" % name)
            setattr(res, name, value)
        if self.namespace is not None:
            self.namespace['res'] = res
        if not req.expect_errors:
            self._check_status(status, res)
            self._check_errors(res)
        res.cookies_set = {}
        for header in res.all_headers('set-cookie'):
            c = BaseCookie(header)
            for key, morsel in c.items():
                self.cookies[key] = morsel.value
                res.cookies_set[key] = morsel.value
        if self.post_request_hook:
            self.post_request_hook(self)
        if self.namespace is None:
            # It's annoying to return the response in doctests, as it'll
            # be printed, so we only return it is we couldn't assign
            # it anywhere
            return res 
开发者ID:linuxscout,项目名称:mishkal,代码行数:61,代码来源:fixture.py


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