本文整理汇总了Python中tiddlyweb.web.util.encode_name函数的典型用法代码示例。如果您正苦于以下问题:Python encode_name函数的具体用法?Python encode_name怎么用?Python encode_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了encode_name函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tiddler_get
def tiddler_get(self, tiddler):
if tiddler.revision:
url = self.revision_url % (encode_name(tiddler.bag), encode_name(tiddler.title), tiddler.revision)
else:
url = self.tiddler_url % (encode_name(tiddler.bag), encode_name(tiddler.title))
self.doit(url, tiddler, self._any_get, NoTiddlerError)
return tiddler
示例2: send_entity
def send_entity(environ, start_response, entity):
"""
Send a bag or recipe out HTTP, first serializing to
the correct type.
"""
username = environ['tiddlyweb.usersign']['name']
try:
serialize_type, mime_type = get_serialize_type(environ)
serializer = Serializer(serialize_type, environ)
serializer.object = entity
content = serializer.to_string()
except NoSerializationError:
raise HTTP415('Content type %s not supported' % mime_type)
etag_string = '"%s"' % (sha(_entity_etag(entity) +
encode_name(username) + encode_name(mime_type)).hexdigest())
start_response("200 OK",
[('Content-Type', mime_type),
('ETag', etag_string),
('Vary', 'Accept')])
if isinstance(content, basestring):
return [content]
else:
return content
示例3: _tiddler_to_wikklyhtml
def _tiddler_to_wikklyhtml(self, tiddler):
"""
Render tiddler.text to HTML using wikklytext.
"""
server_prefix = self._server_prefix()
if tiddler.recipe:
list_link = 'recipes/%s/tiddlers' % encode_name(tiddler.recipe)
list_title = 'Tiddlers in Recipe %s' % tiddler.recipe
else:
list_link = 'bags/%s/tiddlers' % encode_name(tiddler.bag)
list_title = 'Tiddlers in Bag %s' % tiddler.bag
from tiddlyweb.wikklyhtml import wikitext_to_wikklyhtml
html = wikitext_to_wikklyhtml('%s/' % server_prefix,
list_link, tiddler.text)
# Have to be very careful in the following about UTF-8 handling
# because wikklytext wants to encode its output.
self.environ['tiddlyweb.title'] = tiddler.title
return """
<div class="tiddlerslink"><a href="%s" title="tiddler list">%s</a></div>
%s
%s
</div>
""" % ('%s/%s' % (server_prefix, list_link),
list_title.encode('utf-8'),
self._tiddler_div(tiddler).encode('utf-8'),
html)
示例4: recipe_as
def recipe_as(self, recipe):
"""
:py:class:`Recipe <tiddlyweb.model.recipe.Recipe>` as HTML,
including a link to the tiddlers within.
"""
self.environ['tiddlyweb.title'] = 'Recipe %s' % recipe.name
lines = []
for bag, filter_string in recipe.get_recipe():
line = '<li><a href="'
line += '%s/bags/%s/tiddlers' % (
self._server_prefix(), encode_name(bag))
if filter_string:
line += '?%s' % quote(
filter_string.encode('utf-8'), safe=':=;')
line += '">bag: %s filter:%s</a></li>' % (bag, filter_string)
lines.append(line)
output = "\n".join(lines)
tiddler_link = '%s/tiddlers' % encode_name(recipe.name)
return """
%s
<div class="tiddlerslink"><a href="%s">Tiddlers in Recipe</a></div>
<div id="recipedesc" class="description">%s</div>
<ul id="recipe" class="listing">
%s
</ul>
%s
""" % (self._header(), tiddler_link, recipe.desc, output, self._footer())
示例5: tiddler_as
def tiddler_as(self, tiddler):
"""
Transform the provided tiddler into an HTML
representation of the tiddler packaged in a
DIV. Render the content using the render_wikitext
subsystem. Links to the tiddler in the wiki are
provided.
"""
user = self.environ['tiddlyweb.usersign']
store = self.environ['tiddlyweb.store']
if tiddler.recipe:
list_link = '/recipes/%s/tiddlers' % encode_name(tiddler.recipe)
list_title = 'Tiddlers in Recipe %s' % tiddler.recipe
else:
list_link = '/bags/%s/tiddlers' % encode_name(tiddler.bag)
list_title = 'Tiddlers in Bag %s' % tiddler.bag
try:
store.get(Bag(tiddler.bag)).policy.allows(user, 'manage')
container_policy = True
except PermissionsError:
container_policy = False
space_link = self._space_link(tiddler)
html = render_wikitext(tiddler, self.environ)
return send_template(self.environ, 'tiddler.html', {
'title': '%s' % tiddler.title,
'tags': tiddler.tags,
'fields': tiddler.fields,
'html': html,
'list_link': list_link,
'list_title': list_title,
'space_link': space_link,
'tiddler': tiddler,
'container_policy': container_policy,
'tiddler_url': tiddler_url(self.environ, tiddler)})
示例6: recipe_as
def recipe_as(self, recipe):
"""
Recipe as html.
"""
self.environ['tiddlyweb.title'] = 'Recipe %s' % recipe.name
lines = []
for bag, filter_string in recipe.get_recipe():
line = '<li><a href="'
if not isinstance(bag, basestring):
bag = bag.name
line += '%s/bags/%s/tiddlers' % (
self._server_prefix(), encode_name(bag))
if filter_string:
line += '?%s' % urllib.quote(
filter_string.encode('utf-8'), safe=':=;')
line += '">bag: %s filter:%s</a></li>' % (bag, filter_string)
lines.append(line)
output = "\n".join(lines)
title = 'Bags in Recipe %s' % recipe.name
tiddler_link = '%s/tiddlers' % encode_name(recipe.name)
return """
<div class="tiddlerslink"><a href="%s">Tiddlers in Recipe</a></div>
<div id="recipedesc" class="description">%s</div>
<ul id="recipe" class="listing">
%s
</ul>
""" % (tiddler_link, recipe.desc, output)
示例7: _new_tiddler_etag
def _new_tiddler_etag(tiddler):
"""
Calculate the ETag of a tiddler that does not
yet exist. This is a bastardization of ETag handling
but is useful for doing edit contention handling.
"""
return str('"%s/%s/%s"' % (web.encode_name(tiddler.bag),
web.encode_name(tiddler.title), '0'))
示例8: _put_tiddlers_in_tiddlywiki
def _put_tiddlers_in_tiddlywiki(self, tiddlers, title='TiddlyWeb Loading'):
"""
Take the provided tiddlers and inject them into the base_tiddlywiki,
adjusting content for title, subtite, and the various pre and post
head sections of the file.
"""
if tiddlers[0].recipe:
workspace = '/recipes/%s/tiddlers' % encode_name(tiddlers[0].recipe)
else:
workspace = '/bags/%s/tiddlers' % encode_name(tiddlers[0].bag)
browsable_url = server_base_url(self.environ) + workspace
if len(tiddlers) == 1:
default_tiddler = Tiddler('DefaultTiddlers')
default_tiddler.text = '[[' + tiddlers[0].title + ']]'
tiddlers = [tiddlers[0], default_tiddler]
# figure out the content to be pushed into the
# wiki and calculate the title
lines = ''
candidate_title = None
candidate_subtitle = None
markup_tiddlers = MARKUPS.keys()
found_markup_tiddlers = {}
for tiddler in tiddlers:
lines += self._tiddler_as_div(tiddler)
if tiddler.title == 'SiteTitle':
candidate_title = tiddler.text
if tiddler.title == 'SiteSubtitle':
candidate_subtitle = tiddler.text
if tiddler.title in markup_tiddlers:
found_markup_tiddlers[tiddler.title] = tiddler.text
# Turn the title into HTML and then turn it into
# plain text so it is of a form satisfactory to <title>
title = self._determine_title(title, candidate_title, candidate_subtitle)
title = self._plain_textify_string(title)
# load the wiki
wiki = self._get_wiki()
# put the title in place
wiki = self._inject_title(wiki, title)
wiki = self._replace_chunk(wiki, '\n<noscript>\n', '\n</noscript>\n', self._no_script(browsable_url))
# replace the markup bits
if len(found_markup_tiddlers):
for title in found_markup_tiddlers:
start = '\n<!--%s-START-->\n' % MARKUPS[title]
finish = '\n<!--%s-END-->\n' % MARKUPS[title]
wiki = self._replace_chunk(wiki, start, finish, found_markup_tiddlers[title])
# split the wiki into the before store and after store
# sections, put our content in the middle
tiddlystart, tiddlyfinish = wiki.split(SPLITTER, 2)
return tiddlystart + lines + SPLITTER + tiddlyfinish
示例9: _uri
def _uri(environ, *segments, **query_params):
server_prefix = environ['tiddlyweb.config'].get('server_prefix', '')
uri = '/'.join([server_prefix] +
[encode_name(segment) for segment in segments])
if query_params:
uri += '?%s' % ';'.join('%s=%s' % (encode_name(key), encode_name(value))
for key, value in query_params.items())
return uri
示例10: list_tiddlers
def list_tiddlers(self, tiddlers):
"""
Yield the provided :py:class:`tiddlers
<tiddlyweb.model.tiddler.Tiddler>` as HTML.
This is somewhat more complex than the other list methods as
we need to list the tiddler whether it is a revision or not,
if it is in a bag or recipe or if it is a search result.
"""
tiddlers.store = None
title = tiddlers.title
server_prefix = self._server_prefix()
lines = []
container_link = ''
if tiddlers.link:
representation_link = tiddlers.link
elif tiddlers.is_search:
representation_link = '%s/search' % server_prefix
else:
representation_link = ''
for tiddler in tiddlers:
if tiddlers.is_revisions:
line = self._tiddler_revision_info(tiddler)
else:
line = self._tiddler_in_container_info(tiddler)
lines.append(line)
if not tiddlers.is_revisions and not tiddlers.is_search:
if tiddlers.bag:
container_link = ('<div class="baglink">'
'<a href="%s/bags/%s">Bag %s</a></div>'
% (server_prefix, encode_name(tiddlers.bag),
tiddlers.bag))
elif tiddlers.recipe:
container_link = ('<div class="recipelink">'
'<a href="%s/recipes/%s">Recipe %s</a></div>'
% (server_prefix, encode_name(tiddlers.recipe),
tiddlers.recipe))
output = "\n".join(lines)
self.environ['tiddlyweb.title'] = title
return """
%s
%s
%s
<ul id="tiddlers" class="listing">
%s
</ul>
%s
""" % (self._header(),
self._tiddler_list_header(representation_link),
container_link, output, self._footer())
示例11: list_tiddler_revisions
def list_tiddler_revisions(self, tiddler):
url = self.revisions_url % (encode_name(tiddler.bag), encode_name(tiddler.title))
response, content = self._request("GET", url)
if self._is_success(response):
revisions = simplejson.loads(content)
revision_ids = [revision["revision"] for revision in revisions]
# revision_ids.reverse()
return revision_ids
else:
# XXX better error handling than this would be nice
raise NoTiddlerError
示例12: _tiddler_list_info
def _tiddler_list_info(self, tiddler):
"""
Get the basic link info needed for listing tiddlers.
"""
if tiddler.recipe:
representation_link = '%s/recipes/%s/tiddlers' % (
self._server_prefix(), encode_name(tiddler.recipe))
else:
representation_link = '%s/bags/%s/tiddlers' % (
self._server_prefix(), encode_name(tiddler.bag))
return representation_link
示例13: get_auth
def get_auth(username, password):
response, _ = http.request(
"http://0.0.0.0:8080/challenge/cookie_form",
body="user=%s&password=%s" % (encode_name(username), encode_name(password)),
method="POST",
headers={"Content-Type": "application/x-www-form-urlencoded"},
)
assert response.previous["status"] == "303"
user_cookie = response.previous["set-cookie"]
cookie = Cookie.SimpleCookie()
cookie.load(user_cookie)
return cookie["tiddlyweb_user"].value
示例14: _tiddler_etag
def _tiddler_etag(environ, tiddler):
"""
Calculate the ETAG of a tiddler, based on
bag name, tiddler title and revision.
"""
try:
mime_type = web.get_serialize_type(environ)[1]
mime_type = mime_type.split(';', 1)[0].strip()
except (TypeError, AttributeError):
mime_type = tiddler.type or ''
username = environ.get('tiddlyweb.usersign', {}).get('name', '')
digest = sha('%s:%s' % (username, mime_type)).hexdigest()
return str('"%s/%s/%s;%s"' % (web.encode_name(tiddler.bag),
web.encode_name(tiddler.title), tiddler.revision, digest))
示例15: tiddler_as
def tiddler_as(self, tiddler):
"""
Transform the provided tiddler into an HTML
representation of the tiddler packaged in a
DIV. Render the content using the render_wikitext
subsystem. Links to the tiddler in the wiki are
provided.
"""
user = self.environ['tiddlyweb.usersign']
store = self.environ['tiddlyweb.store']
if tiddler.recipe:
list_link = '/recipes/%s/tiddlers' % encode_name(tiddler.recipe)
list_title = 'Tiddlers in Recipe %s' % tiddler.recipe
else:
list_link = '/bags/%s/tiddlers' % encode_name(tiddler.bag)
list_title = 'Tiddlers in Bag %s' % tiddler.bag
try:
store.get(Bag(tiddler.bag)).policy.allows(user, 'manage')
container_policy = True
except PermissionsError:
container_policy = False
if not self.environ['tiddlyweb.space_settings'].get('index', None):
space_link = self._space_link(tiddler)
else:
space_link = ''
try:
modifier_link = space_uri(self.environ, tiddler.modifier)
except AttributeError:
modifier_link = ""
try:
creator_link = space_uri(self.environ, tiddler.creator)
except AttributeError:
creator_link = ""
html = render_wikitext(tiddler, self.environ)
return send_template(self.environ, 'tiddler.html', {
'meta_keywords': ', '.join(tiddler.tags),
'meta_description': tiddler.title,
'title': '%s' % tiddler.title,
'tags': tiddler.tags,
'modifier_link': modifier_link,
'creator_link': creator_link,
'fields': tiddler.fields,
'html': html,
'list_link': list_link,
'list_title': list_title,
'space_link': space_link,
'tiddler': tiddler,
'container_policy': container_policy,
'tiddler_url': tiddler_url(self.environ, tiddler)})