mirror of
https://github.com/evennia/evennia.git
synced 2026-03-24 00:36:30 +01:00
@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
|
||||
|
||||
"""
|
||||
|
||||
from django.conf import settings
|
||||
from src.objects.models import ObjectDB, ObjAttribute
|
||||
from src.players.models import PlayerAttribute
|
||||
|
|
@ -20,7 +19,6 @@ __all__ = ("ObjManipCommand", "CmdSetObjAlias", "CmdCopy",
|
|||
"CmdLock", "CmdExamine", "CmdFind", "CmdTeleport",
|
||||
"CmdScript")
|
||||
|
||||
|
||||
# used by @find
|
||||
CHAR_TYPECLASS = settings.BASE_CHARACTER_TYPECLASS
|
||||
|
||||
|
|
@ -1139,6 +1137,7 @@ class CmdOpen(ObjManipCommand):
|
|||
back_exit_typeclass = self.lhs_objs[1]['option']
|
||||
ok = self.create_exit(back_exit_name, destination, location, back_exit_aliases, back_exit_typeclass)
|
||||
|
||||
|
||||
class CmdSetAttribute(ObjManipCommand):
|
||||
"""
|
||||
@set - set attributes
|
||||
|
|
@ -1176,6 +1175,7 @@ class CmdSetAttribute(ObjManipCommand):
|
|||
comparisons later (e.g. obj.db.value = 2, if value is stored as a
|
||||
string this will always fail).
|
||||
"""
|
||||
|
||||
def rec_convert(obj):
|
||||
"""
|
||||
Helper function of recursive conversion calls.
|
||||
|
|
@ -1198,7 +1198,14 @@ class CmdSetAttribute(ObjManipCommand):
|
|||
for pair in obj[1:-1].split(',') if ":" in pair])
|
||||
# if nothing matches, return as-is
|
||||
return obj
|
||||
return rec_convert(strobj.strip())
|
||||
|
||||
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())
|
||||
|
||||
def func(self):
|
||||
"Implement the set attribute - a limited form of @py."
|
||||
|
|
@ -1315,7 +1322,6 @@ class CmdTypeclass(MuxCommand):
|
|||
caller.msg("This object cannot have a type at all!")
|
||||
return
|
||||
|
||||
old_path = obj.typeclass_path
|
||||
if obj.is_typeclass(typeclass) and not 'force' in self.switches:
|
||||
string = "%s already has the typeclass '%s'." % (obj.name, typeclass)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue