summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbendikro <bendikro@gmail.com>2013-01-01 17:15:00 +0000
committerCalum Lind <calumlind+deluge@gmail.com>2013-01-01 17:22:00 +0000
commitcc5ef891397427a7a7817a574453a11e754cc3aa (patch)
tree1823b51234d55274b7d091450fd3063b00b4692d
parent1a9506f83294b806674965a56270732224e4cc15 (diff)
downloaddeluge-cc5ef89139.tar.gz
deluge-cc5ef89139.tar.bz2
deluge-cc5ef89139.zip
Fix #2241 : Can't add any torrent files with GUI running
This fixes a bug in commit 60f196ff933, adds a test and removes unneeded ignore when encoding unicode to utf8.
-rw-r--r--deluge/common.py8
-rw-r--r--deluge/tests/test_ui_common.py30
-rw-r--r--deluge/tests/unicode_filenames.torrentbin0 -> 34298 bytes
3 files changed, 35 insertions, 3 deletions
diff --git a/deluge/common.py b/deluge/common.py
index b68c1c776..1116572c1 100644
--- a/deluge/common.py
+++ b/deluge/common.py
@@ -659,20 +659,22 @@ def decode_string(s, encoding="utf8"):
pass
return u''
-def utf8_encoded(s):
+def utf8_encoded(s, encoding="utf8"):
"""
Returns a utf8 encoded string of s
:param s: (unicode) string to (re-)encode
:type s: basestring
+ :keyword encoding: the encoding to use in the decoding
+ :type encoding: string
:returns: a utf8 encoded string of s
:rtype: str
"""
if isinstance(s, str):
- s = decode_string(s).encode("utf8")
+ s = decode_string(s, encoding).encode("utf8")
elif isinstance(s, unicode):
- s = s.encode("utf8", "ignore")
+ s = s.encode("utf8")
return s
class VersionSplit(object):
diff --git a/deluge/tests/test_ui_common.py b/deluge/tests/test_ui_common.py
new file mode 100644
index 000000000..14d58e7b4
--- /dev/null
+++ b/deluge/tests/test_ui_common.py
@@ -0,0 +1,30 @@
+# -*- coding: utf-8 -*-
+from twisted.trial import unittest
+import os
+from deluge.ui.common import TorrentInfo
+
+class UICommonTestCase(unittest.TestCase):
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def test_utf8_encoded_paths(self):
+ filename = os.path.join(os.path.dirname(__file__), "test.torrent")
+ ti = TorrentInfo(filename)
+ self.assertTrue(ti.files_tree.has_key("azcvsupdater_2.6.2.jar"))
+
+ def test_utf8_encoded_paths2(self):
+ filename = os.path.join(os.path.dirname(__file__), "unicode_filenames.torrent")
+ ti = TorrentInfo(filename)
+
+ files = ti.files_tree["unicode_filenames"]
+ self.assertTrue(files.has_key("\xe3\x83\x86\xe3\x82\xaf\xe3\x82\xb9\xe3\x83\xbb\xe3\x83"
+ "\x86\xe3\x82\xaf\xe3\x82\xb5\xe3\x83\xb3.mkv"))
+ self.assertTrue(files.has_key("\xd0\x9c\xd0\xb8\xd1\x85\xd0\xb0\xd0\xb8\xd0\xbb \xd0\x93"
+ "\xd0\xbe\xd1\x80\xd0\xb1\xd0\xb0\xd1\x87\xd1\x91\xd0\xb2.mkv"))
+ self.assertTrue(files.has_key("Alisher ibn G'iyosiddin Navoiy.mkv"))
+ self.assertTrue(files.has_key("Ascii title.mkv"))
+ self.assertTrue(files.has_key("\xe0\xa6\xb8\xe0\xa7\x81\xe0\xa6\x95\xe0\xa7\x81\xe0\xa6"
+ "\xae\xe0\xa6\xbe\xe0\xa6\xb0 \xe0\xa6\xb0\xe0\xa6\xbe\xe0\xa7\x9f.mkv"))
diff --git a/deluge/tests/unicode_filenames.torrent b/deluge/tests/unicode_filenames.torrent
new file mode 100644
index 000000000..e34f055df
--- /dev/null
+++ b/deluge/tests/unicode_filenames.torrent
Binary files differ