[Zope3-checkins] SVN: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/rwproperty.py add missing file

Benji York benji at zope.com
Sat Aug 19 22:37:26 EDT 2006


Log message for revision 69703:
  add missing file
  

Changed:
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/rwproperty.py

-=-
Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/rwproperty.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/rwproperty.py	2006-08-20 01:43:23 UTC (rev 69702)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/rwproperty.py	2006-08-20 02:37:26 UTC (rev 69703)
@@ -0,0 +1,75 @@
+# Read & write properties
+#
+# Copyright (c) 2006 by Philipp "philiKON" von Weitershausen
+#                       philikon at philikon.de
+#
+# Freely distributable under the terms of the Zope Public License, v2.1.
+#
+# See rwproperty.txt for detailed explanations
+#
+import sys
+
+__all__ = ['getproperty', 'setproperty', 'delproperty']
+
+class rwproperty(object):
+
+    def __new__(cls, func):
+        name = func.__name__
+
+        # ugly, but common hack
+        frame = sys._getframe(1)
+        locals = frame.f_locals
+
+        if name not in locals:
+            return cls.createProperty(func)
+
+        oldprop = locals[name]
+        if isinstance(oldprop, property):
+            return cls.enhanceProperty(oldprop, func)
+
+        raise TypeError("read & write properties cannot be mixed with "
+                        "other attributes except regular property objects.")
+
+    # this might not be particularly elegant, but it's easy on the eyes
+
+    @staticmethod
+    def createProperty(func):
+        raise NotImplementedError
+
+    @staticmethod
+    def enhanceProperty(oldprop, func):
+        raise NotImplementedError
+
+class getproperty(rwproperty):
+
+    @staticmethod
+    def createProperty(func):
+        return property(func)
+
+    @staticmethod
+    def enhanceProperty(oldprop, func):
+        return property(func, oldprop.fset, oldprop.fdel)
+
+class setproperty(rwproperty):
+
+    @staticmethod
+    def createProperty(func):
+        return property(None, func)
+
+    @staticmethod
+    def enhanceProperty(oldprop, func):
+        return property(oldprop.fget, func, oldprop.fdel)
+
+class delproperty(rwproperty):
+
+    @staticmethod
+    def createProperty(func):
+        return property(None, None, func)
+
+    @staticmethod
+    def enhanceProperty(oldprop, func):
+        return property(oldprop.fget, oldprop.fset, func)
+
+if __name__ == "__main__":
+    import doctest
+    doctest.testfile('rwproperty.txt')


Property changes on: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/rwproperty.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the Zope3-Checkins mailing list