diff --git a/django/contrib/sessions/backends/base.py b/django/contrib/sessions/backends/base.py index 1063760915..1f9c20871b 100644 --- a/django/contrib/sessions/backends/base.py +++ b/django/contrib/sessions/backends/base.py @@ -87,6 +87,25 @@ class SessionBase(object): except: return {} + def update(self, dict_): + self._session.update(dict_) + self.modified = True + + def has_key(self, key): + return self._session.has_key(key) + + def values(self): + return self._session.values() + + def iterkeys(self): + return self._session.iterkeys() + + def itervalues(self): + return self._session.itervalues() + + def iteritems(self): + return self._session.iteritems() + def _get_new_session_key(self): "Returns session key that isn't being used." # The random module is seeded when this Apache child is created. diff --git a/django/contrib/sessions/tests.py b/django/contrib/sessions/tests.py index 0f162b211f..a1bc6799fa 100644 --- a/django/contrib/sessions/tests.py +++ b/django/contrib/sessions/tests.py @@ -89,6 +89,66 @@ False >>> s.pop('some key', 'does not exist') 'does not exist' + +>>> s.get('update key', None) + +# test .update() +>>> s.modified = s.accessed = False # Reset to pretend this wasn't accessed previously +>>> s.update({'update key':1}) +>>> s.accessed, s.modified +(True, True) +>>> s.get('update key', None) +1 + +# test .has_key() +>>> s.modified = s.accessed = False # Reset to pretend this wasn't accessed previously +>>> s.has_key('update key') +True +>>> s.accessed, s.modified +(True, False) + +# test .values() +>>> s = SessionBase() +>>> s.values() +[] +>>> s.accessed +True +>>> s['x'] = 1 +>>> s.values() +[1] + +# test .iterkeys() +>>> s.accessed = False +>>> i = s.iterkeys() +>>> hasattr(i,'__iter__') +True +>>> s.accessed +True +>>> list(i) +['x'] + +# test .itervalues() +>>> s.accessed = False +>>> i = s.itervalues() +>>> hasattr(i,'__iter__') +True +>>> s.accessed +True +>>> list(i) +[1] + +# test .iteritems() +>>> s.accessed = False +>>> i = s.iteritems() +>>> hasattr(i,'__iter__') +True +>>> s.accessed +True +>>> list(i) +[('x', 1)] + + + ######################### # Custom session expiry # #########################