From 9f6e3de63724a58b727541f76711eb6c5ed2a31a Mon Sep 17 00:00:00 2001 From: Griatch Date: Mon, 5 Nov 2012 00:55:25 +0100 Subject: [PATCH] Various cleanups and fixes found during refurbishing the unittest framework (not pushed yet) --- src/objects/models.py | 3 ++- src/typeclasses/models.py | 7 +++---- src/utils/ansi.py | 3 +-- src/utils/create.py | 24 ++++++++++++++---------- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/objects/models.py b/src/objects/models.py index 881b2b2e8..8204f5113 100644 --- a/src/objects/models.py +++ b/src/objects/models.py @@ -653,7 +653,8 @@ class ObjectDB(TypedObject): be used by the protocol. """ if _GA(self, 'player'): - _GA(_GA(self, 'player'), "msg")(message, from_obj=from_obj, data=data) + # note that we check the typeclass' msg, otherwise one couldn't overload it. + _GA(_GA(self, 'player'), "typeclass").msg(message, from_obj=from_obj, data=data) def emit_to(self, message, from_obj=None, data=None): "Deprecated. Alias for msg" diff --git a/src/typeclasses/models.py b/src/typeclasses/models.py index 976b40605..1ebef5f9f 100644 --- a/src/typeclasses/models.py +++ b/src/typeclasses/models.py @@ -868,12 +868,14 @@ class TypedObject(SharedMemoryModel): def __typeclass_path_set(self, value): "Setter. Allows for self.typeclass_path = value" set_field_cache(self, "typeclass_path", value) + _SA(self, "_cached_typeclass", None) #@typeclass_path.deleter def __typeclass_path_del(self): "Deleter. Allows for del self.typeclass_path" self.db_typeclass_path = "" self.save() del_field_cache(self, "typeclass_path") + _SA(self, "_cached_typeclass", None) typeclass_path = property(__typeclass_path_get, __typeclass_path_set, __typeclass_path_del) # date_created property @@ -1030,7 +1032,6 @@ class TypedObject(SharedMemoryModel): return typeclass except AttributeError: pass - errstring = "" if not path: # this means we should get the default obj without giving errors. @@ -1048,9 +1049,7 @@ class TypedObject(SharedMemoryModel): typeclass = _GA(self, "_path_import")(tpath) if callable(typeclass): # we succeeded to import. Cache and return. - _SA(self, 'db_typeclass_path', tpath) - _GA(self, 'save')() - _SA(self, "_cached_db_typeclass_path", tpath) + _SA(self, "typeclass_path", tpath) typeclass = typeclass(self) _SA(self, "_cached_typeclass", typeclass) try: diff --git a/src/utils/ansi.py b/src/utils/ansi.py index b4d47ea93..1ccd234af 100644 --- a/src/utils/ansi.py +++ b/src/utils/ansi.py @@ -228,8 +228,7 @@ class ANSIParser(object): string += "%s%s" % (part, sep[0].strip()) if strip_ansi: # remove all ansi codes (including those manually inserted in string) - for sub in self.ansi_sub: - string = sub[0].sub("", string) + string = self.ansi_regex.sub("", string) return string diff --git a/src/utils/create.py b/src/utils/create.py index 65389f335..1c1ff7eeb 100644 --- a/src/utils/create.py +++ b/src/utils/create.py @@ -468,16 +468,20 @@ def create_player(name, email, password, elif isinstance(typeclass, _Player) or utils.inherits_from(typeclass, _Player): # this is already an object typeclass, extract its path typeclass = typeclass.path - if player_dbobj: - new_db_player = player_dbobj + try: + _GA(player_dbobj, "dbobj") + new_db_player = player_dbobj.dbobj + except AttributeError: + new_db_player = player_dbobj + # use the typeclass from this object + typeclass = new_db_player.typeclass_path else: new_db_player = _PlayerDB(db_key=name, user=new_user) new_db_player.save() - - # assign the typeclass - typeclass = utils.to_unicode(typeclass) - new_db_player.typeclass_path = typeclass + # assign the typeclass + typeclass = utils.to_unicode(typeclass) + new_db_player.typeclass_path = typeclass # this will either load the typeclass or the default one new_player = new_db_player.typeclass @@ -487,7 +491,7 @@ def create_player(name, email, password, SharedMemoryModel.delete(new_db_player) if report_to: _GA(report_to, "msg")("Error creating %s (%s):\n%s" % (new_db_player.key, typeclass, - _GA(new_db_player, "typeclass_last_errmsg"))) + _GA(new_db_player, "typeclass_last_errmsg"))) return None else: raise Exception(_GA(new_db_player, "typeclass_last_errmsg")) @@ -512,12 +516,12 @@ def create_player(name, email, password, # creating the object automatically links the player # and object together by player.obj <-> obj.player new_character = create_object(character_typeclass, key=name, - location=None, home=character_location, + location=character_location, home=character_location, permissions=permissions, player=new_player, report_to=report_to) return new_character return new_player - except Exception: + except Exception, e: # a failure in creating the character if not user: # in there was a failure we clean up everything we can @@ -534,7 +538,7 @@ def create_player(name, email, password, del new_character except Exception: pass - raise + raise e # alias player = create_player