Ejemplo n.º 1
0
def run_app(args, quiet=None):
    logging.basicConfig(level=logging.INFO,
                        format='%(levelname)-8s: %(message)s')

    app_installs = []
    view_installs = []

    # Hide the numbers in incognito mode. We do this on response text via a plug-in.
    if args.incognito:
        args.no_source = True
        app.install(incognito)
        app_installs.append(incognito)
        viewapp.install(incognito)
        view_installs.append(incognito)

    # Install code that will restrict all resources to a particular view.
    if args.view:
        view_url_prefix = '/view/{}/'.format(args.view)
        url_restrictor = url_restrict_generator(view_url_prefix)
        app.install(url_restrictor)
        app_installs.append(url_restrictor)

    app.options = None

    # Add an account transformer.
    app.account_xform = account.AccountTransformer(
        '__' if args.no_colons else None)

    # Load templates.
    with open(path.join(path.dirname(__file__), 'web.html')) as f:
        global template
        template = bottle.SimpleTemplate(f)

    with open(path.join(path.dirname(__file__), 'web.css')) as f:
        global STYLE
        STYLE = f.read()

    # Run the server.
    app.args = args
    bind_address = '0.0.0.0' if args.public else 'localhost'
    app.run(host=bind_address,
            port=args.port,
            debug=args.debug,
            reloader=False,
            quiet=args.quiet if hasattr(args, 'quiet') else quiet)

    # Uninstall applications.
    for function in app_installs:
        app.uninstall(function)
    for function in view_installs:
        viewapp.uninstall(function)
Ejemplo n.º 2
0
 def test_noop(self):
     xfr = account.AccountTransformer()
     acc = 'Assets:US:BofA:Checking'
     self.assertEqual(acc, xfr.render(acc))
     self.assertEqual(acc, xfr.parse(acc))
Ejemplo n.º 3
0
 def test_parse(self):
     xfr = account.AccountTransformer('__')
     self.assertEqual('Assets:US:BofA:Checking',
                      xfr.parse('Assets__US__BofA__Checking'))