As i mentioned in this previous post. Im trying to create a decorator which does the following:
The decorated class represents a document in a Documentbased DB like CouchDB or MongoDB. The Decorator accepts on argument which is a instance of a connector to such a database. The Model Class (in this example User) does automatically map undefined attributes to fields in the DB.
Now i get stuck a bit :-/ The mentioned things is all working. But now i cant call any methods from the Model Class. I'm getting the following error.
TypeError: unbound method myfunc() must be called with User instance as first argument (got nothing instead)
class Connector(object):
    def readvar(self, var):
        data = {"emailAddress":"jack.bauer@ctu.org", "lastName":"Bauer"}
        return data[var]
class DocumentDB(object):
    def __init__(self,connector):
        self.connector = connector
    def __call__(self, *args, **kargs):
        _c = self.connector
        class TransparentAttribute:         
            def __getattr__(self, attrname):
                try:
                    return _c.readvar(attrname)
                except:
                    return getattr(args[0], attrname)
        return TransparentAttribute
c = Connector()
@DocumentDB(c)
class User(object):
    username = "JackBauer"
    def doSomething(self):
        print "bla bla"
    def doSomethingElse(self):
        pass
    def myfunc(self):
        print "afadsadsf adsf asdf asdf"
u = User()
u.myfunc() # Does not work!!!
print u.emailAddress
print u.lastName
print u.username
 
     
     
    