]> wagner.pp.ru Git - oss/ljdump.git/commitdiff
fix filename generation for platforms that don't quite handle UTF-8 filenames
authorGreg Hewgill <greg@hewgill.com>
Thu, 8 Jan 2009 10:46:33 +0000 (23:46 +1300)
committerGreg Hewgill <greg@hewgill.com>
Thu, 8 Jan 2009 11:42:12 +0000 (00:42 +1300)
ljdump.py

index fbae90ad37f5cacbe938c1069e1ce949e7bca9d2..0ab61ec5c79ba6a480479afbca76a245b66a3e24 100755 (executable)
--- a/ljdump.py
+++ b/ljdump.py
@@ -284,7 +284,13 @@ for p in userpics:
     print >>f, """<userpic keyword="%s" url="%s" />""" % (p, userpics[p])
     pic = urllib2.urlopen(userpics[p])
     ext = MimeExtensions.get(pic.info()["Content-Type"], "")
-    picf = open("%s/%s%s" % (Username, codecs.utf_8_decode(p)[0], ext), "wb")
+    try:
+        picfn = codecs.utf_8_decode(p)[0]
+        picf = open("%s/%s%s" % (Username, picfn, ext), "wb")
+    except:
+        # for installations where the above utf_8_decode doesn't work
+        picfn = "".join([ord(x) < 128 and x or "?" for x in p])
+        picf = open("%s/%s%s" % (Username, picfn, ext), "wb")
     shutil.copyfileobj(pic, picf)
     pic.close()
     picf.close()