Some further removal of recursive loops in the typeclass system.

This commit is contained in:
Griatch 2012-09-20 23:18:52 +02:00
parent dc4340b34e
commit c0b03c2ee3
2 changed files with 45 additions and 45 deletions

View file

@ -203,10 +203,10 @@ class ObjectDB(TypedObject):
"Parent must be initialized first." "Parent must be initialized first."
TypedObject.__init__(self, *args, **kwargs) TypedObject.__init__(self, *args, **kwargs)
# handlers # handlers
self.cmdset = CmdSetHandler(self) _SA(self, "cmdset", CmdSetHandler(self))
self.cmdset.update(init_mode=True) _GA(self, "cmdset").update(init_mode=True)
self.scripts = ScriptHandler(self) _SA(self, "scripts", ScriptHandler(self))
self.nicks = ObjectNickHandler(self) _SA(self, "nicks", ObjectNickHandler(self))
# store the attribute class # store the attribute class
# Wrapper properties to easily set database fields. These are # Wrapper properties to easily set database fields. These are
@ -312,7 +312,7 @@ class ObjectDB(TypedObject):
"Getter. Allows for value = self.home" "Getter. Allows for value = self.home"
home = _get_cache(self, "home") home = _get_cache(self, "home")
if home: if home:
return home.typeclass return _GA(home, "typeclass")
return None return None
#@home.setter #@home.setter
def __home_set(self, home): def __home_set(self, home):
@ -323,23 +323,23 @@ class ObjectDB(TypedObject):
elif ObjectDB.objects.dbref(home): elif ObjectDB.objects.dbref(home):
hom = ObjectDB.objects.dbref_search(home) hom = ObjectDB.objects.dbref_search(home)
if hom and hasattr(hom,'dbobj'): if hom and hasattr(hom,'dbobj'):
hom = hom.dbobj hom = _GA(hom, "dbobj")
else: else:
hom = home.dbobj hom = _GA(home, "dbobj")
else: else:
hom = home.dbobj hom = _GA(home, "dbobj")
_set_cache(self, "home", hom) _set_cache(self, "home", hom)
except Exception: except Exception:
string = "Cannot set home: " string = "Cannot set home: "
string += "%s is not a valid home." string += "%s is not a valid home."
self.msg(_(string) % home) _GA(self, "msg")(_(string) % home)
logger.log_trace(string) logger.log_trace(string)
#raise #raise
#@home.deleter #@home.deleter
def __home_del(self): def __home_del(self):
"Deleter. Allows for del self.home." "Deleter. Allows for del self.home."
self.db_home = None _SA(self, "db_home", None)
self.save() _GA(self, "save")()
_del_cache(self, "home") _del_cache(self, "home")
home = property(__home_get, __home_set, __home_del) home = property(__home_get, __home_set, __home_del)
@ -361,7 +361,7 @@ class ObjectDB(TypedObject):
elif ObjectDB.objects.dbref(destination): elif ObjectDB.objects.dbref(destination):
# destination is a dbref; search # destination is a dbref; search
dest = ObjectDB.objects.dbref_search(destination) dest = ObjectDB.objects.dbref_search(destination)
if dest and self._hasattr(dest,'dbobj'): if dest and _GA(self, "_hasattr")(dest,'dbobj'):
dest = _GA(dest, "dbobj") dest = _GA(dest, "dbobj")
else: else:
dest = _GA(destination, "dbobj") dest = _GA(destination, "dbobj")
@ -370,8 +370,8 @@ class ObjectDB(TypedObject):
_set_cache(self, "destination", dest) _set_cache(self, "destination", dest)
except Exception: except Exception:
string = "Cannot set destination: " string = "Cannot set destination: "
string += "%s is not a valid destination." string += "%s is not a valid destination." % destination
_GA(self, "msg")(_(string) % destination) _GA(self, "msg")(string)
logger.log_trace(string) logger.log_trace(string)
raise raise
#@destination.deleter #@destination.deleter
@ -387,20 +387,20 @@ class ObjectDB(TypedObject):
#@property #@property
def __cmdset_storage_get(self): def __cmdset_storage_get(self):
"Getter. Allows for value = self.name. Returns a list of cmdset_storage." "Getter. Allows for value = self.name. Returns a list of cmdset_storage."
if self.db_cmdset_storage: if _GA(self, "db_cmdset_storage"):
return [path.strip() for path in self.db_cmdset_storage.split(',')] return [path.strip() for path in _GA(self, "db_cmdset_storage").split(',')]
return [] return []
#@cmdset_storage.setter #@cmdset_storage.setter
def __cmdset_storage_set(self, value): def __cmdset_storage_set(self, value):
"Setter. Allows for self.name = value. Stores as a comma-separated string." "Setter. Allows for self.name = value. Stores as a comma-separated string."
value = ",".join(str(val).strip() for val in make_iter(value)) value = ",".join(str(val).strip() for val in make_iter(value))
self.db_cmdset_storage = value _SA(self, "db_cmdset_storage", value)
self.save() _GA(self, "save")()
#@cmdset_storage.deleter #@cmdset_storage.deleter
def __cmdset_storage_del(self): def __cmdset_storage_del(self):
"Deleter. Allows for del self.name" "Deleter. Allows for del self.name"
self.db_cmdset_storage = "" _SA(self, "db_cmdset_storage", "")
self.save() _GA(self, "save")()
cmdset_storage = property(__cmdset_storage_get, __cmdset_storage_set, __cmdset_storage_del) cmdset_storage = property(__cmdset_storage_get, __cmdset_storage_set, __cmdset_storage_del)
class Meta: class Meta:
@ -488,7 +488,7 @@ class ObjectDB(TypedObject):
Returns all exits from this object, i.e. all objects Returns all exits from this object, i.e. all objects
at this location having the property destination != None. at this location having the property destination != None.
""" """
return [exi for exi in self.contents return [exi for exi in _GA(self, "contents")
if exi.destination] if exi.destination]
exits = property(__exits_get) exits = property(__exits_get)
@ -619,7 +619,7 @@ class ObjectDB(TypedObject):
if nick.db_nick in raw_list: if nick.db_nick in raw_list:
raw_string = raw_string.replace(nick.db_nick, nick.db_real, 1) raw_string = raw_string.replace(nick.db_nick, nick.db_real, 1)
break break
return cmdhandler.cmdhandler(self.typeclass, raw_string) return cmdhandler.cmdhandler(_GA(self, "typeclass"), raw_string)
def msg(self, message, from_obj=None, data=None): def msg(self, message, from_obj=None, data=None):
""" """
@ -644,7 +644,7 @@ class ObjectDB(TypedObject):
exclude is a list of objects not to send to. See self.msg() for more info. exclude is a list of objects not to send to. See self.msg() for more info.
""" """
contents = self.contents contents = _GA(self, "contents")
if exclude: if exclude:
exclude = make_iter(exclude) exclude = make_iter(exclude)
contents = [obj for obj in contents contents = [obj for obj in contents
@ -684,7 +684,7 @@ class ObjectDB(TypedObject):
trc = traceback.format_exc() trc = traceback.format_exc()
errstring = "%s%s" % (trc, string) errstring = "%s%s" % (trc, string)
logger.log_trace() logger.log_trace()
self.msg(errstring) _GA(self, "msg")(errstring)
errtxt = _("Couldn't perform move ('%s'). Contact an admin.") errtxt = _("Couldn't perform move ('%s'). Contact an admin.")
if not emit_to_obj: if not emit_to_obj:
@ -708,12 +708,12 @@ class ObjectDB(TypedObject):
return False return False
# Save the old location # Save the old location
source_location = self.location source_location = _GA(self, "location")
if not source_location: if not source_location:
# there was some error in placing this room. # there was some error in placing this room.
# we have to set one or we won't be able to continue # we have to set one or we won't be able to continue
if self.home: if _GA(self, "home"):
source_location = self.home source_location = _GA(self, "home")
else: else:
default_home = ObjectDB.objects.get_id(settings.CHARACTER_DEFAULT_HOME) default_home = ObjectDB.objects.get_id(settings.CHARACTER_DEFAULT_HOME)
source_location = default_home source_location = default_home
@ -739,7 +739,7 @@ class ObjectDB(TypedObject):
# Perform move # Perform move
try: try:
self.location = destination _SA(self, "location", destination)
except Exception: except Exception:
emit_to_obj.msg(errtxt % "location change") emit_to_obj.msg(errtxt % "location change")
logger.log_trace() logger.log_trace()
@ -800,7 +800,7 @@ class ObjectDB(TypedObject):
default_home_id = int(settings.CHARACTER_DEFAULT_HOME) default_home_id = int(settings.CHARACTER_DEFAULT_HOME)
try: try:
default_home = ObjectDB.objects.get(id=default_home_id) default_home = ObjectDB.objects.get(id=default_home_id)
if default_home.dbid == self.dbid: if default_home.dbid == _GA(self, "dbid"):
# we are deleting default home! # we are deleting default home!
default_home = None default_home = None
except Exception: except Exception:
@ -811,7 +811,7 @@ class ObjectDB(TypedObject):
for obj in objs: for obj in objs:
home = obj.home home = obj.home
# Obviously, we can't send it back to here. # Obviously, we can't send it back to here.
if not home or (home and home.dbid == self.dbid): if not home or (home and home.dbid == _GA(self, "dbid")):
obj.home = default_home obj.home = default_home
# If for some reason it's still None... # If for some reason it's still None...
@ -850,9 +850,9 @@ class ObjectDB(TypedObject):
returns the new clone name on the form keyXX returns the new clone name on the form keyXX
""" """
key = self.key key = _GA(self, "key")
num = 1 num = 1
for obj in (obj for obj in self.location.contents for obj in (obj for obj in _GA(_GA(self, "location"), "contents")
if obj.key.startswith(key) and obj.key.lstrip(key).isdigit()): if obj.key.startswith(key) and obj.key.lstrip(key).isdigit()):
num += 1 num += 1
return "%s%02i" % (key, num) return "%s%02i" % (key, num)
@ -867,7 +867,7 @@ class ObjectDB(TypedObject):
objects to their respective home locations, as well as clean objects to their respective home locations, as well as clean
up all exits to/from the object. up all exits to/from the object.
""" """
if self.delete_iter > 0: if _GA(self, "delete_iter") > 0:
# make sure to only call delete once on this object # make sure to only call delete once on this object
# (avoid recursive loops) # (avoid recursive loops)
return False return False
@ -876,22 +876,22 @@ class ObjectDB(TypedObject):
# this is an extra pre-check # this is an extra pre-check
# run before deletion mechanism # run before deletion mechanism
# is kicked into gear. # is kicked into gear.
self.delete_iter == 0 _SA(self, "delete_iter", 0)
return False return False
self.delete_iter += 1 self.delete_iter += 1
# See if we need to kick the player off. # See if we need to kick the player off.
for session in self.sessions: for session in _GA(self, "sessions"):
session.msg(_("Your character %s has been destroyed.") % self.name) session.msg(_("Your character %s has been destroyed.") % _GA(self, "key"))
# no need to disconnect, Player just jumps to OOC mode. # no need to disconnect, Player just jumps to OOC mode.
# sever the connection (important!) # sever the connection (important!)
if object.__getattribute__(self, 'player') and self.player: if _GA(self, 'player'):
self.player.character = None _SA(_GA(self, "player"), "character", None)
self.player = None _SA(self, "player", None)
for script in self.scripts.all(): for script in _GA(self, "scripts").all():
script.stop() script.stop()
# if self.player: # if self.player:
@ -899,12 +899,12 @@ class ObjectDB(TypedObject):
# self.player.user.save( # self.player.user.save(
# Destroy any exits to and from this room, if any # Destroy any exits to and from this room, if any
self.clear_exits() _GA(self, "clear_exits")()
# Clear out any non-exit objects located within the object # Clear out any non-exit objects located within the object
self.clear_contents() _GA(self, "clear_contents")()
# clear current location's content cache of this object # clear current location's content cache of this object
if self.location: if _GA(self, "location"):
self.location.contents_update(self, remove=True) _GA(self, "location").contents_update(self, remove=True)
# Perform the deletion of the object # Perform the deletion of the object
super(ObjectDB, self).delete() super(ObjectDB, self).delete()
return True return True

View file

@ -101,7 +101,7 @@ DEFAULT_NCLIENTS = 1
# time between each 'tick', in seconds, if not set on command # time between each 'tick', in seconds, if not set on command
# line. All launched clients will be called upon to possibly do an # line. All launched clients will be called upon to possibly do an
# action with this frequency. # action with this frequency.
DEFAULT_TIMESTEP = 5 DEFAULT_TIMESTEP = 2
# Port to use, if not specified on command line # Port to use, if not specified on command line
DEFAULT_PORT = settings.TELNET_PORTS[0] DEFAULT_PORT = settings.TELNET_PORTS[0]
# chance of an action happening, per timestep. This helps to # chance of an action happening, per timestep. This helps to