def get(environ, start_response):
    """
    Using query parameters, determine the current tiddler
    and produce an editor for it.
    """
    usersign = environ["tiddlyweb.usersign"]
    try:
        tiddler_name = environ["tiddlyweb.query"].get("tiddler", [""])[0]
        recipe_name = environ["tiddlyweb.query"].get("recipe", [""])[0]
        bag_name = environ["tiddlyweb.query"].get("bag", [""])[0]
    except (KeyError, IndexError):
        raise HTTP400("tiddler, recipe and bag query strings required")

    store = environ["tiddlyweb.store"]

    tiddler = Tiddler(tiddler_name)
    if bag_name:
        tiddler.bag = bag_name
    else:
        recipe = Recipe(recipe_name)
        try:
            recipe = store.get(recipe)
            tiddler.bag = determine_bag_from_recipe(recipe, tiddler).name
            tiddler.recipe = recipe.name
        except NoRecipeError, exc:
            raise HTTP404("unable to edit %s, recipe %s not found: %s" % (tiddler.title, recipe_name, exc))
        except NoBagError, exc:
            raise HTTP404("unable to edit %s: %s" % (tiddler.title, exc))
def get(environ, start_response):
    """
    Using query parameters, determine the current tiddler
    and produce an editor for it.
    """
    usersign = environ['tiddlyweb.usersign']
    try:
        tiddler_name = environ['tiddlyweb.query'].get('tiddler', [''])[0]
        recipe_name = environ['tiddlyweb.query'].get('recipe', [''])[0]
        bag_name = environ['tiddlyweb.query'].get('bag', [''])[0]
        #tiddler_name = unicode(urllib.unquote(tiddler_name), 'utf-8')
        #bag_name = unicode(urllib.unquote(bag_name), 'utf-8')
        #recipe_name = unicode(urllib.unquote(recipe_name), 'utf-8')
    except (KeyError, IndexError):
        raise HTTP400('tiddler, recipe and bag query strings required')

    store = environ['tiddlyweb.store']

    tiddler = Tiddler(tiddler_name)
    if bag_name:
        tiddler.bag = bag_name
    else:
        recipe = Recipe(recipe_name)
        try:
            recipe = store.get(recipe)
            tiddler.bag = control.determine_tiddler_bag_from_recipe(recipe, tiddler).name
            tiddler.recipe = recipe.name
        except NoRecipeError, exc:
            raise HTTP404('unable to edit %s, recipe %s not found: %s' % (tiddler.title, recipe_name, exc))
        except NoBagError, exc:
            raise HTTP404('unable to edit %s: %s' % (tiddler.title, exc))
def get(environ, start_response):
    """
    Using query parameters, determine the current tiddler
    and produce an editor for it.
    """
    usersign = environ['tiddlyweb.usersign']
    try:
        tiddler_name = environ['tiddlyweb.query'].get('tiddler', [''])[0]
        recipe_name = environ['tiddlyweb.query'].get('recipe', [''])[0]
        bag_name = environ['tiddlyweb.query'].get('bag', [''])[0]
    except (KeyError, IndexError):
        raise HTTP400('tiddler, recipe and bag query strings required')

    store = environ['tiddlyweb.store']

    tiddler = Tiddler(tiddler_name)
    if bag_name:
        tiddler.bag = bag_name
    else:
        recipe = Recipe(recipe_name)
        try:
            recipe = store.get(recipe)
            tiddler.bag = control.determine_tiddler_bag_from_recipe(
                recipe, tiddler).name
            tiddler.recipe = recipe.name
        except NoRecipeError, exc:
            raise HTTP404('unable to edit %s, recipe %s not found: %s' %
                          (tiddler.title, recipe_name, exc))
        except NoBagError, exc:
            raise HTTP404('unable to edit %s: %s' % (tiddler.title, exc))
Beispiel #4
0
def _manage_update_routes(environ, gym):
    """
    Update routes with new information.
    """
    store = environ['tiddlyweb.store']
    query = environ['tiddlyweb.query']
    existing_titles = query.get('title', [])
    count = len(existing_titles)
    index = 0
    delete = query.get('delete', [])
    lead_route = query.get(LEAD_FIELD, [])
    while index < count:
        title = existing_titles[index]
        tiddler = Tiddler(title, '%s_climbs' % gym)
        try:
            tiddler = store.get(tiddler)
            if title in delete:
                original_bag = tiddler.bag
                tiddler.bag = '%s_archive' % gym
                store.put(tiddler)
                tiddler.bag = original_bag
                store.delete(tiddler)
                index += 1
                continue
        except StoreError:
            pass
        changed = False
        for key in ROUTE_FIELDS:
            value = query.get(key, [''])[index]
            if tiddler.fields[key] != value:
                tiddler.fields[key] = value
                changed = True
        if LEAD_FIELD in tiddler.fields and title not in lead_route:
            del tiddler.fields[LEAD_FIELD]
            changed = True
        elif title in lead_route and LEAD_FIELD not in tiddler.fields:
            tiddler.fields[LEAD_FIELD] = '1'
            changed = True
        if changed:
            store.put(tiddler)
        index += 1
    
    try:
        title = query.get('title', [])[index]
    except IndexError:
        title = str(uuid4())
    tiddler = Tiddler(title, '%s_climbs' % gym)
    new_route = False
    if 'new_one' in lead_route:
        tiddler.fields[LEAD_FIELD] = '1'
    for key in ROUTE_FIELDS:
        value = query.get(key, [''])[index]
        if value == '':
            continue
        new_route = True
        tiddler.fields[key] = value
    if new_route:
        store.put(tiddler)
    raise HTTP303(server_base_url(environ) + '/manager/%s' % gym)
Beispiel #5
0
def test_put_and_get_tiddler():
    tiddler = Tiddler('testbag')
    tiddler.text = 'bag1 here'
    bag = Bag('bag1')
    tiddler.bag = u'bag1'

    store.put(bag)
    store.put(tiddler)

    new_tiddler = Tiddler('testbag')
    new_tiddler.bag = u'bag1'
    new_tiddler = store.get(new_tiddler)

    assert new_tiddler.text == 'bag1 here'
Beispiel #6
0
def test_tiddler_unique_by_bags():
    tiddler_one = Tiddler('testbag')
    tiddler_one.bag = 'bag1'
    tiddler_two = Tiddler('testbag')
    tiddler_two.bag = 'bag2'

    assert tiddler_one.text == tiddler_two.text == '', \
            'empty tiddlers have equally empty content'

    tiddler_one = store.get(tiddler_one)
    tiddler_two = store.get(tiddler_two)

    assert tiddler_one.text != tiddler_two.text, \
            'empty tiddlers have different content'
Beispiel #7
0
def test_put_and_get_tiddler():
    tiddler = Tiddler(title='testbag')
    tiddler.text = 'bag1 here'
    bag = Bag(name = 'bag1')
    tiddler.bag = 'bag1'

    store.put(bag)
    store.put(tiddler)

    new_tiddler = Tiddler(title='testbag')
    new_tiddler.bag = 'bag1'
    new_tiddler = store.get(new_tiddler)

    assert new_tiddler.text == 'bag1 here'
Beispiel #8
0
def test_tiddler_unique_by_bags():
    tiddler_one = Tiddler('testbag')
    tiddler_one.bag = 'bag1'
    tiddler_two = Tiddler('testbag')
    tiddler_two.bag = 'bag2'

    assert tiddler_one.text == tiddler_two.text == None, \
            'empty tiddlers have equally empty content'

    tiddler_one = store.get(tiddler_one)
    tiddler_two = store.get(tiddler_two)

    assert tiddler_one.text != tiddler_two.text, \
            'empty tiddlers have different content'
def url(args):
    """Add a URL via tiddlywebplugins.URLs. Redirect is optional. [--redirect] <selector_path> <destination_url>"""
    if 2 != len(args) != 3:
        print >> sys.stderr, ('you must include both the path you want to use (selector path) and the destination url')
        
    store = get_store(config)
    
    if args[0] == '--redirect':
        redirect = args.pop(0).lstrip('-')
    else:
        redirect = None
    
    selector_path = args[0]
    destination_url = args[1]
    
    tiddler = Tiddler(selector_path)
    tiddler.bag = config['url_bag']
    
    tiddler.text = destination_url
    if redirect:
        tiddler.tags = [redirect]
    
    if validate_url(tiddler):
        store.put(tiddler)
    
    return True
def test_tiddler_title_with_slash():
    tiddler = Tiddler('hello/monkey')
    tiddler.bag = u'bag/puss'
    tiddler.text = 'artifice'

    assert tiddler.title == 'hello/monkey'

    store.put(tiddler)

    tiddler2 = Tiddler('hello/monkey')
    tiddler2.bag = u'bag/puss'

    tiddler2 = store.get(tiddler2)

    assert tiddler2.title == 'hello/monkey'
    assert tiddler2.text == 'artifice'
def _process_choices(environ, start_response, form):
    store = environ['tiddlyweb.store']
    user = environ['tiddlyweb.usersign']

    tmp_bag = form['tmp_bag'][0]
    bag = form['target_bag'][0]
    if bag:
        bag = Bag(bag)
        try:
            bag.skinny = True
            bag = store.get(bag)
        except NoBagError:
            return _send_wimport(environ, start_response,
                    'chosen bag does not exist')
    else:
        bag = form['new_bag'][0]
        bag = _make_bag(environ, bag)

    try:
        bag.policy.allows(user, 'write')
    except (ForbiddenError, UserRequiredError):
        return _send_wimport(environ, start_response,
                'you may not write to that bag')

    tiddler_titles = form['tiddler']
    for title in tiddler_titles:
        tiddler = Tiddler(title.decode('utf-8', 'ignore'), tmp_bag)
        tiddler = store.get(tiddler)
        tiddler.bag = bag.name
        store.put(tiddler)
    tmp_bag = Bag(tmp_bag)
    store.delete(tmp_bag)
    bagurl = bag_url(environ, bag) + '/tiddlers'
    raise HTTP302(bagurl)
def retrieve_from_store(email):
    """
    get the tiddler requested by the email from the store 
    and return it as an email
    """
    store = get_store(config)
    tiddler_title = clean_subject(email["subject"])
    tiddler = Tiddler(tiddler_title)
    bag = determine_bag(email["to"])
    tiddler.bag = bag

    try:
        tiddler = store.get(tiddler)
        response_text = tiddler.text
    except NoTiddlerError:
        # Tiddler not found. Return a list of all tiddlers
        bag = Bag(bag)
        bag = store.get(bag)
        response_text = "The following tiddlers are in %s:\n" % email["to"].split("@")[1]
        tiddlers = bag.gen_tiddlers()
        tiddlers = [tiddler for tiddler in tiddlers]
        response_text += "\n".join([tiddler.title for tiddler in tiddlers])

    response_email = {"from": email["to"], "to": email["from"], "subject": tiddler.title, "body": response_text}

    return response_email
Beispiel #13
0
def test_no_bag_for_tiddler():
    tiddler = Tiddler('testnobag')
    tiddler.text = 'no bag here'
    tiddler.bag = u'no bag of this name'

    with py.test.raises(NoBagError):
        store.put(tiddler)
Beispiel #14
0
def test_get_revision():
    """
    Test we are able to retrieve a particular revision.
    """
    bagone = Bag('bagone')

    store.put(bagone)
    tiddler = Tiddler('RevisionTiddler')
    tiddler.text = 'how now 1'
    tiddler.bag = u'bagone'
    store.put(tiddler)
    tiddler.text = 'how now 2'
    store.put(tiddler)
    tiddler.text = 'how now 3'
    store.put(tiddler)

    tiddler = Tiddler('RevisionTiddler', 'bagone')
    tiddler = store.get(tiddler)

    assert tiddler.text == 'how now 3'
    assert tiddler.revision == 3

    tiddler = Tiddler('RevisionTiddler', 'bagone')
    tiddler.revision = 2
    tiddler = store.get(tiddler)

    assert tiddler.text == 'how now 2'
    assert tiddler.revision == 2

    revisions = store.list_tiddler_revisions(tiddler)
    assert len(revisions) == 3
    assert revisions[0] == 3
Beispiel #15
0
def test_determine_tiddler_from_recipe():
    """
    Work out what bag a provided tiddler is in, when we have no knowledge of the bag,
    but we do have a recipe.
    """
    short_recipe = Recipe(name='foobar')
    short_recipe.set_recipe([
        [bagone, ''],
        [bagfour, 'select=tag:tagone']
        ])
    bag = control.determine_tiddler_bag_from_recipe(short_recipe, tiddlers[0])
    assert bag.name == bagfour.name, 'bag name should be bagfour, is %s' % bag.name

    short_recipe.set_recipe([
        [bagone, ''],
        [bagfour, 'select=tag:tagthree']
        ])
    bag = control.determine_tiddler_bag_from_recipe(short_recipe, tiddlers[0])
    assert bag.name == bagone.name, 'bag name should be bagone, is %s' % bag.name

    lonely_tiddler = Tiddler('lonely')
    lonely_tiddler.bag = 'lonelybag'

    py.test.raises(NoBagError,
            'bag = control.determine_tiddler_bag_from_recipe(short_recipe, lonely_tiddler)')
def test_html_attribute_escape_with_bag():
    tiddler = Tiddler('escape "double" quotes in tiddler field values')
    tiddler.bag = 'foo "bar" baz'
    tiddler.modifier = 'Chris "sensei" Dent'
    tiddler.tags = ["foo", 'xxx "yyy" zzz']
    tiddler.fields["custom"] = u"""lorem 'ipsum' dolor "sit" amet"""
    tiddler.text = ''
    serializer = Serializer('tiddlywebwiki.serialization', environ)
    serializer.object = tiddler
    string = serializer.to_string()

    assert ('title="escape &quot;double&quot; quotes in tiddler field values"'
        in string)
    assert ('server.title="escape &quot;double&quot; quotes in tiddler '
        'field values"' in string)
    assert 'bag="foo &quot;bar&quot; baz"' in string
    assert 'server.workspace="bags/foo &quot;bar&quot; baz"' in string
    assert 'modifier="Chris &quot;sensei&quot; Dent"' in string
    assert 'creator="Chris &quot;sensei&quot; Dent"' in string
    assert 'tags="foo [[xxx &quot;yyy&quot; zzz]]"' in string
    assert '''custom="lorem 'ipsum' dolor &quot;sit&quot; amet"''' in string
    # single tiddler's browse link is that tiddler in its bag
    assert ('you may still <a href="/bags/foo%20%22bar%22%20baz/tiddlers/'
            'escape%20%22double%22%20quotes%20in%20tiddler%20field%20'
            'values">browse' in string)
Beispiel #17
0
def test_no_bag_for_tiddler():
    tiddler = Tiddler('testnobag')
    tiddler.text = 'no bag here'
    tiddler.bag = u'no bag of this name'

    with py.test.raises(NoBagError):
        store.put(tiddler)
def test_tiddler_title_with_slash():
    tiddler = Tiddler('hello/monkey')
    tiddler.bag = u'bag/puss'
    tiddler.text = 'artifice'

    assert tiddler.title == 'hello/monkey'

    store.put(tiddler)

    tiddler2 = Tiddler('hello/monkey')
    tiddler2.bag = u'bag/puss'

    tiddler2 = store.get(tiddler2)

    assert tiddler2.title == 'hello/monkey'
    assert tiddler2.text == 'artifice'
Beispiel #19
0
def test_tiddler_url():
    tiddler = Tiddler('foobar')
    tiddler.bag = 'zoom'

    url = tiddler_url(environ, tiddler)

    assert url == 'http://our_test_domain:8001/bags/zoom/tiddlers/foobar'

    tiddler.recipe = 'car'

    url = tiddler_url(environ, tiddler, container='recipes')

    assert url == 'http://our_test_domain:8001/recipes/car/tiddlers/foobar'

    url = tiddler_url(environ, tiddler, container='recipes', full=False)

    assert url == '/recipes/car/tiddlers/foobar'

    config['server_prefix'] = '/sleep'

    url = tiddler_url(environ, tiddler, container='recipes', full=False)

    assert url == '/sleep/recipes/car/tiddlers/foobar'

    url = tiddler_url(environ, tiddler)

    assert url == 'http://our_test_domain:8001/sleep/bags/zoom/tiddlers/foobar'

    tiddler.fields['_canonical_uri'] = 'http://example.com'
    url = tiddler_url(environ, tiddler)

    # we decided url is always local
    #assert url == 'http://example.com'
    assert url == 'http://our_test_domain:8001/sleep/bags/zoom/tiddlers/foobar'
Beispiel #20
0
def test_tiddler_full_create():
    """
    Confirm we can populate a tiddler at create time.
    """

    tiddler = Tiddler('test tiddler')
    tiddler.modifier = '*****@*****.**'
    tiddler.text = test_tiddler_text
    tiddler.tags = ['foo', 'bar']
    tiddler.bag = u'bagone'

    assert type(tiddler) == Tiddler, \
            'Tiddler returns a Tiddler'
    assert tiddler.title == 'test tiddler', \
            'tiddler title should be test tiddler, got %s' \
            % tiddler.title
    assert tiddler.modifier == '*****@*****.**', \
            'tiddler modifier should [email protected], got %s' \
            % tiddler.modifier
    assert tiddler.text == test_tiddler_text, \
            'tiddler content is correct'
    assert tiddler.tags == ['foo', 'bar'], \
            'tiddler tags are correct'
    assert tiddler.bag == 'bagone', \
            'tiddler has a bag of bagone'
    assert tiddler.revision is None, \
            'tiddler revision is None'
    assert tiddler.creator == '*****@*****.**'
def test_tiddler_title_with_slash():
    tiddler = Tiddler("hello/monkey")
    tiddler.bag = "bag/puss"
    tiddler.text = "artifice"

    assert tiddler.title == "hello/monkey"

    store.put(tiddler)

    tiddler2 = Tiddler("hello/monkey")
    tiddler2.bag = "bag/puss"

    tiddler2 = store.get(tiddler2)

    assert tiddler2.title == "hello/monkey"
    assert tiddler2.text == "artifice"
Beispiel #22
0
def test_tiddler_url():
    tiddler = Tiddler('foobar')
    tiddler.bag = 'zoom'

    url = tiddler_url(environ, tiddler)

    assert url == 'http://our_test_domain:8001/bags/zoom/tiddlers/foobar'

    tiddler.recipe = 'car'

    url = tiddler_url(environ, tiddler, container='recipes')

    assert url == 'http://our_test_domain:8001/recipes/car/tiddlers/foobar'

    url = tiddler_url(environ, tiddler, container='recipes', full=False)

    assert url == '/recipes/car/tiddlers/foobar'

    config['server_prefix'] = '/sleep'

    url = tiddler_url(environ, tiddler, container='recipes', full=False)

    assert url == '/sleep/recipes/car/tiddlers/foobar'

    url = tiddler_url(environ, tiddler)

    assert url == 'http://our_test_domain:8001/sleep/bags/zoom/tiddlers/foobar'

    tiddler.fields['_canonical_uri'] = 'http://example.com'
    url = tiddler_url(environ, tiddler)

    assert url == 'http://our_test_domain:8001/sleep/bags/zoom/tiddlers/foobar'
def _process_choices(environ, start_response, form):
    store = environ['tiddlyweb.store']
    user = environ['tiddlyweb.usersign']

    tmp_bag = form['tmp_bag'][0]
    bag = form['target_bag'][0]
    if bag:
        bag = Bag(bag)
        try:
            bag.skinny = True
            bag = store.get(bag)
        except NoBagError:
            return _send_wimport(environ, start_response,
                                 'chosen bag does not exist')
    else:
        bag = form['new_bag'][0]
        bag = _make_bag(environ, bag)

    try:
        bag.policy.allows(user, 'write')
    except (ForbiddenError, UserRequiredError):
        return _send_wimport(environ, start_response,
                             'you may not write to that bag')

    tiddler_titles = form['tiddler']
    for title in tiddler_titles:
        tiddler = Tiddler(title.decode('utf-8', 'ignore'), tmp_bag)
        tiddler = store.get(tiddler)
        tiddler.bag = bag.name
        store.put(tiddler)
    tmp_bag = Bag(tmp_bag)
    store.delete(tmp_bag)
    bagurl = bag_url(environ, bag) + '/tiddlers'
    raise HTTP302(bagurl)
Beispiel #24
0
def test_call_jsonp():
    """
    test that we can get some stuff as JSONP
    """
    tiddler = Tiddler('public')
    tiddler.bag = 'foo_public'
    tiddler.text = 'some text'
    store.put(tiddler)

    user_cookie = get_auth('foo', 'foobar')
    callback = 'callback'
    response, content = http.request('http://foo.0.0.0.0:8080/bags/'
        'foo_public/tiddlers/public?callback=%s' % callback,
        method='GET',
        headers={
            'Cookie': 'tiddlyweb_user="******"' % user_cookie,
            'Accept': 'application/json'
        })
    assert response['status'] == '200'
    assert content.startswith('%s(' % callback)
    assert content[-1:] == ')'

    response, content = http.request('http://0.0.0.0:8080/bags/'
        'foo_public/tiddlers/public?callback=%s' % callback,
        method='GET',
        headers={
            'Cookie': 'tiddlyweb_user="******"' % user_cookie,
            'Accept': 'application/json'
        })
    assert response['status'] == '200'
    assert content.startswith('%s(' % callback)
    assert content[-1:] == ')'
Beispiel #25
0
def _determine_tiddler(environ):
    """
    Inspect the environment to determine which tiddler from which
    bag will provide content for the page named in the URL. If
    the page exists, and we have permission to read the bag in 
    which it is stored, the return the tiddler.

    If we do not have permission, a login interface will be shown.

    If the tiddler does not exist, an empty tiddler with stub
    text will be returned.
    """
    user = environ['tiddlyweb.usersign']
    config = environ['tiddlyweb.config']
    store = environ['tiddlyweb.store']
    recipe = Recipe(_get_recipe(config))
    recipe = store.get(recipe)
    recipe.policy.allows(user, 'read')

    tiddler_name = environ['wsgiorg.routing_args'][1]['tiddler_name']
    tiddler_name = urllib.unquote(tiddler_name)
    tiddler_name = unicode(tiddler_name, 'utf-8')
    tiddler = Tiddler(tiddler_name)

    try:
        bag = control.determine_bag_from_recipe(recipe, tiddler, environ)
        bag.policy.allows(user, 'read')
        tiddler.bag = bag.name
        tiddler = store.get(tiddler)
    except NoBagError, exc:
        # Apparently the tiddler doesn't exist, let's fill in an empty one
        # then.
        tiddler.text = 'That Page does not yet exist.'
        tiddler.type = 'text/x-markdown'
Beispiel #26
0
def test_tiddler_full_create():
    """
    Confirm we can populate a tiddler at create time.
    """

    tiddler = Tiddler('test tiddler')
    tiddler.modifier = '*****@*****.**'
    tiddler.text = test_tiddler_text
    tiddler.tags = ['foo', 'bar']
    tiddler.bag = u'bagone'

    assert type(tiddler) == Tiddler, \
            'Tiddler returns a Tiddler'
    assert tiddler.title == 'test tiddler', \
            'tiddler title should be test tiddler, got %s' \
            % tiddler.title
    assert tiddler.modifier == '*****@*****.**', \
            'tiddler modifier should [email protected], got %s' \
            % tiddler.modifier
    assert tiddler.text == test_tiddler_text, \
            'tiddler content is correct'
    assert tiddler.tags == ['foo', 'bar'], \
            'tiddler tags are correct'
    assert tiddler.bag == 'bagone', \
            'tiddler has a bag of bagone'
    assert tiddler.revision is None, \
            'tiddler revision is None'
    assert tiddler.creator == '*****@*****.**'
    def _get_status_tiddler(self, environ, status):
        """
        Load up the tiddler associated with the current status.
        If the tiddler is not present in the recipe, load up
        the tiddler with title 'default'. If that tiddler is
        not present, use DEFAULT_TEXT.
        """
        try:
            tiddler = Tiddler(status)
            store = environ['tiddlyweb.store']
            recipe_name = environ['tiddlyweb.config'].get('prettyerror.recipe',
                    '_errors')
            recipe = Recipe(recipe_name)
            recipe = store.get(recipe)
            bag = determine_bag_from_recipe(recipe, tiddler, environ)
            tiddler.bag = bag.name
            tiddler = store.get(tiddler)
        except (NoRecipeError, NoBagError):
            if status == 'default':
                tiddler.text = DEFAULT_TEXT
            else:
                tiddler = self._get_status_tiddler(environ, 'default')
        except (NoTiddlerError):
            # If there is no default tiddler we get recursion error.
            tiddler = self._get_status_tiddler(environ, 'default')
        except:  # Deal with failures early in the stack
            tiddler.text = DEFAULT_TEXT

        return tiddler
def test_get_tiddler_revision():
	_cleanup()

	config = { "server_store": ["tiddlywebplugins.devstore", { "store_root": STORE_DIR }],
		"instance_tiddlers": {
			"myBag": ["%s/alpha/index.recipe" % REPO_DIR]
		},
		"root_dir": ""
	}
	env = { "tiddlyweb.config": config }
	store = Store(config["server_store"][0], config["server_store"][1], env)

	tiddler = Tiddler("lorem")
	tiddler.bag = "myBag"
	t = store.get(tiddler)

	assert t.title == "lorem"
	assert t.bag == "myBag"
	assert t.revision == 1
	assert t.tags == []
	assert t.creator == "FND"
	assert t.modifier == "FND"
	assert len(t.created) == 14
	assert len(t.modified) == 14
	assert t.created == t.modified
	assert t.text == "lorem ipsum"

	tiddler = Tiddler("hello world")
	tiddler.bag = "myBag"
	tiddler.tags = ["foo", "bar"]
	tiddler.modifier = "FND"
	tiddler.text = "lorem ipsum"
	store.put(tiddler)
	tiddler = Tiddler("hello world")
	tiddler.bag = "myBag"
	t = store.get(tiddler)

	assert t.title == "hello world"
	assert t.bag == "myBag"
	assert t.revision == 1
	assert t.tags == ["foo", "bar"]
	assert t.creator == "FND"
	assert t.modifier == "FND"
	assert len(t.created) == 14
	assert len(t.modified) == 14
	assert t.created == t.modified
	assert t.text == "lorem ipsum"
Beispiel #29
0
def test_get_diddle_put_tiddler():
    new_tiddler = Tiddler(title='testbag')
    new_tiddler.bag = u'bag1'
    new_tiddler = store.get(new_tiddler)

    new_tiddler.bag = u'bag2'
    new_tiddler.text = 'bag2 here'

    py.test.raises(NoBagError, "store.put(new_tiddler)")

    bag = Bag('bag2')
    store.put(bag)

    store.put(new_tiddler)

    assert os.path.exists('store/bags/bag2/tiddlers/testbag')
    assert os.path.exists('store/bags/bag1/tiddlers/testbag')
Beispiel #30
0
	def bag_get(self, bag):
		tiddlers = []
		tiddler_count = int(bag.name)
		for i in xrange(tiddler_count):
			tiddler = Tiddler(_generate_title())
			tiddler.bag = bag.name
			bag.add_tiddler(tiddler)
		return bag
 def resolve_tiddler(self, target, title):
     interior_tiddler = Tiddler(title)
     if target:
         tiddlywebconfig = self.environ['tiddlyweb.config']
         target_resolver = tiddlywebconfig.get('markdown.target_resolver')
         if not target_resolver:
             interior_tiddler.bag = 'NoSuchBag'
         else:
             target_resolver(self.environ, target, interior_tiddler)
     else:
         if self.tiddler.recipe:
             interior_bag = get_bag_from_recipe(self.environ,
                     self.tiddler.recipe, interior_tiddler)
             interior_tiddler.bag = interior_bag.name
         else:
             interior_tiddler.bag = self.tiddler.bag
     return interior_tiddler
Beispiel #32
0
def test_get_diddle_put_tiddler():
    new_tiddler = Tiddler(title='testbag')
    new_tiddler.bag = 'bag1'
    new_tiddler = store.get(new_tiddler)

    new_tiddler.bag = 'bag2'
    new_tiddler.text = 'bag2 here'

    py.test.raises(NoBagError, "store.put(new_tiddler)")

    bag = Bag('bag2')
    store.put(bag)

    store.put(new_tiddler)

    assert os.path.exists('store/bags/bag2/tiddlers/testbag')
    assert os.path.exists('store/bags/bag1/tiddlers/testbag')
Beispiel #33
0
def test_tiddler_html_encode():
    serializer = Serializer('html')
    tiddler = Tiddler('jeremy found a bug')
    tiddler.bag = u'foo'
    tiddler.text = u'"Hello." I\'m > than 5 & < you.'
    serializer.object = tiddler
    string = serializer.to_string()

    assert '"Hello." I\'m &gt; than 5 &amp; &lt; you.' in string
def test_tiddler_html_encode():
    serializer = Serializer('html')
    tiddler = Tiddler('jeremy found a bug')
    tiddler.bag = u'foo'
    tiddler.text = u'"Hello." I\'m > than 5 & < you.'
    serializer.object = tiddler
    string = serializer.to_string()

    assert '"Hello." I\'m &gt; than 5 &amp; &lt; you.' in string
def save_tiddler(store, tiddler):
    title = tiddler['title']
    bag = tiddler['bag']
    tiddler_json = simplejson.dumps(tiddler)
    tid = Tiddler(title)
    s = Serializer('json')
    s.object = tid
    s.from_string(tiddler_json)
    tid.bag = bag
    store.put(tid)
Beispiel #36
0
def test_simple_render():
    tiddler = Tiddler('bar')
    tiddler.text = """
|hello|goodbye|h
|foo|bar|
"""
    tiddler.bag = 'zoo'

    html = render(tiddler, {})
    assert 'WikError' in html
Beispiel #37
0
 def bag_get(self, bag):
     bag.desc = 'Available users'
     bag.policy = self._policy()
     store = self.main_store
     users = store.list_users()
     for user in users:
         tiddler = Tiddler(user.usersign)
         tiddler.bag = bag.name
         bag.add_tiddler(tiddler)
     return bag
def save_tiddler(store, tiddler):
    title = tiddler['title']
    bag = tiddler['bag']
    tiddler_json = simplejson.dumps(tiddler)
    tid = Tiddler(title)
    s = Serializer('json')
    s.object = tid
    s.from_string(tiddler_json)
    tid.bag = bag
    store.put(tid)
Beispiel #39
0
 def bag_get(self, bag):
     bag.desc = 'Available users'
     bag.policy = self._policy()
     store = self.main_store
     users = store.list_users()
     for user in users:
         tiddler = Tiddler(user.usersign)
         tiddler.bag = bag.name
         bag.add_tiddler(tiddler)
     return bag
Beispiel #40
0
def get_app(environ, client_id):
    """
    Get the app out of the store.
    """
    store = environ['tiddlyweb.store']
    config = environ['tiddlyweb.config']
    bag = config.get('oauth.app_bag', 'oauth_apps')
    app = Tiddler(client_id)
    app.bag = bag
    return store.get(app)
def test_tiddler_get():
	_cleanup()

	config = {
		"server_store": ["tiddlywebplugins.devstore", { "store_root": STORE_DIR }],
		"instance_tiddlers": {
			"myBag": ["%s/alpha/index.recipe" % REPO_DIR]
		},
		"root_dir": ""
	}
	env = { "tiddlyweb.config": config }
	store = Storage(config["server_store"][1], env)

	tiddler = Tiddler("lorem")
	tiddler.bag = "myBag"
	t = store.tiddler_get(tiddler)

	assert t.title == "lorem"
	assert t.bag == "myBag"
	assert t.tags == []
	assert t.creator == "FND"
	assert t.modifier == "FND"
	assert len(t.created) == 14
	assert len(t.modified) == 14
	assert t.created == t.modified
	assert t.text == "lorem ipsum"

	tiddler = Tiddler("foo")
	tiddler.bag = "myBag"
	t = store.tiddler_get(tiddler)

	assert t.title == "foo"
	assert t.bag == "myBag"
	assert t.type == "text/javascript"
	assert t.revision == 1
	assert t.tags == ["systemConfig"]
	assert t.creator == None
	assert t.modifier == None
	assert len(t.created) == 14
	assert len(t.modified) == 14
	assert t.created == t.modified
	assert t.text == 'console.log("foo");'
def test_put_tiddler_to_store():
	_cleanup()

	config = {
		"server_store": ["tiddlywebplugins.devstore", { "store_root": STORE_DIR }],
		"instance_tiddlers": {
			"myBag": ["%s/alpha/index.recipe" % REPO_DIR]
		},
		"root_dir": ""
	}
	env = { "tiddlyweb.config": config }
	store = Store(config["server_store"][0], config["server_store"][1], env)

	tiddler = Tiddler("lorem")
	tiddler.bag = "myBag"
	store.put(tiddler)

	tiddler_path = os.path.join(STORE_DIR, tiddler.bag, "%s.tid" % tiddler.title)
	assert os.path.exists(tiddler_path)

	tiddler = Tiddler("foo bar")
	tiddler.bag = "myBag"
	store.put(tiddler)

	tiddler_path = os.path.join(STORE_DIR, "myBag", "foo%20bar.tid")
	assert os.path.exists(tiddler_path)
	assert store.get(tiddler).title == "foo bar"

	# XXX: testing get operation here for convenience
	bag = Bag("myBag")
	try:
		assert "foo bar" in [t.title for t in store.list_bag_tiddlers(bag)]
	except AttributeError: # TiddlyWeb 1.0 has no list_bag_tiddlers method
		pass

	tiddler = Tiddler("foo/bar")
	tiddler.bag = "myBag"
	store.put(tiddler)

	tiddler_path = os.path.join(STORE_DIR, "myBag", "foo%2Fbar.tid")
	assert os.path.exists(tiddler_path)
	assert store.get(tiddler).title == "foo/bar"
Beispiel #43
0
def create_test_data():
    testbag = Bag(name='testbag')

    WikiTextTiddler = Tiddler('WikiTextTiddler')
    WikiTextTiddler.modifier = 'WikiAuthor'
    WikiTextTiddler.text = u"A ''tiddler'' //with// {{{wikitext}}}"
    WikiTextTiddler.bag = testbag.name

    store = _get_store()
    store.put(testbag)
    store.put(WikiTextTiddler)
Beispiel #44
0
def test_store_tiddler():
    tiddler = Tiddler('tiddler1')
    tiddler.text = 'i am tiddler 1'
    tiddler.bag = 'bag1'

    store.put(tiddler)

    assert os.path.isdir('store/bag1/tiddler1')
    assert os.path.exists('store/bag1/tiddler1/1')

    loaded_tiddler = Tiddler('tiddler1', 'bag1')
    loaded_tiddler = store.get(loaded_tiddler)
    assert loaded_tiddler.text == tiddler.text
Beispiel #45
0
def test_tiddler_json_render():
    serializer = Serializer('json', environ={'tiddlyweb.query': {
        'render': [1]}, 'tiddlyweb.config': config})
    tiddler = Tiddler('htmltest')
    tiddler.text = '!Hi\n//you//'
    tiddler.bag = 'snoop'

    serializer.object = tiddler

    output = serializer.to_string()
    info = simplejson.loads(output)
    assert info['render'] == '<pre>\n!Hi\n//you//</pre>\n'
    assert info['text'] == '!Hi\n//you//'
Beispiel #46
0
def send_template(environ, template_name, template_data=None):
    """
    Set some defaults for a template and send the output.
    """
    if template_data == None:
        template_data = {}
    template = get_template(environ, template_name)

    store = environ['tiddlyweb.store']

    linked_resources = {
        'HtmlCss': ['/bags/common/tiddlers/profile.css'],
        'HtmlJavascript': []
    }

    # Load CSS and JavaScript overrides.
    current_space = determine_space(environ, determine_host(environ)[0])
    if current_space:
        recipe_name = determine_space_recipe(environ, current_space)
        try:
            recipe = store.get(Recipe(recipe_name))
            for title in linked_resources:
                try:
                    tiddler = Tiddler(title)
                    bag = control.determine_bag_from_recipe(
                        recipe, tiddler, environ)
                    tiddler.bag = bag.name
                    try:
                        tiddler = store.get(tiddler)
                        if 'Javascript' in title:
                            urls = tiddler.text.strip().rstrip().split('\n')
                            linked_resources[title] = urls
                        else:
                            url = '/bags/%s/tiddlers/%s' % (encode_name(
                                tiddler.bag), title)
                            linked_resources[title] = [url]
                    except StoreError:
                        continue
                except StoreError:
                    pass
        except StoreError:
            pass

    template_defaults = {
        'original_server_host': original_server_host_url(environ),
        'css': linked_resources['HtmlCss'],
        'js': linked_resources['HtmlJavascript'],
        'server_host': server_base_url(environ),
    }
    template_defaults.update(template_data)
    return template.generate(template_defaults)
Beispiel #47
0
def test_simple_get():
    """
    get a tiddler that had been stored
    """
    stored_tiddler = Tiddler('TiddlerOne')
    stored_tiddler.bag = u'bagone'
    stored_tiddler.modified = '200803030303'
    stored_tiddler = store.get(stored_tiddler)

    assert stored_tiddler.title == 'TiddlerOne'
    assert stored_tiddler.bag == 'bagone'
    assert stored_tiddler.text == 'c tiddler one content'

    assert sorted(stored_tiddler.tags) == ['tag five', 'tagone', 'tagtwo']
Beispiel #48
0
    def tiddler(args):
        """Import a single tiddler into an existing bag from stdin: <bag> <tiddler>"""
        try:
            bag_name, tiddler_name = args[0:3]
        except (IndexError, ValueError):
            usage('you must include a tiddler and bag name')

        from tiddlyweb.model.tiddler import Tiddler

        new_tiddler = Tiddler(tiddler_name)
        new_tiddler.bag = bag_name

        content = sys.stdin.read()
        _put(new_tiddler, unicode(content, 'UTF-8'), 'text')
Beispiel #49
0
def test_simple_render():
    tiddler = Tiddler('bar')
    tiddler.text = 'Hello [[monkey]]!'
    tiddler.bag = 'zoo'

    html = render(tiddler, {})
    assert 'href="/bags/zoo/tiddlers/monkey"' in html

    tiddler.recipe = 'city'
    html = render(tiddler, {})
    assert 'href="/recipes/city/tiddlers/monkey"' in html

    html = render(tiddler, {'tiddlyweb.config': {'server_prefix': '/wiki'}})
    assert 'href="/wiki/recipes/city/tiddlers/monkey"' in html
Beispiel #50
0
def test_tiddler_json_render_skinny():
    serializer = Serializer('json', environ={'tiddlyweb.query': {
        'render': ['1'], 'fat': ['0']}, 'tiddlyweb.config': config})
    tiddler = Tiddler('htmltest')
    tiddler.bag = 'snoop'
    tiddler.text = '!Hi\n//you//'

    serializer.object = tiddler

    output = serializer.to_string()
    info = simplejson.loads(output)
    assert info['render'] == '<pre>\n!Hi\n//you//</pre>\n'
    with pytest.raises(KeyError):
        info['text']
def populate_store():
    store = get_store(config)

    for bag_name in ["alpha", "bravo"]:
        bag = Bag(bag_name)
        store.put(bag)

        for title in ["foo", "bar"]:
            tiddler = Tiddler(title)
            tiddler.bag = bag.name
            store.put(tiddler)

    for recipe_name in ["omega"]:
        recipe = Recipe(recipe_name)
        store.put(recipe)
Beispiel #52
0
def test_store_lock():
    """
    Make the sure the locking system throws the proper lock.
    """
    if type(store.storage) != Texter:
        py.test.skip('skipping this test for non-text store')

    write_lock('store/bags')
    py.test.raises(LockError, 'write_lock("store/bags")')

    write_lock('store/bags' + '/bagone/tiddlers/foobar')
    tiddler = Tiddler('foobar')
    tiddler.text = 'hello'
    tiddler.bag = u'bagone'
    py.test.raises(StoreLockError, 'store.put(tiddler)')
def test_tiddler_json_base64():
    serializer = Serializer('json')
    tiddler = Tiddler('binarytiddler')
    tiddler.bag = u'foo'
    tiddler.text = file('test/peermore.png', 'rb').read()
    bininfo = tiddler.text
    b64expected = b64encode(tiddler.text)
    tiddler.type = 'image/png'
    serializer.object = tiddler
    string = serializer.to_string()
    info = simplejson.loads(string)
    assert info['text'] == b64expected

    tiddler = serializer.from_string(string)
    assert tiddler.text == bininfo
Beispiel #54
0
def create_tiddler(store, bag, numeral):
    tiddler = Tiddler('tiddler%s' % numeral)
    tiddler.bag = bag.name
    tiddler.text = u'i am tiddler %s' % numeral
    tags = [u'basic tag']
    if not numeral % 2:
        tags.append(u'tagtwo')
    if not numeral % 3:
        tags.append(u'tagthree')
    if not numeral % 4:
        tags.append(u'tagfour')
    tiddler.tags = tags
    if tiddler.title == 'tiddler8':
        tiddler.modified = '200805230303'
    store.put(tiddler)
def test_html_attribute_escape():
    tiddler = Tiddler(
        'escape "double" quotes & &amp; in <tiddler> field values')
    tiddler.bag = u'foo "bar" baz'
    tiddler.modifier = 'Chris "sensei" Dent'
    tiddler.tags = ["foo", 'xxx "yyy" zzz']
    tiddler.fields["custom"] = u"""lorem 'ipsum' dolor "sit" amet"""
    tiddler.text = ''
    serializer = Serializer('html')
    serializer.object = tiddler
    string = serializer.to_string()

    assert r'''title="escape &quot;double&quot; quotes &amp; &amp;amp; in &lt;tiddler&gt; field values"''' in string
    assert r'''modifier="Chris &quot;sensei&quot; Dent"''' in string
    assert r'''tags="foo [[xxx &quot;yyy&quot; zzz]]"''' in string
    assert r'''custom="lorem 'ipsum' dolor &quot;sit&quot; amet"''' in string
Beispiel #56
0
def test_simple_get():
    """
    get a tiddler that had been stored in bagfour
    """

    stored_tiddler = Tiddler(title='TiddlerOne')
    stored_tiddler.bag = u'bagone'
    stored_tiddler.modified = '200803030303'
    stored_tiddler = store.get(stored_tiddler)

    assert stored_tiddler.title == 'TiddlerOne', 'retrieved tiddler has correct title'
    assert stored_tiddler.bag == 'bagone', 'retrieve tiddler has correct bag'
    assert stored_tiddler.text == 'c tiddler one content', 'text is %s should b %s' % (
        stored_tiddler.text, 'c tiddler one content\n')

    assert sorted(stored_tiddler.tags) == ['tag five', 'tagone', 'tagtwo']