summaryrefslogtreecommitdiffstats
path: root/deluge/plugins/AutoAdd/deluge_autoadd/core.py
diff options
context:
space:
mode:
Diffstat (limited to 'deluge/plugins/AutoAdd/deluge_autoadd/core.py')
-rw-r--r--deluge/plugins/AutoAdd/deluge_autoadd/core.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/deluge/plugins/AutoAdd/deluge_autoadd/core.py b/deluge/plugins/AutoAdd/deluge_autoadd/core.py
index 9a2260610..07ad53a8e 100644
--- a/deluge/plugins/AutoAdd/deluge_autoadd/core.py
+++ b/deluge/plugins/AutoAdd/deluge_autoadd/core.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
#
# Copyright (C) 2009 GazpachoKing <chase.sterling@gmail.com>
# Copyright (C) 2011 Pedro Algarvio <pedro@algarvio.me>
@@ -13,8 +12,6 @@
# See LICENSE for more details.
#
-from __future__ import unicode_literals
-
import logging
import os
import shutil
@@ -30,7 +27,7 @@ import deluge.configmanager
from deluge._libtorrent import lt
from deluge.common import AUTH_LEVEL_ADMIN, is_magnet
from deluge.core.rpcserver import export
-from deluge.error import AddTorrentError
+from deluge.error import AddTorrentError, InvalidTorrentError
from deluge.event import DelugeEvent
from deluge.plugins.pluginbase import CorePluginBase
@@ -152,7 +149,7 @@ class Core(CorePluginBase):
try:
with open(filename, file_mode) as _file:
filedump = _file.read()
- except IOError as ex:
+ except OSError as ex:
log.warning('Unable to open %s: %s', filename, ex)
raise ex
@@ -161,7 +158,10 @@ class Core(CorePluginBase):
# Get the info to see if any exceptions are raised
if not magnet:
- lt.torrent_info(lt.bdecode(filedump))
+ decoded_torrent = lt.bdecode(filedump)
+ if decoded_torrent is None:
+ raise InvalidTorrentError('Torrent file failed decoding.')
+ lt.torrent_info(decoded_torrent)
return filedump
@@ -169,9 +169,9 @@ class Core(CorePluginBase):
log.debug('Attempting to open %s for splitting magnets.', filename)
magnets = []
try:
- with open(filename, 'r') as _file:
+ with open(filename) as _file:
magnets = list(filter(len, _file.read().splitlines()))
- except IOError as ex:
+ except OSError as ex:
log.warning('Unable to open %s: %s', filename, ex)
if len(magnets) < 2:
@@ -196,7 +196,7 @@ class Core(CorePluginBase):
try:
with open(mname, 'w') as _mfile:
_mfile.write(magnet)
- except IOError as ex:
+ except OSError as ex:
log.warning('Unable to open %s: %s', mname, ex)
return magnets
@@ -271,7 +271,7 @@ class Core(CorePluginBase):
try:
filedump = self.load_torrent(filepath, magnet)
- except (IOError, EOFError) as ex:
+ except (OSError, EOFError, InvalidTorrentError) as ex:
# If torrent is invalid, keep track of it so can try again on the next pass.
# This catches torrent files that may not be fully saved to disk at load time.
log.debug('Torrent is invalid: %s', ex)