From 8513d9ce2f7c57999233eb894c448a5d3b15cb90 Mon Sep 17 00:00:00 2001
From: lefthaha <lefthaha+dev@gmail.com>
Date: Sat, 7 Jun 2014 09:05:16 +0800
Subject: [PATCH] [#1109] Load torrents with special characters in autoadd dir

self.config["autoadd_location"] is a unicode string, but using
os.listdir(self.config["autoadd_location"]) will return a list of byte string

when some torrents contain non-ascii filename,it may raise UnicodeDecodeError
with os.pats.path.join(),to avoid messing around with encoding, directly using
byte string for file access
---
 deluge/core/autoadd.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/deluge/core/autoadd.py b/deluge/core/autoadd.py
index 8d1219c..61d22d4 100644
--- a/deluge/core/autoadd.py
+++ b/deluge/core/autoadd.py
@@ -73,10 +73,15 @@ def update(self):
             component.pause("AutoAdd")
             return
 
-        for filename in os.listdir(self.config["autoadd_location"]):
+        # Prevent unicode path join error, use byte string when accessing filename
+        autoadd_dir = self.config["autoadd_location"]
+        if isinstance(autoadd_dir, unicode):
+            autoadd_dir = str(autoadd_dir)
+
+        for filename in os.listdir(autoadd_dir):
             try:
-                filepath = os.path.join(self.config["autoadd_location"], filename)
-            except UnicodeDecodeError, e:
+                filepath = os.path.join(autoadd_dir, filename)
+            except (UnicodeDecodeError, UnicodeEncodeError) as e:
                 log.error("Unable to auto add torrent due to improper filename encoding: %s", e)
                 continue
             if os.path.isfile(filepath) and filename.endswith(".torrent"):
-- 
1.9.3

