Created
January 24, 2013 19:41
-
-
Save tehasdf/4626906 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, Blueprint, current_app, request | |
from collections import namedtuple | |
class ConfigBlueprint(Blueprint): | |
def register(self, app, options, first_registration): | |
self.options = options | |
super(ConfigBlueprint, self).register(app, options, first_registration) | |
mod = ConfigBlueprint('damage', __name__, url_prefix='/damage') | |
@mod.route('/right') | |
def example(): | |
return current_app.blueprints[request.blueprint].options["whatever"] | |
@mod.route('/wrong') | |
def example2(): | |
return mod.options["whatever"] | |
app = Flask(__name__) | |
app.register_blueprint(mod, whatever='right value') | |
# now we'll reset the mod name to something that is not the blueprint | |
mod = namedtuple('BlueprintLiar', 'options')({'whatever': 'wrong value'}) | |
assert mod.options['whatever'] != 'right value' | |
with app.test_client() as c: | |
assert c.get('/damage/wrong').data == 'wrong value' | |
assert c.get('/damage/right').data == 'right value' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment