本文整理汇总了Python中webhelpers2.html.literal函数的典型用法代码示例。如果您正苦于以下问题:Python literal函数的具体用法?Python literal怎么用?Python literal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了literal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __str__
def __str__(self):
if self.static:
value = ''
for (v,l) in self.options:
if v == self.value:
value = l
return self.as_static(value)
options = []
for val, label in self.options:
selected = ''
if self.value and self.value == val:
selected = 'selected="selected"'
options.append( '<option value="%s" %s>%s</option>' %
(escape(val), selected, escape(label) ))
html = literal( input_select_template.format(
name = escape(self.name), label = escape(self.label),
value = escape(self.value),
options = '\n'.join(options),
multiple = 'multiple="multiple"' if self.multiple else '',
class_label = 'col-md-%d control-label' % self.offset,
class_value = 'col-md-%d' % self.size,
class_input = 'form-control',
extra_control = literal(self.extra_control) if self.extra_control else '',
))
return self.div_wrap(html)
开发者ID:trmznt,项目名称:rhombus,代码行数:26,代码来源:tags.py
示例2: new
def new(self):
""" create new model object """
schema = self.context.schema.bind(db_session=self.context.db_session)
form = Form(schema, buttons=('add',))
resources = form.get_widget_resources()
js_resources = resources['js']
css_resources = resources['css']
js_links = [self.request.static_url(r) for r in js_resources]
css_links = [self.request.static_url(r) for r in css_resources]
js_tags = [literal('<script type="text/javascript" src="%s"></script>' % link)
for link in js_links]
css_tags = [literal('<link rel="stylesheet" href="%s"/>' % link)
for link in css_links]
resource_tags = js_tags + css_tags
if self.request.method == 'POST':
controls = self.request.params.items()
try:
params = form.validate(controls)
item = self.context.add(params)
del self.request.matchdict['traverse']
location = self.request.resource_url(
self.context,
route_name=self.request.matched_route.name,
route_kw=self.request.matchdict)
return HTTPFound(location=location)
except ValidationFailure as e:
return dict(form=e.render(), resource_tags=resource_tags)
return dict(form=form.render(), resource_tags=resource_tags)
开发者ID:rebeccaframework,项目名称:rebecca.app.admin,代码行数:31,代码来源:views.py
示例3: test_lit_re
def test_lit_re():
lit = literal('This is a <string>')
unlit = 'This is also a <string>'
result = lit_sub(r'<str', literal('<b'), lit)
eq_(u'This is a <bing>', escape(result))
result = lit_sub(r'a <str', 'a <b> <b', unlit)
eq_(u'This is also a <b> <bing>', escape(result))
开发者ID:aodag,项目名称:WebHelpers2,代码行数:9,代码来源:test_html.py
示例4: test_lit_sub
def test_lit_sub(self):
lit = literal("This is a <string>")
unlit = "This is also a <string>"
result = lit_sub(r"<str", literal("<b"), lit)
assert "This is a <bing>" == escape(result)
result = lit_sub(r"a <str", "a <b> <b", unlit)
assert "This is also a <b> <bing>" == escape(result)
开发者ID:jManji,项目名称:Trivia,代码行数:9,代码来源:test_html.py
示例5: render_body
def render_body(self, request):
if self.body_format == 'html':
return literal(self.body)
elif self.body_format == 'md':
photos = self.photos
return literal(markdown(
self.body,
extensions=[ImageSetExtension(request, photos)]))
else:
return self.body
开发者ID:storborg,项目名称:sidecar,代码行数:10,代码来源:collection.py
示例6: test_literal_dict
def test_literal_dict():
lit = literal(u'This string <>')
unq = 'This has <crap>'
sub = literal('%s and %s')
eq_(u'This string <> and This has <crap>', sub % (lit, unq))
sub = literal('%(lit)s and %(lit)r')
eq_(u"This string <> and literal(u'This string <>')", sub % dict(lit=lit))
sub = literal('%(unq)r and %(unq)s')
eq_(u"'This has <crap>' and This has <crap>", sub % dict(unq=unq))
开发者ID:aodag,项目名称:WebHelpers2,代码行数:10,代码来源:test_html.py
示例7: handle_match
def handle_match(matchobj):
all = matchobj.group()
before, prefix, link, after = matchobj.group(1, 2, 3, 4)
if re.match(r'<a\s', before, re.I):
return all
text = literal(prefix + link)
if prefix == "www.":
prefix = "http://www."
a_options = dict(href_attrs)
a_options['href'] = literal(prefix + link)
return literal(before) + HTML.a(text, **a_options) + literal(after)
开发者ID:aodag,项目名称:WebHelpers2,代码行数:11,代码来源:tools.py
示例8: label
def label(value, **kwargs):
"""
Return a label tag
>>> print(label('My label', for_='fieldname'))
<label for="fieldname">My label</label>
"""
if "for_" in kwargs:
kwargs["for"] = kwargs.pop("for_")
return tag("label", open=True, **kwargs) + literal(value) + literal("</label>")
开发者ID:smurfix,项目名称:formalchemy,代码行数:11,代码来源:helpers.py
示例9: test_literal
def test_literal(self):
lit = literal("This string <>")
other = literal("<other>")
assert "This string <><other>" == lit + other
assert type(lit + other) is literal
assert ""<other>" == '"' + other
assert "<other>"" == other + '"'
mod = literal("<%s>ello")
assert "<<H>>ello" == mod % "<H>"
assert type(mod % "<H>") is literal
assert HTML("<a>") == "<a>"
assert type(HTML("<a>")) is literal
开发者ID:jManji,项目名称:Trivia,代码行数:14,代码来源:test_html.py
示例10: test_literal
def test_literal():
lit = literal(u'This string <>')
other = literal(u'<other>')
eq_(u'This string <><other>', lit + other)
assert type(lit + other) is literal
eq_(u'"<other>', '"' + other)
eq_(u'<other>"', other + '"')
mod = literal('<%s>ello')
eq_(u'<<H>>ello', mod % '<H>')
assert type(mod % '<H>') is literal
eq_(HTML('<a>'), '<a>')
assert type(HTML('<a>')) is literal
开发者ID:aodag,项目名称:WebHelpers2,代码行数:14,代码来源:test_html.py
示例11: auto_link
def auto_link(text, link="all", **href_attrs):
"""
Turn all urls and email addresses into clickable links.
``link``
Used to determine what to link. Options are "all",
"email_addresses", or "urls"
``href_attrs``
Additional attributes for generated <a> tags.
Example::
>>> auto_link("Go to http://www.planetpython.com and say hello to [email protected]")
literal(u'Go to <a href="http://www.planetpython.com">http://www.planetpython.com</a> and say hello to <a href="mailto:[email protected]">[email protected]</a>')
"""
if not text:
return literal(u"")
text = escape(text)
if link == "all":
return _auto_link_urls(_auto_link_email_addresses(text), **href_attrs)
elif link == "email_addresses":
return _auto_link_email_addresses(text)
else:
return _auto_link_urls(text, **href_attrs)
开发者ID:aodag,项目名称:WebHelpers2,代码行数:26,代码来源:tools.py
示例12: test_stylesheet_link_tag
def test_stylesheet_link_tag(self):
eq_(literal(u'<link href="/dir/file.css" media="all" rel="stylesheet" type="text/css" />'),
stylesheet_link('/dir/file.css', media='all'))
eq_('<link href="style.css" media="all" rel="stylesheet" type="text/css" />',
stylesheet_link('style.css', media='all'))
eq_('<link href="/random.styles" media="screen" rel="stylesheet" type="text/css" />\n<link href="/css/stylish.css" media="screen" rel="stylesheet" type="text/css" />',
stylesheet_link('/random.styles', '/css/stylish.css'))
开发者ID:aodag,项目名称:WebHelpers2,代码行数:7,代码来源:test_tags.py
示例13: stylesheet_link
def stylesheet_link(*urls, **attrs):
"""Return CSS link tags for the specified stylesheet URLs.
``urls`` should be the exact URLs desired. A previous version of this
helper added magic prefixes; this is no longer the case.
Examples::
>>> stylesheet_link('/stylesheets/style.css')
literal(u'<link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />')
>>> stylesheet_link('/stylesheets/dir/file.css', media='all')
literal(u'<link href="/stylesheets/dir/file.css" media="all" rel="stylesheet" type="text/css" />')
"""
if "href" in attrs:
raise TypeError("keyword arg 'href' not allowed")
attrs.setdefault("rel", "stylesheet")
attrs.setdefault("type", "text/css")
attrs.setdefault("media", "screen")
tags = []
for url in urls:
tag = HTML.tag("link", href=url, **attrs)
tags.append(tag)
return literal('\n').join(tags)
开发者ID:lxrave,项目名称:WebHelpers2,代码行数:25,代码来源:tags.py
示例14: javascript_link
def javascript_link(*urls, **attrs):
"""Return script include tags for the specified javascript URLs.
``urls`` should be the exact URLs desired. A previous version of this
helper added magic prefixes; this is no longer the case.
Specify the keyword argument ``defer=True`` to enable the script
defer attribute.
Examples::
>>> print javascript_link('/javascripts/prototype.js', '/other-javascripts/util.js')
<script src="/javascripts/prototype.js" type="text/javascript"></script>
<script src="/other-javascripts/util.js" type="text/javascript"></script>
>>> print javascript_link('/app.js', '/test/test.1.js')
<script src="/app.js" type="text/javascript"></script>
<script src="/test/test.1.js" type="text/javascript"></script>
"""
tags = []
for url in urls:
tag = HTML.tag("script", "", type="text/javascript", src=url, **attrs)
tags.append(tag)
return literal("\n").join(tags)
开发者ID:lxrave,项目名称:WebHelpers2,代码行数:25,代码来源:tags.py
示例15: table_column_headings
def table_column_headings(self):
headings = []
for col in self.grid.iter_columns('html'):
headings.append(self.table_th(col))
th_str = '\n'.join(headings)
th_str = reindent(th_str, 12)
return literal(th_str)
开发者ID:level12,项目名称:webgrid,代码行数:7,代码来源:renderers.py
示例16: table_tr_output
def table_tr_output(self, cells, row_hah):
# do some formatting so that the source code is properly indented
tds_str = u'\n'.join(cells)
tds_str = reindent(tds_str, 12)
tds_str = u'\n{0}\n '.format(tds_str)
return _HTML.tr(literal(tds_str), **row_hah)
开发者ID:level12,项目名称:webgrid,代码行数:7,代码来源:renderers.py
示例17: test_literal_dict
def test_literal_dict(self):
lit = literal("This string <>")
unq = "This has <crap>"
sub = literal("%s and %s")
assert "This string <> and This has <crap>", sub % (lit == unq)
sub = literal("%(lit)s and %(lit)r")
b = "This string <> and literal(u'This string <>')"
if six.PY3:
b = b.replace( "(u", "(" ) # Delete 'u' string prefix.
assert sub % dict(lit=lit) == b
sub = literal("%(unq)r and %(unq)s")
b = "u'This has <crap>' and This has <crap>"
if six.PY3:
b = b[1:] # Delete 'u' string prefix.
assert sub % dict(unq=unq) == b
开发者ID:jManji,项目名称:Trivia,代码行数:16,代码来源:test_html.py
示例18: test_hidden_fields_from_dict
def test_hidden_fields_from_dict(self):
tag = form("/submit", hidden_fields={'foo': 'bar'})
assert tag == literal(
'<form action="/submit" method="post">'
'<div style="display:none">\n'
'<input name="foo" type="hidden" value="bar" />\n'
'</div>\n')
开发者ID:jManji,项目名称:Trivia,代码行数:7,代码来源:test_tags.py
示例19: table_totals
def table_totals(self, rownum, record, label, numrecords):
row_hah = self.table_tr_styler(rownum, record)
row_hah.class_ += 'totals'
# get the <td>s for this row
cells = []
colspan = 0
firstcol = True
for col in self.grid.iter_columns('html'):
if col.key not in list(self.grid.subtotal_cols.keys()):
if firstcol:
colspan += 1
else:
cells.append(_HTML.td(literal(' ')))
continue
if firstcol:
bufferval = ngettext('{label} ({num} record):',
'{label} ({num} records):',
numrecords,
label=label)
buffer_hah = HTMLAttributes(
colspan=colspan,
class_='totals-label'
)
if colspan:
cells.append(_HTML.td(bufferval, **buffer_hah))
firstcol = False
colspan = 0
cells.append(self.table_td(col, record))
return self.table_tr_output(cells, row_hah)
开发者ID:level12,项目名称:webgrid,代码行数:31,代码来源:renderers.py
示例20: _legacy_highlight
def _legacy_highlight(text, phrase, highlighter, flags):
"""WebHelpers 0.6 style highlight with deprecated ``highlighter arg."""
warnings.warn("the ``highlighter`` argument is deprecated",
DeprecationWarning)
pat = "(%s)" % re.escape(phrase)
rx = re.compile(pat, flags)
highlighter = literal(highlighter)
return lit_sub(rx, highlighter, text)
开发者ID:aodag,项目名称:WebHelpers2,代码行数:8,代码来源:tools.py
注:本文中的webhelpers2.html.literal函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论