def js_escape(s): """Escape Javascript code to be embedded in HTML. When embedding Javascript code inside a <script> tag, the ETAGO (i.e. the two character sequence "</") must be escaped to avoid premature ending of the script element. """ # assume the sequence occurs inside a string, use backslash escape s = stringify(s) return htmltext(_ETAGO_PAT.sub(r'<\/', s))
def url_quote(value, fallback=None): """url_quote(value : any [, fallback : string]) -> string Quotes 'value' for use in a URL; see urllib.quote(). If value is None, then the behavior depends on the fallback argument. If it is not supplied then an error is raised. Otherwise, the fallback value is returned unquoted. """ if value is None: if fallback is None: raise ValueError("value is None and no fallback supplied") else: return fallback return urllib.parse.quote(stringify(value))
def url_quote(value, fallback=None): """url_quote(value : any [, fallback : string]) -> string Quotes 'value' for use in a URL; see urllib.quote(). If value is None, then the behavior depends on the fallback argument. If it is not supplied then an error is raised. Otherwise, the fallback value is returned unquoted. """ if value is None: if fallback is None: raise ValueError, "value is None and no fallback supplied" else: return fallback return urllib.quote(stringify(value))
def htmltag(tag, xml_end=False, css_class=None, **attrs): """Create a HTML tag.""" r = ["<%s" % tag] if css_class is not None: attrs['class'] = css_class for (attr, val) in attrs.items(): if val is ValuelessAttr: val = attr if val is not None: r.append(' %s="%s"' % (attr, stringify(htmlescape(val)))) if xml_end: r.append(" />") else: r.append(">") return htmltext("".join(r))
def htmltag(tag, xml_end=False, css_class=None, **attrs): """Create a HTML tag. """ r = ["<%s" % tag] if css_class is not None: attrs['class'] = css_class for (attr, val) in attrs.items(): if val is ValuelessAttr: val = attr if val is not None: r.append(' %s="%s"' % (attr, stringify(htmlescape(val)))) if xml_end: r.append(" />") else: r.append(">") return htmltext("".join(r))