From 99b73c173cf7a532055ffa4654c5b7e1f426e01b Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 13 Apr 2014 09:07:45 +0200 Subject: [PATCH] Moved here/me,self replacement out of dbobj.search and into the typeclass. --- src/objects/models.py | 34 +++++++++++++++++++------------- src/objects/objects.py | 44 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 62 insertions(+), 16 deletions(-) diff --git a/src/objects/models.py b/src/objects/models.py index f117fed08a..4ef9393fa3 100644 --- a/src/objects/models.py +++ b/src/objects/models.py @@ -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 diff --git a/src/objects/objects.py b/src/objects/objects.py index ce4b57bfb2..b9820ad9d6 100644 --- a/src/objects/objects.py +++ b/src/objects/objects.py @@ -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: # - search by unique dbref. This is always a global search. me,self - self-reference to this object + here - current location - - 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