Ejemplo n.º 1
0
class BaseHandler(tornado.web.RequestHandler):
    escape = tornado.escape

    def render(selfb, template_name, __d={}, **kwargs):
        __d = __d or kwargs
        __d.pop('self', 0)
        super(BaseHandler, selfb).render(template_name, **__d)

    def get_session_id(self):
        sid = self.get_secure_cookie('sid')
        if not sid:
            sid = uuid.uuid4().get_hex()
            self.set_secure_cookie('sid', sid)
        #print sid
        return sid

    def initialize(self):
        self.session = Session(self.get_session_id())
        if DEBUG:
            print 'initialize' + '-' * 40
            #print self.cookies
            #print self.request
            #print self._headers
            print self.request.headers
        self._st = time.time()
        self.log = DEBUG

    def prepare(self, *args, **kwargs):  #开始都会运行
        print 'prepare' + '-' * 40

    def on_finish(self):  #结束都会运行
        if self.log:
            print 'log' + '-' * 40
        self.session.save()
Ejemplo n.º 2
0
class BaseHandler(tornado.web.RequestHandler):
    escape = tornado.escape
    def render(selfb,template_name,__d={},**kwargs):
            __d = __d or kwargs
            __d.pop('self',0)
            super(BaseHandler,selfb).render(template_name,**__d)

    def get_session_id(self):
        sid = self.get_secure_cookie('sid')
        if not sid:
            sid =  uuid.uuid4().get_hex()
            self.set_secure_cookie('sid',sid)
        #print sid
        return sid
    def initialize(self):
        self.session = Session(self.get_session_id())
        if DEBUG:
            print 'initialize' + '-' * 40
            #print self.cookies
            #print self.request
            #print self._headers
            print self.request.headers
        self._st = time.time()
        self.log = DEBUG

    def prepare(self,*args,**kwargs):#开始都会运行
        print 'prepare' + '-' * 40


    def on_finish(self):#结束都会运行
        if self.log:
            print 'log'+'-'*40
        self.session.save()
Ejemplo n.º 3
0
class BaseHandler(tornado.web.RequestHandler):
    escape = tornado.escape

    def render(selfb, template_name, __d={}, **kwargs):
        __d = __d or kwargs
        __d.pop('self', 0)
        super(BaseHandler, selfb).render(template_name, **__d)

    def get_session_id(self):
        sid = self.get_secure_cookie('sid')
        if not sid:
            sid = uuid.uuid4().get_hex()
            self.set_secure_cookie('sid', sid)

        return sid

    def initialize(self):
        self._st = time.time()
        self.session = Session(self.get_session_id(), self)

    def prepare(self, *args, **kwargs):
        """
        开始都会运行
        :param args:
        :param kwargs:
        :return:
        """
        pass

    def finish(self, *args, **kwargs):
        self.session.save(SESSION_EXPIRE_TIME)
        super(BaseHandler, self).finish(*args, **kwargs)

    def on_finish(self):
        """
        结束都会运行

        :return:
        """
        pass