Esempio n. 1
0
def path_to_unicode(path):
    """
    Return a path string `path` as a unicode string.
    """
    if isinstance(path, unicode):
        return path
    if TRACE: logger_debug('path_to_unicode:', fsdecode(path))
    return fsdecode(path)
Esempio n. 2
0
def path_to_unicode(path):
    """
    Return a path string `path` as a unicode string.
    """
    if isinstance(path, unicode):
        return path
    if TRACE: logger_debug('path_to_unicode:', fsdecode(path))
    return fsdecode(path)
Esempio n. 3
0
 def scandir_python(path=unicode('.')):
     """Like os.listdir(), but yield DirEntry objects instead of returning
     a list of names.
     """
     if isinstance(path, bytes):
         opendir_path = path
         is_bytes = True
     else:
         opendir_path = path.encode(file_system_encoding)
         is_bytes = False
     dir_p = opendir(opendir_path)
     if not dir_p:
         raise posix_error(path)
     try:
         result = Dirent_p()
         while True:
             entry = Dirent()
             if readdir_r(dir_p, entry, result):
                 raise posix_error(path)
             if not result:
                 break
             name = entry.d_name
             if name not in (b'.', b'..'):
                 if not is_bytes:
                     name = fsdecode(name)
                 yield PosixDirEntry(path, name, entry.d_type,
                                     entry.d_ino)
     finally:
         if closedir(dir_p):
             raise posix_error(path)
Esempio n. 4
0
 def test_identity(self):
     # assert fsdecode(fsencode(x)) == x
     for fn in ('unicode\u0141', 'latin\xe9', 'ascii'):
         try:
             bytesfn = os.fsencode(fn)
         except UnicodeEncodeError:
             continue
         self.assertEqual(os.fsdecode(bytesfn), fn)
Esempio n. 5
0
    def test_identity(self):
        # assert fsdecode(fsencode(x)) == x
        for fn in ('unicode\u0141', 'latin\xe9', 'ascii'):
            try:
                bytesfn = os.fsencode(fn)
            except UnicodeEncodeError:
                continue

            # XXX backport: Ignore bug in future.utils.surrogateescape.replace_surrogate_encode()
            # by treating the below NameError like the above UnicodeEncodeError.
            #
            # Bug: https://github.com/PythonCharmers/python-future/issues/256
            # (This workaround can be removed once that is fixed.)
            except NameError as e:  # pragma: no cover
                if e.message == "global name 'exc' is not defined":
                    continue
                else:
                    raise

            self.assertEqual(os.fsdecode(bytesfn), fn)
Esempio n. 6
0
 def test_decode_binary(self, b):
     self.assertEqual(os.fsdecode(b), real_os.fsdecode(b))
Esempio n. 7
0
 def test_binary_roundtrip(self, b):
     self.assertEqual(os.fsencode(os.fsdecode(b)), b)
Esempio n. 8
0
 def test_text_roundtrip(self, s):
     self.assertEqual(os.fsdecode(os.fsencode(s)), s)
Esempio n. 9
0
 def test_decode_surrogates(self):
     """
     Explicitly decode all the high bytes to surrogates.
     """
     self.assertEqual(os.fsdecode(HIGH_BYTES), HIGH_SURROGATES)
Esempio n. 10
0
 def test_decode_text(self, s):
     self.assertEqual(os.fsdecode(s), real_os.fsdecode(s))
Esempio n. 11
0
 def test_nop(self):
     self.assertEqual(os.fsencode(b'abc\xff'), b'abc\xff')
     self.assertEqual(os.fsdecode('abc\u0141'), 'abc\u0141')
Esempio n. 12
0
 def test_binary_roundtrip(self, b):
     self.assertEqual(os.fsencode(os.fsdecode(b)), b)
Esempio n. 13
0
 def test_text_roundtrip(self, s):
     self.assertEqual(os.fsdecode(os.fsencode(s)), s)
Esempio n. 14
0
 def test_decode_surrogates(self):
     """
     Explicitly decode all the high bytes to surrogates.
     """
     self.assertEqual(os.fsdecode(HIGH_BYTES), HIGH_SURROGATES)
Esempio n. 15
0
 def test_decode_text(self, s):
     self.assertEqual(os.fsdecode(s), real_os.fsdecode(s))
Esempio n. 16
0
 def test_decode_binary(self, b):
     self.assertEqual(os.fsdecode(b), real_os.fsdecode(b))