diff --git a/src/objects/objects.py b/src/objects/objects.py index 5d14135528..8c7190b497 100644 --- a/src/objects/objects.py +++ b/src/objects/objects.py @@ -14,11 +14,13 @@ That an object is controlled by a player/user is just defined by its 'user' property being set. This means a user may switch which object they control by simply linking to a new object's user property. """ + +from django.conf import settings from src.typeclasses.typeclass import TypeClass from src.commands.cmdsethandler import CmdSetHandler from src.scripts.scripthandler import ScriptHandler -#from src.permissions.permissions import has_perm from src.objects.exithandler import EXITHANDLER +from src.utils import utils # # Base class to inherit from. @@ -48,12 +50,13 @@ class Object(TypeClass): try: dummy = object.__getattribute__(dbobj, 'scripts') create_scripts = type(dbobj.scripts) != ScriptHandler + except AttributeError: create_scripts = True if create_cmdset: dbobj.cmdset = CmdSetHandler(dbobj) - if dbobj.player: - dbobj.cmdset.outside_access = False + if utils.inherits_from(self, settings.BASE_CHARACTER_TYPECLASS): + dbobj.cmdset.outside_access = False if create_scripts: dbobj.scripts = ScriptHandler(dbobj) diff --git a/src/utils/utils.py b/src/utils/utils.py index 1ad9e5f445..15b8283d35 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -249,3 +249,29 @@ def validate_email_address(emailaddress): return True # Email address is fine. else: return False # Email address has funny characters. + + +def inherits_from(obj, parent): + """ + Takes an object and tries to determine if it inherits + from parent. What differs this function from e.g. isinstance() + is that obj may be both an instance and a class, and parent + may be an instance, a class, or the python path to a class (counting + from the evennia root directory). + """ + + if callable(obj): + # this is a class + obj_paths = ["%s.%s" % (mod.__module__, mod.__name__) for mod in obj.mro()] + else: + obj_paths = ["%s.%s" % (mod.__module__, mod.__name__) for mod in obj.__class__.mro()] + + if isinstance(parent, basestring): + # a given string path, for direct matching + parent_path = parent + elif callable(parent): + # this is a class + parent_path = "%s.%s" % (parent.__module__, parent.__name__) + else: + parent_path = "%s.%s" % (parent.__class__.__module__, parent.__class__.__name__) + return any(True for obj_path in obj_paths if obj_path == parent_path)