[Python-checkins] r53304 - python/trunk/Lib/logging/__init__.py

vinay.sajip python-checkins at python.org
Tue Jan 9 15:50:28 CET 2007


Author: vinay.sajip
Date: Tue Jan  9 15:50:28 2007
New Revision: 53304

Modified:
   python/trunk/Lib/logging/__init__.py
Log:
Bug #1627575: Added _open() method to FileHandler which can be used to reopen files. The FileHandler instance now saves the encoding (which can be None) in an attribute called "encoding".

Modified: python/trunk/Lib/logging/__init__.py
==============================================================================
--- python/trunk/Lib/logging/__init__.py	(original)
+++ python/trunk/Lib/logging/__init__.py	Tue Jan  9 15:50:28 2007
@@ -41,8 +41,8 @@
 
 __author__  = "Vinay Sajip <vinay_sajip at red-dove.com>"
 __status__  = "production"
-__version__ = "0.5.0.0"
-__date__    = "08 January 2007"
+__version__ = "0.5.0.1"
+__date__    = "09 January 2007"
 
 #---------------------------------------------------------------------------
 #   Miscellaneous module data
@@ -764,17 +764,15 @@
         """
         Open the specified file and use it as the stream for logging.
         """
-        if codecs is None:
-            encoding = None
-        if encoding is None:
-            stream = open(filename, mode)
-        else:
-            stream = codecs.open(filename, mode, encoding)
-        StreamHandler.__init__(self, stream)
         #keep the absolute path, otherwise derived classes which use this
         #may come a cropper when the current directory changes
+        if codecs is None:
+            encoding = None
         self.baseFilename = os.path.abspath(filename)
         self.mode = mode
+        self.encoding = encoding
+        stream = self._open()
+        StreamHandler.__init__(self, stream)
 
     def close(self):
         """
@@ -784,6 +782,13 @@
         self.stream.close()
         StreamHandler.close(self)
 
+    def _open(self):
+        if self.encoding is None:
+            stream = open(self.baseFilename, self.mode)
+        else:
+            stream = codecs.open(self.baseFilename, self.mode, self.encoding)
+        return stream
+
 #---------------------------------------------------------------------------
 #   Manager classes and functions
 #---------------------------------------------------------------------------


More information about the Python-checkins mailing list