From a4abbbc5589e948e469849c58b67d179212785d0 Mon Sep 17 00:00:00 2001 From: "luxagraf@c63593aa-01b0-44d9-8516-4b9c7e931d7f" Date: Sun, 4 Jul 2010 00:42:45 +0000 Subject: fuck up --- lib/utils/strutils.py | 50 -------------------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 lib/utils/strutils.py (limited to 'lib/utils/strutils.py') diff --git a/lib/utils/strutils.py b/lib/utils/strutils.py deleted file mode 100644 index 368d3d8..0000000 --- a/lib/utils/strutils.py +++ /dev/null @@ -1,50 +0,0 @@ - -# -# String/unicode conversion utils. -# - -def safestr(s): - """ - Safely corerce *anything* to a string. If the object can't be str'd, an - empty string will be returned. - - You can (and I do) use this for really crappy unicode handling, but it's - a bit like killing a mosquito with a bazooka. - """ - if s is None: - return "" - if isinstance(s, unicode): - return s.encode('ascii', 'xmlcharrefreplace') - else: - try: - return str(s) - except: - return "" - -def safeint(s): - """Like safestr(), but always returns an int. Returns 0 on failure.""" - try: - return int(safestr(s)) - except ValueError: - return 0 - - -def convertentity(m): - import htmlentitydefs - """Convert a HTML entity into normal string (ISO-8859-1)""" - if m.group(1)=='#': - try: - return chr(int(m.group(2))) - except ValueError: - return '&#%s;' % m.group(2) - try: - return htmlentitydefs.entitydefs[m.group(2)] - except KeyError: - return '&%s;' % m.group(2) - -def unquotehtml(s): - import re - """Convert a HTML quoted string into normal string (ISO-8859-1). - - Works with &#XX; and with   > etc.""" - return re.sub(r'&(#?)(.+?);',convertentity,s) -- cgit v1.2.3-70-g09d2