def __new__(cls, source, *p, **n):
        '''
        this will create a proxy, wrap the target and return the result... 
        else return the target.
        '''
        osetattr = object.__setattr__
        cls_name = cls.__name__
        try:
            # process proxy cache...
            _obj = cls._getcached(source)
            if _obj != None:
                return _obj
            # create an object of a class (also just created) inherited
            # from cls and source.__class__
            _obj = object.__new__(new.classobj('',(cls, source.__class__), {}))
            # get the new class....
            cls = object.__getattribute__(_obj, '__class__')
            # name the new class... 
            # NOTE: the name may not be unique!
            cls.__name__ = cls_name + '_' + str(cls.__proxy_count__)
            cls.__proxy_count__ += 1
            # considering that the class we just created is unique we
            # can use it as a data store... (and we do not want to
            # pollute the targets dict :) )
            setattr(cls, cls.__proxy_target_attr_name__, source)
            # replace the dict so that the proxy behaves exactly like
            # the target...
            osetattr(_obj, '__dict__', source.__dict__)
        # we fall here in case we either are a class constructor, function or a callable....
        # WARNING: this might be Python implementation specific!!
        except (TypeError, AttributeError), e:
            # function or callable
            if type(source) in (types.FunctionType, types.LambdaType, \
                                    types.MethodType, weakref.CallableProxyType):
                # callable wrapper hook...
                if hasattr(cls, '__proxy_call__') and cls.__proxy_call__ != None:
                    return cls.__proxy_call__(source)
                return source
            # class (nested class constructors...)
            elif callable(source):
                # class wrapper hook...
                if hasattr(cls, '__proxy_class__') and cls.__proxy_class__ != None:
                    return cls.__proxy_class__(source)
                return source
            return source
        # process proxy cache...
        cls._setcache(source, _obj)
        return _obj

        this will create a proxy, wrap the target and return the result... 
        else return the target.
        
recipes/Python/305308_mixins_for_proxy_construction/recipe-305308.py