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 load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(base_wsgi_app=RedditApp) # CUSTOM MIDDLEWARE HERE (filtered by the error handling middlewares) # last thing first from here down app = CleanupMiddleware(app) app = LimitUploadSize(app) app = ProfileGraphMiddleware(app) app = ProfilingMiddleware(app) app = SourceViewMiddleware(app) app = DomainListingMiddleware(app) app = SubredditMiddleware(app) app = ExtensionMiddleware(app) app = DomainMiddleware(app) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, error_template=error_template, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and 500 when # debug is disabled) app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf) # Establish the Registry for this application app = RegistryManager(app) # Static files javascripts_app = StaticJavascripts() static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, javascripts_app, app]) #add the rewrite rules app = RewriteMiddleware(app) 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 load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp() # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if pylons.__version__ >= '0.9.7': # Routing/Session/Cache Middleware from beaker.middleware import CacheMiddleware, SessionMiddleware from routes.middleware import RoutesMiddleware app = RoutesMiddleware(app, pylons.config['routes.map']) app = SessionMiddleware(app, pylons.config) app = CacheMiddleware(app, pylons.config) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, error_template=error_template, **pylons.config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf) # Establish the Registry for this application app = RegistryManager(app) # Static files javascripts_app = StaticJavascripts() static_app = StaticURLParser(pylons.config['pylons.paths']['static_files']) app = Cascade([static_app, javascripts_app, app]) 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 load_environment( global_conf, app_conf ) # The Pylons WSGI app # Overload with DIRAC app after the PYTHONPATH has been set from dirac.lib.DiracWebApp import DiracWebApp app = DiracWebApp() # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) 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) app = ErrorDocuments( app, global_conf, mapper = error_mapper, **app_conf ) # Establish the Registry for this application app = RegistryManager( app ) # Static files staticFiles = config['pylons.paths']['static_files'] cascadeApps = [] if type( staticFiles ) in ( types.ListType, types.TupleType ): for staticFile in staticFiles: cascadeApps.append( StaticURLParser( staticFile ) ) else: cascadeApps.append( StaticURLParser( staticFiles ) ) cascadeApps.extend( [ app ] ) app = Cascade( cascadeApps ) return app
def make_app(global_conf, full_stack=True, **app_conf): """Create a WSGI application and return it global_conf is a dict representing the Paste configuration options, the paste.deploy.converters should be used when parsing Paste config options to ensure they're treated properly. """ # Setup the Paste CONFIG object CONFIG.push_process_config({'app_conf': app_conf, 'global_conf': global_conf}) # Load our Pylons configuration defaults config = load_environment(global_conf, app_conf) config.init_app(global_conf, app_conf, package='web') # Load our default Pylons WSGI app and make g available app = pylons.wsgiapp.PylonsApp(config, helpers=web.lib.helpers, g=app_globals.Globals) g = app.globals app = ConfigMiddleware(app, {'app_conf':app_conf, 'global_conf':global_conf}) # YOUR MIDDLEWARE # Put your own middleware here, so that any problems are caught by the error # handling middleware underneath # If errror handling and exception catching will be handled by middleware # for multiple apps, you will want to set full_stack = False in your config # file so that it can catch the problems. if asbool(full_stack): # Change HTTPExceptions to HTTP responses app = httpexceptions.make_middleware(app, global_conf) # Error Handling app = ErrorHandler(app, global_conf, error_template=error_template, **config.errorware) # Display error documents for 401, 403, 404 status codes (if debug is disabled also # intercepts 500) app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf) # Establish the Registry for this application app = RegistryManager(app) static_app = StaticURLParser(config.paths['static_files']) javascripts_app = StaticJavascripts() app = Cascade([static_app, javascripts_app, app]) return app
def make_app(global_conf, full_stack=True, **app_conf): """Create a WSGI application and return it global_conf is a dict representing the Paste configuration options, the paste.deploy.converters should be used when parsing Paste config options to ensure they're treated properly. """ load_environment(global_conf, app_conf) # Pull the other engine and put a new one up first config.template_engines.pop() kidopts = {'kid.assume_encoding': 'utf-8', 'kid.encoding': 'utf-8'} pylons.config.add_template_engine('kid', 'projectname.kidtemplates', kidopts) # Load our default Pylons WSGI app and make g available app = pylons.wsgiapp.PylonsApp(helpers=projectname.lib.helpers, g=app_globals.Globals) app = ConfigMiddleware(app, config._current_obj()) # If errror handling and exception catching will be handled by middleware # for multiple apps, you will want to set full_stack = False in your config # file so that it can catch the problems. if asbool(full_stack): # Change HTTPExceptions to HTTP responses app = httpexceptions.make_middleware(app, global_conf) # Error Handling app = ErrorHandler(app, global_conf, error_template=error_template, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (if debug is disabled also # intercepts 500) app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf) # Establish the Registry for this application app = RegistryManager(app) static_app = StaticURLParser(config['pylons.paths']['static_files']) javascripts_app = StaticJavascripts() app = Cascade([static_app, javascripts_app, app]) 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 load_environment(global_conf, app_conf) g = config['pylons.g'] # The Pylons WSGI app app = RedditApp() app = RoutesMiddleware(app, config["routes.map"]) # CUSTOM MIDDLEWARE HERE (filtered by the error handling middlewares) # last thing first from here down app = CleanupMiddleware(app) app = LimitUploadSize(app) profile_directory = g.config.get('profile_directory') if profile_directory: app = ProfilingMiddleware(app, profile_directory) app = DomainListingMiddleware(app) app = SubredditMiddleware(app) app = ExtensionMiddleware(app) app = DomainMiddleware(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) app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf) # Establish the Registry for this application app = RegistryManager(app) # Static files static_app = StaticURLParser(config['pylons.paths']['static_files']) static_cascade = [static_app, app] if config['r2.plugins'] and g.config['uncompressedJS']: plugin_static_apps = Cascade([ StaticURLParser(plugin.static_dir) for plugin in config['r2.plugins'] ]) static_cascade.insert(0, plugin_static_apps) app = Cascade(static_cascade) app = FullPathMiddleware(app) if not g.config['uncompressedJS'] and g.config['debug']: static_fallback = StaticTestMiddleware(static_app, g.config['static_path'], g.config['static_domain']) app = Cascade([static_fallback, app]) app = SafetyMiddleware(app) 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 load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(base_wsgi_app=RedditApp) # CUSTOM MIDDLEWARE HERE (filtered by the error handling middlewares) app = LimitUploadSize(app) app = ProfilingMiddleware(app) app = SourceViewMiddleware(app) app = DomainListingMiddleware(app) app = SubredditMiddleware(app) app = ExtensionMiddleware(app) app = DomainMiddleware(app) log_path = global_conf.get('log_path') if log_path: process_iden = global_conf.get('scgi_port', 'default') app = RequestLogMiddleware(log_path, process_iden, app) #TODO: breaks on 404 #app = make_gzip_middleware(app, app_conf) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, error_template=error_template, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and 500 when # debug is disabled) app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf) # Establish the Registry for this application app = RegistryManager(app) # Static files javascripts_app = StaticJavascripts() # Set cache headers indicating the client should cache for 7 days static_app = StaticURLParser(config['pylons.paths']['static_files'], cache_max_age=604800) app = Cascade([static_app, javascripts_app, app]) app = AbsoluteRedirectMiddleware(app) #add the rewrite rules app = RewriteMiddleware(app) app = CleanupMiddleware(app) return app