Ticket #7429: session-dictlike.diff

File session-dictlike.diff, 2.4 KB (added by Jeremy Dunck, 16 years ago)

As of Django svn 7543.

  • django/contrib/sessions/backends/base.py

    old new  
    8686        except:
    8787            return {}
    8888
     89    def update(self, update_dict):
     90        self._session.update(update_dict)
     91        self.modified = True
     92
     93    def has_key(self, key):
     94        return self._session.has_key(key)
     95
     96    def values(self):
     97        return self._session.values()
     98
     99    def iterkeys(self):
     100        return self._session.iterkeys()
     101
     102    def itervalues(self):
     103        return self._session.itervalues()
     104
     105    def iteritems(self):
     106        return self._session.iteritems()
     107
    89108    def _get_new_session_key(self):
    90109        "Returns session key that isn't being used."
    91110        # The random module is seeded when this Apache child is created.
  • django/contrib/sessions/tests.py

    old new  
    8888
    8989>>> s.pop('some key', 'does not exist')
    9090'does not exist'
     91
     92>>> s.get('update key', None)
     93
     94test .update
     95>>> s.modified = s.accessed = False   # Reset to pretend this wasn't accessed previously
     96>>> s.update({'update key':1})
     97>>> s.accessed, s.modified
     98(True, True)
     99>>> s.get('update key', None)
     1001
     101
     102test .has_key
     103>>> s.modified = s.accessed = False   # Reset to pretend this wasn't accessed previously
     104>>> s.has_key('update key')
     105True
     106>>> s.accessed, s.modified
     107(True, False)
     108
     109test .values
     110>>> s = SessionBase()
     111>>> s.values()
     112[]
     113>>> s.accessed
     114True
     115>>> s['x'] = 1
     116>>> s.values()
     117[1]
     118
     119test .iterkeys
     120>>> s.accessed = False
     121>>> i = s.iterkeys()
     122>>> hasattr(i,'__iter__')
     123True
     124>>> s.accessed
     125True
     126>>> list(i)
     127['x']
     128
     129test .itervalues
     130>>> s.accessed = False
     131>>> i = s.itervalues()
     132>>> hasattr(i,'__iter__')
     133True
     134>>> s.accessed
     135True
     136>>> list(i)
     137[1]
     138
     139test .iteritems
     140>>> s.accessed = False
     141>>> i = s.iteritems()
     142>>> hasattr(i,'__iter__')
     143True
     144>>> s.accessed
     145True
     146>>> list(i)
     147[('x', 1)]
     148
     149
    91150"""
    92151
    93152if __name__ == '__main__':
Back to Top