[Zope3-checkins] CVS: Zope3/src/zope/app/interfaces/utilities - session.py:1.1.2.2

Stuart Bishop zen at shangri-la.dropbear.id.au
Sun Feb 8 22:09:27 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/interfaces/utilities
In directory cvs.zope.org:/tmp/cvs-serv27663/src/zope/app/interfaces/utilities

Modified Files:
      Tag: ozzope-session-branch
	session.py 
Log Message:
Work in progress - API solidifying


=== Zope3/src/zope/app/interfaces/utilities/session.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/app/interfaces/utilities/session.py:1.1.2.1	Sat Feb  7 22:19:02 2004
+++ Zope3/src/zope/app/interfaces/utilities/session.py	Sun Feb  8 22:08:56 2004
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# Copyright (c) 2004 Zope Corporation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -11,7 +11,6 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-
 """Interfaces for session service."""
 
 import re
@@ -20,7 +19,40 @@
 from zope.i18n import MessageIDFactory
 from zope.app.interfaces.container import IContainer
 
-_ = MessageIDFactory("zope.app.interfaces.utilities.session")
+_ = MessageIDFactory("zope")
+
+# XXX: We currently lookup the IBrowserIdManager utility with a well known
+# name, as there appears to be a problem in the utility service.
+BrowserIdManager = 'Browser Id Manager'
+
+
+# XXX: These mapping interfaces should probably live somewhere like 
+# zope.interface.common.mapping, but there are already similar but less
+# useful ones defined there.
+_missing = []
+class IReadMapping(Interface):
+    ''' Mapping methods for retrieving data '''
+    def __getitem__(key): 'Return a value'
+    def __contains__(key): 'True if there is a value for key'
+    def get(key, default=_missing):
+        'Return a value, or default if key not found'
+
+class IWriteMapping(Interface):
+    ''' Mapping methods for changing data '''
+    def __delitem__(key): 'Delete a value'
+    def __setitem__(key): 'Set a value'
+
+class IIterableMapping(Interface):
+    ''' Mapping methods for listing keys and values ''' 
+    def __len__(key): 'Number of items in the IMapping'
+    def __iter__(): 'Iterate over all the keys'
+    def keys(): 'Return a sequence of the keys'
+    def items(): 'Return a sequence of the (key, value) tuples'
+    def values(): 'Return a sequence of the values'
+
+class IFullMapping(IReadMapping, IWriteMapping, IIterableMapping):
+    ''' Full mapping interface '''
+
 
 class IBrowserIdManager(Interface):
     ''' Manages sessions - fake state over multiple browser requests. '''
@@ -39,10 +71,11 @@
         '''
 
 
-class IBrowserIdManager(Interface):
+    """ XXX: Want this
     def invalidate(browser_id):
         ''' Expire the browser_id, and remove any matching ISessionData data 
         '''
+    """
 
 
 class ICookieBrowserIdManager(IBrowserIdManager):
@@ -77,27 +110,34 @@
 
 class IBrowserId(Interface):
     ''' A unique ID representing a session '''
+    def __str__(): '''as a unique ASCII string'''
 
 
-class ISessionData(IContainer):
+class ISessionDataContainer(IReadMapping, IWriteMapping):
     ''' Stores data objects for sessions. The object implementing this
-        interface is responsible for expiring data as appropriate.
+        interface is responsible for expiring data as it feels appropriate.
 
-        keys are always in the format (key, browser_id, product_id)
-    '''
+        Used like:
+            session_data_container[browser_id][product_id][key] = value
 
+        Attempting to access a key that does not exist will raise a KeyError.
+    '''
+    timeout = schema.Int(
+            title=_(u"Timeout"),
+            description=_("Number of seconds before inactive data is removed"),
+            default=3600,
+            required=True,
+            min=1,
+            )
 
-class ISession(Interface):
-    def __init__(data_manager, browser_id, product_id):
-        ''' Construct a session '''
-
-    def __getitem__(key):
-        ''' Return an item stored in the session, using
-            (key, browser_id, product_id) as the key into the data_manager
-        '''
 
-    def __setitem__(key, value):
-        ''' Set an item specific to this session using the
-            key as per __getitem__ 
-        '''
+class ISession(IFullMapping):
+    ''' To access bits of data within an ISessionDataContainer, we
+        need to know the browser_id, the product_id, and the actual key.
+        An ISession is a wrapper around an ISessionDataContainer that
+        simplifies this by storing the browser_id and product_id enabling
+        access using just the key.
+    '''
+    def __init__(session_data_container, browser_id, product_id):
+        ''' Construct an ISession '''
 




More information about the Zope3-Checkins mailing list