Merge "Remove some dead code for older pythons"

This commit is contained in:
Zuul
2025年02月11日 22:54:32 +00:00
committed by Gerrit Code Review

View File

@@ -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'))

View File

@@ -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
Reference in New Issue
openstack/swift
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.

The note is not visible to the blocked user.