From: Greg Hewgill Date: Thu, 8 Jan 2009 10:46:33 +0000 (+1300) Subject: fix filename generation for platforms that don't quite handle UTF-8 filenames X-Git-Tag: ljdump-1.3.2~3 X-Git-Url: http://wagner.pp.ru/gitweb/?a=commitdiff_plain;h=bd071668c8d0fcebb52ae072f2524e0bc772deb1;p=oss%2Fljdump.git fix filename generation for platforms that don't quite handle UTF-8 filenames --- 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()