Mercurial > hg > decoupage
comparison decoupage/formatters.py @ 77:ebf3d3c39cb7
fix this muthafuckin assertion
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 16 Apr 2013 00:16:03 -0700 |
parents | 262fb90a54b4 |
children | a8a74f6bcf93 |
comparison
equal
deleted
inserted
replaced
76:1892ac35e9c8 | 77:ebf3d3c39cb7 |
---|---|
204 """ | 204 """ |
205 allow list of links per item: | 205 allow list of links per item: |
206 foo.html = description of foo; [PDF]=foo.pdf; [TXT]=foo.txt | 206 foo.html = description of foo; [PDF]=foo.pdf; [TXT]=foo.txt |
207 """ | 207 """ |
208 | 208 |
209 fatal = False | |
209 defaults = { 'separator': ';' } | 210 defaults = { 'separator': ';' } |
210 | 211 |
212 | |
211 def __call__(self, request, data): | 213 def __call__(self, request, data): |
212 for f in data['files']: | 214 for f in data['files']: |
213 if f['description'] and self.separator in f['description']: | 215 if f['description'] and self.separator in f['description']: |
214 f['description'], links = f['description'].split(self.separator, 1) | 216 description, links = f['description'].split(self.separator, 1) |
215 links = links.split(self.separator) | 217 links = links.rstrip().split(self.separator) |
216 assert min(['=' in link for link in links]) | 218 |
217 links = [ link.split('=', 1) for link in links ] | 219 if not min(['=' in link for link in links]): |
218 f['links'] = [{ 'text': text, 'link': link } | 220 message = """%s |
221 | |
222 %s: misformatted description: %s (separator: %s)""" % (f, | |
223 self.__class__.__name__, | |
224 description, | |
225 self.separator) | |
226 if self.fatal: | |
227 raise AssertionError(message) | |
228 else: | |
229 print >> sys.stderr, message | |
230 continue | |
231 | |
232 f['description'] = description | |
233 | |
234 links = [link.split('=', 1) for link in links] | |
235 f['links'] = [{'text': text, 'link': link} | |
219 for text, link in links] | 236 for text, link in links] |
220 | 237 |
221 | 238 |
222 class Up(object): | 239 class Up(object): |
223 """ | 240 """ |