Use list* from future.utils.

dict.keys() -> list(dict)
dict.values() -> listvalues(dict)
dict.tems() -> listitems(dict)
This commit is contained in:
Ahmed Charles 2015-11-02 11:23:56 +00:00
parent ccd1451a02
commit 487fcdf873
11 changed files with 26 additions and 20 deletions

View file

@ -26,11 +26,11 @@ Set theory.
to affect the low-priority cmdset. Ex: A1,A3 + B1,B2,B4,B5 = B2,B4,B5
"""
from future.utils import listvalues, with_metaclass
from weakref import WeakKeyDictionary
from django.utils.translation import ugettext as _
from evennia.utils.utils import inherits_from, is_iter
from future.utils import with_metaclass
__all__ = ("CmdSet",)
@ -579,7 +579,7 @@ class CmdSet(with_metaclass(_CmdSetMeta, object)):
unique[cmd.key] = cmd
else:
unique[cmd.key] = cmd
self.commands = unique.values()
self.commands = listvalues(unique)
def get_all_cmd_keys_and_aliases(self, caller=None):
"""

View file

@ -244,7 +244,7 @@ class LanguageHandler(DefaultScript):
in range(word_length_variance)))
if wlen not in grammar:
# always create a translation, use random length
structure = choice(grammar[choice(grammar.keys())])
structure = choice(grammar[choice(list(grammar))])
else:
# use the corresponding length
structure = choice(grammar[wlen])
@ -409,7 +409,7 @@ def available_languages():
if not _LANGUAGE_HANDLER:
from evennia import create_script
_LANGUAGE_HANDLER = create_script(LanguageHandler)
return _LANGUAGE_HANDLER.attributes.get("language_storage", {}).keys()
return list(_LANGUAGE_HANDLER.attributes.get("language_storage", {}))

View file

@ -18,6 +18,7 @@ Weapon
WeaponRack
"""
from future.utils import listvalues
import random
@ -523,7 +524,7 @@ class CmdShiftRoot(Command):
self.obj.db.root_pos = root_pos
# Check victory condition
if root_pos.values().count(0) == 0: # no roots in middle position
if listvalues(root_pos).count(0) == 0: # no roots in middle position
# This will affect the cmd: lock of CmdPressButton
self.obj.db.button_exposed = True
self.caller.msg("Holding aside the root you think you notice something behind it ...")

View file

@ -65,7 +65,7 @@ class ContentsHandler(object):
objects (list): the Objects inside this location
"""
pks = self._pkcache.keys()
pks = list(self._pkcache)
if exclude:
pks = [pk for pk in pks if pk not in [excl.pk for excl in make_iter(exclude)]]
try:

View file

@ -6,6 +6,7 @@ entities.
"""
from builtins import object
from future.utils import listvalues, with_metaclass
import traceback
from django.conf import settings
@ -21,7 +22,6 @@ from evennia.commands import cmdhandler
from evennia.utils import logger
from evennia.utils.utils import (variable_from_module, lazy_property,
make_iter, to_str, to_unicode)
from future.utils import with_metaclass
_MULTISESSION_MODE = settings.MULTISESSION_MODE
@ -870,7 +870,7 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
self.tags.add(cdict["tags"])
if cdict.get("attributes"):
# this should be a dict of attrname:value
keys, values = cdict["attributes"].keys(), cdict["attributes"].values()
keys, values = list(cdict["attributes"]), listvalues(cdict["attributes"])
self.attributes.batch_add(keys, values)
if cdict.get("nattributes"):
# this should be a dict of nattrname:value

View file

@ -55,6 +55,8 @@ call the handler's `save()` and `restore()` methods when the server reboots.
"""
from builtins import object
from future.utils import listvalues
from twisted.internet.defer import inlineCallbacks
from django.core.exceptions import ObjectDoesNotExist
from evennia.scripts.scripts import ExtendedLoopingCall
@ -405,7 +407,7 @@ class TickerHandler(object):
self.ticker_pool.remove(store_key, interval)
else:
# remove all objects with any intervals
intervals = self.ticker_pool.tickers.keys()
intervals = list(self.ticker_pool.tickers)
should_save = False
for interval in intervals:
isdb, store_key = self._store_key(obj, interval, idstring)
@ -455,13 +457,13 @@ class TickerHandler(object):
"""
if interval is None:
# return dict of all, ordered by interval
return dict((interval, ticker.subscriptions.values())
return dict((interval, listvalues(ticker.subscriptions))
for interval, ticker in self.ticker_pool.tickers.items())
else:
# get individual interval
ticker = self.ticker_pool.tickers.get(interval, None)
if ticker:
return ticker.subscriptions.values()
return listvalues(ticker.subscriptions)
# main tickerhandler

View file

@ -2,6 +2,7 @@
IMC2 client module. Handles connecting to and communicating with an IMC2 server.
"""
from builtins import object
from future.utils import listitems
from time import time
from twisted.internet import task
@ -45,7 +46,7 @@ class IMC2MudList(dict):
"""
Returns a sorted list of connected Muds.
"""
muds = self.items()
muds = listitems(self)
muds.sort()
return [value for key, value in muds]
@ -101,7 +102,7 @@ class IMC2ChanList(dict):
Returns a sorted list of cached channels.
"""
channels = self.items()
channels = listitems(self)
channels.sort()
return [value for key, value in channels]

View file

@ -13,6 +13,7 @@ There are two similar but separate stores of sessions:
"""
from builtins import object
from future.utils import listvalues
from time import time
from django.conf import settings
@ -103,7 +104,7 @@ class SessionHandler(object):
"""
if include_unloggedin:
return self.sessions.values()
return listvalues(self.sessions)
else:
return [session for session in self.sessions.values() if session.logged_in]

View file

@ -116,6 +116,7 @@ table string.
"""
from __future__ import print_function
from builtins import object, range
from future.utils import listitems
from django.conf import settings
from textwrap import TextWrapper
@ -1371,7 +1372,7 @@ class EvTable(object):
"""
# this will replace default options with new ones without changing default
options = dict(self.options.items() + kwargs.items())
options = dict(listitems(self.options) + listitems(kwargs))
xpos = kwargs.get("xpos", None)
column = EvColumn(*args, **options)
@ -1430,7 +1431,7 @@ class EvTable(object):
"""
# this will replace default options with new ones without changing default
row = list(args)
options = dict(self.options.items() + kwargs.items())
options = dict(listitems(self.options) + listitems(kwargs))
ypos = kwargs.get("ypos", None)
wtable = self.ncols

View file

@ -16,7 +16,7 @@ class SharedMemoryManager(Manager):
"""
Data entity lookup.
"""
items = kwargs.keys()
items = list(kwargs)
inst = None
if len(items) == 1:
# CL: support __exact

View file

@ -8,6 +8,7 @@ Also adds `cache_size()` for monitoring the size of the cache.
"""
from __future__ import absolute_import, division
from builtins import object
from future.utils import listitems, listvalues, with_metaclass
import os, threading, gc, time
from weakref import WeakValueDictionary
@ -20,7 +21,6 @@ from evennia.utils import logger
from evennia.utils.utils import dbref, get_evennia_pids, to_str
from .manager import SharedMemoryManager
from future.utils import with_metaclass
AUTO_FLUSH_MIN_INTERVAL = 60.0 * 5 # at least 5 mins between cache flushes
@ -189,7 +189,7 @@ class SharedMemoryModelBase(ModelBase):
if cls.__name__ in ("ServerConfig", "TypeNick"):
return
# dynamically create the wrapper properties for all fields not already handled (manytomanyfields are always handlers)
for fieldname, field in ((fname, field) for fname, field in attrs.items()
for fieldname, field in ((fname, field) for fname, field in listitems(attrs)
if fname.startswith("db_") and type(field).__name__ != "ManyToManyField"):
foreignkey = type(field).__name__ == "ForeignKey"
wrappername = "dbid" if fieldname == "id" else fieldname.replace("db_", "", 1)
@ -282,7 +282,7 @@ class SharedMemoryModel(with_metaclass(SharedMemoryModelBase, Model)):
Return the objects so far cached by idmapper for this class.
"""
return cls.__dbclass__.__instance_cache__.values()
return listvalues(cls.__dbclass__.__instance_cache__)
@classmethod
def _flush_cached_by_key(cls, key, force=True):