Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(30846)

Delta Between Two Patch Sets: Lib/os.py

Issue 25994: File descriptor leaks in os.scandir()
Left Patch Set: Created 3 years, 7 months ago
Right Patch Set: Created 3 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 r"""OS routines for NT or Posix depending on what system we're on. 1 r"""OS routines for NT or Posix depending on what system we're on.
2 2
3 This exports: 3 This exports:
4 - all functions from posix, nt or ce, e.g. unlink, stat, etc. 4 - all functions from posix, nt or ce, e.g. unlink, stat, etc.
5 - os.path is either posixpath or ntpath 5 - os.path is either posixpath or ntpath
6 - os.name is either 'posix', 'nt' or 'ce'. 6 - os.name is either 'posix', 'nt' or 'ce'.
7 - os.curdir is a string representing the current directory ('.' or ':') 7 - os.curdir is a string representing the current directory ('.' or ':')
8 - os.pardir is a string representing the parent directory ('..' or '::') 8 - os.pardir is a string representing the parent directory ('..' or '::')
9 - os.sep is the (or a most common) pathname separator ('/' or ':' or '\\') 9 - os.sep is the (or a most common) pathname separator ('/' or ':' or '\\')
10 - os.extsep is the extension separator (always '.') 10 - os.extsep is the extension separator (always '.')
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 if followlinks or not islink(new_path): 431 if followlinks or not islink(new_path):
432 yield from walk(new_path, topdown, onerror, followlinks) 432 yield from walk(new_path, topdown, onerror, followlinks)
433 else: 433 else:
434 # Yield after recursion if going bottom up 434 # Yield after recursion if going bottom up
435 yield top, dirs, nondirs 435 yield top, dirs, nondirs
436 436
437 class _DummyDirEntry: 437 class _DummyDirEntry:
438 def __init__(self, dir, name): 438 def __init__(self, dir, name):
439 self.name = name 439 self.name = name
440 self.path = path.join(dir, name) 440 self.path = path.join(dir, name)
441
441 def is_dir(self): 442 def is_dir(self):
442 return path.isdir(self.path) 443 return path.isdir(self.path)
444
443 def is_symlink(self): 445 def is_symlink(self):
444 return path.islink(self.path) 446 return path.islink(self.path)
445 447
446 class _dummy_scandir: 448 class _dummy_scandir:
447 # listdir-based implementation for bytes patches on Windows 449 # listdir-based implementation for bytes patches on Windows
448 def __init__(self, dir): 450 def __init__(self, dir):
449 self.dir = dir 451 self.dir = dir
450 self.it = iter(listdir(dir)) 452 self.it = iter(listdir(dir))
453
451 def __iter__(self): 454 def __iter__(self):
452 return self 455 return self
456
453 def __next__(self): 457 def __next__(self):
454 return _DummyDirEntry(self.dir, next(self.it)) 458 return _DummyDirEntry(self.dir, next(self.it))
459
455 def __enter__(self): 460 def __enter__(self):
456 return self 461 return self
462
457 def __exit__(self, *args): 463 def __exit__(self, *args):
458 self.it = iter(()) 464 self.it = iter(())
459 465
460 __all__.append("walk") 466 __all__.append("walk")
461 467
462 if {open, stat} <= supports_dir_fd and {listdir, stat} <= supports_fd: 468 if {open, stat} <= supports_dir_fd and {listdir, stat} <= supports_fd:
463 469
464 def fwalk(top=".", topdown=True, onerror=None, *, follow_symlinks=False, dir _fd=None): 470 def fwalk(top=".", topdown=True, onerror=None, *, follow_symlinks=False, dir _fd=None):
465 """Directory tree generator. 471 """Directory tree generator.
466 472
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 return getattr(self._stream, name) 1054 return getattr(self._stream, name)
1049 def __iter__(self): 1055 def __iter__(self):
1050 return iter(self._stream) 1056 return iter(self._stream)
1051 1057
1052 # Supply os.fdopen() 1058 # Supply os.fdopen()
1053 def fdopen(fd, *args, **kwargs): 1059 def fdopen(fd, *args, **kwargs):
1054 if not isinstance(fd, int): 1060 if not isinstance(fd, int):
1055 raise TypeError("invalid fd type (%s, expected integer)" % type(fd)) 1061 raise TypeError("invalid fd type (%s, expected integer)" % type(fd))
1056 import io 1062 import io
1057 return io.open(fd, *args, **kwargs) 1063 return io.open(fd, *args, **kwargs)
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+