I have a Request handler and a decorator, I would like to work with the self object inside the decorator
class MyHandler(webapp.RequestHandler):
    @myDecorator
        def get(self):
            #code
Update: Please notice the difference between the first and second self
class myDecorator(object):
    def __init__(self, f):
        self.f = f
    def __call__(self):
        #work with self
- MyHandler>- get( function ) >- self( argument )
- myDecorator>- __call__( function ) >- self( argument )
the self arguments mentioned above are different. My intention is to access the first self from inside __call__ function, or find a way to do something similar.
Hi can I access MyHandlers self argument from get function inside the decorator?
Update2: I want to implement a decorator to work with a custom login in google app engine:
I have a class ( requestHandler ):
class SomeHandler(webapp.RequestHandler):
    @only_registered_users
    def get(self):
        #do stuff here
And I want to decorate the get function in order to check out if the user is logged in or not:
from util.sessions import Session
import logging
class only_registered_users(object):
    def __init__(self, f):
        self.f = f
    def __call__(self):
        def decorated_get(self):
        logging.debug("request object:", self.request)
        session = Session()
        if hasattr(session, 'user_key'):
            return self.f(self)
        else:
            self.request.redirect("/login")
    return decorated_get
I know if a user is logged in if has the property 'user_key' in a session Object.
That's the main goal I'm interested in on this specific case
Let me know your suggestions / opinions if I'm doing something wrong!
Thanks!
 
     
     
     
     
     
     
    