Remove unreachable code, PEP 8 whitespace,

mark debug code in comments
This commit is contained in:
BlauFeuer 2017-03-03 20:48:25 -05:00 committed by Griatch
parent 08670008ad
commit e762441d4d

View file

@ -24,11 +24,12 @@ from evennia.utils.utils import lazy_property, to_str, make_iter
_TYPECLASS_AGGRESSIVE_CACHE = settings.TYPECLASS_AGGRESSIVE_CACHE _TYPECLASS_AGGRESSIVE_CACHE = settings.TYPECLASS_AGGRESSIVE_CACHE
#------------------------------------------------------------ # -------------------------------------------------------------
# #
# Attributes # Attributes
# #
#------------------------------------------------------------ # -------------------------------------------------------------
class Attribute(SharedMemoryModel): class Attribute(SharedMemoryModel):
""" """
@ -110,12 +111,15 @@ class Attribute(SharedMemoryModel):
def __lock_storage_get(self): def __lock_storage_get(self):
return self.db_lock_storage return self.db_lock_storage
def __lock_storage_set(self, value): def __lock_storage_set(self, value):
self.db_lock_storage = value self.db_lock_storage = value
self.save(update_fields=["db_lock_storage"]) self.save(update_fields=["db_lock_storage"])
def __lock_storage_del(self): def __lock_storage_del(self):
self.db_lock_storage = "" self.db_lock_storage = ""
self.save(update_fields=["db_lock_storage"]) self.save(update_fields=["db_lock_storage"])
lock_storage = property(__lock_storage_get, __lock_storage_set, __lock_storage_del) lock_storage = property(__lock_storage_get, __lock_storage_set, __lock_storage_del)
# Wrapper properties to easily set database fields. These are # Wrapper properties to easily set database fields. These are
@ -144,12 +148,12 @@ class Attribute(SharedMemoryModel):
see self.__value_get. see self.__value_get.
""" """
self.db_value = to_pickle(new_value) self.db_value = to_pickle(new_value)
#print "value_set, self.db_value:", repr(self.db_value) # print("value_set, self.db_value:", repr(self.db_value)) # DEBUG
self.save(update_fields=["db_value"]) self.save(update_fields=["db_value"])
# @value.deleter # @value.deleter
def __value_del(self): def __value_del(self):
"Deleter. Allows for del attr.value. This removes the entire attribute." """Deleter. Allows for del attr.value. This removes the entire attribute."""
self.delete() self.delete()
value = property(__value_get, __value_set, __value_del) value = property(__value_get, __value_set, __value_del)
@ -202,7 +206,7 @@ class AttributeHandler(object):
_attrtype = None _attrtype = None
def __init__(self, obj): def __init__(self, obj):
"Initialize handler." """Initialize handler."""
self.obj = obj self.obj = obj
self._objid = obj.id self._objid = obj.id
self._model = to_str(obj.__dbclass__.__name__.lower()) self._model = to_str(obj.__dbclass__.__name__.lower())
@ -213,7 +217,7 @@ class AttributeHandler(object):
self._cache_complete = False self._cache_complete = False
def _fullcache(self): def _fullcache(self):
"Cache all attributes of this object" """Cache all attributes of this object"""
query = {"%s__id" % self._model: self._objid, query = {"%s__id" % self._model: self._objid,
"attribute__db_model": self._model, "attribute__db_model": self._model,
"attribute__db_attrtype": self._attrtype} "attribute__db_attrtype": self._attrtype}
@ -297,8 +301,8 @@ class AttributeHandler(object):
"attribute__db_model": self._model, "attribute__db_model": self._model,
"attribute__db_attrtype": self._attrtype, "attribute__db_attrtype": self._attrtype,
"attribute__db_category__iexact": category.lower() if category else None} "attribute__db_category__iexact": category.lower() if category else None}
attrs = [conn.attribute for conn in getattr(self.obj, attrs = [conn.attribute for conn
self._m2m_fieldname).through.objects.filter(**query)] in getattr(self.obj, self._m2m_fieldname).through.objects.filter(**query)]
for attr in attrs: for attr in attrs:
if attr.pk: if attr.pk:
cachekey = "%s-%s" % (attr.db_key, category) cachekey = "%s-%s" % (attr.db_key, category)
@ -306,7 +310,6 @@ class AttributeHandler(object):
# mark category cache as up-to-date # mark category cache as up-to-date
self._catcache[catkey] = True self._catcache[catkey] = True
return attrs return attrs
return []
def _setcache(self, key, category, attr_obj): def _setcache(self, key, category, attr_obj):
""" """
@ -402,6 +405,7 @@ class AttributeHandler(object):
accessing_obj (object, optional): If set, an `attrread` accessing_obj (object, optional): If set, an `attrread`
permission lock will be checked before returning each permission lock will be checked before returning each
looked-after Attribute. looked-after Attribute.
default_access (bool, optional):
Returns: Returns:
result (any, Attribute or list): This will be the value of the found result (any, Attribute or list): This will be the value of the found
@ -416,7 +420,7 @@ class AttributeHandler(object):
""" """
class RetDefault(object): class RetDefault(object):
"Holds default values" """Holds default values"""
def __init__(self): def __init__(self):
self.key = None self.key = None
self.value = default self.value = default
@ -446,7 +450,6 @@ class AttributeHandler(object):
return ret if len(key) > 1 else default return ret if len(key) > 1 else default
return ret[0] if len(ret) == 1 else ret return ret[0] if len(ret) == 1 else ret
def add(self, key, value, category=None, lockstring="", def add(self, key, value, category=None, lockstring="",
strattr=False, accessing_obj=None, default_access=True): strattr=False, accessing_obj=None, default_access=True):
""" """
@ -470,8 +473,7 @@ class AttributeHandler(object):
`attrcreate` is defined on the Attribute in question. `attrcreate` is defined on the Attribute in question.
""" """
if accessing_obj and not self.obj.access(accessing_obj, if accessing_obj and not self.obj.access(accessing_obj, self._attrcreate, default=default_access):
self._attrcreate, default=default_access):
# check create access # check create access
return return
@ -506,7 +508,6 @@ class AttributeHandler(object):
# update cache # update cache
self._setcache(keystr, category, new_attr) self._setcache(keystr, category, new_attr)
def batch_add(self, key, value, category=None, lockstring="", def batch_add(self, key, value, category=None, lockstring="",
strattr=False, accessing_obj=None, default_access=True): strattr=False, accessing_obj=None, default_access=True):
""" """
@ -535,8 +536,7 @@ class AttributeHandler(object):
RuntimeError: If `key` and `value` lists are not of the RuntimeError: If `key` and `value` lists are not of the
same lengths. same lengths.
""" """
if accessing_obj and not self.obj.access(accessing_obj, if accessing_obj and not self.obj.access(accessing_obj, self._attrcreate, default=default_access):
self._attrcreate, default=default_access):
# check create access # check create access
return return
@ -578,7 +578,6 @@ class AttributeHandler(object):
# Add new objects to m2m field all at once # Add new objects to m2m field all at once
getattr(self.obj, self._m2m_fieldname).add(*new_attrobjs) getattr(self.obj, self._m2m_fieldname).add(*new_attrobjs)
def remove(self, key, raise_exception=False, category=None, def remove(self, key, raise_exception=False, category=None,
accessing_obj=None, default_access=True): accessing_obj=None, default_access=True):
""" """
@ -729,7 +728,6 @@ def initialize_nick_templates(in_template, out_template):
""" """
# create the regex for in_template # create the regex for in_template
regex_string = fnmatch.translate(in_template) regex_string = fnmatch.translate(in_template)
# we must account for a possible line break coming over the wire # we must account for a possible line break coming over the wire