def _generate_constructor(cls, names, backend): gtype = cls.__gtype__ specs = cls.props body = CodeBlock() in_args = [] instances = [] backend.var.add_blacklist(names) for name in names: try: spec = getattr(specs, name) except AttributeError: raise TypeError("Property %r not supported" % name) type_ = spec._info.get_type() const = get_construct_class(type_) real_name = unescape_parameter(name) instance = const(real_name, type_, backend) instance.setup() instance.desc = "%s.%s property '%s'" % (cls.__module__, cls.__name__, real_name) instances.append(instance) in_args.append(name) block, out = instance.set(name) block.write_into(body) call_block, return_var = backend.get_constructor(gtype, instances) docstring = build_constructor_docstring(cls, instances) main, var = backend.parse(""" def _init_($values): '''$docstring''' $func_body $call_block return $return_var """, values=", ".join(in_args), call_block=call_block, func_body=body, return_var=return_var, docstring=docstring) func = main.compile()["_init_"] func._code = main return func
def _generate_constructor(cls, names, backend): gtype = cls.__gtype__ specs = cls.props body = CodeBlock() in_args = [] instances = [] backend.var.add_blacklist(names) for name in names: try: spec = getattr(specs, name) except AttributeError: raise TypeError("Property %r not supported" % name) type_ = spec._info.get_type() const = get_construct_class(type_) real_name = unescape_parameter(name) instance = const(real_name, type_, backend) instance.setup() instance.desc = "%s.%s property '%s'" % ( cls.__module__, cls.__name__, real_name) instances.append(instance) in_args.append(name) block, out = instance.set(name) block.write_into(body) call_block, return_var = backend.get_constructor(gtype, instances) docstring = build_constructor_docstring(cls, instances) main, var = backend.parse(""" def _init_($values): '''$docstring''' $func_body $call_block return $return_var """, values=", ".join(in_args), call_block=call_block, func_body=body, return_var=return_var, docstring=docstring) func = main.compile()["_init_"] func._code = main return func
def test_unescape_property(self): self.assertEqual(unescape_parameter("foo_"), "foo") self.assertEqual(unescape_parameter("fo_oo"), "fo-oo")