Exemple #1
0
 def getChild(self, path, request):
     if not request.prepath:
         return None
     cookie = request.getCookie(self.cookieKey)
     setupURL = urlToChild(request, INIT_SESSION, *([path] + request.postpath))
     request.setupSessionURL = setupURL
     request.setupSession = lambda: Redirect(setupURL)
     if path.startswith(SESSION_KEY):
         key = path[len(SESSION_KEY) :]
         if key not in self.sessions:
             return redirectToSession(request, "__start_session__")
         self.sessions[key].setLifetime(self.sessionLifetime)
         if cookie == key:
             return redirectToSession(request, "__session_just_started__")
         else:
             _setSession(self, request, key)
             return self.resource
     elif cookie in self.sessions:
         _setSession(self, request, cookie)
         return getResource(self.resource, path, request)
     elif path == INIT_SESSION:
         newCookie = _sessionCookie()
         request.addCookie(self.cookieKey, newCookie, path="/")
         self.sessions[newCookie] = GuardSession(self, newCookie)
         sz = self.sessions[newCookie]
         sz.checkExpired()
         rd = Redirect(urlToChild(request, SESSION_KEY + newCookie, *request.postpath))
         rd.isLeaf = 1
         return rd
     else:
         request.getSession = lambda interface=None: None
         return getResource(self.resource, path, request)
Exemple #2
0
 def getChild(self, path, request):
     if not request.prepath:
         return None
     cookie = request.getCookie(self.cookieKey)
     setupURL = urlToChild(request, INIT_SESSION,
                           *([path] + request.postpath))
     request.setupSessionURL = setupURL
     request.setupSession = lambda: Redirect(setupURL)
     if path.startswith(SESSION_KEY):
         key = path[len(SESSION_KEY):]
         if key not in self.sessions:
             return redirectToSession(request, '__start_session__')
         self.sessions[key].setLifetime(self.sessionLifetime)
         if cookie == key:
             # /sessionized-url/${SESSION_KEY}aef9c34aecc3d9148/foo
             #                  ^
             #                  we are this getChild
             # with a matching cookie
             return redirectToSession(request, '__session_just_started__')
         else:
             # We attempted to negotiate the session but failed (the user
             # probably has cookies disabled): now we're going to return the
             # resource we contain.  In general the getChild shouldn't stop
             # there.
             # /sessionized-url/${SESSION_KEY}aef9c34aecc3d9148/foo
             #                  ^ we are this getChild
             # without a cookie (or with a mismatched cookie)
             _setSession(self, request, key)
             return self.resource
     elif cookie in self.sessions:
         # /sessionized-url/foo
         #                 ^ we are this getChild
         # with a session
         _setSession(self, request, cookie)
         return getResource(self.resource, path, request)
     elif path == INIT_SESSION:
         # initialize the session
         # /sessionized-url/session-init
         #                  ^ this getChild
         # without a session
         newCookie = _sessionCookie()
         request.addCookie(self.cookieKey, newCookie, path="/")
         sz = self.sessions[newCookie] = GuardSession(self, newCookie)
         sz.checkExpired()
         rd = Redirect(
             urlToChild(request, SESSION_KEY + newCookie,
                        *request.postpath))
         rd.isLeaf = 1
         return rd
     else:
         # /sessionized-url/foo
         #                 ^ we are this getChild
         # without a session
         request.getSession = lambda interface=None: None
         return getResource(self.resource, path, request)
Exemple #3
0
 def getChild(self, path, request):
     if not request.prepath:
         return None
     cookie = request.getCookie(self.cookieKey)
     setupURL = urlToChild(request, INIT_SESSION, *([path]+request.postpath))
     request.setupSessionURL = setupURL
     request.setupSession = lambda: Redirect(setupURL)
     if path.startswith(SESSION_KEY):
         key = path[len(SESSION_KEY):]
         if key not in self.sessions:
             return redirectToSession(request, '__start_session__')
         self.sessions[key].setLifetime(self.sessionLifetime)
         if cookie == key:
             # /sessionized-url/${SESSION_KEY}aef9c34aecc3d9148/foo
             #                  ^
             #                  we are this getChild
             # with a matching cookie
             return redirectToSession(request, '__session_just_started__')
         else:
             # We attempted to negotiate the session but failed (the user
             # probably has cookies disabled): now we're going to return the
             # resource we contain.  In general the getChild shouldn't stop
             # there.
             # /sessionized-url/${SESSION_KEY}aef9c34aecc3d9148/foo
             #                  ^ we are this getChild
             # without a cookie (or with a mismatched cookie)
             _setSession(self, request, key)
             return self.resource
     elif cookie in self.sessions:
         # /sessionized-url/foo
         #                 ^ we are this getChild
         # with a session
         _setSession(self, request, cookie)
         return getResource(self.resource, path, request)
     elif path == INIT_SESSION:
         # initialize the session
         # /sessionized-url/session-init
         #                  ^ this getChild
         # without a session
         newCookie = _sessionCookie()
         request.addCookie(self.cookieKey, newCookie, path="/")
         sz = self.sessions[newCookie] = GuardSession(self, newCookie)
         sz.checkExpired()
         rd = Redirect(urlToChild(request, SESSION_KEY+newCookie,
                                           *request.postpath))
         rd.isLeaf = 1
         return rd
     else:
         # /sessionized-url/foo
         #                 ^ we are this getChild
         # without a session
         request.getSession = lambda interface=None: None
         return getResource(self.resource, path, request)
Exemple #4
0
 def getChild(self, path, request):
     # XXX refactor with PerspectiveWrapper
     if not request.prepath:
         return None
     pp = request.prepath.pop()
     _urlToMe = request.prePathURL()
     request.prepath.append(pp)
     def urlToChild(*ar):
         c = '/'.join(ar)
         if _urlToMe[-1] == '/':
             # this SHOULD only happen in the case where the URL is just the hostname
             return _urlToMe + c
         else:
             return _urlToMe + '/' + c
     # XXX
     # print "I think I'm at:", _urlToMe
     cookie = request.getCookie(self.cookieKey)
     setupURL = request.setupSessionURL = urlToChild(INIT_SESSION, *([path]+request.postpath))
     request.setupSession = lambda: Redirect(setupURL)
     if self.sessions.has_key(path):
         self.sessions[path].setLifetime(1800)
         if cookie == path:
             # /sessionized-url/aef9c34aecc3d9148/foo
             #                  ^
             #                  we are this getChild
             # with a matching cookie
             rd = Redirect(urlToChild(*request.postpath) +
                           # this next bit prevents 'redirect cycles' in
                           # wget (and possibly other browsers)
                           "?__session_just_started__=1")
             rd.isLeaf = 1
             return rd
         else:
             # We attempted to negotiate the session but failed (the user
             # probably has cookies disabled): now we're going to return the
             # resource we contain.  In general the getChild shouldn't stop
             # there.
             # /sessionized-url/aef9c34aecc3d9148/foo
             #                 ^ we are this getChild
             # without a cookie (or with a mismatched cookie)
             _setSession(self, request, path)
             return self.resource
     elif self.sessions.has_key(cookie):
         # /sessionized-url/foo
         #                 ^ we are this getChild
         # with a session
         _setSession(self, request, cookie)
         return self.resource.getChildWithDefault(path, request)
     elif path == INIT_SESSION:
         # initialize the session
         # /sessionized-url/session-init
         #                  ^ this getChild
         # without a session
         newCookie = _sessionCookie()
         request.addCookie(self.cookieKey, newCookie, path="/")
         rd = Redirect(urlToChild(newCookie,*request.postpath))
         rd.isLeaf = 1
         sz = self.sessions[newCookie] = GuardSession(self, newCookie)
         sz.checkExpired()
         return rd
     else:
         # /sessionized-url/foo
         #                 ^ we are this getChild
         # without a session
         request.getSession = lambda interface=None: None
         return self.resource.getChildWithDefault(path, request)
Exemple #5
0
def redirectToSession(request, garbage):
    rd = Redirect(urlToChild(request, *request.postpath, **{garbage: 1}))
    rd.isLeaf = 1
    return rd
Exemple #6
0
def redirectToSession(request, garbage):
    rd = Redirect(urlToChild(request, *request.postpath, **{garbage:1}))
    rd.isLeaf = 1
    return rd