summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHans Ulrich Niedermann <hun@n-dimensional.de>2008-06-28 10:20:37 +0200
committerHans Ulrich Niedermann <hun@n-dimensional.de>2008-07-15 12:28:54 +0200
commita911dd60217156dac742226853c186f31047aede (patch)
tree39988f9b53a9b6a53b19efc1a5963bef1e84b482 /src
parent4a5d08030158b081e612790f2736ddf2632123ff (diff)
downloadnbb-a911dd60217156dac742226853c186f31047aede.tar.gz
nbb-a911dd60217156dac742226853c186f31047aede.tar.xz
nbb-a911dd60217156dac742226853c186f31047aede.zip
Store property values in instance, not prop obj
Diffstat (limited to 'src')
-rw-r--r--src/nbblib/main.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/nbblib/main.py b/src/nbblib/main.py
index 46dbd41..3348e27 100644
--- a/src/nbblib/main.py
+++ b/src/nbblib/main.py
@@ -150,28 +150,35 @@ class InvalidPropertyValue(Exception):
class Property(object):
- def __init__(self, **kwargs):
+ def __init__(self, *args, **kwargs):
+ assert(len(args) == 0)
if kwargs.has_key('default'):
self.default = kwargs['default']
+ valid_kwargs = ('default',)
+ for kwa in kwargs.iterkeys():
+ assert(kwa in valid_kwargs)
+ self.name = "property-%08x" % hash(self)
def __get__(self, instance, owner):
# print "Property.__get__", instance, owner
- if hasattr(self, 'value'):
- return self.value
+ if hasattr(instance, self.name):
+ return getattr(instance, self.name)
elif hasattr(self, 'default'):
return self.default
else:
return None
def __set__(self, instance, value):
# print "Property.__set__", instance, value
- if hasattr(self, 'value'):
+ if hasattr(instance, self.name):
raise PropertySetAgainError()
elif not self.isvalid(value):
raise InvalidPropertyValue
else:
- self.value = self.convert(value)
+ setattr(instance, self.name, self.convert(value))
def __str__(self):
- if hasattr(self, 'value'):
- return self.value
+ if hasattr(instance, self.name):
+ return getattr(instance, self.name)
+ elif hasattr(self, 'default'):
+ return '<property defaulting to %s>' % self.default
else:
return '<undefined property>'
def isvalid(self, value):