- Code: Select all
#!/usr/bin/env python
import string
class header(object):
def __init__(self, content_type="text/html", cache_control="no-cache"):
self.content_type = "Content-type: %s" % content_type
self.cache_control = "Cache-Control: %s" % cache_control
return None
def generate(self):
return "%s\n%s\n\n" % (self.content_type, self.cache_control)
class html(object):
def __init__(self):
self.code = ["<html>"]
return None
def __selector(self, selector=("","")):
valid_types = ["class","id"]
if selector[0] not in valid_types:
return ""
else:
return " %s='%s'" % (selector[0],selector[1])
def write(self, string=str):
self.code.append(string)
return None
def include(self, path=str):
FILE = open(path, "r")
contents = FILE.readlines()
FILE.close()
for item in contents:
new_item = item.strip()
self.write(new_item)
return None
def generate(self):
if self.code[-1] == "</html>": pass
else: self.code.append("</html>")
return string.join(self.code, "")
## >>> Builtin html generators
def head(self, title=str, description="", keywords=[]):
self.write("<head>")
self.write("<title>%s</title>" % title)
self.write("<meta name='description' content='%s'" % description)
self.write("<meta name='keywords' content='")
counter = 1
for item in keywords:
if len(keywords) > 1 and counter < len(keywords):
self.write("%s%s" % (str(item), ", "))
else: self.write(str(item))
counter += 1
self.write("'>")
self.write("<meta name='GENERATOR' content='HBcgi'")
self.write("</head>")
return None
def heading(self, content, weight=6, selector=("","")):
if weight > 6 or weight < 1: raise ValueError, "Weight not in range(1-6)"
real_weight = 7 - weight
self.write("<h%s%s>%s</h%s>" % (str(real_weight), self.__selector(selector), str(content), str(real_weight)))
return None
def introduction(self, content, selector=("","")):
self.write("<p%sstyle='font-style: italic;'>%s</p>" % (self.__selector(selector), str(content)))
return None
def paragraph(self, content, selector=("","")):
self.write("<p%s>%s</p>" % (self.__selector(selector), str(content)))
return None
def code(self, content, selector=("","")):
nl_replaced = str(content).replace("\n","<br />")
self.write("<code%s style='font-family: monospace;'>%s</code>" % (self.__selector(selector), nl_replaced))
return None
def blockquote(self, content, selector=("","")):
self.write("<blockquote%s>%s</blockquote>" % (self.__selector(selector), str(content)))
print header().generate(),
html = html()
html.code("<body>")
html.code("import foo", ("class","code_block")) #<< WHY WONT THIS WORK?
html.write("</body>")
print html.generate()
I really don't have a clue why it keeps raising:
- Code: Select all
TypeError: 'list' object is not callable
Any ideas on what could be causing it? Because it seems like the most random-assed error ever... Much appreciated!
