~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to django/contrib/sessions/backends/base.py

  • Committer: Package Import Robot
  • Author(s): Raphaël Hertzog
  • Date: 2014-09-17 14:15:11 UTC
  • mfrom: (1.3.17) (6.2.18 experimental)
  • Revision ID: package-import@ubuntu.com-20140917141511-icneokthe9ww5sk4
Tags: 1.7-2
* Release to unstable.
* Add a migrate-south sample script to help users apply their South
  migrations. Thanks to Brian May.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
from django.utils.crypto import salted_hmac
13
13
from django.utils import timezone
14
14
from django.utils.encoding import force_bytes, force_text
15
 
from django.utils.module_loading import import_by_path
 
15
from django.utils.module_loading import import_string
16
16
 
17
17
from django.contrib.sessions.exceptions import SuspiciousSession
18
18
 
20
20
# on case insensitive file systems.
21
21
VALID_KEY_CHARS = string.ascii_lowercase + string.digits
22
22
 
 
23
 
23
24
class CreateError(Exception):
24
25
    """
25
26
    Used internally as a consistent exception type to catch from save (see the
27
28
    """
28
29
    pass
29
30
 
 
31
 
30
32
class SessionBase(object):
31
33
    """
32
34
    Base class for all Session classes.
38
40
        self._session_key = session_key
39
41
        self.accessed = False
40
42
        self.modified = False
41
 
        self.serializer = import_by_path(settings.SESSION_SERIALIZER)
 
43
        self.serializer = import_string(settings.SESSION_SERIALIZER)
42
44
 
43
45
    def __contains__(self, key):
44
46
        return key in self._session
284
286
        """
285
287
        Returns True if the given session_key already exists.
286
288
        """
287
 
        raise NotImplementedError
 
289
        raise NotImplementedError('subclasses of SessionBase must provide an exists() method')
288
290
 
289
291
    def create(self):
290
292
        """
292
294
        a unique key and will have saved the result once (with empty data)
293
295
        before the method returns.
294
296
        """
295
 
        raise NotImplementedError
 
297
        raise NotImplementedError('subclasses of SessionBase must provide a create() method')
296
298
 
297
299
    def save(self, must_create=False):
298
300
        """
300
302
        is created (otherwise a CreateError exception is raised). Otherwise,
301
303
        save() can update an existing object with the same key.
302
304
        """
303
 
        raise NotImplementedError
 
305
        raise NotImplementedError('subclasses of SessionBase must provide a save() method')
304
306
 
305
307
    def delete(self, session_key=None):
306
308
        """
307
309
        Deletes the session data under this key. If the key is None, the
308
310
        current session key value is used.
309
311
        """
310
 
        raise NotImplementedError
 
312
        raise NotImplementedError('subclasses of SessionBase must provide a delete() method')
311
313
 
312
314
    def load(self):
313
315
        """
314
316
        Loads the session data and returns a dictionary.
315
317
        """
316
 
        raise NotImplementedError
 
318
        raise NotImplementedError('subclasses of SessionBase must provide a load() method')
317
319
 
318
320
    @classmethod
319
321
    def clear_expired(cls):
324
326
        NotImplementedError. If it isn't necessary, because the backend has
325
327
        a built-in expiration mechanism, it should be a no-op.
326
328
        """
327
 
        raise NotImplementedError
 
329
        raise NotImplementedError('This backend does not support clear_expired().')