Beispiel #1
0
def establish_www(config):
    """
    Set up the routes and WSGI Middleware used by TiddlySpace.
    """
    replace_handler(config['selector'], '/', dict(GET=home))
    config['selector'].add('/_safe', GET=safe_mode, POST=safe_mode)
    add_spaces_routes(config['selector'])
    add_profile_routes(config['selector'])
    config['selector'].add('/users/{username}/identities',
            GET=get_identities)
    config['selector'].add('/{tiddler_name:segment}[/{tiddler_extra:any}]',
            GET=friendly_uri)

    if ControlView not in config['server_request_filters']:
        config['server_request_filters'].insert(
                config['server_request_filters'].
                index(Negotiate) + 1, ControlView)

    if DropPrivs not in config['server_request_filters']:
        config['server_request_filters'].insert(
                config['server_request_filters'].
                index(ControlView) + 1, DropPrivs)

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

    if AllowOrigin not in config['server_response_filters']:
        config['server_response_filters'].insert(
                config['server_response_filters'].
                index(PrettyHTTPExceptor) + 1, AllowOrigin)
Beispiel #2
0
def init(config):
    merge_config(config, local_config)
    tiddlywebplugins.wikidata.magicuser.init(config)
    tiddlywebplugins.jsonp.init(config)

    if 'selector' in config:
        tiddlywebplugins.logout.init(config)

        config['selector'].add('/pages/{template_file:segment}',
                GET=template_route)
        config['selector'].add('/test/{template_file:segment}',
                GET=test_template_route)
        config['selector'].add('/index.html', GET=index)
        config['selector'].add('/verify', POST=verify)
        config['selector'].add('/verify_simple', POST=verify_simple)
        config['selector'].add('/lib/fields.js', GET=get_fields_js)
        config['selector'].add('/env', GET=env)
        config['selector'].add('/register', POST=register)
        config['selector'].add('/_admin/createuser', GET=tier2_user_form, POST=create_tier2_user)
        config['selector'].add('/_admin/updateuser', GET=update_user_form, POST=update_user)
        config['selector'].add('/createuser', POST=create_tier1_user)
        replace_handler(config['selector'], '/', dict(GET=index))
        remove_handler(config['selector'], '/recipes')
        remove_handler(config['selector'], '/recipes/{recipe_name}')
        remove_handler(config['selector'], '/recipes/{recipe_name}/tiddlers')
        remove_handler(config['selector'], '/bags')
        remove_handler(config['selector'], '/bags/{bag_name}')
        remove_handler(config['selector'], '/bags/{bag_name}/tiddlers')
Beispiel #3
0
def init(init_config):
    selector = init_config['selector']
    replace_handler(selector, '/', GET=home_page)
    selector.add('/loadall', GET=load_all)
    store = Store(config['server_store'][0],
                  config['server_store'][1],
                  environ={'tiddlyweb.config': config})
Beispiel #4
0
def init(config):
    merge_config(config, local_config)
    tiddlywebplugins.wikidata.magicuser.init(config)
    tiddlywebplugins.jsonp.init(config)

    if "selector" in config:
        tiddlywebplugins.logout.init(config)

        config["selector"].add("/pages/{template_file:segment}", GET=template_route)
        config["selector"].add("/test/{template_file:segment}", GET=test_template_route)
        config["selector"].add("/index.html", GET=index)
        config["selector"].add("/verify", POST=verify)
        config["selector"].add("/verify_simple", POST=verify_simple)
        config["selector"].add("/lib/fields.js", GET=get_fields_js)
        config["selector"].add("/env", GET=env)
        config["selector"].add("/register", POST=register)
        config["selector"].add("/_admin/createuser", GET=tier2_user_form, POST=create_tier2_user)
        config["selector"].add("/_admin/updateuser", GET=update_user_form, POST=update_user)
        config["selector"].add("/createuser", POST=create_tier1_user)
        replace_handler(config["selector"], "/", dict(GET=index))
        remove_handler(config["selector"], "/recipes")
        remove_handler(config["selector"], "/recipes/{recipe_name}")
        remove_handler(config["selector"], "/recipes/{recipe_name}/tiddlers")
        remove_handler(config["selector"], "/bags")
        remove_handler(config["selector"], "/bags/{bag_name}")
        remove_handler(config["selector"], "/bags/{bag_name}/tiddlers")
Beispiel #5
0
def establish_www(config):
    """
    Set up the routes and WSGI Middleware used by TiddlySpace.
    """
    replace_handler(config['selector'], '/', dict(GET=home))
    config['selector'].add('/_safe', GET=safe_mode, POST=safe_mode)
    add_spaces_routes(config['selector'])
    add_profile_routes(config['selector'])
    config['selector'].add('/users/{username}/identities', GET=get_identities)
    config['selector'].add('/tiddlers[.{format}]', GET=get_space_tiddlers)
    config['selector'].add('/{tiddler_name:segment}', GET=friendly_uri)

    if ControlView not in config['server_request_filters']:
        config['server_request_filters'].insert(
            config['server_request_filters'].index(Negotiate) + 1, ControlView)

    if DropPrivs not in config['server_request_filters']:
        config['server_request_filters'].insert(
            config['server_request_filters'].index(ControlView) + 1, DropPrivs)

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

    if ServerSettings not in config['server_request_filters']:
        config['server_request_filters'].insert(
            config['server_request_filters'].index(ControlView),
            ServerSettings)

    if AllowOrigin not in config['server_response_filters']:
        config['server_response_filters'].insert(
            config['server_response_filters'].index(PrettyHTTPExceptor) + 1,
            AllowOrigin)
