Skip to content

Commit f04afda

Browse files
authored
Merge pull request #104 from der-michik/master
Allow unpickling of LazyStrings
2 parents 54296ab + 92788da commit f04afda

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

flask_babel/speaklater.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ def __init__(self, func, *args, **kwargs):
99
self._kwargs = kwargs
1010

1111
def __getattr__(self, attr):
12+
if attr == "__setstate__":
13+
raise AttributeError(attr)
1214
string = text_type(self)
1315
if hasattr(string, attr):
1416
return getattr(string, attr)

tests/tests.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import os
66
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
77

8+
import pickle
9+
810
import unittest
911
from decimal import Decimal
1012
import flask
@@ -60,6 +62,13 @@ def test_lazy_old_style_formatting(self):
6062
lazy_string = lazy_gettext(u'test')
6163
assert u'Hello %s' % lazy_string == u'Hello test'
6264

65+
def test_lazy_pickling(self):
66+
lazy_string = lazy_gettext(u'Foo')
67+
pickled = pickle.dumps(lazy_string)
68+
unpickled = pickle.loads(pickled)
69+
70+
assert unpickled == lazy_string
71+
6372

6473
class DateFormattingTestCase(unittest.TestCase):
6574

0 commit comments

Comments
 (0)