From 1e22099b2826a2182c0ad8b3932b5ef38f4b62fa Mon Sep 17 00:00:00 2001 From: inpos Date: Wed, 9 Mar 2016 13:29:58 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8F=20lo?= =?UTF-8?q?calize=5Fpath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pyrrent2http/pyrrent2http.py | 12 +++--------- lib/pyrrent2http/util.py | 7 +++++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/pyrrent2http/pyrrent2http.py b/lib/pyrrent2http/pyrrent2http.py index e384a83..4145d3e 100644 --- a/lib/pyrrent2http/pyrrent2http.py +++ b/lib/pyrrent2http/pyrrent2http.py @@ -28,7 +28,7 @@ import BaseHTTPServer import SocketServer import threading import io -import socket +from util import localize_path @@ -377,10 +377,7 @@ class TorrentFS(object): raise IndexError fileEntry = info.file_at(index) fe_path = fileEntry.path - fe_path = fe_path.decode(chardet.detect(fe_path)['encoding']) - if not sys.platform.startswith('win'): - fe_path = fe_path.encode(sys.getfilesystemencoding()) - path = os.path.abspath(os.path.join(self.SavePath(), fe_path)) + path = os.path.abspath(os.path.join(self.SavePath(), localize_path(fe_path))) return TorrentFile( self, fileEntry, @@ -388,10 +385,7 @@ class TorrentFS(object): index ) def FileByName(self, name): - name = name.decode(chardet.detect(name)['encoding']) - if not sys.platform.startswith('win'): - name = name.encode(sys.getfilesystemencoding()) - savePath = os.path.abspath(os.path.join(self.SavePath(), name)) + savePath = os.path.abspath(os.path.join(self.SavePath(), localize_path(name))) for file_ in self.Files(): if file_.savePath == savePath: return file_ diff --git a/lib/pyrrent2http/util.py b/lib/pyrrent2http/util.py index b8f3514..51c2b6c 100644 --- a/lib/pyrrent2http/util.py +++ b/lib/pyrrent2http/util.py @@ -1,7 +1,14 @@ import sys import socket +import chardet +def localize_path(path): + path = path.decode(chardet.detect(path)['encoding']) + if not sys.platform.startswith('win'): + path = path.encode(sys.getfilesystemencoding()) + return path + def can_bind(host, port): """ Checks we can bind to specified host and port