def testHostName(self): # About all we can do is invoke hostName() to see that no exceptions # are thrown, and do a little type checking on the return type. host = hostName() self.assertIsNotNone(host) self.assertIsInstance(host, str) self.assertEqual(host, host.lower())
def initSessions(self): """Initialize all session related attributes.""" self._sessionPrefix = self.setting('SessionPrefix') or '' if self._sessionPrefix: if self._sessionPrefix == 'hostname': from MiscUtils.Funcs import hostName self._sessionPrefix = hostName() self._sessionPrefix += '-' self._sessionTimeout = self.setting('SessionTimeout') * 60 self._sessionName = (self.setting('SessionName') or self.defaultConfig()['SessionName']) self._autoPathSessions = self.setting('UseAutomaticPathSessions') self._alwaysSaveSessions = self.setting('AlwaysSaveSessions') self._retainSessions = self.setting('RetainSessions') moduleName = self.setting('SessionModule') className = moduleName.rsplit('.', 1)[-1] try: exec 'from %s import %s' % (moduleName, className) cls = locals()[className] if not isinstance(cls, type): raise ImportError self._sessionClass = cls except ImportError: print( "ERROR: Could not import Session class '%s'" " from module '%s'") % (className, moduleName) self._sessionClass = None moduleName = self.setting('SessionStore') if moduleName in ('Dynamic', 'File', 'Memcached', 'Memory', 'Redis', 'Shelve'): moduleName = 'Session%sStore' % moduleName className = moduleName.rsplit('.', 1)[-1] try: exec 'from %s import %s' % (moduleName, className) cls = locals()[className] if not isinstance(cls, type): raise ImportError self._sessions = cls(self) except ImportError as err: print( "ERROR: Could not import SessionStore class '%s'" " from module '%s':\n%s") % (className, moduleName, err) self._sessions = None
def initSessions(self): """Initialize all session related attributes.""" self._sessionPrefix = self.setting('SessionPrefix') or '' if self._sessionPrefix: if self._sessionPrefix == 'hostname': from MiscUtils.Funcs import hostName self._sessionPrefix = hostName() self._sessionPrefix += '-' self._sessionTimeout = self.setting('SessionTimeout')*60 self._sessionName = self.setting('SessionName') \ or self.defaultConfig()['SessionName'] self._autoPathSessions = self.setting('UseAutomaticPathSessions') moduleName = self.setting('SessionModule') className = moduleName.split('.')[-1] try: exec 'from %s import %s' % (moduleName, className) klass = locals()[className] if not isinstance(klass, ClassType) \ and not issubclass(klass, Object): raise ImportError self._sessionClass = klass except ImportError: print "ERROR: Could not import Session class '%s'" \ " from module '%s'" % (className, moduleName) self._sessionClass = None moduleName = self.setting('SessionStore') if moduleName in ('Dynamic', 'File', 'Memory'): moduleName = 'Session%sStore' % moduleName self._sessionDir = moduleName != 'SessionMemoryStore' \ and self.serverSidePath( self.setting('SessionStoreDir') or 'Sessions') or None className = moduleName.split('.')[-1] try: exec 'from %s import %s' % (moduleName, className) klass = locals()[className] if not isinstance(klass, ClassType) \ and not issubclass(klass, Object): raise ImportError self._sessions = klass(self) except ImportError: print "ERROR: Could not import SessionStore class '%s'" \ " from module '%s'" % (className, moduleName) self._sessions = None
def initSessions(self): """Initialize all session related attributes.""" setting = self.setting self._sessionPrefix = setting('SessionPrefix') or '' if self._sessionPrefix: if self._sessionPrefix == 'hostname': from MiscUtils.Funcs import hostName self._sessionPrefix = hostName() self._sessionPrefix += '-' self._sessionTimeout = setting('SessionTimeout') * 60 self._sessionName = (setting('SessionName') or self.defaultConfig()['SessionName']) self._autoPathSessions = setting('UseAutomaticPathSessions') self._alwaysSaveSessions = setting('AlwaysSaveSessions') self._retainSessions = setting('RetainSessions') moduleName = setting('SessionModule') className = moduleName.rpartition('.')[2] try: exec(f'from {moduleName} import {className}') cls = locals()[className] if not isinstance(cls, type): raise ImportError self._sessionClass = cls except ImportError: print(f"ERROR: Could not import Session class '{className}'" f" from module '{moduleName}'") self._sessionClass = None moduleName = setting('SessionStore') if moduleName in ('Dynamic', 'File', 'Memcached', 'Memory', 'Redis', 'Shelve'): moduleName = f'Session{moduleName}Store' className = moduleName.rpartition('.')[2] try: exec(f'from {moduleName} import {className}') cls = locals()[className] if not isinstance(cls, type): raise ImportError self._sessions = cls(self) except ImportError as err: print(f"ERROR: Could not import SessionStore class '{className}'" f" from module '{moduleName}':\n{err}") self._sessions = None
def initSessions(self): """Initialize all session related attributes.""" self._sessionPrefix = self.setting('SessionPrefix') or '' if self._sessionPrefix: if self._sessionPrefix == 'hostname': from MiscUtils.Funcs import hostName self._sessionPrefix = hostName() self._sessionPrefix += '-' self._sessionTimeout = self.setting('SessionTimeout')*60 self._sessionName = (self.setting('SessionName') or self.defaultConfig()['SessionName']) self._autoPathSessions = self.setting('UseAutomaticPathSessions') self._alwaysSaveSessions = self.setting('AlwaysSaveSessions') moduleName = self.setting('SessionModule') className = moduleName.rsplit('.', 1)[-1] try: exec 'from %s import %s' % (moduleName, className) klass = locals()[className] if not isinstance(klass, type): raise ImportError self._sessionClass = klass except ImportError: print ("ERROR: Could not import Session class '%s'" " from module '%s'" % (className, moduleName)) self._sessionClass = None moduleName = self.setting('SessionStore') if moduleName in ('Dynamic', 'File', 'Memcached', 'Memory', 'Shelve'): moduleName = 'Session%sStore' % moduleName self._sessionDir = self.serverSidePath( self.setting('SessionStoreDir') or 'Sessions') className = moduleName.rsplit('.', 1)[-1] try: exec 'from %s import %s' % (moduleName, className) klass = locals()[className] if not isinstance(klass, type): raise ImportError self._sessions = klass(self) except ImportError, err: print ("ERROR: Could not import SessionStore class '%s'" " from module '%s':\n%s" % (className, moduleName, err)) self._sessions = None
from Common import * from MiscUtils.Funcs import uniqueId, hostName from time import localtime, time # Only compute this once, for improved speed. _hostname = hostName() class SessionError(Exception): pass class Session(Object): """ All methods that deal with time stamps, such as creationTime(), treat time as the number of seconds since January 1, 1970. Session identifiers are stored in cookies. Therefore, clients must have cookies enabled. Unlike Response and Request, which have HTTP subclass versions (e.g., HTTPRequest and HTTPResponse respectively), Session does not. This is because there is nothing protocol specific in Session. (Is that true considering cookies? @@ 2000-04-09 ce) 2000-04-27 ce: With regards to ids/cookies, maybe the notion of a session id should be part of the interface of a Request. Note that the session id should be a string that is valid as part of a filename. This is currently true, and should be maintained if the session id generation technique is modified. Session ids can be used in filenames.