Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 299

Show
Ignore:
Timestamp:
06/12/05 22:05:24
Author:
fumanchu
Message:

Merges from trunk.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/ooconf/cherrypy/lib/cptools.py

    r118 r299  
    5050    def __getattr__(self, key): 
    5151        return self.items[key] 
     52 
     53class PositionalParametersAware(object): 
     54    """ 
     55    Utility class that restores positional parameters functionality that 
     56    was found in 2.0.0-beta. 
     57 
     58    Use case: 
     59 
     60    from cherrypy.lib import cptools 
     61    from cherrypy import cpg 
     62    class Root(cptools.PositionalParametersAware): 
     63        def something(self, name): 
     64            return "hello, " + name 
     65        something.exposed 
     66    cpg.root = Root() 
     67    cpg.server.start() 
     68 
     69    Now, fetch http://localhost:8080/something/name_is_here 
     70    """ 
     71    def default( self, *args, **kwargs ): 
     72        # remap parameters to fix positional parameters 
     73        if hasattr( self, args[ 0 ] ): 
     74            return getattr( self, args[ 0 ] )( *args[ 1: ], **kwargs ) 
     75    default.exposed = True 
     76     
  • branches/ooconf/cherrypy/lib/filter/logdebuginfofilter.py

    r247 r299  
    7272                logList.append("Page size: %.02fKB" % ( 
    7373                    len(body)/float(1024))) 
    74              
     74            '''  
     75            # this is not compatible with the session filter 
    7576            if (cpg.config.get('logDebugInfoFilter.logSessionSize', True) 
    7677                and cpg.config.get('session.storageType')): 
     
    8586                except: 
    8687                    logList.append("Session data size: Unable to pickle session") 
     88            ''' 
    8789             
    8890            debuginfo += ', '.join(logList) 
  • branches/ooconf/cherrypy/lib/filter/nsgmlsfilter.py

    r258 r299  
    6767                nsgmlsPath, catalogPath, errFile, pageFile) 
    6868            command = command.replace('\\', '/') 
    69             #command = '"%s" -f%s -s -E10 %s' % ( 
    70             #    nsgmlsPath, errFile, pageFile) 
    71             print "** comand:", command 
    7269            os.system(command) 
    7370            f = open(errFile, 'rb') 
    7471            err = f.read() 
    7572            f.close() 
    76              
    7773            errList = err.splitlines() 
    7874            newErrList = [] 
    79             for err in newErrList: 
    80                 if err.find('characters in the document character set with numbers exceeding 65535 not supported') != -1: 
    81                     continue 
    82                 newErrList.append(err) 
     75            for err in errList: 
     76                ignore = False 
     77                for errIgn in cpg.config.get('nsgmlsFilter.errorsToIgnore', []): 
     78                    if err.find(errIgn) != -1: 
     79                        ignore = True 
     80                        break 
     81                if not ignore: 
     82                    newErrList.append(err) 
    8383            if newErrList: 
    8484                newBody = "Wrong HTML:<br />" + cgi.escape('\n'.join(newErrList)).replace('\n','<br />') 
  • branches/ooconf/cherrypy/lib/filter/sessionauthenticatefilter.py

    r258 r299  
    6666            cpg.request.sessionMap['username'] = None 
    6767            cpg.threadData.user = None 
    68             cpg.response.body = httptools.redirect('/') 
     68            fromPage = cpg.request.paramMap.get('fromPage') 
     69            if fromPage is None: 
     70                fromPage = '/' 
     71            cpg.response.body = httptools.redirect(fromPage) 
    6972        elif cpg.request.path.endswith('doLogin'): 
    7073            fromPage = cpg.request.paramMap['fromPage'] 
     
    7376            errorMsg = self.checkLoginAndPassword(login, password) 
    7477            if errorMsg: 
    75                 cpg.response.body = loginScreen(fromPage, login = login, errorMsg = errorMsg) 
     78                cpg.response.body = self.loginScreen(fromPage, login = login, errorMsg = errorMsg) 
    7679            else: 
    7780                cpg.request.sessionMap['username'] = login 
     81                if not fromPage: 
     82                    fromPage = '/' 
    7883                cpg.response.body = httptools.redirect(fromPage) 
    7984            return 
     
    8388            self.notLoggedIn() 
    8489        if not cpg.request.sessionMap.get('username'): 
    85             cpg.response.body = loginScreen(cpg.request.browserUrl) 
     90            cpg.response.body = self.loginScreen(cpg.request.browserUrl) 
    8691            return 
    8792 
  • branches/ooconf/cherrypy/lib/filter/sessionfilter/basesession.py

    r283 r299  
    3939    """ 
    4040    This is the class from which all session storage types are derived. 
     41    The functions which need to be redefined are at the end of the file 
    4142    """ 
    4243 
    43     # configname is the string storageType value used by the  
    44     # configuration file 
    45     configName = 'BaseSession' 
     44    # these are the  functions that need to rewritten  
     45    def delSession(self, sessionKey): 
     46        """ delete a session from storage """ 
     47 
     48    def getSession(self, sessionKey): 
     49        """ function to lookup the session """ 
    4650     
    47     """ 
    48     autoKeys is used to tell the server if the session storage class 
    49     can automaticly determine all of the key names.  This would be  
    50     true if you are using a relational database and false if you are  
    51     using python dictionaries. 
     51    def setSession(self, sessionData): 
     52        """ function to save sesion data """ 
    5253 
    53     If autoKeys is false the key names must be provided at runtime. 
    54     If it is true any key names provied at runtime are ignored. 
    55     """ 
    56     autoKeys   = True 
    57      
     54    def cleanUpOldSessions(self): 
     55        """This function cleans up expired sessions""" 
     56 
     57    def newSession(self): 
     58        """ Return a new sessiondict instance """ 
     59 
     60    # it might be usefull to redefine this function 
     61    def generateSessionKey(self): 
     62        """ Function to return a new sessioId """ 
     63        sessionKeyFunc = sessionconfig.retrieve('keyGenerator', self.sessionName, None) 
     64         
     65        if sessionKeyFunc: 
     66            newKey = cherrypy._cputil.getSpecialAttribute(sessionKeyFunc)() 
     67        else: 
     68            newKey = sha.new('%s%s' % (time.time(), random.random())).hexdigest() 
     69         
     70        return newKey 
    5871 
    5972    def __init__(self, sessionName): 
     73        """ 
     74        Create the session caceh and set the session name.  Make if you write 
     75        a custom __init__ function make sure you make a call to  
     76        BaseSession.__init__(sessioName) 
     77        """ 
     78         
    6079        self.__sessionCache = {} 
    61         self.defaultValues = {} 
    6280        self.sessionName = sessionName 
    63         """ 
    64         This is where the you initialize your session storage class. 
    65         sessionOptions is a direct mapping of the configuration 
    66         options. 
    67          
    68         The keys 'host', 'user', 'password', and 'database', 
    69         must be used by classes that need to connect to remote 
    70         databases.  'tableName' will contain the table name (duh!). 
    71  
    72         The keyw 'dataKeys' will map to a list of the variable names you wish 
    73         to store in your session object.  If autoKeys is true you will use it 
    74         to set to create sessionMap instances. 
    75         """ 
     81   
     82    
     83    # there should never be a reason to modify the remaining functions, they used  
     84    # internally by the sessionFilter 
    7685     
    7786    def getDefaultAttributes(self): 
     
    8392             } 
    8493        
    85     def newSession(self): 
    86         """ Return a new sessionMap instance """ 
    87         # this needs to check the config file for default values 
    88         newData = self.getDefaultAttributes() 
    89         newData.update(self.defaultValues) 
    90         return SimpleSessionDict(newData) 
    91  
    92     def generateSessionKey(self): 
    93         """ Function to return a new sessioId """ 
    94         sessionKeyFunc = sessionconfig.retrieve('keyGenerator', self.sessionName, None) 
    95          
    96         if sessionKeyFunc: 
    97             newKey = cherrypy._cputil.getSpecialAttribute(sessionKeyFunc)() 
    98         else: 
    99             s = '' 
    100             for i in range(50): 
    101                 s += random.choice(string.letters+string.digits) 
    102             s += '%s'%time.time() 
    103             newKey = sha.sha(s).hexdigest() 
    104          
    105         return newKey 
    106  
    10794    def loadSession(self, sessionKey, autoCreate = True): 
    10895        cpg = cherrypy.cpg 
     
    156143                    del self.__sessionCache[session.key] 
    157144     
    158     def dropSession(self, sessionKey): 
    159         self.delSession() 
    160         """ delete a session from storage """ 
    161  
    162     def cleanUpOldSessions(self): 
    163         """This function cleans up expired sessions""" 
    164  
  • branches/ooconf/cherrypy/lib/filter/sessionfilter/dbmsession.py

    r280 r299  
    3333 
    3434from sessionerrors import * 
    35  
    36 import cPickle as pickle 
     35from simplesessiondict import SimpleSessionDict 
    3736 
    3837class DBMSession(BaseSession): 
     
    4544        sessionFile=cpg.config.get('%s.dbFile' % sessionName, '%s.db' % sessionName) 
    4645        self.__data = shelve.open(sessionFile, 'c') 
     46     
     47    def newSession(self): 
     48        """ Return a new sessiondict instance """ 
     49        newData = self.getDefaultAttributes() 
     50        return SimpleSessionDict(newData) 
    4751 
    4852    def getSession(self, sessionKey): 
  • branches/ooconf/cherrypy/lib/filter/sessionfilter/filesession.py

    r282 r299  
    3737 
    3838import threading 
     39from simplesessiondict import SimpleSessionDict 
    3940 
    4041class FileSession(BaseSession): 
     
    4950        return storageDir 
    5051     
     52    def newSession(self): 
     53        """ Return a new sessiondict instance """ 
     54        newData = self.getDefaultAttributes() 
     55        return SimpleSessionDict(newData) 
     56    
    5157    # all session writes are blocked  
    5258    def getSession(self, sessionKey): 
  • branches/ooconf/cherrypy/lib/filter/sessionfilter/ramsession.py

    r275 r299  
    3131 
    3232from sessionerrors import * 
     33from simplesessiondict import SimpleSessionDict 
    3334 
    3435class RamSession(BaseSession): 
     
    3637        BaseSession.__init__(self, sessionName) 
    3738        self.__data = {} 
    38  
     39     
     40    def newSession(self): 
     41        """ Return a new sessiondict instance """ 
     42        newData = self.getDefaultAttributes() 
     43        return SimpleSessionDict(newData) 
     44         
    3945    def getSession(self, sessionKey): 
    4046        try: 
     
    4450     
    4551    def setSession(self, sessionData): 
    46         # since everything in in rame the  
     52        # since everything in in ram the  
    4753        # session we don't need to update the data 
    4854        # unless int is a new session 
  • branches/ooconf/cherrypy/lib/filter/sessionfilter/sqlobjectsession.py

    r284 r299  
    4949        if attr in ['timestamp', 'timeout', 'lastAccess', 'key']: 
    5050            return getattr(self.__sqlObject, self.__attrSub(attr)) 
     51        else: 
     52            return object.__getattr__(self, attr) 
    5153 
    5254    def __setattr__(self, attr, value): 
     
    112114    def cleanUpOldSessions(self): 
    113115        # running a single query would be a huge performace boost 
    114         for sessionKey in __data: 
    115             session = sessionData[sessionKey] 
    116             if session.expired(): 
    117                 self.delSession(sessionKey) 
    118  
    119 ''' 
    120 Session.createTable() 
    121 p = Session(session_key = 'abcd', timestamp = 330, count = 123) 
    122 Session.delete(Session.q.session_key=='abcd') 
    123  
    124 smanage = SQLObjectSession('test') 
    125 print smanage.getSession('abcd') 
    126 ''' 
     116        pass 
  • branches/ooconf/cherrypy/test/test_logdebuginfo_filter.py

    r267 r299  
    6060        self.assert_('Build time' in cpg.response.body) 
    6161        self.assert_('Page size' in cpg.response.body) 
    62         self.assert_('Session data size' in cpg.response.body) 
     62        # not compatible with the sessionFilter 
     63        #self.assert_('Session data size' in cpg.response.body) 
    6364 
    6465 
  • branches/ooconf/cherrypy/tutorial/tut10_sessionfilter.conf

    r275 r299  
    44server.environment = "production" 
    55 
     6# by default we get 
     7# sessionFilter.on=True 
     8# sessionFilter.new='sessionMap' 
     9# sessionMap.storageType='ram' 
     10 
    611[/admin] 
     12# this tell CherryPy to create a session, 
     13# named 'adminSession' and to store the data in ram 
    714sessionFilter.new='adminSession' 
    815adminSession.storageType='ram' 
  • branches/ooconf/cherrypy/tutorial/tut10_sessionfilter.py

    r279 r299  
    66 
    77class HitCounter: 
     8   
     9    # this is just a primative template function 
    810    def __examplePage(self, poweredBy, count, links, sessionKey): 
    911        yield '<html><head><title>sessionFilter exampe</title><body>\n' 
     
    1719        yield '\n</body></html>' 
    1820 
     21    # a list of the pages used in the example so we add pages 
     22    # without changing any code 
    1923    samplePages = ['admin', 'index', 'forum'] 
    20  
    21     def admin(self): 
    22         adminCount = cpg.sessions.adminSession.get('adminCount', 0) + 1 
    23         cpg.sessions.adminSession['adminCount'] = adminCount 
     24     
     25    def index(self): 
     26        # this function uses the sessionMap which is turned on by defualt 
     27        # it may not be the defualt in future versions 
    2428         
    25         key = cpg.sessions.adminSession.key 
    26         return self.__examplePage('ram', adminCount, self.samplePages, key) 
    27  
    28     admin.exposed = True 
    29      
    30     def forum(self): 
    31         forumCount = cpg.sessions.forumSession.get('forumCount', 0) + 1 
    32         cpg.sessions.forumSession['forumCount'] = forumCount 
    33          
    34         key = cpg.sessions.forumSession.key 
    35         return self.__examplePage('ram', forumCount, self.samplePages, key) 
    36     forum.exposed=True 
    37  
    38     def index(self): 
    3929        # Increase the silly hit counter 
    4030        count = cpg.sessions.sessionMap.get('count', 0) + 1 
     
    5040    index.exposed = True 
    5141 
    52     # these functions do the same as the index but with a different session dictionary 
    5342    def admin(self): 
     43        # this function uses the adminSession which is defined in 
     44        # the config file "tut10_sessionFilter.conf", otherwise 
     45        # it mirrors the session function 
     46 
    5447        adminCount = cpg.sessions.adminSession.get('adminCount', 0) + 1 
    5548        cpg.sessions.adminSession['adminCount'] = adminCount 
     
    5750        key = cpg.sessions.adminSession.key 
    5851        return self.__examplePage('ram', adminCount, self.samplePages, key) 
    59  
    6052    admin.exposed = True 
    6153     
    6254    def forum(self): 
     55        # this function uses the forumSession which is defined in 
     56        # the config file "tut10_sessionFilter.conf", otherwise 
     57        # it mirrors the session function 
     58         
    6359        forumCount = cpg.sessions.forumSession.get('forumCount', 0) + 1 
    6460        cpg.sessions.forumSession['forumCount'] = forumCount 

Hosted by WebFaction

Log in as guest/cpguest to create tickets