示例#1
0
def unicodify(name, encoding=None):
    if encoding is None:
        encoding = sysencoding
    try:
        name = text_(name, sysencoding)
    except UnicodeError:
        if encoding in ('utf-8', 'utf8'):
            raise TypeError(
                'Byte string names must be decodeable using the system '
                'encoding of "utf-8" (%s)' % name)
        try:
            name = text_(name, 'utf-8')
        except UnicodeError:
            raise TypeError(
                'Byte string names must be decodeable using either the system '
                'encoding of "%s" or the "utf-8" encoding (%s)' %
                (sysencoding, name))

    return name
示例#2
0
def unicodify(name, encoding=None):
    if encoding is None:
        encoding = sysencoding
    try:
        name = text_(name, sysencoding)
    except UnicodeError:
        if encoding in ('utf-8', 'utf8'):
            raise TypeError(
                'Byte string names must be decodeable using the system '
                'encoding of "utf-8" (%s)' % name
                )
        try:
            name = text_(name, 'utf-8')
        except UnicodeError:
            raise TypeError(
                'Byte string names must be decodeable using either the system '
                'encoding of "%s" or the "utf-8" encoding (%s)' % (
                sysencoding, name)
                )

    return name
示例#3
0
 def test_sysencoding_utf8(self):
     from repoze.folder._compat import text_
     name = text_(b'La Pe\xc3\xb1a', 'utf-8').encode('utf-16')
     self.assertRaises(TypeError, self._callFUT, name, 'utf-8')
示例#4
0
 def test_unicode_works(self):
     from repoze.folder._compat import text_
     result = self._callFUT(text_(b'La Pe\xc3\xb1a', 'utf-8'))
     self.assertEqual(result, text_(b'La Pe\xc3\xb1a', 'utf-8'))
示例#5
0
 def test_default_encoding_works(self):
     from repoze.folder._compat import text_
     result = self._callFUT('abc')
     self.assertEqual(result, text_(b'abc'))
示例#6
0
 def test_unresolveable_unicode_getitem(self):
     from repoze.folder._compat import text_
     name = text_(b'La Pe\xc3\xb1a', 'utf-8').encode('latin-1')
     folder = self._makeOne()
     self.assertRaises(TypeError, folder.__getitem__, name)
示例#7
0
 def test_sysencoding_utf8(self):
     from repoze.folder._compat import text_
     name = text_(b'La Pe\xc3\xb1a', 'utf-8').encode('utf-16')
     self.assertRaises(TypeError, self._callFUT, name, 'utf-8')
示例#8
0
 def test_unicode_works(self):
     from repoze.folder._compat import text_
     result = self._callFUT(text_(b'La Pe\xc3\xb1a', 'utf-8'))
     self.assertEqual(result, text_(b'La Pe\xc3\xb1a', 'utf-8'))
示例#9
0
 def test_default_encoding_works(self):
     from repoze.folder._compat import text_
     result = self._callFUT('abc')
     self.assertEqual(result, text_(b'abc'))
示例#10
0
 def test_unresolveable_unicode_getitem(self):
     from repoze.folder._compat import text_
     name = text_(b'La Pe\xc3\xb1a', 'utf-8').encode('latin-1')
     folder = self._makeOne()
     self.assertRaises(TypeError, folder.__getitem__, name)