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', view=True, **kwargs):
31 super(Record, self).__init__(**kwargs)
33 return '!record {model: %s, id: %s}:' % (str(self.model,), str(self.id,))
35 class Python(YamlTag):
36 def __init__(self, model, severity=logging.ERROR, name="", **kwargs):
38 self.severity = severity
40 super(Python, self).__init__(**kwargs)
42 return '!python {model: %s}: |' % (str(self.model), )
44 class Menuitem(YamlTag):
45 def __init__(self, id, name, **kwargs):
48 super(Menuitem, self).__init__(**kwargs)
50 class Workflow(YamlTag):
51 def __init__(self, model, action, ref=None, **kwargs):
55 super(Workflow, self).__init__(**kwargs)
57 return '!workflow {model: %s, action: %s, ref: %s}' % (str(self.model,), str(self.action,), str(self.ref,))
59 class ActWindow(YamlTag):
60 def __init__(self, **kwargs):
61 super(ActWindow, self).__init__(**kwargs)
63 class Function(YamlTag):
64 def __init__(self, model, name, **kwargs):
67 super(Function, self).__init__(**kwargs)
69 class Report(YamlTag):
70 def __init__(self, model, name, string, **kwargs):
74 super(Report, self).__init__(**kwargs)
76 class Delete(YamlTag):
77 def __init__(self, **kwargs):
78 super(Delete, self).__init__(**kwargs)
80 class Context(YamlTag):
81 def __init__(self, **kwargs):
82 super(Context, self).__init__(**kwargs)
85 def __init__(self, **kwargs):
86 super(Url, self).__init__(**kwargs)
89 def __init__(self, expression):
90 self.expression = expression
91 super(Eval, self).__init__()
93 return '!eval %s' % str(self.expression)
96 def __init__(self, expr="False", *args, **kwargs):
98 super(Ref, self).__init__(*args, **kwargs)
100 return 'ref(%s)' % repr(self.expr)
102 class IrSet(YamlTag):
104 super(IrSet, self).__init__()
106 def assert_constructor(loader, node):
107 kwargs = loader.construct_mapping(node)
108 return Assert(**kwargs)
110 def record_constructor(loader, node):
111 kwargs = loader.construct_mapping(node)
112 return Record(**kwargs)
114 def python_constructor(loader, node):
115 kwargs = loader.construct_mapping(node)
116 return Python(**kwargs)
118 def menuitem_constructor(loader, node):
119 kwargs = loader.construct_mapping(node)
120 return Menuitem(**kwargs)
122 def workflow_constructor(loader, node):
123 kwargs = loader.construct_mapping(node)
124 return Workflow(**kwargs)
126 def act_window_constructor(loader, node):
127 kwargs = loader.construct_mapping(node)
128 return ActWindow(**kwargs)
130 def function_constructor(loader, node):
131 kwargs = loader.construct_mapping(node)
132 return Function(**kwargs)
134 def report_constructor(loader, node):
135 kwargs = loader.construct_mapping(node)
136 return Report(**kwargs)
138 def delete_constructor(loader, node):
139 kwargs = loader.construct_mapping(node)
140 return Delete(**kwargs)
142 def context_constructor(loader, node):
143 kwargs = loader.construct_mapping(node)
144 return Context(**kwargs)
146 def url_constructor(loader, node):
147 kwargs = loader.construct_mapping(node)
150 def eval_constructor(loader, node):
151 expression = loader.construct_scalar(node)
152 return Eval(expression)
154 def ref_constructor(loader, tag_suffix, node):
155 if tag_suffix == "id":
156 kwargs = {"id": loader.construct_scalar(node)}
158 kwargs = loader.construct_mapping(node)
161 def ir_set_constructor(loader, node):
162 kwargs = loader.construct_mapping(node)
163 return IrSet(**kwargs)
165 # Registers constructors for custom tags.
166 # Constructors are actually defined globally: do not redefined them in another
167 # class/file/package. This means that module recorder need import this file.
168 def add_constructors():
169 yaml.add_constructor(u"!assert", assert_constructor)
170 yaml.add_constructor(u"!record", record_constructor)
171 yaml.add_constructor(u"!python", python_constructor)
172 yaml.add_constructor(u"!menuitem", menuitem_constructor)
173 yaml.add_constructor(u"!workflow", workflow_constructor)
174 yaml.add_constructor(u"!act_window", act_window_constructor)
175 yaml.add_constructor(u"!function", function_constructor)
176 yaml.add_constructor(u"!report", report_constructor)
177 yaml.add_constructor(u"!context", context_constructor)
178 yaml.add_constructor(u"!delete", delete_constructor)
179 yaml.add_constructor(u"!url", url_constructor)
180 yaml.add_constructor(u"!eval", eval_constructor)
181 yaml.add_multi_constructor(u"!ref", ref_constructor)
182 yaml.add_constructor(u"!ir_set", ir_set_constructor)
186 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: