6 Superclass for constructors of custom tags defined in yaml file.
7 __str__ is overriden in subclass and used for serialization in module recorder.
9 def __init__(self, **kwargs):
10 self.__dict__.update(kwargs)
11 def __getitem__(self, key):
12 return getattr(self, key)
13 def __getattr__(self, attr):
16 return "<%s %s>" % (self.__class__.__name__, sorted(self.__dict__.items()))
18 class Assert(YamlTag):
19 def __init__(self, model, id=None, severity=logging.WARNING, string="NONAME", **kwargs):
22 self.severity = severity
24 super(Assert, self).__init__(**kwargs)
26 class Record(YamlTag):
27 def __init__(self, model, id, use='id', **kwargs):
30 super(Record, self).__init__(**kwargs)
32 return '!record {model: %s, id: %s}:' % (str(self.model,), str(self.id,))
34 class Python(YamlTag):
35 def __init__(self, model, severity=logging.WARNING, name="", **kwargs):
37 self.severity = severity
39 super(Python, self).__init__(**kwargs)
41 return '!python {model: %s}: |' % (str(self.model), )
43 class Menuitem(YamlTag):
44 def __init__(self, id, name, **kwargs):
47 super(Menuitem, self).__init__(**kwargs)
49 class Workflow(YamlTag):
50 def __init__(self, model, action, ref=None, **kwargs):
54 super(Workflow, self).__init__(**kwargs)
56 return '!workflow {model: %s, action: %s, ref: %s}' % (str(self.model,), str(self.action,), str(self.ref,))
58 class ActWindow(YamlTag):
59 def __init__(self, **kwargs):
60 super(ActWindow, self).__init__(**kwargs)
62 class Function(YamlTag):
63 def __init__(self, model, name, **kwargs):
66 super(Function, self).__init__(**kwargs)
68 class Report(YamlTag):
69 def __init__(self, model, name, string, **kwargs):
73 super(Report, self).__init__(**kwargs)
75 class Delete(YamlTag):
76 def __init__(self, **kwargs):
77 super(Delete, self).__init__(**kwargs)
79 class Context(YamlTag):
80 def __init__(self, **kwargs):
81 super(Context, self).__init__(**kwargs)
84 def __init__(self, **kwargs):
85 super(Url, self).__init__(**kwargs)
88 def __init__(self, expression):
89 self.expression = expression
90 super(Eval, self).__init__()
92 return '!eval %s' % str(self.expression)
95 def __init__(self, expr="False", *args, **kwargs):
97 super(Ref, self).__init__(*args, **kwargs)
99 return 'ref(%s)' % repr(self.expr)
101 class IrSet(YamlTag):
103 super(IrSet, self).__init__()
105 def assert_constructor(loader, node):
106 kwargs = loader.construct_mapping(node)
107 return Assert(**kwargs)
109 def record_constructor(loader, node):
110 kwargs = loader.construct_mapping(node)
111 return Record(**kwargs)
113 def python_constructor(loader, node):
114 kwargs = loader.construct_mapping(node)
115 return Python(**kwargs)
117 def menuitem_constructor(loader, node):
118 kwargs = loader.construct_mapping(node)
119 return Menuitem(**kwargs)
121 def workflow_constructor(loader, node):
122 kwargs = loader.construct_mapping(node)
123 return Workflow(**kwargs)
125 def act_window_constructor(loader, node):
126 kwargs = loader.construct_mapping(node)
127 return ActWindow(**kwargs)
129 def function_constructor(loader, node):
130 kwargs = loader.construct_mapping(node)
131 return Function(**kwargs)
133 def report_constructor(loader, node):
134 kwargs = loader.construct_mapping(node)
135 return Report(**kwargs)
137 def delete_constructor(loader, node):
138 kwargs = loader.construct_mapping(node)
139 return Delete(**kwargs)
141 def context_constructor(loader, node):
142 kwargs = loader.construct_mapping(node)
143 return Context(**kwargs)
145 def url_constructor(loader, node):
146 kwargs = loader.construct_mapping(node)
149 def eval_constructor(loader, node):
150 expression = loader.construct_scalar(node)
151 return Eval(expression)
153 def ref_constructor(loader, tag_suffix, node):
154 if tag_suffix == "id":
155 kwargs = {"id": loader.construct_scalar(node)}
157 kwargs = loader.construct_mapping(node)
160 def ir_set_constructor(loader, node):
161 kwargs = loader.construct_mapping(node)
162 return IrSet(**kwargs)
164 # Registers constructors for custom tags.
165 # Constructors are actually defined globally: do not redefined them in another
166 # class/file/package. This means that module recorder need import this file.
167 def add_constructors():
168 yaml.add_constructor(u"!assert", assert_constructor)
169 yaml.add_constructor(u"!record", record_constructor)
170 yaml.add_constructor(u"!python", python_constructor)
171 yaml.add_constructor(u"!menuitem", menuitem_constructor)
172 yaml.add_constructor(u"!workflow", workflow_constructor)
173 yaml.add_constructor(u"!act_window", act_window_constructor)
174 yaml.add_constructor(u"!function", function_constructor)
175 yaml.add_constructor(u"!report", report_constructor)
176 yaml.add_constructor(u"!context", context_constructor)
177 yaml.add_constructor(u"!delete", delete_constructor)
178 yaml.add_constructor(u"!url", url_constructor)
179 yaml.add_constructor(u"!eval", eval_constructor)
180 yaml.add_multi_constructor(u"!ref", ref_constructor)
181 yaml.add_constructor(u"!ir_set", ir_set_constructor)