当前位置: 首页>>代码示例>>Python>>正文


Python html.literal函数代码示例

本文整理汇总了Python中webhelpers2.html.literal函数的典型用法代码示例。如果您正苦于以下问题:Python literal函数的具体用法?Python literal怎么用?Python literal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了literal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 &lt;b&gt; &lt;bing&gt;', 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 &lt;b&gt; &lt;bing&gt;" == 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 &lt;crap&gt;', sub % (lit, unq))
    
    sub = literal('%(lit)s and %(lit)r')
    eq_(u"This string <> and literal(u&#39;This string &lt;&gt;&#39;)", sub % dict(lit=lit))
    sub = literal('%(unq)r and %(unq)s')
    eq_(u"&#39;This has &lt;crap&gt;&#39; and This has &lt;crap&gt;", 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 "&#34;<other>" == '"' + other
     assert "<other>&#34;" == other + '"'
     
     mod = literal("<%s>ello")
     assert "<&lt;H&gt;>ello" == mod % "<H>"
     assert type(mod % "<H>") is literal
     assert HTML("<a>") == "&lt;a&gt;"
     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'&#34;<other>', '"' + other)
    eq_(u'<other>&#34;', other + '"')
    
    mod = literal('<%s>ello')
    eq_(u'<&lt;H&gt;>ello', mod % '<H>')
    assert type(mod % '<H>') is literal
    eq_(HTML('<a>'), '&lt;a&gt;')
    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


注:本文中的webhelpers2.html.literal函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。