Various cleanups and fixes found during refurbishing the unittest framework (not pushed yet)
This commit is contained in:
parent
6c20987d9a
commit
9f6e3de637
4 changed files with 20 additions and 17 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue