This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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