Skip to content

Commit

Permalink
Make data arg for Session ctor mandatory
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Nov 25, 2015
1 parent 578a5ca commit efd2d38
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions aiohttp_session/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Session(MutableMapping):

"""Session dict-like object."""

def __init__(self, identity, *, data=None, new):
def __init__(self, identity, *, data, new):
self._changed = False
self._mapping = {}
self._identity = identity
Expand Down Expand Up @@ -222,7 +222,7 @@ def __init__(self, *, cookie_name="AIOHTTP_SESSION",
def load_session(self, request):
cookie = self.load_cookie(request)
if cookie is None:
return Session(None, new=True)
return Session(None, data=None, new=True)
else:
data = json.loads(cookie)
return Session(None, data=data, new=False)
Expand Down
2 changes: 1 addition & 1 deletion aiohttp_session/cookie_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, secret_key, *, cookie_name="AIOHTTP_SESSION",
def load_session(self, request):
cookie = self.load_cookie(request)
if cookie is None:
return Session(None, new=True)
return Session(None, data=None, new=True)
else:
data = json.loads(
self._fernet.decrypt(cookie.encode('utf-8')).decode('utf-8')
Expand Down
2 changes: 1 addition & 1 deletion aiohttp_session/nacl_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, secret_key, *, cookie_name="AIOHTTP_SESSION",
def load_session(self, request):
cookie = self.load_cookie(request)
if cookie is None:
return Session(None, new=True)
return Session(None, data=None, new=True)
else:
data = json.loads(
self._secretbox.decrypt(cookie.encode('utf-8'),
Expand Down
4 changes: 2 additions & 2 deletions aiohttp_session/redis_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ def __init__(self, redis_pool, *, cookie_name="AIOHTTP_SESSION",
def load_session(self, request):
cookie = self.load_cookie(request)
if cookie is None:
return Session(None, new=True)
return Session(None, data=None, new=True)
else:
with (yield from self._redis) as conn:
key = str(cookie)
data = yield from conn.get(self.cookie_name + '_' + key)
if data is None:
return Session(None, new=True)
return Session(None, data=None, new=True)
data = data.decode('utf-8')
data = self._decoder(data)
return Session(key, data=data, new=False)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_get_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_get_stored_session(self):
@asyncio.coroutine
def go():
req = self.make_request('GET', '/')
session = Session('identity', new=False)
session = Session('identity', data=None, new=False)
req[SESSION_KEY] = session

ret = yield from get_session(req)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_session_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class SessionTests(unittest.TestCase):

def test_create(self):
s = Session('test_identity', new=True)
s = Session('test_identity', data=None, new=True)
self.assertEqual(s, {})
self.assertTrue(s.new)
self.assertEqual('test_identity', s.identity)
Expand All @@ -24,15 +24,15 @@ def test_create2(self):
self.assertIsNotNone(s.created)

def test_create3(self):
s = Session(identity=1, new=True)
s = Session(identity=1, data=None, new=True)
self.assertEqual(s, {})
self.assertTrue(s.new)
self.assertEqual(s.identity, 1)
self.assertFalse(s._changed)
self.assertIsNotNone(s.created)

def test__repr__(self):
s = Session('test_identity', new=True)
s = Session('test_identity', data=None, new=True)
self.assertEqual(
str(s),
'<Session [new:True, changed:False, created:{0}] {{}}>'.format(
Expand Down Expand Up @@ -85,7 +85,7 @@ def test_invalidate2(self):
self.assertIsNotNone(s.created)

def test_operations(self):
s = Session('test_identity', new=False)
s = Session('test_identity', data=None, new=False)
self.assertEqual(s, {})
self.assertEqual(len(s), 0)
self.assertEqual(list(s), [])
Expand Down

0 comments on commit efd2d38

Please sign in to comment.