summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAarni Koskela <akx@iki.fi>2019-05-27 11:24:33 +0300
committerAarni Koskela <akx@iki.fi>2019-05-27 11:37:12 +0300
commit509f20915c18f452d6d2d247289423fc0c4b8686 (patch)
tree228b1ef02dd24e37bcd7110cf1f9a7bebbdfd1d8
parent1d7a4da9e1a563e800dc6475bc95e1fa58a07473 (diff)
downloadbabel-509f20915c18f452d6d2d247289423fc0c4b8686.tar.gz
pofile: don't crash when message.locations can't be sorted
Fixes #606
-rw-r--r--babel/messages/pofile.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/babel/messages/pofile.py b/babel/messages/pofile.py
index 2943fa2..9eb3a5c 100644
--- a/babel/messages/pofile.py
+++ b/babel/messages/pofile.py
@@ -581,7 +581,16 @@ def write_po(fileobj, catalog, width=76, no_location=False, omit_header=False,
if not no_location:
locs = []
- for filename, lineno in sorted(message.locations):
+
+ # Attempt to sort the locations. If we can't do that, for instance
+ # because there are mixed integers and Nones or whatnot (see issue #606)
+ # then give up, but also don't just crash.
+ try:
+ locations = sorted(message.locations)
+ except TypeError: # e.g. "TypeError: unorderable types: NoneType() < int()"
+ locations = message.locations
+
+ for filename, lineno in locations:
if lineno and include_lineno:
locs.append(u'%s:%d' % (filename.replace(os.sep, '/'), lineno))
else: