Fix loading improperly created torrents with mismatched encodings

This commit is contained in:
Andrew Resch 2009-04-21 17:16:19 +00:00
parent 4fde1b4a2f
commit be1a1fc0be
1 changed files with 6 additions and 6 deletions

View File

@ -58,10 +58,10 @@ class TorrentInfo(object):
if self.__m_metadata["info"].has_key("files"): if self.__m_metadata["info"].has_key("files"):
prefix = "" prefix = ""
if len(self.__m_metadata["info"]["files"]) > 1: if len(self.__m_metadata["info"]["files"]) > 1:
prefix = self.__m_metadata["info"]["name"].decode(self.encoding).encode("utf8") prefix = self.__m_metadata["info"]["name"].decode(self.encoding, "replace").encode("utf8")
for index, f in enumerate(self.__m_metadata["info"]["files"]): for index, f in enumerate(self.__m_metadata["info"]["files"]):
path = os.path.join(prefix, *f["path"]).decode(self.encoding).encode("utf8") path = os.path.join(prefix, *f["path"]).decode(self.encoding, "replace").encode("utf8")
f["index"] = index f["index"] = index
paths[path] = f paths[path] = f
@ -75,24 +75,24 @@ class TorrentInfo(object):
self.__m_files_tree = file_tree.get_tree() self.__m_files_tree = file_tree.get_tree()
else: else:
self.__m_files_tree = { self.__m_files_tree = {
self.__m_metadata["info"]["name"].decode(self.encoding).encode("utf8"): (self.__m_metadata["info"]["length"], True) self.__m_metadata["info"]["name"].decode(self.encoding, "replace").encode("utf8"): (self.__m_metadata["info"]["length"], True)
} }
self.__m_files = [] self.__m_files = []
if self.__m_metadata["info"].has_key("files"): if self.__m_metadata["info"].has_key("files"):
prefix = "" prefix = ""
if len(self.__m_metadata["info"]["files"]) > 1: if len(self.__m_metadata["info"]["files"]) > 1:
prefix = self.__m_metadata["info"]["name"].decode(self.encoding).encode("utf8") prefix = self.__m_metadata["info"]["name"].decode(self.encoding, "replace").encode("utf8")
for f in self.__m_metadata["info"]["files"]: for f in self.__m_metadata["info"]["files"]:
self.__m_files.append({ self.__m_files.append({
'path': os.path.join(prefix, *f["path"]).decode(self.encoding).encode("utf8"), 'path': os.path.join(prefix, *f["path"]).decode(self.encoding, "replace").encode("utf8"),
'size': f["length"], 'size': f["length"],
'download': True 'download': True
}) })
else: else:
self.__m_files.append({ self.__m_files.append({
"path": self.__m_metadata["info"]["name"].decode(self.encoding).encode("utf8"), "path": self.__m_metadata["info"]["name"].decode(self.encoding, "replace").encode("utf8"),
"size": self.__m_metadata["info"]["length"], "size": self.__m_metadata["info"]["length"],
"download": True "download": True
}) })