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) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) app = authkit.authenticate.middleware(app, app_conf) # added for auth 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, [400, 401, 403, 404, 415]) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 415, 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 = gzipper.middleware(app, compress_level=6) return app
def create_pipe(app, *args, **kw): '''Use with Apache only, fixes the content-length when gzipped''' try: from paste.gzipper import middleware app = middleware(app) except ImportError: pass return app
from paste.fixture import TestApp from paste.gzipper import middleware import gzip, cStringIO def simple_app(environ, start_response): start_response('200 OK', [('content-type', 'text/plain')]) return 'this is a test' wsgi_app = middleware(simple_app) app = TestApp(wsgi_app) def test_gzip(): res = app.get('/', extra_environ=dict(HTTP_ACCEPT_ENCODING='gzip')) assert int(res.header('content-length')) == len(res.body) assert res.body != 'this is a test' actual = gzip.GzipFile(fileobj=cStringIO.StringIO(res.body)).read() assert actual == 'this is a test'
from libs import bottle from libs.bottle import run from src.dispatcher import * from config import Config from init_db import init_tables init_tables() Config().refresh_config() #run(host='localhost', port=8090, debug=True) if __name__ == '__main__': try: from paste import gzipper # @UnresolvedImport app = gzipper.middleware(bottle.app()) from cherrypy import wsgiserver # @UnusedImport @UnresolvedImport print "Paste Gzip activated, CherryPy activated" run(app=app, host='localhost', port=Config().ServerPort, server='cherrypy') except: try: from cherrypy import wsgiserver # @UnusedImport @Reimport @UnresolvedImport print "Paste Gzip not found, CherryPy activated" run(host='localhost', port=Config().ServerPort, server='cherrypy') except: print "Paste Gzip not found, CherryPy not found Debug mode" run(host='localhost', port=Config().ServerPort, debug=True)
from paste.fixture import TestApp from paste.gzipper import middleware import gzip import six def simple_app(environ, start_response): start_response('200 OK', [('content-type', 'text/plain')]) return [b'this is a test'] wsgi_app = middleware(simple_app) app = TestApp(wsgi_app) def test_gzip(): res = app.get( '/', extra_environ=dict(HTTP_ACCEPT_ENCODING='gzip')) assert int(res.header('content-length')) == len(res.body) assert res.body != b'this is a test' actual = gzip.GzipFile(fileobj=six.BytesIO(res.body)).read() assert actual == b'this is a test'
def main(): parser = optparse.OptionParser( usage='%prog [OPTS]', ) parser.add_option( '-v', '--verbose', help='Verbose mode [default %default]', action="store_true", dest="verbose" ) parser.add_option( '--config', help=('Path to the file with information on how to ' 'configure google-get' ), metavar='PATH', ) parser.add_option( '--db-config', help=('Path to the file with information on how to ' 'retrieve and store data in the database' ), metavar='PATH', ) parser.set_defaults( verbose=False, ) options, args = parser.parse_args() if args: parser.error('Wrong number of arguments.') if options.config is None: parser.error('Missing option --config=.') if options.db_config is None: parser.error('Missing option --db-config=.') config = config_parser(options.config) host = config.get('connection', 'host') port = config.get('connection', 'port') coll = collections( config=options.db_config, read_preference=pymongo.ReadPreference.SECONDARY, ) events_coll = coll['events-collection'] keys_coll = coll['keys-collection'] logging.basicConfig( level=logging.DEBUG if options.verbose else logging.INFO, format='%(asctime)s.%(msecs)03d %(name)s: %(levelname)s: %(message)s', datefmt='%Y-%m-%dT%H:%M:%S', ) indices = [ {'facebook.start_time': pymongo.ASCENDING}, ] mongo.create_indices( collection=events_coll, indices=indices, ) uber_api = EventAPI01( keys_coll=keys_coll, events_coll=events_coll, ) install(uber_api) log.info( 'Starting server http://{host}:{port}'.format( host=host, port=port, ) ) app = middleware(default_app()) run(app=app, host=host, port=port, server=APIServer, quiet=True, )
def main(): parser = argparse.ArgumentParser(description='Start the Glue API', ) parser.add_argument( '-v', '--verbose', action='store_true', default=False, help='output DEBUG logging statements (default: %(default)s)', ) parser.add_argument( '--config', help=('path to the file with information on how to ' 'configure the Glue API'), required=True, metavar='PATH', type=str, ) parser.add_argument( '--db-config', help=('path to the file with information on how to ' 'retrieve and store data in the database'), required=True, metavar='PATH', type=str, ) args = parser.parse_args() logging.basicConfig( level=logging.DEBUG if args.verbose else logging.INFO, format='%(asctime)s.%(msecs)03d %(name)s: %(levelname)s: %(message)s', datefmt='%Y-%m-%dT%H:%M:%S', ) config = config_parser(args.config) host = config.get('connection', 'host') port = config.get('connection', 'port') pem = config_option(config.get, 'connection', 'ssl-pem') colls = collections(config=args.db_config, ) indices = [ { 'meta.hosts': pymongo.ASCENDING }, ] mongo.create_indices( collection=colls['gumjabi-keys'], indices=indices, ) restrict = config_option( config.getboolean, 'api', 'restrict-hosts', ) if restrict is None: restrict = False glue_api = EventAPI01( colls, restrict_hosts=restrict, ) install(glue_api) log.info('Starting server http://{host}:{port}'.format( host=host, port=port, )) app = middleware(default_app()) server_opts = dict([ ('quiet', True), ]) if pem: pem = abs_path(pem) server_opts['ssl_pem'] = pem run(app=app, host=host, port=port, server=APIServer, **server_opts)
def main(): parser = argparse.ArgumentParser( description='Start the Glue API', ) parser.add_argument( '-v', '--verbose', action='store_true', default=False, help='output DEBUG logging statements (default: %(default)s)', ) parser.add_argument( '--config', help=('path to the file with information on how to ' 'configure the Glue API' ), required=True, metavar='PATH', type=str, ) parser.add_argument( '--db-config', help=('path to the file with information on how to ' 'retrieve and store data in the database' ), required=True, metavar='PATH', type=str, ) args = parser.parse_args() logging.basicConfig( level=logging.DEBUG if args.verbose else logging.INFO, format='%(asctime)s.%(msecs)03d %(name)s: %(levelname)s: %(message)s', datefmt='%Y-%m-%dT%H:%M:%S', ) config = config_parser(args.config) host = config.get('connection', 'host') port = config.get('connection', 'port') pem = config_option(config.get, 'connection', 'ssl-pem') colls = collections( config=args.db_config, ) indices = [ {'meta.hosts': pymongo.ASCENDING}, ] mongo.create_indices( collection=colls['gumjabi-keys'], indices=indices, ) restrict = config_option( config.getboolean, 'api', 'restrict-hosts', ) if restrict is None: restrict = False glue_api = EventAPI01( colls, restrict_hosts=restrict, ) install(glue_api) log.info( 'Starting server http://{host}:{port}'.format( host=host, port=port, ) ) app = middleware(default_app()) server_opts = dict([ ('quiet', True), ]) if pem: pem = abs_path(pem) server_opts['ssl_pem'] = pem run(app=app, host=host, port=port, server=APIServer, **server_opts )