[Python-checkins] python/dist/src/Lib os.py,1.70,1.71

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Tue, 13 May 2003 10:57:25 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv29917

Modified Files:
	os.py 
Log Message:
Add optional 'onerror' argument to os.walk(), to control error
handling.


Index: os.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/os.py,v
retrieving revision 1.70
retrieving revision 1.71
diff -C2 -d -r1.70 -r1.71
*** os.py	25 Apr 2003 07:11:48 -0000	1.70
--- os.py	13 May 2003 17:57:23 -0000	1.71
***************
*** 204,208 ****
  __all__.extend(["makedirs", "removedirs", "renames"])
  
! def walk(top, topdown=True):
      """Directory tree generator.
  
--- 204,208 ----
  __all__.extend(["makedirs", "removedirs", "renames"])
  
! def walk(top, topdown=True, onerror=None):
      """Directory tree generator.
  
***************
*** 233,236 ****
--- 233,243 ----
      generated.
  
+     By default errors from the os.listdir() call are ignored.  If
+     optional arg 'onerror' is specified, it should be a function; it
+     will be called with one argument, an os.error instance.  It can
+     report the error to continue with the walk, or raise the exception
+     to abort the walk.  Note that the filename is available as the
+     filename attribute of the exception object.
+ 
      Caution:  if you pass a relative pathname for top, don't change the
      current working directory between resumptions of walk.  walk never
***************
*** 260,264 ****
          # to earlier import-*.
          names = listdir(top)
!     except error:
          return
  
--- 267,273 ----
          # to earlier import-*.
          names = listdir(top)
!     except error, err:
!         if onerror is not None:
!             onerror(err)
          return
  
***************
*** 275,279 ****
          path = join(top, name)
          if not islink(path):
!             for x in walk(path, topdown):
                  yield x
      if not topdown:
--- 284,288 ----
          path = join(top, name)
          if not islink(path):
!             for x in walk(path, topdown, onerror):
                  yield x
      if not topdown: