From bd071668c8d0fcebb52ae072f2524e0bc772deb1 Mon Sep 17 00:00:00 2001 From: Greg Hewgill Date: Thu, 8 Jan 2009 23:46:33 +1300 Subject: [PATCH] fix filename generation for platforms that don't quite handle UTF-8 filenames --- ljdump.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ljdump.py b/ljdump.py index fbae90a..0ab61ec 100755 --- a/ljdump.py +++ b/ljdump.py @@ -284,7 +284,13 @@ for p in userpics: print >>f, """""" % (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() -- 2.39.2