summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Resch <andrewresch@gmail.com>2009-04-10 17:34:55 +0000
committerAndrew Resch <andrewresch@gmail.com>2009-04-10 17:34:55 +0000
commit1693bc7373de005bbd2ed7385ff30fdcee00df3e (patch)
tree43cc500f367564dc36b2947e78e4c5966aaa5927
parent2023fac5c5e144fe20c1c7574b41446176c15b89 (diff)
downloaddeluge-1693bc7373de005bbd2ed7385ff30fdcee00df3e.tar.gz
deluge-1693bc7373de005bbd2ed7385ff30fdcee00df3e.tar.bz2
deluge-1693bc7373de005bbd2ed7385ff30fdcee00df3e.zip
Fix for adding torrents with invalid filename encodings
-rw-r--r--ChangeLog1
-rw-r--r--deluge/ui/client.py10
-rw-r--r--deluge/ui/common.py2
-rw-r--r--deluge/ui/gtkui/addtorrentdialog.py4
4 files changed, 11 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index ad9a26b7b..cc2a0eb55 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
=== Deluge 1.1.7 - (In Development) ===
==== GtkUI ====
* Fix #883 segfault if locale is not using UTF-8 encoding
+ * Fix for adding torrents with invalid filename encodings
=== Deluge 1.1.6 - (06 April 2009) ===
==== Core ====
diff --git a/deluge/ui/client.py b/deluge/ui/client.py
index e0bcaf0c6..0d3474a98 100644
--- a/deluge/ui/client.py
+++ b/deluge/ui/client.py
@@ -271,13 +271,17 @@ class BaseClient(object):
# Open the .torrent file for reading because we need to send it's
# contents to the core.
try:
- f = open(unicode(torrent_file), "rb")
+ f = open(torrent_file, "rb")
except Exception, e:
log.warning("Unable to open %s: %s", torrent_file, e)
continue
- # Get the filename because the core doesn't want a path.
- (path, filename) = os.path.split(torrent_file)
+ # Get the name of the torrent from the TorrentInfo object because
+ # it does better handling of encodings
+ import deluge.ui.common
+ ti = deluge.ui.common.TorrentInfo(torrent_file)
+ filename = ti.name
+
fdump = xmlrpclib.Binary(f.read())
f.close()
diff --git a/deluge/ui/common.py b/deluge/ui/common.py
index 2b0b781a3..f7eaab276 100644
--- a/deluge/ui/common.py
+++ b/deluge/ui/common.py
@@ -62,6 +62,8 @@ class TorrentInfo(object):
self.encoding = "UTF-8"
if "encoding" in self.__m_metadata:
self.encoding = self.__m_metadata["encoding"]
+ elif "codepage" in self.__m_metadata:
+ self.encoding = str(self.__m_metadata["codepage"])
# Get list of files from torrent info
self.__m_files = []
diff --git a/deluge/ui/gtkui/addtorrentdialog.py b/deluge/ui/gtkui/addtorrentdialog.py
index 36cb97927..095d2297d 100644
--- a/deluge/ui/gtkui/addtorrentdialog.py
+++ b/deluge/ui/gtkui/addtorrentdialog.py
@@ -186,14 +186,12 @@ class AddTorrentDialog(component.Component):
new_row = None
for filename in filenames:
- # Convert the path to unicode
- filename = unicode(filename)
-
# Get the torrent data from the torrent file
try:
info = deluge.ui.common.TorrentInfo(filename)
except Exception, e:
log.debug("Unable to open torrent file: %s", e)
+ log.exception(e)
continue
if info.info_hash in self.files: