def __init__(self, id): Session.__init__(self, id) self.dirty = False self.user = None self.results = [] self.breadcrumbs = [] self.wantedit = False # true if the user wants to edit things
def start_request(self): """ This is called from the main object publishing loop whenever we start processing a new request. Obviously, this is a good place to track the number of requests made. (If we were interested in the number of *successful* requests made, then we could override finish_request(), which is called by the publisher at the end of each successful request.) """ Session.start_request(self) self.num_requests += 1
def start_request(self, request): '''start_request(request : HTTPRequest) Called near the beginning of each request: after the HTTPRequest object has been built and this Session object has been fetched or built, but before we traverse the URL or call the callable object found by URL traversal. ''' now = time() if now - self.last_access_time > self.timeout_period: raise SessionError(session_id=self.id) if now - self.last_access_time > self.resolution: self.set_last_access_time(now) Session.start_request(self, request)
def start_request (self): Session.start_request(self) request = get_request() t = time.time() request.response.set_charset('utf-8') # Determine IP of originator, keep Squid in mind :-) try: self.ip = request.environ['HTTP_X_FORWARDED_FOR'] except: self.ip = request.environ['REMOTE_ADDR'] self.port = request.environ['REMOTE_PORT'] #session = sessions.setdefault(ip, # configlets.Holder( # firstaccess=t, # user=None, # phone='', # language='en', # level=-1, # Try to auto-login, based on IP # )) # level==-1 means we should auto-login # This works by searching for the first CfgOptUser configlet where # the 'pc' variable matches the request originating IP: if self.level == -1: # Only try auto-login once, so set it to lowest level self.level = 0 users = backend.getConfiglets(name="CfgOptUser") if len(users) == 0: # be Admin if there are no users configured self.user = "******" self.level = 4 self.language = 'en' sys.stderr.write ("[%s] Logging in with user 'programmer' from ip %s, port %s\n" % (time.asctime(time.localtime()), self.ip, self.port)) else: for user in users: if user.pc == self.ip: self.user = user.name self.level = int(user.level) self.phone = user.phone self.language = user.language break language.setLanguage(self.language)
def has_info(self): """ Overriding has_info() is essential but non-obvious. The session manager uses has_info() to know if it should hang on to a session object or not: if a session is "dirty", then it must be saved. This prevents saving sessions that don't need to be saved, which is especially important as a defensive measure against clients that don't handle cookies: without it, we might create and store a new session object for every request made by such clients. With has_info(), we create the new session object every time, but throw it away unsaved as soon as the request is complete. (Of course, if you write your session class such that has_info() always returns true after a request has been processed, you're back to the original problem -- and in fact, this class *has* been written that way, because num_requests is incremented on every request, which makes has_info() return true, which makes SessionManager always store the session object. In a real application, think carefully before putting data in a session object that causes has_info() to return true.) """ return (self.num_requests > 0) or Session.has_info(self)
def __init__(self, id): Session.__init__(self, id) self.num_requests = 0
def __init__(self, id): QuixoteSession.__init__(self, id) self._dirty = False
def _set_access_time (self, resolution): Session._set_access_time(self, resolution) self._dirty = 1
def __init__(self, session_id): Session.__init__(self, session_id) self.n = 0
def _set_access_time(self, resolution): if self._access_time is None: self._access_time = time.time() QuixoteSession._set_access_time(self, resolution) self._dirty = True
def __init__ (self, request, id): Session.__init__(self, request, id) self.messages = '' self._dirty = 0 self._form_tokens = []
def __init__(self, request, id): Session.__init__(self, request, id) self.last_access_time = time()
def __init__(self, id): Session.__init__(self, id) self.level = -1 self.language = 'en'
def has_info(self): return self.user is not None or \ (self.results is not None and len(self.results) != 0) or \ self.breadcrumbs or \ Session.has_info(self)
def start_request(self): Session.start_request(self)
def __init__(self, id): Session.__init__(self, id) self.user = {}
def has_info(self): return Session.has_info(self)
def __init__(self,id): #super(MySession,self).__init__(id) Session.__init__(self,id) #old-style class self.token = None