Various fixes and debugging of weak-ref changes
This commit is contained in:
parent
0030530021
commit
63c099c22f
6 changed files with 24 additions and 81 deletions
|
|
@ -262,6 +262,7 @@ def at_multimatch_cmd(caller, matches):
|
|||
|
||||
id1 = ""
|
||||
id2 = ""
|
||||
print "cmd.obj:", cmd, cmd.obj
|
||||
if (not (is_channel or is_exit) and
|
||||
(hasattr(cmd, 'obj') and cmd.obj != caller) and
|
||||
hasattr(cmd.obj, "key")):
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ def import_cmdset(python_path, cmdsetobj, emit_to_obj=None, no_logging=False):
|
|||
if not no_logging:
|
||||
logger.log_trace(errstring)
|
||||
if emit_to_obj and not ServerConfig.objects.conf("server_starting_mode"):
|
||||
object.__getattribute__(emit_to_obj, "msg")(errstring)
|
||||
emit_to_obj.msg(errstring)
|
||||
err_cmdset = _ErrorCmdSet()
|
||||
err_cmdset.errmessage = errstring
|
||||
return err_cmdset
|
||||
|
|
@ -254,7 +254,7 @@ class CmdSetHandler(object):
|
|||
elif path:
|
||||
cmdset = self._import_cmdset(path)
|
||||
if cmdset:
|
||||
cmdset.permanent = cmdset.key != '_ERROR_CMDSET'
|
||||
cmdset.permanent = cmdset.key != '_CMDSET_ERROR'
|
||||
self.cmdset_stack.append(cmdset)
|
||||
|
||||
# merge the stack into a new merged cmdset
|
||||
|
|
@ -290,9 +290,9 @@ class CmdSetHandler(object):
|
|||
handler. Not sure when this would be useful, but it's a 'quirk'
|
||||
that has to be documented.
|
||||
"""
|
||||
if not (isinstance(cmdset, basestring) or utils.inherits_from(cmdset, CmdSet)):
|
||||
raise Exception(_("Only CmdSets can be added to the cmdsethandler!"))
|
||||
if callable(cmdset):
|
||||
if not utils.inherits_from(cmdset, CmdSet):
|
||||
raise Exception(_("Only CmdSets can be added to the cmdsethandler!"))
|
||||
cmdset = cmdset(self.obj)
|
||||
elif isinstance(cmdset, basestring):
|
||||
# this is (maybe) a python path. Try to import from cache.
|
||||
|
|
|
|||
|
|
@ -200,11 +200,10 @@ class CmdPy(MuxCommand):
|
|||
errlist = errlist[4:]
|
||||
ret = "\n".join("{n<<< %s" % line for line in errlist if line)
|
||||
|
||||
if ret is not None:
|
||||
try:
|
||||
self.msg(ret, sessid=self.sessid)
|
||||
except TypeError:
|
||||
self.msg(ret)
|
||||
try:
|
||||
self.msg(ret, sessid=self.sessid)
|
||||
except TypeError:
|
||||
self.msg(ret)
|
||||
|
||||
|
||||
# helper function. Kept outside so it can be imported and run
|
||||
|
|
|
|||
|
|
@ -235,6 +235,8 @@ CMDSET_SESSION = "src.commands.default.cmdset_session.SessionCmdSet"
|
|||
CMDSET_CHARACTER = "src.commands.default.cmdset_character.CharacterCmdSet"
|
||||
# Command set for players without a character (ooc)
|
||||
CMDSET_PLAYER = "src.commands.default.cmdset_player.PlayerCmdSet"
|
||||
# Location to search for cmdsets if full path not given
|
||||
CMDSET_PATHS = ["game.gamesrc.commands"]
|
||||
|
||||
######################################################################
|
||||
# Typeclasses and other paths
|
||||
|
|
|
|||
|
|
@ -168,78 +168,6 @@ class SharedMemoryModelBase(ModelBase):
|
|||
create_wrapper(cls, fieldname, wrappername, editable=field.editable, foreignkey=foreignkey)
|
||||
return super(SharedMemoryModelBase, cls).__new__(cls, classname, bases, classdict, *args, **kwargs)
|
||||
|
||||
#def __init__(cls, *args, **kwargs):
|
||||
# """
|
||||
# Field shortcut creation:
|
||||
# Takes field names db_* and creates property wrappers named without the db_ prefix. So db_key -> key
|
||||
# This wrapper happens on the class level, so there is no overhead when creating objects. If a class
|
||||
# already has a wrapper of the given name, the automatic creation is skipped. Note: Remember to
|
||||
# document this auto-wrapping in the class header, this could seem very much like magic to the user otherwise.
|
||||
# """
|
||||
# super(SharedMemoryModelBase, cls).__init__(*args, **kwargs)
|
||||
# def create_wrapper(cls, fieldname, wrappername, editable=True):
|
||||
# "Helper method to create property wrappers with unique names (must be in separate call)"
|
||||
# def _get(cls, fname):
|
||||
# "Wrapper for getting database field"
|
||||
# value = _GA(cls, fieldname)
|
||||
# if type(value) in (basestring, int, float, bool):
|
||||
# return value
|
||||
# elif hasattr(value, "typeclass"):
|
||||
# return _GA(value, "typeclass")
|
||||
# return value
|
||||
# def _set_nonedit(cls, fname, value):
|
||||
# "Wrapper for blocking editing of field"
|
||||
# raise FieldError("Field %s cannot be edited." % fname)
|
||||
# def _set(cls, fname, value):
|
||||
# "Wrapper for setting database field"
|
||||
# #print "_set:", fname
|
||||
# if hasattr(value, "dbobj"):
|
||||
# value = _GA(value, "dbobj")
|
||||
# elif isinstance(value, basestring) and (value.isdigit() or value.startswith("#")):
|
||||
# # we also allow setting using dbrefs, if so we try to load the matching object.
|
||||
# # (we assume the object is of the same type as the class holding the field, if
|
||||
# # not a custom handler must be used for that field)
|
||||
# dbid = dbref(value, reqhash=False)
|
||||
# if dbid:
|
||||
# try:
|
||||
# value = cls._default_manager.get(id=dbid)
|
||||
# except ObjectDoesNotExist:
|
||||
# # maybe it is just a name that happens to look like a dbid
|
||||
# from src.utils.logger import log_trace
|
||||
# log_trace()
|
||||
# #print "_set wrapper:", fname, value, type(value), cls._get_pk_val(cls._meta)
|
||||
# _SA(cls, fname, value)
|
||||
# # only use explicit update_fields in save if we actually have a
|
||||
# # primary key assigned already (won't be set when first creating object)
|
||||
# update_fields = [fname] if _GA(cls, "_get_pk_val")(_GA(cls, "_meta")) is not None else None
|
||||
# _GA(cls, "save")(update_fields=update_fields)
|
||||
# def _del_nonedit(cls, fname):
|
||||
# "wrapper for not allowing deletion"
|
||||
# raise FieldError("Field %s cannot be edited." % fname)
|
||||
# def _del(cls, fname):
|
||||
# "Wrapper for clearing database field - sets it to None"
|
||||
# _SA(cls, fname, None)
|
||||
# update_fields = [fname] if _GA(cls, "_get_pk_val")(_GA(cls, "_meta")) is not None else None
|
||||
# _GA(cls, "save")(update_fields=update_fields)
|
||||
|
||||
# # create class field wrappers
|
||||
# fget = lambda cls: _get(cls, fieldname)
|
||||
# fset = lambda cls, val: _set(cls, fieldname, val) if editable else _set_nonedit(cls, fieldname, val)
|
||||
# fdel = lambda cls: _del(cls, fieldname) if editable else _del_nonedit(cls,fieldname)
|
||||
# type(cls).__setattr__(cls, wrappername, property(fget, fset, fdel))#, doc))
|
||||
|
||||
# # exclude some models that should not auto-create wrapper fields
|
||||
# if cls.__name__ in ("ServerConfig", "TypeNick"):
|
||||
# return
|
||||
# # dynamically create the wrapper properties for all fields not already handled
|
||||
# for field in cls._meta.fields:
|
||||
# fieldname = field.name
|
||||
# if fieldname.startswith("db_"):
|
||||
# wrappername = "dbid" if fieldname == "id" else fieldname.replace("db_", "")
|
||||
# if not hasattr(cls, wrappername):
|
||||
# # makes sure not to overload manually created wrappers on the model
|
||||
# #print "wrapping %s -> %s" % (fieldname, wrappername)
|
||||
# create_wrapper(cls, fieldname, wrappername, editable=field.editable)
|
||||
|
||||
class SharedMemoryModel(Model):
|
||||
# CL: setting abstract correctly to allow subclasses to inherit the default
|
||||
|
|
|
|||
|
|
@ -1081,3 +1081,16 @@ class LazyLoadHandler(object):
|
|||
def __unicode__(self):
|
||||
return str(_GA(self, "_instantiate")())
|
||||
|
||||
class NonWeakLazyLoadHandler(LazyLoadHandler):
|
||||
"""
|
||||
Variation of LazyLoadHandler that does not
|
||||
create a weak reference when initiating.
|
||||
"""
|
||||
def _instantiate(self):
|
||||
"""
|
||||
Initialize handler as cls(obj, *args)
|
||||
"""
|
||||
obj = _GA(self, "obj")()
|
||||
instance = _GA(self, "cls")(obj, *_GA(self, "args"))
|
||||
_SA(obj, _GA(self, "name"), instance)
|
||||
return instance
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue