Mercurial > babel > old > mirror
comparison babel3/babel/messages/extract.py @ 494:cddcd04db33e experimental
Commit the resulting files after a 2to3 -nvw run.
author | jruigrok |
---|---|
date | Thu, 15 Apr 2010 14:20:11 +0000 |
parents | 0b228ee775fe |
children |
comparison
equal
deleted
inserted
replaced
493:0b228ee775fe | 494:cddcd04db33e |
---|---|
58 def _strip(line): | 58 def _strip(line): |
59 for tag in tags: | 59 for tag in tags: |
60 if line.startswith(tag): | 60 if line.startswith(tag): |
61 return line[len(tag):].strip() | 61 return line[len(tag):].strip() |
62 return line | 62 return line |
63 comments[:] = map(_strip, comments) | 63 comments[:] = list(map(_strip, comments)) |
64 | 64 |
65 | 65 |
66 def extract_from_dir(dirname=os.getcwd(), method_map=DEFAULT_MAPPING, | 66 def extract_from_dir(dirname=os.getcwd(), method_map=DEFAULT_MAPPING, |
67 options_map=None, keywords=DEFAULT_KEYWORDS, | 67 options_map=None, keywords=DEFAULT_KEYWORDS, |
68 comment_tags=(), callback=None, strip_comment_tags=False): | 68 comment_tags=(), callback=None, strip_comment_tags=False): |
151 ) | 151 ) |
152 for pattern, method in method_map: | 152 for pattern, method in method_map: |
153 if pathmatch(pattern, filename): | 153 if pathmatch(pattern, filename): |
154 filepath = os.path.join(absname, filename) | 154 filepath = os.path.join(absname, filename) |
155 options = {} | 155 options = {} |
156 for opattern, odict in options_map.items(): | 156 for opattern, odict in list(options_map.items()): |
157 if pathmatch(opattern, filename): | 157 if pathmatch(opattern, filename): |
158 options = odict | 158 options = odict |
159 if callback: | 159 if callback: |
160 callback(filename, method, options) | 160 callback(filename, method, options) |
161 for lineno, message, comments in \ | 161 for lineno, message, comments in \ |
263 func = entry_point.load(require=True) | 263 func = entry_point.load(require=True) |
264 break | 264 break |
265 if func is None: | 265 if func is None: |
266 raise ValueError('Unknown extraction method %r' % method) | 266 raise ValueError('Unknown extraction method %r' % method) |
267 | 267 |
268 results = func(fileobj, keywords.keys(), comment_tags, | 268 results = func(fileobj, list(keywords.keys()), comment_tags, |
269 options=options or {}) | 269 options=options or {}) |
270 | 270 |
271 for lineno, funcname, messages, comments in results: | 271 for lineno, funcname, messages, comments in results: |
272 if funcname: | 272 if funcname: |
273 spec = keywords[funcname] or (1,) | 273 spec = keywords[funcname] or (1,) |
299 first_msg_index = spec[0] - 1 | 299 first_msg_index = spec[0] - 1 |
300 if not messages[first_msg_index]: | 300 if not messages[first_msg_index]: |
301 # An empty string msgid isn't valid, emit a warning | 301 # An empty string msgid isn't valid, emit a warning |
302 where = '%s:%i' % (hasattr(fileobj, 'name') and \ | 302 where = '%s:%i' % (hasattr(fileobj, 'name') and \ |
303 fileobj.name or '(unknown)', lineno) | 303 fileobj.name or '(unknown)', lineno) |
304 print >> sys.stderr, empty_msgid_warning % where | 304 print(empty_msgid_warning % where, file=sys.stderr) |
305 continue | 305 continue |
306 | 306 |
307 messages = tuple(msgs) | 307 messages = tuple(msgs) |
308 if len(messages) == 1: | 308 if len(messages) == 1: |
309 messages = messages[0] | 309 messages = messages[0] |