Show More
@@ -129,15 +129,18 b' def xmlescape(text):' | |||
|
129 | 129 | ('\r', '\\r'), ('\f', '\\f'), ('\b', '\\b'), |
|
130 | 130 | ] |
|
131 | 131 | |
|
132 | def jsonescape(s): | |
|
133 | for k, v in _escapes: | |
|
134 | s = s.replace(k, v) | |
|
135 | return s | |
|
136 | ||
|
132 | 137 | def json(obj): |
|
133 | 138 | if obj is None or obj is False or obj is True: |
|
134 | 139 | return {None: 'null', False: 'false', True: 'true'}[obj] |
|
135 | 140 | elif isinstance(obj, int) or isinstance(obj, float): |
|
136 | 141 | return str(obj) |
|
137 | 142 | elif isinstance(obj, str): |
|
138 | for k, v in _escapes: | |
|
139 | obj = obj.replace(k, v) | |
|
140 | return '"%s"' % obj | |
|
143 | return '"%s"' % jsonescape(obj) | |
|
141 | 144 | elif isinstance(obj, unicode): |
|
142 | 145 | return json(obj.encode('utf-8')) |
|
143 | 146 | elif hasattr(obj, 'keys'): |
@@ -169,6 +172,8 b' filters = {' | |||
|
169 | 172 | "hgdate": lambda x: "%d %d" % x, |
|
170 | 173 | "isodate": lambda x: util.datestr(x, '%Y-%m-%d %H:%M %1%2'), |
|
171 | 174 | "isodatesec": lambda x: util.datestr(x, '%Y-%m-%d %H:%M:%S %1%2'), |
|
175 | "json": json, | |
|
176 | "jsonescape": jsonescape, | |
|
172 | 177 | "obfuscate": obfuscate, |
|
173 | 178 | "permissions": permissions, |
|
174 | 179 | "person": person, |
@@ -182,5 +187,4 b' filters = {' | |||
|
182 | 187 | "user": lambda x: util.shortuser(x), |
|
183 | 188 | "stringescape": lambda x: x.encode('string_escape'), |
|
184 | 189 | "xmlescape": xmlescape, |
|
185 | "json": json, | |
|
186 | 190 | } |
General Comments 0
You need to be logged in to leave comments.
Login now