Dolda2000 GitWeb
/
wrw.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added encoding tools for parameterized MIME headers.
[wrw.git]
/
wrw
/
sp
/
xhtml.py
diff --git
a/wrw/sp/xhtml.py
b/wrw/sp/xhtml.py
index
e78d197
..
eb82f57
100644
(file)
--- a/
wrw/sp/xhtml.py
+++ b/
wrw/sp/xhtml.py
@@
-1,11
+1,11
@@
-import xml.dom.minidom,
StringIO
-import cons as _cons
-import util
+import xml.dom.minidom,
io
+
from .
import cons as _cons
+
from .
import util
dom = xml.dom.minidom.getDOMImplementation()
dom = xml.dom.minidom.getDOMImplementation()
-ns =
u
"http://www.w3.org/1999/xhtml"
-doctype =
u
"-//W3C//DTD XHTML 1.1//EN"
-dtd =
u
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
+ns = "http://www.w3.org/1999/xhtml"
+doctype = "-//W3C//DTD XHTML 1.1//EN"
+dtd = "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
class htmlelement(_cons.element):
def __todoc__(self):
class htmlelement(_cons.element):
def __todoc__(self):
@@
-15,11
+15,11
@@
class htmlelement(_cons.element):
return doc
class xhtmlcontext(_cons.context):
return doc
class xhtmlcontext(_cons.context):
- attrmap = {
u"klass": u
"class"}
+ attrmap = {
"klass":
"class"}
def addattr(self, node, k, v):
def addattr(self, node, k, v):
- k =
unicode
(k)
-
node.attrs[self.attrmap.get(k, k)] = unicode(
v)
+ k =
str
(k)
+
super().addattr(node, self.attrmap.get(k, k),
v)
def cons(ctx=None):
if ctx is None: ctx = xhtmlcontext()
def cons(ctx=None):
if ctx is None: ctx = xhtmlcontext()
@@
-30,7
+30,7
@@
def head(title=None, css=None):
head = h.head
if title:
head(h.title(title))
head = h.head
if title:
head(h.title(title))
- if isinstance(css, str) or isinstance(css,
unicode
):
+ if isinstance(css, str) or isinstance(css,
bytes
):
head(h.link(rel="stylesheet", type="text/css", href=css))
elif css:
for ss in css:
head(h.link(rel="stylesheet", type="text/css", href=css))
elif css:
for ss in css:
@@
-38,20
+38,21
@@
def head(title=None, css=None):
return head
class htmlformatter(util.formatter):
return head
class htmlformatter(util.formatter):
- allowshort =
set([u"br", u"hr", u"img", u"input", u"meta", u"link"])
- def
element(self, el, **extra
):
+ allowshort =
{"br", "hr", "img", "input", "meta", "link"}
+ def
shorttag(self, el
):
if el.name in self.allowshort:
if el.name in self.allowshort:
- super(
htmlformatter, self).element(el, **extra
)
+ super(
).shorttag(el
)
else:
else:
- self.longtag(el, **extra)
+ self.handle(">", el)
+ self.handle("<", el)
-class htmlindenter(util.indenter, htmlformatter):
+class htmlindenter(util.
text
indenter, htmlformatter):
pass
def forreq(req, tree):
# XXX: Use proper Content-Type for clients accepting it.
req.ohead["Content-Type"] = "text/html; charset=utf-8"
pass
def forreq(req, tree):
# XXX: Use proper Content-Type for clients accepting it.
req.ohead["Content-Type"] = "text/html; charset=utf-8"
- buf =
StringIO.String
IO()
+ buf =
io.Bytes
IO()
htmlindenter.output(buf, tree, doctype=(doctype, dtd), charset="utf-8")
ret = buf.getvalue()
req.ohead["Content-Length"] = len(ret)
htmlindenter.output(buf, tree, doctype=(doctype, dtd), charset="utf-8")
ret = buf.getvalue()
req.ohead["Content-Length"] = len(ret)