Skip to content

Commit 69ab21b

Browse files
committed
os: Use uos.ilistdir() if available.
1 parent 217bb5f commit 69ab21b

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

os/os/__init__.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,24 @@ def makedirs(name, mode=0o777, exist_ok=False):
106106
if e.args[0] != errno_.EEXIST:
107107
raise
108108

109-
def ilistdir(path="."):
110-
dir = opendir_(path)
111-
if not dir:
112-
raise_error()
113-
res = []
114-
dirent_fmt = "LLHB256s"
115-
while True:
116-
dirent = readdir_(dir)
117-
if not dirent:
118-
break
119-
import uctypes
120-
dirent = uctypes.bytes_at(dirent, struct.calcsize(dirent_fmt))
121-
dirent = struct.unpack(dirent_fmt, dirent)
122-
dirent = (dirent[-1].split(b'\0', 1)[0], dirent[-2], dirent[0])
123-
yield dirent
109+
if hasattr(uos, "ilistdir"):
110+
ilistdir = uos.ilistdir
111+
else:
112+
def ilistdir(path="."):
113+
dir = opendir_(path)
114+
if not dir:
115+
raise_error()
116+
res = []
117+
dirent_fmt = "LLHB256s"
118+
while True:
119+
dirent = readdir_(dir)
120+
if not dirent:
121+
break
122+
import uctypes
123+
dirent = uctypes.bytes_at(dirent, struct.calcsize(dirent_fmt))
124+
dirent = struct.unpack(dirent_fmt, dirent)
125+
dirent = (dirent[-1].split(b'\0', 1)[0], dirent[-2], dirent[0])
126+
yield dirent
124127

125128
def listdir(path="."):
126129
is_str = type(path) is not bytes

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy