本文整理匯總了Python中werkzeug.http.parse_cookie方法的典型用法代碼示例。如果您正苦於以下問題:Python http.parse_cookie方法的具體用法?Python http.parse_cookie怎麽用?Python http.parse_cookie使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類werkzeug.http
的用法示例。
在下文中一共展示了http.parse_cookie方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: check_pin_trust
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import parse_cookie [as 別名]
def check_pin_trust(self, environ):
"""Checks if the request passed the pin test. This returns `True` if the
request is trusted on a pin/cookie basis and returns `False` if not.
Additionally if the cookie's stored pin hash is wrong it will return
`None` so that appropriate action can be taken.
"""
if self.pin is None:
return True
val = parse_cookie(environ).get(self.pin_cookie_name)
if not val or '|' not in val:
return False
ts, pin_hash = val.split('|', 1)
if not ts.isdigit():
return False
if pin_hash != hash_pin(self.pin):
return None
return (time.time() - PIN_TIME) < int(ts)
示例2: get_session
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import parse_cookie [as 別名]
def get_session(response):
""" Return session cookie contents.
This a base64 encoded json.
Returns a dict
"""
# Alas seems like if there are multiple set-cookie headers - we are on our own
for index, h in enumerate(response.headers):
if h[0] == "Set-Cookie":
cookie = parse_cookie(response.headers[index][1])
encoded_cookie = cookie.get("session", None)
if encoded_cookie:
serializer = URLSafeTimedSerializer(
"secret", serializer=TaggedJSONSerializer()
)
val = serializer.loads_unsafe(encoded_cookie)
return val[1]
示例3: _get_auth_cookies
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import parse_cookie [as 別名]
def _get_auth_cookies() -> List["TypeConversionDict[Any, Any]"]:
# Login with the user specified to get the reports
with app.test_request_context():
user = security_manager.find_user(config["EMAIL_REPORTS_USER"])
login_user(user)
# A mock response object to get the cookie information from
response = Response()
app.session_interface.save_session(app, session, response)
cookies = []
# Set the cookies in the driver
for name, value in response.headers:
if name.lower() == "set-cookie":
cookie = parse_cookie(value)
cookies.append(cookie["session"])
return cookies
示例4: get_auth_cookies
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import parse_cookie [as 別名]
def get_auth_cookies(user: "User") -> List[Dict[Any, Any]]:
# Login with the user specified to get the reports
with current_app.test_request_context("/login"):
login_user(user)
# A mock response object to get the cookie information from
response = Response()
current_app.session_interface.save_session(current_app, session, response)
cookies = []
# Set the cookies in the driver
for name, value in response.headers:
if name.lower() == "set-cookie":
cookie = parse_cookie(value)
cookies.append(cookie["session"])
return cookies
示例5: test_cookies
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import parse_cookie [as 別名]
def test_cookies(self):
self.assert_strict_equal(
dict(http.parse_cookie('dismiss-top=6; CP=null*; PHPSESSID=0a539d42abc001cd'
'c762809248d4beed; a=42; b="\\\";"')),
{
'CP': u'null*',
'PHPSESSID': u'0a539d42abc001cdc762809248d4beed',
'a': u'42',
'dismiss-top': u'6',
'b': u'\";'
}
)
self.assert_strict_equal(
set(http.dump_cookie('foo', 'bar baz blub', 360, httponly=True,
sync_expires=False).split(u'; ')),
set([u'HttpOnly', u'Max-Age=360', u'Path=/', u'foo="bar baz blub"'])
)
self.assert_strict_equal(dict(http.parse_cookie('fo234{=bar; blub=Blah')),
{'fo234{': u'bar', 'blub': u'Blah'})
示例6: post_process
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import parse_cookie [as 別名]
def post_process(self, environ, headers):
user = User.get_current()
if not user:
cookies = http.parse_cookie(environ)
if self.name in cookies:
raw = http.dump_cookie(self.name, "", expires=1)
headers.append((utils.to_native("Set-Cookie"), raw))
return
cookie = SecureCookie(
{"uid": user.id, "session_token": user.get_session_token()}, self.secret
)
raw = http.dump_cookie(
self.name, cookie.serialize(), expires=self.expires, max_age=self.max_age
)
headers.append((utils.to_native("Set-Cookie"), raw))
示例7: is_trusted
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import parse_cookie [as 別名]
def is_trusted(self, environ):
"""Checks if the request passed the pin test."""
if self.pin is None:
return True
ts = parse_cookie(environ).get(self.pin_cookie_name, type=int)
if ts is None:
return False
return (time.time() - PIN_TIME) < ts
示例8: test_cookie_quoting
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import parse_cookie [as 別名]
def test_cookie_quoting(self):
val = http.dump_cookie("foo", "?foo")
self.assert_strict_equal(val, 'foo="?foo"; Path=/')
self.assert_strict_equal(dict(http.parse_cookie(val)), {'foo': u'?foo'})
self.assert_strict_equal(dict(http.parse_cookie(r'foo="foo\054bar"')),
{'foo': u'foo,bar'})
示例9: test_cookie_unicode_dumping
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import parse_cookie [as 別名]
def test_cookie_unicode_dumping(self):
val = http.dump_cookie('foo', u'\N{SNOWMAN}')
h = datastructures.Headers()
h.add('Set-Cookie', val)
self.assert_equal(h['Set-Cookie'], 'foo="\\342\\230\\203"; Path=/')
cookies = http.parse_cookie(h['Set-Cookie'])
self.assert_equal(cookies['foo'], u'\N{SNOWMAN}')
示例10: test_cookie_unicode_keys
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import parse_cookie [as 別名]
def test_cookie_unicode_keys(self):
# Yes, this is technically against the spec but happens
val = http.dump_cookie(u'fö', u'fö')
self.assert_equal(val, wsgi_encoding_dance(u'fö="f\\303\\266"; Path=/', 'utf-8'))
cookies = http.parse_cookie(val)
self.assert_equal(cookies[u'fö'], u'fö')
示例11: test_cookie_unicode_parsing
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import parse_cookie [as 別名]
def test_cookie_unicode_parsing(self):
# This is actually a correct test. This is what is being submitted
# by firefox if you set an unicode cookie and we get the cookie sent
# in on Python 3 under PEP 3333.
cookies = http.parse_cookie(u'fö=fö')
self.assert_equal(cookies[u'fö'], u'fö')