Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

made underlying session.id accessible #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Unreleased
------------------
[jvanasco]
- add .id attribute to proxy underlying session id


0.6.1 (2011-11-19)
------------------

Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,5 @@ Contributors
- Blaise Laflamme, 2011/10/22

- Michael Merickel, 2011/11/13

- Jonathan Vanasco, 2013/03/26
8 changes: 8 additions & 0 deletions pyramid_beaker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class PyramidBeakerSessionObject(SessionObject):
_cookie_on_exception = _options.pop('cookie_on_exception', True)
def __init__(self, request):
SessionObject.__init__(self, request.environ, **self._options)

def session_callback(request, response):
exception = getattr(request, 'exception', None)
if (exception is None or self._cookie_on_exception
Expand All @@ -29,6 +30,13 @@ def session_callback(request, response):
response.headerlist.append(
('Set-Cookie', headers['cookie_out']))
request.add_response_callback(session_callback)

@property
def id(self):
# this is as inspected in SessionObject.__init__
if self.__dict__['_params'].get('type') != 'cookie':
return self._session().id
return None

# ISession API

Expand Down
13 changes: 13 additions & 0 deletions pyramid_beaker/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ def test_get_csrf_token_new(self):
self.failUnless(token)
self.assertEqual(session['_csrft_'], token)

def test_id_none_on_cookie_session(self):
request = DummyRequest()
session = self._makeOne(request,type='cookie')
session_id = session.id
self.assertIsNone(session_id)

def test_id_on_noncookie_session(self):
request = DummyRequest()
session = self._makeOne(request)
session_id = session.id
self.assertIsNotNone(session_id)


class Test_session_factory_from_settings(unittest.TestCase):
def _callFUT(self, settings):
from pyramid_beaker import session_factory_from_settings
Expand Down