Skip to content
Myr

Added better error reporting for unicode errors in sessions

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 8339cb3 · Browse files · 2 files+17 added−0 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+17 added−0 removed

  • other:+17 added−0 removed

2 files+17 added−0 removed

modified:flask/debughelpers.py+6 added
8 unmodified lines
9 :license: BSD, see LICENSE for more details.10"""111213class UnexpectedUnicodeError(AssertionError, UnicodeError):14 """Raised in places where we want some better error reporting for15 unexpected unicode or binary data.16 """171819class DebugFilesKeyError(KeyError, AssertionError):20 """Raised from request.files during debugging. The idea is that it can21 provide a better error message than just a generic KeyError/BadRequest.22 """
63 unmodified lines
modified:flask/sessions.py+11 added
64 unmodified lines
65 elif isinstance(value, datetime):66 return {' d': http_date(value)}67 elif isinstance(value, dict):68 return dict((k, _tag(v)) for k, v in value.iteritems())69 elif isinstance(value, str):70 try:71 return unicode(value)72 except UnicodeError:73 raise UnexpectedUnicodeError(u'A byte string with '74 u'non-ASCII data was passed to the session system '75 u'which can only store unicode strings. Consider '76 u'base64 encoding your string (String was %r)' % value)77 return value78 return json.dumps(_tag(value), separators=(',', ':'))7980 def loads(self, value):
218 unmodified lines
299 val = self.get_signing_serializer(app).dumps(dict(session))300 response.set_cookie(app.session_cookie_name, val,301 expires=expires, httponly=httponly,302 domain=domain, path=path, secure=secure)303304305from flask.debughelpers import UnexpectedUnicodeError