Skip to content
Myr

Another try for #12

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent dc3f13d · Browse files · 1 file+42 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+42 added−0 removed

  • other:+42 added−0 removed

1 file+42 added−0 removed

modified:flask.py+42 added
273 unmodified lines
274else:275 _tojson_filter = json.dumps276277278class _ModuleSetupState(object):279280 def __init__(self, app, url_prefix=None):281 self.app = app282 self.url_prefix = url_prefix283284285class Module(object):286 """Container object that enables pluggable applications"""287288 def __init__(self, name, url_prefix=None, package_name=None):289 self.name = name290 self.package_name = package_name291 self.url_prefix = url_prefix292 self._register_events = []293294 def route(self, rule, **options):295 def decorator(f):296 self.add_url_rule(rule, f.__name__, f, **options)297 return f298 return decorator299300 def add_url_rule(self, rule, endpoint, view_func=None, **options):301 self._record(self._register_rule, (rule, endpoint, view_func, options))302303 def _record(self, func, args):304 self._register_events.append((func, args))305306 def _register_rule(self, state, rule, endpoint, view_func, options):307 if self.url_prefix:308 rule = state.url_prefix + rule309 self.app.add_url_rule(rule, '%s.%s' % (self.name, endpoint),310 view_func, **options)311312313class Flask(object):314 """The flask object implements a WSGI application and acts as the central315 object. It is passed the name of the module or package of the316 application. Once it is created it will act as a central registry for
223 unmodified lines
540 :param response: an instance of :attr:`response_class`541 """542 session.save_cookie(response, self.session_cookie_name)543544 def register_module(self, module, **options):545 """Registers a module with this application."""546 options.setdefault('url_prefix', self.url_prefix)547 state = _ModuleSetupState(app, options)548 for func, args in module._register_events:549 func(state, *args)550551 def add_url_rule(self, rule, endpoint, view_func=None, **options):552 """Connects a URL rule. Works exactly like the :meth:`route`553 decorator. If a view_func is provided it will be registered with the554 endpoint.
289 unmodified lines