code: def login_required(f):
      '''
      Definition decorator for all function requiring an active session
      Credit: http://stackoverflow.com/a/7590709
      '''
      def _wrapper(self, *args, **kwargs):
          '''
          Function to be applied on top of all decorated methods
          '''
          if self._token_age:
              timediff = self._token_age - datetime.datetime.now()
              if timediff.total_seconds() / 60 > TOKEN_TIMEOUT:
                  self.logout()  # Log out to invalidate previous token
                  self.login()  # Request new token
          else:  # haven't logged in yet
              self.login()
          return f(self, *args, **kwargs)
      return _wrappef login_required(f):
      '''
      Definition decorator for all function requiring an active session
      Credit: http://stackoverflow.com/a/7590709
      '''
      def _wrapper(self, *args, **kwargs):
          '''
          Function to be applied on top of all decorated methods
          '''
          if self._token_age:
              timediff = self._token_age - datetime.datetime.now()
              if timediff.total_seconds() / 60 > TOKEN_TIMEOUT:
                  self.logout()  # Log out to invalidate previous token
                  self.login()  # Request new token
          else:  # haven't logged in yet
              self.login()
          return f(self, *args, **kwargs)
      return _wrapper
docs: Definition decorator for all function requiring an active session
      Credit: http://stackoverflow.com/a/7590709