def _create_html_module():

    to_str = helpers.to_str
    _escape_table = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }
    _escape_pattern = re.compile(r'[&<>"]')
    _escape_callable = lambda m: _escape_table[m.group(0)]

    def escape_xml(s):
        """Escape '&', '<', '>', '"' into '&amp;', '&lt;', '&gt;', '&quot;'.
        """
        return _escape_pattern.sub(_escape_callable, s)
        #return s.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;').replace('"','&quot;')

    def tagattr(name, expr, value=None, escape=True):
        """return empty string when expr is false value, ' name="value"' when
           value is specified, or ' name="expr"' when value is None.
           ex.
           >>> tagattr('size', 20)
           ' size="20"'
           >>> tagattr('size', 0)
           ''
           >>> tagattr('checked', True, 'checked')
           ' checked="checked"'
           >>> tagattr('checked', False, 'checked')
           ''
           """
        if not expr:
            return ''
        if value is None:
            value = to_str(expr)
        else:
            value = to_str(value)
        if escape:
            value = escape_xml(value)
        return ' %s="%s"' % (name, value)

    def checked(expr):
        """return ' checked="checked"' if expr is true."""
        return expr and ' checked="checked"' or ''
        #return attr('checked', expr, 'checked')

    def selected(expr):
        """return ' selected="selected"' if expr is true."""
        return expr and ' selected="selected"' or ''
        #return attr('selected', expr, 'selected')

    def disabled(expr):
        """return ' disabled="disabled"' if expr is true."""
        return expr and ' disabled="disabled"' or ''
        #return attr('disabled, expr, 'disabled')

    def nl2br(text):
        """replace "\n" to "<br />\n" and return it."""
        if not text:
            return ''
        return text.replace('\n', '<br />\n')

    def text2html(text):
        """(experimental) escape xml characters, replace "\n" to "<br />\n", and return it."""
        if not text:
            return ''
        return nl2br(escape_xml(text).replace('  ', ' &nbsp;'))

    mod = _create_module('tenjin.helpers.html')
    mod._escape_table = _escape_table
    mod.escape_xml = escape_xml
    mod.escape     = escape_xml
    mod.tagattr    = tagattr
    mod.checked    = checked
    mod.selected   = selected
    mod.disabled   = disabled
    mod.nl2br      = nl2br
    mod.text2html  = text2html
    return mod
dataset/ETHPy150Open rst2pdf/rst2pdf/rst2pdf/tenjin.py/_create_html_module/original