本文整理汇总了Python中tiddlyweb.web.util.encode_name函数的典型用法代码示例。如果您正苦于以下问题:Python encode_name函数的具体用法?Python encode_name怎么用?Python encode_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了encode_name函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:jdlrobson,项目名称:tiddlyweb-plugins,代码行数:7,代码来源:tiddlywebweb.py
示例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
开发者ID:chancejiang,项目名称:tiddlyweb,代码行数:26,代码来源:sendentity.py
示例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)
开发者ID:ingydotnet,项目名称:tiddlyweb,代码行数:27,代码来源:html.py
示例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())
开发者ID:24king,项目名称:tiddlyweb,代码行数:27,代码来源:html.py
示例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)})
开发者ID:carnotip,项目名称:tiddlyspace,代码行数:34,代码来源:htmlserialization.py
示例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)
开发者ID:djswagerman,项目名称:tiddlyweb,代码行数:27,代码来源:html.py
示例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'))
开发者ID:JazzDeben,项目名称:tiddlyweb-xmobile,代码行数:8,代码来源:tiddler.py
示例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
开发者ID:ingydotnet,项目名称:tiddlyweb,代码行数:57,代码来源:wiki.py
示例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
开发者ID:pads,项目名称:tiddlywebplugins.bfw,代码行数:10,代码来源:web.py
示例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())
开发者ID:24king,项目名称:tiddlyweb,代码行数:55,代码来源:html.py
示例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
开发者ID:jdlrobson,项目名称:tiddlyweb-plugins,代码行数:11,代码来源:tiddlywebweb.py
示例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
开发者ID:JazzDeben,项目名称:tiddlyweb-xmobile,代码行数:11,代码来源:html.py
示例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
开发者ID:tiddlyweb,项目名称:tiddlywebplugins.csrf,代码行数:13,代码来源:test_post_validate.py
示例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))
开发者ID:chancejiang,项目名称:tiddlyweb,代码行数:14,代码来源:tiddler.py
示例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)})
开发者ID:pads,项目名称:tiddlyspace,代码行数:50,代码来源:htmlserialization.py
示例16: list_tiddlers
def list_tiddlers(self, tiddlers):
"""
List the tiddlers as html.
"""
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())
开发者ID:FND,项目名称:tiddlyweb,代码行数:49,代码来源:html.py
示例17: _create_tiddlers
def _create_tiddlers(self, title, tiddlers):
"""
Figure out the content to be pushed into the
wiki and calculate the title.
"""
kept_tiddlers = []
window_title = None
candidate_title = None
candidate_subtitle = None
markup_tiddlers = MARKUPS.keys()
found_markup_tiddlers = {}
tiddler_count = 0
for tiddler in tiddlers:
if not self._lazy_eligible(tiddler):
kept_tiddlers.append(tiddler)
tiddler_title = tiddler.title
if tiddler_title == 'WindowTitle':
window_title = tiddler.text
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
tiddler_count += 1
if tiddler_count == 1:
default_tiddler = Tiddler('DefaultTiddlers', '')
default_tiddler.tags = ['excludeLists']
default_tiddler.text = '[[' + tiddler.title + ']]'
kept_tiddlers.append(default_tiddler)
browsable_url = None
try:
if tiddler.recipe:
workspace = ('/recipes/%s/tiddlers'
% encode_name(tiddler.recipe))
else:
workspace = '/bags/%s/tiddlers' % encode_name(tiddler.bag)
browsable_url = server_base_url(self.environ) + workspace
except UnboundLocalError:
pass # tiddler is not set because tiddlers was empty
# 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, window_title, candidate_title,
candidate_subtitle)
return browsable_url, kept_tiddlers, title, found_markup_tiddlers
开发者ID:cdent,项目名称:lazytiddlywebwiki,代码行数:49,代码来源:serialization.py
示例18: list_tiddlers
def list_tiddlers(self, tiddlers):
"""
List the tiddlers as html.
"""
title = tiddlers.title
server_prefix = self._server_prefix()
lines = []
representation_link = ''
bag_link = ''
for tiddler in tiddlers:
if not representation_link:
representation_link = self._tiddler_list_info(tiddler)
if tiddlers.is_revisions:
line = self._tiddler_revision_info(tiddler)
else:
line = self._tiddler_in_container_info(tiddler)
lines.append(line)
# If we were able to load the tiddler revisions there is at
# least one revision, so tiddler.title is defined here.
if tiddlers.is_revisions:
representation_link += '/%s/revisions' % encode_name(
tiddler.title)
if tiddlers.is_search:
representation_link = '%s/search' % server_prefix
try:
routing_args = self.environ.get('wsgiorg.routing_args')[1]
except (TypeError, IndexError, KeyError):
routing_args = {}
if 'bag_name' in routing_args and not 'tiddler_name' in routing_args:
bag_name = routing_args['bag_name']
bag_name = urllib.unquote(bag_name)
bag_name = unicode(bag_name, 'utf-8')
bag_link = ('<div class="baglink"><a href="%s/bags/%s">'
'Bag %s</a></div>' % (server_prefix,
encode_name(bag_name), bag_name))
output = "\n".join(lines)
self.environ['tiddlyweb.title'] = title
return """
%s
%s
<ul id="tiddlers" class="listing">
%s
</ul>
""" % (self._tiddler_list_header(representation_link), bag_link, output)
开发者ID:chancejiang,项目名称:tiddlyweb,代码行数:49,代码来源:html.py
示例19: render
def render(tiddler, environ):
"""
Render TiddlyWiki wikitext in the provided
tiddler to HTML. The provided path helps
set paths in wikilinks correctly.
"""
server_prefix = environ.get("tiddlyweb.config", {}).get("server_prefix", "")
if tiddler.recipe:
path = "recipes/%s/tiddlers" % encode_name(tiddler.recipe)
elif tiddler.bag:
path = "bags/%s/tiddlers" % encode_name(tiddler.bag)
else:
path = ""
html = wikitext_to_wikklyhtml("%s/" % server_prefix, path, tiddler.text, environ)
return unicode(html, "utf-8")
开发者ID:tiddlyweb,项目名称:tiddlywebplugins.wikklytextrender,代码行数:15,代码来源:wikklytextrender.py
示例20: test_invalid_cookie
def test_invalid_cookie():
"""
Test that an invalid/old cookie causes a new cookie to be sent
"""
store = get_store(config)
hostname = "foo.0.0.0.0:8080"
user = User(u"f\u00F6o")
user.set_password("foobar")
store.put(user)
user_cookie = get_auth(u"f\u00F6o", "foobar")
time = datetime.utcnow() - timedelta(hours=3)
time = time.strftime("%Y%m%d%H")
cookie = "csrf_token=%s:%s:%s" % (
time,
encode_name(user.usersign),
sha("%s:%s:%s:%s" % (encode_name(user.usersign), time, hostname, config["secret"])).hexdigest(),
)
response, _ = http.request(
"http://foo.0.0.0.0:8080/status",
method="GET",
headers={"Cookie": 'tiddlyweb_user="%s"; %s' % (user_cookie, cookie)},
)
assert "csrf_token" in response["set-cookie"]
cookie = "csrf_token=adiudh9389wefnf98"
response, _ = http.request(
"http://foo.0.0.0.0:8080/status",
method="GET",
headers={"Cookie": 'tiddlyweb_user="%s"; %s' % (user_cookie, cookie)},
)
assert "csrf_token" in response["set-cookie"]
user2 = User("bar")
user2.set_password("foobar")
store.put(user2)
user2_cookie = get_auth("bar", "foobar")
response, _ = http.request(
"http://foo.0.0.0.0:8080/status",
method="GET",
headers={"Cookie": 'tiddlyweb_user="%s"; %s' % (user2_cookie, cookie)},
)
assert "csrf_token" in response.get("set-cookie", "")
开发者ID:tiddlyweb,项目名称:tiddlywebplugins.csrf,代码行数:48,代码来源:test_post_validate.py
注:本文中的tiddlyweb.web.util.encode_name函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论