| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
| 9 |
| 10 |
| 11 |
| 12 |
| 13 |
| 14 |
| 15 |
| 16 |
| 17 |
| 18 |
| 19 |
| 20 |
| 21 |
| 22 |
| 23 |
| 24 |
| 25 |
| 26 |
| 27 |
| 28 |
| 29 |
| 30 |
| 31 |
| 32 |
| 33 |
| 34 |
| 35 |
| 36 |
| 37 |
| 38 |
| 39 |
| 40 |
| 41 |
| 42 |
| 43 |
| 44 |
| 45 |
| 46 |
| 47 |
| 48 |
| 49 |
| 50 |
| 51 |
| 52 |
| 53 |
| 54 |
| 55 |
| 56 |
| 57 |
| 58 |
| 59 |
| 60 | |
""" |
|
|
""" |
from py.xml import Namespace, Tag |
from py.__.xmlobj.visit import SimpleUnicodeVisitor |
|
|
class HtmlVisitor(SimpleUnicodeVisitor): |
|
single = dict([(x, 1) for x in |
('br,img,area,param,col,hr,meta,link,base,' |
'input,frame').split(',')]) |
inline = dict([(x, 1) for x in |
('a abbr acronym b basefont bdo big br cite code dfn em font ' |
'i img input kbd label q s samp select small span strike ' |
'strong sub sup textarea tt u var'.split(' '))]) |
|
|
def repr_attribute(self, attrs, name): |
if name == 'class_': |
value = getattr(attrs, name) |
if value is None: |
return |
return super(HtmlVisitor, self).repr_attribute(attrs, name) |
|
|
def _issingleton(self, tagname): |
return tagname in self.single |
|
|
def _isinline(self, tagname): |
return tagname in self.inline |
|
|
class HtmlTag(Tag): |
def unicode(self, indent=2): |
l = [] |
HtmlVisitor(l.append, indent, shortempty=False).visit(self) |
return u"".join(l) |
|
|
|
|
class html(Namespace): |
__tagclass__ = HtmlTag |
__stickyname__ = True |
__tagspec__ = dict([(x,1) for x in ( |
'a,abbr,acronym,address,applet,area,b,bdo,big,blink,' |
'blockquote,body,br,button,caption,center,cite,code,col,' |
'colgroup,comment,dd,del,dfn,dir,div,dl,dt,em,embed,' |
'fieldset,font,form,frameset,h1,h2,h3,h4,h5,h6,head,html,' |
'i,iframe,img,input,ins,kbd,label,legend,li,link,listing,' |
'map,marquee,menu,meta,multicol,nobr,noembed,noframes,' |
'noscript,object,ol,optgroup,option,p,pre,q,s,script,' |
'select,small,span,strike,strong,style,sub,sup,table,' |
'tbody,td,textarea,tfoot,th,thead,title,tr,tt,u,ul,xmp,' |
'base,basefont,frame,hr,isindex,param,samp,var' |
).split(',') if x]) |
|
|
class Style(object): |
def __init__(self, **kw): |
for x, y in kw.items(): |
x = x.replace('_', '-') |
setattr(self, x, y) |
|
|
|
| |