Ejemplo n.º 1
0
    def setUp(self):
        app = Flask(__name__)

        app.debug = False
        app.config['CACHE_TYPE'] = 'simple'

        self.cache = Cache()
        self.cache.init_app(app)

        self.app = app
Ejemplo n.º 2
0
def configure_extensions(app):
    print '  [LOAD] PostgreSQL extension'
    app.db = PostgreSQL(app)

    print '  [LOAD] Cache extension'
    app.cache = Cache(app)

    print '  [LOAD] Authentication extension'
    app.auth = Auth(app)

    print '  [LOAD] Amazon S3 extension'
    app.s3 = S3Connection(app.config['AWS_ACCESS_KEY_ID'],
                          app.config['AWS_SECRET_ACCESS_KEY'])
Ejemplo n.º 3
0
from flaskext.cache import Cache
from flaskext.uploads import UploadSet, IMAGES, configure_uploads
from blinker import Namespace
import setting
import sys


app = Flask(__name__)
app.config.from_object(setting)

app.debug = True
toolbar = DebugToolbarExtension(app)

mail = Mail(app)
babel = Babel(app)
cache = Cache(app)
#db = SQLAlchemy(app)
principals = Principal(app)
login_manager = LoginManager()
login_manager.setup_app(app)
userimage = UploadSet('userimage', IMAGES)
configure_uploads(app, (userimage))

# setting
# fix issue of unicode
reload(sys)
sys.setdefaultencoding("utf-8")

# fix issue of forerign_keys problem for SQLite
#db.session.execute('PRAGMA foreign_keys=ON;')
class SQLiteForeignKeysListener(PoolListener):
Ejemplo n.º 4
0
class ProxyFixupHelper(object):
    def __init__(self, app):
        self.app = app

    def __call__(self, environ, start_response):
        # Only perform this fixup if the current remote host is localhost.
        if environ['REMOTE_ADDR'] == '127.0.0.1':
            host = environ.get('HTTP_X_REAL_IP', False)
            if host:
                environ['REMOTE_ADDR'] = host
        return self.app(environ, start_response)


# Flask Extensions
babel = Babel()
cache = Cache()

# SQL ORM Missive:
#
# Don't use models to automatically generate schemas. After iterating several
# times with SQLAlchemy (and nearly every other ORM from frameworks both long
# since dead and still trendy), to get a schema "just right" requires
# entirely too much fiddling in the ORM. My hard earned lesson: SQL is the
# right dialect to describe your database's structure (read: do not use an
# ORM to generate DDL). Other than portability, what's the advantage of
# describing your schema in SQLAlchemy?
#
# For as fantastic as SQLAlchemy is, using SQLAlchemy to generate schema is
# the equivalent of giving yourself a lobotomy while in the middle of
# attempting to write a Pulitzer Prize article. Why handicap yourself? Use
# SQLAlchemy for what it excels at: generating efficient SQL based on
Ejemplo n.º 5
0
def create_app_ext(flask_config_file=None,
                   flask_config_dict=None,
                   moin_config_class=None,
                   warn_default=True,
                   **kwargs):
    """
    Factory for moin wsgi apps

    @param flask_config_file: a flask config file name (may have a MOINCFG class),
                              if not given, a config pointed to by MOINCFG env var
                              will be loaded (if possible).
    @param flask_config_dict: a dict used to update flask config (applied after
                              flask_config_file was loaded [if given])
    @param moin_config_class: if you give this, it'll be instantiated as app.cfg,
                              otherwise it'll use MOINCFG from flask config. If that
                              also is not there, it'll use the DefaultConfig built
                              into MoinMoin.
    @oaram warn_default: emit a warning if moin falls back to its builtin default
                         config (maybe user forgot to specify MOINCFG?)
    @param **kwargs: if you give additional key/values here, they'll get patched
                     into the moin configuration class (before it instance is created)
    """
    clock = Clock()
    clock.start('create_app total')
    app = Flask('MoinMoin')
    clock.start('create_app load config')
    if flask_config_file:
        app.config.from_pyfile(flask_config_file)
    else:
        app.config.from_envvar('MOINCFG', silent=True)
    if flask_config_dict:
        app.config.update(flask_config_dict)
    Config = moin_config_class
    if not Config:
        Config = app.config.get('MOINCFG')
    if not Config:
        if warn_default:
            logging.warning("using builtin default configuration")
        from MoinMoin.config.default import DefaultConfig as Config
    for key, value in kwargs.iteritems():
        setattr(Config, key, value)
    if Config.secrets is None:
        # reuse the secret configured for flask (which is required for sessions)
        Config.secrets = app.config.get('SECRET_KEY')
    app.cfg = Config()
    clock.stop('create_app load config')
    clock.start('create_app register')
    # register converters
    from werkzeug.routing import PathConverter
    app.url_map.converters['itemname'] = PathConverter
    # register modules, before/after request functions
    from MoinMoin.apps.frontend import frontend
    frontend.before_request(before_wiki)
    frontend.after_request(after_wiki)
    app.register_module(frontend)
    from MoinMoin.apps.admin import admin
    admin.before_request(before_wiki)
    admin.after_request(after_wiki)
    app.register_module(admin, url_prefix='/+admin')
    from MoinMoin.apps.feed import feed
    feed.before_request(before_wiki)
    feed.after_request(after_wiki)
    app.register_module(feed, url_prefix='/+feed')
    from MoinMoin.apps.misc import misc
    misc.before_request(before_wiki)
    misc.after_request(after_wiki)
    app.register_module(misc, url_prefix='/+misc')
    from MoinMoin.apps.serve import serve
    app.register_module(serve, url_prefix='/+serve')
    clock.stop('create_app register')
    clock.start('create_app flask-cache')
    cache = Cache()
    cache.init_app(app)
    app.cache = cache
    clock.stop('create_app flask-cache')
    # init storage
    clock.start('create_app init backends')
    app.unprotected_storage, app.storage = init_backends(app)
    clock.stop('create_app init backends')
    clock.start('create_app index rebuild')
    if app.cfg.index_rebuild:
        app.unprotected_storage.index_rebuild()  # XXX run this from a script
    clock.stop('create_app index rebuild')
    clock.start('create_app load/save xml')
    import_export_xml(app)
    clock.stop('create_app load/save xml')
    clock.start('create_app flask-babel')
    i18n_init(app)
    clock.stop('create_app flask-babel')
    # configure templates
    clock.start('create_app flask-themes')
    setup_themes(app)
    if app.cfg.template_dirs:
        app.jinja_env.loader = ChoiceLoader([
            FileSystemLoader(app.cfg.template_dirs),
            app.jinja_env.loader,
        ])
    app.error_handlers[403] = themed_error
    clock.stop('create_app flask-themes')
    clock.stop('create_app total')
    del clock
    return app
Ejemplo n.º 6
0
    def test_19_dict_config_both(self):
        cache = Cache(config={'CACHE_TYPE': 'null'})
        cache.init_app(self.app, config={'CACHE_TYPE': 'simple'})

        assert cache.config['CACHE_TYPE'] == 'simple'
Ejemplo n.º 7
0
    def test_18_dict_config_initapp(self):
        cache = Cache()
        cache.init_app(self.app, config={'CACHE_TYPE': 'simple'})

        assert cache.config['CACHE_TYPE'] == 'simple'
Ejemplo n.º 8
0
    def test_17_dict_config(self):
        cache = Cache(config={'CACHE_TYPE': 'simple'})
        cache.init_app(self.app)

        assert cache.config['CACHE_TYPE'] == 'simple'