def test_escaping_newline_tabs(self): """test that we handle all kinds of newline permutations""" dtdsource = '<!ENTITY noupdatesfound.intro "A hard coded newline.\\nAnd tab\\t and a \\r carriage return.">\n' converter = dtd2po.dtd2po() thedtd = dtd.dtdunit() thedtd.parse(dtdsource) thepo = po.pounit() converter.convertstrings(thedtd, thepo) print(thedtd) print(thepo.source) # \n in a dtd should also appear as \n in the PO file assert thepo.source == r"A hard coded newline.\nAnd tab\t and a \r carriage return."
def dtd2po(self, dtdsource, dtdtemplate=None): """helper that converts dtd source to po source without requiring files""" inputfile = BytesIO(dtdsource.encode()) inputdtd = dtd.dtdfile(inputfile) convertor = dtd2po.dtd2po() if dtdtemplate is None: outputpo = convertor.convertstore(inputdtd) else: templatefile = BytesIO(dtdtemplate.encode()) templatedtd = dtd.dtdfile(templatefile) outputpo = convertor.mergestore(templatedtd, inputdtd) return outputpo
def dtd2po(self, dtdsource, dtdtemplate=None): """helper that converts dtd source to po source without requiring files""" inputfile = wStringIO.StringIO(dtdsource) inputdtd = dtd.dtdfile(inputfile) convertor = dtd2po.dtd2po() if dtdtemplate is None: outputpo = convertor.convertstore(inputdtd) else: templatefile = wStringIO.StringIO(dtdtemplate) templatedtd = dtd.dtdfile(templatefile) outputpo = convertor.mergestore(templatedtd, inputdtd) return outputpo