예제 #1
0
    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)
예제 #2
0
 def test_encode_iso_does_not_convert_character_into_entities(self):
     self.assertEqual(encoding.encode("á", "iso-8859-1"), b"\xe1")
예제 #3
0
 def test_encode_keeps_input_value(self):
     self.assertEqual(encoding.encode(b"a"), b"a")
예제 #4
0
 def test_encode_iso_converts_character_into_entities(self):
     self.assertEqual(encoding.encode("磨", "iso-8859-1"), b"磨")
예제 #5
0
 def test_encode_converts_input_value(self):
     self.assertEqual(encoding.encode("a"), b"a")