Added an extension to the "holds" lockfunc, to allow it to check attribute values of objects held by the accessing_object. Resolves Issue 281.
This commit is contained in:
parent
09b4b69da9
commit
af160c740e
1 changed files with 12 additions and 5 deletions
|
|
@ -367,6 +367,7 @@ def holds(accessing_obj, accessed_obj, *args, **kwargs):
|
||||||
Usage:
|
Usage:
|
||||||
holds() # checks if accessed_obj or accessed_obj.obj is held by accessing_obj
|
holds() # checks if accessed_obj or accessed_obj.obj is held by accessing_obj
|
||||||
holds(key/dbref) # checks if accessing_obj holds an object with given key/dbref
|
holds(key/dbref) # checks if accessing_obj holds an object with given key/dbref
|
||||||
|
holds(attrname, value) # checks if accessing_obj holds an object with the given attrname and value
|
||||||
|
|
||||||
This is passed if accessed_obj is carried by accessing_obj (that is,
|
This is passed if accessed_obj is carried by accessing_obj (that is,
|
||||||
accessed_obj.location == accessing_obj), or if accessing_obj itself holds an
|
accessed_obj.location == accessing_obj), or if accessing_obj itself holds an
|
||||||
|
|
@ -393,17 +394,23 @@ def holds(accessing_obj, accessed_obj, *args, **kwargs):
|
||||||
return any((True for obj in contents
|
return any((True for obj in contents
|
||||||
if obj.key.lower() == objid or objid in [al.lower() for al in obj.aliases]))
|
if obj.key.lower() == objid or objid in [al.lower() for al in obj.aliases]))
|
||||||
|
|
||||||
if args and args[0]:
|
if not args:
|
||||||
return check_holds(args[0])
|
# holds() - check if accessed_obj is held by accessing_ob
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
if check_holds(accessed_obj.dbid):
|
if check_holds(accessed_obj.dbid):
|
||||||
#print "holds: accessed_obj.id - True"
|
|
||||||
return True
|
return True
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
#print "holds: accessed_obj.obj.id -", hasattr(accessed_obj, "obj") and check_holds(accessed_obj.obj.id)
|
|
||||||
return hasattr(accessed_obj, "obj") and check_holds(accessed_obj.obj.dbid)
|
return hasattr(accessed_obj, "obj") and check_holds(accessed_obj.obj.dbid)
|
||||||
|
if len(args) == 1:
|
||||||
|
# command is holds(dbref/key) - check if given objname/dbref is held by accessing_ob
|
||||||
|
return check_holds(args[0])
|
||||||
|
elif len(args = 2):
|
||||||
|
# command is holds(attrname, value) check if any held object has the given attribute and value
|
||||||
|
for obj in contents:
|
||||||
|
if obj.attr(args[0]) == args[1]:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def superuser(*args, **kwargs):
|
def superuser(*args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue