Exemple #1
0
    def test_unescape_surrogates(self):
        if compat.PY2:
            self.skipTest('surrogateescape is not supported in Python 2')

        test_values = [b'', b'a', b'\xc3\xa3\xff\xf6\0\x00\n', b'a\n\\0']
        actual = [unescape(t, errors='surrogateescape') for t in test_values]
        expected = [u'', u'a', u'ã\udcff\udcf6\x00\x00\n', u'a\n\x00']
        self.assertListEqual(actual, expected)
Exemple #2
0
    def test_reverse_surrogates(self):
        # What's stored in the database:
        expected = [b'', b'a', b'\xc3\xa3\xff\x55\xf6\0\x00\x45\0\n']

        # What comes over the wire:
        test_values = [b'', b'a', b'\xc3\xa3\xff\x55\xf6\0\x00\x45\\0\n']

        escaped = [unescape(t, errors='surrogateescape') for t in test_values]
        actual = [t.encode('utf-8', errors='surrogateescape') for t in escaped]
        self.assertListEqual(actual, expected)
Exemple #3
0
 def test_unescape(self):
     test_values = [b'', b'a', b'\xff']
     actual = [unescape(t) for t in test_values]
     self.assertListEqual(actual, ['', 'a', '\ufffd'])
Exemple #4
0
 def test_unescape_surrogates(self):
     test_values = [b'', b'a', b'\xc3\xa3\xff\xf6\0\x00\n', b'a\n\\0']
     actual = [unescape(t, errors='surrogateescape') for t in test_values]
     expected = ['', 'a', 'ã\udcff\udcf6\x00\x00\n', 'a\n\x00']
     self.assertListEqual(actual, expected)
Exemple #5
0
 def test_unescape(self):
     test_values = [b'', b'a', b'\xff']
     actual = [unescape(t) for t in test_values]
     assert actual == ['', 'a', '�']
 def test_unescape(self):
     test_values = [b'', b'a', b'\xff']
     actual = [unescape(t) for t in test_values]
     assert actual == [u'', u'a', u'\ufffd']