Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
  • Loading branch information...
commit 5db4d602152c14bb4b25011d9a881f7fa1639152 1 parent 1fc0077
@gdub gdub authored
View
11 django/contrib/sessions/backends/base.py
@@ -5,14 +5,15 @@
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 @@ def get_expiry_date(self):
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
View
3  django/contrib/sessions/backends/cache.py
@@ -2,6 +2,7 @@
from django.contrib.sessions.backends.base import SessionBase
from django.core.cache import cache
+
class SessionStore(SessionBase):
"""
A cache-based session store.
@@ -23,4 +24,4 @@ def exists(self, session_key):
return False
def delete(self, session_key):
- self._cache.delete(session_key)
+ self._cache.delete(session_key)
View
6 django/contrib/sessions/backends/db.py
@@ -1,12 +1,14 @@
+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)
View
16 django/contrib/sessions/backends/file.py
@@ -1,9 +1,11 @@
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 @@ def __init__(self, session_key=None):
# 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 @@ def _key_to_file(self, session_key=None):
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)
View
2  django/contrib/sessions/middleware.py
@@ -7,6 +7,7 @@
TEST_COOKIE_NAME = 'testcookie'
TEST_COOKIE_VALUE = 'worked'
+
class SessionMiddleware(object):
def process_request(self, request):
@@ -40,5 +41,4 @@ def process_response(self, request, response):
expires=expires, domain=settings.SESSION_COOKIE_DOMAIN,
path=settings.SESSION_COOKIE_PATH,
secure=settings.SESSION_COOKIE_SECURE or None)
-
return response
View
9 django/contrib/sessions/models.py
@@ -6,9 +6,12 @@
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
+
class SessionManager(models.Manager):
def encode(self, session_dict):
- "Returns the given session dictionary pickled and encoded as a string."
+ """
+ Returns the given session dictionary pickled and encoded as a string.
+ """
pickled = pickle.dumps(session_dict)
pickled_md5 = md5.new(pickled + settings.SECRET_KEY).hexdigest()
return base64.encodestring(pickled + pickled_md5)
@@ -21,6 +24,7 @@ def save(self, session_key, session_dict, expire_date):
s.delete() # Clear sessions with no data.
return s
+
class Session(models.Model):
"""
Django provides full support for anonymous sessions. The session
@@ -38,7 +42,8 @@ class Session(models.Model):
the sessions documentation that is shipped with Django (also available
on the Django website).
"""
- session_key = models.CharField(_('session key'), max_length=40, primary_key=True)
+ session_key = models.CharField(_('session key'), max_length=40,
+ primary_key=True)
session_data = models.TextField(_('session data'))
expire_date = models.DateTimeField(_('expire date'))
objects = SessionManager()
Please sign in to comment.
Something went wrong with that request. Please try again.