Mercurial > repos > dcouvin > resfinder4
comparison resfinder/cge/out/parserdict.py @ 0:55051a9bc58d draft default tip
Uploaded
author | dcouvin |
---|---|
date | Mon, 10 Jan 2022 20:06:07 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:55051a9bc58d |
---|---|
1 #!/usr/bin/env python3 | |
2 | |
3 from .valueparsers import ValueParsers | |
4 | |
5 | |
6 class ParserDict(dict): | |
7 | |
8 def __init__(self, input_parser=None): | |
9 | |
10 if(input_parser is None): | |
11 parser_class = ValueParsers | |
12 else: | |
13 parser_class = input_parser.__class__ | |
14 | |
15 val_parser_list = self.get_method_names(parser_class) | |
16 | |
17 for parser in val_parser_list: | |
18 if(parser.startswith("parse_")): | |
19 parse_key = parser[6:] | |
20 self[parse_key] = getattr(parser_class, parser) | |
21 else: | |
22 raise SyntaxError(("A function in the {} class did " | |
23 "not start with 'parse_'. Function is " | |
24 "named: {}" | |
25 .format(parser_class.__name__, parser))) | |
26 | |
27 @staticmethod | |
28 def get_method_names(cls): | |
29 return [func for func in dir(cls) if(callable(getattr(cls, func)) | |
30 and not func.startswith("__"))] |