Added support for subdomain bound modules
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 b49afa2 · Browse files · 4 files·+35 added−2 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+35 added−2 removed
- tests:+21 added−0 removed
- other:+14 added−2 removed
Provenance
- Commit
7680d52- Tree
484a1b5- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
b49afa2
4 files changed+35 added−2 removed
modified:flask/app.py+1 added
452 unmodified lines453 :class:`Module` class and will override the values of the module if454 provided.455 """456 options.setdefault('url_prefix', module.url_prefix)457+ options.setdefault('subdomain', module.subdomain)458 state = _ModuleSetupState(self, **options)459 for func in module._register_events:460 func(state)461 414 unmodified linesmodified:flask/module.py+10 added-2 removed
35 unmodified lines36 37 38 class _ModuleSetupState(object):39 40- def __init__(self, app, url_prefix=None):40+ def __init__(self, app, url_prefix=None, subdomain=None):41 self.app = app42 self.url_prefix = url_prefix43+ self.subdomain = subdomain44 45 46 class Module(_PackageBoundObject):47 """Container object that enables pluggable applications. A module can46 unmodified lines94 The `static_path` parameter was added and it's now possible for95 modules to refer to their own templates and static files. See96 :ref:`modules-and-resources` for more information.97 98+ .. versionadded:: 0.699+ The `subdomain` parameter was added.100+101 :param import_name: the name of the Python package or module102 implementing this :class:`Module`.103 :param name: the internal short name for the module. Unless specified104 the rightmost part of the import name105 :param url_prefix: an optional string that is used to prefix all the106 URL rules of this module. This can also be specified107 when registering the module with the application.108+ :param subdomain: used to set the subdomain setting for URL rules that109+ do not have a subdomain setting set.110 :param static_path: can be used to specify a different path for the111 static files on the web. Defaults to ``/static``.112 This does not affect the folder the files are served113 *from*.114 """115 116 def __init__(self, import_name, name=None, url_prefix=None,111- static_path=None):117+ static_path=None, subdomain=None):118 if name is None:119 assert '.' in import_name, 'name required if package name ' \120 'does not point to a submodule'121 name = import_name.rsplit('.', 1)[1]122 _PackageBoundObject.__init__(self, import_name)123 self.name = name124 self.url_prefix = url_prefix125+ self.subdomain = subdomain126 self._register_events = [_register_module(self, static_path)]127 128 def route(self, rule, **options):129 """Like :meth:`Flask.route` but for a module. The endpoint for the16 unmodified lines146 def register_rule(state):147 the_rule = rule148 if state.url_prefix:149 the_rule = state.url_prefix + rule150+ options.setdefault('subdomain', state.subdomain)151 the_endpoint = endpoint152 if the_endpoint is None:153 the_endpoint = _endpoint_from_view_func(view_func)154 state.app.add_url_rule(the_rule, '%s.%s' % (self.name,67 unmodified linesmodified:tests/flask_tests.py+21 added
1036 unmodified lines1037 c = app.test_client()1038 rv = c.get('/', 'http://mitsuhiko.localhost/')1039 assert rv.data == 'index for mitsuhiko'1040 1041+ def test_module_subdomain_support(self):1042+ app = flask.Flask(__name__)1043+ mod = flask.Module(__name__, 'test', subdomain='testing')1044+ app.config['SERVER_NAME'] = 'localhost'1045 1046+ @mod.route('/test')1047+ def test():1048+ return 'Test'1049+1050+ @mod.route('/outside', subdomain='xtesting')1051+ def bar():1052+ return 'Outside'1053+1054+ app.register_module(mod)1055+1056+ c = app.test_client()1057+ rv = c.get('/test', 'http://testing.localhost/')1058+ assert rv.data == 'Test'1059+ rv = c.get('/outside', 'http://xtesting.localhost/')1060+ assert rv.data == 'Outside'1061+1062+1063 class TestSignals(unittest.TestCase):1064 1065 def test_template_rendered(self):1066 app = flask.Flask(__name__)102 unmodified linesmodified:CHANGES+3 added
32 unmodified lines33 you want to use it, make sure to have `blinker`_ installed.34 - refactored the way url adapters are created. This process is now35 fully customizable with the :meth:`~flask.Flask.create_url_adapter`36 method.37+- modules can now register for a subdomain instead of just an URL38+ prefix. This makes it possible to bind a whole module to a39+ configurable subdomain.40 41 .. _blinker: http://pypi.python.org/pypi/blinker42 43 Version 0.5.2108 unmodified lines