From 028d445cf9b2f1785f1f191f3c8bae8d4f3f4c3e Mon Sep 17 00:00:00 2001 From: idle sign Date: Fri, 1 May 2020 16:12:21 +0700 Subject: [PATCH] Removed OrderedDict. --- uwsgiconf/base.py | 5 +- uwsgiconf/config.py | 9 +- .../contrib/django/uwsgify/admin/realms.py | 126 +++++++++--------- 3 files changed, 66 insertions(+), 74 deletions(-) diff --git a/uwsgiconf/base.py b/uwsgiconf/base.py index 8464788..5051b9b 100644 --- a/uwsgiconf/base.py +++ b/uwsgiconf/base.py @@ -1,4 +1,3 @@ -from collections import OrderedDict from .utils import listify @@ -229,7 +228,7 @@ def handle_plugin_required(val): opts[key] = value def _make_section_like(self): - self._section = type('SectionLike', (object,), {'_opts': OrderedDict()}) + self._section = type('SectionLike', (object,), {'_opts': {}}) def _contribute_to_opts(self, target): target_section = target._section @@ -256,7 +255,7 @@ class ParametrizedValue(OptionsGroup): def __init__(self, *args): self.args = list(args) - self._opts = OrderedDict() + self._opts = {} super(ParametrizedValue, self).__init__(_section=self) def __str__(self): diff --git a/uwsgiconf/config.py b/uwsgiconf/config.py index f2c3793..ee193db 100644 --- a/uwsgiconf/config.py +++ b/uwsgiconf/config.py @@ -1,6 +1,5 @@ import os import sys -from collections import OrderedDict from copy import deepcopy from datetime import datetime from functools import partial @@ -166,8 +165,8 @@ def __init__( self._plugins = embedded_plugins or [] self._section = self - self._options_objects = OrderedDict() - self._opts = OrderedDict() + self._options_objects = {} + self._opts = {} self.name = name or 'uwsgi' self._runtime_dir = runtime_dir or '' @@ -563,7 +562,7 @@ def get_descriptions(cls): descriptions = sorted(descriptions.items(), key=lambda item: item[0].lower()) - return OrderedDict(descriptions) + return dict(descriptions) @classmethod def bootstrap(cls, dsn, allow_shared_sockets=None, **init_kwargs): @@ -735,7 +734,7 @@ def configure_uwsgi(configurator_func): return None configurations = configurator_func() - registry = OrderedDict() + registry = {} if not isinstance(configurations, (list, tuple)): configurations = [configurations] diff --git a/uwsgiconf/contrib/django/uwsgify/admin/realms.py b/uwsgiconf/contrib/django/uwsgify/admin/realms.py index 5d08290..00b409c 100644 --- a/uwsgiconf/contrib/django/uwsgify/admin/realms.py +++ b/uwsgiconf/contrib/django/uwsgify/admin/realms.py @@ -1,4 +1,3 @@ -from collections import OrderedDict from datetime import datetime, timedelta from django.template.defaultfilters import filesizeformat @@ -41,35 +40,35 @@ def get_signals_info(signals): rss, vsz = uwsgi.memory config = uwsgi.config - info_basic = OrderedDict([ - (_('Version'), uwsgi.get_version()), - (_('Hostname'), uwsgi.hostname), - (_('Serving since'), time_started), - (_('Serving for'), datetime.now() - time_started), - (_('Clock'), uwsgi.clock), - (_('Master PID'), uwsgi.master_pid), - (_('Memory (RSS, VSZ)'), '\n'.join((filesizeformat(rss), filesizeformat(vsz)))), - (_('Buffer size'), uwsgi.buffer_size), - (_('Cores'), uwsgi.cores_count), - (_('Workers'), uwsgi.workers_count), - (_('Mules'), config.get('mules', 0)), - (_('Farms'), '\n'.join(map(str, Farm.get_farms()))), - (_('Threads support'), '+' if uwsgi.threads_enabled else '-'), - (_('Current worker'), uwsgi.worker_id), - (_('Requests by worker'), uwsgi.request.id), - (_('Requests total'), uwsgi.request.total_count), - (_('Socket queue size'), uwsgi.get_listen_queue()), - (_('Log size'), get_current_log_size()), - (_('RPC'), '\n'.join(get_rpc_list())), - (_('Post fork hooks'), '\n'.join(map(get_func_name, uwsgi.postfork_hooks.funcs))), - (_('Signals'), '\n'.join(get_signals_info(registry_signals))), - (_('Spoolers'), '\n'.join(map(str, Spooler.get_spoolers()))), - ]) + info_basic = { + _('Version'): uwsgi.get_version(), + _('Hostname'): uwsgi.hostname, + _('Serving since'): time_started, + _('Serving for'): datetime.now() - time_started, + _('Clock'): uwsgi.clock, + _('Master PID'): uwsgi.master_pid, + _('Memory (RSS, VSZ)'): '\n'.join((filesizeformat(rss), filesizeformat(vsz))), + _('Buffer size'): uwsgi.buffer_size, + _('Cores'): uwsgi.cores_count, + _('Workers'): uwsgi.workers_count, + _('Mules'): config.get('mules', 0), + _('Farms'): '\n'.join(map(str, Farm.get_farms())), + _('Threads support'): '+' if uwsgi.threads_enabled else '-', + _('Current worker'): uwsgi.worker_id, + _('Requests by worker'): uwsgi.request.id, + _('Requests total'): uwsgi.request.total_count, + _('Socket queue size'): uwsgi.get_listen_queue(), + _('Log size'): get_current_log_size(), + _('RPC'): '\n'.join(get_rpc_list()), + _('Post fork hooks'): '\n'.join(map(get_func_name, uwsgi.postfork_hooks.funcs)), + _('Signals'): '\n'.join(get_signals_info(registry_signals)), + _('Spoolers'): '\n'.join(map(str, Spooler.get_spoolers())), + } context.update({ 'panels': { '': { - 'rows': OrderedDict(((key, [val]) for key, val in info_basic.items())), + 'rows': dict((key, [val]) for key, val in info_basic.items()), } }, }) @@ -82,7 +81,7 @@ def contribute_onepage_context(self, request, context): context.update({ 'panels': { - '': {'rows': OrderedDict(((key, [val]) for key, val in uwsgi.config.items()))}, + '': {'rows': dict((key, [val]) for key, val in uwsgi.config.items())}, }, }) @@ -94,46 +93,41 @@ def contribute_onepage_context(self, request, context): fromts = datetime.fromtimestamp - info_worker_map = OrderedDict([ - ('id', (_('ID'), None)), - ('pid', (_('PID'), None)), - ('status', (_('Status'), None)), - - ('running_time', (_('Running for'), lambda val: timedelta(microseconds=val))), - ('last_spawn', (_('Spawned at'), lambda val: fromts(val))), - - ('respawn_count', (_('Respawns'), None)), - ('requests', (_('Requests'), None)), - ('delta_requests', (_('Delta requests'), None)), # Used alongside with MAX_REQUESTS - ('exceptions', (_('Exceptions'), None)), - ('signals', (_('Signals'), None)), - - ('rss', (_('RSS'), lambda val: filesizeformat(val))), - ('vsz', (_('VSZ'), lambda val: filesizeformat(val))), - - ('tx', (_('Transmitted'), lambda val: filesizeformat(val))), - ('avg_rt', (_('Avg. response'), lambda val: timedelta(microseconds=val))), - - ('apps', (None, lambda val: iter_items(val, info_app_map))), - ]) - - info_app_map = OrderedDict([ - ('id', (_('ID'), None)), - ('startup_time', (_('Serving since'), None)), - ('interpreter', (_('Interpreter'), None)), - ('modifier1', (_('Modifier 1'), None)), - ('mountpoint', (_('Mountpoint'), None)), - ('callable', (_('Callable'), None)), - ('chdir', (_('Directory'), None)), - ('requests', (_('Requests'), None)), - ('exceptions', (_('Exceptions'), None)), - ]) - - panels = OrderedDict() - info_workers = OrderedDict() + info_worker_map = { + 'id': (_('ID'), None), + 'pid': (_('PID'), None), + 'status': (_('Status'), None), + 'running_time': (_('Running for'), lambda val: timedelta(microseconds=val)), + 'last_spawn': (_('Spawned at'), lambda val: fromts(val)), + 'respawn_count': (_('Respawns'), None), + 'requests': (_('Requests'), None), + 'delta_requests': (_('Delta requests'), None), # Used alongside with MAX_REQUESTS + 'exceptions': (_('Exceptions'), None), + 'signals': (_('Signals'), None), + 'rss': (_('RSS'), lambda val: filesizeformat(val)), + 'vsz': (_('VSZ'), lambda val: filesizeformat(val)), + 'tx': (_('Transmitted'), lambda val: filesizeformat(val)), + 'avg_rt': (_('Avg. response'), lambda val: timedelta(microseconds=val)), + 'apps': (None, lambda val: iter_items(val, info_app_map)), + } + + info_app_map = { + 'id': (_('ID'), None), + 'startup_time': (_('Serving since'), None), + 'interpreter': (_('Interpreter'), None), + 'modifier1': (_('Modifier 1'), None), + 'mountpoint': (_('Mountpoint'), None), + 'callable': (_('Callable'), None), + 'chdir': (_('Directory'), None), + 'requests': (_('Requests'), None), + 'exceptions': (_('Exceptions'), None), + } + + panels = {} + info_workers = {} panels[''] = {'rows': info_workers} - info_apps = OrderedDict() + info_apps = {} def iter_items(info, mapping): @@ -157,7 +151,7 @@ def iter_items(info, mapping): # Get info about applications served by worker, for idx_app, keyname_app, name_app, value_app in value_worker: app_key = f'%s {idx_worker + 1}. %s {idx_app}' % (_('Worker'), _('Application')) - info_apps.setdefault(app_key, OrderedDict())[name_app] = [value_app] + info_apps.setdefault(app_key, {})[name_app] = [value_app] else: info_workers.setdefault(name_worker, []).append(value_worker)