--- my-gits/enigma2-plugins/autotimer/src/AutoTimerEditor.py 2022-11-02 12:43:17.325607470 +0000
+++ AT-Regex/AutoTimerEditor.py 2023-06-21 00:51:11.698200471 +0100
@@ -40,6 +40,11 @@
# Default Record Directory
from Tools import Directories
+# So we can check for a valid regex
+#
+from re import compile as re_compile
+from sys import version_info as pv_info
+
# Tags
try:
from Screens.TagEditor import TagEditor
@@ -1099,6 +1104,59 @@
def retval(self):
return self.returnVal
+# Check that a string/list of strings is/are valid regular expressions.
+# Returns the error message on an invalid regex.
+# Returns an empty string if all is OK
+#
+def CheckValidRegex(str_arg):
+ if not isinstance(str_arg, (list, tuple)):
+ str_arg = (str_arg,) # Make a tuple from a single string
+ try:
+ for val in str_arg:
+ dnc = re_compile(val)
+ except Exception as ex:
+ import traceback
+ estr = traceback.format_exception_only(ex)
+ errm = (_("The filter must be a valid regular expression.\n") +
+ _("%s is not valid.") % val +
+ "\n\n" + estr[0] + "\n" +
+ _("See: ") +
+ "https://docs.python.org/%d.%d/library/re.html" % (pv_info.major, pv_info.minor)
+ )
+ return errm
+ return ""
+
+# Extend the ConfigText class so we can check that we have a valid
+# regular expression before saving it.
+#
+class ConfigRegex(ConfigText):
+ def __init__(self, **kwargs):
+ if "err_timeout" in kwargs:
+ self.err_timeout = kwargs["err_timeout"]
+ del kwargs["err_timeout"]
+ else:
+ self.err_timeout = 5
+ if "rpt_session" in kwargs:
+ self.rpt_session = kwargs["rpt_session"]
+ del kwargs["rpt_session"]
+ else:
+ self.rpt_session = None
+ ConfigText.__init__(self, **kwargs)
+
+ def setValue(self, val):
+ errm = CheckValidRegex(val)
+ if errm != "":
+ if self.rpt_session:
+ self.rpt_session.open(
+ MessageBox,
+ errm,
+ type=MessageBox.TYPE_ERROR,
+ timeout=self.err_timeout
+ )
+ else:
+ print("[AutoTimerEditor::ConfigRegex]", errm)
+ return
+ ConfigText.setValue(self, val)
class AutoTimerFilterEditor(Screen, ConfigListScreen):
"""Edit AutoTimer Filter"""
@@ -1287,7 +1345,7 @@
if self.typeSelection.value == "day":
entry = getConfigListEntry(text, NoSave(ConfigSelection(choices=weekdays)))
else:
- entry = getConfigListEntry(text, NoSave(ConfigText(fixed_size=False)))
+ entry = getConfigListEntry(text, NoSave(ConfigRegex(rpt_session=self.session,fixed_size=False)))
list.insert(pos, entry)
self["config"].setList(list)
--- my-gits/enigma2-plugins/autotimer/src/AutoTimerResource.py 2022-11-02 12:43:17.325607470 +0000
+++ AT-Regex/AutoTimerResource.py 2023-06-21 00:49:39.892327324 +0100
@@ -16,6 +16,8 @@
from .AutoTimerSettings import getAutoTimerSettingsDefinitions
+from .AutoTimerEditor import CheckValidRegex
+
API_VERSION = "1.7"
@@ -410,6 +412,10 @@
description.remove('')
while '' in dayofweek:
dayofweek.remove('')
+# These must be valid regexes
+ errm = CheckValidRegex(title + shortdescription + description)
+ if errm != "":
+ return self.returnResult(req, False, errm)
timer.include = (title, shortdescription, description, dayofweek)
# Excludes
@@ -431,6 +437,10 @@
description.remove('')
while '' in dayofweek:
dayofweek.remove('')
+# These must be valid regexes
+ errm = CheckValidRegex(title + shortdescription + description)
+ if errm != "":
+ return self.returnResult(req, False, errm)
timer.exclude = (title, shortdescription, description, dayofweek)
tags = getA("tag")