Patchwork [6,of,7] templatefilters: drop old jsonescape() function

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 23, 2016, 3:45 p.m.
Message ID <484371c3f9c61fd2694a.1456242331@mimosa>
Download mbox | patch
Permalink /patch/13319/
State Accepted
Delegated to: Augie Fackler
Headers show

Comments

Yuya Nishihara - Feb. 23, 2016, 3:45 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1451209803 -32400
#      Sun Dec 27 18:50:03 2015 +0900
# Node ID 484371c3f9c61fd2694aae90b1c650dec203c596
# Parent  0a325e2f77abaee6f8c58ae61d6a502ef94497b0
templatefilters: drop old jsonescape() function

It's been superseded by encoding.jsonescape(paranoid=True).

Patch

diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
--- a/mercurial/templatefilters.py
+++ b/mercurial/templatefilters.py
@@ -215,23 +215,6 @@  def json(obj):
     else:
         raise TypeError('cannot encode type %s' % obj.__class__.__name__)
 
-def _uescape(c):
-    if 0x20 <= ord(c) < 0x80:
-        return c
-    else:
-        return '\\u%04x' % ord(c)
-
-_escapes = [
-    ('\\', '\\\\'), ('"', '\\"'), ('\t', '\\t'), ('\n', '\\n'),
-    ('\r', '\\r'), ('\f', '\\f'), ('\b', '\\b'),
-    ('<', '\\u003c'), ('>', '\\u003e'), ('\0', '\\u0000')
-]
-
-def jsonescape(s):
-    for k, v in _escapes:
-        s = s.replace(k, v)
-    return ''.join(_uescape(c) for c in s)
-
 def lower(text):
     """:lower: Any text. Converts the text to lowercase."""
     return encoding.lower(text)
diff --git a/tests/test-template-engine.t b/tests/test-template-engine.t
--- a/tests/test-template-engine.t
+++ b/tests/test-template-engine.t
@@ -44,17 +44,4 @@ 
   0 97e5f848f0936960273bbf75be6388cd0350a32b -1 0000000000000000000000000000000000000000
   -1 0000000000000000000000000000000000000000 -1 0000000000000000000000000000000000000000
 
-Fuzzing the unicode escaper to ensure it produces valid data
-
-#if hypothesis
-
-  >>> from hypothesishelpers import *
-  >>> import mercurial.templatefilters as tf
-  >>> import json
-  >>> @check(st.text().map(lambda s: s.encode('utf-8')))
-  ... def testtfescapeproducesvalidjson(text):
-  ...     json.loads('"' + tf.jsonescape(text) + '"')
-
-#endif
-
   $ cd ..