Skip to content

Instantly share code, notes, and snippets.

@miki725
Created Mar 12, 2018
Embed
What would you like to do?
def SimpleProxy(subject):
def __getattribute__(self, item):
print(item)
if item == '__subject__':
return object.__getattribute__(self, item)
return getattr(self.__subject__, item)
attrs = {}
def make_getter(i):
def getter(self, *args, **kwargs):
print(i)
return getattr(self.__subject__, i)(*args, **kwargs)
return getter
for i in dir(subject):
if not (i.startswith('__') and i.endswith('__')) or i in ['__new__', '__init__']:
continue
attrs[i] = make_getter(i)
attrs.update({
'__subject__': subject,
'__getattribute__': __getattribute__,
})
return type(str('SimpleProxy'), (object,), attrs)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment