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

Changeset 296

Show
Ignore:
Timestamp:
06/12/05 09:54:49
Author:
peterhunt
Message:

added positional parameters to cherrypy.lib.cptools.PositionalParametersAware?

Files:

Legend:

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

    r118 r296  
    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     

Hosted by WebFaction

Log in as guest/cpguest to create tickets