I have two classes with similar first checking codes, but different behaviors. I suppose there is a way to refactor the code, so I don't need to retype it every time.  Is it possible to refactor this, or I must retype this code every time?# Get actual logged useruser, msg = checkLoggedUser()if user:    self.renderPage(customMessage.htm, custom_msg=msg)else:The code is simple. Forget about my way to render the page, is a method over my own PageHandler class that works.# Check for actual logged userdef checkLoggedUser():    # Get actual logged user    user = users.get_current_user()    # Don't allow to register for a logged user    if user:        return True, You are already logged in.    else:        return False, None# Get and post for the login pageclass Login(custom.PageHandler):    def get(self):        # Get actual logged user        user, msg = checkLoggedUser()        if user:            self.renderPage(customMessage.htm, custom_msg=msg)        else:            self.renderPage('login.htm')    def post(self):        # Get actual logged user        user, msg = checkLoggedUser()        if user:            self.renderPage(customMessage.htm, custom_msg=msg)        else:            # Make the login            # bla, bla bla... code for login the user.# Get and post for the register pageclass Register(custom.PageHandler):    def get(self):        # Get actual logged user        user, msg = checkLoggedUser()        if user:            self.renderPage(customMessage.htm, custom_msg=msg)        else:            self.renderPage(registerUser.htm)    def post(self):        # Get actual logged user        user, msg = checkLoggedUser()        if user:            self.renderPage(customMessage.htm, custom_msg=msg)        else:            # Store in vars the form values            # bla, bla bla... code for register the user.
Checking for a logged user
python;logging
Create a classclass MyPageHandler(custom.PageHandler):     def veryUserNotLoggedIn(self):         if users.getCurrentUser():             self.renderPage(customMessage.htm, custom_msg=msg)             return False         else:             return TrueThen you can write you class likeclass Login(MyPageHandler):    def get(self):        if self.verifyUserNotLoggedIn():             self.renderPage('login.htm')