aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/properties.py
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-06-19 14:42:15 -0400
committerW. Trevor King <wking@drexel.edu>2009-06-19 14:42:15 -0400
commit89b2ba997492895328203c3d80cfd8a66dd17363 (patch)
tree7e2eaf73205bf83a6d78dcc6880d9489729ee486 /libbe/properties.py
parent8949c86542fcabbe1ddea8e9936c4436698654db (diff)
parentbd8d5fdc0d37970824daac68f8d7c76975e9d36d (diff)
downloadbugseverywhere-89b2ba997492895328203c3d80cfd8a66dd17363.tar.gz
Merged Thomas Habets 2009-01-07 XML output for "be show".
I rewrote a few of his routines, e.g. generalizing Comment.string_thread to run a caller-specified method avoided the need for some duplicate code in Comment.xml_thread. There was also a reasonable reorganization of libbe.settings_object.versioned_property because the <in_reply_to> field of the Comment.xml output was giving me `-1' (= old settings_object.EMPTY) instead of None, even after I had set comm.in_reply_to to None. The rewritten versioned_property avoids the ambiguity of UNPRIMED vs EMPTY, and avoids the stupididy of my using EMPTY=-1 ;).
Diffstat (limited to 'libbe/properties.py')
-rw-r--r--libbe/properties.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/libbe/properties.py b/libbe/properties.py
index 176e898..a8e89fb 100644
--- a/libbe/properties.py
+++ b/libbe/properties.py
@@ -28,6 +28,7 @@ for more information on decorators.
import unittest
+
class ValueCheckError (ValueError):
def __init__(self, name, value, allowed):
msg = "%s not in %s for %s" % (value, allowed, name)
@@ -65,10 +66,11 @@ def doc_property(doc=None):
return funcs
return decorator
-def local_property(name):
+def local_property(name, null=None):
"""
Define get/set access to per-parent-instance local storage. Uses
._<name>_value to store the value for a particular owner instance.
+ If the ._<name>_value attribute does not exist, returns null.
"""
def decorator(funcs):
if hasattr(funcs, "__call__"):
@@ -78,7 +80,7 @@ def local_property(name):
def _fget(self):
if fget is not None:
fget(self)
- value = getattr(self, "_%s_value" % name, None)
+ value = getattr(self, "_%s_value" % name, null)
return value
def _fset(self, value):
setattr(self, "_%s_value" % name, value)
@@ -90,7 +92,7 @@ def local_property(name):
return funcs
return decorator
-def settings_property(name):
+def settings_property(name, null=None):
"""
Similar to local_property, except where local_property stores the
value in instance._<name>_value, settings_property stores the
@@ -104,7 +106,7 @@ def settings_property(name):
def _fget(self):
if fget is not None:
fget(self)
- value = self.settings.get(name, None)
+ value = self.settings.get(name, null)
return value
def _fset(self, value):
self.settings[name] = value