mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-08 01:18:39 +00:00
label.core: assert->checkinput , regexp for label_id
This commit is contained in:
parent
421c439c21
commit
ceafbfd990
1 changed files with 21 additions and 9 deletions
|
@ -40,6 +40,12 @@ from deluge.configmanager import ConfigManager
|
||||||
|
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
|
|
||||||
|
import traceback
|
||||||
|
import re
|
||||||
|
|
||||||
|
RE_VALID = re.compile("[a-z0-9_-]*\Z")
|
||||||
|
RE_VALID = re.compile("[a-z0-9_-]*\Z")
|
||||||
|
|
||||||
KNOWN_STATES = ['Downloading','Seeding','Paused','Checking','Allocating','Queued','Error']
|
KNOWN_STATES = ['Downloading','Seeding','Paused','Checking','Allocating','Queued','Error']
|
||||||
STATE = "state"
|
STATE = "state"
|
||||||
TRACKER = "tracker"
|
TRACKER = "tracker"
|
||||||
|
@ -55,7 +61,11 @@ OPTIONS_KEYS = ["max_download_speed", "max_upload_speed",
|
||||||
"max_connections", "max_upload_slots", "prioritize_first_last"]
|
"max_connections", "max_upload_slots", "prioritize_first_last"]
|
||||||
NO_LABEL = "No Label"
|
NO_LABEL = "No Label"
|
||||||
|
|
||||||
import traceback
|
|
||||||
|
def CheckInput(cond, message):
|
||||||
|
if not cond:
|
||||||
|
raise Exception(message)
|
||||||
|
|
||||||
|
|
||||||
class Core(CorePluginBase):
|
class Core(CorePluginBase):
|
||||||
def enable(self):
|
def enable(self):
|
||||||
|
@ -251,8 +261,11 @@ class Core(CorePluginBase):
|
||||||
"""add a label
|
"""add a label
|
||||||
see label_set_options for more options.
|
see label_set_options for more options.
|
||||||
"""
|
"""
|
||||||
assert label_id
|
label_id = label_id.lower()
|
||||||
assert not (label_id in self.labels)
|
CheckInput(RE_VALID.match(label_id) , _("Invalid label, valid characters:[a-z0-9_-]"))
|
||||||
|
CheckInput(label_id, _("Empty Label"))
|
||||||
|
CheckInput(not (label_id in self.labels) , _("Unknown Label"))
|
||||||
|
|
||||||
|
|
||||||
#default to current global per-torrent settings.
|
#default to current global per-torrent settings.
|
||||||
self.labels[label_id] = {
|
self.labels[label_id] = {
|
||||||
|
@ -265,7 +278,7 @@ class Core(CorePluginBase):
|
||||||
|
|
||||||
def export_remove(self, label_id):
|
def export_remove(self, label_id):
|
||||||
"remove a label"
|
"remove a label"
|
||||||
assert label_id in self.labels
|
CheckInput(label_id in self.labels, _("Unknown Label"))
|
||||||
del self.labels[label_id]
|
del self.labels[label_id]
|
||||||
self.clean_config()
|
self.clean_config()
|
||||||
self.config.save()
|
self.config.save()
|
||||||
|
@ -283,7 +296,7 @@ class Core(CorePluginBase):
|
||||||
|
|
||||||
apply : applies download-options to all torrents currently labelled by label_id
|
apply : applies download-options to all torrents currently labelled by label_id
|
||||||
"""
|
"""
|
||||||
assert label_id in self.labels
|
CheckInput(not (label_id in self.labels) , _("Unknown Label"))
|
||||||
for key in options_dict.keys():
|
for key in options_dict.keys():
|
||||||
if not key in OPTIONS_KEYS:
|
if not key in OPTIONS_KEYS:
|
||||||
raise Exception("label: Invalid options_dict key:%s" % key)
|
raise Exception("label: Invalid options_dict key:%s" % key)
|
||||||
|
@ -314,10 +327,9 @@ class Core(CorePluginBase):
|
||||||
"""
|
"""
|
||||||
if label_id == NO_LABEL:
|
if label_id == NO_LABEL:
|
||||||
label_id = None
|
label_id = None
|
||||||
log.debug(torrent_id)
|
|
||||||
log.debug(self.torrents.keys())
|
CheckInput((not label_id) or (label_id in self.labels) , _("Unknown Label"))
|
||||||
assert (not label_id) or (label_id in self.labels)
|
CheckInput(torrent_id in self.torrents , _("Unknown Torrent"))
|
||||||
assert torrent_id in self.torrents
|
|
||||||
|
|
||||||
if not label_id:
|
if not label_id:
|
||||||
if torrent_id in self.torrent_labels:
|
if torrent_id in self.torrent_labels:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue