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 dolmen.beaker

How to install dolmen.beaker

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install dolmen.beaker
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.1 Failed View build log
Windows (64-bit)
Mac OS X (10.5+)
0.1 Available View build log
Linux (32-bit)
0.1 Available View build log
Linux (64-bit)
0.1 Available View build log
 
License
GPL
Lastest release
version 0.1 on Jan 5th, 2011

Session

Configuration
>>> from zope.component import getUtility, queryUtility
>>> from dolmen.beaker.interfaces import ISessionConfig
>>> session_config = queryUtility(ISessionConfig)
>>> session_config.get('key')
'beaker.session.id'
Initialisation

dolmen.beaker initialize the beaker session when the traversing starts (traversing the IRootFolder object):

>>> from zope.event import notify
>>> import grokcore.component as grok
>>> from zope.publisher.browser import TestRequest
>>> from zope.publisher.interfaces.http import IHTTPRequest
>>> from zope.traversing.interfaces import BeforeTraverseEvent

First we create an instance of the Request:

>>> request = TestRequest()
>>> IHTTPRequest.providedBy(request)
True

We initalize our Session with the help of the BeforeTraverseEvent. This event will make an instance of a Session Object in the Request:

>>> from zope.component.hooks import getSite
>>> site = getSite()
>>> notify(BeforeTraverseEvent(site, request))

We can get the session object using two available adapters:

>>> from dolmen.beaker.interfaces import ISession
>>> session = ISession(request)
>>> session.__class__
<class 'beaker.session.SessionObject'>

Let's assign an value to our session and save it:

>>> session['foo'] = 'bar'
>>> session.save()
>>> session['foo']
'bar'

A new request will not have access to the session without traversing:

>>> newrequest = TestRequest()
>>> newrequest.response._cookies
{}

>>> session = ISession(newrequest)
>>> session['foo']
Traceback (most recent call last):
...
KeyError: 'foo'
closure and invalidation
>>> cookie = request.response._cookies
>>> cookie
{}
>>> from zope.publisher.interfaces import EndRequestEvent
>>> notify(EndRequestEvent(site, request))
>>> cookie = request.response._cookies
>>> cookie
{'beaker.session.id': {'path': '/', 'value': '...'}}
Invalidating
>>> session = ISession(request)
>>> print session['foo']
bar
>>> session.invalidate() # Or destroy, to get rid of everything
>>> session['foo']
Traceback (most recent call last):
...
KeyError: 'foo'
>>> print session
{'_id': '...'}

The Zope Session adapter

>>> from zope.session.interfaces import ISession as IZopeSession
>>> request = TestRequest()
>>> notify(BeforeTraverseEvent(site, request))
>>> zsession = IZopeSession(request)
>>> print zsession
<dolmen.beaker.session.ZopeSession object at ...>
>>> from zope.interface.verify import verifyObject
>>> verifyObject(IZopeSession, zsession)
True
>>> data = zsession['my_package']
>>> print data
<dolmen.beaker.session.NamespaceSessionData object at ...>
>>> data['someitem'] = 'test'
>>> print data['someitem']
test
>>> print zsession.keys()
['my_package.someitem', '_id']
>>> data = zsession['some.other.package']
>>> data['info'] = 'Grok !'
>>> print zsession.keys()
['my_package.someitem', '_id', 'some.other.package.info']

Changelog

0.2 (unreleased)
  • Nothing changed yet.
0.1 (2010-07-01)
  • Initial release

Subscribe to package updates

Last updated Jan 5th, 2011

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.