Mercurial > genshi > genshi-test
comparison genshi/util.py @ 859:fbe34d12acde
More bits of 2to3 related cleanup.
author | cmlenz |
---|---|
date | Thu, 12 Nov 2009 17:01:52 +0000 |
parents | 24733a5854d9 |
children | c5faa881d87f |
comparison
equal
deleted
inserted
replaced
858:df860bdad9ca | 859:fbe34d12acde |
---|---|
11 # individuals. For the exact contribution history, see the revision | 11 # individuals. For the exact contribution history, see the revision |
12 # history and logs, available at http://genshi.edgewall.org/log/. | 12 # history and logs, available at http://genshi.edgewall.org/log/. |
13 | 13 |
14 """Various utility classes and functions.""" | 14 """Various utility classes and functions.""" |
15 | 15 |
16 try: | 16 import htmlentitydefs as entities |
17 import htmlentitydefs as entities | |
18 except ImportError: | |
19 from html import entities | |
20 import re | 17 import re |
21 | 18 |
22 __docformat__ = 'restructuredtext en' | 19 __docformat__ = 'restructuredtext en' |
23 | 20 |
24 | 21 |
249 """ | 246 """ |
250 return _STRIPTAGS_RE.sub('', text) | 247 return _STRIPTAGS_RE.sub('', text) |
251 | 248 |
252 | 249 |
253 def stringrepr(string): | 250 def stringrepr(string): |
254 slen = len(string) | |
255 ascii = string.encode('ascii', 'backslashreplace') | 251 ascii = string.encode('ascii', 'backslashreplace') |
256 r = "'" + ascii.replace("'", "\\'") + "'" | 252 quoted = "'" + ascii.replace("'", "\\'") + "'" |
257 if (unicode is not str) and (len(ascii) > len(string)): | 253 if len(ascii) > len(string): |
258 return 'u' + r | 254 return 'u' + quoted |
259 return r | 255 return quoted |
260 | 256 |
261 | 257 |
262 # Compatibility fallback implementations for older Python versions | 258 # Compatibility fallback implementations for older Python versions |
263 | 259 |
264 try: | 260 try: |