def pyfunctionfromclass(self, source, target):
    """Convert Class to function if class has stereotype function set.
    if not is_class_a_function(source):

    class_ = read_target_node(source,
    dec_keys = [ for dec in class_.decorators()]
    decorators = [class_.detach(key) for key in dec_keys]
    module = class_.parent
    container = module
    if not source.parent.stereotype('pyegg:pymodule'):
        container = module.parent['']
    functions = container.functions(class_.classname)
    if functions:
        if len(functions) > 1:
            raise "expected exactly one function by name '%s'" \
                % class_.classname
        function = functions[0]
        function = python.Function(class_.classname)
        function.__name__ = function.uuid
    del module[str(class_.uuid)]

    # resync target to function, class was deleted
    writesourcepath(source, function)
    write_source_to_target_mapping(source, function)

    tgv = TaggedValues(source)
    _args ='args', 'pyegg:function')
    _kwargs ='kwargs', 'pyegg:function')
    _code ='code', 'pyegg:function')
    if _args is not UNSET:
        function.s_args = _args
    if _kwargs is not UNSET:
        function.s_kwargs = _kwargs
    if _code is not UNSET:
        if not function.blocks():

    other_decorators = function.decorators()
    for dec in decorators:
        exists = 0
        for other in other_decorators:
            if dec.equals(other):
                exists = 1
        if exists:
        function[str(dec.uuid)] = dec
Esempio n. 2
 def finalize(self, source, target, set_anchor=True):
     writesourcepath(source, target)
     write_source_to_target_mapping(source, target)
     if set_anchor:
         self.anchor = target