mirror of
https://github.com/evennia/evennia.git
synced 2026-03-22 15:56:30 +01:00
Cleaning some unnecessary whitespace, overall cleanup of various source codes.
This commit is contained in:
parent
d4c97d7df8
commit
c0322c9eae
27 changed files with 1342 additions and 1318 deletions
|
|
@ -7,7 +7,7 @@ with a 'normal' Python class. The only restrictions is that
|
|||
the typeclass must inherit from TypeClass and not reimplement
|
||||
the get/setters defined below. There are also a few properties
|
||||
that are protected, so as to not overwrite property names
|
||||
used by the typesystem or django itself.
|
||||
used by the typesystem or django itself.
|
||||
"""
|
||||
|
||||
from src.utils.logger import log_trace, log_errmsg
|
||||
|
|
@ -45,12 +45,9 @@ class MetaTypeClass(type):
|
|||
mcs.typename = mcs.__name__
|
||||
mcs.path = "%s.%s" % (mcs.__module__, mcs.__name__)
|
||||
|
||||
|
||||
|
||||
|
||||
def __str__(cls):
|
||||
return "%s" % cls.__name__
|
||||
|
||||
|
||||
class TypeClass(object):
|
||||
"""
|
||||
This class implements a 'typeclass' object. This is connected
|
||||
|
|
@ -58,14 +55,14 @@ class TypeClass(object):
|
|||
the TypeClass allows for all customization.
|
||||
Most of the time this means that the admin never has to
|
||||
worry about database access but only deal with extending
|
||||
TypeClasses to create diverse objects in the game.
|
||||
TypeClasses to create diverse objects in the game.
|
||||
|
||||
The ObjectType class has all functionality for wrapping a
|
||||
database object transparently.
|
||||
database object transparently.
|
||||
|
||||
It's up to its child classes to implement eventual custom hooks
|
||||
and other functions called by the engine.
|
||||
|
||||
and other functions called by the engine.
|
||||
|
||||
"""
|
||||
__metaclass__ = MetaTypeClass
|
||||
|
||||
|
|
@ -73,8 +70,8 @@ class TypeClass(object):
|
|||
"""
|
||||
Initialize the object class. There are two ways to call this class.
|
||||
o = object_class(dbobj) : this is used to initialize dbobj with the class name
|
||||
o = dbobj.object_class(dbobj) : this is used when dbobj.object_class is already set.
|
||||
|
||||
o = dbobj.object_class(dbobj) : this is used when dbobj.object_class is already set.
|
||||
|
||||
"""
|
||||
# typecheck of dbobj - we can't allow it to be added here
|
||||
# unless it's really a TypedObject.
|
||||
|
|
@ -84,7 +81,7 @@ class TypeClass(object):
|
|||
raise Exception("dbobj is not a TypedObject: %s: %s" % (dbobj_cls, dbobj_mro))
|
||||
|
||||
# store the reference to the database model instance
|
||||
SA(self, 'dbobj', dbobj)
|
||||
SA(self, 'dbobj', dbobj)
|
||||
|
||||
def __getattribute__(self, propname):
|
||||
"""
|
||||
|
|
@ -93,7 +90,7 @@ class TypeClass(object):
|
|||
self.dbobj. Note that dbobj properties have
|
||||
priority, so if you define a same-named
|
||||
property on the class, it will NOT be
|
||||
accessible through getattr.
|
||||
accessible through getattr.
|
||||
"""
|
||||
if propname == 'dbobj':
|
||||
return GA(self, 'dbobj')
|
||||
|
|
@ -101,7 +98,7 @@ class TypeClass(object):
|
|||
# python specials are parsed as-is (otherwise things like
|
||||
# isinstance() fail to identify the typeclass)
|
||||
return GA(self, propname)
|
||||
#print "get %s (dbobj:%s)" % (propname, type(dbobj))
|
||||
#print "get %s (dbobj:%s)" % (propname, type(dbobj))
|
||||
try:
|
||||
return GA(self, propname)
|
||||
except AttributeError:
|
||||
|
|
@ -109,7 +106,7 @@ class TypeClass(object):
|
|||
dbobj = GA(self, 'dbobj')
|
||||
except AttributeError:
|
||||
log_trace("Typeclass CRITICAL ERROR! dbobj not found for Typeclass %s!" % self)
|
||||
raise
|
||||
raise
|
||||
try:
|
||||
return GA(dbobj, propname)
|
||||
except AttributeError:
|
||||
|
|
@ -118,31 +115,31 @@ class TypeClass(object):
|
|||
except AttributeError:
|
||||
string = "Object: '%s' not found on %s(%s), nor on its typeclass %s."
|
||||
raise AttributeError(string % (propname, dbobj, dbobj.dbref, dbobj.typeclass_path))
|
||||
|
||||
|
||||
def __setattr__(self, propname, value):
|
||||
"""
|
||||
Transparently save data to the dbobj object in
|
||||
all situations. Note that this does not
|
||||
necessarily mean storing it to the database
|
||||
unless data is stored into a propname
|
||||
corresponding to a field on ObjectDB model.
|
||||
corresponding to a field on ObjectDB model.
|
||||
"""
|
||||
#print "set %s -> %s" % (propname, value)
|
||||
if propname in PROTECTED:
|
||||
string = "%s: '%s' is a protected attribute name."
|
||||
string = "%s: '%s' is a protected attribute name."
|
||||
string += " (protected: [%s])" % (", ".join(PROTECTED))
|
||||
log_errmsg(string % (self.name, propname))
|
||||
return
|
||||
return
|
||||
|
||||
try:
|
||||
dbobj = GA(self, 'dbobj')
|
||||
except AttributeError:
|
||||
dbobj = None
|
||||
log_trace("This is probably due to an unsafe reload.")
|
||||
|
||||
if dbobj:
|
||||
dbobj = None
|
||||
log_trace("This is probably due to an unsafe reload.")
|
||||
|
||||
if dbobj:
|
||||
try:
|
||||
# only set value on propname if propname already exists
|
||||
# only set value on propname if propname already exists
|
||||
# on dbobj. __getattribute__ will raise attribute error otherwise.
|
||||
GA(dbobj, propname)
|
||||
SA(dbobj, propname, value)
|
||||
|
|
@ -154,25 +151,25 @@ class TypeClass(object):
|
|||
def __eq__(self, other):
|
||||
"""
|
||||
dbobj-recognized comparison
|
||||
"""
|
||||
"""
|
||||
try:
|
||||
return other == self or other == GA(self, dbobj) or other == GA(self, dbobj).user
|
||||
except AttributeError:
|
||||
# if self.dbobj.user fails it means the two previous comparisons failed already
|
||||
return False
|
||||
|
||||
|
||||
|
||||
def __delattr__(self, propname):
|
||||
"""
|
||||
Transparently deletes data from the typeclass or dbobj by first searching on the typeclass,
|
||||
secondly on the dbobj.db.
|
||||
Will not allow deletion of properties stored directly on dbobj.
|
||||
Will not allow deletion of properties stored directly on dbobj.
|
||||
"""
|
||||
if propname in PROTECTED:
|
||||
string = "%s: '%s' is a protected attribute name."
|
||||
string = "%s: '%s' is a protected attribute name."
|
||||
string += " (protected: [%s])" % (", ".join(PROTECTED))
|
||||
log_errmsg(string % (self.name, propname))
|
||||
return
|
||||
return
|
||||
|
||||
try:
|
||||
DA(self, propname)
|
||||
|
|
@ -181,10 +178,10 @@ class TypeClass(object):
|
|||
try:
|
||||
dbobj = GA(self, 'dbobj')
|
||||
except AttributeError:
|
||||
log_trace("This is probably due to an unsafe reload.")
|
||||
return # ignore delete
|
||||
log_trace("This is probably due to an unsafe reload.")
|
||||
return # ignore delete
|
||||
try:
|
||||
dbobj.del_attribute_raise(propname)
|
||||
dbobj.del_attribute_raise(propname)
|
||||
except AttributeError:
|
||||
string = "Object: '%s' not found on %s(%s), nor on its typeclass %s."
|
||||
raise AttributeError(string % (propname, dbobj,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue