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