Exemplo n.º 1
0
def make_app(config_file=None, benchmark=False, login_template=None):
    from edwin.config import read_config
    config = {}
    if config_file is not None and os.path.exists(config_file):
        config = read_config(config_file)
    app = Application(ApplicationContext(config=config))
    app = login_middleware(app, config_file, form_template=login_template)
    if benchmark:
        app = timeit(app)
    return wsgi_app(app)
Exemplo n.º 2
0
def main(args=sys.argv[1:]): #pragma NO COVERAGE, called from console
    from edwin.config import read_config
    profile = False
    if '--profile' in args:
        profile = True
        args.remove('--profile')

    config_file = None
    if args:
        config_file = args[0]
    app = make_app(config_file)

    from paste.httpserver import serve
    config = read_config(config_file)
    port = config.get('http_port', 8080)

    if profile:
        import cProfile
        cProfile.runctx('serve(app, port=port)', globals(), locals())
    else:
        serve(app, port=port)
Exemplo n.º 3
0
def login_middleware(app, config_file=None, form_template=None):
    from happy.login import FormLoginMiddleware
    from happy.login import HtpasswdBroker
    from happy.login import FlatFilePrincipalsBroker
    from happy.login import RandomUUIDCredentialBroker
    from edwin.config import read_config
    if config_file is None:
        from edwin.config import get_default_config_file
        config_file = get_default_config_file()
    config = read_config(config_file, 'login')
    here = os.path.dirname(config_file)
    htpasswd_file = config.get('htpasswd_file', os.path.join(here, 'htpasswd'))
    principals_file = config.get('principals_file',
                                 os.path.join(here, 'principals'))
    credentials_file = config.get('credentials_file',
                                  os.path.join(here, 'credentials.db'))
    return FormLoginMiddleware(
        app,
        HtpasswdBroker(htpasswd_file),
        FlatFilePrincipalsBroker(principals_file),
        RandomUUIDCredentialBroker(credentials_file),
        form_template=form_template,
    )