Last active
December 20, 2015 09:29
-
-
Save mitgr81/6107903 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
class BaseClass(object): | |
bar = 'baz' | |
class PantsMixin(object): | |
@property | |
def public_attrs(self): | |
start = self._public_attrs | |
start.update({'for more info': 'GET THEE SOME ACCESSES!'}) | |
return start | |
@property | |
def private_attrs(self): | |
start = self._private_attrs | |
start.update({'and even more things': True}) | |
return start | |
def serialize(self, access=False): | |
if access: | |
return self.private_attrs | |
return self.public_attrs if self.ext == 'banana' else {'banana mode!!!': 'activated'} | |
def __iter__(self): | |
return self.serialize().iteritems() | |
class Foo(BaseClass, PantsMixin): | |
def __init__(self): | |
self.ber = 'bor' | |
self.ext = 'banana' | |
self._private_attrs = {'private_bar': self.bar + self.ber, 'ber': self.ber} | |
self._public_attrs = {'bar': self.bar} | |
if __name__ == '__main__': | |
f = Foo() | |
print(dict(f)) | |
print(f.serialize(access=True)) | |
f.ext = 'definintely not a banana' | |
print(dict(f)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment