|
9 | 9 | ) |
10 | 10 | import pkg_resources |
11 | 11 |
|
| 12 | + |
| 13 | +from sifter.grammar.comparator import Comparator |
| 14 | +from sifter.grammar.rule import Rule |
| 15 | +from sifter.grammar.command import Command |
| 16 | +from sifter.grammar.test import Test |
12 | 17 | if TYPE_CHECKING: |
13 | | - from sifter.grammar.rule import Rule |
14 | | - from sifter.grammar.comparator import Comparator |
| 18 | + from sifter.grammar.tag import Tag |
15 | 19 |
|
16 | 20 |
|
17 | 21 | class ExtensionRegistry(): |
@@ -39,6 +43,33 @@ def register_extension(cls, extension_name: Text) -> None: |
39 | 43 | def register_handler(cls, ext_cls: Union[Type['Comparator'], Type['Rule']]) -> None: |
40 | 44 | cls.register(ext_cls.handler_type(), ext_cls.handler_id(), ext_cls) |
41 | 45 |
|
| 46 | + @classmethod |
| 47 | + def get_comparator(cls, comparator: Union[Text, 'Tag']) -> Type['Comparator']: |
| 48 | + handler = cls.get('comparator', comparator) |
| 49 | + if not isinstance(handler, type) or not issubclass(handler, Comparator): |
| 50 | + raise ValueError('Wrong Comparator Type!') |
| 51 | + return handler |
| 52 | + |
| 53 | + @classmethod |
| 54 | + def get_command(cls, commandname: Text) -> Type['Command']: |
| 55 | + handler = cls.get('command', commandname) |
| 56 | + if not isinstance(handler, type) or not issubclass(handler, Command): |
| 57 | + raise ValueError('Wrong Command Type!') |
| 58 | + return handler |
| 59 | + |
| 60 | + @classmethod |
| 61 | + def get_test(cls, testname: Text) -> Type['Test']: |
| 62 | + handler = cls.get('test', testname) |
| 63 | + if not isinstance(handler, type) or not issubclass(handler, Test): |
| 64 | + raise ValueError('Wrong Test Type!') |
| 65 | + return handler |
| 66 | + |
| 67 | + @classmethod |
| 68 | + def has_extension(cls, ext_name: Text) -> bool: |
| 69 | + if cls.get('extension', ext_name): |
| 70 | + return True |
| 71 | + return False |
| 72 | + |
42 | 73 | @classmethod |
43 | 74 | def register( |
44 | 75 | cls, |
|
0 commit comments