From b94d7960f7ac598760e19179c9ee48be2712ff87 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: 2025年2月10日 10:06:10 -0800 Subject: [PATCH] Remove some dead code for older pythons Change-Id: I9a793e4c352cd40a073326315a6ae144a14de1e0 --- swift/__init__.py | 35 ----------------------------------- swift/common/utils/logs.py | 36 ------------------------------------ 2 files changed, 71 deletions(-) diff --git a/swift/__init__.py b/swift/__init__.py index 0ba983d2eb..b0269c486c 100644 --- a/swift/__init__.py +++ b/swift/__init__.py @@ -14,7 +14,6 @@ # limitations under the License. import os -import sys import gettext import warnings @@ -58,40 +57,6 @@ def gettext_(msg): return _t.gettext(msg) -if (3, 0) <= sys.version_info[:2] <= (3, 5): - # In the development of py3, json.loads() stopped accepting byte strings - # for a while. https://bugs.python.org/issue17909 got fixed for py36, but - # since it was termed an enhancement and not a regression, we don't expect - # any backports. At the same time, it'd be better if we could avoid - # leaving a whole bunch of json.loads(resp.body.decode(...)) scars in the - # code that'd probably persist even *after* we drop support for 3.5 and - # earlier. So, monkey patch stdlib. - import json - if not getattr(json.loads, 'patched_to_decode', False): - class JsonLoadsPatcher(object): - def __init__(self, orig): - self._orig = orig - - def __call__(self, s, **kw): - if isinstance(s, bytes): - # No fancy byte-order mark detection for us; just assume - # UTF-8 and raise a UnicodeDecodeError if appropriate. - s = s.decode('utf8') - return self._orig(s, **kw) - - def __getattribute__(self, attr): - if attr == 'patched_to_decode': - return True - if attr == '_orig': - return super().__getattribute__(attr) - # Pass through all other attrs to the original; among other - # things, this preserves doc strings, etc. - return getattr(self._orig, attr) - - json.loads = JsonLoadsPatcher(json.loads) - del JsonLoadsPatcher - - warnings.filterwarnings('ignore', module='cryptography|OpenSSL', message=( 'Python 2 is no longer supported by the Python core team. ' 'Support for it is now deprecated in cryptography')) diff --git a/swift/common/utils/logs.py b/swift/common/utils/logs.py index b9833635f9..bb88a7ebbb 100644 --- a/swift/common/utils/logs.py +++ b/swift/common/utils/logs.py @@ -257,39 +257,6 @@ class SwiftLogAdapter(logging.LoggerAdapter, object): self.server = server self.warn = self.warning - # There are a few properties needed for py35; see - # - https://bugs.python.org/issue31457 - # - https://github.com/python/cpython/commit/1bbd482 - # - https://github.com/python/cpython/commit/0b6a118 - # - https://github.com/python/cpython/commit/ce9e625 - - def _log(self, level, msg, args, exc_info=None, extra=None, - stack_info=False): - """ - Low-level log implementation, proxied to allow nested logger adapters. - """ - return self.logger._log( - level, - msg, - args, - exc_info=exc_info, - extra=extra, - stack_info=stack_info, - ) - - @property - def manager(self): - return self.logger.manager - - @manager.setter - def manager(self, value): - self.logger.manager = value - - @property - def name(self): - # py3 does this for us already; add it for py2 - return self.logger.name - @property def txn_id(self): if hasattr(self._cls_thread_local, 'txn_id'): @@ -316,9 +283,6 @@ class SwiftLogAdapter(logging.LoggerAdapter, object): def thread_locals(self, value): self.txn_id, self.client_ip = value - def getEffectiveLevel(self): - return self.logger.getEffectiveLevel() - def process(self, msg, kwargs): """ Add extra info to message

AltStyle によって変換されたページ (->オリジナル) /