vert-x/mod-lang-jython — pull request #9 by jordanhalterman (2013-08-12 12:03:29+00:00)
Title: Allow RouteMatcher methods to be used as handler callback decorators.

This branch adds decorators to the `RouteMatcher`. Using the example from [the manual](http://vertx.io/core_manual_python.html#extracting-parameters-from-the-path) the decorators look like this:

```python
server = vertx.create_http_server()

route_matcher = RouteMatcher()

@route_matcher.put('/:blogname/:post')
def matched(req):
blogname = req.params['blogname']
post = req.params['post']
req.response.end("blogname is %s post is %s" %(blogName, post))

server.request_handler(route_matcher).listen(8080, 'localhost')
```

This is consistent with decorators for handlers in other areas of the API. Fortunately, the way decorators with arguments are created in Python, this type of change to the behavior of the methods is accomplished without *actually* altering the existing `RouteMatcher` interface. If a single argument is passed to the methods then it behaves as a decorator, but if a second handler argument is passed then it behaves as a normal method call. It simply does something like this:

```python
def get(self, pattern, *args):
if len(args) > 0:
# This is a normal method call. args[0] is a callback.
self.java_obj.get(pattern, HttpServerRequestHandler(handler))
return self
else:
# This is a decorator call. Create a decorator.
def wrap(handler):
self.java_obj.get(pattern, HttpServerRequestHandler(handler))
return handler
return wrap
```

So, the original example still works, e.g.:

```python
route_matcher.put('/:blogname/:post', matched)
```

Of course, an alternate approach would be to provide a helper class - `RouteMatcherDecorator` or something - for decorating callbacks for the `RouteMatcher`, but personally I don't dislike using a single method for both approaches in Python.

Sorry for the verbosity, I just like to explain my reasoning behind design decisions :-)