[Zope-CVS] CVS: Packages/pypes/pypes - extent.py:1.1 interfaces.py:1.9

Casey Duncan casey at zope.com
Mon Feb 9 00:25:22 EST 2004


Update of /cvs-repository/Packages/pypes/pypes
In directory cvs.zope.org:/tmp/cvs-serv21905

Modified Files:
	interfaces.py 
Added Files:
	extent.py 
Log Message:
Add basic extent service infrastructure and tests
Simplify IExtentMap interface


=== Added File Packages/pypes/pypes/extent.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""Pypes extent service

Service managing automated global extent sets by class and interface.

$Id: extent.py,v 1.1 2004/02/09 05:24:51 caseman Exp $"""

from zope.interface import implements
from pypes import services
from pypes.identity import IdRegisteredMessage, IdUnregisteredMessage
from pypes.interfaces import IExtentService
from pypes.interfaces import IExtent, ICanonicalExtent, IDerivedExtent
from persistent import Persistent


class ClassExtentMap:
    pass


class InterfaceExtentMap:
    pass
    

class ExtentService(Persistent):
    """Extent service managing class and interface extents.

    Dependancies: Identity Service, Event Service
    """

    implements(IExtentService)
    
    # Map factory hooks for testing/overriding
    _class_map_factory = ClassExtentMap
    _interface_map_factory = InterfaceExtentMap
    
    def __init__(self, dbconn, class_extents=True, interface_extents=True):
        """Create an extent service. By default both class extents and
        interface extents are enabled. You may override this by specifying
        the appropriate keyword argument. At least one extent type must
        be enabled. dbconn is an open ZODB dbconnection object.
        """
        assert class_extents or interface_extents, (
            'Cannot create service with neither class nor interface '
            'extents enabled.')
        self._extent_maps = []
        if class_extents:
            self._extent_maps.append(self._class_map_factory(dbconn))
        if interface_extents:
            self._extent_maps.append(self._interface_map_factory(dbconn))

    def __getitem__(self, key):
        for extent_map in self._extent_maps:
            try:
                return extent_map[key]
            except TypeError:
                pass
        raise TypeError, 'Key type %s not supported' % type(key)

    def __contains__(self, key):
        try:
            self[key]
        except KeyError:
            return False
        else:
            return True

    def __iter__(self):
        for extent_map in self._extent_maps:
            for extent in extent_map:
                yield extent


        


=== Packages/pypes/pypes/interfaces.py 1.8 => 1.9 ===
--- Packages/pypes/pypes/interfaces.py:1.8	Sun Feb  8 22:56:21 2004
+++ Packages/pypes/pypes/interfaces.py	Mon Feb  9 00:24:51 2004
@@ -266,11 +266,15 @@
     
     def __getitem__(key):
         """Return the canonical extent for key. For class extents the key is a 
-        class. For interface extents it is an interface object.  
+        class. For interface extents it is an interface object. Raise KeyError
+        if key is not contained in the service. Raise TypeError if key type
+        is not supported.
         """
 
     def __contains__(key):
-        """Return true if key is an identifier of an extent, false otherwise"""
+        """Return true if key is an identifier of an extent, false otherwise.
+        Raise TypeError if key type is not supported.
+        """
     
     def __iter__():
         """Return an iterator of all extents in the service"""
@@ -278,12 +282,11 @@
 
 class IExtentMap(Interface):
     """Simple mapping-like container for canonical extents of a single type"""
-
-    key_type = Attribute('key_type',
-       """Type of key objects used to identify extents in the map""")
        
     def __getitem__(key):
-        """Return extent for key or raise KeyError"""
+        """Return extent for key. Raise KeyError if key is the correct type
+        but is not in the map. Raise TypeError if key is not the correct type
+        for the extent map"""
 
     def __iter__():
         """Return an iterator of all extents in the mapping"""




More information about the Zope-CVS mailing list