diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2007-01-09 14:50:28 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2007-01-09 14:50:28 (GMT) |
commit | 825b75a053e77c886b799c59653d4cbbb34803d0 (patch) | |
tree | b4ced10af4024c01ff32aa002eb17f00a5d56e19 | |
parent | c9137263d5e0c9892a54a710d8f661b97df7a0ee (diff) | |
download | cpython-825b75a053e77c886b799c59653d4cbbb34803d0.zip cpython-825b75a053e77c886b799c59653d4cbbb34803d0.tar.gz cpython-825b75a053e77c886b799c59653d4cbbb34803d0.tar.bz2 |
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".
-rw-r--r-- | Lib/logging/__init__.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 797fac6e..d178091 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -41,8 +41,8 @@ except ImportError: __author__ = "Vinay Sajip <vinay_sajip@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 @@ class FileHandler(StreamHandler): """ 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 @@ class FileHandler(StreamHandler): 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 #--------------------------------------------------------------------------- |