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.
|
be used by the protocol.
|
||||||
"""
|
"""
|
||||||
if _GA(self, 'player'):
|
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):
|
def emit_to(self, message, from_obj=None, data=None):
|
||||||
"Deprecated. Alias for msg"
|
"Deprecated. Alias for msg"
|
||||||
|
|
|
||||||
|
|
@ -868,12 +868,14 @@ class TypedObject(SharedMemoryModel):
|
||||||
def __typeclass_path_set(self, value):
|
def __typeclass_path_set(self, value):
|
||||||
"Setter. Allows for self.typeclass_path = value"
|
"Setter. Allows for self.typeclass_path = value"
|
||||||
set_field_cache(self, "typeclass_path", value)
|
set_field_cache(self, "typeclass_path", value)
|
||||||
|
_SA(self, "_cached_typeclass", None)
|
||||||
#@typeclass_path.deleter
|
#@typeclass_path.deleter
|
||||||
def __typeclass_path_del(self):
|
def __typeclass_path_del(self):
|
||||||
"Deleter. Allows for del self.typeclass_path"
|
"Deleter. Allows for del self.typeclass_path"
|
||||||
self.db_typeclass_path = ""
|
self.db_typeclass_path = ""
|
||||||
self.save()
|
self.save()
|
||||||
del_field_cache(self, "typeclass_path")
|
del_field_cache(self, "typeclass_path")
|
||||||
|
_SA(self, "_cached_typeclass", None)
|
||||||
typeclass_path = property(__typeclass_path_get, __typeclass_path_set, __typeclass_path_del)
|
typeclass_path = property(__typeclass_path_get, __typeclass_path_set, __typeclass_path_del)
|
||||||
|
|
||||||
# date_created property
|
# date_created property
|
||||||
|
|
@ -1030,7 +1032,6 @@ class TypedObject(SharedMemoryModel):
|
||||||
return typeclass
|
return typeclass
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
errstring = ""
|
errstring = ""
|
||||||
if not path:
|
if not path:
|
||||||
# this means we should get the default obj without giving errors.
|
# this means we should get the default obj without giving errors.
|
||||||
|
|
@ -1048,9 +1049,7 @@ class TypedObject(SharedMemoryModel):
|
||||||
typeclass = _GA(self, "_path_import")(tpath)
|
typeclass = _GA(self, "_path_import")(tpath)
|
||||||
if callable(typeclass):
|
if callable(typeclass):
|
||||||
# we succeeded to import. Cache and return.
|
# we succeeded to import. Cache and return.
|
||||||
_SA(self, 'db_typeclass_path', tpath)
|
_SA(self, "typeclass_path", tpath)
|
||||||
_GA(self, 'save')()
|
|
||||||
_SA(self, "_cached_db_typeclass_path", tpath)
|
|
||||||
typeclass = typeclass(self)
|
typeclass = typeclass(self)
|
||||||
_SA(self, "_cached_typeclass", typeclass)
|
_SA(self, "_cached_typeclass", typeclass)
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -228,8 +228,7 @@ class ANSIParser(object):
|
||||||
string += "%s%s" % (part, sep[0].strip())
|
string += "%s%s" % (part, sep[0].strip())
|
||||||
if strip_ansi:
|
if strip_ansi:
|
||||||
# remove all ansi codes (including those manually inserted in string)
|
# remove all ansi codes (including those manually inserted in string)
|
||||||
for sub in self.ansi_sub:
|
string = self.ansi_regex.sub("", string)
|
||||||
string = sub[0].sub("", string)
|
|
||||||
return string
|
return string
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -468,16 +468,20 @@ def create_player(name, email, password,
|
||||||
elif isinstance(typeclass, _Player) or utils.inherits_from(typeclass, _Player):
|
elif isinstance(typeclass, _Player) or utils.inherits_from(typeclass, _Player):
|
||||||
# this is already an object typeclass, extract its path
|
# this is already an object typeclass, extract its path
|
||||||
typeclass = typeclass.path
|
typeclass = typeclass.path
|
||||||
|
|
||||||
if player_dbobj:
|
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:
|
else:
|
||||||
new_db_player = _PlayerDB(db_key=name, user=new_user)
|
new_db_player = _PlayerDB(db_key=name, user=new_user)
|
||||||
new_db_player.save()
|
new_db_player.save()
|
||||||
|
# assign the typeclass
|
||||||
# assign the typeclass
|
typeclass = utils.to_unicode(typeclass)
|
||||||
typeclass = utils.to_unicode(typeclass)
|
new_db_player.typeclass_path = typeclass
|
||||||
new_db_player.typeclass_path = typeclass
|
|
||||||
|
|
||||||
# this will either load the typeclass or the default one
|
# this will either load the typeclass or the default one
|
||||||
new_player = new_db_player.typeclass
|
new_player = new_db_player.typeclass
|
||||||
|
|
@ -487,7 +491,7 @@ def create_player(name, email, password,
|
||||||
SharedMemoryModel.delete(new_db_player)
|
SharedMemoryModel.delete(new_db_player)
|
||||||
if report_to:
|
if report_to:
|
||||||
_GA(report_to, "msg")("Error creating %s (%s):\n%s" % (new_db_player.key, typeclass,
|
_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
|
return None
|
||||||
else:
|
else:
|
||||||
raise Exception(_GA(new_db_player, "typeclass_last_errmsg"))
|
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
|
# creating the object automatically links the player
|
||||||
# and object together by player.obj <-> obj.player
|
# and object together by player.obj <-> obj.player
|
||||||
new_character = create_object(character_typeclass, key=name,
|
new_character = create_object(character_typeclass, key=name,
|
||||||
location=None, home=character_location,
|
location=character_location, home=character_location,
|
||||||
permissions=permissions,
|
permissions=permissions,
|
||||||
player=new_player, report_to=report_to)
|
player=new_player, report_to=report_to)
|
||||||
return new_character
|
return new_character
|
||||||
return new_player
|
return new_player
|
||||||
except Exception:
|
except Exception, e:
|
||||||
# a failure in creating the character
|
# a failure in creating the character
|
||||||
if not user:
|
if not user:
|
||||||
# in there was a failure we clean up everything we can
|
# in there was a failure we clean up everything we can
|
||||||
|
|
@ -534,7 +538,7 @@ def create_player(name, email, password,
|
||||||
del new_character
|
del new_character
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
raise
|
raise e
|
||||||
|
|
||||||
# alias
|
# alias
|
||||||
player = create_player
|
player = create_player
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue