def write(self, filename, records): path = os.path.dirname(filename) if not os.path.isdir(path): os.makedirs(path) content = self._format_file(records) content = html.unescape(content) content = content.replace(PRESERVECIRC, "\\^") # converterá a entidades, os caracteres utf-8 que não tem # correspondencia em iso-8859-1 content = encoding.encode(content, "iso-8859-1") content = encoding.decode(content, "iso-8859-1") try: fs_utils.write_file(filename, content, 'iso-8859-1') except (UnicodeError, IOError, OSError) as e: logger.error("Nao foi possivel escrever o arquivo %s: %s", filename, e)
def test_encode_iso_does_not_convert_character_into_entities(self): self.assertEqual(encoding.encode("á", "iso-8859-1"), b"\xe1")
def test_encode_keeps_input_value(self): self.assertEqual(encoding.encode(b"a"), b"a")
def test_encode_iso_converts_character_into_entities(self): self.assertEqual(encoding.encode("磨", "iso-8859-1"), b"磨")
def test_encode_converts_input_value(self): self.assertEqual(encoding.encode("a"), b"a")