[Sugar-devel] [PATCH] OLPC #8857 - Browse fails to download some files with non-ascii characters

godiard at sugarlabs.org godiard at sugarlabs.org
Thu Nov 18 16:02:06 EST 2010


From: Gonzalo Odiard <godiard at sugarlabs.org>

Browse can't download a file if the name is encoded in a codec different to UTF-8
---
 downloadmanager.py |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/downloadmanager.py b/downloadmanager.py
index c396317..90d22a5 100644
--- a/downloadmanager.py
+++ b/downloadmanager.py
@@ -306,9 +306,13 @@ class Download:
         elif self._source.scheme == 'data':
             return 'Data URI'
         else:
-            path = urlparse.urlparse(self._source.spec).path
+            uri = self._source
+            if uri == None:
+                return ''
+            cls = components.classes['@mozilla.org/intl/texttosuburi;1']
+            texttosuburi = cls.getService(interfaces.nsITextToSubURI)
+            path = texttosuburi.unEscapeURIForUI(uri.originCharset, uri.spec)
             location, file_name = os.path.split(path)
-            file_name = urllib.unquote(file_name.encode('utf-8', 'replace'))
             return file_name
 
     def _create_journal_object(self):
-- 
1.7.2.3



More information about the Sugar-devel mailing list