Merged revisions 60234-60244 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r60234 | gregory.p.smith | 2008-01-24 10:38:26 +0100 (Thu, 24 Jan 2008) | 4 lines

  Fix issue1789: The tutorial contained a misuse of the struct module.

  (also remove an unneeded import struct from test_largefile)
........
  r60237 | vinay.sajip | 2008-01-24 13:37:08 +0100 (Thu, 24 Jan 2008) | 1 line

  Added optional delay argument to FileHandler and subclasses.
........
  r60238 | vinay.sajip | 2008-01-24 13:37:33 +0100 (Thu, 24 Jan 2008) | 1 line

  Added optional delay argument to FileHandler and subclasses.
........
  r60239 | vinay.sajip | 2008-01-24 13:38:30 +0100 (Thu, 24 Jan 2008) | 1 line

  Added documentation for optional delay argument to FileHandler and subclasses.
........
  r60240 | vinay.sajip | 2008-01-24 13:43:33 +0100 (Thu, 24 Jan 2008) | 1 line

  Updated for optional delay argument to FileHandler and subclasses.
........
  r60243 | guido.van.rossum | 2008-01-24 16:53:22 +0100 (Thu, 24 Jan 2008) | 2 lines

  Fi debug turd -- a call accidentally left out.
........
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index 08bebbd..850e3bd 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -51,13 +51,13 @@
     Not meant to be instantiated directly.  Instead, use RotatingFileHandler
     or TimedRotatingFileHandler.
     """
-    def __init__(self, filename, mode, encoding=None):
+    def __init__(self, filename, mode, encoding=None, delay=0):
         """
         Use the specified filename for streamed logging
         """
         if codecs is None:
             encoding = None
-        logging.FileHandler.__init__(self, filename, mode, encoding)
+        logging.FileHandler.__init__(self, filename, mode, encoding, delay)
         self.mode = mode
         self.encoding = encoding
 
@@ -82,7 +82,7 @@
     Handler for logging to a set of files, which switches from one file
     to the next when the current file reaches a certain size.
     """
-    def __init__(self, filename, mode='a', maxBytes=0, backupCount=0, encoding=None):
+    def __init__(self, filename, mode='a', maxBytes=0, backupCount=0, encoding=None, delay=0):
         """
         Open the specified file and use it as the stream for logging.
 
@@ -105,7 +105,7 @@
         """
         if maxBytes > 0:
             mode = 'a' # doesn't make sense otherwise!
-        BaseRotatingHandler.__init__(self, filename, mode, encoding)
+        BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
         self.maxBytes = maxBytes
         self.backupCount = backupCount
 
@@ -154,8 +154,8 @@
     If backupCount is > 0, when rollover is done, no more than backupCount
     files are kept - the oldest ones are deleted.
     """
-    def __init__(self, filename, when='h', interval=1, backupCount=0, encoding=None):
-        BaseRotatingHandler.__init__(self, filename, 'a', encoding)
+    def __init__(self, filename, when='h', interval=1, backupCount=0, encoding=None, delay=0):
+        BaseRotatingHandler.__init__(self, filename, 'a', encoding, delay)
         self.when = when.upper()
         self.backupCount = backupCount
         # Calculate the real rollover interval, which is just the number of
@@ -300,10 +300,13 @@
     This handler is based on a suggestion and patch by Chad J.
     Schroeder.
     """
-    def __init__(self, filename, mode='a', encoding=None):
-        logging.FileHandler.__init__(self, filename, mode, encoding)
-        stat = os.stat(self.baseFilename)
-        self.dev, self.ino = stat[ST_DEV], stat[ST_INO]
+    def __init__(self, filename, mode='a', encoding=None, delay=0):
+        logging.FileHandler.__init__(self, filename, mode, encoding, delay)
+        if not os.path.exists(self.baseFilename):
+            self.dev, self.ino = -1, -1
+        else:
+            stat = os.stat(self.baseFilename)
+            self.dev, self.ino = stat[ST_DEV], stat[ST_INO]
 
     def emit(self, record):
         """
@@ -319,7 +322,7 @@
         else:
             stat = os.stat(self.baseFilename)
             changed = (stat[ST_DEV] != self.dev) or (stat[ST_INO] != self.ino)
-        if changed:
+        if changed and self.stream is not None:
             self.stream.flush()
             self.stream.close()
             self.stream = self._open()