Commit 5db4d602 authored by Gary Wilson Jr's avatar Gary Wilson Jr
Browse files

Several Django styling fixes in the `contrib.sessions` app.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@7725 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 1fc0077a
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -5,14 +5,15 @@ import random
import sys
import time
from datetime import datetime, timedelta
from django.conf import settings
from django.core.exceptions import SuspiciousOperation

try:
    import cPickle as pickle
except ImportError:
    import pickle

from django.conf import settings
from django.core.exceptions import SuspiciousOperation


class SessionBase(object):
    """
    Base class for all Session classes.
@@ -169,8 +170,8 @@ class SessionBase(object):

    def set_expiry(self, value):
        """
        Sets a custom expiration for the session. ``value`` can be an integer, a
        Python ``datetime`` or ``timedelta`` object or ``None``.
        Sets a custom expiration for the session. ``value`` can be an integer,
        a Python ``datetime`` or ``timedelta`` object or ``None``.

        If ``value`` is an integer, the session will expire after that many
        seconds of inactivity. If set to ``0`` then the session will expire on
+2 −1
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ from django.conf import settings
from django.contrib.sessions.backends.base import SessionBase
from django.core.cache import cache


class SessionStore(SessionBase):
    """
    A cache-based session store.
+4 −2
Original line number Diff line number Diff line
import datetime

from django.conf import settings
from django.contrib.sessions.models import Session
from django.contrib.sessions.backends.base import SessionBase
from django.core.exceptions import SuspiciousOperation
import datetime


class SessionStore(SessionBase):
    """
    Implements database session store
    Implements database session store.
    """
    def __init__(self, session_key=None):
        super(SessionStore, self).__init__(session_key)
+10 −6
Original line number Diff line number Diff line
import os
import tempfile

from django.conf import settings
from django.contrib.sessions.backends.base import SessionBase
from django.core.exceptions import SuspiciousOperation, ImproperlyConfigured


class SessionStore(SessionBase):
    """
    Implements a file based session store.
@@ -15,10 +17,10 @@ class SessionStore(SessionBase):

        # Make sure the storage path is valid.
        if not os.path.isdir(self.storage_path):
            raise ImproperlyConfigured("The session storage path %r doesn't exist. "\
                                       "Please set your SESSION_FILE_PATH setting "\
                                       "to an existing directory in which Django "\
                                       "can store session data." % self.storage_path)
            raise ImproperlyConfigured(
                "The session storage path %r doesn't exist. Please set your"
                " SESSION_FILE_PATH setting to an existing directory in which"
                " Django can store session data." % self.storage_path)

        self.file_prefix = settings.SESSION_COOKIE_NAME
        super(SessionStore, self).__init__(session_key)
@@ -31,9 +33,11 @@ class SessionStore(SessionBase):
            session_key = self.session_key

        # Make sure we're not vulnerable to directory traversal. Session keys
        # should always be md5s, so they should never contain directory components.
        # should always be md5s, so they should never contain directory
        # components.
        if os.path.sep in session_key:
            raise SuspiciousOperation("Invalid characters (directory components) in session key")
            raise SuspiciousOperation(
                "Invalid characters (directory components) in session key")

        return os.path.join(self.storage_path, self.file_prefix + session_key)

+1 −1
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ from django.utils.http import cookie_date
TEST_COOKIE_NAME = 'testcookie'
TEST_COOKIE_VALUE = 'worked'


class SessionMiddleware(object):

    def process_request(self, request):
@@ -40,5 +41,4 @@ class SessionMiddleware(object):
                        expires=expires, domain=settings.SESSION_COOKIE_DOMAIN,
                        path=settings.SESSION_COOKIE_PATH,
                        secure=settings.SESSION_COOKIE_SECURE or None)

        return response
Loading