[Checkins] SVN: Sandbox/malthe/zope.container/s Depend on zope.cachedescriptors to get the property-module from there. The 3.4.0-release does depend on ZODB, but this has been changed in svn.

Malthe Borch mborch at gmail.com
Tue Apr 22 08:46:05 EDT 2008


Log message for revision 85593:
  Depend on zope.cachedescriptors to get the property-module from there. The 3.4.0-release does depend on ZODB, but this has been changed in svn.

Changed:
  U   Sandbox/malthe/zope.container/setup.py
  U   Sandbox/malthe/zope.container/src/zope/container/constraints.py
  D   Sandbox/malthe/zope.container/src/zope/container/property.py
  D   Sandbox/malthe/zope.container/src/zope/container/property.txt
  D   Sandbox/malthe/zope.container/src/zope/container/tests/test_property.py

-=-
Modified: Sandbox/malthe/zope.container/setup.py
===================================================================
--- Sandbox/malthe/zope.container/setup.py	2008-04-22 12:37:09 UTC (rev 85592)
+++ Sandbox/malthe/zope.container/setup.py	2008-04-22 12:46:00 UTC (rev 85593)
@@ -60,6 +60,7 @@
                         'zope.location',
                         'zope.lifecycleevent',
                         'zope.deprecation',
+                        'zope.cachedescriptors',
                         ],
       include_package_data = True,
       zip_safe = False,

Modified: Sandbox/malthe/zope.container/src/zope/container/constraints.py
===================================================================
--- Sandbox/malthe/zope.container/src/zope/container/constraints.py	2008-04-22 12:37:09 UTC (rev 85592)
+++ Sandbox/malthe/zope.container/src/zope/container/constraints.py	2008-04-22 12:46:00 UTC (rev 85593)
@@ -153,7 +153,7 @@
 
 import sys
 
-from zope.container.property import readproperty
+from zope.cachedescriptors.property import readproperty
 from zope.dottedname.resolve import resolve
 import zope.schema
 from zope.interface import providedBy

Deleted: Sandbox/malthe/zope.container/src/zope/container/property.py
===================================================================
--- Sandbox/malthe/zope.container/src/zope/container/property.py	2008-04-22 12:37:09 UTC (rev 85592)
+++ Sandbox/malthe/zope.container/src/zope/container/property.py	2008-04-22 12:46:00 UTC (rev 85593)
@@ -1,106 +0,0 @@
-##############################################################################
-# Copyright (c) 2008 Zope Corporation and Contributors.
-# All Rights Reserved.
-# 
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-##############################################################################
-"""Cached properties
-
-See the CachedProperty class.
-
-$Id$
-"""
-
-ncaches = 0l
-
-
-class CachedProperty(object):
-    """Cached Properties.
-    """
-
-    def __init__(self, func, *names):
-        global ncaches
-        ncaches += 1
-        self.data = (func, names,
-                     "_v_cached_property_key_%s" % ncaches,
-                     "_v_cached_property_value_%s" % ncaches)
-
-    def __get__(self, inst, class_):
-        if inst is None:
-            return self
-
-        func, names, key_name, value_name = self.data
-
-        key = names and [getattr(inst, name) for name in names]
-        value = getattr(inst, value_name, self)
-
-        if value is not self:
-            # We have a cached value
-            if key == getattr(inst, key_name, self):
-                # Cache is still good!
-                return value
-
-        # We need to compute and cache the value
-
-        value = func(inst)
-        setattr(inst, key_name, key)
-        setattr(inst, value_name, value)
-
-        return value
-
-
-class Lazy(object):
-    """Lazy Attributes.
-    """
-
-    def __init__(self, func, name=None):
-        if name is None:
-            name = func.__name__
-        self.data = (func, name)
-
-    def __get__(self, inst, class_):
-        if inst is None:
-            return self
-
-        func, name = self.data
-        value = func(inst)
-        inst.__dict__[name] = value
-
-        return value
-
-
-class readproperty(object):
-
-    def __init__(self, func):
-        self.func = func
-
-    def __get__(self, inst, class_):
-        if inst is None:
-            return self
-
-        func = self.func
-        return func(inst)
-
-
-class cachedIn(object):
-    """Cached property with given cache attribute."""
-
-    def __init__(self, attribute_name):
-        self.attribute_name = attribute_name
-
-    def __call__(self, func):
-
-        def get(instance):
-            try:
-                value = getattr(instance, self.attribute_name)
-            except AttributeError:
-                value = func(instance)
-                setattr(instance, self.attribute_name, value)
-            return value
-
-        return property(get)

Deleted: Sandbox/malthe/zope.container/src/zope/container/property.txt
===================================================================
--- Sandbox/malthe/zope.container/src/zope/container/property.txt	2008-04-22 12:37:09 UTC (rev 85592)
+++ Sandbox/malthe/zope.container/src/zope/container/property.txt	2008-04-22 12:46:00 UTC (rev 85593)
@@ -1,208 +0,0 @@
-Cached Properties
-=================
-
-Cached properties are computed properties that cache their computed
-values.  They take into account instance attributes that they depend
-on, so when the instance attributes change, the properties will change
-the values they return.
-
-Cached properties cache their data in _v_ attributes, so they are
-also useful for managing the computation of volatile attributes for
-persistent objects. Let's look at an example::
-
-    >>> from zope.container import property
-    >>> import math
-
-    >>> class Point:
-    ... 
-    ...     def __init__(self, x, y):
-    ...         self.x, self.y = x, y
-    ...
-    ...     def radius(self):
-    ...         print 'computing radius'
-    ...         return math.sqrt(self.x**2 + self.y**2)
-    ...     radius = property.CachedProperty(radius, 'x', 'y')
-
-    >>> point = Point(1.0, 2.0)   
-
-If we ask for the radius the first time::
-
-    >>> '%.2f' % point.radius
-    computing radius
-    '2.24'
-
-We see that the radius function is called, but if we ask for it again::
-
-    >>> '%.2f' % point.radius
-    '2.24'
-
-The function isn't called.  If we change one of the attribute the
-radius depends on, it will be recomputed::
-
-    >>> point.x = 2.0
-    >>> '%.2f' % point.radius
-    computing radius
-    '2.83'
-
-But changing other attributes doesn't cause recomputation::
-
-    >>> point.q = 1
-    >>> '%.2f' % point.radius
-    '2.83'
-
-Note that we don't have any non-volitile attributes added::
-
-    >>> names = [name for name in point.__dict__ if not name.startswith('_v_')]
-    >>> names.sort()
-    >>> names
-    ['q', 'x', 'y']
-
-
-Lazy Computed Attributes
-------------------------
-
-The `property` module provides another descriptor that supports a
-slightly different caching model: lazy attributes.  Like cached
-proprties, they are computed the first time they are used. however,
-they aren't stored in volatile attributes and they aren't
-automatically updated when other attributes change.  Furthermore, the
-store their data using their attribute name, thus overriding
-themselves. This provides much faster attribute access after the
-attribute has been computed. Let's look at the previous example using
-lazy attributes::
-
-    >>> class Point:
-    ... 
-    ...     def __init__(self, x, y):
-    ...         self.x, self.y = x, y
-    ...
-    ...     def radius(self):
-    ...         print 'computing radius'
-    ...         return math.sqrt(self.x**2 + self.y**2)
-    ...     radius = property.Lazy(radius)
-
-    >>> point = Point(1.0, 2.0)   
-
-If we ask for the radius the first time::
-
-    >>> '%.2f' % point.radius
-    computing radius
-    '2.24'
-
-We see that the radius function is called, but if we ask for it again::
-
-    >>> '%.2f' % point.radius
-    '2.24'
-
-The function isn't called.  If we change one of the attribute the
-radius depends on, it still isn't called::
-    
-    >>> point.x = 2.0
-    >>> '%.2f' % point.radius
-    '2.24'
-
-If we want the radius to be recomputed, we have to manually delete it::
-
-    >>> del point.radius
-
-    >>> point.x = 2.0
-    >>> '%.2f' % point.radius
-    computing radius
-    '2.83'
-
-Note that the radius is stored in the instance dictionary::
-
-    >>> '%.2f' % point.__dict__['radius']
-    '2.83'
-
-The lazy attribute needs to know the attribute name.  It normally
-deduces the attribute name from the name of the function passed. If we
-want to use a different name, we need to pass it::
-
-    >>> def d(point):
-    ...     print 'computing diameter'
-    ...     return 2*point.radius
-
-    >>> Point.diameter = property.Lazy(d, 'diameter')
-    >>> '%.2f' % point.diameter
-    computing diameter
-    '5.66'
-
-
-readproperties
-==============
-
-readproperties are like lazy computed attributes except that the
-attribute isn't set by the property::
-
-
-    >>> class Point:
-    ... 
-    ...     def __init__(self, x, y):
-    ...         self.x, self.y = x, y
-    ...
-    ...     def radius(self):
-    ...         print 'computing radius'
-    ...         return math.sqrt(self.x**2 + self.y**2)
-    ...     radius = property.readproperty(radius)
-
-    >>> point = Point(1.0, 2.0)   
-
-    >>> '%.2f' % point.radius
-    computing radius
-    '2.24'
-
-    >>> '%.2f' % point.radius
-    computing radius
-    '2.24'
-
-But you *can* replace the property by setting a value. This is the major
-difference to the builtin `property`::
-
-    >>> point.radius = 5
-    >>> point.radius
-    5
-
-
-cachedIn
-========
-
-The `cachedIn` property allows to specify the attribute where to store the
-computed value::
-
-    >>> class Point:
-    ... 
-    ...     def __init__(self, x, y):
-    ...         self.x, self.y = x, y
-    ...
-    ...     @property.cachedIn('_radius_attribute')
-    ...     def radius(self):
-    ...         print 'computing radius'
-    ...         return math.sqrt(self.x**2 + self.y**2)
-    
-    >>> point = Point(1.0, 2.0)   
-
-    >>> '%.2f' % point.radius
-    computing radius
-    '2.24'
-
-    >>> '%.2f' % point.radius
-    '2.24'
-
-The radius is cached in the attribute with the given name, `_radius_attribute`
-in this case::
-
-    >>> '%.2f' % point._radius_attribute
-    '2.24'
-
-When the attribute is removed the radius is re-calculated once. This allows
-invalidation::
-
-    >>> del point._radius_attribute
-
-    >>> '%.2f' % point.radius
-    computing radius
-    '2.24'
-
-    >>> '%.2f' % point.radius
-    '2.24'

Deleted: Sandbox/malthe/zope.container/src/zope/container/tests/test_property.py
===================================================================
--- Sandbox/malthe/zope.container/src/zope/container/tests/test_property.py	2008-04-22 12:37:09 UTC (rev 85592)
+++ Sandbox/malthe/zope.container/src/zope/container/tests/test_property.py	2008-04-22 12:46:00 UTC (rev 85593)
@@ -1,33 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2008 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Container constraint tests
-
-$Id: test_constraints.py 40495 2005-12-02 17:51:22Z efge $
-"""
-import unittest
-from zope.testing import doctest, module
-
-def setUp(test):
-    module.setUp(test, 'zope.container.property_txt')
-
-def tearDown(test):
-    module.tearDown(test, 'zope.container.property_txt')
-
-def test_suite():
-    return unittest.TestSuite((
-        doctest.DocFileSuite('../property.txt',
-                             setUp=setUp, tearDown=tearDown),
-        ))
-
-if __name__ == '__main__': unittest.main()



More information about the Checkins mailing list