[Checkins] SVN: zope.minmax/trunk/ Initial checkin of zope.minmax project.

Zvezdan Petkovic zvezdan at zope.com
Mon Jun 18 15:50:09 EDT 2007


Log message for revision 76769:
  Initial checkin of zope.minmax project.
  
  

Changed:
  _U  zope.minmax/trunk/
  A   zope.minmax/trunk/CHANGES.txt
  A   zope.minmax/trunk/README.txt
  A   zope.minmax/trunk/bootstrap.py
  A   zope.minmax/trunk/buildout.cfg
  A   zope.minmax/trunk/setup.py
  A   zope.minmax/trunk/src/
  A   zope.minmax/trunk/src/zope/
  A   zope.minmax/trunk/src/zope/__init__.py
  A   zope.minmax/trunk/src/zope/minmax/
  A   zope.minmax/trunk/src/zope/minmax/__init__.py
  A   zope.minmax/trunk/src/zope/minmax/_minmax.py
  A   zope.minmax/trunk/src/zope/minmax/interfaces.py
  A   zope.minmax/trunk/src/zope/minmax/minmax.txt
  A   zope.minmax/trunk/src/zope/minmax/tests.py

-=-

Property changes on: zope.minmax/trunk
___________________________________________________________________
Name: svn:ignore
   + bin
parts
develop-eggs
.installed.cfg


Added: zope.minmax/trunk/CHANGES.txt
===================================================================
--- zope.minmax/trunk/CHANGES.txt	                        (rev 0)
+++ zope.minmax/trunk/CHANGES.txt	2007-06-18 19:50:08 UTC (rev 76769)
@@ -0,0 +1,3 @@
+1.0.0
+
+Initial release.


Property changes on: zope.minmax/trunk/CHANGES.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: zope.minmax/trunk/README.txt
===================================================================
--- zope.minmax/trunk/README.txt	                        (rev 0)
+++ zope.minmax/trunk/README.txt	2007-06-18 19:50:08 UTC (rev 76769)
@@ -0,0 +1 @@
+Homogeneous values favoring maximum or minimum for conflict resolution.


Property changes on: zope.minmax/trunk/README.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: zope.minmax/trunk/bootstrap.py
===================================================================
--- zope.minmax/trunk/bootstrap.py	                        (rev 0)
+++ zope.minmax/trunk/bootstrap.py	2007-06-18 19:50:08 UTC (rev 76769)
@@ -0,0 +1,52 @@
+##############################################################################
+#
+# Copyright (c) 2006 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.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id: bootstrap.py 69908 2006-08-31 21:53:00Z jim $
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+ez = {}
+exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+                     ).read() in ez
+ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+import pkg_resources
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+if sys.platform == 'win32':
+    cmd = '"%s"' % cmd # work around spawn lamosity on windows
+
+ws = pkg_resources.working_set
+assert os.spawnle(
+    os.P_WAIT, sys.executable, sys.executable,
+    '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
+    dict(os.environ,
+         PYTHONPATH=
+         ws.find(pkg_resources.Requirement.parse('setuptools')).location
+         ),
+    ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)

Added: zope.minmax/trunk/buildout.cfg
===================================================================
--- zope.minmax/trunk/buildout.cfg	                        (rev 0)
+++ zope.minmax/trunk/buildout.cfg	2007-06-18 19:50:08 UTC (rev 76769)
@@ -0,0 +1,15 @@
+[buildout]
+develop = .
+parts = test py
+
+find-links = http://download.zope.org/distribution/
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = zope.minmax
+
+[py]
+recipe = zc.recipe.egg
+eggs = setuptools
+interpreter = py
+scripts = py


Property changes on: zope.minmax/trunk/buildout.cfg
___________________________________________________________________
Name: svn:eol-style
   + native

Added: zope.minmax/trunk/setup.py
===================================================================
--- zope.minmax/trunk/setup.py	                        (rev 0)
+++ zope.minmax/trunk/setup.py	2007-06-18 19:50:08 UTC (rev 76769)
@@ -0,0 +1,20 @@
+from setuptools import setup
+
+setup(
+    name="zope.minmax",
+    version="1.0.0-dev",
+    license="ZPL 2.1",
+    author="Zope Project",
+    author_email="zope3-dev at zope.org",
+
+    namespace_packages=["zope"],
+    packages=["zope", "zope.minmax"],
+    package_dir={"": "src"},
+    include_package_data=True,
+    install_requires=["setuptools", "zope.interface", "ZODB3"],
+    tests_require=["zope.testing"],
+    description=open('README.txt').read(),
+    long_description=open("src/zope/minmax/minmax.txt").read(),
+    keywords="zope zope3",
+    zip_safe=False
+    )

Added: zope.minmax/trunk/src/zope/__init__.py
===================================================================
--- zope.minmax/trunk/src/zope/__init__.py	                        (rev 0)
+++ zope.minmax/trunk/src/zope/__init__.py	2007-06-18 19:50:08 UTC (rev 76769)
@@ -0,0 +1,7 @@
+# this is a namespace package
+try:
+    import pkg_resources
+    pkg_resources.declare_namespace(__name__)
+except ImportError:
+    import pkgutil
+    __path__ = pkgutil.extend_path(__path__, __name__)

Added: zope.minmax/trunk/src/zope/minmax/__init__.py
===================================================================
--- zope.minmax/trunk/src/zope/minmax/__init__.py	                        (rev 0)
+++ zope.minmax/trunk/src/zope/minmax/__init__.py	2007-06-18 19:50:08 UTC (rev 76769)
@@ -0,0 +1 @@
+from zope.minmax._minmax import Maximum, Minimum

Added: zope.minmax/trunk/src/zope/minmax/_minmax.py
===================================================================
--- zope.minmax/trunk/src/zope/minmax/_minmax.py	                        (rev 0)
+++ zope.minmax/trunk/src/zope/minmax/_minmax.py	2007-06-18 19:50:08 UTC (rev 76769)
@@ -0,0 +1,36 @@
+import persistent
+import zope.interface
+
+from zope.minmax import interfaces
+
+class AbstractValue(persistent.Persistent):
+
+    zope.interface.implements(interfaces.IAbstractValue)
+
+    def __init__(self, value=None):
+        self.value = value
+
+    def __getstate__(self):
+        return self.value
+
+    def __setstate__(self, value):
+        self.value = value
+
+    def __nonzero__(self):
+        return bool(self.value)
+
+    def _p_independent(self):
+        return True
+
+    def _p_resolveConflict(self, old, commited, new):
+        raise NotImplementedError()
+
+class Maximum(AbstractValue):
+    def _p_resolveConflict(self, old, commited, new):
+        # including old does not seem logical but it's open to discussion
+        return max(commited, new)
+
+class Minimum(AbstractValue):
+    def _p_resolveConflict(self, old, commited, new):
+        # including old does not seem logical but it's open to discussion
+        return min(commited, new)

Added: zope.minmax/trunk/src/zope/minmax/interfaces.py
===================================================================
--- zope.minmax/trunk/src/zope/minmax/interfaces.py	                        (rev 0)
+++ zope.minmax/trunk/src/zope/minmax/interfaces.py	2007-06-18 19:50:08 UTC (rev 76769)
@@ -0,0 +1,13 @@
+import persistent.interfaces
+import zope.interface
+
+class IAbstractValue(persistent.interfaces.IPersistent):
+    """A persistent value with the conflict resolution.
+
+    The values are expected to be homogeneous.
+    """
+
+    value = zope.interface.Attribute('The initial value')
+
+    def __nonzero__():
+        """Return Boolean cast of the value as True or False."""

