From ad8b1d81d59b9d80fe36c67dfccf47eeec24fffa Mon Sep 17 00:00:00 2001 From: trhr Date: Sun, 9 Feb 2020 19:52:10 -0600 Subject: [PATCH 1/9] django.utils.safestring.SafeBytes - Unused since Django 2.0. --- evennia/utils/dbserialize.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/evennia/utils/dbserialize.py b/evennia/utils/dbserialize.py index b3e55d1ca6..27fc43e1a1 100644 --- a/evennia/utils/dbserialize.py +++ b/evennia/utils/dbserialize.py @@ -28,11 +28,12 @@ except ImportError: from pickle import dumps, loads from django.core.exceptions import ObjectDoesNotExist from django.contrib.contenttypes.models import ContentType -from django.utils.safestring import SafeString, SafeBytes +from django.utils.safestring import SafeString from evennia.utils.utils import uses_database, is_iter, to_str, to_bytes from evennia.utils import logger -__all__ = ("to_pickle", "from_pickle", "do_pickle", "do_unpickle", "dbserialize", "dbunserialize") +__all__ = ("to_pickle", "from_pickle", "do_pickle", + "do_unpickle", "dbserialize", "dbunserialize") PICKLE_PROTOCOL = 2 @@ -116,13 +117,15 @@ def _init_globals(): global _FROM_MODEL_MAP, _TO_MODEL_MAP, _SESSION_HANDLER, _IGNORE_DATETIME_MODELS if not _FROM_MODEL_MAP: _FROM_MODEL_MAP = defaultdict(str) - _FROM_MODEL_MAP.update(dict((c.model, c.natural_key()) for c in ContentType.objects.all())) + _FROM_MODEL_MAP.update(dict((c.model, c.natural_key()) + for c in ContentType.objects.all())) if not _TO_MODEL_MAP: from django.conf import settings _TO_MODEL_MAP = defaultdict(str) _TO_MODEL_MAP.update( - dict((c.natural_key(), c.model_class()) for c in ContentType.objects.all()) + dict((c.natural_key(), c.model_class()) + for c in ContentType.objects.all()) ) _IGNORE_DATETIME_MODELS = [] for src_key, dst_key in settings.ATTRIBUTE_STORED_MODEL_RENAME: @@ -185,7 +188,8 @@ class _SaverMutable(object): ) self._db_obj.value = self else: - logger.log_err("_SaverMutable %s has no root Attribute to save to." % self) + logger.log_err( + "_SaverMutable %s has no root Attribute to save to." % self) def _convert_mutables(self, data): """converts mutables to Saver* variants and assigns ._parent property""" @@ -201,7 +205,8 @@ class _SaverMutable(object): return dat elif dtype == dict: dat = _SaverDict(_parent=parent) - dat._data.update((key, process_tree(val, dat)) for key, val in item.items()) + dat._data.update((key, process_tree(val, dat)) + for key, val in item.items()) return dat elif dtype == set: dat = _SaverSet(_parent=parent) @@ -549,7 +554,7 @@ def to_pickle(data): def process_item(item): """Recursive processor and identification of data""" dtype = type(item) - if dtype in (str, int, float, bool, bytes, SafeString, SafeBytes): + if dtype in (str, int, float, bool, bytes, SafeString): return item elif dtype == tuple: return tuple(process_item(val) for val in item) @@ -577,7 +582,8 @@ def to_pickle(data): except TypeError: return item except Exception: - logger.log_error(f"The object {item} of type {type(item)} could not be stored.") + logger.log_error( + f"The object {item} of type {type(item)} could not be stored.") raise return process_item(data) @@ -609,7 +615,7 @@ def from_pickle(data, db_obj=None): def process_item(item): """Recursive processor and identification of data""" dtype = type(item) - if dtype in (str, int, float, bool, bytes, SafeString, SafeBytes): + if dtype in (str, int, float, bool, bytes, SafeString): return item elif _IS_PACKED_DBOBJ(item): # this must be checked before tuple @@ -638,7 +644,7 @@ def from_pickle(data, db_obj=None): def process_tree(item, parent): """Recursive processor, building a parent-tree from iterable data""" dtype = type(item) - if dtype in (str, int, float, bool, bytes, SafeString, SafeBytes): + if dtype in (str, int, float, bool, bytes, SafeString): return item elif _IS_PACKED_DBOBJ(item): # this must be checked before tuple From ce95961663e9745ac26183259e7ab346516da6e7 Mon Sep 17 00:00:00 2001 From: trhr Date: Sun, 9 Feb 2020 19:54:20 -0600 Subject: [PATCH 2/9] The smart_text() and force_text() aliases (since Django 2.0) of smart_str() and force_str() are deprecated --- evennia/utils/picklefield.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/evennia/utils/picklefield.py b/evennia/utils/picklefield.py index c2b5abb98a..50408c5949 100644 --- a/evennia/utils/picklefield.py +++ b/evennia/utils/picklefield.py @@ -43,7 +43,7 @@ from django.forms.fields import CharField from django.forms.widgets import Textarea from pickle import loads, dumps -from django.utils.encoding import force_text +from django.utils.encoding import force_str DEFAULT_PROTOCOL = 4 @@ -210,10 +210,10 @@ class PickledObjectField(models.Field): """ Returns the default value for this field. - The default implementation on models.Field calls force_text + The default implementation on models.Field calls force_str on the default, which means you can't set arbitrary Python objects as the default. To fix this, we just return the value - without calling force_text on it. Note that if you set a + without calling force_str on it. Note that if you set a callable as a default, the field will still call it. It will *not* try to pickle and encode it. @@ -267,13 +267,13 @@ class PickledObjectField(models.Field): """ if value is not None and not isinstance(value, PickledObject): - # We call force_text here explicitly, so that the encoded string + # We call force_str here explicitly, so that the encoded string # isn't rejected by the postgresql_psycopg2 backend. Alternatively, # we could have just registered PickledObject with the psycopg # marshaller (telling it to store it like it would a string), but # since both of these methods result in the same value being stored, # doing things this way is much easier. - value = force_text(dbsafe_encode(value, self.compress, self.protocol)) + value = force_str(dbsafe_encode(value, self.compress, self.protocol)) return value def value_to_string(self, obj): From 090157979b79a577982d2b0a0b32084a4b774abc Mon Sep 17 00:00:00 2001 From: trhr Date: Sun, 9 Feb 2020 19:55:49 -0600 Subject: [PATCH 3/9] =?UTF-8?q?django.utils.translation.ugettext(),=20uget?= =?UTF-8?q?text=5Flazy(),=20ugettext=5Fnoop(),=20ungettext(),=20and=20unge?= =?UTF-8?q?ttext=5Flazy()=20are=20deprecated=20in=20favor=20of=20the=20fun?= =?UTF-8?q?ctions=20that=20they=E2=80=99re=20aliases=20for:=20django.utils?= =?UTF-8?q?.translation.gettext(),=20gettext=5Flazy(),=20gettext=5Fnoop(),?= =?UTF-8?q?=20ngettext(),=20and=20ngettext=5Flazy().?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- evennia/accounts/accounts.py | 2 +- evennia/commands/cmdhandler.py | 2 +- evennia/commands/cmdset.py | 2 +- evennia/commands/cmdsethandler.py | 2 +- evennia/comms/channelhandler.py | 2 +- evennia/locks/lockhandler.py | 2 +- evennia/objects/objects.py | 2 +- evennia/scripts/scripthandler.py | 2 +- evennia/scripts/scripts.py | 2 +- evennia/server/initial_setup.py | 2 +- evennia/server/server.py | 2 +- evennia/server/serversession.py | 2 +- evennia/server/sessionhandler.py | 2 +- evennia/utils/evmenu.py | 2 +- evennia/utils/utils.py | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/evennia/accounts/accounts.py b/evennia/accounts/accounts.py index f1bc45acf6..f3217e88ea 100644 --- a/evennia/accounts/accounts.py +++ b/evennia/accounts/accounts.py @@ -37,7 +37,7 @@ from evennia.scripts.scripthandler import ScriptHandler from evennia.commands.cmdsethandler import CmdSetHandler from evennia.utils.optionhandler import OptionHandler -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from random import getrandbits __all__ = ("DefaultAccount",) diff --git a/evennia/commands/cmdhandler.py b/evennia/commands/cmdhandler.py index 8ccbcbae93..6f8f247a72 100644 --- a/evennia/commands/cmdhandler.py +++ b/evennia/commands/cmdhandler.py @@ -48,7 +48,7 @@ from evennia.comms.channelhandler import CHANNELHANDLER from evennia.utils import logger, utils from evennia.utils.utils import string_suggestions -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ _IN_GAME_ERRORS = settings.IN_GAME_ERRORS diff --git a/evennia/commands/cmdset.py b/evennia/commands/cmdset.py index 5bb3ec8d28..f124bbbb06 100644 --- a/evennia/commands/cmdset.py +++ b/evennia/commands/cmdset.py @@ -27,7 +27,7 @@ Set theory. """ from weakref import WeakKeyDictionary -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from evennia.utils.utils import inherits_from, is_iter __all__ = ("CmdSet",) diff --git a/evennia/commands/cmdsethandler.py b/evennia/commands/cmdsethandler.py index e855d551e9..395c9c2ba3 100644 --- a/evennia/commands/cmdsethandler.py +++ b/evennia/commands/cmdsethandler.py @@ -72,7 +72,7 @@ from evennia.utils import logger, utils from evennia.commands.cmdset import CmdSet from evennia.server.models import ServerConfig -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ __all__ = ("import_cmdset", "CmdSetHandler") diff --git a/evennia/comms/channelhandler.py b/evennia/comms/channelhandler.py index feea9f6e33..98e28786a0 100644 --- a/evennia/comms/channelhandler.py +++ b/evennia/comms/channelhandler.py @@ -27,7 +27,7 @@ from django.conf import settings from evennia.commands import cmdset, command from evennia.utils.logger import tail_log_file from evennia.utils.utils import class_from_module -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ # we must late-import these since any overloads are likely to # themselves be using these classes leading to a circular import. diff --git a/evennia/locks/lockhandler.py b/evennia/locks/lockhandler.py index 22f5844e31..ac8c85abc8 100644 --- a/evennia/locks/lockhandler.py +++ b/evennia/locks/lockhandler.py @@ -107,7 +107,7 @@ to any other identifier you can use. import re from django.conf import settings from evennia.utils import logger, utils -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ __all__ = ("LockHandler", "LockException") diff --git a/evennia/objects/objects.py b/evennia/objects/objects.py index d980b88303..25731923e6 100644 --- a/evennia/objects/objects.py +++ b/evennia/objects/objects.py @@ -31,7 +31,7 @@ from evennia.utils.utils import ( list_to_string, to_str, ) -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ _INFLECT = inflect.engine() _MULTISESSION_MODE = settings.MULTISESSION_MODE diff --git a/evennia/scripts/scripthandler.py b/evennia/scripts/scripthandler.py index d2298a7ce2..d924636f8c 100644 --- a/evennia/scripts/scripthandler.py +++ b/evennia/scripts/scripthandler.py @@ -9,7 +9,7 @@ from evennia.scripts.models import ScriptDB from evennia.utils import create from evennia.utils import logger -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ class ScriptHandler(object): diff --git a/evennia/scripts/scripts.py b/evennia/scripts/scripts.py index 42bb1c8797..2f9bb5d5e2 100644 --- a/evennia/scripts/scripts.py +++ b/evennia/scripts/scripts.py @@ -8,7 +8,7 @@ ability to run timers. from twisted.internet.defer import Deferred, maybeDeferred from twisted.internet.task import LoopingCall from django.core.exceptions import ObjectDoesNotExist -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from evennia.typeclasses.models import TypeclassBase from evennia.scripts.models import ScriptDB from evennia.scripts.manager import ScriptManager diff --git a/evennia/server/initial_setup.py b/evennia/server/initial_setup.py index 8f7fd3300f..e0845c0859 100644 --- a/evennia/server/initial_setup.py +++ b/evennia/server/initial_setup.py @@ -9,7 +9,7 @@ Everything starts at handle_setup() import time from django.conf import settings -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from evennia.accounts.models import AccountDB from evennia.server.models import ServerConfig from evennia.utils import create, logger diff --git a/evennia/server/server.py b/evennia/server/server.py index 1c1783bef1..2093b5b88c 100644 --- a/evennia/server/server.py +++ b/evennia/server/server.py @@ -38,7 +38,7 @@ from evennia.utils import logger from evennia.comms import channelhandler from evennia.server.sessionhandler import SESSIONS -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ _SA = object.__setattr__ diff --git a/evennia/server/serversession.py b/evennia/server/serversession.py index 6ae0ec4b63..2443758b12 100644 --- a/evennia/server/serversession.py +++ b/evennia/server/serversession.py @@ -23,7 +23,7 @@ _ObjectDB = None _ANSI = None # i18n -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ # Handlers for Session.db/ndb operation diff --git a/evennia/server/sessionhandler.py b/evennia/server/sessionhandler.py index 1bf43746d6..0d099d6d30 100644 --- a/evennia/server/sessionhandler.py +++ b/evennia/server/sessionhandler.py @@ -67,7 +67,7 @@ PSTATUS = chr(18) # ping server or portal status SRESET = chr(19) # server shutdown in reset mode # i18n -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ _SERVERNAME = settings.SERVERNAME _MULTISESSION_MODE = settings.MULTISESSION_MODE diff --git a/evennia/utils/evmenu.py b/evennia/utils/evmenu.py index 0bc5b37475..ccf2840f91 100644 --- a/evennia/utils/evmenu.py +++ b/evennia/utils/evmenu.py @@ -187,7 +187,7 @@ _CMD_NOINPUT = cmdhandler.CMD_NOINPUT # Return messages # i18n -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ _ERR_NOT_IMPLEMENTED = _( "Menu node '{nodename}' is either not implemented or " "caused an error. Make another choice." diff --git a/evennia/utils/utils.py b/evennia/utils/utils.py index 49c8af1e7b..53fd73de42 100644 --- a/evennia/utils/utils.py +++ b/evennia/utils/utils.py @@ -27,7 +27,7 @@ from collections import defaultdict, OrderedDict from twisted.internet import threads, reactor from django.conf import settings from django.utils import timezone -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.apps import apps from evennia.utils import logger From ce0a012e518781acd33259df9e20b7317fb8262c Mon Sep 17 00:00:00 2001 From: trhr Date: Sun, 9 Feb 2020 19:58:21 -0600 Subject: [PATCH 4/9] =?UTF-8?q?The=20django.db.backends.postgresql=5Fpsyco?= =?UTF-8?q?pg2=20module=20is=20deprecated=20in=20favor=20of=20django.db.ba?= =?UTF-8?q?ckends.postgresql.=20It=E2=80=99s=20been=20an=20alias=20since?= =?UTF-8?q?=20Django=201.9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis/postgresql_settings.py | 2 +- evennia/settings_default.py | 2 +- evennia/typeclasses/migrations/0010_delete_old_player_tables.py | 2 +- evennia/utils/picklefield.py | 2 +- evennia/utils/utils.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis/postgresql_settings.py b/.travis/postgresql_settings.py index 292cb9cc70..c12927af3a 100644 --- a/.travis/postgresql_settings.py +++ b/.travis/postgresql_settings.py @@ -40,7 +40,7 @@ SERVERNAME = "testing_mygame" DATABASES = { "default": { - "ENGINE": "django.db.backends.postgresql_psycopg2", + "ENGINE": "django.db.backends.postgresql", "NAME": "evennia", "USER": "evennia", "PASSWORD": "password", diff --git a/evennia/settings_default.py b/evennia/settings_default.py index b2a06e328e..5ecafb75b5 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -245,7 +245,7 @@ IN_GAME_ERRORS = True # ENGINE - path to the the database backend. Possible choices are: # 'django.db.backends.sqlite3', (default) # 'django.db.backends.mysql', -# 'django.db.backends.postgresql_psycopg2', +# 'django.db.backends.postgresql', # 'django.db.backends.oracle' (untested). # NAME - database name, or path to the db file for sqlite3 # USER - db admin (unused in sqlite3) diff --git a/evennia/typeclasses/migrations/0010_delete_old_player_tables.py b/evennia/typeclasses/migrations/0010_delete_old_player_tables.py index 0732f0fe99..32e1f80923 100644 --- a/evennia/typeclasses/migrations/0010_delete_old_player_tables.py +++ b/evennia/typeclasses/migrations/0010_delete_old_player_tables.py @@ -27,7 +27,7 @@ def _drop_table(db_cursor, table_name): db_cursor.execute("SET FOREIGN_KEY_CHECKS=0;") db_cursor.execute("DROP TABLE {table};".format(table=table_name)) db_cursor.execute("SET FOREIGN_KEY_CHECKS=1;") - elif _ENGINE == "postgresql_psycopg2": + elif _ENGINE == "postgresql": db_cursor.execute("ALTER TABLE {table} DISABLE TRIGGER ALL;".format(table=table_name)) db_cursor.execute("DROP TABLE {table};".format(table=table_name)) db_cursor.execute("ALTER TABLE {table} ENABLE TRIGGER ALL;".format(table=table_name)) diff --git a/evennia/utils/picklefield.py b/evennia/utils/picklefield.py index 50408c5949..084fc6d638 100644 --- a/evennia/utils/picklefield.py +++ b/evennia/utils/picklefield.py @@ -268,7 +268,7 @@ class PickledObjectField(models.Field): """ if value is not None and not isinstance(value, PickledObject): # We call force_str here explicitly, so that the encoded string - # isn't rejected by the postgresql_psycopg2 backend. Alternatively, + # isn't rejected by the postgresql backend. Alternatively, # we could have just registered PickledObject with the psycopg # marshaller (telling it to store it like it would a string), but # since both of these methods result in the same value being stored, diff --git a/evennia/utils/utils.py b/evennia/utils/utils.py index 53fd73de42..cc191fdd53 100644 --- a/evennia/utils/utils.py +++ b/evennia/utils/utils.py @@ -1036,7 +1036,7 @@ def uses_database(name="sqlite3"): shortcut to having to use the full backend name. Args: - name (str): One of 'sqlite3', 'mysql', 'postgresql_psycopg2' + name (str): One of 'sqlite3', 'mysql', 'postgresql' or 'oracle'. Returns: From 308818bd5d2d6270cba229e606e501ac41bf4e6a Mon Sep 17 00:00:00 2001 From: trhr Date: Sun, 9 Feb 2020 20:00:33 -0600 Subject: [PATCH 5/9] {% load staticfiles %} and {% load admin_static %} are deprecated in favor of {% load static %}, which works the same. --- evennia/web/webclient/templates/webclient/base.html | 2 +- evennia/web/website/templates/website/_menu.html | 2 +- evennia/web/website/templates/website/base.html | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/evennia/web/webclient/templates/webclient/base.html b/evennia/web/webclient/templates/webclient/base.html index 46353b18ad..e65467da12 100644 --- a/evennia/web/webclient/templates/webclient/base.html +++ b/evennia/web/webclient/templates/webclient/base.html @@ -6,7 +6,7 @@ with evennia set up automatically and get the Evennia JS lib and JQuery available. --> -{% load staticfiles %} +{% load static %} {{game_name}} diff --git a/evennia/web/website/templates/website/_menu.html b/evennia/web/website/templates/website/_menu.html index a947445167..3d6501fb45 100644 --- a/evennia/web/website/templates/website/_menu.html +++ b/evennia/web/website/templates/website/_menu.html @@ -3,7 +3,7 @@ Allow to customize the menu that appears at the top of every Evennia webpage. Copy this file to your game dir's web/template_overrides/website folder and edit it to add/remove links to the menu. {% endcomment %} -{% load staticfiles %} +{% load static %}