def __new__(cls, name, bases, attrs):
        '''Add the fields in 'extended_fields to all 
        grandchildren of Extendable. Also connect the post_save signal
        to save the content_object.'''
        
        # get the inner Extend class
        class Extend: pass
        extend = attrs.setdefault('Extend', Extend)

        # Only do this for subclasses of Extendable
        if (name != "Extendable" or
        attrs['__module__'] != ExtendableMeta.__module__):

            # get the extended fields of the parents
            extended_fields = {}
            repl_kw = set()
            for base in bases:
                if isinstance(base, ExtendableMeta):
                    base_extend = getattr(base, "Extend", Extend)
                    # check for clashes in field names and replacement keywords
                    # and add to dict
                    for fname, fval in \
                    getattr(base_extend, "fields", {}).items():
                        field_cls, args, kwargs, args_repl, kwargs_repl = fval
                        if fname in extended_fields:
                            raise Exception(
                                "Extended field '%s' from %s " % (fname, base)
                                +"already defined in another parent of "
                                +"%s.%s" % (attrs['__module__'], name))
                        else:
                            clashes = set(args_repl).intersection(repl_kw)
                            clashes = clashes.union(set(kwargs_repl.values())\
                                .intersection(repl_kw))
                            if clashes:
                                raise Exception(
                                    "Replacement keywords '%s' " % clashes
                                    +"from %s already " % attrs['__module__']
                                    +"defined in another parent of %s.%s" % (
                                        name, base))
                            else:
                                extended_fields[fname] = fval
            
            # get the delegations, check that they are all in extended_fields
            delegations = getattr(extend, "redelegate", [])
            for d in delegations:
                if d not in extended_fields:
                    raise Exception(
                        "Redelegated field '%s' is not an extended" % d
                        +" field in any of %s.%s's parents." %(
                            attrs['__module__'], name))
                else:
                    # remove the field from the list to add to this class
                    # and put it in this class's inner Extend
                    extend.fields = getattr(extend, "fields", {})
                    extend.fields[d] = extended_fields[d]
                    del extended_fields[d]
            
            if extended_fields:
                # get replacements
                repl = getattr(extend, 'replacements', {})
                
                # create each field in the child, replacing when necessary
                for fname, fval in extended_fields.items():
                    # expand the information about the field
                    field_cls, args, kwargs, args_repl, kwargs_repl = fval

                    # check if there are any replacement for arguments
                    if args_repl:
                        if len(args_repl) != len(args):
                            raise Exception("Arguments list must be of the "
                                            + "same length as its replacement "
                                            + "keywords.")
                        z = zip(args, args_repl)
                        args = [repl[t[1]] \
                                if t[1] != None and t[1] in repl \
                                else t[0] for t in z]
                        
                    # check for keyword argument replacements
                    kwargs = kwargs.copy()
                    if kwargs_repl:
                        for repl_arg, repl_key in kwargs_repl.items():
                            if repl_key in repl:
                                kwargs[repl_arg] = repl[repl_key]
                    
                    # check for clashes
                    if fname in attrs:
                        raise Exception(
                            "Field '%s' clashes with extended field " % fname
                            +"in class %s.%s" % (attrs['__module__'], name))
                    
                    # now create the field in this class
                    attrs[fname] = field_cls(*args, **kwargs)
                
        new_cls = super(ExtendableMeta, cls).__new__(cls, name, bases, attrs)
        
        # connect the signal to save the content_object
        signals.post_save.connect(_extendable_post_save, new_cls)
        
        return new_cls
dataset/ETHPy150Open fp7-ofelia/ocf/optin_manager/src/python/openflow/common/extendable/models.py/ExtendableMeta.__new__/original