Added: zope.minmax/trunk/src/zope/minmax/minmax.txt
===================================================================
--- zope.minmax/trunk/src/zope/minmax/minmax.txt	                        (rev 0)
+++ zope.minmax/trunk/src/zope/minmax/minmax.txt	2007-06-18 19:50:08 UTC (rev 76769)
@@ -0,0 +1,163 @@
+===================================================
+Conflict Resolution using Maximum or Minimum Values
+===================================================
+
+The `zope.minmax.AbstractValue` class provides a super class which can
+be subclassed to store arbitrary *homogeneous* values in a persistent
+storage and apply different conflict resolution policies.
+
+The subclasses defined here are resolving the conflicts using always
+either the maximum or the minimum of the conflicting values.
+
+Maximum
+-------
+
+The `zope.minmax.Maximum` class always resolves conflicts favoring the
+maximum value.  Let's instantiate one object and verify that it
+satisfies the interface.
+
+    >>> import zope.minmax
+    >>> import zope.interface.verify
+    >>> max_favored = zope.minmax.Maximum()
+    >>> zope.interface.verify.verifyObject(
+    ...     zope.minmax.interfaces.IAbstractValue, max_favored)
+    True
+
+We can confirm that the initial value is zero.
+
+    >>> bool(max_favored)
+    False
+    >>> print max_favored.value
+    None
+
+Now, we can store a new value in the object.
+
+    >>> max_favored.value = 11
+    >>> print max_favored.value
+    11
+    >>> bool(max_favored)
+    True
+
+Or we can use the methods.
+
+    >>> max_favored.__setstate__(4532)
+    >>> max_favored.__getstate__()
+    4532
+    >>> print max_favored.value
+    4532
+    >>> bool(max_favored)
+    True
+
+Do notice that using a direct assignment to the value attribute is a
+more natural use.
+
+Minimum
+-------
+
+The `zope.minmax.Minimum` class always resolves conflicts favoring the
+minimum value.  Again, we instantiate an object and verify that it
+satisfies the interface.
+
+    >>> min_favored = zope.minmax.Minimum()
+    >>> zope.interface.verify.verifyObject(
+    ...     zope.minmax.interfaces.IAbstractValue, min_favored)
+    True
+
+We need a confirmation that the initial value is zero.
+
+    >>> bool(min_favored)
+    False
+    >>> print min_favored.value
+    None
+
+Let's populate this one too.
+
+    >>> min_favored.value = 22
+    >>> print min_favored.value
+    22
+    >>> bool(min_favored)
+    True
+
+Or we can use the methods, again.
+
+    >>> min_favored.__setstate__(8796)
+    >>> min_favored.__getstate__()
+    8796
+    >>> print min_favored.value
+    8796
+    >>> bool(min_favored)
+    True
+
+Please, notice, again, that using a direct assignment to the value
+attribute is a more natural use.
+
+Conflict Resolution
+-------------------
+
+Now, we need to exercise the conflict resolution interface.
+First for the `zope.minmax.Maximum`:
+
+Let's try differing values larger than the old value.
+
+    >>> max_favored._p_resolveConflict(max_favored.value, 4536, 4535)
+    4536
+    >>> max_favored._p_resolveConflict(max_favored.value, 4573, 4574)
+    4574
+
+What happens when all the values are equal, including the old.
+
+    >>> max_favored._p_resolveConflict(max_favored.value, 4532, 4532)
+    4532
+
+Notice that when the old value is larger than both the committed and
+new, it is still disregarded.
+
+    >>> max_favored._p_resolveConflict(max_favored.value, 4531, 4530)
+    4531
+
+Now, the `zope.minmax.Minimum`:
+
+Let's try differing values smaller than the old value.
+
+    >>> min_favored._p_resolveConflict(min_favored.value, 8792, 8791)
+    8791
+    >>> min_favored._p_resolveConflict(min_favored.value, 8785, 8786)
+    8785
+
+What happens when all the values are equal, including the old.
+
+    >>> min_favored._p_resolveConflict(min_favored.value, 8796, 8796)
+    8796
+
+Notice that when the old value is smaller than both the committed and
+new, it is still disregarded.
+
+    >>> min_favored._p_resolveConflict(min_favored.value, 8798, 8799)
+    8798
+
+How about an example that is not numerical?
+
+    >>> max_word = zope.minmax.Maximum('joy')
+    >>> print max_word.value
+    joy
+    >>> bool(max_word)
+    True
+    >>> max_word._p_resolveConflict(max_word.value, 'happiness', 'exuberance')
+    'happiness'
+    >>> max_word._p_resolveConflict(max_word.value, 'exuberance', 'happiness')
+    'happiness'
+    >>> min_word = zope.minmax.Minimum(max_word.value)
+    >>> print min_word.value
+    joy
+    >>> bool(min_word)
+    True
+    >>> min_word._p_resolveConflict(min_word.value, 'happiness', 'exuberance')
+    'exuberance'
+    >>> min_word._p_resolveConflict(min_word.value, 'exuberance', 'happiness')
+    'exuberance'
+
+As indicated, we don't need to have numbers, just *homegeneous* items.
+The homogeneous values are not really inherently required.  However, it
+makes no sense to apply min() or max() on, say, one number and one
+string.  Simply, the ordering relations do not work at all on
+heterogeneous values.


Property changes on: zope.minmax/trunk/src/zope/minmax/minmax.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: zope.minmax/trunk/src/zope/minmax/tests.py
===================================================================
--- zope.minmax/trunk/src/zope/minmax/tests.py	                        (rev 0)
+++ zope.minmax/trunk/src/zope/minmax/tests.py	2007-06-18 19:50:08 UTC (rev 76769)
@@ -0,0 +1,10 @@
+import unittest
+import zope.testing
+
+def test_suite():
+    return unittest.TestSuite((
+        zope.testing.doctest.DocFileSuite('minmax.txt'),
+        ))
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')



More information about the Checkins mailing list