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
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
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')
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'))
def test_default_encoding_works(self): from repoze.folder._compat import text_ result = self._callFUT('abc') self.assertEqual(result, text_(b'abc'))
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)