def read(self): # tested '''create fake file from a tree, adding DTD and charset information and return its value as a string''' self.fix_divs() # fix required when using etree fake_file = StringIO() fake_file.write(DTD + '\n') self.add_charset() try: self.tree.write(fake_file) except Exception: return handle_exception() return fake_file.getvalue()