def read_page(self, file_name, section_name, sec=None): """If sec is not None,sec will be used instead of the section specified by section_name """ with open(self.htmls[file_name]) as f: file_content = f.read() confparser = ConfParser() template = Template(file_content) if sec is None: sec = confparser.read_section(section=section_name) return template.substitute(sec)
def handle_request(self): http_request = self.create_http_request() http_response = HttpResponse() field_storage = cgi.FieldStorage() action = field_storage.getfirst("action").strip() confparser = ConfParser() handler_section = confparser.read_section(section="handler") try: handler_class_name = handler_section[action] except KeyError: handler_class_name = "view.handler.ErrorPageHandler" handler_class = load_class(handler_class_name) handler = handler_class() handler.handle(http_request, http_response) print(http_response)