|
1 | 1 | import re |
2 | | -import sifter.grammar |
3 | | -import sifter.validators |
4 | | -import sifter.grammar.notificationmethod |
5 | 2 | from sifter.grammar.command import Command |
| 3 | +from sifter.grammar.string import expand_variables |
6 | 4 | from sifter.validators.stringlist import StringList |
7 | 5 | from sifter.validators.tag import Tag |
| 6 | +from sifter.grammar.rule import RuleSyntaxError |
| 7 | +from sifter.extensions import ExtensionRegistry |
8 | 8 |
|
9 | 9 |
|
10 | 10 | # RFC 5435 |
@@ -33,27 +33,27 @@ def __init__(self, arguments=None, tests=None, block=None): |
33 | 33 | if 'options' in self.tagged_args: |
34 | 34 | self.notify_options = self.tagged_args['options'][1] |
35 | 35 | if 'message' in self.tagged_args: |
36 | | - self.notify_message = self.tagged_args['message'][1][0] |
37 | | - self.notify_method = self.positional_args[0][0] |
| 36 | + self.notify_message = self.tagged_args['message'][1][0] # type: ignore |
| 37 | + self.notify_method = self.positional_args[0][0] # type: ignore |
38 | 38 |
|
39 | 39 | def evaluate(self, message, state): |
40 | 40 | state.check_required_extension('enotify', 'NOTIFY') |
41 | | - notify_from = sifter.grammar.string.expand_variables(self.notify_from, state) |
42 | | - notify_importance = sifter.grammar.string.expand_variables(self.notify_importance, state) |
43 | | - notify_options = map(lambda s: sifter.grammar.string.expand_variables(s, state), self.notify_options) |
44 | | - notify_message = sifter.grammar.string.expand_variables(self.notify_message, state) |
45 | | - notify_method = sifter.grammar.string.expand_variables(self.notify_method, state) |
| 41 | + notify_from = expand_variables(self.notify_from, state) |
| 42 | + notify_importance = expand_variables(self.notify_importance, state) |
| 43 | + notify_options = map(lambda s: expand_variables(s, state), self.notify_options) |
| 44 | + notify_message = expand_variables(self.notify_message, state) |
| 45 | + notify_method = expand_variables(self.notify_method, state) |
46 | 46 |
|
47 | 47 | m = re.match('^([A-Za-z][A-Za-z0-9.+-]*):', notify_method) |
48 | 48 | if not m: |
49 | | - raise sifter.grammar.RuleSyntaxError("Notification method must be an URI, e.g. 'mailto:email@example.com'") |
| 49 | + raise RuleSyntaxError("Notification method must be an URI, e.g. 'mailto:email@example.com'") |
50 | 50 | if notify_importance and notify_importance not in ["1", "2", "3"]: |
51 | | - raise sifter.grammar.RuleSyntaxError("Illegal notify importance '%s' encountered" % self.notify_importance) |
52 | | - notify_method_cls = sifter.grammar.notificationmethod.get_cls(m.group(1).lower()) |
| 51 | + raise RuleSyntaxError("Illegal notify importance '%s' encountered" % self.notify_importance) |
| 52 | + notify_method_cls = ExtensionRegistry.get_notification_method(m.group(1).lower()) |
53 | 53 | if not notify_method_cls: |
54 | | - raise sifter.grammar.RuleSyntaxError("Unsupported notification method '%s'" % m.group(1)) |
| 54 | + raise RuleSyntaxError("Unsupported notification method '%s'" % m.group(1)) |
55 | 55 | (res, msg) = notify_method_cls.test_valid(notify_method) |
56 | 56 | if not res: |
57 | | - raise sifter.grammar.RuleSyntaxError(msg) |
| 57 | + raise RuleSyntaxError(msg) |
58 | 58 |
|
59 | 59 | state.actions.append('notify', (notify_method, notify_from, notify_importance, notify_options, notify_message)) |
0 commit comments