Beispiel #1
0
    def __init__(mcs, name, bases, dict_):
        ParameterizedMetaclass.__init__(mcs, name, bases, dict_)
        mcs._parser = ReactiveHTMLParser(mcs)
        mcs._parser.feed(mcs._html)
        mcs._attrs, mcs._node_callbacks = {}, {}
        mcs._inline_callbacks = []
        for node, attrs in mcs._parser.attrs.items():
            for (attr, parameters, template) in attrs:
                param_attrs = []
                for p in parameters:
                    if p in mcs.param:
                        param_attrs.append(p)
                    elif hasattr(mcs, p):
                        if node not in mcs._node_callbacks:
                            mcs._node_callbacks[node] = []
                        mcs._node_callbacks[node].append((attr, p))
                        mcs._inline_callbacks.append((node, attr, p))
                    else:
                        matches = difflib.get_close_matches(p, dir(mcs))
                        raise ValueError("HTML template references unknown "
                                         f"parameter or method '{p}', "
                                         "similar parameters and methods "
                                         f"include {matches}.")
                if node not in mcs._attrs:
                    mcs._attrs[node] = []
                mcs._attrs[node].append((attr, param_attrs, template))
        ignored = list(Reactive.param) + list(mcs._parser.children.values())

        # Create model with unique name
        ReactiveHTMLMetaclass._name_counter[name] += 1
        model_name = f'{name}{ReactiveHTMLMetaclass._name_counter[name]}'
        mcs._data_model = construct_data_model(mcs,
                                               name=model_name,
                                               ignore=ignored)
Beispiel #2
0
 def __new__(mcs,classname,bases,classdict):
     if '__call__' in classdict:
         classdict['__call__'] = mcs._safecall(classdict['__call__'])
         #assert '_except' in classdic
     # else it is probably abstract, or something
     return ParameterizedMetaclass.__new__(mcs,classname,bases,classdict)
Beispiel #3
0
 def __new__(mcs, classname, bases, classdict):
     if '__call__' in classdict:
         classdict['__call__'] = mcs._safecall(classdict['__call__'])
         #assert '_except' in classdic
     # else it is probably abstract, or something
     return ParameterizedMetaclass.__new__(mcs, classname, bases, classdict)