[Zope3-checkins] CVS: Zope3/src/zope/app/interfaces/utilities -
session.py:1.1.2.1
Stuart Bishop
zen at shangri-la.dropbear.id.au
Sat Feb 7 22:19:03 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/interfaces/utilities
In directory cvs.zope.org:/tmp/cvs-serv15955/src/zope/app/interfaces/utilities
Added Files:
Tag: ozzope-session-branch
session.py
Log Message:
Non-service session design and initial Browser Id Manager Utility
implementation.
=== Added File Zope3/src/zope/app/interfaces/utilities/session.py ===
##############################################################################
#
# Copyright (c) 2001, 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.
#
##############################################################################
"""Interfaces for session service."""
import re
from zope.interface import Interface
from zope import schema
from zope.i18n import MessageIDFactory
from zope.app.interfaces.container import IContainer
_ = MessageIDFactory("zope.app.interfaces.utilities.session")
class IBrowserIdManager(Interface):
''' Manages sessions - fake state over multiple browser requests. '''
def getBrowserId(request):
''' Return the IBrowserId for the given request.
If the request doesn't have an attached sessionId a new one will
be generated.
This will do whatever is possible to do the HTTP request to ensure
the session id will be preserved. Depending on the specific
method, further action might be necessary on the part of the user.
See the documentation for the specific implementation and its
interfaces.
'''
class IBrowserIdManager(Interface):
def invalidate(browser_id):
''' Expire the browser_id, and remove any matching ISessionData data
'''
class ICookieBrowserIdManager(IBrowserIdManager):
''' Manages sessions using a cookie '''
namespace = schema.TextLine(
title=_('Cookie Name'),
description=_(
"Name of cookie used to maintain state. "
"Must be unique to the site domain name, and only contain "
"ASCII letters, digits and '_'"
),
required=True,
min_length=1,
max_length=30,
constraint=re.compile("^[\d\w_]+$").search,
)
cookieLifeSeconds = schema.Int(
title=_('Cookie Lifetime'),
description=_(
"Number of seconds until the browser expires the cookie. "
"Leave blank to never expire the cookie. Set to 0 to expire "
"the cookie when the browser is quit."
),
min=0,
required=False,
default=None,
missing_value=None,
)
class IBrowserId(Interface):
''' A unique ID representing a session '''
class ISessionData(IContainer):
''' Stores data objects for sessions. The object implementing this
interface is responsible for expiring data as appropriate.
keys are always in the format (key, browser_id, product_id)
'''
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__
'''
More information about the Zope3-Checkins
mailing list