Beispiel #6
0
def init(config):
    import tiddlywebwiki
    import tiddlywebplugins.register
    import tiddlywebplugins.wimporter
    import tiddlywebplugins.logout
    import tiddlywebplugins.form

    merge_config(config, hoster_config)

    tiddlywebwiki.init(config)
    tiddlywebplugins.register.init(config)
    tiddlywebplugins.wimporter.init(config)
    tiddlywebplugins.logout.init(config)
    tiddlywebplugins.form.init(config)

    merge_config(config, hoster_config)

    if 'selector' in config:
        remove_handler(config['selector'], '/{recipe_name:segment}')
        replace_handler(config['selector'], '/', dict(GET=front))
        config['selector'].add('/help', GET=help_page)
        config['selector'].add('/login', GET=login)
        config['selector'].add('/uploader', GET=uploader)
        config['selector'].add('/formeditor',
                               GET=get_tiddler_edit,
                               POST=post_tiddler_edit)
        config['selector'].add('/addemail', POST=add_email)
        config['selector'].add('/follow', POST=add_friend)
        config['selector'].add('/members', GET=members_list)
        config['selector'].add('/bagfavor', POST=bag_favor)
        config['selector'].add('/recipefavor', POST=recipe_favor)
        config['selector'].add('/bagpolicy', POST=entity_policy)
        config['selector'].add('/recipepolicy', POST=entity_policy)
        config['selector'].add('/createrecipe',
                               GET=get_createrecipe,
                               POST=post_createrecipe)
        config['selector'].add('/createbag',
                               GET=get_createbag,
                               POST=post_createbag)
        config['selector'].add('/feedbag[.{format}]', GET=public_stuff)
        config['selector'].add('/home', GET=get_home)
        # THE FOLLOWING MUST COME LAST
        config['selector'].add('/{userpage:segment}', GET=user_page)

        new_serializer = [
            'tiddlywebplugins.hoster.serialization', 'text/html; charset=UTF-8'
        ]
        config['serializers']['text/html'] = new_serializer
    else:

        @make_command()
        def upstore(args):
            """Update the store structure."""
            from tiddlywebplugins.hoster.instance import store_structure
            from tiddlywebplugins.instancer import Instance
            from tiddlyweb.config import config
            instance = Instance('.', config)
            instance._init_store(store_structure)
Beispiel #7
0
def init(config):
    """
    Initialize the plugin by establishing the serialization.
    """
    config['extension_types'].update(EXTENSION_TYPES)
    config['serializers'].update(SERIALIZERS)
    if 'selector' in config:
        replace_handler(config['selector'], '/', dict(
            GET=replacement_root_handler))
Beispiel #8
0
def establish_handlers(config):
    selector = config['selector']
    replace_handler(selector, '/', dict(GET=home))
    selector.add('/admin', GET=admin)
    selector.add('/admin/{gym:segment}', GET=gym_editor, POST=gym_edit)
    selector.add('/manager', GET=manager)
    selector.add('/manager/{gym:segment}', GET=manage_gym, POST=manage_edit)
    selector.add('/gyms/{gym:segment}', GET=gym_info)
    selector.add('/gyms/{gym:segment}/routes', GET=gym_routes)
Beispiel #9
0
def init(config):
    import tiddlywebwiki
    import tiddlywebplugins.register
    import tiddlywebplugins.wimporter
    import tiddlywebplugins.logout
    import tiddlywebplugins.form

    tiddlywebwiki.init(config)
    tiddlywebplugins.register.init(config)
    tiddlywebplugins.wimporter.init(config)
    tiddlywebplugins.logout.init(config)
    tiddlywebplugins.form.init(config)

    # XXX this clobbers?
    config["instance_tiddlers"] = instance_tiddlers

    if "selector" in config:
        replace_handler(config["selector"], "/", dict(GET=front))
        config["selector"].add("/help", GET=help_page)
        config["selector"].add("/login", GET=login)
        config["selector"].add("/uploader", GET=uploader)
        config["selector"].add("/formeditor", GET=get_tiddler_edit, POST=post_tiddler_edit)
        config["selector"].add("/addemail", POST=add_email)
        config["selector"].add("/follow", POST=add_friend)
        config["selector"].add("/members", GET=members_list)
        config["selector"].add("/bagfavor", POST=bag_favor)
        config["selector"].add("/recipefavor", POST=recipe_favor)
        config["selector"].add("/bagpolicy", POST=entity_policy)
        config["selector"].add("/recipepolicy", POST=entity_policy)
        config["selector"].add("/createrecipe", GET=get_createrecipe, POST=post_createrecipe)
        config["selector"].add("/createbag", GET=get_createbag, POST=post_createbag)
        config["selector"].add("/feedbag[.{format}]", GET=public_stuff)
        config["selector"].add("/home", GET=get_home)
        # THE FOLLOWING MUST COME LAST
        config["selector"].add("/{userpage:segment}", GET=user_page)

        presenter_index = config["server_response_filters"].index(HTMLPresenter)
        config["server_response_filters"][presenter_index] = PrettyPresenter
        # XXX: disable the specialized extractor for now. The roles it
        # adds are not used (yet).
        # simple_cookie_index = config['extractors'].index('simple_cookie')
        # config['extractors'][simple_cookie_index] = 'tiddlywebplugins.hoster.extractor'

        new_serializer = ["tiddlywebplugins.hoster.serialization", "text/html; charset=UTF-8"]
        config["serializers"]["text/html"] = new_serializer
    else:

        @make_command()
        def upstore(args):
            """Update the store structure."""
            from tiddlywebplugins.hoster.instance import store_structure
            from tiddlywebplugins.instancer import Instance
            from tiddlyweb.config import config

            instance = Instance(".", config)
            instance._init_store(store_structure)
