Ejemplo n.º 1
0
def wserver(args):
    """Run a server that reloads code automagically."""
    poll_interval = config.get('reloader_interval', 1)
    extra_files = config.get('reloader_extra_files', [])
    pid = _start_server()
    if pid:
        # we must call load_app() to process system_plugins and handlers
        # and get them into sys.modules, which is what the Monitor
        # watches.
        load_app()
        signal.signal(signal.SIGCHLD, sig_child_handler(pid))
        mon = ForkingMonitor(poll_interval=poll_interval, extra_files=extra_files)
        mon.pid = pid
        mon.periodic_reload()
Ejemplo n.º 2
0
def wserver(args):
    """Run a server that reloads code automagically."""
    poll_interval = config.get('reloader_interval', 1)
    extra_files = config.get('reloader_extra_files', [])
    pid = _start_server()
    if pid:
        # we must call load_app() to process system_plugins and handlers
        # and get them into sys.modules, which is what the Monitor
        # watches.
        load_app()
        signal.signal(signal.SIGCHLD, sig_child_handler(pid))
        mon = ForkingMonitor(poll_interval=poll_interval,
                             extra_files=extra_files)
        mon.pid = pid
        mon.periodic_reload()
def setup_module(module):
    # cleanup
    try:
        shutil.rmtree('store')
    except OSError:
        pass

    # establish web server
    app = load_app()
    def app_fn():
        return app
    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('our_test_domain', 8001, app_fn)

    # establish store
    store = Store(config['server_store'][0], config['server_store'][1],
            environ={'tiddlyweb.config': config})

    # make some stuff
    bag = Bag('place')
    store.put(bag)
    for i in range(1, 10):
        tiddler = Tiddler('tiddler%s' % i, 'place')
        tiddler.text = 'hi%s'
        store.put(tiddler)

    module.http = httplib2.Http()
Ejemplo n.º 4
0
def initialize_app():
    app = load_app()
    def app_fn():
        return app

    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('our_test_domain', 8001, app_fn)
Ejemplo n.º 5
0
def start():
    dirname = os.path.dirname(__file__)
    if sys.path[0] != dirname:
        sys.path.insert(0, dirname)
    from tiddlyweb.web import serve
    app = serve.load_app(app_prefix='', dirname=dirname)
    return app
Ejemplo n.º 6
0
def initialize_app():
    app = load_app()
    def app_fn():
        return app

    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('our_test_domain', 8001, app_fn)
Ejemplo n.º 7
0
def make_test_env(module):
    global SESSION_COUNT
    try:
        shutil.rmtree('test_instance')
    except:
        pass

    os.system('mysqladmin -f drop tiddlyspacetest create tiddlyspacetest')
    if SESSION_COUNT > 1:
        del sys.modules['tiddlywebplugins.tiddlyspace.store']
        del sys.modules['tiddlywebplugins.mysql2']
        del sys.modules['tiddlywebplugins.sqlalchemy2']
        import tiddlywebplugins.tiddlyspace.store
        import tiddlywebplugins.mysql2
        import tiddlywebplugins.sqlalchemy2
        clear_hooks(HOOKS)
    SESSION_COUNT += 1
    db_config = init_config['server_store'][1]['db_config']
    db_config = db_config.replace('///tiddlyspace?', '///tiddlyspacetest?')
    init_config['server_store'][1]['db_config'] = db_config
    init_config['log_level'] = 'DEBUG'

    if sys.path[0] != os.getcwd():
        sys.path.insert(0, os.getcwd())
    spawn('test_instance', init_config, instance_module)
    os.symlink('../tiddlywebplugins/templates', 'templates')

    from tiddlyweb.web import serve
    module.store = get_store(config)

    app = serve.load_app()

    def app_fn():
        return app
    module.app_fn = app_fn
Ejemplo n.º 8
0
def setup_module(module):
    try:
        shutil.rmtree('indexdir')
        shutil.rmtree('store')
    except:
        pass
    app = load_app()

    def app_fn(): return app

    requests_intercept.install()
    wsgi_intercept.add_wsgi_intercept('tankt.peermore.com', 8080, app_fn)

    store = get_store(config)
    test_bag1 = Bag('newtank')

    try:
        store.delete(test_bag1)
    except StoreError:
        pass

    test_bag1.policy.accept = ['NONE']
    store.put(test_bag1)
    module.environ = {'tiddlyweb.store': store, 'tiddlyweb.config': config}
    module.store = store
    module.cookie, module.csrf = establish_user_auth(config, store,
            'tankt.peermore.com:8080', 'tester')
Ejemplo n.º 9
0
def setup_module(module):
    try:
        shutil.rmtree('indexdir')
        shutil.rmtree('store')
    except:
        pass

    app = load_app()

    def app_fn(): return app

    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('tankt.peermore.com', 8080, app_fn)

    store = get_store(config)
    test_bag = Bag('editable')

    try:
        store.delete(test_bag)
    except StoreError:
        pass

    store.put(test_bag)
    module.environ = {'tiddlyweb.store': store, 'tiddlyweb.config': config}
    module.store = store
    module.http = httplib2.Http()
    module.csrf = None
Ejemplo n.º 10
0
def start():
    dirname = os.path.dirname(__file__)
    if sys.path[0] != dirname:
        sys.path.insert(0, dirname)
    from tiddlyweb.web import serve
    app = serve.load_app(app_prefix='', dirname=dirname)
    return app
Ejemplo n.º 11
0
def setup_module(module):
    try:
        shutil.rmtree('indexdir')
        shutil.rmtree('store')
    except:
        pass

    app = load_app()

    def app_fn():
        return app

    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('tankt.peermore.com', 8080, app_fn)

    store = get_store(config)
    test_bag = Bag('editable')

    try:
        store.delete(test_bag)
    except StoreError:
        pass

    store.put(test_bag)
    module.environ = {'tiddlyweb.store': store, 'tiddlyweb.config': config}
    module.store = store
    module.http = httplib2.Http()
    module.csrf = None
Ejemplo n.º 12
0
def setup_module(module):
    try:
        shutil.rmtree('indexdir')
        shutil.rmtree('store')
    except:
        pass
    app = load_app()

    def app_fn():
        return app

    requests_intercept.install()
    wsgi_intercept.add_wsgi_intercept('tankt.peermore.com', 8080, app_fn)

    store = get_store(config)
    test_bag1 = Bag('newtank')

    try:
        store.delete(test_bag1)
    except StoreError:
        pass

    test_bag1.policy.accept = ['NONE']
    store.put(test_bag1)
    module.environ = {'tiddlyweb.store': store, 'tiddlyweb.config': config}
    module.store = store
    module.cookie, module.csrf = establish_user_auth(
        config, store, 'tankt.peermore.com:8080', 'tester')
Ejemplo n.º 13
0
def make_test_env(module, hsearch=False):
    """
    If hsearch is False, don't bother updating the whoosh index
    for this test instance. We do this by removing the store HOOK
    used by whoosh.
    """
    global SESSION_COUNT

    # bump up a level if we're already in the test instance
    if os.getcwd().endswith('test_instance'):
        os.chdir('..')

    try:
        shutil.rmtree('test_instance')
    except:
        pass

    os.system(
        'echo "drop database if exists tiddlyspacetest; create database tiddlyspacetest character set = utf8mb4 collate = utf8mb4_bin;" | mysql'
    )
    if SESSION_COUNT > 1:
        del sys.modules['tiddlywebplugins.tiddlyspace.store']
        del sys.modules['tiddlywebplugins.mysql3']
        del sys.modules['tiddlywebplugins.sqlalchemy3']
        import tiddlywebplugins.tiddlyspace.store
        import tiddlywebplugins.mysql3
        import tiddlywebplugins.sqlalchemy3
        tiddlywebplugins.mysql3.Session.remove()
        clear_hooks(HOOKS)
    SESSION_COUNT += 1
    db_config = init_config['server_store'][1]['db_config']
    db_config = db_config.replace('///tiddlyspace?', '///tiddlyspacetest?')
    init_config['server_store'][1]['db_config'] = db_config
    init_config['log_level'] = 'DEBUG'

    if sys.path[0] != os.getcwd():
        sys.path.insert(0, os.getcwd())
    spawn('test_instance', init_config, instance_module)
    os.chdir('test_instance')
    os.symlink('../tiddlywebplugins/templates', 'templates')
    os.symlink('../tiddlywebplugins', 'tiddlywebplugins')

    from tiddlyweb.web import serve
    module.store = get_store(init_config)

    app = serve.load_app()

    if not hsearch:
        from tiddlywebplugins.whoosher import _tiddler_change_handler
        try:
            HOOKS['tiddler']['put'].remove(_tiddler_change_handler)
            HOOKS['tiddler']['delete'].remove(_tiddler_change_handler)
        except ValueError:
            pass

    def app_fn():
        return app

    module.app_fn = app_fn
Ejemplo n.º 14
0
def initialize_app():
    app = load_app()

    def app_fn():
        return app

    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('0.0.0.0', 8080, app_fn)
Ejemplo n.º 15
0
def establish():
    """
    Set up the global app.
    """
    from tiddlyweb.config import config

    global app
    app = App(load_app(), config)
    return app
Ejemplo n.º 16
0
def make_test_env(module, hsearch=False):
    """
    If hsearch is False, don't bother updating the whoosh index
    for this test instance. We do this by removing the store HOOK
    used by whoosh.
    """
    global SESSION_COUNT

    # bump up a level if we're already in the test instance
    if os.getcwd().endswith('test_instance'):
        os.chdir('..')

    try:
        shutil.rmtree('test_instance')
    except:
        pass

    os.system('echo "drop database if exists tiddlyspacetest; create database tiddlyspacetest character set = utf8mb4 collate = utf8mb4_bin;" | mysql')
    if SESSION_COUNT > 1:
        del sys.modules['tiddlywebplugins.tiddlyspace.store']
        del sys.modules['tiddlywebplugins.mysql3']
        del sys.modules['tiddlywebplugins.sqlalchemy3']
        import tiddlywebplugins.tiddlyspace.store
        import tiddlywebplugins.mysql3
        import tiddlywebplugins.sqlalchemy3
        tiddlywebplugins.mysql3.Session.remove()
        clear_hooks(HOOKS)
    SESSION_COUNT += 1
    db_config = init_config['server_store'][1]['db_config']
    db_config = db_config.replace('///tiddlyspace?', '///tiddlyspacetest?')
    init_config['server_store'][1]['db_config'] = db_config
    init_config['log_level'] = 'DEBUG'

    if sys.path[0] != os.getcwd():
        sys.path.insert(0, os.getcwd())
    spawn('test_instance', init_config, instance_module)
    os.chdir('test_instance')
    os.symlink('../tiddlywebplugins/templates', 'templates')
    os.symlink('../tiddlywebplugins', 'tiddlywebplugins')

    from tiddlyweb.web import serve
    module.store = get_store(init_config)

    app = serve.load_app()

    if not hsearch:
        from tiddlywebplugins.whoosher import _tiddler_change_handler
        try:
            HOOKS['tiddler']['put'].remove(_tiddler_change_handler)
            HOOKS['tiddler']['delete'].remove(_tiddler_change_handler)
        except ValueError:
            pass

    def app_fn():
        return app
    module.app_fn = app_fn
def start():
    # What is our hostname
    hostname = config['hostname']

    # What is path to us (the base url)
    port = 80
    if ':' in hostname:
        hostname, port = hostname.split(':')

    app = serve.load_app(hostname, port, config['urls_map'])
    return app
Ejemplo n.º 18
0
def initialize_app(cfg):
    config.update(cfg) # XXX: side-effecty
    config['server_host'] = {
        'scheme': 'http',
        'host': 'example.org',
        'port': '8001',
    }

    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('example.org', 8001, lambda: load_app())

    return config
Ejemplo n.º 19
0
def _initialize_app(cfg):
    config.update(cfg) # XXX: side-effecty
    config['server_host'] = {
        'scheme': 'http',
        'host': 'example.org',
        'port': '8001',
    }
    config['system_plugins'].append('tiddlywebplugins.tagdex')

    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('example.org', 8001, lambda: load_app())

    return config
Ejemplo n.º 20
0
def setup_module(module):
    app = load_app()
    def app_fn():
        return app

    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('0.0.0.0', 8080, app_fn)

    module.store = get_store(config)
    module.http = httplib2.Http()

    try:
        shutil.rmtree('store')
    except:
        pass  # we don't care
Ejemplo n.º 21
0
def make_test_env(module, hsearch=False):
    """
    If hsearch is False, don't bother updating the whoosh index
    for this test instance. We do this by removing the store HOOK
    used by whoosh.
    """
    global SESSION_COUNT
    try:
        shutil.rmtree('test_instance')
    except:
        pass

    os.system('mysqladmin -f drop tiddlyspacetest create tiddlyspacetest')
    if SESSION_COUNT > 1:
        del sys.modules['tiddlywebplugins.tiddlyspace.store']
        del sys.modules['tiddlywebplugins.mysql3']
        del sys.modules['tiddlywebplugins.sqlalchemy3']
        import tiddlywebplugins.tiddlyspace.store
        import tiddlywebplugins.mysql3
        import tiddlywebplugins.sqlalchemy3
        clear_hooks(HOOKS)
    SESSION_COUNT += 1
    db_config = init_config['server_store'][1]['db_config']
    db_config = db_config.replace('///tiddlyspace?', '///tiddlyspacetest?')
    init_config['server_store'][1]['db_config'] = db_config
    init_config['log_level'] = 'DEBUG'

    if sys.path[0] != os.getcwd():
        sys.path.insert(0, os.getcwd())
    spawn('test_instance', init_config, instance_module)
    os.symlink('tiddlywebplugins/templates', 'test_instance/templates')

    from tiddlyweb.web import serve
    module.store = get_store(config)

    app = serve.load_app()

    if not hsearch:
        from tiddlywebplugins.whoosher import _tiddler_change_handler
        try:
            HOOKS['tiddler']['put'].remove(_tiddler_change_handler)
            HOOKS['tiddler']['delete'].remove(_tiddler_change_handler)
        except ValueError:
            pass

    def app_fn():
        return app
    module.app_fn = app_fn
def setup_module(module):
    # cleanup
    try:
        shutil.rmtree('store')
    except OSError:
        pass

    # establish web server
    app = load_app()
    def app_fn():
        return app
    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('our_test_domain', 8001, app_fn)

    module.store = get_store(config)
    module.http = httplib2.Http()
Ejemplo n.º 23
0
def start_server(config):
    from cheroot.wsgi import Server as WSGIServer
    hostname = config['server_host']['host']
    port = int(config['server_host']['port'])
    scheme = config['server_host']['scheme']
    app = load_app()
    server = WSGIServer((hostname, port), app)
    try:
        LOGGER.debug('starting Cheroot at %s://%s:%s',
                scheme, hostname, port)
        std_error_message("Starting Cheroot at %s://%s:%s"
                % (scheme, hostname, port))
        server.start()
    except KeyboardInterrupt:
        server.stop()
        sys.exit(0)
Ejemplo n.º 24
0
def initialize_app(config, domain='our_test_domain', port=8001):
    """
    Setup a wsgi intercepted server.
    """
    config['server_host'] = {
        'scheme': 'http',
        'host': domain,
        'port': str(port),
    }
    app = load_app()

    def app_fn():
        return app

    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept(domain, port, app_fn)
Ejemplo n.º 25
0
def initialize_app(config, domain='our_test_domain', port=8001):
    """
    Setup a wsgi intercepted server.
    """
    config['server_host'] = {
            'scheme': 'http',
            'host': domain,
            'port': str(port),
    }
    app = load_app()

    def app_fn():
        return app

    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept(domain, port, app_fn)
def setup_module(module):
    try:
        shutil.rmtree('store')
    except:  # it's not there
        pass

    app = load_app()
    def app_fn():
        return app

    module.store = get_store(config)

    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('0.0.0.0', 8080, app_fn)

    module.http = httplib2.Http()
def setup_module(module):
    if os.path.exists("store"):
        shutil.rmtree("store")

    if CSRFProtector not in config["server_request_filters"]:
        config["server_request_filters"].append(CSRFProtector)

    app = load_app()

    def app_fn():
        return app

    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept("0.0.0.0", 8080, app_fn)
    wsgi_intercept.add_wsgi_intercept("foo.0.0.0.0", 8080, app_fn)

    module.http = httplib2.Http()
def setup_module(module):
    # cleanup
    try:
        shutil.rmtree("store")
    except OSError:
        pass

    # establish web server
    app = load_app()

    def app_fn():
        return app

    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept("our_test_domain", 8001, app_fn)

    # establish store
    store = Store(config["server_store"][0], config["server_store"][1], environ={"tiddlyweb.config": config})

    # make some stuff
    bag = Bag("place")
    store.put(bag)

    recipe = Recipe("plaice")
    recipe.set_recipe([("place", "")])
    store.put(recipe)

    tiddler = Tiddler("one", "place")
    tiddler.text = "hi"
    store.put(tiddler)

    tiddler = Tiddler("two", "place")
    tiddler.tags = ["tagged"]
    tiddler.text = "hi"
    store.put(tiddler)

    module.store = store
    # module.http = httplib2.Http('.test_cache')
    module.http = httplib2.Http()
Ejemplo n.º 29
0
def make_test_env(module):
    global SESSION_COUNT
    try:
        shutil.rmtree("test_instance")
    except:
        pass

    os.system("mysqladmin -f drop tiddlyspacetest create tiddlyspacetest")
    if SESSION_COUNT > 1:
        del sys.modules["tiddlywebplugins.tiddlyspace.store"]
        del sys.modules["tiddlywebplugins.mysql3"]
        del sys.modules["tiddlywebplugins.sqlalchemy3"]
        import tiddlywebplugins.tiddlyspace.store
        import tiddlywebplugins.mysql3
        import tiddlywebplugins.sqlalchemy3

        clear_hooks(HOOKS)
    SESSION_COUNT += 1
    db_config = init_config["server_store"][1]["db_config"]
    db_config = db_config.replace("///tiddlyspace?", "///tiddlyspacetest?")
    init_config["server_store"][1]["db_config"] = db_config
    init_config["log_level"] = "DEBUG"

    if sys.path[0] != os.getcwd():
        sys.path.insert(0, os.getcwd())
    spawn("test_instance", init_config, instance_module)
    os.symlink("../tiddlywebplugins/templates", "templates")

    from tiddlyweb.web import serve

    module.store = get_store(config)

    app = serve.load_app()

    def app_fn():
        return app

    module.app_fn = app_fn
Ejemplo n.º 30
0
def make_test_env(module):
    global SESSION_COUNT
    try:
        shutil.rmtree('test_instance')
    except:
        pass

    os.system('mysqladmin -f drop tiddlyspacetest create tiddlyspacetest')
    if SESSION_COUNT > 1:
        del sys.modules['tiddlywebplugins.tiddlyspace.store']
        del sys.modules['tiddlywebplugins.mysql2']
        del sys.modules['tiddlywebplugins.sqlalchemy2']
        import tiddlywebplugins.tiddlyspace.store
        import tiddlywebplugins.mysql2
        import tiddlywebplugins.sqlalchemy2
        clear_hooks(HOOKS)
    SESSION_COUNT += 1
    db_config = init_config['server_store'][1]['db_config']
    db_config = db_config.replace('///tiddlyspace?', '///tiddlyspacetest?')
    init_config['server_store'][1]['db_config'] = db_config
    init_config['log_level'] = 'DEBUG'

    if sys.path[0] != os.getcwd():
        sys.path.insert(0, os.getcwd())
    spawn('test_instance', init_config, instance_module)
    os.symlink('../tiddlywebplugins/templates', 'templates')

    from tiddlyweb.web import serve
    module.store = get_store(config)

    app = serve.load_app()

    def app_fn():
        return app

    module.app_fn = app_fn
Ejemplo n.º 31
0
 def app_fn():
     return serve.load_app()
Ejemplo n.º 32
0
def start():
    app = serve.load_app()
    return app
Ejemplo n.º 33
0
def main():
    wsgiref.handlers.CGIHandler().run(load_app())
Ejemplo n.º 34
0
def _app():
    return serve.load_app()
Ejemplo n.º 35
0
def test_missing_system_plugin():
    config['system_plugins'] = ['missingplugin']
    with py.test.raises(ImportError):
        serve.load_app()
    config['system_plugins'] = []
Ejemplo n.º 36
0
def test_existing_system_plugin():
    config['system_plugins'] = ['test.simpleplugin']
    with py.test.raises(PluginHere):
        serve.load_app()
    config['system_plugins'] = []
Ejemplo n.º 37
0
def _app():
    return serve.load_app()
Ejemplo n.º 38
0
 def app_fn():
     return load_app()
def app_fn():
    from tiddlyweb.web import serve
    return serve.load_app()
Ejemplo n.º 40
0
def main():
    wsgiref.handlers.CGIHandler().run(load_app())
Ejemplo n.º 41
0
 def app_fn():
     return serve.load_app()