Ñò
†°Ic @ sÈ d Z d d k l Z d d k l Z y d d k i i Z Wn" e j
o d d k
i Z n Xd Z d d d „ ƒ YZ e ƒ Z
d e i f d „ ƒ YZ d
e f d „ ƒ YZ d „ Z d
g Z d S( s
Kind of like htmlgen, only much simpler. The only important symbol
that is exported is ``html``.
This builds ElementTree nodes, but with some extra useful methods.
(Open issue: should it use ``ElementTree`` more, and the raw
``Element`` stuff less?)
You create tags with attribute access. I.e., the ``A`` anchor tag is
``html.a``. The attributes of the HTML tag are done with keyword
arguments. The contents of the tag are the non-keyword arguments
(concatenated). You can also use the special ``c`` keyword, passing a
list, tuple, or single tag, and it will make up the contents (this is
useful because keywords have to come after all non-keyword arguments,
which is non-intuitive). Or you can chain them, adding the keywords
with one call, then the body with a second call, like::
>>> print html.a(href='http://yahoo.com')('')
<Yahoo>
Note that strings will be quoted; only tags given explicitly will
remain unquoted.
If the value of an attribute is None, then no attribute
will be inserted. So::
>>> print html.a(href='http://www.yahoo.com', name=None,
... c='Click Here')
Click Here
If the value is None, then the empty string is used. Otherwise str()
is called on the value.
``html`` can also be called, and it will produce a special list from
its arguments, which adds a ``__str__`` method that does ``html.str``
(which handles quoting, flattening these lists recursively, and using
'' for ``None``).
``html.comment`` will generate an HTML comment, like
``html.comment('comment text')`` -- note that it cannot take keyword
arguments (because they wouldn't mean anything).
Examples::
>>> print html.html(
... html.head(html.title("Page Title")),
... html.body(
... bgcolor='#000066',
... text='#ffffff',
... c=[html.h1('Page Title'),
... html.p('Hello world!')],
... ))
Page TitlePage Title
Hello world!
>>> print html.a(href='#top')('return to top')
return to top
iÿÿÿÿ( t
generators( t escapeNs utf-8t _HTMLc B s/ e Z d „ Z d „ Z d „ Z d d „ Z RS( c C sŸ | i d ƒ o
t ‚ n | i ƒ } | i d ƒ o | d } n | i d ƒ d j o | i d d ƒ } n | d j o t t i h ƒ St | h ƒ Sd S( Nt _iÿÿÿÿt __t :t comment( t
startswitht AttributeErrort lowert endswitht findt replacet Elementt ETt Comment( t selft attr( ( s6 /usr/lib/python2.6/site-packages/formencode/htmlgen.pyt __getattr__G s
c G s
t | ƒ S( N( t ElementList( R t args( ( s6 /usr/lib/python2.6/site-packages/formencode/htmlgen.pyt __call__T s c C s. | d j o d St t | ƒ i t ƒ d ƒ S( Nt i ( t NoneR t unicodet encodet default_encoding( R t arg( ( s6 /usr/lib/python2.6/site-packages/formencode/htmlgen.pyt quoteW s
c C s§ t | t ƒ o | S| d j o d St | t ƒ o | i t ƒ St | t t f ƒ o d i t | i | ƒ ƒ St | t
ƒ o t | ƒ St | ƒ i t ƒ Sd S( NR ( t
isinstancet strR R R R t listt tuplet joint mapR
( R R t encoding( ( s6 /usr/lib/python2.6/site-packages/formencode/htmlgen.pyR \ s
N( t __name__t
__module__R R R R R ( ( ( s6 /usr/lib/python2.6/site-packages/formencode/htmlgen.pyR E s
R
c B s, e Z d „ Z d „ Z d „ Z d „ Z RS( c
O sH | i | i | i ƒ } | i d ƒ oO | o t d ƒ ‚ n | d } | d =t | t t f ƒ p
| f } qw n x« | i ƒ D] \ } } | d j o | | =q„ n t
| ƒ | | <| i d ƒ o | | | d <| | =n | i d ƒ d j o' | i
d d ƒ } | | | <| | =q„ q„ W| i i | ƒ | i | _ d } x' | i ƒ D] } | } | i | ƒ qTWxÐ t | ƒ D]Â } | d j o q~n t i | ƒ p… | d j o<