Changed default dbref search mechanic to require #N format and thus allow searching for objects named as integers (so "@create/drop 2" followed by 'look 2' will now work as expected instead of looking at the object with dbref=2). Doing "look #2" will now look at the object with dbref 2 (Limbo). Resolves Issue 284.

This commit is contained in:
Griatch 2012-10-14 15:45:21 +02:00
parent 31daf5b013
commit 5b5328e6ca
3 changed files with 13 additions and 7 deletions

View file

@ -23,12 +23,14 @@ class CommError(Exception):
# helper functions
#
def dbref(dbref):
def dbref(dbref, reqhash=True):
"""
Valid forms of dbref (database reference number)
are either a string '#N' or an integer N.
Output is the integer part.
"""
if reqhash and not (isinstance(dbref, basestring) and dbref.startswith("#")):
return None
if isinstance(dbref, basestring):
dbref = dbref.lstrip('#')
try:
@ -136,7 +138,7 @@ class MsgManager(models.Manager):
def get_message_by_id(self, idnum):
"Retrieve message by its id."
try:
return self.get(id=self.dbref(idnum))
return self.get(id=self.dbref(idnum, reqhash=False))
except Exception:
return None