Author: andar

Revision: 5009

Log:
        Fix displaying torrents with non-utf8 encodings in add torrent dialog

Diff:
Modified: branches/1.1.0_RC/ChangeLog
===================================================================
--- branches/1.1.0_RC/ChangeLog 2009-04-04 13:02:26 UTC (rev 5008)
+++ branches/1.1.0_RC/ChangeLog 2009-04-05 18:31:43 UTC (rev 5009)
@@ -4,6 +4,9 @@
   * Fix #855 force a resume on a torrent if a 'Force Recheck' is initiated
   * Fix #862 deluged crash when access http://localhost:58846
 
+==== GtkUI ====
+  * Fix displaying torrents with non-utf8 encodings in add torrent dialog
+
 ==== WebUI ====
   * Fix #870 use proper config location for loading ssl cert
 

Modified: branches/1.1.0_RC/deluge/ui/common.py
===================================================================
--- branches/1.1.0_RC/deluge/ui/common.py       2009-04-04 13:02:26 UTC (rev 
5008)
+++ branches/1.1.0_RC/deluge/ui/common.py       2009-04-05 18:31:43 UTC (rev 
5009)
@@ -46,29 +46,34 @@
 
         self.__m_info_hash = 
sha(bencode.bencode(self.__m_metadata["info"])).hexdigest()
 
+        # Get encoding from torrent file if available
+        self.encoding = "UTF-8"
+        if "encoding" in self.__m_metadata:
+            self.encoding = self.__m_metadata["encoding"]
+
         # Get list of files from torrent info
         self.__m_files = []
         if self.__m_metadata["info"].has_key("files"):
             prefix = ""
             if len(self.__m_metadata["info"]["files"]) > 1:
-                prefix = self.__m_metadata["info"]["name"]
+                prefix = 
self.__m_metadata["info"]["name"].decode(self.encoding).encode("utf8")
 
             for f in self.__m_metadata["info"]["files"]:
                 self.__m_files.append({
-                    'path': os.path.join(prefix, *f["path"]),
+                    'path': os.path.join(prefix, 
*f["path"]).decode(self.encoding).encode("utf8"),
                     'size': f["length"],
                     'download': True
                 })
         else:
             self.__m_files.append({
-                "path": self.__m_metadata["info"]["name"],
+                "path": 
self.__m_metadata["info"]["name"].decode(self.encoding).encode("utf8"),
                 "size": self.__m_metadata["info"]["length"],
                 "download": True
         })
 
     @property
     def name(self):
-        return self.__m_metadata["info"]["name"]
+        return 
self.__m_metadata["info"]["name"].decode(self.encoding).encode("utf8")
 
     @property
     def info_hash(self):

Modified: trunk/deluge/core/rpcserver.py
===================================================================
--- trunk/deluge/core/rpcserver.py      2009-04-04 13:02:26 UTC (rev 5008)
+++ trunk/deluge/core/rpcserver.py      2009-04-05 18:31:43 UTC (rev 5009)
@@ -134,16 +134,22 @@
                     continue
 
                 # Format the RPCRequest message for debug printing
-                s = call[1] + "("
-                if call[2]:
-                    s += ", ".join([str(x) for x in call[2]])
-                if call[3]:
+                try:
+                    s = call[1] + "("
                     if call[2]:
-                        s += ", "
-                    s += ", ".join([key + "=" + str(value) for key, value in 
call[3].items()])
-                s += ")"
+                        s += ", ".join([str(x) for x in call[2]])
+                    if call[3]:
+                        if call[2]:
+                            s += ", "
+                        s += ", ".join([key + "=" + str(value) for key, value 
in call[3].items()])
+                    s += ")"
+                except UnicodeEncodeError:
+                    pass
+                    #log.debug("RPCRequest had some non-ascii text..")
+                else:
+                    pass
+                    #log.debug("RPCRequest: %s", s)
 
