""" $URL: svn+ssh://svn.mems-exchange.org/repos/trunk/qp/fill/html.qpy $ $Id: html.qpy 28351 2006-05-10 17:27:02Z dbinger $ """ from qpy import h8, stringify from urllib import quote as url_quote def htmltag [html] (tag, xml_end=False, css_class=None, **attrs): "<" tag if css_class is not None: attrs['class'] = css_class for (attr, val) in attrs.iteritems(): if val is not None: ' %s="%s"' % (attr, val) if xml_end: " />" else: ">" def href [html] (url, text, title=None, **attrs): htmltag("a", href=url, title=title, **attrs) text "" def dl [html] (tuples, **kwargs): htmltag('dl', **kwargs) for title, description in tuples: if title: '
%s
' % title if description: '
%s
' % description '' def ul [html] (items, **kwargs): htmltag('ul', **kwargs) for item in items: '
  • %s
  • ' % item '' def ol [html] (items, **kwargs): htmltag('ol', **kwargs) for item in items: '
  • %s
  • ' % item '' def nl2br [html] (v): return h8(h8.quote(v).replace("\n", "
    ")) def div [html] (*args, **kwargs): htmltag('div', **kwargs) for arg in args: arg '' def url_with_query(path, **attrs): result = h8(url_quote(stringify(path))) if attrs: result += "?" + h8("&").join([ url_quote(stringify(key)) + "=" + url_quote(stringify(value)) for key, value in attrs.items()]) return result