From faacf58f56b22cca925b16ba8863f4a406ebb0c9 Mon Sep 17 00:00:00 2001 From: Ahmed Charles Date: Mon, 2 Nov 2015 09:35:22 +0000 Subject: [PATCH] Use viewkeys from future.utils, with the following mapping: dict.keys() -> viewkeys(dict) --- evennia/server/oob_cmds.py | 5 +++-- evennia/server/portal/irc.py | 3 ++- evennia/utils/utils.py | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/evennia/server/oob_cmds.py b/evennia/server/oob_cmds.py index 52e81d46f9..3301f751cf 100644 --- a/evennia/server/oob_cmds.py +++ b/evennia/server/oob_cmds.py @@ -55,6 +55,7 @@ protocol), but tells the Evennia OOB Protocol that you want to send a name. """ +from future.utils import viewkeys from django.conf import settings from evennia.utils.utils import to_str @@ -353,7 +354,7 @@ def oob_list(session, mode, *args, **kwargs): # "RESET", "SEND"))) elif mode == "REPORTABLE_VARIABLES": - session.msg(oob=("REPORTABLE_VARIABLES", tuple(key for key in OOB_REPORTABLE.keys()))) + session.msg(oob=("REPORTABLE_VARIABLES", tuple(key for key in viewkeys(OOB_REPORTABLE)))) elif mode == "REPORTED_VARIABLES": # we need to check so as to use the right return value depending on if it is # an Attribute (identified by tracking the db_value field) or a normal database field @@ -362,7 +363,7 @@ def oob_list(session, mode, *args, **kwargs): reported = [rep[0].key if rep[1] == "db_value" else rep[1] for rep in reported] session.msg(oob=("REPORTED_VARIABLES", reported)) elif mode == "SENDABLE_VARIABLES": - session.msg(oob=("SENDABLE_VARIABLES", tuple(key for key in OOB_REPORTABLE.keys()))) + session.msg(oob=("SENDABLE_VARIABLES", tuple(key for key in viewkeys(OOB_REPORTABLE)))) elif mode == "CONFIGURABLE_VARIABLES": # Not implemented (game specific) oob_error(session, "Not implemented (game specific)") diff --git a/evennia/server/portal/irc.py b/evennia/server/portal/irc.py index 3d636a475a..b09922473d 100644 --- a/evennia/server/portal/irc.py +++ b/evennia/server/portal/irc.py @@ -4,6 +4,7 @@ The bot then pipes what is being said between the IRC channel and one or more Evennia channels. """ from __future__ import print_function +from future.utils import viewkeys import re from twisted.application import internet @@ -79,7 +80,7 @@ IRC_COLOR_MAP = dict([ (r'{[w', IRC_COLOR + IRC_NORMAL + "," + IRC_GRAY), # light grey background (r'{[x', IRC_COLOR + IRC_NORMAL + "," + IRC_BLACK) # pure black background ]) -RE_IRC_COLOR = re.compile(r"|".join([re.escape(key) for key in IRC_COLOR_MAP.keys()]), re.DOTALL) +RE_IRC_COLOR = re.compile(r"|".join([re.escape(key) for key in viewkeys(IRC_COLOR_MAP)]), re.DOTALL) RE_MXP = re.compile(r'\{lc(.*?)\{lt(.*?)\{le', re.DOTALL) RE_ANSI_ESCAPES = re.compile(r"(%s)" % "|".join(("{{", "%%", "\\\\")), re.DOTALL) diff --git a/evennia/utils/utils.py b/evennia/utils/utils.py index acf2b83364..4fc10195aa 100644 --- a/evennia/utils/utils.py +++ b/evennia/utils/utils.py @@ -7,6 +7,7 @@ be of use when designing your own game. """ from __future__ import division, print_function from builtins import object, range +from future.utils import viewkeys import os import sys @@ -766,7 +767,7 @@ def clean_object_caches(obj): pass # on-object property cache - [_DA(obj, cname) for cname in obj.__dict__.keys() + [_DA(obj, cname) for cname in viewkeys(obj.__dict__) if cname.startswith("_cached_db_")] try: hashid = _GA(obj, "hashid")