diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-03-07 12:33:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-07 12:33:21 (GMT) |
commit | 8f6b344d368c15c3fe56c65c2f2776e7766fef55 (patch) | |
tree | 5b87db90a48d67bb3fba2881de4acceef1e5501f /Lib/os.py | |
parent | 8886d5f39286dffa7d9337857b151e7fb4af23fd (diff) | |
download | cpython-8f6b344d368c15c3fe56c65c2f2776e7766fef55.zip cpython-8f6b344d368c15c3fe56c65c2f2776e7766fef55.tar.gz cpython-8f6b344d368c15c3fe56c65c2f2776e7766fef55.tar.bz2 |
bpo-28682: Added support for bytes paths in os.fwalk(). (#489)
Diffstat (limited to 'Lib/os.py')
-rw-r--r-- | Lib/os.py | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -460,16 +460,19 @@ if {open, stat} <= supports_dir_fd and {listdir, stat} <= supports_fd: try: if (follow_symlinks or (st.S_ISDIR(orig_st.st_mode) and path.samestat(orig_st, stat(topfd)))): - yield from _fwalk(topfd, top, topdown, onerror, follow_symlinks) + yield from _fwalk(topfd, top, isinstance(top, bytes), + topdown, onerror, follow_symlinks) finally: close(topfd) - def _fwalk(topfd, toppath, topdown, onerror, follow_symlinks): + def _fwalk(topfd, toppath, isbytes, topdown, onerror, follow_symlinks): # Note: This uses O(depth of the directory tree) file descriptors: if # necessary, it can be adapted to only require O(1) FDs, see issue # #13734. names = listdir(topfd) + if isbytes: + names = map(fsencode, names) dirs, nondirs = [], [] for name in names: try: @@ -504,7 +507,8 @@ if {open, stat} <= supports_dir_fd and {listdir, stat} <= supports_fd: try: if follow_symlinks or path.samestat(orig_st, stat(dirfd)): dirpath = path.join(toppath, name) - yield from _fwalk(dirfd, dirpath, topdown, onerror, follow_symlinks) + yield from _fwalk(dirfd, dirpath, isbytes, + topdown, onerror, follow_symlinks) finally: close(dirfd) |