diff options
author | Inada Naoki <songofacandy@gmail.com> | 2021-04-06 02:18:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-06 02:18:41 (GMT) |
commit | fb78692f2ad5ee4747f13a73943fbf134b637669 (patch) | |
tree | beb9f1abe584a74f281955ead6541cdeeeaa17a8 /Lib/logging | |
parent | f84d5a113680c5a6aaaf9130aed7a34d611748ff (diff) | |
download | cpython-fb78692f2ad5ee4747f13a73943fbf134b637669.zip cpython-fb78692f2ad5ee4747f13a73943fbf134b637669.tar.gz cpython-fb78692f2ad5ee4747f13a73943fbf134b637669.tar.bz2 |
bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25189)
* Fix _sitebuiltins
* Fix test_inspect
* Fix test_interpreters
* Fix test_io
* Fix test_iter
* Fix test_json
* Fix test_linecache
* Fix test_lltrace
* Fix test_logging
* Fix logging
Diffstat (limited to 'Lib/logging')
-rw-r--r-- | Lib/logging/__init__.py | 6 | ||||
-rw-r--r-- | Lib/logging/handlers.py | 7 |
2 files changed, 11 insertions, 2 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 411aa53..555f598 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1150,6 +1150,8 @@ class FileHandler(StreamHandler): self.baseFilename = os.path.abspath(filename) self.mode = mode self.encoding = encoding + if "b" not in mode: + self.encoding = io.text_encoding(encoding) self.errors = errors self.delay = delay # bpo-26789: FileHandler keeps a reference to the builtin open() @@ -2022,8 +2024,10 @@ def basicConfig(**kwargs): filename = kwargs.pop("filename", None) mode = kwargs.pop("filemode", 'a') if filename: - if 'b'in mode: + if 'b' in mode: errors = None + else: + encoding = io.text_encoding(encoding) h = FileHandler(filename, mode, encoding=encoding, errors=errors) else: diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index 867ef4e..b0d5885 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -23,7 +23,7 @@ Copyright (C) 2001-2016 Vinay Sajip. All Rights Reserved. To use, simply 'import logging.handlers' and log away! """ -import logging, socket, os, pickle, struct, time, re +import io, logging, socket, os, pickle, struct, time, re from stat import ST_DEV, ST_INO, ST_MTIME import queue import threading @@ -150,6 +150,8 @@ class RotatingFileHandler(BaseRotatingHandler): # on each run. if maxBytes > 0: mode = 'a' + if "b" not in mode: + encoding = io.text_encoding(encoding) BaseRotatingHandler.__init__(self, filename, mode, encoding=encoding, delay=delay, errors=errors) self.maxBytes = maxBytes @@ -205,6 +207,7 @@ class TimedRotatingFileHandler(BaseRotatingHandler): def __init__(self, filename, when='h', interval=1, backupCount=0, encoding=None, delay=False, utc=False, atTime=None, errors=None): + encoding = io.text_encoding(encoding) BaseRotatingHandler.__init__(self, filename, 'a', encoding=encoding, delay=delay, errors=errors) self.when = when.upper() @@ -442,6 +445,8 @@ class WatchedFileHandler(logging.FileHandler): """ def __init__(self, filename, mode='a', encoding=None, delay=False, errors=None): + if "b" not in mode: + encoding = io.text_encoding(encoding) logging.FileHandler.__init__(self, filename, mode=mode, encoding=encoding, delay=delay, errors=errors) |