import vampire import time class Old: def __init__(self): self.__time = time.time() def __call__(self, req, arg1=None, arg2=None): return self.__time, "Old.__call__()", arg1, arg2 old = vampire.Instance(Old) class New(object): def __init__(self): self.__time = time.time() def __call__(self, req, arg1=None, arg2=None): return self.__time, "New.__call__()", arg1, arg2 new = vampire.Instance(New)
import vampire import sys config = vampire.loadConfig(__req__, ".vampire") layouts = config.get("Handlers", "layouts_root") layout = vampire.importModule("basic", layouts, __req__) class Template(layout.Template): no_cache = True def renderTemplate(self): def renderModule(node, label): node.label.content = label if hasattr(sys.modules[label], "__file__"): node.path.content = sys.modules[label].__file__ keys = sys.modules.keys() keys.sort() self.template.module.repeat(renderModule, keys) handler_html = vampire.Instance(Template)
import vampire import cgi class Handler: def __init__(self, req): self.__req = req def __call__(self, message=""): if not message: message = "Give Blood!" self.__req.content_type = "text/html" self.__req.send_http_header() self.__req.write("<html><body>") self.__req.write(cgi.escape(message)) self.__req.write("</body></html>") handler_html = vampire.Instance(Handler)