Ticket #11555: 11555.diff

File 11555.diff, 4.7 KB (added by Aymeric Augustin, 14 years ago)
  • django/contrib/sessions/tests.py

     
    170170            # session key; make sure that entry is manually deleted
    171171            session.delete('1')
    172172
     173    def test_session_key_is_read_only(self):
     174        def set_session_key(session):
     175            session.session_key = session._get_new_session_key()
     176        self.assertRaises(AttributeError, set_session_key, self.session)
     177
    173178    # Custom session expiry
    174179    def test_default_expiry(self):
    175180        # A normal session has a max age equal to settings
  • django/contrib/sessions/backends/base.py

     
    168168                break
    169169        return session_key
    170170
    171     def _get_session_key(self):
     171    def _get_or_create_session_key(self):
    172172        if self._session_key:
    173173            return self._session_key
    174174        else:
    175175            self._session_key = self._get_new_session_key()
    176176            return self._session_key
    177177
    178     def _set_session_key(self, session_key):
    179         self._session_key = session_key
     178    def _get_session_key(self):
     179        return self._session_key
    180180
    181     session_key = property(_get_session_key, _set_session_key)
     181    session_key = property(_get_session_key)
    182182
    183183    def _get_session(self, no_load=False):
    184184        """
  • django/contrib/sessions/backends/file.py

     
    3333        Get the file associated with this session key.
    3434        """
    3535        if session_key is None:
    36             session_key = self.session_key
     36            session_key = self._get_or_create_session_key()
    3737
    3838        # Make sure we're not vulnerable to directory traversal. Session keys
    3939        # should always be md5s, so they should never contain directory
  • django/contrib/sessions/backends/cache.py

     
    2323        # and then raise an exception. That's the risk you shoulder if using
    2424        # cache backing.
    2525        for i in xrange(10000):
    26             self.session_key = self._get_new_session_key()
     26            self._session_key = self._get_new_session_key()
    2727            try:
    2828                self.save(must_create=True)
    2929            except CreateError:
     
    3737            func = self._cache.add
    3838        else:
    3939            func = self._cache.set
    40         result = func(self.session_key, self._get_session(no_load=must_create),
     40        result = func(self._get_or_create_session_key(),
     41                self._get_session(no_load=must_create),
    4142                self.get_expiry_age())
    4243        if must_create and not result:
    4344            raise CreateError
  • django/contrib/sessions/backends/db.py

     
    3333
    3434    def create(self):
    3535        while True:
    36             self.session_key = self._get_new_session_key()
     36            self._session_key = self._get_new_session_key()
    3737            try:
    3838                # Save immediately to ensure we have a unique entry in the
    3939                # database.
     
    5353        entry).
    5454        """
    5555        obj = Session(
    56             session_key = self.session_key,
     56            session_key = self._get_or_create_session_key(),
    5757            session_data = self.encode(self._get_session(no_load=must_create)),
    5858            expire_date = self.get_expiry_date()
    5959        )
  • tests/regressiontests/test_client_regress/session.py

     
    1414        return False
    1515
    1616    def create(self):
    17         self.session_key = self.encode({})
     17        self._session_key = self.encode({})
    1818
    1919    def save(self, must_create=False):
    20         self.session_key = self.encode(self._session)
     20        self._session_key = self.encode(self._session)
    2121
    2222    def delete(self, session_key=None):
    23         self.session_key = self.encode({})
     23        self._session_key = self.encode({})
    2424
    2525    def load(self):
    2626        try:
Back to Top