def threads(self): import sys import traceback items = sys._current_frames().items() dumps = [] for thread, frame in items: dumps.append({ "id": str(thread), "info": _get_info(frame), "trace": "\n".join(traceback.format_stack(frame)), }) from webhelpers.html import HTML, literal out = literal() out += str(len(items)) + " threads:\n" for data in dumps: out += HTML.br() out += HTML.a(data["info"], href="#" + data["id"]) for data in dumps: out += HTML.hr() out += HTML.a(data["id"] + ": " + HTML.b(data["info"]), name=data["id"]) out += HTML.p() out += HTML.pre(data["trace"]) return out
def test_html(): a = HTML.a(href='http://mostlysafe" <tag', c="Bad <script> tag") assert u'<a href="http://mostlysafe" <tag">Bad <script> tag</a>' == a img = HTML.img(src="http://some/image.jpg") assert u'<img src="http://some/image.jpg" />' == img br = HTML.br() assert u"<br />" == br
def test_html(): a = HTML.a(href='http://mostlysafe\" <tag', c="Bad <script> tag") eq_(a, '<a href="http://mostlysafe" <tag">Bad <script> tag</a>') img = HTML.img(src='http://some/image.jpg') eq_(img, '<img src="http://some/image.jpg" />') br = HTML.br() eq_('<br />', br)
def test_html(): a = HTML.a(href='http://mostlysafe\" <tag', c="Bad <script> tag") eq_(a, u'<a href="http://mostlysafe" <tag">Bad <script> tag</a>') img = HTML.img(src='http://some/image.jpg') eq_(img, u'<img src="http://some/image.jpg" />') br = HTML.br() eq_(u'<br />', br)
def field( label='', field='', required=False, label_desc='', field_desc='', sub_label='', help='', error='' ): """\ Format a field with a label. ``label`` The label for the field ``field`` The HTML representing the field. If not using ``webhelpers.html.tags``, wrap the HTML in a ``literal()``. ``required`` Can be ``True`` or ``False`` depending on whether the label should be formatted as required or not. By default required fields have an asterix. ``label_desc`` Any text to appear underneath the label, level with ``field_desc`` . ``field_desc`` Any text to appear underneath the field ``sub_label`` Any text to appear immediately beneath the label but above the label_desc. This is useful if the field itself is very large and using label_desc would result in the description of the label being a long way from the label itself. ``help`` Any HTML or JavaScript to appear imediately to the right of the field which could be used to implement a help system on the form ``error`` Any text to appear immediately before the HTML field, usually used for an error message. It should be noted that when used with FormEncode's ``htmlfill`` module, errors appear immediately before the HTML field in the position of the ``error`` argument. No ``<form:error>`` tags are added automatically by this helper because errors are placed there anyway and adding the tags would lead to this helper generating invalid HTML. """ field = error + field if label: label = label + literal(":") output = [] if required: required = HTML.span("*", class_="required") else: required = "" desc = "" if sub_label: desc = HTML.br() + HTML.span(sub_label, class_="small") if help: output.append( HTML.tr(class_="field", c=[ HTML.td(class_="label", valign="top", c=[ required, HTML.label(label), desc), class_="label", valign="top") ] ] )
"""Experimental HTML helpers (UNSTABLE!) HELPERS IN THIS MODULE ARE RELEASED FOR EXPERIMENTATION AND FEEDBACK ONLY. THEY MAY CHANGE OR DISAPPEAR IN A FUTURE VERSION OF WebHelpers. FUNCTIONS APPROVED FOR LONG-TERM SUPPORT WILL BE MOVED TO OTHER MODULES. If you want to use a function defined here in an application, please copy it to the application rather than importing it. """ from webhelpers.html.tags import form as start_form, end_form from webhelpers.html import HTML, literal #from webhelpers.rails import options_for_select NL = literal("\n") BR = HTML.br() + NL def form_start(*k, **p): """\ Start a form the way you would with ``start_form()`` but include the HTML necessary for the use of the ``fields()`` helper. >>> form_start('/action', method='post') literal(u'<form action="/action" method="post"><table>') >>> form_start('/action', method='post', table_class='form') literal(u'<form action="/action" method="post"><table class="form">') """ if p.has_key('table_class'): table_class = p.get('table_class', 'form') del p['table_class'] return start_form(*k,**p) + HTML.table(
# render() and sanitize() are imported from the private module 'render'. from webhelpers.html.render import render, sanitize __all__ = [ "format_paragraphs", "markdown", "nl2br", "render", "sanitize", "textilize", ] _universal_newline_rx = re.compile(R"\r\n|\n|\r") # All types of newline. _paragraph_rx = re.compile(R"\n{2,}") # Paragraph break: 2 or more newlines. br = HTML.br() + "\n" def markdown(text, markdown=None, **kwargs): """Format the text to HTML with Markdown formatting. Markdown is a wiki-like text markup language, originally written by John Gruber for Perl. The helper converts Markdown text to HTML. There are at least two Python implementations of Markdown. Markdown <http://www.freewisdom.org/projects/python-markdown/>`_is the original port, and version 2.x contains extensions for footnotes, RSS, etc. `Markdown2 <http://code.google.com/p/python-markdown2/>`_ is another port which claims to be faster and to handle edge cases better. You can pass the desired Markdown module as the ``markdown``
import re from webhelpers.html import HTML, escape, literal, lit_sub import webhelpers.textile as textile import webhelpers.markdown as _markdown __all__ = [ "markdown", "textilize", "nl2br", "format_paragraphs", ] _universal_newline_rx = re.compile(R"\r\n|\n|\r") # All types of newline. _paragraph_rx = re.compile(R"\n{2,}") # Paragraph break: 2 or more newlines. br = HTML.br() + "\n" def markdown(text, **kwargs): """Format the text to HTML with MarkDown formatting. This function uses the `Python MarkDown library <http://www.freewisdom.org/projects/python-markdown/>`_ which is included with WebHelpers. It does not include extensions due to circular import issues. If you need the footnotes or RSS extensions, use the full Markdown package instead. IMPORTANT: If your source text is untrusted and may contain malicious HTML markup, pass ``safe_mode="escape"`` to escape it, ``safe_mode="replace"`` to replace it with a scolding message, or ``safe_mode="remove"`` to strip it.