From: Ben Darnell Date: Tue, 20 Jul 2010 02:39:42 +0000 (-0700) Subject: When no json library is found, don't throw an exception unless X-Git-Tag: v1.0.0~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad104ffb412dbbf66da0bb67d5e48d8907a7b17c;p=thirdparty%2Ftornado.git When no json library is found, don't throw an exception unless json functionality is used, to make the simplejson dependency optional for python 2.5 users. --- diff --git a/tornado/escape.py b/tornado/escape.py index af99f52fe..8852ca295 100644 --- a/tornado/escape.py +++ b/tornado/escape.py @@ -21,6 +21,8 @@ import re import xml.sax.saxutils import urllib +# json module is in the standard library as of python 2.6; fall back to +# simplejson if present for older versions. try: import json assert hasattr(json, "loads") and hasattr(json, "dumps") @@ -38,8 +40,11 @@ except: _json_decode = lambda s: simplejson.loads(_unicode(s)) _json_encode = lambda v: simplejson.dumps(v) except ImportError: - raise Exception("A JSON parser is required, e.g., simplejson at " - "http://pypi.python.org/pypi/simplejson/") + def _json_decode(s): + raise NotImplementedError( + "A JSON parser is required, e.g., simplejson at " + "http://pypi.python.org/pypi/simplejson/") + _json_encode = _json_decode def xhtml_escape(value):