Various improvements in regards to the itsdangerous usage, bumped to 0.17
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent a4977cf · Browse files · 2 files·+41 added−16 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+41 added−16 removed
- other:+41 added−16 removed
Provenance
- Commit
fe85970- Tree
f3ba769- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
a4977cf
2 files changed+41 added−16 removed
modified:flask/sessions.py+40 added-15 removed
8 unmodified lines9 :copyright: (c) 2011 by Armin Ronacher.10 :license: BSD, see LICENSE for more details.11 """12 13+import hashlib14 from datetime import datetime15 from werkzeug.http import http_date, parse_date16 from werkzeug.datastructures import CallbackDict17 from .helpers import json36 unmodified lines54 55 def dumps(self, value):56 def _tag(value):57 if isinstance(value, tuple):57- return {'##t': [_tag(x) for x in value]}58+ return {' t': [_tag(x) for x in value]}59 elif callable(getattr(value, '__html__', None)):59- return {'##m': unicode(value.__html__())}60+ return {' m': unicode(value.__html__())}61 elif isinstance(value, list):62 return [_tag(x) for x in value]63 elif isinstance(value, datetime):63- return {'##d': http_date(value)}64+ return {' d': http_date(value)}65 elif isinstance(value, dict):66 return dict((k, _tag(v)) for k, v in value.iteritems())67 return value68 return json.dumps(_tag(value), separators=(',', ':'))2 unmodified lines71 def object_hook(obj):72 if len(obj) != 1:73 return obj74 the_key, the_value = obj.iteritems().next()74- if the_key == '##t':75+ if the_key == ' t':76 return tuple(the_value)76- elif the_key == '##m':77+ elif the_key == ' m':78 return Markup(the_value)78- elif the_key == '##d':79+ elif the_key == ' d':80 return parse_date(the_value)81 return obj82 return json.loads(value, object_hook=object_hook)83 61 unmodified lines145 #: :meth:`is_null_session` method will perform a typecheck against146 #: this type.147 null_session_class = NullSession148 149+ #: A flag that indicates if the session interface is pickle based.150+ #: This can be used by flask extensions to make a decision in regards151+ #: to how to deal with the session object.152+ #:153+ #: .. versionadded:: 0.10154+ pickle_based = False155+156 def make_null_session(self, app):157 """Creates a null session which acts as a replacement object if the158 real session support could not be loaded due to a configuration159 error. This mainly aids the user experience because the job of the72 unmodified lines232 raise NotImplementedError()233 234 235 class SecureCookieSessionInterface(SessionInterface):236+ """The default session interface that stores sessions in signed cookies237+ through the :mod:`itsdangerous` module.238+ """239+ #: the salt that should be applied on top of the secret key for the240+ #: signing of cookie based sessions.241 salt = 'cookie-session'229- session_class = SecureCookieSession242+ #: the hash function to use for the signature. The default is sha1243+ digest_method = staticmethod(hashlib.sha1)244+ #: the name of the itsdangerous supported key derivation. The default245+ #: is hmac.246+ key_derivation = 'hmac'247+ #: A python serializer for the payload. The default is a compact248+ #: JSON derived serializer with support for some extra Python types249+ #: such as datetime objects or tuples.250 serializer = session_json_serializer251+ session_class = SecureCookieSession252 232- def get_serializer(self, app):253+ def get_signing_serializer(self, app):254 if not app.secret_key:255 return None235- return URLSafeTimedSerializer(app.secret_key,236- salt=self.salt,237- serializer=self.serializer)256+ signer_kwargs = dict(257+ key_derivation=self.key_derivation,258+ digest_method=self.digest_method259+ )260+ return URLSafeTimedSerializer(app.secret_key, salt=self.salt,261+ serializer=self.serializer,262+ signer_kwargs=signer_kwargs)263 264 def open_session(self, app, request):240- s = self.get_serializer(app)265+ s = self.get_signing_serializer(app)266 if s is None:267 return None268 val = request.cookies.get(app.session_cookie_name)269 if not val:7 unmodified lines277 278 def save_session(self, app, session, response):279 domain = self.get_cookie_domain(app)280 path = self.get_cookie_path(app)256- httponly = self.get_cookie_httponly(app)257- secure = self.get_cookie_secure(app)281 if not session:282 if session.modified:283 response.delete_cookie(app.session_cookie_name,284 domain=domain, path=path)285 return286+ httponly = self.get_cookie_httponly(app)287+ secure = self.get_cookie_secure(app)288 expires = self.get_expiration_time(app, session)264- val = self.get_serializer(app).dumps(dict(session))289+ val = self.get_signing_serializer(app).dumps(dict(session))290 response.set_cookie(app.session_cookie_name, val,291 expires=expires, httponly=httponly,292 domain=domain, path=path, secure=secure)modified:setup.py+1 added-1 removed
90 unmodified lines91 platforms='any',92 install_requires=[93 'Werkzeug>=0.7',94 'Jinja2>=2.4',95- 'itsdangerous>=0.16'95+ 'itsdangerous>=0.17'96 ],97 classifiers=[98 'Development Status :: 4 - Beta',99 'Environment :: Web Environment',13 unmodified lines