def __init__(self, app): self.app = app threadedprint.install(leave_stdout=True) threadedprint.install_stdin() self.counter = count() self.static_app = StaticURLParser(os.path.join(here, 'pdbcapture/static')) self.media_app = StaticURLParser(os.path.join(here, 'eval-media')) self.states = {}
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) # 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']) import os root = config['pylons.paths']['root'] overroot = os.path.dirname(root) appcelerator_static = StaticURLParser(os.path.join(overroot, 'public'), root_directory=overroot) app = Cascade([appcelerator_static, static_app, app]) 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 load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp() 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, [401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) # Static files if asbool(static_files): static_app = StaticURLParser(config['pylons.paths']['static_files']) media_app = StaticURLParser(config['app_conf']['media_dir']) thumb_app = StaticURLParser(config['app_conf']['thumb_dir']) urlmap = URLMap() urlmap['/media'] = media_app urlmap['/thumb'] = thumb_app app = Cascade([urlmap, static_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 render_graph(self, req): """ Used to display rendered graphs; if the graph that the user is trying to access does not exist--and the ``session_uuid`` exists in our history--it will be rendered. This also creates a thumbnail image, since some of these graphs can grow to be extremely large. ``req``: :class:`webob.Request` containing the environment information from the request itself. Returns a WSGI application. """ path_info = req.path_info_peek() if '.' not in path_info: return StaticURLParser(GRAPH_DIR) fileid, _, ext = path_info.rpartition('.') if path_info.startswith("thumb-"): fileid = fileid[6:] if '--' not in fileid: return StaticURLParser(GRAPH_DIR) session_uuid, _, cutoff_time = fileid.rpartition('--') cutoff_time = int(cutoff_time) # We now have the session_uuid session = self._backend.get(session_uuid) if session: force_thumbnail_creation = False filename = "%s.png" % fileid path = os.path.join(GRAPH_DIR, filename) if not os.path.exists(path): graph, root_nodes, removed_edges = prepare_graph( session._graph, cutoff_time, False) draw_graph(graph, path) force_thumbnail_creation = True thumbnail_filename = "thumb-%s.png" % fileid thumbnail_path = os.path.join(GRAPH_DIR, thumbnail_filename) if not os.path.exists(thumbnail_path) or force_thumbnail_creation: log.debug("Creating thumbnail for %s at %s.", session_uuid, thumbnail_path) im = Image.open(path, 'r') im.thumbnail((600, 600), Image.ANTIALIAS) im.save(thumbnail_path) return StaticURLParser(GRAPH_DIR)
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 __call__(self, environ, start_response): req = Request(environ) if req.path_info_peek() == '.media': req.path_info_pop() app = StaticURLParser(os.path.join(os.path.dirname(__file__), 'media')) return app(environ, start_response) if self.base_dir: filename = os.path.join(self.base_dir, req.path_info.lstrip('/')) assert filename.startswith(self.base_dir) else: filename = self.filename if req.method not in ('GET', 'POST'): resp = exc.HTTPMethodNotAllowed('Bad method: %s' % req.method, allow='GET,POST') elif os.path.isdir(filename): if req.method == 'POST': resp = self.save_create(req, filename) else: if not req.path.endswith('/'): resp = exc.HTTPMovedPermanently(add_slash=True) else: resp = self.view_dir(req, filename) else: if req.method == 'POST': resp = self.save_file(req, filename) elif req.method == 'GET': resp = self.edit_file(req, filename) return resp(environ, start_response)
def make_wsgi_app(): # BasicAuth applications create = AuthBasicHandler(BlogCreate, 'www', authfunc) update = AuthBasicHandler(BlogUpdate, 'www', authfunc) delete = AuthBasicHandler(BlogDelete, 'www', authfunc) # URL dispatching middleware dispatch = selector.Selector() dispatch.add('/', GET=BlogIndex) dispatch.prefix = '/article' dispatch.add('/add', GET=create, POST=create) dispatch.add('/{id:digits}', GET=BlogRead) dispatch.add('/{id:digits}/edit', GET=update, POST=update) dispatch.add('/{id:digits}/delete', GET=delete) # Static files from paste.urlparser import StaticURLParser static_app = StaticURLParser("my_wsgi_blog/static/") from paste import urlmap mapping = urlmap.URLMap() mapping['/static'] = static_app from paste.cascade import Cascade app = Cascade([mapping, dispatch]) 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) # 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 _serve_file(self, root, path): """Call Paste's FileApp (a WSGI application) to serve the file at the specified path """ static = StaticURLParser(root) request.environ['PATH_INFO'] = '/%s' % path return static(request.environ, self.start_response)
def filter_app_factory(cls, app, global_conf, prefix='', **app_conf): """Set-up Policy Enforcement Point to enforce access control decisions based on the URI path requested and/or the HTTP response code set by application(s) to be protected. An AuthKit ``MultiHandler`` is setup to handle the latter. ``PEPResultHandlerMiddleware`` handles the output set following an access denied decision :type app: callable following WSGI interface :param app: next middleware application in the chain :type global_conf: dict :param global_conf: ``PasteDeploy`` global configuration dictionary :type prefix: basestring :param prefix: prefix for configuration items :type app_conf: dict :param app_conf: ``PasteDeploy`` application specific configuration \ dictionary """ # Allow for static content for use with PEP result handler middleware resultHandlerParamPrefix = prefix + cls.RESULT_HANDLER_PARAM_PREFIX resultHandlerStaticContentDirParamName = \ resultHandlerParamPrefix + \ cls.RESULT_HANDLER_STATIC_CONTENT_DIR_PARAMNAME resultHandlerStaticContentDir = app_conf.get( resultHandlerStaticContentDirParamName) if resultHandlerStaticContentDir is not None: staticApp = StaticURLParser(resultHandlerStaticContentDir) app = Cascade([app, staticApp], catch=(httplib.NOT_FOUND,)) pepPrefix = prefix + cls.PEP_PARAM_PREFIX pepFilter = cls.PEP_FILTER.filter_app_factory(app, global_conf, prefix=pepPrefix, **app_conf) # Now add the multi-handler to enable result handler to be invoked on # 403 forbidden status from upstream middleware app = MultiHandler(pepFilter) resultHandlerClassName = app_conf.pop( prefix+cls.RESULT_HANDLER_PARAMNAME, None) if resultHandlerClassName is None: resultHandler = PEPResultHandlerMiddleware else: resultHandler = importClass(resultHandlerClassName, objectType=PEPResultHandlerMiddlewareBase) app.add_method(resultHandler.__class__.__name__, resultHandler.filter_app_factory, global_conf, prefix=resultHandlerParamPrefix, **app_conf) app.add_checker(resultHandler.__class__.__name__, Http403ForbiddenStatusHandler.intercept) 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 setup_module(module): from paste.script import testapp static_app = StaticURLParser( os.path.join(os.path.dirname(__file__), 'test-static')) wsgi_intercept.add_wsgi_intercept('wsgify.org', 80, lambda: static_app) wsgi_intercept.add_wsgi_intercept( 'wsgify.org', 9999, lambda: testapp.TestApplication(text=True))
def docs_app(self, environ, start_response): """Registers widgetbrowser_js as resources before serving static html files so it is injected into the page""" from paste.urlparser import StaticURLParser app = StaticURLParser(self.built_docs) resources = widgets.widgetbrowser_js.retrieve_resources() tw.framework.register_resources(resources) return app(environ, start_response)
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 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) # Teambox debugging. if config['debug']: app = TeamboxDebugMiddleware(app) # Production setup. else: app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Handle special status codes. 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]) # Change the url scheme when needed. if config.has_key('url_scheme'): app = UrlSchemeMiddleware(app, config['url_scheme']) return app
def devserver(storageModel): """Starts a development server with a development, sqllite based model. Otherwise, gcloud compatible storage will be used.""" from paste import httpserver from paste.urlparser import StaticURLParser from paste.cascade import Cascade static_server = StaticURLParser('client') testapp = Cascade([static_server, app]) httpserver.serve(testapp, host='127.0.0.1', port='8080')
def main(): from paste import httpserver from paste.cascade import Cascade from paste.urlparser import StaticURLParser assets_dir = os.path.join(os.path.dirname(__file__)) static_app = StaticURLParser(directory=assets_dir) web_app = Cascade([app, static_app]) httpserver.serve(web_app, host='localhost', port='8080')
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) #app = TransLogger(app) app = AuthenticationMiddleware(app) import pylons if pylons.__version__ >= "0.9.7": # Routing/Session/Cache Middleware from beaker.middleware import CacheMiddleware, SessionMiddleware from routes.middleware import RoutesMiddleware 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, [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]) 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 not asbool(app_conf.get('noauth')): app = authkit.authorize.middleware(app, BlueChipUser()) # 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) status_codes = [400, 401, 403, 404] if not asbool(config.get('debug')): status_codes.append(500) app = StatusCodeRedirect(app, status_codes) # 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']) app = Cascade([static_app, app]) if not asbool(app_conf.get('noauth')): app = AuthBasicHandler(app, 'BlueChips', authenticate) app = DummyAuthenticate(app, app_conf) return app
def media(self, req): """ Serves up static files relative to ``MEDIA_DIR``. ``req``: :class:`webob.Request` containing the environment information from the request itself. Returns a WSGI application. """ return StaticURLParser(MEDIA_DIR)
def add_media_to_app(django_app): """ Return a WSGI application made up of the Django application, its media and the Django Admin media. """ app = URLMap() app['/'] = django_app # The Django App has been loaded, so it's now safe to access the settings: from django.conf import settings # Setting up the Admin media: admin_media = path.join(_DJANGO_ROOT, "contrib", "admin", "media") app[settings.ADMIN_MEDIA_PREFIX] = StaticURLParser(admin_media) # Setting up the media for the Django application: app[settings.MEDIA_URL] = StaticURLParser(settings.MEDIA_ROOT) return app
def factory(global_conf, **app_conf): """create a sample redirector""" assert 'app.directory' in app_conf directory = app_conf['app.directory'] assert os.path.isdir(directory) keystr = 'redirector.' args = dict([(key.split(keystr, 1)[-1], value) for key, value in app_conf.items() if key.startswith(keystr) ]) app = StaticURLParser(directory) redirector = Redirector(app, **args) return HTTPExceptionHandler(redirector)
def main(): from paste.urlparser import StaticURLParser from paste.cascade import Cascade # FIXME: this makes the source of the # App downloadable; we should put css/js # inside of a special serving folder static_app = StaticURLParser(".") # look for css, js, html before webapp URLs appfull = Cascade([static_app, app]) from paste import httpserver httpserver.serve(appfull)
def __init__(self, root_dir, cache_max_age=3600, package_name=None): # package_name is for bw compat; it is preferred to pass in a # package-relative path as root_dir # (e.g. ``anotherpackage:foo/static``). if package_name is None: package_name = caller_package().__name__ package_name, root_dir = resolve_asset_spec(root_dir, package_name) if package_name is None: app = StaticURLParser(root_dir, cache_max_age=cache_max_age) else: app = PackageURLParser( package_name, root_dir, cache_max_age=cache_max_age) self.app = 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, False) # The Pylons WSGI app app = PylonsApp() 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 config['pylons.app_globals'].OPT.compressionEnabled: app = gzipper(app, config['pylons.app_globals'].OPT.compressionLevel) # Static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) prefix = config['pylons.app_globals'].OPT.urlPrefix if prefix and prefix.startswith('/') and len(prefix) > 1: app = PrefixMiddleware(app, global_conf, prefix=prefix) 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() # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) app = CacheMiddleware(app, config) if asbool(full_stack): # Display error documents for 401, 403, 404 status codes (and 500 when debug is disabled) if asbool(config['debug']): app = ErrorHandler(app, global_conf, **config['pylons.errorware']) else: app = PrintErrors(app, global_conf, **config['pylons.errorware']) # 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 = GzipMiddleware(app, compresslevel=5) if asbool(config.get("nwrsc.onsite", False)): announcer = DatabaseAnnouncer(config.get('seriesdir', 'missing')) announcer.start() return app
def action_media(self, req, resource_fetcher): """ Serves up media from the ``deliverance/media`` directory. """ ## FIXME: I'm not using this currently, because the Javascript ## didn't work. Dunno why. from paste.urlparser import StaticURLParser app = StaticURLParser(os.path.join(os.path.dirname(__file__), 'media')) ## FIXME: need to pop some segments from the req? req.path_info_pop() resp = req.get_response(app) if resp.content_type == 'application/x-javascript': resp.content_type = 'application/javascript' return resp
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 asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, error_template=error_template, **config['pylons.errorware']) # AuthKit Support app = authkit.authenticate.middleware(app, app_conf) # 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]) 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 __init__(self, static_paths={}): """Constructor. static_paths -- a dictionary mapping plugin identifiers (used in static file URIs) to the paths where those plugins' static files reside """ self.static_paths = static_paths self.url_parsers = {} for plugin_name, path in self.static_paths.items(): self.url_parsers[plugin_name] = StaticURLParser(path) if not 'spline' in self.url_parsers: raise ValueError("A default 'spline' static path is required.") self.default_parser = self.url_parsers['spline']