Fixed some errors in channel loading.

This commit is contained in:
Griatch 2014-12-25 18:58:11 +01:00
parent dd20740e73
commit 11449f3d62
3 changed files with 17 additions and 11 deletions

View file

@ -298,7 +298,7 @@ BASE_ROOM_TYPECLASS = "src.objects.objects.DefaultRoom"
# Typeclass for Exit objects (fallback).
BASE_EXIT_TYPECLASS = "src.objects.objects.DefaultExit"
# Typeclass for Channel (fallback).
BASE_CHANNEL_TYPECLASS = "src.comms.comms.DefaultChannel"
BASE_CHANNEL_TYPECLASS = "src.comms.comms.Channel"
# Typeclass for Scripts (fallback). You usually don't need to change this
# but create custom variations of scripts on a per-case basis instead.
BASE_SCRIPT_TYPECLASS = "src.scripts.scripts.DoNothing"

View file

@ -46,7 +46,7 @@ from src.server.caches import get_prop_cache, set_prop_cache
from src.typeclasses import managers
from src.locks.lockhandler import LockHandler
from src.utils.utils import (
is_iter, to_str, inherits_from, lazy_property,
is_iter, inherits_from, lazy_property,
class_from_module)
from src.typeclasses.django_new_patch import patched_new
@ -191,7 +191,7 @@ class TypedObject(SharedMemoryModel):
else:
self.db_typeclass_path = "%s.%s" % (self.__module__, self.__class__.__name__)
# important to put this at the end since _meta is based on the set __class__
self.__dbclass__ = self._meta.proxy_for_model
self.__dbclass__ = self._meta.proxy_for_model or self.__class__
# initialize all handlers in a lazy fashion
@lazy_property
@ -348,6 +348,7 @@ class TypedObject(SharedMemoryModel):
"right type instead." % self.key)
self.typeclass_path = new_typeclass.path
self.__class__ = new_typeclass
if clean_attributes:
# Clean out old attributes

View file

@ -933,24 +933,29 @@ def class_from_module(path, defaultpaths=None):
"""
cls = None
if defaultpaths:
paths = [path] + make_iter(defaultpaths) if defaultpaths else []
paths = [path] + ["%s.%s" % (dpath, path) for dpath in make_iter(defaultpaths)] if defaultpaths else []
else:
paths = [path]
for path in paths:
path, clsname = path.rsplit(".", 1)
for testpath in paths:
if "." in path:
testpath, clsname = testpath.rsplit(".", 1)
else:
testpath, clsname = ".", testpath
try:
mod = import_module(path)
mod = import_module(testpath)
except ImportError, ex:
# normally this is due to a not-found property
if not str(ex).startswith ("No module named %s" % path):
raise ex
if not str(ex).startswith("No module named"):
exc = sys.exc_info()
raise exc[1], None, exc[2]
try:
cls = getattr(mod, clsname)
break
except AttributeError, ex:
if not str(ex).startswith("Object 'module' has no attribute '%s'" % clsname):
raise ex
if not str(ex).startswith("'module' object has no attribute '%s'" % clsname):
exc = sys.exc_info()
raise exc[1], None, exc[2]
if not cls:
raise ImportError("Could not load typeclass '%s'." % path)
return cls