]> git.decadent.org.uk Git - dak.git/blobdiff - daklib/textutils.py
Add by-hash support
[dak.git] / daklib / textutils.py
old mode 100755 (executable)
new mode 100644 (file)
index 97d09c4..b464675
@@ -22,7 +22,6 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-import codecs
 import email.Header
 
 from dak_exceptions import *
@@ -35,6 +34,8 @@ def force_to_utf8(s):
     Forces a string to UTF-8.  If the string isn't already UTF-8,
     it's assumed to be ISO-8859-1.
     """
+    if isinstance(s, unicode):
+        return s
     try:
         unicode(s, 'utf-8')
         return s
@@ -47,18 +48,15 @@ def rfc2047_encode(s):
     Encodes a (header) string per RFC2047 if necessary.  If the
     string is neither ASCII nor UTF-8, it's assumed to be ISO-8859-1.
     """
-    try:
-        codecs.lookup('ascii')[1](s)
-        return s
-    except UnicodeError:
-        pass
-    try:
-        codecs.lookup('utf-8')[1](s)
-        h = email.Header.Header(s, 'utf-8', 998)
-        return str(h)
-    except UnicodeError:
-        h = email.Header.Header(s, 'iso-8859-1', 998)
-        return str(h)
+    for enc in ['ascii', 'utf-8', 'iso-8859-1']:
+        try:
+            h = email.Header.Header(s, enc, 998)
+            return str(h)
+        except UnicodeError:
+            pass
+
+    # If we get here, we're boned beyond belief
+    return ''
 
 ################################################################################
 
@@ -92,7 +90,7 @@ def fix_maintainer(maintainer):
     else:
         m = re_parse_maintainer.match(maintainer)
         if not m:
-            raise ParseMaintError, "Doesn't parse as a valid Maintainer field."
+            raise ParseMaintError("Doesn't parse as a valid Maintainer field.")
         name = m.group(1)
         email = m.group(2)
 
@@ -110,8 +108,13 @@ def fix_maintainer(maintainer):
         rfc2047_maint = "%s <%s>" % (rfc2047_name, email)
 
     if email.find("@") == -1 and email.find("buildd_") != 0:
-        raise ParseMaintError, "No @ found in email address part."
+        raise ParseMaintError("No @ found in email address part.")
 
     return (rfc822_maint, rfc2047_maint, name, email)
 
 ################################################################################
+
+def split_uploaders(field):
+    import re
+    for u in re.sub(">[ ]*,", ">\t", field).split("\t"):
+        yield u.strip()