-                #log.debug("RPCRequest: %s", s)
                 reactor.callLater(0, self._dispatch, *call)
 
     def sendData(self, data):

Modified: trunk/deluge/ui/common.py
===================================================================
--- trunk/deluge/ui/common.py   2009-04-04 13:02:26 UTC (rev 5008)
+++ trunk/deluge/ui/common.py   2009-04-05 18:31:43 UTC (rev 5009)
@@ -48,15 +48,20 @@
 
         self.__m_info_hash = 
sha(bencode.bencode(self.__m_metadata["info"])).hexdigest()
 
+        # Get encoding from torrent file if available
+        self.encoding = "UTF-8"
+        if "encoding" in self.__m_metadata:
+            self.encoding = self.__m_metadata["encoding"]
+
         # Get list of files from torrent info
         paths = {}
         if self.__m_metadata["info"].has_key("files"):
             prefix = ""
             if len(self.__m_metadata["info"]["files"]) > 1:
-                prefix = self.__m_metadata["info"]["name"]
+                prefix = 
self.__m_metadata["info"]["name"].decode(self.encoding).encode("utf8")
 
             for index, f in enumerate(self.__m_metadata["info"]["files"]):
-                path = os.path.join(prefix, *f["path"])
+                path = os.path.join(prefix, 
*f["path"]).decode(self.encoding).encode("utf8")
                 f["index"] = index
                 paths[path] = f
 
@@ -70,40 +75,40 @@
             self.__m_files_tree = file_tree.get_tree()
         else:
             self.__m_files_tree = {
-                self.__m_metadata["info"]["name"]: 
(self.__m_metadata["info"]["length"], True)
+                
self.__m_metadata["info"]["name"].decode(self.encoding).encode("utf8"): 
(self.__m_metadata["info"]["length"], True)
             }
 
         self.__m_files = []
         if self.__m_metadata["info"].has_key("files"):
             prefix = ""
             if len(self.__m_metadata["info"]["files"]) > 1:
-                prefix = self.__m_metadata["info"]["name"]
+                prefix = 
self.__m_metadata["info"]["name"].decode(self.encoding).encode("utf8")
 
             for f in self.__m_metadata["info"]["files"]:
                 self.__m_files.append({
-                    'path': os.path.join(prefix, *f["path"]),
+                    'path': os.path.join(prefix, 
*f["path"]).decode(self.encoding).encode("utf8"),
                     'size': f["length"],
                     'download': True
                 })
         else:
             self.__m_files.append({
-                "path": self.__m_metadata["info"]["name"],
+                "path": 
self.__m_metadata["info"]["name"].decode(self.encoding).encode("utf8"),
                 "size": self.__m_metadata["info"]["length"],
                 "download": True
         })
-    
+
     def as_dict(self, *keys):
         """
         Return the torrent info as a dictionary, only including the passed in
         keys.
-        
+
         :param *keys: str, a number of key strings
         """
         return dict([(key, getattr(self, key)) for key in keys])
 
     @property
     def name(self):
-        return self.__m_metadata["info"]["name"]
+        return 
self.__m_metadata["info"]["name"].decode(self.encoding).encode("utf8")
 
     @property
     def info_hash(self):
@@ -125,7 +130,7 @@
     def __init__(self, paths):
         """
         Convert a list of paths in a file tree.
-        
+
         :param paths: list, The paths to be converted.
         """
         self.tree = {}
@@ -152,7 +157,7 @@
     def get_tree(self):
         """
         Return the tree, after first converting all file lists to a tuple.
-        
+
         :returns: dict, the file tree.
         """
         def to_tuple(path, item):
@@ -166,7 +171,7 @@
         """
         Walk through the file tree calling the callback function on each item
         contained.
-        
+
         :param callback: function, The function to be used as a callback, it
             should have the signature func(item, path) where item is a `tuple`
             for a file and `dict` for a directory.



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to