Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install zope.minmax

How to install zope.minmax

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install zope.minmax
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.7.7
0.8Never BuiltWhy not?
0.7.7 Available View build log
0.7.4 Available View build log
0.7.2 Available View build log
0.7.1 Available View build log
0.7.0 Available View build log
0.6.0 Available View build log
0.5.0 Available View build log
0.7.4
0.8Never BuiltWhy not?
0.7.4 Available View build log
0.7.2 Available View build log
0.7.1 Available View build log
0.7.0 Available View build log
0.6.0 Available View build log
0.5.0 Available View build log
Windows (64-bit)
0.7.7
0.8Never BuiltWhy not?
0.7.7 Available View build log
0.7.4 Available View build log
0.7.2 Available View build log
0.7.1 Available View build log
0.7.0 Available View build log
0.6.0 Available View build log
0.5.0 Available View build log
0.7.4
0.8Never BuiltWhy not?
0.7.4 Available View build log
0.7.2 Available View build log
0.7.1 Available View build log
0.7.0 Available View build log
0.6.0 Available View build log
0.5.0 Available View build log
Mac OS X (10.5+)
0.7.7
0.8Never BuiltWhy not?
0.7.7 Available View build log
0.7.4 Available View build log
0.7.2 Available View build log
0.7.1 Available View build log
0.7.0 Available View build log
0.6.0 Available View build log
0.5.0 Available View build log
0.7.7
0.8Never BuiltWhy not?
0.7.7 Available View build log
0.7.5 Failed View build log
0.7.4 Available View build log
0.7.2 Available View build log
0.7.1 Available View build log
0.7.0 Available View build log
0.6.0 Available View build log
0.5.0 Available View build log
Linux (32-bit)
0.7.7
0.8Never BuiltWhy not?
0.7.7 Available View build log
0.7.5 Available View build log
0.7.4 Available View build log
0.7.2 Available View build log
0.7.1 Available View build log
0.7.0 Available View build log
0.6.0 Available View build log
0.5.0 Available View build log
0.7.7
0.8Never BuiltWhy not?
0.7.7 Available View build log
0.7.5 Failed View build log
0.7.4 Available View build log
0.7.2 Available View build log
0.7.1 Available View build log
0.7.0 Available View build log
0.6.0 Available View build log
0.5.0 Available View build log
Linux (64-bit)
0.8
0.8 Available View build log
0.7.7 Available View build log
0.7.6 Available View build log
0.7.5 Available View build log
0.7.4 Available View build log
0.7.2 Available View build log
0.7.1 Available View build log
0.7.0 Available View build log
0.6.0 Available View build log
0.5.0 Available View build log
0.7.7
0.8Never BuiltWhy not?
0.7.7 Available View build log
0.7.5 Failed View build log
0.7.4 Available View build log
0.7.2 Available View build log
0.7.1 Available View build log
0.7.0 Available View build log
0.6.0 Available View build log
0.5.0 Available View build log
0.8
0.8 Available View build log
0.7.7 Available View build log
0.7.6 Available View build log
0.7.4 Available View build log
 
License
ZPL 2.1
Imports
Lastest release
version 2.0.0 on Feb 20th, 2013

Min/Max Value Conflict Resolution

This package provides support for homogeneous values favoring maximum or minimum for ZODB conflict resolution. See src/zope/minmax/minmax.txt for a detailed description.

Detailed Documentation

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.

CHANGES

2.0.0 (2013-02-19)
  • Added Python 3.3 and PyPy 1.9 support.
  • Replaced deprecated zope.interface.implements usage with equivalent zope.interface.implementer decorator.
  • Dropped support for Python 2.4 and 2.5.
1.1.2 (2009-09-24)
  • Use the standard Python doctest module instead of the deprecated zope.testing.doctest.
1.1.1 (2009-09-09)
  • Fixed homepage link and mailing list address.
  • Cleaned up.
1.1 (2007-10-02)
  • Refactored package setup.
1.0 (2007-09-28)
  • No further changes since 1.0b2
1.0b2 (2007-07-09)
  • Removed _p_independent method from AbstractValue class.
1.0b1 (2007-07-03)
  • Initial release.

Subscribe to package updates

Last updated Feb 20th, 2013

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.