Coverage for tw2.core.compat : 75%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Collections of extra pieces to help smooth over community divergence. """
""" A widget mixin that provides more advanced controller routing and dispatching.
The need for this mainly sprung from a divergence of source trees (unintentionally forking) between the developers of tw2 while it was still alpha/beta. One team expected users to define controllers as a 'request' classmethod on the widget and another team expected users to define a Controller class as a child of the widget. Team A's pattern is now the default in the main tree. This is a shim to support Team B's approach.
Use it like this:
>>> import tw2.core >>> class MyWidget(tw2.core.TGStyleController, tw2.core.Widget): ... class Controller(object): ... @jsonify ... def some_method(self, req): ... return dict(foo="bar")
"""
def dispatch(cls, req, controller): method_name = 'index' else: # later we want to better handle .ext conditions, but hey # this aint TG method_name = method_name[:-5] method = getattr(controller, 'default', None)
def request(cls, req): """ Override this method to define your own way of handling a widget request.
The default does TG-style object dispatch. """
return util.abort(req, 401)
return util.abort(req, 404)
return util.abort(req, 403)
return util.abort(req, 404) |