def test_ifdefaultisFalse_withextension(self): f=opaque([ 'public' ], [ ] , default=False, allowExtension=True )(self.initClass())(2) self.assertTrue(hasattr(f,'__dict__')) # because has allow_extension self.assertRaiseRuntimeError(f,'secret') self.assertTrue(hasattr(f,'public')) with self.assertRaises(RuntimeError) as cm: f.__class__.__bases__[0].__getattr__(f,'secret')
def opaquer(aClassObject,aField): return opaque([ aField ], [] , default=False, allowExtension=True )(aClassObject)
class A(): def __init__(self,q): self.secret = q self.public = q class B(object): def __init__(self,q): self.secret = q self.public = q def opaquer(aClassObject,aField): return opaque([ aField ], [] , default=False, allowExtension=True )(aClassObject) A = opaquer(A,'public') B = opaque([ 'public' ], [ 'secret' ] , True )(B) class C(B): pass class D(object): def __init__(self,q): self.secret=q self.public=q def __call__(self): return self.secret D=opaque([ 'public' ], [ 'secret' ] , True )(D) class E(object): def __init__(self,q):
import md5 class password(): def __init__(self,password): self.password = md5.new(password).digest() self.triesLeft = 3 self.username = "******" def checkPassword(self,guessPassword): if (self.triesLeft == 0): print "No more tries left!" return if self.password == md5.new(guessPassword).digest(): self.triesLeft = 3 print 'very good!' else: print 'wrong!' self.triesLeft -= 1 '''Uncomment the following lines to protect the password field''' from opaque import opaque password=opaque(['checkPassword','username'], ['password','triesLeft'] , True )(password) pass1=password('thisisasecret')