def _make_app(self, config, full_stack=True, static_files=True): # The Pylons WSGI app log.pcore.debug("Initializing middleware...") app = PylonsApp(config=config) # Routing/Session Middleware app = RoutesMiddleware(app, config['routes.map'], singleton=False) app = SessionMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) spells = Implementations(IMiddlewareSpell) for spell in spells: app = spell.add_middleware(app) if asbool(full_stack): # Handle Python exceptions global_conf = config # I think that it's correct, config is slightly modified global_conf app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # Routing/Session Middleware app = RoutesMiddleware(app, config['routes.map'], singleton=False) app = SessionMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(full_stack): # permission = ValidAuthKitUser() # app = authkit.authorize.middleware(app, permission) app = authkit.authenticate.middleware(app, app_conf) # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # Routing/Session Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app, [417]) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 417, 500]) # authenticator = OCSAuthenticator(config) # app = AuthBasicHandler(app, "OCSManager", authenticator) fqdn = "%(hostname)s.%(dnsdomain)s" % config["samba"] app = NTLMAuthHandler(app, samba_host=fqdn) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # Routing/Session Middleware app = RoutesMiddleware(app, config['routes.map'], singleton=False) app = SessionMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) app = make_who_with_config(app, global_conf, app_conf['who.config_file'], app_conf['who.log_file'], app_conf['who.log_level']) # start turbomail adapter tm_pylons.start_extension() if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # Set error handler, if we're customizing the full stack. This can't be merged # with the block below, because order is important with middleware. The # VariableErrorHandler relies on SessionMiddleware, so it needs to be wrapped tighter # (instantiated before, ergo called after). if asbool(full_stack): app = VariableErrorHandler(app, global_conf, **config['pylons.errorware']) # Routing/Session Middleware app = RoutesMiddleware(app, config['routes.map'], singleton=False) app = SessionMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(full_stack): # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) app.config = config return app
def make_app(global_conf, full_stack=False, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # Routing/Session Middleware app = RoutesMiddleware(app, config['routes.map'], singleton=False) app = SessionMiddleware(app, config) # At some point it seems that Pylons converts the Content-Type of any # response without a 200 OK status to 'text/html; charset=utf-8'. Well # no more Pylons! The HTML2JSONContentType middleware zaps those # nasty text/html content types and converts them to application/json! app = HTML2JSONContentType(app) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, include_cache_middleware=False, attribsafe=False, **app_conf): import pylons import pylons.configuration as configuration from pylons import url from pylons.decorators import jsonify from pylons.middleware import ErrorHandler, StatusCodeRedirect from pylons.error import handle_mako_error from pylons.wsgiapp import PylonsApp root = os.path.dirname(os.path.abspath(__file__)) paths = dict(root=os.path.join(test_root, 'sample_controllers'), controllers=os.path.join(test_root, 'sample_controllers', 'controllers'), templates=os.path.join(test_root, 'sample_controllers', 'templates')) sys.path.append(test_root) config = configuration.PylonsConfig() config.init_app(global_conf, app_conf, package='sample_controllers', paths=paths) map = Mapper(directory=config['pylons.paths']['controllers']) map.connect('/{controller}/{action}') config['routes.map'] = map class AppGlobals(object): pass config['pylons.app_globals'] = AppGlobals() config['pylons.app_globals'].mako_lookup = TemplateLookup( directories=paths['templates'], imports=['from markupsafe import escape']) if attribsafe: config['pylons.strict_tmpl_context'] = False app = PylonsApp(config=config) app = RoutesMiddleware(app, config['routes.map'], singleton=False) if include_cache_middleware: app = CacheMiddleware(app, config) app = SessionMiddleware(app, config) if asbool(full_stack): app = ErrorHandler(app, global_conf, **config['pylons.errorware']) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [401, 403, 404, 500]) app = RegistryManager(app) app.config = config return app
def make_app(global_conf, full_stack=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether or not this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) app = CacheMiddleware(app, config) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) # Static files (If running in production, and Apache or another web # server is handling this static content, remove the following 3 lines) static_app = StaticURLParser( config['pylons.paths']['static_files'], cache_max_age=31536000 # Cache it for one-year ) app = Cascade([static_app, app]) # Authentication Middleware app = multigate.authenticate.middleware(app, app_conf) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # Routing/Session Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) # FTS3 authentication/authorization middleware app = FTS3AuthMiddleware(app, config) # Convert errors to a json representation app = ErrorAsJson(app, config) # Request logging app = RequestLogger(app, config) # Error handling if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) app.config = config return app
def make_app(global_conf, full_stack=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether or not this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) import pylons # Routing/Session/Cache Middleware from beaker.middleware import SessionMiddleware from routes.middleware import RoutesMiddleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) # Static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) #app = LimitUploadSize(app, 30 * 1024000) # 20mb, max upload size app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether or not this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Apply compatibility patches patches.kombu_1_5_1_python_2_7_11() patches.inspect_getargspec() # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) if rhodecode.is_test: app = csrf.CSRFDetector(app) expected_origin = config.get('expected_origin') if expected_origin: # The API can be accessed from other Origins. app = csrf.OriginChecker(app, expected_origin, skip_urls=[routes.util.url_for('api')]) if asbool(full_stack): # Appenlight monitoring and error handler app, appenlight_client = wrap_in_appenlight_if_enabled(app, config) # we want our low level middleware to get to the request ASAP. We don't # need any pylons stack middleware in them app = VCSMiddleware(app, config, appenlight_client) # Establish the Registry for this application app = RegistryManager(app) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, include_cache_middleware=False, attribsafe=False, **app_conf): import pylons import pylons.configuration as configuration from beaker.cache import CacheManager from beaker.middleware import SessionMiddleware, CacheMiddleware from nose.tools import raises from paste.registry import RegistryManager from paste.deploy.converters import asbool from pylons.decorators import jsonify from pylons.middleware import ErrorHandler, StatusCodeRedirect from pylons.wsgiapp import PylonsApp from routes import Mapper from routes.middleware import RoutesMiddleware paths = dict(root=os.path.join(test_root, 'sample_controllers'), controllers=os.path.join(test_root, 'sample_controllers', 'controllers')) config = configuration.pylons_config config.init_app(global_conf, app_conf, package='sample_controllers', paths=paths) map = Mapper(directory=config['pylons.paths']['controllers']) map.connect('/{controller}/{action}') map.connect('/test_func', controller='sample_controllers.controllers.hello:special_controller') map.connect('/test_empty', controller='sample_controllers.controllers.hello:empty_wsgi') config['routes.map'] = map class AppGlobals(object): def __init__(self): self.cache = 'Nothing here but a string' config['pylons.app_globals'] = AppGlobals() if attribsafe: config['pylons.strict_tmpl_context'] = False app = PylonsApp(config=config) app = RoutesMiddleware(app, config['routes.map'], singleton=False) if include_cache_middleware: app = CacheMiddleware(app, config) app = SessionMiddleware(app, config) if asbool(full_stack): app = ErrorHandler(app, global_conf, **config['pylons.errorware']) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [401, 403, 404, 500]) app = RegistryManager(app) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, include_cache_middleware=False, attribsafe=False, **app_conf): import pylons import pylons.configuration as configuration from pylons import url from pylons.decorators import jsonify from pylons.middleware import ErrorHandler, StatusCodeRedirect from pylons.error import handle_mako_error from pylons.wsgiapp import PylonsApp root = os.path.dirname(os.path.abspath(__file__)) paths = dict(root=os.path.join(test_root, 'sample_controllers'), controllers=os.path.join(test_root, 'sample_controllers', 'controllers'), templates=os.path.join(test_root, 'sample_controllers', 'templates')) sys.path.append(test_root) config = configuration.PylonsConfig() config.init_app(global_conf, app_conf, package='sample_controllers', paths=paths) map = Mapper(directory=config['pylons.paths']['controllers']) map.connect('/{controller}/{action}') config['routes.map'] = map class AppGlobals(object): pass config['pylons.app_globals'] = AppGlobals() config['pylons.app_globals'].mako_lookup = TemplateLookup( directories=paths['templates'], imports=['from markupsafe import escape'] ) if attribsafe: config['pylons.strict_tmpl_context'] = False app = PylonsApp(config=config) app = RoutesMiddleware(app, config['routes.map'], singleton=False) if include_cache_middleware: app = CacheMiddleware(app, config) app = SessionMiddleware(app, config) if asbool(full_stack): app = ErrorHandler(app, global_conf, **config['pylons.errorware']) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [401, 403, 404, 500]) app = RegistryManager(app) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it""" # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # Routing/Session Middleware app = RoutesMiddleware(app, config["routes.map"]) app = SessionMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config["pylons.errorware"]) # Display error documents for 400, 403, 404, 405 status codes (and # 500, 503 when debug is disabled) if asbool(config["debug"]): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 403, 404, 405, 500, 503]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config["pylons.paths"]["static_files"]) app = Cascade([static_app, app]) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """ Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # Routing/Session Middleware app = RoutesMiddleware(app, config['routes.map'], singleton=False) app = SessionMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(full_stack): app = RecursiveMiddleware(app, global_conf) app = AuthkitMiddleware(app, app_conf) # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) app.config = config """ Initialize Jodis connections We load jodis here so that we have access to the database """ try: init_jodis(config) except Exception, e: print '!!!Jodis failed to initialize!!!' traceback.print_exc(file=sys.stdout)
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """ Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp() # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) app = CacheMiddleware(app, config) g = config['pylons.app_globals'] g.cache_manager = app.cache_manager # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) # this is a compatibility hack for pylons > 1.0!!! conf = PyConf(config) conf['global_conf'] = global_conf conf['app_conf'] = app_conf conf['__file__'] = global_conf['__file__'] conf['FILE'] = global_conf['__file__'] conf['routes.map'] = config['routes.map'] if not hasattr(conf, 'init_app'): setattr(conf, 'init_app', config.init_app) app.config = conf return app
def make_app(global_conf, full_stack=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether or not this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app #app = PylonsApp() app = PylonsApp(config=config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) from facebook.wsgi import create_pylons_facebook_middleware app = create_pylons_facebook_middleware(app, app_conf) from tw.api import make_middleware app = make_middleware(app, { 'toscawidgets.framework' : 'pylons', 'toscawidgets.framework.default_view' : 'mako', 'toscawidgets.middleware.inject_resources' : True, }) # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) app = CacheMiddleware(app, config) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) # Static files (If running in production, and Apache or another web # server is handling this static content, remove the following 2 lines) static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) if not getattr(meta.metadata, 'set_up', False): setup_tables(meta.engine) setup_orm() meta.metadata.set_up = True # The Pylons WSGI app app = PylonsApp(config=config) # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) app = CacheMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(full_stack): # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) app = StatusCodeRedirect(app) else: from raven.contrib.pylons import Sentry if config.get('sentry.dsn'): app = Sentry(app, config) else: app = ErrorHandler(app, global_conf, **config['pylons.errorware']) app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files kwargs = {} if not asbool(config['debug']): kwargs['cache_max_age'] = 3600 static_app = StaticURLParser(config['pylons.paths']['static_files'], **kwargs) app = Cascade([static_app, app]) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) if config['profile']: # pragma: no cover - nightly profiles do the full stack from repoze.profiler import AccumulatingProfileMiddleware app = AccumulatingProfileMiddleware( app, log_filename='/tmp/cb-website.prof', discard_first_request=True, flush_at_shutdown=True, path='/__profile__' ) # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) #app = CacheMiddleware(app, config) # Cache now setup in app_globals as suggested in http://pylonshq.com/docs/en/1.0/upgrading/ # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) app = MobileDetectionMiddleware(app) app = EnvironMiddleware(app) app = SecurifyCookiesMiddleware(app) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = HeaderURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # Set error handler, if we're customizing the full stack. This can't be merged # with the block below, because order is important with middleware. The # VariableErrorHandler relies on SessionMiddleware, so it needs to be wrapped tighter # (instantiated before, ergo called after). if asbool(full_stack): app = VariableErrorHandler(app, global_conf, **config['pylons.errorware']) # Routing/Session Middleware app = RoutesMiddleware(app, config['routes.map'], singleton=False) app = SessionMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(full_stack): # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app_list = [static_app, app] if config['files_storage'].startswith('file://'): images_app = StaticURLParser( config['files_storage'][len('file://'):]) app_list.insert(0, images_app) app = Cascade(app_list) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) plugin_mgr = config['pylons.app_globals'].plugin_mgr # The Pylons WSGI app app = PylonsApp(config=config) # Allow the plugin manager to tweak our WSGI app app = plugin_mgr.wrap_pylons_app(app) # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config['routes.map'], singleton=False) app = SessionMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) # Set up repoze.what-quickstart authentication: # http://wiki.pylonshq.com/display/pylonscookbook/Authorization+with+repoze.what app = add_auth(app, config) # ToscaWidgets Middleware app = setup_tw_middleware(app, config) # Strip the name of the .fcgi script, if using one, from the SCRIPT_NAME app = FastCGIScriptStripperMiddleware(app) # If enabled, set up the proxy prefix for routing behind # fastcgi and mod_proxy based deployments. if config.get('proxy_prefix', None): app = setup_prefix_middleware(app, global_conf, config['proxy_prefix']) # END CUSTOM MIDDLEWARE if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Cleanup the DBSession only after errors are handled app = DBSessionRemoverMiddleware(app) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files from our public directory public_app = StaticURLParser(config['pylons.paths']['static_files']) static_urlmap = URLMap() # Serve static files from all plugins for dir, path in plugin_mgr.public_paths().iteritems(): static_urlmap[dir] = StaticURLParser(path) # Serve static media and podcast images from outside our public directory for image_type in ('media', 'podcasts'): dir = '/images/' + image_type path = os.path.join(config['image_dir'], image_type) static_urlmap[dir] = StaticURLParser(path) # Serve appearance directory outside of public as well dir = '/appearance' path = os.path.join(config['app_conf']['cache_dir'], 'appearance') static_urlmap[dir] = StaticURLParser(path) # We want to serve goog closure code for debugging uncompiled js. if config['debug']: goog_path = os.path.join(config['pylons.paths']['root'], '..', 'closure-library', 'closure', 'goog') if os.path.exists(goog_path): static_urlmap['/scripts/goog'] = StaticURLParser(goog_path) app = Cascade([public_app, static_urlmap, app]) if asbool(config.get('enable_gzip', 'true')): app = setup_gzip_middleware(app, global_conf) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether or not this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(config['pdebug']): from rhodecode.lib.profiler import ProfilingMiddleware app = ProfilingMiddleware(app) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # we want our low level middleware to get to the request ASAP. We don't # need any pylons stack middleware in them app = SimpleHg(app, config) app = SimpleGit(app, config) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) #enable https redirets based on HTTP_X_URL_SCHEME set by proxy app = HttpsFixup(app, config) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) app = make_gzip_middleware(app, global_conf, compress_level=1) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config['routes.map'], singleton=False) app = SessionMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) # Set up repoze.what-quickstart authentication: # http://wiki.pylonshq.com/display/pylonscookbook/Authorization+with+repoze.what app = add_auth(app, config) # Set up the TW middleware, as per errors and instructions at: # http://groups.google.com/group/toscawidgets-discuss/browse_thread/thread/c06950b8d1f62db9 # http://toscawidgets.org/documentation/ToscaWidgets/install/pylons_app.html app = tw.api.make_middleware(app, { 'toscawidgets.framework': 'pylons', 'toscawidgets.framework.default_view': 'genshi', }) # Add transaction management app = make_tm(app, transaction_commit_veto) app = DBSessionRemoverMiddleware(app, DBSession) # If enabled, set up the proxy prefix for routing behind # fastcgi and mod_proxy based deployments. if (config.get('proxy_prefix', None)): app = setup_prefix_middleware(app, global_conf, config['proxy_prefix']) # END CUSTOM MIDDLEWARE if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ debug = (asbool(global_conf.get('debug', False)) or asbool(app_conf.get('debug', False))) # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config['routes.map']) if config.get('adhocracy.session.implementation', 'beaker') == 'cookie': app = CookieSessionMiddleware(app, config) else: app = beaker.middleware.SessionMiddleware(app, config) app = beaker.middleware.CacheMiddleware(app, config) #app = make_profile_middleware(app, config, log_filename='profile.log.tmp') # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) app = setup_auth(app, config) app = make_prefix_middleware(app, config, scheme=config.get('adhocracy.protocol', 'http')) app = setup_discriminator(app, config) if asbool(config.get('adhocracy.requestlog_active', 'False')): app = RequestLogger(app, config) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): cache_age = int(config.get('adhocracy.static.age', 7200)) # Serve static files overlay_app = StaticURLParser( get_site_path('static', app_conf=config), cache_max_age=None if debug else cache_age) static_app = StaticURLParser( config['pylons.paths']['static_files'], cache_max_age=None if debug else cache_age) app = Cascade([overlay_app, static_app, app]) # Fanstatic inserts links for javascript and css ressources. # The required resources can be specified at runtime with <resource>.need() # and can will be delivered with version specifiers in the url and # minified when not in debug mode. fanstatic_base_url = base_url('', instance=None, config=config).rstrip('/') app = Fanstatic(app, minified=not (debug), versioning=True, recompute_hashes=debug, bundle=not (debug), base_url=fanstatic_base_url, bottom=True) if asbool(config.get('adhocracy.include_machine_name_in_header', 'false')): app = IncludeMachineName(app, config) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # Routing/Session Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app, [417]) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 417, 500]) # authenticator = OCSAuthenticator(config) # app = AuthBasicHandler(app, "OCSManager", authenticator) fqdn = "%(hostname)s.%(dnsdomain)s" % config["samba"] auth_handler = NTLMAuthHandler(app) def ntlm_env_setter(environ, start_response): for var in ["SAMBA_HOST", "NTLMAUTHHANDLER_WORKDIR"]: try: environ[var] = app_conf[var] except KeyError: # FIXME: logging? pass return auth_handler(environ, start_response) # Establish the Registry for this application app = RegistryManager(ntlm_env_setter) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config["routes.map"], singleton=False) app = SessionMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) format = ( "%(REMOTE_ADDR)s - %(REMOTE_USER)s [%(time)s] " '"%(REQUEST_METHOD)s %(REQUEST_URI)s %(HTTP_VERSION)s" ' "%(status)s %(bytes)s" ) app = TransLogger(app, format=format, logger_name="access") if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config["pylons.errorware"]) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config["debug"]): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config["pylons.paths"]["static_files"]) app = Cascade([static_app, app]) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config["routes.map"]) app = SessionMiddleware(app, config) # app = CacheMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(full_stack): # Handle Python exceptions app = authkit.authenticate.middleware(app, app_conf) app = ErrorHandler(app, global_conf, **config["pylons.errorware"]) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config["debug"]): # from dozer import Logview # app = Logview(app, config) app = StatusCodeRedirect(app) """from repoze.debug.responselogger import ResponseLoggingMiddleware from logging import getLogger app = ResponseLoggingMiddleware( app, max_bodylen=3072, keep=100, verbose_logger=getLogger('orders'), trace_logger = getLogger('pytis'), ) from repoze.profile.profiler import AccumulatingProfileMiddleware app = AccumulatingProfileMiddleware( app, log_filename='pytis.log', cachegrind_filename='pytis.out.bar', discard_first_request=True, flush_at_shutdown=True, path='/__profile__' ) """ else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config["pylons.paths"]["static_files"], cache_max_age=3600) app = Cascade([static_app, app]) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ debug = asbool(global_conf.get("debug", False)) or asbool(app_conf.get("debug", False)) # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) if debug and asbool(app_conf.get("adhocracy.enable_profiling", False)): from werkzeug.contrib.profiler import ProfilerMiddleware app = ProfilerMiddleware(app, sort_by=("ncalls",), restrictions=("src/adhocracy/.*", 25)) # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config["routes.map"]) if config.get("adhocracy.session.implementation", "beaker") == "cookie": app = CookieSessionMiddleware(app, config) else: app = beaker.middleware.SessionMiddleware(app, config) app = beaker.middleware.CacheMiddleware(app, config) # app = make_profile_middleware(app, config, log_filename='profile.log.tmp') # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) app = setup_auth(app, config) app = make_prefix_middleware(app, config, scheme=config.get("adhocracy.protocol", "http")) app = setup_discriminator(app, config) if asbool(config.get("adhocracy.requestlog_active", "False")): app = RequestLogger(app, config) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config["pylons.errorware"]) # Display error documents for 401, 403, 404 status codes app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): cache_age = int(config.get("adhocracy.static.age", 7200)) # Serve static files overlay_app = StaticURLParser( get_site_path("static", app_conf=config), cache_max_age=None if debug else cache_age ) static_app = StaticURLParser(config["pylons.paths"]["static_files"], cache_max_age=None if debug else cache_age) app = Cascade([overlay_app, static_app, app]) # Fanstatic inserts links for javascript and css ressources. # The required resources can be specified at runtime with <resource>.need() # and can will be delivered with version specifiers in the url and # minified when not in debug mode. fanstatic_base_url = base_url("", instance=None, config=config).rstrip("/") app = Fanstatic( app, minified=not (debug), versioning=True, recompute_hashes=debug, bundle=not (debug), base_url=fanstatic_base_url, bottom=True, ) if asbool(config.get("adhocracy.include_machine_name_in_header", "false")): app = IncludeMachineName(app, config) app = CorsMiddleware(app, config) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """ Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp() # Profiling Middleware if profile_load: if asbool(config['profile']): app = AccumulatingProfileMiddleware( app, log_filename='/var/log/linotp/profiling.log', cachegrind_filename='/var/log/linotp/cachegrind.out', discard_first_request=True, flush_at_shutdown=True, path='/__profile__') # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) app = CacheMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) # repoze.who if repoze_load: if 'who.generate_random_secret' in app_conf and not app_conf[ 'who.generate_random_secret']: app = make_who_with_config(app, global_conf, app_conf['who.config_file'], app_conf['who.log_file'], app_conf['who.log_level']) else: # Read the current configuration file and replace "secret" keys in every line who_config_lines = [] secret = binascii.hexlify(os.urandom(16)) if len(secret) != 32: raise RuntimeError( 'Could not generate random repoze.who secret, no os.urandom support?' ) with open(app_conf['who.config_file']) as f: for line in f.readlines(): who_config_lines.append( re.sub(r'^(secret)\s*=\s*.*$', r'\1 = %s' % secret, line)) with tempinput(''.join(who_config_lines)) as who_config_file: app = make_who_with_config(app, global_conf, who_config_file, app_conf['who.log_file'], app_conf['who.log_level']) # this is a compatibility hack for pylons > 1.0!!! conf = PyConf(config) conf['global_conf'] = global_conf conf['app_conf'] = app_conf conf['__file__'] = global_conf['__file__'] conf['FILE'] = global_conf['__file__'] conf['routes.map'] = config['routes.map'] if not hasattr(conf, 'init_app'): setattr(conf, 'init_app', config.init_app) app.config = conf return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # Routing/Session Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) # FTS3 authentication/authorization middleware app = FTS3AuthMiddleware(app, config) # Trap timeouts and the like app = TimeoutHandler(app, config) # Convert errors to a json representation app = ErrorAsJson(app, config) # Request logging app = RequestLogger(app, config) # Error handling if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) app.config = config # Heartbeat thread Heartbeat('fts_rest', int(config.get('fts3.HeartBeatInterval', 60))).start() return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) plugin_mgr = config["pylons.app_globals"].plugin_mgr # The Pylons WSGI app app = PylonsApp(config=config) # Allow the plugin manager to tweak our WSGI app app = plugin_mgr.wrap_pylons_app(app) # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config["routes.map"], singleton=False) app = SessionMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) # Set up repoze.what-quickstart authentication: # http://wiki.pylonshq.com/display/pylonscookbook/Authorization+with+repoze.what app = add_auth(app, config) # ToscaWidgets Middleware app = setup_tw_middleware(app, config) # Strip the name of the .fcgi script, if using one, from the SCRIPT_NAME app = FastCGIScriptStripperMiddleware(app) # If enabled, set up the proxy prefix for routing behind # fastcgi and mod_proxy based deployments. if config.get("proxy_prefix", None): app = setup_prefix_middleware(app, global_conf, config["proxy_prefix"]) # END CUSTOM MIDDLEWARE if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config["pylons.errorware"]) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config["debug"]): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Cleanup the DBSession only after errors are handled app = DBSessionRemoverMiddleware(app) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files from our public directory public_app = StaticURLParser(config["pylons.paths"]["static_files"]) static_urlmap = URLMap() # Serve static files from all plugins for dir, path in plugin_mgr.public_paths().iteritems(): static_urlmap[dir] = StaticURLParser(path) # Serve static media and podcast images from outside our public directory for image_type in ("media", "podcasts"): dir = "/images/" + image_type path = os.path.join(config["image_dir"], image_type) static_urlmap[dir] = StaticURLParser(path) # Serve appearance directory outside of public as well dir = "/appearance" path = os.path.join(config["app_conf"]["cache_dir"], "appearance") static_urlmap[dir] = StaticURLParser(path) # We want to serve goog closure code for debugging uncompiled js. if config["debug"]: goog_path = os.path.join(config["pylons.paths"]["root"], "..", "closure-library", "closure", "goog") if os.path.exists(goog_path): static_urlmap["/scripts/goog"] = StaticURLParser(goog_path) app = Cascade([public_app, static_urlmap, app]) if asbool(config.get("enable_gzip", "true")): app = setup_gzip_middleware(app, global_conf) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) app = CacheMiddleware(app, config) # Needed by authkit app = RecursiveMiddleware(app, global_conf) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) # Ponies! app = PonyMiddleware(app) # CUSTOM MIDDLEWARE END if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) app = authkit.authenticate.middleware(app, app_conf) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = [] for static_files_dir in config['pylons.paths']['static_files']: static_app.append(StaticURLParser(static_files_dir)) static_apps = Cascade(static_app, catch=(404,)) app = Cascade([static_apps, app]) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """ Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp() # Profiling Middleware if profile_load: if asbool(config['profile']): app = AccumulatingProfileMiddleware( app, log_filename='/var/log/linotp/profiling.log', cachegrind_filename='/var/log/linotp/cachegrind.out', discard_first_request=True, flush_at_shutdown=True, path='/__profile__' ) # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) app = CacheMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) # repoze.who if repoze_load: if 'who.generate_random_secret' in app_conf and not app_conf['who.generate_random_secret']: app = make_who_with_config(app, global_conf, app_conf['who.config_file'], app_conf['who.log_file'], app_conf['who.log_level']) else: # Read the current configuration file and replace "secret" keys in every line who_config_lines = [] secret = binascii.hexlify(os.urandom(16)) if len(secret) != 32: raise RuntimeError('Could not generate random repoze.who secret, no os.urandom support?') with open(app_conf['who.config_file']) as f: for line in f.readlines(): who_config_lines.append(re.sub(r'^(secret)\s*=\s*.*$', r'\1 = %s' % secret, line)) with tempinput(''.join(who_config_lines)) as who_config_file: app = make_who_with_config(app, global_conf, who_config_file, app_conf['who.log_file'], app_conf['who.log_level']) # this is a compatibility hack for pylons > 1.0!!! conf = PyConf(config) conf['global_conf'] = global_conf conf['app_conf'] = app_conf conf['__file__'] = global_conf['__file__'] conf['FILE'] = global_conf['__file__'] conf['routes.map'] = config['routes.map'] if not hasattr(conf, 'init_app'): setattr(conf, 'init_app', config.init_app) app.config = conf return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether or not this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config["routes.map"]) app = SessionMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(config["pdebug"]): from rhodecode.lib.profiler import ProfilingMiddleware app = ProfilingMiddleware(app) if asbool(full_stack): from rhodecode.lib.middleware.sentry import Sentry from rhodecode.lib.middleware.errormator import Errormator if Errormator and asbool(config["app_conf"].get("errormator")): app = Errormator(app, config) elif Sentry: app = Sentry(app, config) # Handle Python exceptions app = ErrorHandler(app, global_conf, **config["pylons.errorware"]) # we want our low level middleware to get to the request ASAP. We don't # need any pylons stack middleware in them app = SimpleHg(app, config) app = SimpleGit(app, config) app = RequestWrapper(app, config) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config["debug"]): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # enable https redirets based on HTTP_X_URL_SCHEME set by proxy app = HttpsFixup(app, config) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config["pylons.paths"]["static_files"]) app = Cascade([static_app, app]) app = make_gzip_middleware(app, global_conf, compress_level=1) app.config = config return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # Routing/Session Middleware app = RoutesMiddleware(app, config['routes.map'], singleton=False) app = SessionMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) # need to setup ldap plugin in who_args['authenticators'] from bookie.model import meta from bookie.model.auth import User, Group, Permission app = setup_morpace_auth(app, User, Group, Permission, meta.Session, post_login_url='/post_login', post_logout_url='/login', #log_level='debug', #log_file='stdout' pylons_config=config, ) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) try: import inupy if asbool(config['inupy.profiler']) or asbool(config['inupy.logview']): app = inupy.setup(app, config) except: # just skip it if we can't import it pass # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) app.config = config return app