summaryrefslogtreecommitdiffstats
path: root/deluge/ui/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'deluge/ui/common.py')
-rw-r--r--deluge/ui/common.py39
1 files changed, 12 insertions, 27 deletions
diff --git a/deluge/ui/common.py b/deluge/ui/common.py
index 21bcafd..f9f774e 100644
--- a/deluge/ui/common.py
+++ b/deluge/ui/common.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
#
# Copyright (C) Damien Churchill 2008-2009 <damoxc@gmail.com>
# Copyright (C) Andrew Resch 2009 <andrewresch@gmail.com>
@@ -11,11 +10,8 @@
"""
The ui common module contains methods and classes that are deemed useful for all the interfaces.
"""
-from __future__ import unicode_literals
-
import logging
import os
-from binascii import hexlify
from hashlib import sha1 as sha
from deluge import bencode
@@ -161,7 +157,6 @@ DISK_CACHE_KEYS = [
'disk.num_blocks_written',
'disk.num_read_ops',
'disk.num_write_ops',
- 'disk.num_blocks_cache_hits',
'read_hit_ratio',
'write_hit_ratio',
'disk.disk_blocks_in_use',
@@ -169,7 +164,7 @@ DISK_CACHE_KEYS = [
]
-class TorrentInfo(object):
+class TorrentInfo:
"""Collects information about a torrent file.
Args:
@@ -188,7 +183,7 @@ class TorrentInfo(object):
try:
with open(filename, 'rb') as _file:
self._filedata = _file.read()
- except IOError as ex:
+ except OSError as ex:
log.warning('Unable to open %s: %s', filename, ex)
return
@@ -206,12 +201,9 @@ class TorrentInfo(object):
self._info_hash = sha(bencode.bencode(info_dict)).hexdigest()
# Get encoding from torrent file if available
- encoding = info_dict.get('encoding', None)
- codepage = info_dict.get('codepage', None)
- if not encoding:
- encoding = codepage if codepage else b'UTF-8'
- if encoding:
- encoding = encoding.decode()
+ encoding = info_dict.get(
+ 'encoding', info_dict.get('codepage', b'UTF-8')
+ ).decode()
# Decode 'name' with encoding unless 'name.utf-8' found.
if 'name.utf-8' in info_dict:
@@ -231,27 +223,20 @@ class TorrentInfo(object):
if 'path.utf-8' in f:
path = decode_bytes(os.path.join(*f['path.utf-8']))
- del f['path.utf-8']
else:
path = decode_bytes(os.path.join(*f['path']), encoding)
if prefix:
path = os.path.join(prefix, path)
+ # Ensure agnostic path separator
+ path = path.replace('\\', '/')
+
self._files.append(
{'path': path, 'size': f['length'], 'download': True}
)
+ paths[path] = {'path': path, 'index': index, 'length': f['length']}
- f['path'] = path
- f['index'] = index
- if 'sha1' in f and len(f['sha1']) == 20:
- f['sha1'] = hexlify(f['sha1']).decode()
- if 'ed2k' in f and len(f['ed2k']) == 16:
- f['ed2k'] = hexlify(f['ed2k']).decode()
- if 'filehash' in f and len(f['filehash']) == 20:
- f['filehash'] = hexlify(f['filehash']).decode()
-
- paths[path] = f
dirname = os.path.dirname(path)
while dirname:
dirinfo = dirs.setdefault(dirname, {})
@@ -399,7 +384,7 @@ class TorrentInfo(object):
return self._filedata
-class FileTree2(object):
+class FileTree2:
"""
Converts a list of paths in to a file tree.
@@ -479,7 +464,7 @@ class FileTree2(object):
return '\n'.join(lines)
-class FileTree(object):
+class FileTree:
"""
Convert a list of paths in a file tree.
@@ -538,7 +523,7 @@ class FileTree(object):
def walk(directory, parent_path):
for path in list(directory):
- full_path = os.path.join(parent_path, path)
+ full_path = os.path.join(parent_path, path).replace('\\', '/')
if isinstance(directory[path], dict):
directory[path] = (
callback(full_path, directory[path]) or directory[path]