From 8f6b344d368c15c3fe56c65c2f2776e7766fef55 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 7 Mar 2017 14:33:21 +0200 Subject: bpo-28682: Added support for bytes paths in os.fwalk(). (#489) --- Lib/os.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'Lib/os.py') diff --git a/Lib/os.py b/Lib/os.py index fa06f3937b..18ec124b29 100644 --- a/Lib/os.py +++ b/Lib/os.py @@ -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) -- cgit v1.2.1