Anonymous avatar Anonymous committed d188090

added positional parameters to cherrypy.lib.cptools.PositionalParametersAware

Comments (0)

Files changed (1)

cherrypy/lib/cptools.py

         self.items = items
     def __getattr__(self, key):
         return self.items[key]
+
+class PositionalParametersAware(object):
+    """
+    Utility class that restores positional parameters functionality that
+    was found in 2.0.0-beta.
+
+    Use case:
+
+    from cherrypy.lib import cptools
+    from cherrypy import cpg
+    class Root(cptools.PositionalParametersAware):
+        def something(self, name):
+            return "hello, " + name
+        something.exposed
+    cpg.root = Root()
+    cpg.server.start()
+
+    Now, fetch http://localhost:8080/something/name_is_here
+    """
+    def default( self, *args, **kwargs ):
+        # remap parameters to fix positional parameters
+        if hasattr( self, args[ 0 ] ):
+            return getattr( self, args[ 0 ] )( *args[ 1: ], **kwargs )
+    default.exposed = True
+    
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.