def init(config):
    if 'selector' in config:
        cachedir = os.path.join(config['root_dir'], WIKI_CACHE_DIR)
        try:
            os.mkdir(cachedir)
        except (IOError, OSError), exc:
            logging.warn('unable to create %s: %s', cachedir, exc)
        replace_handler(config['selector'], '/', dict(GET=home))
        HOOKS['tiddler']['put'].append(tiddler_written_handler)
        HOOKS['tiddler']['delete'].append(tiddler_written_handler)
def init(config):
    if 'selector' in config:
        cachedir = os.path.join(config['root_dir'], WIKI_CACHE_DIR)
        try:
            os.mkdir(cachedir)
        except (IOError, OSError), exc:
            logging.warn('unable to create %s: %s', cachedir, exc)
        replace_handler(config['selector'], '/', dict(GET=home))
        HOOKS['tiddler']['put'].append(tiddler_written_handler)
        HOOKS['tiddler']['delete'].append(tiddler_written_handler)
Beispiel #12
0
def init(init_config):
    print 'Life Stream init...'
    selector = init_config['selector']
    replace_handler(selector, '/', GET=home_page)
    selector.add('/loadall', GET=load_all)
    selector.add('/loadtweets', GET=load_tweets)
    selector.add('/loadblogs', GET=load_blogs)
    selector.add('/loadgithub', GET=load_github)
    store = Store(config['server_store'][0], config['server_store'][1], environ={'tiddlyweb.config': config})
    scheduledLoad = ScheduledLoad(store)
    scheduledLoad.load()
Beispiel #13
0
def init(config):
    import tiddlywebwiki
    import tiddlywebplugins.register
    import tiddlywebplugins.wimporter
    import tiddlywebplugins.logout
    import tiddlywebplugins.form
    tiddlywebwiki.init(config)
    tiddlywebplugins.register.init(config)
    tiddlywebplugins.wimporter.init(config)
    tiddlywebplugins.logout.init(config)
    tiddlywebplugins.form.init(config)
    
    # XXX this clobbers?
    config['instance_tiddlers'] = instance_tiddlers

    if 'selector' in config:
        replace_handler(config['selector'], '/', dict(GET=front))
        config['selector'].add('/help', GET=help_page)
        config['selector'].add('/login', GET=login)
        config['selector'].add('/uploader', GET=uploader)
        config['selector'].add('/formeditor', GET=get_tiddler_edit,
                POST=post_tiddler_edit)
        config['selector'].add('/addemail', POST=add_email)
        config['selector'].add('/follow', POST=add_friend)
        config['selector'].add('/members', GET=members_list)
        config['selector'].add('/bagfavor', POST=bag_favor)
        config['selector'].add('/recipefavor', POST=recipe_favor)
        config['selector'].add('/bagpolicy', POST=entity_policy)
        config['selector'].add('/recipepolicy', POST=entity_policy)
        config['selector'].add('/createrecipe', GET=get_createrecipe,
                POST=post_createrecipe)
        config['selector'].add('/createbag', GET=get_createbag,
                POST=post_createbag)
        config['selector'].add('/feedbag[.{format}]', GET=public_stuff)
        config['selector'].add('/home', GET=get_home)
        # THE FOLLOWING MUST COME LAST
        config['selector'].add('/{userpage:segment}', GET=user_page)

        # XXX: disable the specialized extractor for now. The roles it
        # adds are not used (yet).
        #simple_cookie_index = config['extractors'].index('simple_cookie')
        #config['extractors'][simple_cookie_index] = 'tiddlywebplugins.hoster.extractor'

        new_serializer = ['tiddlywebplugins.hoster.serialization', 'text/html; charset=UTF-8']
        config['serializers']['text/html'] = new_serializer
    else:
        @make_command()
        def upstore(args):
            """Update the store structure."""
            from tiddlywebplugins.hoster.instance import store_structure
            from tiddlywebplugins.instancer import Instance
            from tiddlyweb.config import config
            instance = Instance('.', config)
            instance._init_store(store_structure)
Beispiel #14
0
def init(config):
    import tiddlywebwiki
    import tiddlywebplugins.register
    import tiddlywebplugins.wimporter
    import tiddlywebplugins.logout
    import tiddlywebplugins.form

    merge_config(config, hoster_config)

    tiddlywebwiki.init(config)
    tiddlywebplugins.register.init(config)
    tiddlywebplugins.wimporter.init(config)
    tiddlywebplugins.logout.init(config)
    tiddlywebplugins.form.init(config)

    merge_config(config, hoster_config)

    if 'selector' in config:
        remove_handler(config['selector'], '/{recipe_name:segment}')
        replace_handler(config['selector'], '/', dict(GET=front))
        config['selector'].add('/help', GET=help_page)
        config['selector'].add('/login', GET=login)
        config['selector'].add('/uploader', GET=uploader)
        config['selector'].add('/formeditor', GET=get_tiddler_edit,
                POST=post_tiddler_edit)
        config['selector'].add('/addemail', POST=add_email)
        config['selector'].add('/follow', POST=add_friend)
        config['selector'].add('/members', GET=members_list)
        config['selector'].add('/bagfavor', POST=bag_favor)
        config['selector'].add('/recipefavor', POST=recipe_favor)
        config['selector'].add('/bagpolicy', POST=entity_policy)
        config['selector'].add('/recipepolicy', POST=entity_policy)
        config['selector'].add('/createrecipe', GET=get_createrecipe,
                POST=post_createrecipe)
        config['selector'].add('/createbag', GET=get_createbag,
                POST=post_createbag)
        config['selector'].add('/feedbag[.{format}]', GET=public_stuff)
        config['selector'].add('/home', GET=get_home)
        # THE FOLLOWING MUST COME LAST
        config['selector'].add('/{userpage:segment}', GET=user_page)

        new_serializer = ['tiddlywebplugins.hoster.serialization',
                'text/html; charset=UTF-8']
        config['serializers']['text/html'] = new_serializer
    else:
        @make_command()
        def upstore(args):
            """Update the store structure."""
            from tiddlywebplugins.hoster.instance import store_structure
            from tiddlywebplugins.instancer import Instance
            from tiddlyweb.config import config
            instance = Instance('.', config)
            instance._init_store(store_structure)
Beispiel #15
0
def init(config):
    """
    TiddlyWeb plugin initialization
    """
    if "selector" in config: # system plugin
        # inject middleware
        if Slasher not in config["server_request_filters"]: # XXX: unnecessary?
            index = config["server_request_filters"].index(Query) + 1
            config["server_request_filters"].insert(index, Slasher)
        # add/augment URI handlers
        handlers = { "OPTIONS": handshake, "PROPFIND": list_collection }
        for uri in ("/", "/bags", "/recipes", "/bags/.../tiddlers"): # TODO: reuse determine_entries:candidates
            replace_handler(config["selector"], uri, handlers) # XXX: we want to extend, not replace
def init(config):
    """
    TiddlyWeb plugin initialization
    """
    if "selector" in config:  # system plugin
        # inject middleware
        if Slasher not in config[
                "server_request_filters"]:  # XXX: unnecessary?
            index = config["server_request_filters"].index(Query) + 1
            config["server_request_filters"].insert(index, Slasher)
        # add/augment URI handlers
        handlers = {"OPTIONS": handshake, "PROPFIND": list_collection}
        for uri in ("/", "/bags", "/recipes", "/bags/.../tiddlers"
                    ):  # TODO: reuse determine_entries:candidates
            replace_handler(config["selector"], uri,
                            handlers)  # XXX: we want to extend, not replace
Beispiel #17
0
def init(config):
    import tiddlywebwiki
    import tiddlywebplugins.register
    import tiddlywebplugins.wimporter
    tiddlywebwiki.init(config)
    tiddlywebplugins.register.init(config)
    tiddlywebplugins.wimporter.init(config)
    
    # XXX this clobbers?
    config['instance_tiddlers'] = instance_tiddlers

    if config['selector']:
        replace_handler(config['selector'], '/', dict(GET=front))
        config['selector'].add('/help', GET=help_page)
        config['selector'].add('/formeditor', GET=get_profiler, POST=post_profile)
        config['selector'].add('/addemail', POST=add_email)
        config['selector'].add('/follow', POST=add_friend)
        config['selector'].add('/logout', POST=logout)
        config['selector'].add('/members', GET=members_list)
        config['selector'].add('/bagfavor', POST=bag_favor)
        config['selector'].add('/bagpolicy', POST=bag_policy)
        config['selector'].add('/createrecipe', GET=get_createrecipe,
                POST=post_createrecipe)
        config['selector'].add('/createbag', GET=get_createbag,
                POST=post_createbag)
        # THE FOLLOWING MUST COME LAST
        config['selector'].add('/{userpage:segment}', GET=user_page)

        presenter_index = config['server_response_filters'].index(HTMLPresenter)
        config['server_response_filters'][presenter_index] = PrettyPresenter
        # XXX: disable the specialized extractor for now. The roles it
        # adds are not used (yet).
        #simple_cookie_index = config['extractors'].index('simple_cookie')
        #config['extractors'][simple_cookie_index] = 'tiddlywebplugins.hoster.extractor'

        new_serializer = ['tiddlywebplugins.hoster.serialization', 'text/html; charset=UTF-8']
        config['serializers']['text/html'] = new_serializer
        config['serializers']['default'] = new_serializer
    else:
        @make_command()
        def upstore(args):
            """Update the store structure."""
            from tiddlywebplugins.hoster.instance import store_structure
            from tiddlywebplugins.instancer import Instance
            from tiddlyweb.config import config
            instance = Instance('.', config)
            instance._init_store(store_structure)
Beispiel #18
0
def init(config):
    """
    merge custom config with config
    """
    import tiddlywebwiki
    tiddlywebwiki.init(config)
    import tiddlywebplugins.virtualhosting
    # calling init on virtualhosting not required

    merge_config(config, space_config) # XXX: we probably don't wanna do this here

    if 'selector' in config:
        replace_handler(config['selector'], '/', dict(GET=home))
        config['selector'].add('/dashboard[/]', GET=dashboard)
        config['selector'].add('/spaces[/]', POST=post_space_handler)
        config['selector'].add('/users', GET=list_users, POST=post_user)
        config['selector'].add('/users/{usersign}', GET=get_user, PUT=put_user)
Beispiel #19
0
def init_server(config, selector):
    import tiddlywebplugins.static as static
    static.init(config)

    config['server_response_filters'].insert(0, middleware.FriendlyError) # XXX: position arbitrary!?

    selector.status404 = _error_handler('404 Not Found', 'not found')
    selector.status405 = _error_handler('405 Method Not Allowed',
            'method not allowed')

    replace_handler(selector, '/', GET=web.frontpage)
    selector.add('/~', GET=web.dashboard)
    selector.add('/register', POST=web.register_user) # XXX: verb as URI
    selector.add('/wikis', POST=web.create_wiki) # XXX: bad URI?
    selector.add('/pages', POST=web.put_page) # XXX: bad URI?
    selector.add('/editor', GET=web.page_editor) # XXX: bad URI?
    selector.add('/logout', POST=web.logout)
    selector.add('/{wiki_name:segment}', GET=web.wiki_index)
    selector.add('/{wiki_name:segment}/{page_name:segment}', GET=web.wiki_page)
Beispiel #20
0
def establish_web(config):
    atom_init(config)
    extraclude_init(config)
    status_init(config)
    logout_init(config)
    oauth_init(config)

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

    selector = config['selector']
    replace_handler(selector, '/', dict(GET=home))
    selector.add('/auth/{key_name:segment}', DELETE=destroy_key)
    selector.add('/auth', GET=view_auth, POST=make_key)
    selector.add('/dash', GET=dash)
    selector.add('/register', POST=register)
    selector.add('/tanks/{bag_name:segment}[/{tiddler_name:segment}]',
            GET=wiki_page)
    selector.add('/edit', GET=editor, POST=edit)
    selector.add('/forge', POST=forge)
    selector.add('/tags', GET=list_tags)
    selector.add('/comps/{recipe_name:segment}', GET=comp)
Beispiel #21
0
def init(config):
    merge_config(config, bfwconfig)
    try:
        selector = config['selector']
    except KeyError: # twanager mode
        return

    config['server_response_filters'].insert(0, middleware.FriendlyError) # XXX: position arbitrary!?

    selector.status404 = _error_handler('404 Not Found', 'not found')
    selector.status405 = _error_handler('405 Method Not Allowed',
            'method not allowed')

    replace_handler(selector, '/', GET=web.frontpage)
    selector.add('/~', GET=web.user_home)
    selector.add('/register', POST=web.register_user) # XXX: verb as URI
    selector.add('/wikis', POST=web.create_wiki) # XXX: bad URI?
    selector.add('/pages', POST=web.put_page) # XXX: bad URI?
    selector.add('/editor', GET=web.editor) # XXX: bad URI?
    selector.add('/logout', POST=web.logout)
    selector.add('/{wiki_name:segment}', GET=web.wiki_home)
    selector.add('/{wiki_name:segment}/{page_name:segment}', GET=web.wiki_page)
Beispiel #22
0
def establish_web(config):
    atom_init(config)
    cors_init(config)
    extraclude_init(config)
    status_init(config)
    logout_init(config)
    oauth_init(config)
    privateer_init(config)

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

    response_filters = config['server_response_filters']

    if PrettyError not in response_filters:
        response_filters.insert(
                response_filters.index(PermissionsExceptor) + 1,
                PrettyError)

    selector = config['selector']
    selector.status404 = raiser('404', 'path not found')
    selector.status405 = raiser('405', 'method not allow')

    replace_handler(selector, '/', dict(GET=home))
    selector.add('/auth/{key_name:segment}', DELETE=destroy_key)
    selector.add('/auth', GET=view_auth, POST=make_key)
    selector.add('/dash', GET=dash)
    selector.add('/register', POST=register)
    selector.add('/closet/{bag_name:segment}', POST=closet)
    selector.add('/tanks', GET=list_tanks)
    selector.add('/tanks/{bag_name:segment}[/{tiddler_name:segment}]',
            GET=wiki_page)
    selector.add('/edit', GET=editor, POST=edit)
    selector.add('/forge', POST=forge)
    selector.add('/tags', GET=list_tags)
    selector.add('/comps/{recipe_name:segment}', GET=comp)
    selector.add('/policymgr', GET=policymgr)
Beispiel #23
0
def establish_web(config):
    atom_init(config)
    cors_init(config)
    extraclude_init(config)
    status_init(config)
    logout_init(config)
    oauth_init(config)
    privateer_init(config)

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

    response_filters = config['server_response_filters']

    if PrettyError not in response_filters:
        response_filters.insert(
            response_filters.index(PermissionsExceptor) + 1, PrettyError)

    selector = config['selector']
    selector.status404 = raiser('404', 'path not found')
    selector.status405 = raiser('405', 'method not allow')

    replace_handler(selector, '/', dict(GET=home))
    selector.add('/auth/{key_name:segment}', DELETE=destroy_key)
    selector.add('/auth', GET=view_auth, POST=make_key)
    selector.add('/dash', GET=dash)
    selector.add('/register', POST=register)
    selector.add('/closet/{bag_name:segment}', POST=closet)
    selector.add('/tanks', GET=list_tanks)
    selector.add('/tanks/{bag_name:segment}[/{tiddler_name:segment}]',
                 GET=wiki_page)
    selector.add('/edit', GET=editor, POST=edit)
    selector.add('/forge', POST=forge)
    selector.add('/tags', GET=list_tags)
    selector.add('/comps/{recipe_name:segment}', GET=comp)
    selector.add('/policymgr', GET=policymgr)
    file.write(content.encode('UTF-8'))
    file.close()
    logging.debug('attempt to write %s to cache' % name)
    destination_filename = os.path.abspath(link_filename)
    try:
        if os.path.exists(destination_filename):
            os.unlink(destination_filename)
        os.symlink(os.path.abspath(etag_filename), destination_filename)
    except (IOError, OSError), exc:
        logging.warn('unable to link %s <- %s: %s' % (etag_filename, link_filename, exc))



def init(config):
    cachedir = os.path.join(config['root_dir'], WIKI_CACHE_DIR)
    try:
        os.mkdir(cachedir)
    except (IOError, OSError), exc:
        logging.warn('unable to create %s: %s' % (cachedir, exc))
    replace_handler(config['selector'], '/', dict(GET=home))
    TIDDLER_WRITTEN_HANDLERS.append(tiddler_written_handler)


def _header_value(headers, name):
    name = name.lower()
    try:
        found_value = [value for header,value in headers if header.lower() == name][0]
    except IndexError:
        found_value = None
    return found_value
Beispiel #25
0
def init(config):
    """
    Establish required plugins and HTTP routes.
    """
    import tiddlywebwiki
    import tiddlywebplugins.logout
    import tiddlywebplugins.virtualhosting  # calling init not required
    import tiddlywebplugins.magicuser
    import tiddlywebplugins.socialusers
    import tiddlywebplugins.mselect
    import tiddlywebplugins.oom
    import tiddlywebplugins.cookiedomain
    import tiddlywebplugins.tiddlyspace.validator
    import tiddlywebplugins.prettyerror
    import tiddlywebplugins.pathinfohack
    import tiddlywebplugins.hashmaker
    import tiddlywebplugins.form
    import tiddlywebplugins.reflector
    import tiddlywebplugins.privateer
    import tiddlywebplugins.relativetime
    import tiddlywebplugins.jsonp

    # Only load and run dispatcher if we are specifically configured
    # to use it.
    if config.get('use_dispatcher', False):
        import tiddlywebplugins.dispatcher
        import tiddlywebplugins.dispatcher.listener

    @make_command()
    def addmember(args):
        """Add a member to a space: <space name> <user name>"""
        store = get_store(config)
        space_name, username = args
        change_space_member(store, space_name, add=username)
        return True

    @make_command()
    def delmember(args):
        """Delete a member from a space: <space name> <user name>"""
        store = get_store(config)
        space_name, username = args
        change_space_member(store, space_name, remove=username)
        return True

    @make_command()
    def deltiddler(args):
        """Delete a tiddler from a bag: <bag> <title>"""
        from tiddlyweb.model.tiddler import Tiddler
        from tiddlyweb.store import NoTiddlerError
        from tiddlyweb.util import std_error_message
        bag, title = args
        prompt = 'deleting tiddler %s from bag %s - enter "yes" to confirm' % (
            title, bag)
        if raw_input('%s\n' % prompt) == 'yes':
            store = get_store(config)
            tiddler = Tiddler(title, bag)
            try:
                store.delete(tiddler)
            except NoTiddlerError:
                std_error_message('error deleting tiddler %s from bag %s: %s' %
                                  (title, bag, 'no such tiddler'))
            return True
        else:
            std_error_message('aborted')
            return False

    merge_config(config, space_config)

    tiddlywebwiki.init(config)
    tiddlywebplugins.logout.init(config)
    tiddlywebplugins.magicuser.init(config)
    tiddlywebplugins.socialusers.init(config)
    tiddlywebplugins.mselect.init(config)
    tiddlywebplugins.oom.init(config)
    tiddlywebplugins.cookiedomain.init(config)
    tiddlywebplugins.prettyerror.init(config)
    tiddlywebplugins.pathinfohack.init(config)
    tiddlywebplugins.hashmaker.init(config)
    tiddlywebplugins.form.init(config)
    tiddlywebplugins.reflector.init(config)
    tiddlywebplugins.privateer.init(config)
    tiddlywebplugins.jsonp.init(config)

    if config.get('use_dispatcher', False):
        tiddlywebplugins.dispatcher.init(config)
        tiddlywebplugins.dispatcher.listener.init(config)

    # XXX: The following is required to work around issues with twp.instancer.
    # Without this, config settings from tiddlywebwiki take precedence.
    config['serializers']['text/x-tiddlywiki'] = space_config['serializers'][
        'text/x-tiddlywiki']
    # This only fixes 'twanager update', instance creation still does not have
    # the right information, thus requiring a twanager update after instance
    # creation. Presumably the instance script needs to do something similar.
    config['instance_tiddlers'] = get_tiddler_locations(
        store_contents, 'tiddlywebplugins.tiddlyspace')

    # inject lazy serialization information
    config['extension_types'].update({'lwiki': 'text/x-ltiddlywiki'})
    config['serializers'].update({
        'text/x-ltiddlywiki': [
            'tiddlywebplugins.tiddlyspace.betalazyserialization',
            'text/html; charset=UTF-8'
        ]
    })

    if 'selector' in config:  # system plugin
        replace_handler(config['selector'], '/', dict(GET=home))
        config['selector'].add('/_safe', GET=safe_mode, POST=safe_mode)
        add_spaces_routes(config['selector'])
        add_profile_routes(config['selector'])
        config['selector'].add('/{tiddler_name:segment}', GET=friendly_uri)
        config['selector'].add('/users/{username}/identities',
                               GET=get_identities)

        if ControlView not in config['server_request_filters']:
            config['server_request_filters'].insert(
                config['server_request_filters'].index(UserExtract) + 1,
                ControlView)

        if DropPrivs not in config['server_request_filters']:
            config['server_request_filters'].insert(
                config['server_request_filters'].index(ControlView) + 1,
                DropPrivs)

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

        if AllowOrigin not in config['server_response_filters']:
            config['server_response_filters'].insert(
                config['server_response_filters'].index(PrettyHTTPExceptor) +
                1, AllowOrigin)

        new_serializer = [
            'tiddlywebplugins.tiddlyspace.htmlserialization',
            'text/html; charset=UTF-8'
        ]
        config['serializers']['text/html'] = new_serializer
        config['serializers']['default'] = new_serializer
def init(config):
    if __name__ not in config.get('beanstalk.listeners', []):
        # tiddler_change handles both put and deleted tiddlers
        HOOKS['tiddler']['put'].append(_tiddler_change_handler)
        HOOKS['tiddler']['delete'].append(_tiddler_change_handler)

    @make_command()
    def wtags(args):
        """List tags used in index."""
        searcher = get_searcher(config)
        set_tags = set()
        for stored_fields in searcher.documents():
            set_tags.update(stored_fields['tags'].split(','))
        print('tags: %s' % ', '.join(set_tags))

    @make_command()
    def wsearch(args):
        """Search the whoosh index for provided terms."""
        query = ' '.join(args)
        ids = search(config, query)
        for result in ids:
            bag, title = result['id'].split(':', 1)
            print('%s:%s' % (bag, title))

    @make_command()
    def wreindex(args):
        """Rebuild the entire whoosh index."""
        try:
            prefix = args[0]
        except IndexError:
            prefix = None
        store = get_store(config)
        schema = config.get('wsearch.schema',
                SEARCH_DEFAULTS['wsearch.schema'])
        if __name__ in config.get('beanstalk.listeners', []):
            _reindex_async(config)
        else:
            for bag in store.list_bags():
                bag = store.get(bag)
                writer = get_writer(config)
                if writer:
                    try:
                        try:
                            tiddlers = bag.get_tiddlers()
                        except AttributeError:
                            tiddlers = store.list_bag_tiddlers(bag)
                        for tiddler in tiddlers:
                            if prefix and not tiddler.title.startswith(prefix):
                                continue
                            tiddler = store.get(tiddler)
                            index_tiddler(tiddler, schema, writer)
                        writer.commit()
                    except:
                        LOGGER.debug('whoosher: exception while indexing: %s',
                                format_exc())
                        writer.cancel()
                else:
                    LOGGER.debug('whoosher: unable to get writer '
                            '(locked) for %s', bag.name)

    @make_command()
    def woptimize(args):
        """Optimize the index by collapsing files."""
        index = get_index(config)
        index.optimize()

    if 'selector' in config:
        handler = config.get('wsearch.handler')
        if handler:
            config['selector'].add('/%s[.{format}]' % handler,
                    GET=whoosher_search)
        else:
            replace_handler(config['selector'], '/search',
                    dict(GET=whoosher_search))
