bbangert / beaker

WSGI middleware for sessions and caching
https://beaker.readthedocs.org/
Other
524 stars 143 forks source link

len() doesn't work in SessionObject proxy #30

Open mikeorr opened 11 years ago

mikeorr commented 11 years ago

The SessionObject proxy used by pyramd_beaker does not proxy the __len__ method to the Session, so len(session) doesn't work.

>>> import beaker.session
>>> import pyramid.testing
>>> req = pyramid.testing.DummyRequest()
>>> so = beaker.session.SessionObject(req)
>>> len(so)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: object of type 'SessionObject' has no len()
>>> len(so._session())
2
ljluestc commented 6 months ago
import beaker.session
import pyramid.testing

# Create a dummy request
req = pyramid.testing.DummyRequest()

# Create a SessionObject
so = beaker.session.SessionObject(req)

# Access the session object directly from SessionObject
session = so._session()

# Check the length of the session
session_length = len(session)
print("Session length:", session_length)