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


Python Tiddler.type方法代码示例

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


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

示例1: test_tiddler_listing

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import type [as 别名]
def test_tiddler_listing():
    bag = Bag('bravo')
    STORE.put(bag)

    tiddlers = STORE.list_bag_tiddlers(bag)
    assert len(list(tiddlers)) == 0

    tiddler = Tiddler('Foo', bag.name)
    tiddler.type = 'application/binary'
    STORE.put(tiddler)

    tiddlers = STORE.list_bag_tiddlers(bag)
    titles = [tiddler.title for tiddler in tiddlers]
    assert len(titles) == 1

    tiddler = Tiddler('Bar', bag.name)
    STORE.put(tiddler)

    tiddlers = STORE.list_bag_tiddlers(bag)
    titles = [tiddler.title for tiddler in tiddlers]
    assert len(titles) == 2

    tiddler = Tiddler('Baz', bag.name)
    tiddler.type = 'image/png'
    STORE.put(tiddler)

    tiddlers = STORE.list_bag_tiddlers(bag)
    titles = [tiddler.title for tiddler in tiddlers]
    assert len(titles) == 3
开发者ID:FND,项目名称:tiddlywebplugins.gitstore,代码行数:31,代码来源:test_binary_tiddler.py

示例2: test_get_profile_html

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import type [as 别名]
def test_get_profile_html():
    response, content = http.request('http://0.0.0.0:8080/profiles/cdent')
    # the lack of a profile tiddler indicates you don't want to
    # participate
    assert response['status'] == '404', content

    tiddler = Tiddler('profile', 'cdent_public')
    tiddler.text = '#Hello There\n[[monkey]]'
    tiddler.type = 'text/x-markdown'
    tiddler.modifier = 'cdent'
    store.put(tiddler)

    response, content = http.request('http://0.0.0.0:8080/profiles/cdent')
    assert response['status'] == '200', content

    assert 'Hello There' in content
    assert 'http://cdent.0.0.0.0:8080/profile' in content
    assert '<li><a href="http://cdent.0.0.0.0:8080/profile">profile</a></li>' in content
    assert '<base href="http://cdent.0.0.0.0:8080/"' in content
    assert '<p><a class="wikilink" href="monkey">monkey</a></p>' in content

    response, content = http.request('http://cdent.0.0.0.0:8080/profiles/cdent')
    assert response['status'] == '404', content
    assert 'No profiles at this host' in content

    response, content = http.request('http://0.0.0.0:8080/profiles/notexist')
    assert response['status'] == '404', content
    assert 'Profile not found for notexist' in content
开发者ID:Alanchi,项目名称:tiddlyspace,代码行数:30,代码来源:test_web_finger.py

示例3: test_file_separation

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import type [as 别名]
def test_file_separation():
    STORE_ROOT = os.path.join(TMPDIR, 'test_store')

    tiddler = Tiddler('Foo', BAG.name)
    tiddler.type = 'application/binary'
    tiddler.text = 'lorem ipsum'
    STORE.put(tiddler)
    assert tiddler.text == 'lorem ipsum'
    assert tiddler.type == 'application/binary'

    bag_dir = os.path.join(STORE_ROOT, 'bags', 'alpha')
    tiddlers_dir = os.path.join(bag_dir, 'tiddlers')
    tiddler_file = os.path.join(tiddlers_dir, 'Foo')
    bin_dir = os.path.join(tiddlers_dir, '_binaries')
    bin_file = os.path.join(bin_dir, 'Foo')
    assert os.path.isfile(tiddler_file)
    assert os.path.isdir(bin_dir)
    assert os.path.isfile(bin_file)
    with open(tiddler_file) as fh:
        contents = fh.read()
        assert 'type: application/binary' in contents
        assert 'lorem ipsum' not in contents
        lines = contents.splitlines()
        assert ': ' in lines[-3] # header
        assert lines[-2] == '' # separator
        assert len(lines[-1]) == 60 # body
    with open(bin_file) as fh:
        contents = fh.read()
        assert contents == 'lorem ipsum'

    stored_tiddler = STORE.get(Tiddler(tiddler.title, tiddler.bag))
    assert stored_tiddler.text == 'lorem ipsum'
开发者ID:FND,项目名称:tiddlywebplugins.gitstore,代码行数:34,代码来源:test_binary_tiddler.py

示例4: test_commit

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import type [as 别名]
def test_commit():
    tiddler = Tiddler('Bar', BAG.name)
    tiddler.type = 'application/binary'
    tiddler.text = 'lorem ipsum'
    STORE.put(tiddler)

    bag_dir = os.path.join(STORE_ROOT, 'bags', 'alpha')
    tiddler_file = os.path.join(bag_dir, 'tiddlers', 'Bar')
    binary_file = os.path.join(bag_dir, 'tiddlers', '_binaries', 'Bar')

    trevs = run('git', 'log', '--format=%h', '--', tiddler_file, cwd=STORE_ROOT)
    brevs = run('git', 'log', '--format=%h', '--', binary_file, cwd=STORE_ROOT)
    assert len(trevs.splitlines()) == 1
    assert len(brevs.splitlines()) == 1
    assert trevs == brevs

    tiddler.text = 'lorem ipsum\ndolor sit amet'
    STORE.put(tiddler)

    trevs = run('git', 'log', '--format=%h', '--', tiddler_file, cwd=STORE_ROOT)
    brevs = run('git', 'log', '--format=%h', '--', binary_file, cwd=STORE_ROOT)
    assert len(trevs.splitlines()) == 2
    assert len(brevs.splitlines()) == 2
    assert trevs == brevs

    STORE.delete(tiddler)

    trevs = run('git', 'log', '--format=%h', '--', tiddler_file, cwd=STORE_ROOT)
    brevs = run('git', 'log', '--format=%h', '--', binary_file, cwd=STORE_ROOT)
    assert len(trevs.splitlines()) == 3
    assert len(brevs.splitlines()) == 3
    assert trevs == brevs
开发者ID:FND,项目名称:tiddlywebplugins.gitstore,代码行数:34,代码来源:test_binary_tiddler.py

示例5: from_special

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import type [as 别名]
def from_special(uri, handle, mime=None):
    """
    Import a binary or pseudo binary tiddler. If a mime is provided,
    set the type of the tiddler to that. Otherwise use the type determined
    by the URL handler. If a meta file is present and has a type, it will
    be used.

    This code is inspired by @bengillies bimport.
    """
    title = _get_title_from_uri(uri)
    if mime:
        content_type = mime
    else:
        content_type = handle.headers['content-type'].split(';')[0]
    data = handle.read()

    meta_uri = '%s.meta' % uri
    try:
        meta_content = _get_url(meta_uri)
        tiddler = _from_text(title, meta_content + '\n\n')
    except (HTTPError, URLError, IOError, OSError):
        tiddler = Tiddler(title)

    if not tiddler.type and content_type:
        tiddler.type = content_type

    if pseudo_binary(tiddler.type):
        data = data.decode('utf-8', 'ignore')

    tiddler.text = data

    return tiddler
开发者ID:tiddlyweb,项目名称:tiddlywebplugins.twimport,代码行数:34,代码来源:twimport.py

示例6: setup_module

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import type [as 别名]
def setup_module(module):
    module.TMPDIR = tempfile.mkdtemp()

    _initialize_app(TMPDIR)
    module.ADMIN_COOKIE = make_cookie('tiddlyweb_user', 'admin',
            mac_key=CONFIG['secret'])

    module.STORE = get_store(CONFIG)

    # register admin user
    data = {
        'username': 'admin',
        'password': 'secret',
        'password_confirmation': 'secret'
    }
    response, content = _req('POST', '/register', urlencode(data),
            headers={ 'Content-Type': 'application/x-www-form-urlencoded' })

    bag = Bag('alpha')
    bag.policy = Policy(read=['admin'], write=['admin'], create=['admin'],
            delete=['admin'], manage=['admin'])
    STORE.put(bag)

    bag = Bag('bravo')
    STORE.put(bag)

    bag = Bag('charlie')
    bag.policy = Policy(read=['nobody'], write=['nobody'], create=['nobody'],
            delete=['nobody'], manage=['nobody'])
    STORE.put(bag)

    tiddler = Tiddler('index', 'bravo')
    tiddler.text = 'lorem ipsum\ndolor *sit* amet'
    tiddler.type = 'text/x-markdown'
    STORE.put(tiddler)
开发者ID:pads,项目名称:tiddlywebplugins.bfw,代码行数:37,代码来源:test_web.py

示例7: test_space_server_settings_index

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import type [as 别名]
def test_space_server_settings_index():
    http = httplib2.Http()
    response, content = http.request('http://foo.0.0.0.0:8080/')
    assert response['status'] == '200'
    assert 'TiddlyWiki' in content

    tiddler = Tiddler('ServerSettings', 'foo_public')
    tiddler.text = 'index: MySPA\n'
    store.put(tiddler)

    http = httplib2.Http()
    response, content = http.request('http://foo.0.0.0.0:8080/')
    assert response['status'] == '404'

    tiddler = Tiddler('MySPA', 'foo_public')
    tiddler.text = '<html><h1>Hello!</h1></html>'
    tiddler.type = 'text/html'
    store.put(tiddler)

    http = httplib2.Http()
    response, content = http.request('http://foo.0.0.0.0:8080/')
    assert response['status'] == '200'

    assert '<h1>Hello!</h1>' in content
    assert 'TiddlyWiki' not in content
    assert 'TiddlyWeb' not in content
开发者ID:dahukanna,项目名称:tiddlyspace,代码行数:28,代码来源:test_web_use_instance.py

示例8: register_user

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import type [as 别名]
def register_user(environ, start_response):
    username, password, confirmation = [environ['tiddlyweb.query'][param][0] for
            param in ('username', 'password', 'password_confirmation')]

    user = User(username)
    store = environ['tiddlyweb.store']
    try:
        store.get(user)
        available = False
    except NoUserError:
        available = username not in BLACKLIST
    if not available:
        raise HTTP409('username unavailable')

    if not password == confirmation:
        raise HTTP400('passwords do not match')

    _create_wiki(store, username, username, private=True)

    user.set_password(password)
    store.put(user)

    index = Tiddler('index', username)
    index.type = 'text/x-markdown'
    index.text = "Welcome to %s's personal wiki." % username
    store.put(index)

    cookie = make_cookie('tiddlyweb_user', user.usersign,
            path=uri('front page', environ),
            mac_key=environ['tiddlyweb.config']['secret'],
            expires=environ['tiddlyweb.config'].get('cookie_age', None))

    start_response('303 See Other', [('Set-Cookie', cookie),
            ('Location', uri('dashboard', environ).encode('UTF-8'))])
    return ['']
开发者ID:FND,项目名称:tiddlywebplugins.bfw,代码行数:37,代码来源:web.py

示例9: _determine_tiddler

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

示例10: _manage_create_news

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import type [as 别名]
def _manage_create_news(environ, gym):
    store = environ['tiddlyweb.store']
    news = environ['tiddlyweb.query'].get('news', [''])[0]
    tiddler = Tiddler(str(uuid4()), '%s_news' % gym)
    tiddler.text = news
    tiddler.type = TIDDLER_TYPE
    store.put(tiddler)
    raise HTTP303(server_base_url(environ) + '/manager/%s' % gym)
开发者ID:FND,项目名称:nitor,代码行数:10,代码来源:__init__.py

示例11: test_svg_output

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import type [as 别名]
def test_svg_output():
    tiddler = Tiddler('svg thing', 'fake')
    tiddler.text = SVG
    tiddler.type = 'image/svg+xml'

    serializer.object = tiddler
    output = serializer.to_string()
    assert 'wikkly-error-head' not in output
开发者ID:tiddlyweb,项目名称:tiddlywebplugins.atom,代码行数:10,代码来源:test_pseudo_binary.py

示例12: test_svg_output

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import type [as 别名]
def test_svg_output():
    tiddler = Tiddler('markdown thing', 'fake')
    tiddler.text = MARKDOWN
    tiddler.type = 'text/x-markdown'

    serializer.object = tiddler
    output = serializer.to_string()
    assert '* list one' not in output
    assert '&lt;li&gt;list one' in output
开发者ID:tiddlyweb,项目名称:tiddlywebplugins.atom,代码行数:11,代码来源:test_wikitext_render_map.py

示例13: test_nonhtml_output

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import type [as 别名]
def test_nonhtml_output():
    tiddler = Tiddler('html thing', 'fake')
    tiddler.text = '<h1>Hi</h1>'
    tiddler.type = 'text/nothtml'

    serializer.object = tiddler
    output = serializer.to_string()
    assert 'type="html"' in output
    assert '>&lt;pre&gt;&lt;h1&gt;Hi&lt;/h1&gt;&lt;/pre&gt;</content>' in output
    assert '&lt;pre&gt;' in output
开发者ID:tiddlyweb,项目名称:tiddlywebplugins.atom,代码行数:12,代码来源:test_pseudo_binary.py

示例14: test_markdown_support

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import type [as 别名]
def test_markdown_support():
    tiddler = Tiddler("Markdown Test", "cdent_public")
    tiddler.text = "_No Way_"
    tiddler.type = "text/x-markdown"
    store.put(tiddler)
    http = httplib2.Http()
    response, content = http.request("http://cdent.0.0.0.0:8080/Markdown%20Test", method="GET")
    assert response["status"] == "200", content
    assert "text/html" in response["content-type"]
    assert "<em>No Way</em>" in content
开发者ID:colmjude,项目名称:tiddlyspace,代码行数:12,代码来源:test_friendly_uri.py

示例15: test_revision_listing

# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import type [as 别名]
def test_revision_listing():
    contents = ['lipsum', 'lorem ipsum', 'lorem ipsum\ndolor sit amet']
    for i, text in enumerate(contents):
        tiddler = Tiddler('FooBar', BAG.name)
        tiddler.text = text
        tiddler.type = None if i % 2 == 0 else 'application/binary'
        STORE.put(tiddler)

    tiddler = Tiddler('FooBar', BAG.name)
    revisions = STORE.list_tiddler_revisions(tiddler)
    assert len(revisions) == 3
开发者ID:FND,项目名称:tiddlywebplugins.gitstore,代码行数:13,代码来源:test_binary_tiddler.py


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