Функция localize_path

sandbox1
inpos 2016-03-09 13:29:58 +03:00
parent 7e8efc570e
commit 1e22099b28
2 changed files with 10 additions and 9 deletions

View File

@ -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_

View File

@ -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