Browse Source

Slightly faster _tojson_filter.

pull/1638/head
florentx 15 years ago
parent
commit
75057bb411
  1. 15
      flask.py

15
flask.py

@ -49,8 +49,7 @@ except (ImportError, AttributeError):
# figure out if simplejson escapes slashes. This behaviour was changed # figure out if simplejson escapes slashes. This behaviour was changed
# from one version to another without reason. # from one version to another without reason.
if json_available: _json_escapes_slashes = json_available and '\\/' in json.dumps('/')
_json_escapes_slashes = '\\/' in json.dumps('/')
class Request(RequestBase): class Request(RequestBase):
@ -273,14 +272,14 @@ def _get_package_path(name):
return os.getcwd() return os.getcwd()
def _tojson_filter(string, *args, **kwargs): if not _json_escapes_slashes:
"""Calls dumps for the template engine, escaping Slashes properly.""" def _tojson_filter(string, *args, **kwargs):
"""Calls dumps for the template engine, escaping slashes properly."""
if __debug__: if __debug__:
_assert_have_json() _assert_have_json()
rv = json.dumps(string, *args, **kwargs) return json.dumps(string, *args, **kwargs).replace('/', '\\/')
if not _json_escapes_slashes: else:
rv = rv.replace('/', '\\/') _tojson_filter = json.dumps
return rv
class Flask(object): class Flask(object):

Loading…
Cancel
Save