Ejemplo n.º 1
0
 async def start(self, cookies, cookieopts=None):
     """
     Session start operation. First check among the cookies to find existed sessions;
     if there is not an existed session, create a new one.
     
     :param cookies: cookie header from the client
     
     :param cookieopts: extra options used when creating a new cookie
     
     :return: ``(session_handle, cookies)`` where session_handle is a SessionHandle object,
              and cookies is a list of created Set-Cookie headers (may be empty)
     """
     c = SimpleCookie(cookies)
     sid = c.get(self.cookiename)
     create = True
     if sid is not None:
         sh = await self.get(sid.value)
         if sh is not None:
             return (self.SessionHandle(sh, self.apiroutine), [])
     if create:
         sh = await self.create()
         m = Morsel()
         m.key = self.cookiename
         m.value = sh.id
         m.coded_value = sh.id
         opts = {'path': '/', 'httponly': True}
         if cookieopts:
             opts.update(cookieopts)
             if not cookieopts['httponly']:
                 del cookieopts['httponly']
         m.update(opts)
         return (sh, [m])
Ejemplo n.º 2
0
 def start(self, cookies, cookieopts=None):
     c = SimpleCookie(cookies)
     sid = c.get(self.cookiename)
     create = True
     if sid is not None:
         for m in self.get(sid.value):
             yield m
         if self.apiroutine.retvalue is not None:
             self.apiroutine.retvalue = (self.SessionHandle(self.apiroutine.retvalue, self.apiroutine), [])
             create = False
     if create:
         for m in self.create():
             yield m
         sh = self.apiroutine.retvalue
         m = Morsel()
         m.key = self.cookiename
         m.value = sh.id
         m.coded_value = sh.id
         opts = {"path": "/", "httponly": True}
         if cookieopts:
             opts.update(cookieopts)
             if not cookieopts["httponly"]:
                 del cookieopts["httponly"]
         m.update(opts)
         self.apiroutine.retvalue = (sh, [m])
Ejemplo n.º 3
0
 def start(self, cookies, cookieopts=None):
     c = SimpleCookie(cookies)
     sid = c.get(self.cookiename)
     create = True
     if sid is not None:
         for m in self.get(sid.value):
             yield m
         if self.apiroutine.retvalue is not None:
             self.apiroutine.retvalue = (self.SessionHandle(
                 self.apiroutine.retvalue, self.apiroutine), [])
             create = False
     if create:
         for m in self.create():
             yield m
         sh = self.apiroutine.retvalue
         m = Morsel()
         m.key = self.cookiename
         m.value = sh.id
         m.coded_value = sh.id
         opts = {'path': '/', 'httponly': True}
         if cookieopts:
             opts.update(cookieopts)
             if not cookieopts['httponly']:
                 del cookieopts['httponly']
         m.update(opts)
         self.apiroutine.retvalue = (sh, [m])
Ejemplo n.º 4
0
 def destroy(self, sessionid):
     for m in callAPI(self.apiroutine, "memorystorage", "delete", {"key": __name__ + "." + sessionid}):
         yield m
     m = Morsel()
     m.key = self.cookiename
     m.value = "deleted"
     m.coded_value = "deleted"
     opts = {"path": "/", "httponly": True, "max-age": 0}
     m.update(opts)
     self.apiroutine.retvalue = [m]
Ejemplo n.º 5
0
 def destroy(self, sessionid):
     for m in callAPI(self.apiroutine, 'memorystorage', 'delete',
                      {'key': __name__ + '.' + sessionid}):
         yield m
     m = Morsel()
     m.key = self.cookiename
     m.value = 'deleted'
     m.coded_value = 'deleted'
     opts = {'path': '/', 'httponly': True, 'max-age': 0}
     m.update(opts)
     self.apiroutine.retvalue = [m]
Ejemplo n.º 6
0
 async def destroy(self, sessionid):
     """
     Destroy a session
     
     :param sessionid: session ID
     
     :return: a list of Set-Cookie headers to be sent to the client
     """
     await call_api(self.apiroutine, 'memorystorage', 'delete',
                    {'key': __name__ + '.' + sessionid})
     m = Morsel()
     m.key = self.cookiename
     m.value = 'deleted'
     m.coded_value = 'deleted'
     opts = {'path': '/', 'httponly': True, 'max-age': 0}
     m.update(opts)
     return [m]