本文整理汇总了Python中tiddlywebplugins.tiddlyspace.space.Space.name_from_bag方法的典型用法代码示例。如果您正苦于以下问题:Python Space.name_from_bag方法的具体用法?Python Space.name_from_bag怎么用?Python Space.name_from_bag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tiddlywebplugins.tiddlyspace.space.Space
的用法示例。
在下文中一共展示了Space.name_from_bag方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: web_tiddler_url
# 需要导入模块: from tiddlywebplugins.tiddlyspace.space import Space [as 别名]
# 或者: from tiddlywebplugins.tiddlyspace.space.Space import name_from_bag [as 别名]
def web_tiddler_url(environ, tiddler, container='bags', full=True):
"""
Override default tiddler_url to be space+host aware.
If the bag or recipe of the tiddler is of a space, switch to
that space's host for the duration of uri creation.
Do this all the time, so that we get the right URIs even
when working around ControlView.
If the bag does not fit in a space, then make is URI be at
the server_host domain. If/when auxbags are made to work this
will need to be reviewed.
"""
if '_canonical_uri' in tiddler.fields:
return tiddler.fields['_canonical_uri']
saved_host = environ.get('HTTP_HOST', '')
try:
if container == 'recipes':
space_name = Space.name_from_recipe(tiddler.recipe)
else:
space_name = Space.name_from_bag(tiddler.bag)
space_name = space_name + '.'
except ValueError, exc:
space_name = ''
示例2: web_tiddler_url
# 需要导入模块: from tiddlywebplugins.tiddlyspace.space import Space [as 别名]
# 或者: from tiddlywebplugins.tiddlyspace.space.Space import name_from_bag [as 别名]
def web_tiddler_url(environ, tiddler, container='bags', full=True,
friendly=False):
"""
Override default tiddler_url to be space+host aware.
If the bag or recipe of the tiddler is of a space, switch to
that space's host for the duration of uri creation.
Do this all the time, so that we get the right URIs even
when working around ControlView.
If the bag does not fit in a space, then make is URI be at
the server_host domain. If/when auxbags are made to work this
will need to be reviewed.
"""
saved_host = environ.get('HTTP_HOST', '')
try:
if container == 'recipes':
space_name = Space.name_from_recipe(tiddler.recipe)
else:
space_name = Space.name_from_bag(tiddler.bag)
space_name = space_name + '.'
except ValueError:
space_name = ''
host = environ['tiddlyweb.config']['server_host']['host']
port = environ['tiddlyweb.config']['server_host']['port']
if port is '443' or port is '80':
port = ''
else:
port = ':%s' % port
environ['HTTP_HOST'] = '%s%s%s' % (space_name.encode('utf-8'),
host, port)
if friendly and space_name:
url = '%s/%s' % (tiddlyweb.web.util.server_base_url(environ),
tiddlyweb.web.util.encode_name(tiddler.title))
else:
url = original_tiddler_url(environ, tiddler, container, full)
if saved_host:
environ['HTTP_HOST'] = saved_host
elif 'HTTP_HOST' in environ:
del environ['HTTP_HOST']
return url
示例3: web_tiddler_url
# 需要导入模块: from tiddlywebplugins.tiddlyspace.space import Space [as 别名]
# 或者: from tiddlywebplugins.tiddlyspace.space.Space import name_from_bag [as 别名]
def web_tiddler_url(environ, tiddler, container='bags', full=True):
"""
Override default tiddler_url to be space+host aware.
If the bag or recipe of the tiddler is of a space, switch to
that space's host for the duration of uri creation.
Do this all the time, so that we get the right URIs even
when working around ControlView.
"""
if '_canonical_uri' in tiddler.fields:
return tiddler.fields['_canonical_uri']
saved_host = environ.get('HTTP_HOST', '')
try:
if container == 'recipes':
space_name = Space.name_from_recipe(tiddler.recipe)
else:
space_name = Space.name_from_bag(tiddler.bag)
host = environ['tiddlyweb.config']['server_host']['host']
port = environ['tiddlyweb.config']['server_host']['port']
if port is '443' or port is '80':
port = ''
else:
port = ':%s' % port
environ['HTTP_HOST'] = '%s.%s%s' % (space_name.encode('utf-8'),
host, port)
except ValueError:
pass
url = original_tiddler_url(environ, tiddler, container, full)
if saved_host:
environ['HTTP_HOST'] = saved_host
elif 'HTTP_HOST' in environ:
del environ['HTTP_HOST']
return url
示例4: test_name_from_bag
# 需要导入模块: from tiddlywebplugins.tiddlyspace.space import Space [as 别名]
# 或者: from tiddlywebplugins.tiddlyspace.space.Space import name_from_bag [as 别名]
def test_name_from_bag():
assert Space.name_from_bag('cat_private') == 'cat'
py.test.raises(ValueError, 'Space.name_from_bag("cat_ball")')