Moved here/me,self replacement out of dbobj.search and into the typeclass.

This commit is contained in:
Griatch 2014-04-13 09:07:45 +02:00
parent e76061ee4c
commit 99b73c173c
2 changed files with 62 additions and 16 deletions

View file

@ -42,10 +42,6 @@ _GA = object.__getattribute__
_SA = object.__setattr__
_DA = object.__delattr__
_ME = _("me")
_SELF = _("self")
_HERE = _("here")
#------------------------------------------------------------
#
@ -367,12 +363,6 @@ class ObjectDB(TypedObject):
"""
is_string = isinstance(searchdata, basestring)
# handle some common self-references:
if searchdata == _HERE:
return self.location
if searchdata in (_ME, _SELF):
return self.typeclass
if use_nicks:
# do nick-replacement on search
searchdata = self.nicks.nickreplace(searchdata, categories=("object", "player"), include_player=True)
@ -412,10 +402,28 @@ class ObjectDB(TypedObject):
def search_player(self, searchdata, quiet=False):
"""
Simple wrapper of the player search also handling me, self
Simple shortcut wrapper to search for players, not characters.
searchdata - search criterion - the key or dbref of the player
to search for. If this is "here" or "me", search
for the player connected to this object.
quiet - return the results as a list rather than echo eventual
standard error messages.
Returns:
quiet=False (default):
no match or multimatch:
auto-echoes errors to self.msg, then returns None
(results are handled by settings.SEARCH_AT_RESULT
and settings.SEARCH_AT_MULTIMATCH_INPUT)
match:
a unique player match
quiet=True:
no match or multimatch:
returns None or list of multi-matches
match:
a unique object match
"""
if searchdata in (_ME, _SELF) and _GA(self, "db_player"):
return _GA(self, "db_player")
results = PlayerDB.objects.player_search(searchdata)
if quiet:
return results

View file

@ -190,7 +190,7 @@ class Object(TypeClass):
## methods inherited from the database object (overload them here)
def search(self, ostring,
def search(self, searchdata,
global_search=False,
use_nicks=True,
typeclass=None,
@ -208,13 +208,14 @@ class Object(TypeClass):
Inputs:
ostring (str): Primary search criterion. Will be matched against
searchdata (str): Primary search criterion. Will be matched against
object.key (with object.aliases second)
unless the keyword attribute_name specifies otherwise.
Special strings:
#<num> - search by unique dbref. This is always a
global search.
me,self - self-reference to this object
here - current location
<num>-<string> - can be used to differentiate between
multiple same-named matches
global_search (bool): Search all objects globally. This is overruled
@ -252,7 +253,14 @@ class Object(TypeClass):
a unique object match
"""
return self.dbobj.search(ostring,
if isinstance(searchdata, basestring):
# searchdata is a string; wrap some common self-references
if searchdata.lower() in ("here", ):
return self.location
if searchdata.lower() in ("me", "self",):
return self
return self.dbobj.search(searchdata,
global_search=global_search,
use_nicks=use_nicks,
typeclass=typeclass,
@ -261,6 +269,36 @@ class Object(TypeClass):
quiet=quiet,
exact=exact)
def search_player(self, searchdata, quiet=False):
"""
Simple shortcut wrapper to search for players, not characters.
searchdata - search criterion - the key or dbref of the player
to search for. If this is "here" or "me", search
for the player connected to this object.
quiet - return the results as a list rather than echo eventual
standard error messages.
Returns:
quiet=False (default):
no match or multimatch:
auto-echoes errors to self.msg, then returns None
(results are handled by settings.SEARCH_AT_RESULT
and settings.SEARCH_AT_MULTIMATCH_INPUT)
match:
a unique player match
quiet=True:
no match or multimatch:
returns None or list of multi-matches
match:
a unique object match
"""
if isinstance(searchdata, basestring):
# searchdata is a string; wrap some common self-references
if searchdata.lower() in ("me", "self",):
return self.player
self.dbobj.search_player(searchdata, quiet=quiet)
def execute_cmd(self, raw_string, sessid=None):
"""
Do something as this object. This command transparently