当前位置: 首页>>代码示例>>Python>>正文


Python Tiddler.bag方法代码示例

本文整理汇总了Python中tiddlyweb.model.tiddler.Tiddler.bag方法的典型用法代码示例。如果您正苦于以下问题:Python Tiddler.bag方法的具体用法?Python Tiddler.bag怎么用?Python Tiddler.bag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tiddlyweb.model.tiddler.Tiddler的用法示例。


在下文中一共展示了Tiddler.bag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import bag [as 别名]
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))
开发者ID:tiddlyweb,项目名称:tiddlyweb-plugins,代码行数:30,代码来源:tiddlyeditor.py

示例2: get

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import bag [as 别名]
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))
开发者ID:FND,项目名称:tiddlywiki-svn-mirror,代码行数:33,代码来源:tiddlywebeditor_plus.py

示例3: _manage_update_routes

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import bag [as 别名]
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)
开发者ID:cdent,项目名称:nitor,代码行数:61,代码来源:__init__.py

示例4: test_put_and_get_tiddler

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import bag [as 别名]
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'
开发者ID:angeluseve,项目名称:tiddlyweb,代码行数:16,代码来源:test_roundtrip.py

示例5: test_tiddler_unique_by_bags

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import bag [as 别名]
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'
开发者ID:angeluseve,项目名称:tiddlyweb,代码行数:16,代码来源:test_roundtrip.py

示例6: url

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import bag [as 别名]
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
开发者ID:bengillies,项目名称:tiddlywebplugins.urls,代码行数:28,代码来源:twanager.py

示例7: _process_choices

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import bag [as 别名]
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)
开发者ID:tiddlyweb,项目名称:tiddlywebplugins.wimporter,代码行数:36,代码来源:wimporter.py

示例8: retrieve_from_store

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import bag [as 别名]
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
开发者ID:jdlrobson,项目名称:tiddlywebplugins.email,代码行数:28,代码来源:mail.py

示例9: test_tiddler_title_with_slash

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import bag [as 别名]
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'
开发者ID:JazzDeben,项目名称:tiddlyweb-xmobile,代码行数:18,代码来源:test_tiddler_slash.py

示例10: test_get_revision

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import bag [as 别名]
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
开发者ID:24king,项目名称:tiddlyweb,代码行数:34,代码来源:test_store_tiddler.py

示例11: test_call_jsonp

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import bag [as 别名]
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="%s"' % 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="%s"' % user_cookie,
            'Accept': 'application/json'
        })
    assert response['status'] == '200'
    assert content.startswith('%s(' % callback)
    assert content[-1:] == ')'
开发者ID:EnoX1,项目名称:tiddlyspace,代码行数:34,代码来源:test_jsonp.py

示例12: test_tiddler_url

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import bag [as 别名]
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'
开发者ID:FND,项目名称:tiddlyweb,代码行数:36,代码来源:test_web_util.py

示例13: test_html_attribute_escape_with_bag

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import bag [as 别名]
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)
开发者ID:tiddlyweb,项目名称:tiddlywebwiki,代码行数:27,代码来源:test_serialize_tiddler.py

示例14: test_determine_tiddler_from_recipe

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import bag [as 别名]
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)')
开发者ID:ingydotnet,项目名称:tiddlyweb,代码行数:27,代码来源:test_recipe.py

示例15: test_no_bag_for_tiddler

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import bag [as 别名]
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)
开发者ID:tiddlyweb,项目名称:tiddlyweb,代码行数:9,代码来源:test_roundtrip.py


注:本文中的tiddlyweb.model.tiddler.Tiddler.bag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。