forked from orbit-oss/flask
Added support for bytes in sessions back
This commit is contained in:
parent
c502dfbbfb
commit
58ad83f37c
3 changed files with 11 additions and 0 deletions
3
CHANGES
3
CHANGES
|
|
@ -12,6 +12,9 @@ Pending bugfix release.
|
|||
made the filter not work properly in HTML attributes. Now it's
|
||||
possible to use that filter in single quoted attributes. This should
|
||||
make using that filter with angular.js easier.
|
||||
- Added support for byte strings back to the session system. This broke
|
||||
compatibility with the common case of people putting binary data for
|
||||
token verification into the session.
|
||||
|
||||
Version 0.10
|
||||
------------
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
import uuid
|
||||
import hashlib
|
||||
from base64 import b64encode, b64decode
|
||||
from datetime import datetime
|
||||
from werkzeug.http import http_date, parse_date
|
||||
from werkzeug.datastructures import CallbackDict
|
||||
|
|
@ -62,6 +63,8 @@ class TaggedJSONSerializer(object):
|
|||
return {' t': [_tag(x) for x in value]}
|
||||
elif isinstance(value, uuid.UUID):
|
||||
return {' u': value.hex}
|
||||
elif isinstance(value, bytes):
|
||||
return {' b': b64encode(value).decode('ascii')}
|
||||
elif callable(getattr(value, '__html__', None)):
|
||||
return {' m': text_type(value.__html__())}
|
||||
elif isinstance(value, list):
|
||||
|
|
@ -90,6 +93,8 @@ class TaggedJSONSerializer(object):
|
|||
return tuple(the_value)
|
||||
elif the_key == ' u':
|
||||
return uuid.UUID(the_value)
|
||||
elif the_key == ' b':
|
||||
return b64decode(the_value)
|
||||
elif the_key == ' m':
|
||||
return Markup(the_value)
|
||||
elif the_key == ' d':
|
||||
|
|
|
|||
|
|
@ -326,6 +326,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
flask.session['m'] = flask.Markup('Hello!')
|
||||
flask.session['u'] = the_uuid
|
||||
flask.session['dt'] = now
|
||||
flask.session['b'] = b'\xff'
|
||||
flask.session['t'] = (1, 2, 3)
|
||||
return response
|
||||
|
||||
|
|
@ -340,6 +341,8 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
self.assert_equal(type(rv['m']), flask.Markup)
|
||||
self.assert_equal(rv['dt'], now)
|
||||
self.assert_equal(rv['u'], the_uuid)
|
||||
self.assert_equal(rv['b'], b'\xff')
|
||||
self.assert_equal(type(rv['b']), bytes)
|
||||
self.assert_equal(rv['t'], (1, 2, 3))
|
||||
|
||||
def test_flashes(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue