#!/usr/bin/python
"""
"""
import types
def main():
pagina = pagemaker()
result = "risultato"
pagina.set_kind("html")
pagina.set_content(result)
print pagina.build()
class pagemaker:
def __init__(self):
self.content = ""
self.kind = "xml"
self.css = None
self.xslt = None
def set_content(self,contenuto):
"""
the xml documentElement in list or str format
"""
if type(contenuto) in (types.ListType,types.TupleType):
self.content = "\n".join(contenuto)
else:
self.content = contenuto
def set_kind(self,kind):
"html | xml"
self.kind = kind
def set_css(self,css):
self.css = css
def set_xslt(self,xslt):
self.xslt = xslt
def build(self):
if self.kind == "xml":
x= "Content-type:text/xml\n\n"
x+="<?xml version='1.0'?>\n"
if self.css:
x+="<?xml-stylesheet type='text/css' href='%s'?>\n" % self.css
if self.xslt:
x+="<?xml-stylesheet type='text/xsl' href='%s'?>\n" % self.xslt
x+=self.content
elif self.kind== "html":
x= "Content-type:text/html\n\n"
x+="<html charset-encoding='UTF-8'>\n"
x+=self.content
x+="\n</html>"
return x.encode("UTF-8")
if __name__ == "__main__":
main()
|