Use try-except instead of if statement to gain a little performance
This commit is contained in:
parent
c741e127b9
commit
7cc8243849
|
@ -553,11 +553,10 @@ class TorrentManager(component.Component):
|
||||||
:raises InvalidTorrentError: if the torrent_id is not in the session
|
:raises InvalidTorrentError: if the torrent_id is not in the session
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
if torrent_id not in self.torrents:
|
|
||||||
raise InvalidTorrentError("torrent_id not in session")
|
|
||||||
|
|
||||||
torrent_name = self.torrents[torrent_id].get_status(["name"])["name"]
|
torrent_name = self.torrents[torrent_id].get_status(["name"])["name"]
|
||||||
|
except KeyError:
|
||||||
|
raise InvalidTorrentError("torrent_id not in session")
|
||||||
|
|
||||||
# Emit the signal to the clients
|
# Emit the signal to the clients
|
||||||
component.get("EventManager").emit(PreTorrentRemovedEvent(torrent_id))
|
component.get("EventManager").emit(PreTorrentRemovedEvent(torrent_id))
|
||||||
|
@ -789,10 +788,10 @@ class TorrentManager(component.Component):
|
||||||
Cleans up after libtorrent folder renames.
|
Cleans up after libtorrent folder renames.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if torrent_id not in self.torrents:
|
try:
|
||||||
raise InvalidTorrentError("torrent_id is not in session")
|
|
||||||
|
|
||||||
info = self.torrents[torrent_id].get_status(['save_path'])
|
info = self.torrents[torrent_id].get_status(['save_path'])
|
||||||
|
except KeyError:
|
||||||
|
raise InvalidTorrentError("torrent_id not in session")
|
||||||
# Regex removes leading slashes that causes join function to ignore save_path
|
# Regex removes leading slashes that causes join function to ignore save_path
|
||||||
folder_full_path = os.path.join(info['save_path'], re.sub("^/*", "", folder))
|
folder_full_path = os.path.join(info['save_path'], re.sub("^/*", "", folder))
|
||||||
folder_full_path = os.path.normpath(folder_full_path)
|
folder_full_path = os.path.normpath(folder_full_path)
|
||||||
|
|
Loading…
Reference in New Issue