changeset 77:ebf3d3c39cb7

fix this muthafuckin assertion
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 16 Apr 2013 00:16:03 -0700
parents 1892ac35e9c8
children 5330cd62e179
files decoupage/formatters.py
diffstat 1 files changed, 22 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/decoupage/formatters.py	Mon Apr 15 23:30:39 2013 -0700
+++ b/decoupage/formatters.py	Tue Apr 16 00:16:03 2013 -0700
@@ -206,16 +206,33 @@
     foo.html = description of foo; [PDF]=foo.pdf; [TXT]=foo.txt
     """
 
+    fatal = False
     defaults = { 'separator': ';' }
 
+
     def __call__(self, request, data):
         for f in data['files']:
             if f['description'] and self.separator in f['description']:
-                f['description'], links = f['description'].split(self.separator, 1)
-                links = links.split(self.separator)
-                assert min(['=' in link for link in links])
-                links = [ link.split('=', 1) for link in links ]
-                f['links'] = [{ 'text': text, 'link': link }
+                description, links = f['description'].split(self.separator, 1)
+                links = links.rstrip().split(self.separator)
+
+                if not min(['=' in link for link in links]):
+                    message = """%s
+
+%s: misformatted description: %s (separator: %s)""" % (f,
+                                                       self.__class__.__name__,
+                                                       description,
+                                                       self.separator)
+                    if self.fatal:
+                        raise AssertionError(message)
+                    else:
+                        print >> sys.stderr, message
+                        continue
+
+                f['description'] = description
+
+                links = [link.split('=', 1) for link in links]
+                f['links'] = [{'text': text, 'link': link}
                               for text, link in links]