def test_invalid_mountpoint(self): try: DepotManager.make_middleware(self.wsgi_app, mountpoint='hello') except ValueError as err: assert 'mountpoint must be an absolute path' in str(err) else: assert False, 'Should have raised ValueError'
def setup(): setup_database() DepotManager._clear() DepotManager.configure('default', {'depot.storage_path': './lfs'}) DepotManager.configure('another', {'depot.storage_path': './lfs'}) DepotManager.alias('another_alias', 'another') DepotManager.make_middleware(None)
def setup(): setup_database() DepotManager._clear() DepotManager.configure("default", {"depot.storage_path": "./lfs"}) DepotManager.configure("another", {"depot.storage_path": "./lfs"}) DepotManager.alias("another_alias", "another") DepotManager.make_middleware(None)
def make_app(global_conf, **app_conf): """ Set sample-ecommerce up with the settings found in the PasteDeploy configuration file used. :param dict global_conf: The global settings for sample-ecommerce (those defined under the ``[DEFAULT]`` section). :return: The sample-ecommerce application with all the relevant middleware loaded. This is the PasteDeploy factory for the sample-ecommerce application. ``app_conf`` contains all the application-specific settings (those defined under ``[app:main]``. """ app = base_config.make_wsgi_app(global_conf, app_conf, wrap_app=None) # Wrap your final TurboGears 2 application with custom middleware here # The following line is needed because during tests we create multiple apps and DEPOT can only have a single middleware. DepotManager._middleware = None app = DepotManager.make_middleware(app) return app
def make_app(global_conf, full_stack=True, **app_conf): """ Set etl up with the settings found in the PasteDeploy configuration file used. :param global_conf: The global settings for etl (those defined under the ``[DEFAULT]`` section). :type global_conf: dict :param full_stack: Should the whole TG2 stack be set up? :type full_stack: str or bool :return: The etl application with all the relevant middleware loaded. This is the PasteDeploy factory for the etl application. ``app_conf`` contains all the application-specific settings (those defined under ``[app:main]``. """ app = make_base_app(global_conf, full_stack=True, **app_conf) # Wrap your base TurboGears 2 application with custom middleware here # This is needed because during tests we create multiple apps and DEPOT can only have a single middleware. DepotManager._middleware = None app = DepotManager.make_middleware(app) return app
def setup_app(app_name=__name__, db_uri=None): """ Set up Flask application and database. Args: app_name: Name of the Flask application. db_uri: Database URI for SQLAlchemy to connected to. """ global app, db # Flask application app = Flask(app_name) # Application configuration app.config.update({ "SQLALCHEMY_DATABASE_URI": db_uri, "SQLALCHEMY_TRACK_MODIFICATIONS": False }) # Database object db = SQLAlchemy(app) # Depot DepotManager.configure("default", {"depot.storage_path": DATA_ROOT}) app.wsgi_app = DepotManager.make_middleware(app.wsgi_app, replace_wsgi_filewrapper=True) # Import all related modules import_module("app.models") import_module("app.views")
def make_app(global_conf, full_stack=True, **app_conf): """ Set depotexample up with the settings found in the PasteDeploy configuration file used. :param global_conf: The global settings for depotexample (those defined under the ``[DEFAULT]`` section). :type global_conf: dict :param full_stack: Should the whole TG2 stack be set up? :type full_stack: str or bool :return: The depotexample application with all the relevant middleware loaded. This is the PasteDeploy factory for the depotexample application. ``app_conf`` contains all the application-specific settings (those defined under ``[app:main]``. """ app = make_base_app(global_conf, full_stack=True, **app_conf) # Wrap your base TurboGears 2 application with custom middleware here from depot.manager import DepotManager app = DepotManager.make_middleware(app) return app
def register_depot(app: Flask) -> Flask: from flask import request from werkzeug import Response from depot.manager import DepotManager from flask_login import login_required try: os.makedirs(app.config['DEPOT_STORAGE_PATH']) except FileExistsError: pass DepotManager.configure( 'default', {'depot.storage_path': app.config['DEPOT_STORAGE_PATH']}) app.depot_middleware = DepotManager.make_middleware(None, cache_max_age=0) @app.route('/depot/<path:path>', methods=['GET', 'HEAD']) @login_required def depot_proxy(path): kwargs = {} def fake_start_response(status, headers): kwargs['status'] = status kwargs['headers'] = headers kwargs['response'] = \ app.depot_middleware(request.environ, fake_start_response) return Response(**kwargs) return app
def make_app(global_conf, full_stack=True, **app_conf): """ Set algobowl up with the settings found in the PasteDeploy configuration file used. :param global_conf: The global settings for algobowl (those defined under the ``[DEFAULT]`` section). :type global_conf: dict :param full_stack: Should the whole TG2 stack be set up? :type full_stack: str or bool :return: The algobowl application with all the relevant middleware loaded. This is the PasteDeploy factory for the algobowl application. ``app_conf`` contains all the application-specific settings (those defined under ``[app:main]``. """ app = make_base_app(global_conf, full_stack=True, **app_conf) app = DepotManager.make_middleware(app) return app
def make_app(global_conf, **app_conf): """ Set contacts up with the settings found in the PasteDeploy configuration file used. :param dict global_conf: The global settings for contacts (those defined under the ``[DEFAULT]`` section). :return: The contacts application with all the relevant middleware loaded. This is the PasteDeploy factory for the contacts application. ``app_conf`` contains all the application-specific settings (those defined under ``[app:main]``. """ app = base_config.make_wsgi_app(global_conf, app_conf, wrap_app=None) # Wrap your final TurboGears 2 application with custom middleware here DepotManager._middleware = None app = DepotManager.make_middleware(app) return app
def wrap_wsgi_app(self, app): """Perform any necessary WSGI application wrapping. """ app = DepotManager.make_middleware(app, replace_wsgi_filewrapper=True) return app
def make_app(self, **options): wsgi_app = DepotManager.make_middleware(self.wsgi_app, **options) return TestApp(wsgi_app)
""" WSGI config for depotexample project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ """ import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "depotexample.settings") from django.core.wsgi import get_wsgi_application application = get_wsgi_application() # Configure a "default" storage based on DEPOT settings from django.conf import settings from depot.manager import DepotManager DepotManager.configure('default', settings.DEPOT, prefix='') # Wrap the application with depot middleware to serve files on /depot application = DepotManager.make_middleware(application)
from flask import Flask, request, redirect, url_for, render_template app = Flask(__name__) # This is just an horrible way to keep around # uploaded files, but in the end we just wanted # to showcase how to setup DEPOT, not how to upload files. UPLOADED_FILES = [] @app.route("/", methods=['GET', 'POST']) def index(): if request.method == 'POST': file = request.files['file'] if file: fileid = DepotManager.get().create(file) UPLOADED_FILES.append(fileid) return redirect(url_for('index')) files = [DepotManager.get().get(fileid) for fileid in UPLOADED_FILES] return render_template('index.html', files=files) from depot.manager import DepotManager DepotManager.configure('default', {'depot.storage_path': '/tmp/'}) app.wsgi_app = DepotManager.make_middleware(app.wsgi_app) if __name__ == "__main__": app.run(host='0.0.0.0', port=5001, debug=True)
def zopsedu_app(new_app): """Zopsedu bağımlılıklarını aldığı app'e ekler""" from zopsedu.auth.models.auth import load_user from zopsedu.lib.anonymous import Anonymous from zopsedu.common.app.file.views import FileView from zopsedu.common.app.sablon.views import SablonView from zopsedu.common.app.model_filter.views import FilterView from zopsedu.common.export import ExportView from zopsedu.lib.mail import init_mail from zopsedu.app import scheduler, job_store from flask_menu import Menu from flask_babel import gettext as _ # init session object login manager login_manager = ZopseduLoginManager() # login_manager.localize_callback = localize_callback login_manager.login_message = _( "Sayfayı görüntülemek için, lütfen giriş yapınız!") login_manager.needs_refresh_message = _( "Sayfayı görüntülemek için, lütfen tekrar giriş yapınız!") login_manager.init_app(new_app) login_manager.login_view = 'auth.login' login_manager.user_callback = load_user login_manager.anonymous_user = Anonymous new_app.secret_key = new_app.config['SECRET_KEY'] # depolama ayarlari DepotManager.configure( 'local', {'depot.storage_path': new_app.config['DEPOT_STORAGE_PATH']}) Babel(new_app) FileView.register(new_app) SablonView.register(new_app) FilterView.register(new_app) ExportView.register(new_app) # Depot Manager talep edilirse asagidaki gibi s3 uyumlu bir network # servisine baglanabilir. # DepotManager.configure('s3', { # 'depot.backend': 'depot.io.boto3.S3Storage', # 'depot.access_key_id': "123", # 'depot.secret_access_key': "1234", # 'depot.bucket': "bucket", # 'depot.endpoint_url': "http://localhost:8000" # }) new_app.wsgi_app = DepotManager.make_middleware(new_app.wsgi_app) JWTManager(new_app) # extendd app with flask menu Menu(app=new_app) scheduler.init_app(new_app) scheduler.scheduler.add_jobstore(jobstore=job_store) scheduler.start() # @new_app.teardown_appcontext # def session_commit(exception): # try: # DB.session.commit() # except IntegrityError as integrity_error: # new_app.logger.error(integrity_error) # DB.session.rollback() # except Exception as exc: # new_app.logger.error(exc) # DB.session.rollback() # debug toolbar # enable only if you need while developing, do not in test and prod # new_app = debug_toolbar(new_app) register_blueprints(new_app) register_signal_listeners(new_app) if new_app.config['CRUD_LOG']: from zopsedu.lib.db_event_listeners import register_db_event_listeners register_db_event_listeners() # gereksiz 415 tane endpoint(model filtrelemek icin) olusturdugundan dolayı kaldirildi # build_api(new_app) init_mail(new_app) return new_app
def test_prevent_multiple_middlewares(self): DepotManager.make_middleware(None) DepotManager.make_middleware(None)
migrate = Migrate(app, db) admin = Admin(app, name='Oxford Mindmap Admin', template_mode='bootstrap3', \ index_view=AdminHomeView()) # login_manager settings from server.models import User @login_manager.user_loader def load_user(uid): return User.query.filter_by(id=uid).first() # Define back-end file storage DepotManager.configure('default', {'depot.storage_path': '/tmp/depot/'}) app.wsgi_app = DepotManager.make_middleware(app.wsgi_app) try: if app.config['PREFIX']: app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix=app.config['PREFIX']) prefix = app.config['PREFIX'] except KeyError: prefix = '' from server.models import Trigger, Story, TriggerWarning from server import views # Initialise administrative views class AdminView(ModelView):