@set now supports all forms of nested dicts and lists under Python 2.6. Python2.5 still depends on the old recursive solution that does not support nesting. Maybe time to up the python dependency number? Fixes Issue 225.
This commit is contained in:
parent
9475fbd0d9
commit
5264dc85bb
1 changed files with 10 additions and 4 deletions
|
|
@ -3,7 +3,6 @@
|
||||||
Building and world design commands
|
Building and world design commands
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from src.objects.models import ObjectDB, ObjAttribute
|
from src.objects.models import ObjectDB, ObjAttribute
|
||||||
from src.players.models import PlayerAttribute
|
from src.players.models import PlayerAttribute
|
||||||
|
|
@ -20,7 +19,6 @@ __all__ = ("ObjManipCommand", "CmdSetObjAlias", "CmdCopy",
|
||||||
"CmdLock", "CmdExamine", "CmdFind", "CmdTeleport",
|
"CmdLock", "CmdExamine", "CmdFind", "CmdTeleport",
|
||||||
"CmdScript")
|
"CmdScript")
|
||||||
|
|
||||||
|
|
||||||
# used by @find
|
# used by @find
|
||||||
CHAR_TYPECLASS = settings.BASE_CHARACTER_TYPECLASS
|
CHAR_TYPECLASS = settings.BASE_CHARACTER_TYPECLASS
|
||||||
|
|
||||||
|
|
@ -1139,6 +1137,7 @@ class CmdOpen(ObjManipCommand):
|
||||||
back_exit_typeclass = self.lhs_objs[1]['option']
|
back_exit_typeclass = self.lhs_objs[1]['option']
|
||||||
ok = self.create_exit(back_exit_name, destination, location, back_exit_aliases, back_exit_typeclass)
|
ok = self.create_exit(back_exit_name, destination, location, back_exit_aliases, back_exit_typeclass)
|
||||||
|
|
||||||
|
|
||||||
class CmdSetAttribute(ObjManipCommand):
|
class CmdSetAttribute(ObjManipCommand):
|
||||||
"""
|
"""
|
||||||
@set - set attributes
|
@set - set attributes
|
||||||
|
|
@ -1176,6 +1175,7 @@ class CmdSetAttribute(ObjManipCommand):
|
||||||
comparisons later (e.g. obj.db.value = 2, if value is stored as a
|
comparisons later (e.g. obj.db.value = 2, if value is stored as a
|
||||||
string this will always fail).
|
string this will always fail).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def rec_convert(obj):
|
def rec_convert(obj):
|
||||||
"""
|
"""
|
||||||
Helper function of recursive conversion calls.
|
Helper function of recursive conversion calls.
|
||||||
|
|
@ -1198,6 +1198,13 @@ class CmdSetAttribute(ObjManipCommand):
|
||||||
for pair in obj[1:-1].split(',') if ":" in pair])
|
for pair in obj[1:-1].split(',') if ":" in pair])
|
||||||
# if nothing matches, return as-is
|
# if nothing matches, return as-is
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
try:
|
||||||
|
# under python 2.6, literal_eval can do this for us.
|
||||||
|
from ast import literal_eval
|
||||||
|
return literal_eval(strobj)
|
||||||
|
except ImportError:
|
||||||
|
# fall back to old recursive solution (don't support nested lists/dicts)
|
||||||
return rec_convert(strobj.strip())
|
return rec_convert(strobj.strip())
|
||||||
|
|
||||||
def func(self):
|
def func(self):
|
||||||
|
|
@ -1315,7 +1322,6 @@ class CmdTypeclass(MuxCommand):
|
||||||
caller.msg("This object cannot have a type at all!")
|
caller.msg("This object cannot have a type at all!")
|
||||||
return
|
return
|
||||||
|
|
||||||
old_path = obj.typeclass_path
|
|
||||||
if obj.is_typeclass(typeclass) and not 'force' in self.switches:
|
if obj.is_typeclass(typeclass) and not 'force' in self.switches:
|
||||||
string = "%s already has the typeclass '%s'." % (obj.name, typeclass)
|
string = "%s already has the typeclass '%s'." % (obj.name, typeclass)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue