mirror of
https://github.com/evennia/evennia.git
synced 2026-03-23 00:06:30 +01:00
[#1928] change to plus for append/insert
This commit is contained in:
parent
08d967d174
commit
2f5ebaeafb
2 changed files with 12 additions and 9 deletions
|
|
@ -53,6 +53,7 @@ __all__ = (
|
|||
|
||||
# used by set
|
||||
from ast import literal_eval as _LITERAL_EVAL
|
||||
LIST_APPEND_CHAR = '+'
|
||||
|
||||
# used by find
|
||||
CHAR_TYPECLASS = settings.BASE_CHARACTER_TYPECLASS
|
||||
|
|
@ -1648,7 +1649,9 @@ class CmdSetAttribute(ObjManipCommand):
|
|||
val = val.strip('[]')
|
||||
if val[0] in quotes:
|
||||
return val.strip(quotes)
|
||||
|
||||
if val[0] == LIST_APPEND_CHAR:
|
||||
# List insert/append syntax
|
||||
return val
|
||||
try:
|
||||
return int(val)
|
||||
except ValueError:
|
||||
|
|
@ -1720,7 +1723,7 @@ class CmdSetAttribute(ObjManipCommand):
|
|||
# a key that starts with @ will insert a new item at that
|
||||
# location, and move the other elements down.
|
||||
# Just '@' will append to the list
|
||||
if isinstance(acc_key, str) and acc_key[0] == '@':
|
||||
if isinstance(acc_key, str) and acc_key[0] == LIST_APPEND_CHAR:
|
||||
try:
|
||||
if len(acc_key) > 1:
|
||||
where = int(acc_key[1:])
|
||||
|
|
|
|||
|
|
@ -553,9 +553,9 @@ class TestBuilding(CommandTest):
|
|||
"Obj/test1[5] =", "Obj has no attribute 'test1[5]'.")
|
||||
# Append
|
||||
self.call(building.CmdSetAttribute(),
|
||||
"Obj/test1[@] = 42", "Modified attribute Obj/test1 = [2, 42]")
|
||||
"Obj/test1[+] = 42", "Modified attribute Obj/test1 = [2, 42]")
|
||||
self.call(building.CmdSetAttribute(),
|
||||
"Obj/test1[@0] = -1", "Modified attribute Obj/test1 = [-1, 2, 42]")
|
||||
"Obj/test1[+0] = -1", "Modified attribute Obj/test1 = [-1, 2, 42]")
|
||||
|
||||
# dict - removing white space proves real parsing
|
||||
self.call(building.CmdSetAttribute(),
|
||||
|
|
@ -578,19 +578,19 @@ class TestBuilding(CommandTest):
|
|||
self.call(building.CmdSetAttribute(),
|
||||
"Obj/test2['five'] =", "Obj has no attribute 'test2['five']'.")
|
||||
self.call(building.CmdSetAttribute(),
|
||||
"Obj/test2[@]=42", "Modified attribute Obj/test2 = {'one': 99, 'three': 3, '@': 42}")
|
||||
"Obj/test2[+]=42", "Modified attribute Obj/test2 = {'one': 99, 'three': 3, '+': 42}")
|
||||
self.call(building.CmdSetAttribute(),
|
||||
"Obj/test2[@1]=33",
|
||||
"Modified attribute Obj/test2 = {'one': 99, 'three': 3, '@': 42, '@1': 33}")
|
||||
"Obj/test2[+1]=33",
|
||||
"Modified attribute Obj/test2 = {'one': 99, 'three': 3, '+': 42, '+1': 33}")
|
||||
|
||||
# tuple
|
||||
self.call(building.CmdSetAttribute(), "Obj/tup = (1,2)", "Created attribute Obj/tup = (1, 2)")
|
||||
self.call(building.CmdSetAttribute(),
|
||||
"Obj/tup[1] = 99", "'tuple' object does not support item assignment - (1, 2)")
|
||||
self.call(building.CmdSetAttribute(),
|
||||
"Obj/tup[@] = 99", "'tuple' object does not support item assignment - (1, 2)")
|
||||
"Obj/tup[+] = 99", "'tuple' object does not support item assignment - (1, 2)")
|
||||
self.call(building.CmdSetAttribute(),
|
||||
"Obj/tup[@1] = 99", "'tuple' object does not support item assignment - (1, 2)")
|
||||
"Obj/tup[+1] = 99", "'tuple' object does not support item assignment - (1, 2)")
|
||||
self.call(building.CmdSetAttribute(),
|
||||
# Special case for tuple, could have a better message
|
||||
"Obj/tup[1] = ", "Obj has no attribute 'tup[1]'.")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue