本文整理汇总了Python中tiddlywebplugins.tiddlyspace.web.determine_host函数的典型用法代码示例。如果您正苦于以下问题:Python determine_host函数的具体用法?Python determine_host怎么用?Python determine_host使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了determine_host函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: safe_mode
def safe_mode(environ, start_response):
"""
Serve up a space in safe mode. Safe mode means that
non-required plugins are turned off and plugins that
duplicate those in the core bags (system and tiddlyspace)
are deleted from the store of the space in question.
"""
http_host, _ = determine_host(environ)
space_name = determine_space(environ, http_host)
recipe_name = determine_space_recipe(environ, space_name)
if recipe_name != '%s_private' % space_name:
raise HTTP403('membership required for safe mode')
if environ['REQUEST_METHOD'] == 'GET':
return _send_safe_mode(environ, start_response)
store = environ['tiddlyweb.store']
# Get the list of core plugins
core_plugin_tiddler_titles = _get_core_plugins(store)
# Delete those plugins in the space's recipes which
# duplicate the core plugins
recipe = _delete_duplicates(environ, core_plugin_tiddler_titles,
recipe_name, space_name)
# Process the recipe. For those tiddlers which do not have a bag
# in CORE_RECIPE, remove the systemConfig tag.
try:
candidate_tiddlers = control.get_tiddlers_from_recipe(recipe, environ)
except NoBagError, exc:
raise HTTP404('recipe %s lists an unknown bag: %s' %
(recipe.name, exc))
示例2: _status_gather_data
def _status_gather_data(environ):
"""
Monkey patch twp.status to add additional information
specific to TiddlySpace.
"""
data = original_gather_data(environ)
data['server_host'] = environ['tiddlyweb.config']['server_host']
data['tiddlyspace_version'] = environ['tiddlyweb.config'][
'tiddlyspace.version']
# gather space data
http_host, host_url = determine_host(environ)
if http_host != host_url:
space_name = determine_space(environ, http_host)
try:
recipe_name = determine_space_recipe(environ, space_name)
data['space'] = {'name': space_name, 'recipe': recipe_name}
except HTTP404:
pass
# ensure user is known
usersign = environ['tiddlyweb.usersign']['name']
store = environ['tiddlyweb.store']
try:
store.get(User(usersign))
except NoUserError:
data['username'] = 'GUEST'
if usersign != 'GUEST':
data['identity'] = usersign
return data
示例3: _handle_dropping_privs
def _handle_dropping_privs(self, environ, req_uri):
"""
Determin if this request is to be considered "in space" or
not. If it is not and the current user is not GUEST we need
to pretend that the current user is GUEST, effectively
"dropping" privileges.
"""
if environ['tiddlyweb.usersign']['name'] == 'GUEST':
return
http_host, _ = determine_host(environ)
space_name = determine_space(environ, http_host)
if space_name is None:
return
space = Space(space_name)
container_name = req_uri.split('/')[2]
if (req_uri.startswith('/bags/')
and self._valid_bag(environ, space, container_name)):
return
if (req_uri.startswith('/recipes/')
and container_name in space.list_recipes()):
return
self._drop_privs(environ)
return
示例4: _same_space_required
def _same_space_required(environ, space_name):
"""
Raise 403 unless the current space (http_host) is the same as the
target space.
"""
current_space = determine_space(environ, determine_host(environ)[0])
if current_space != space_name:
raise HTTP403('space membership changes only allowed from space')
示例5: __call__
def __call__(self, environ, start_response):
http_host, host_url = determine_host(environ)
if http_host == host_url:
space_name = DEFAULT_SPACE_NAME
else:
space_name = determine_space(environ, http_host)
update_space_settings(environ, space_name)
return self.application(environ, start_response)
示例6: get_nonce_components
def get_nonce_components(environ):
"""
return username, spacename, timestamp (from cookie) and secret
"""
username = environ['tiddlyweb.usersign']['name']
http_host = determine_host(environ)[0]
spacename = determine_space(environ, http_host) or ''
secret = environ['tiddlyweb.config']['secret']
return (username, spacename, secret)
示例7: home
def home(environ, start_response):
"""
handles requests at /, serving either the front page or a space (public or
private) based on whether a subdomain is used.
relies on tiddlywebplugins.virtualhosting
"""
http_host, host_url = determine_host(environ)
if http_host == host_url:
http_host = 'frontpage.' + http_host
return serve_space(environ, start_response, http_host)
示例8: list_tiddlers
def list_tiddlers(self, tiddlers):
"""
Override tiddlers.link so the location in noscript is to
/tiddlers.
"""
http_host, _ = determine_host(self.environ)
space_name = determine_space(self.environ, http_host)
recipe_name = determine_space_recipe(self.environ, space_name)
if '/recipes/%s' % recipe_name in tiddlers.link:
tiddlers.link = '/tiddlers'
return WikiSerialization.list_tiddlers(self, tiddlers)
示例9: host_meta
def host_meta(environ, start_response):
"""
Send the host_meta information, so webfinger info can be found.
"""
http_host, host_url = determine_host(environ)
if http_host != host_url:
# Or should it be a 302?
raise HTTP404('No host-meta at this host: %s' % http_host)
start_response('200 OK', [
('Content-Type', 'application/xrd+xml')])
return send_template(environ, 'hostmeta.xml', {'host': http_host})
示例10: host_meta
def host_meta(environ, start_response):
"""
Send the host_meta information, so webfinger info can be found.
"""
http_host, host_url = determine_host(environ)
if http_host != host_url:
# Or should it be a 302?
raise HTTP404('No host-meta at this host: %s' % http_host)
start_response('200 OK', [
('Content-Type', 'application/xrd+xml')])
return [HOST_META_TEMPLATE % {'host': http_host, 'server_host':
server_base_url(environ)}]
示例11: send_template
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)
示例12: _setup_friendly_environ
def _setup_friendly_environ(environ):
"""
Manipulate the environ so that we appear to be in the context of the
recipe appropriate for this current space and the current membership
status. Return space_name to caller.
"""
http_host, host_url = determine_host(environ)
if http_host == host_url:
space_name = "frontpage"
else:
space_name = determine_space(environ, http_host)
recipe_name = determine_space_recipe(environ, space_name)
environ['wsgiorg.routing_args'][1]['recipe_name'] = recipe_name.encode(
'UTF-8')
示例13: friendly_uri
def friendly_uri(environ, start_response):
"""
Transform a not alread mapped request at the root of a space
into a request for a tiddler in the public or private recipe
of the current space.
"""
http_host, host_url = determine_host(environ)
if http_host == host_url:
raise HTTP404('No resource found')
else:
space_name = determine_space(environ, http_host)
recipe_name = determine_space_recipe(environ, space_name)
# tiddler_name already in uri
environ['wsgiorg.routing_args'][1]['recipe_name'] = recipe_name.encode(
'UTF-8')
return get_tiddler(environ, start_response)
示例14: profile
def profile(environ, start_response):
"""
Choose between an atom or html profile.
"""
http_host, host_url = determine_host(environ)
if http_host != host_url:
# Or should it be a 302?
raise HTTP404('No profiles at this host: %s' % http_host)
_, mime_type = get_serialize_type(environ)
if 'atom' in mime_type:
return atom_profile(environ, start_response)
elif 'html' in mime_type:
return html_profile(environ, start_response)
else:
raise HTTP415('Atom and HTML only')
示例15: _handle_dropping_privs
def _handle_dropping_privs(self, environ, req_uri):
if environ['tiddlyweb.usersign']['name'] == 'GUEST':
return
http_host, _ = determine_host(environ)
space_name = determine_space(environ, http_host)
if space_name == None:
return
space = Space(space_name)
store = environ['tiddlyweb.store']
container_name = req_uri.split('/')[2]
if req_uri.startswith('/bags/'):
recipe_name = determine_space_recipe(environ, space_name)
space_recipe = store.get(Recipe(recipe_name))
template = recipe_template(environ)
recipe_bags = [bag for bag, _ in space_recipe.get_recipe(template)]
recipe_bags.extend(space.extra_bags())
if environ['REQUEST_METHOD'] == 'GET':
if container_name in recipe_bags:
return
if container_name in ADMIN_BAGS:
return
else:
base_bags = space.list_bags()
# add bags in the recipe which may have been added
# by the recipe mgt. That is: bags which are not
# included and not core.
acceptable_bags = [bag for bag in recipe_bags if not (
Space.bag_is_public(bag) or Space.bag_is_private(bag)
or Space.bag_is_associate(bag))]
acceptable_bags.extend(base_bags)
acceptable_bags.extend(ADMIN_BAGS)
if container_name in acceptable_bags:
return
if (req_uri.startswith('/recipes/')
and container_name in space.list_recipes()):
return
self._drop_privs(environ)
return