Created
June 22, 2012 20:23
-
-
Save jzempel/2974967 to your computer and use it in GitHub Desktop.
Flask and Flask-Babel Exception
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import session | |
from flask.ext.babel import lazy_gettext | |
from traceback import format_exc | |
import os | |
import pickle | |
text = lazy_gettext('foo') | |
repr(text) # "lu'foo'" | |
text.value # u'foo' | |
text.__getattribute__('value') # u'foo' | |
pickle.dump(text, open('lazy.string', 'wb')) | |
text = pickle.load(open('lazy.string', 'rb')) | |
os.remove('lazy.string') | |
repr(text) # '<_LazyString broken>' | |
try: | |
text.value # Traceback ... RuntimeError: maximum recursion depth exceeded | |
except Exception: | |
# format_exc() | |
try: | |
text.__getattribute__('value') # Traceback ... RuntimeError: maximum recursion depth exceeded in cmp | |
except Exception: | |
pass # format_exc() | |
session['text'] = lazy_gettext('bar') | |
string = session.serialize() | |
cookie = session.unserialize(string, session.secret_key) | |
repr(cookie['text']) # '<_LazyString broken>' | |
try: | |
cookie['text'].value # Traceback ... RuntimeError: maximum recursion depth exceeded | |
except Exception: | |
# format_exc() | |
try: | |
cookie['text'].__getattribute__('value') # Traceback ... RuntimeError: maximum recursion depth exceeded in cmp | |
except Exception: | |
pass # format_exc() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment