def proxy(obj, names):
    """Factory function for Proxies that can delegate magic names."""
    #Build class.
    cls = type("%sProxy" % obj.__class__.__name__,
               (Proxy,),
               {})
    #Add magic names.
    for name in names:
        #Filter magic names.
        if name.startswith("__") and name.endswith("__"):
            if hasattr(obj.__class__, name):
                #Set attribute.
                setattr(cls, name, getter(name))
    #Return instance.
    return cls(obj)
Factory function for Proxies that can delegate magic names.
recipes/Python/252151_Generalized_delegates/recipe-252151.py