本文整理汇总了Python中werkzeug.utils.escape函数的典型用法代码示例。如果您正苦于以下问题:Python escape函数的具体用法?Python escape怎么用?Python escape使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了escape函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _make_text_block
def _make_text_block(name, content, content_type=None):
"""Helper function for the builder that creates an XML text block."""
if content_type == "xhtml":
return u'<%s type="xhtml"><div xmlns="%s">%s</div></%s>\n' % (name, XHTML_NAMESPACE, content, name)
if not content_type:
return u"<%s>%s</%s>\n" % (name, escape(content), name)
return u'<%s type="%s">%s</%s>\n' % (name, content_type, escape(content), name)
开发者ID:bryanjos,项目名称:ken,代码行数:7,代码来源:geo_atom.py
示例2: render_summary
def render_summary(self, include_title=True):
"""Render the traceback for the interactive console."""
title = ""
description = ""
frames = []
classes = ["traceback"]
if not self.frames:
classes.append("noframe-traceback")
if include_title:
if self.is_syntax_error:
title = u"Syntax Error"
else:
title = u"Traceback <em>(most recent call last)</em>:"
for frame in self.frames:
frames.append(u"<li%s>%s" % (frame.info and u' title="%s"' % escape(frame.info) or u"", frame.render()))
if self.is_syntax_error:
description_wrapper = u"<pre class=syntaxerror>%s</pre>"
else:
description_wrapper = u"<blockquote>%s</blockquote>"
return SUMMARY_HTML % {
"classes": u" ".join(classes),
"title": title and u"<h3>%s</h3>" % title or u"",
"frames": u"\n".join(frames),
"description": description_wrapper % escape(self.exception),
}
开发者ID:paradoxxxzero,项目名称:werkzeug,代码行数:29,代码来源:tbtools.py
示例3: render_summary
def render_summary(self, include_title=True):
"""Render the traceback for the interactive console."""
title = ''
frames = []
classes = ['traceback']
if not self.frames:
classes.append('noframe-traceback')
if include_title:
if self.is_syntax_error:
title = u'Syntax Error'
else:
title = u'Traceback <em>(most recent call last)</em>:'
for frame in self.frames:
frames.append(u'<li%s>%s' % (
frame.info and u' title="%s"' % escape(frame.info) or u'',
frame.render()
))
if self.is_syntax_error:
description_wrapper = u'<pre class=syntaxerror>%s</pre>'
else:
description_wrapper = u'<blockquote>%s</blockquote>'
return SUMMARY_HTML % {
'classes': u' '.join(classes),
'title': title and u'<h3>%s</h3>' % title or u'',
'frames': u'\n'.join(frames),
'description': description_wrapper % escape(self.exception)
}
开发者ID:DancerMikerLiuNeng,项目名称:tinyFlaskwebToy,代码行数:31,代码来源:tbtools.py
示例4: redirect
def redirect(location, code=302):
"""Return a response object (a WSGI application) that, if called,
redirects the client to the target location. Supported codes are 301,
302, 303, 305, and 307. 300 is not supported because it's not a real
redirect and 304 because it's the answer for a request with a request
with defined If-Modified-Since headers.
.. versionadded:: 0.6
The location can now be a unicode string that is encoded using
the :func:`iri_to_uri` function.
:param location: the location the response should redirect to.
:param code: the redirect status code. defaults to 302.
"""
display_location = escape(location)
if isinstance(location, str):
location = iri_to_uri(location)
response = Response(
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n'
'<title>Redirecting...</title>\n'
'<h1>Redirecting...</h1>\n'
'<p>You should be redirected automatically to target URL: '
'<a href="%s">%s</a>. If not click the link.' %
(escape(location), display_location), code, mimetype="text/html")
response.headers["Location"] = location
return response
开发者ID:robhudson,项目名称:warehouse,代码行数:26,代码来源:utils.py
示例5: xml_add_links
def xml_add_links(cls, data):
""" Returns as many <link> nodes as there are in the datastream. The
links are then removed from the datastream to allow for further
processing.
:param data: the data stream to be rendered as xml.
.. versionchanged:: 0.5
Always return ordered items (#441).
.. versionchanged:: 0.0.6
Links are now properly escaped.
.. versionadded:: 0.0.3
"""
xml = ''
chunk = '<link rel="%s" href="%s" title="%s" />'
links = data.pop(config.LINKS, {})
ordered_links = OrderedDict(sorted(links.items()))
for rel, link in ordered_links.items():
if isinstance(link, list):
xml += ''.join([chunk % (rel, utils.escape(d['href']),
utils.escape(d['title']))
for d in link])
else:
xml += ''.join(chunk % (rel, utils.escape(link['href']),
link['title']))
return xml
开发者ID:iotrl,项目名称:eve,代码行数:28,代码来源:render.py
示例6: test_escape
def test_escape(self):
class Foo(str):
def __html__(self):
return text_type(self)
self.assert_equal(utils.escape(None), '')
self.assert_equal(utils.escape(42), '42')
self.assert_equal(utils.escape('<>'), '<>')
self.assert_equal(utils.escape('"foo"'), '"foo"')
self.assert_equal(utils.escape(Foo('<foo>')), '<foo>')
开发者ID:ArslanRafique,项目名称:werkzeug,代码行数:9,代码来源:utils.py
示例7: render
def render(self):
"""Render a single frame in a traceback."""
return FRAME_HTML % {
"id": self.id,
"filename": escape(self.filename),
"lineno": self.lineno,
"function_name": escape(self.function_name),
"current_line": highlight_or_escape(self.current_line.strip()),
}
开发者ID:paradoxxxzero,项目名称:werkzeug,代码行数:9,代码来源:tbtools.py
示例8: test_escape
def test_escape():
class Foo(str):
def __html__(self):
return text_type(self)
assert utils.escape(None) == ''
assert utils.escape(42) == '42'
assert utils.escape('<>') == '<>'
assert utils.escape('"foo"') == '"foo"'
assert utils.escape(Foo('<foo>')) == '<foo>'
开发者ID:nzavagli,项目名称:UnrealPy,代码行数:9,代码来源:test_utils.py
示例9: render
def render(self):
"""Render a single frame in a traceback."""
return FRAME_HTML % {
'id': self.id,
'filename': escape(self.filename),
'lineno': self.lineno,
'function_name': escape(self.function_name),
'current_line': escape(self.current_line.strip())
}
开发者ID:MostAwesomeDude,项目名称:werkzeug,代码行数:9,代码来源:tbtools.py
示例10: render
def render(self):
"""Render a single frame in a traceback."""
return FRAME_HTML % {
'id': self.id,
'filename': escape(self.filename),
'lineno': self.lineno,
'function_name': escape(self.function_name),
'lines': self.render_line_context(),
}
开发者ID:DancerMikerLiuNeng,项目名称:tinyFlaskwebToy,代码行数:9,代码来源:tbtools.py
示例11: test_escape
def test_escape():
class Foo(str):
def __html__(self):
return text_type(self)
assert utils.escape(None) == ""
assert utils.escape(42) == "42"
assert utils.escape("<>") == "<>"
assert utils.escape('"foo"') == ""foo""
assert utils.escape(Foo("<foo>")) == "<foo>"
开发者ID:pallets,项目名称:werkzeug,代码行数:10,代码来源:test_utils.py
示例12: render
def render(self, mark_lib=True):
"""Render a single frame in a traceback."""
return FRAME_HTML % {
'id': self.id,
'filename': escape(self.filename),
'lineno': self.lineno,
'function_name': escape(self.function_name),
'lines': self.render_line_context(),
"library": "library" if mark_lib and self.is_library else "",
}
开发者ID:gaoussoucamara,项目名称:simens-cerpad,代码行数:10,代码来源:tbtools.py
示例13: generate
def generate(self):
"""Yields pieces of ATOM XML."""
base = ""
if self.xml_base:
base = ' xml:base="%s"' % escape(self.xml_base, True)
yield u"<entry%s>\n" % base
yield u" " + _make_text_block("title", self.title, self.title_type)
yield u" <id>%s</id>\n" % escape(self.id)
yield u" <updated>%s</updated>\n" % format_iso8601(self.updated)
if self.published:
yield u" <published>%s</published>\n" % format_iso8601(self.published)
if self.url:
yield u' <link href="%s" />\n' % escape(self.url)
for author in self.author:
yield u" <author>\n"
yield u" <name>%s</name>\n" % escape(author["name"])
if "uri" in author:
yield u" <uri>%s</uri>\n" % escape(author["uri"])
if "email" in author:
yield u" <email>%s</email>\n" % escape(author["email"])
yield u" </author>\n"
for link in self.links:
yield u" <link %s/>\n" % "".join('%s="%s" ' % (k, escape(link[k], True)) for k in link)
for category in self.categories:
yield u" <category %s/>\n" % "".join('%s="%s" ' % (k, escape(category[k], True)) for k in category)
if self.summary:
yield u" " + _make_text_block("summary", self.summary, self.summary_type)
if self.content:
yield u" " + _make_text_block("content", self.content, self.content_type)
if self.lat_lon:
yield u" <georss:point>%s</georss:point>\n" % escape(" ".join(self.lat_lon))
yield u"</entry>\n"
开发者ID:bryanjos,项目名称:ken,代码行数:32,代码来源:geo_atom.py
示例14: render_object_dump
def render_object_dump(self, items, title, repr=None):
html_items = []
for key, value in items:
html_items.append('<tr><th>%s<td><pre class=repr>%s</pre>' %
(escape(key), value))
if not html_items:
html_items.append('<tr><td><em>Nothing</em>')
return OBJECT_DUMP_HTML % {
'title': escape(title),
'repr': repr and '<pre class=repr>%s</pre>' % repr or '',
'items': '\n'.join(html_items)
}
开发者ID:FakeSherlock,项目名称:Report,代码行数:12,代码来源:repr.py
示例15: _make_text_block
def _make_text_block(name, content, content_type = None):
if content_type == 'xhtml':
return u'<%s type="xhtml"><div xmlns="%s">%s</div></%s>\n' % (name,
XHTML_NAMESPACE,
content,
name)
if not content_type:
return u'<%s>%s</%s>\n' % (name, escape(content), name)
return u'<%s type="%s">%s</%s>\n' % (name,
content_type,
escape(content),
name)
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:12,代码来源:atom.py
示例16: make_report
def make_report():
lat = escape(request.get_json()['lat'])
lng = escape(request.get_json()['lng'])
description = escape(request.get_json()['description'])
category_id = escape(request.get_json()['category_id'])
user_id = session[SESSION_ID_KEY]
category = category_service.get_by_id(category_id)
user = user_service.get_by_id(user_id)
if user is not None and category is not None:
report = report_service.make_report(lat, lng, description, round(time.time()*1000), user, category)
return dumps(report_service.report_to_dict(report))
else:
return redirect(url_for('not_found'))
开发者ID:davidmogar,项目名称:SafePoint,代码行数:13,代码来源:controller.py
示例17: generate
def generate(self):
"""Yields pieces of ATOM XML."""
base = ''
if self.xml_base:
base = ' xml:base="%s"' % escape(self.xml_base, True)
yield u'<entry%s>\n' % base
yield u' ' + _make_text_block('title', self.title, self.title_type)
yield u' <id>%s</id>\n' % escape(self.id)
yield u' <updated>%s</updated>\n' % format_iso8601(self.updated)
if self.published:
yield u' <published>%s</published>\n' % \
format_iso8601(self.published)
if self.url:
yield u' <link href="%s" />\n' % escape(self.url)
for author in self.author:
yield u' <author>\n'
yield u' <name>%s</name>\n' % escape(author['name'])
if 'uri' in author:
yield u' <uri>%s</uri>\n' % escape(author['uri'])
if 'email' in author:
yield u' <email>%s</email>\n' % escape(author['email'])
yield u' </author>\n'
for link in self.links:
yield u' <link %s/>\n' % ''.join('%s="%s" ' % \
(k, escape(link[k], True)) for k in link)
for category in self.categories:
yield u' <category %s/>\n' % ''.join('%s="%s" ' % \
(k, escape(category[k], True)) for k in category)
if self.summary:
yield u' ' + _make_text_block('summary', self.summary,
self.summary_type)
if self.content:
yield u' ' + _make_text_block('content', self.content,
self.content_type)
yield u'</entry>\n'
开发者ID:good1111,项目名称:pj-redis,代码行数:35,代码来源:atom.py
示例18: string_repr
def string_repr(self, obj, limit=70):
buf = ['<span class="string">']
a = repr(obj[:limit])
b = repr(obj[limit:])
if isinstance(obj, text_type) and PY2:
buf.append('u')
a = a[1:]
b = b[1:]
if b != "''":
buf.extend((escape(a[:-1]), '<span class="extended">', escape(b[1:]), '</span>'))
else:
buf.append(escape(a))
buf.append('</span>')
return _add_subclass_info(u''.join(buf), obj, (bytes, text_type))
开发者ID:vipermark7,项目名称:code,代码行数:14,代码来源:repr.py
示例19: render_full
def render_full(self, evalex=False, secret=None):
"""Render the Full HTML page with the traceback info."""
exc = escape(self.exception)
return PAGE_HTML % {
"evalex": evalex and "true" or "false",
"console": "false",
"title": exc,
"exception": exc,
"exception_type": escape(self.exception_type),
"summary": self.render_summary(include_title=False),
"plaintext": self.plaintext,
"plaintext_cs": re.sub("-{2,}", "-", self.plaintext),
"traceback_id": self.id,
"secret": secret,
}
开发者ID:ajones620,项目名称:werkzeug,代码行数:15,代码来源:tbtools.py
示例20: render_full
def render_full(self, evalex=False, lodgeit_url=None):
"""Render the Full HTML page with the traceback info."""
exc = escape(self.exception)
return PAGE_HTML % {
'evalex': evalex and 'true' or 'false',
'console': 'false',
'lodgeit_url': escape(lodgeit_url),
'title': exc,
'exception': exc,
'exception_type': escape(self.exception_type),
'summary': self.render_summary(include_title=False),
'plaintext': self.plaintext,
'plaintext_cs': re.sub('-{2,}', '-', self.plaintext),
'traceback_id': self.id
}
开发者ID:MostAwesomeDude,项目名称:werkzeug,代码行数:15,代码来源:tbtools.py
注:本文中的werkzeug.utils.escape函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论