Beispiel #27
0
def init(config):
    """
    Establish required plugins and HTTP routes.
    """
    import tiddlywebwiki
    import tiddlywebplugins.logout
    import tiddlywebplugins.virtualhosting  # calling init not required
    import tiddlywebplugins.magicuser
    import tiddlywebplugins.socialusers
    import tiddlywebplugins.mselect
    import tiddlywebplugins.oom
    import tiddlywebplugins.cookiedomain
    import tiddlywebplugins.tiddlyspace.validator
    import tiddlywebplugins.prettyerror
    import tiddlywebplugins.pathinfohack
    import tiddlywebplugins.hashmaker
    import tiddlywebplugins.form
    import tiddlywebplugins.reflector
    import tiddlywebplugins.lazy
    import tiddlywebplugins.privateer
    import tiddlywebplugins.relativetime
    import tiddlywebplugins.jsonp

    @make_command()
    def addmember(args):
        """Add a member to a space: <space name> <user name>"""
        store = get_store(config)
        space_name, username = args
        change_space_member(store, space_name, add=username)
        return True

    @make_command()
    def delmember(args):
        """Delete a member from a space: <space name> <user name>"""
        store = get_store(config)
        space_name, username = args
        change_space_member(store, space_name, remove=username)
        return True

    @make_command()
    def deltiddler(args):
        """Delete a tiddler from a bag: <bag> <title>"""
        from tiddlyweb.model.tiddler import Tiddler
        from tiddlyweb.store import NoTiddlerError
        from tiddlyweb.util import std_error_message
        bag, title = args
        prompt = 'deleting tiddler %s from bag %s - enter "yes" to confirm' % (
                title, bag)
        if raw_input('%s\n' % prompt) == 'yes':
            store = get_store(config)
            tiddler = Tiddler(title, bag)
            try:
                store.delete(tiddler)
            except NoTiddlerError:
                std_error_message(
                        'error deleting tiddler %s from bag %s: %s' % (
                            title, bag, 'no such tiddler'))
            return True
        else:
            std_error_message('aborted')
            return False

    merge_config(config, space_config)

    tiddlywebwiki.init(config)
    tiddlywebplugins.logout.init(config)
    tiddlywebplugins.magicuser.init(config)
    tiddlywebplugins.socialusers.init(config)
    tiddlywebplugins.mselect.init(config)
    tiddlywebplugins.oom.init(config)
    tiddlywebplugins.cookiedomain.init(config)
    tiddlywebplugins.prettyerror.init(config)
    tiddlywebplugins.pathinfohack.init(config)
    tiddlywebplugins.hashmaker.init(config)
    tiddlywebplugins.form.init(config)
    tiddlywebplugins.reflector.init(config)
    tiddlywebplugins.lazy.init(config)
    tiddlywebplugins.privateer.init(config)
    tiddlywebplugins.jsonp.init(config)

    # XXX: The following is required to work around issues with twp.instancer.
    # Without this, config settings from tiddlywebwiki take precedence.
    config['serializers']['text/x-tiddlywiki'] = space_config[
            'serializers']['text/x-tiddlywiki']
    # This only fixes 'twanager update', instance creation still does not have
    # the right information, thus requiring a twanager update after instance
    # creation. Presumably the instance script needs to do something similar.
    config['instance_tiddlers'] = get_tiddler_locations(store_contents,
            'tiddlywebplugins.tiddlyspace')

    if 'selector' in config:  # system plugin
        replace_handler(config['selector'], '/', dict(GET=home))
        config['selector'].add('/_safe', GET=safe_mode, POST=safe_mode)
        add_spaces_routes(config['selector'])
        config['selector'].add('/{tiddler_name:segment}', GET=friendly_uri)
        config['selector'].add('/users/{username}/identities',
                GET=get_identities)

        if ControlView not in config['server_request_filters']:
            config['server_request_filters'].insert(
                    config['server_request_filters'].
                    index(UserExtract) + 1, ControlView)

        if DropPrivs not in config['server_request_filters']:
            config['server_request_filters'].insert(
                    config['server_request_filters'].
                    index(ControlView) + 1, DropPrivs)

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

        if AllowOrigin not in config['server_response_filters']:
            config['server_response_filters'].insert(
                    config['server_response_filters'].
                    index(PrettyHTTPExceptor) + 1, AllowOrigin)

        new_serializer = ['tiddlywebplugins.tiddlyspace.htmlserialization',
                'text/html; charset=UTF-8']
        config['serializers']['text/html'] = new_serializer
        config['serializers']['default'] = new_serializer
Beispiel #28
0
    logging.debug('attempt to write %s to cache' % name)
    destination_filename = os.path.abspath(link_filename)
    try:
        if os.path.exists(destination_filename):
            os.unlink(destination_filename)
        os.symlink(os.path.abspath(etag_filename), destination_filename)
    except (IOError, OSError), exc:
        logging.warn('unable to link %s <- %s: %s' %
                     (etag_filename, link_filename, exc))


def init(config):
    cachedir = os.path.join(config['root_dir'], WIKI_CACHE_DIR)
    try:
        os.mkdir(cachedir)
    except (IOError, OSError), exc:
        logging.warn('unable to create %s: %s' % (cachedir, exc))
    replace_handler(config['selector'], '/', dict(GET=home))
    TIDDLER_WRITTEN_HANDLERS.append(tiddler_written_handler)


def _header_value(headers, name):
    name = name.lower()
    try:
        found_value = [
            value for header, value in headers if header.lower() == name
        ][0]
    except IndexError:
        found_value = None
    return found_value
def init(init_config):
    selector = init_config["selector"]
    replace_handler(selector, "/", GET=home_page)
    selector.add("/loadall", GET=load_all)
    store = Store(config["server_store"][0], config["server_store"][1], environ={"tiddlyweb.config": config})