# HG changeset patch # User RhodeCode Admin # Date 2024-06-13 19:30:11 # Node ID 2e534b16f6bedc672a35ebc3511c4b0802eb4dee # Parent 2f6a1e33c4b22e75d58e9dcc8ee188f7f55b439b core: refactor of vendor lib to easier sync with vcsserver diff --git a/rhodecode/lib/_vendor/jsonlogger/__init__.py b/rhodecode/lib/_vendor/jsonlogger/__init__.py --- a/rhodecode/lib/_vendor/jsonlogger/__init__.py +++ b/rhodecode/lib/_vendor/jsonlogger/__init__.py @@ -11,9 +11,9 @@ import importlib from inspect import istraceback from collections import OrderedDict -from rhodecode.lib.logging_formatter import _inject_req_id, ExceptionAwareFormatter -from rhodecode.lib.ext_json import sjson as json +from ...logging_formatter import _inject_req_id, ExceptionAwareFormatter +from ...ext_json import sjson as json ZERO = timedelta(0) HOUR = timedelta(hours=1) @@ -78,7 +78,7 @@ class JsonEncoder(json.JSONEncoder): return str(obj) try: - return super(JsonEncoder, self).default(obj) + return super().default(obj) except TypeError: try: @@ -194,7 +194,7 @@ class JsonFormatter(ExceptionAwareFormat def serialize_log_record(self, log_record): """Returns the final representation of the log record.""" - return "%s%s" % (self.prefix, self.jsonify_log_record(log_record)) + return "{}{}".format(self.prefix, self.jsonify_log_record(log_record)) def format(self, record): """Formats a log record and serializes to json""" diff --git a/rhodecode/lib/_vendor/redis_lock/__init__.py b/rhodecode/lib/_vendor/redis_lock/__init__.py --- a/rhodecode/lib/_vendor/redis_lock/__init__.py +++ b/rhodecode/lib/_vendor/redis_lock/__init__.py @@ -102,7 +102,7 @@ class NotExpirable(RuntimeError): pass -class Lock(object): +class Lock: """ A Lock context manager implemented via redis SETNX/BLPOP. """ diff --git a/rhodecode/lib/_vendor/statsd/__init__.py b/rhodecode/lib/_vendor/statsd/__init__.py --- a/rhodecode/lib/_vendor/statsd/__init__.py +++ b/rhodecode/lib/_vendor/statsd/__init__.py @@ -1,5 +1,3 @@ - - import logging from .stream import TCPStatsClient, UnixSocketStatsClient # noqa diff --git a/rhodecode/lib/_vendor/statsd/base.py b/rhodecode/lib/_vendor/statsd/base.py --- a/rhodecode/lib/_vendor/statsd/base.py +++ b/rhodecode/lib/_vendor/statsd/base.py @@ -1,5 +1,3 @@ - - import re import random from collections import deque @@ -31,7 +29,7 @@ def normalize_tags(tag_list): return _normalize_tags_with_cache(tuple(tag_list)) -class StatsClientBase(object): +class StatsClientBase: """A Base class for various statsd clients.""" def close(self): @@ -73,7 +71,7 @@ class StatsClientBase(object): def incr(self, stat, count=1, rate=1, tags=None): """Increment a stat by `count`.""" - self._send_stat(stat, '%s|c' % count, rate, tags) + self._send_stat(stat, f'{count}|c', rate, tags) def decr(self, stat, count=1, rate=1, tags=None): """Decrement a stat by `count`.""" @@ -87,18 +85,18 @@ class StatsClientBase(object): return with self.pipeline() as pipe: pipe._send_stat(stat, '0|g', 1) - pipe._send_stat(stat, '%s|g' % value, 1) + pipe._send_stat(stat, f'{value}|g', 1) else: prefix = '+' if delta and value >= 0 else '' - self._send_stat(stat, '%s%s|g' % (prefix, value), rate, tags) + self._send_stat(stat, f'{prefix}{value}|g', rate, tags) def set(self, stat, value, rate=1): """Set a set value.""" - self._send_stat(stat, '%s|s' % value, rate) + self._send_stat(stat, f'{value}|s', rate) def histogram(self, stat, value, rate=1, tags=None): """Set a histogram""" - self._send_stat(stat, '%s|h' % value, rate, tags) + self._send_stat(stat, f'{value}|h', rate, tags) def _send_stat(self, stat, value, rate, tags=None): self._after(self._prepare(stat, value, rate, tags)) @@ -110,10 +108,10 @@ class StatsClientBase(object): if rate < 1: if random.random() > rate: return - value = '%s|@%s' % (value, rate) + value = f'{value}|@{rate}' if self._prefix: - stat = '%s.%s' % (self._prefix, stat) + stat = f'{self._prefix}.{stat}' res = '%s:%s%s' % ( stat, diff --git a/rhodecode/lib/_vendor/statsd/stream.py b/rhodecode/lib/_vendor/statsd/stream.py --- a/rhodecode/lib/_vendor/statsd/stream.py +++ b/rhodecode/lib/_vendor/statsd/stream.py @@ -1,5 +1,3 @@ - - import socket from .base import StatsClientBase, PipelineBase diff --git a/rhodecode/lib/_vendor/statsd/timer.py b/rhodecode/lib/_vendor/statsd/timer.py --- a/rhodecode/lib/_vendor/statsd/timer.py +++ b/rhodecode/lib/_vendor/statsd/timer.py @@ -1,5 +1,3 @@ - - import functools from time import perf_counter as time_now @@ -11,7 +9,7 @@ def safe_wraps(wrapper, *args, **kwargs) return functools.wraps(wrapper, *args, **kwargs) -class Timer(object): +class Timer: """A context manager/decorator for statsd.timing().""" def __init__(self, client, stat, rate=1, tags=None, use_decimals=True, auto_send=True): diff --git a/rhodecode/lib/_vendor/statsd/udp.py b/rhodecode/lib/_vendor/statsd/udp.py --- a/rhodecode/lib/_vendor/statsd/udp.py +++ b/rhodecode/lib/_vendor/statsd/udp.py @@ -1,5 +1,3 @@ - - import socket from .base import StatsClientBase, PipelineBase @@ -8,7 +6,7 @@ from .base import StatsClientBase, Pipel class Pipeline(PipelineBase): def __init__(self, client): - super(Pipeline, self).__init__(client) + super().__init__(client) self._maxudpsize = client._maxudpsize def _send(self): diff --git a/rhodecode/lib/logging_formatter.py b/rhodecode/lib/logging_formatter.py --- a/rhodecode/lib/logging_formatter.py +++ b/rhodecode/lib/logging_formatter.py @@ -141,7 +141,7 @@ class ColorFormatter(ExceptionAwareForma """ Changes record's levelname to use with COLORS enum """ - def_record = super(ColorFormatter, self).format(record) + def_record = super().format(record) levelname = record.levelname start = COLOR_SEQ % (COLORS[levelname])