Ticket #6082: 6082.diff

File 6082.diff, 1.6 KB (added by jags78, 17 years ago)

Patch for missing directory

  • contrib/sessions/backends/file.py

     
    11import os
    22from django.conf import settings
    33from django.contrib.sessions.backends.base import SessionBase
    4 from django.core.exceptions import SuspiciousOperation
     4from django.core.exceptions import SuspiciousOperation, ImproperlyConfigured
    55
    66class SessionStore(SessionBase):
    77    """
     
    99    """
    1010    def __init__(self, session_key=None):
    1111        self.storage_path = settings.SESSION_FILE_PATH
     12       
     13        if not os.path.isdir(self.storage_path):
     14            try:
     15                if os.path.isdir(os.environ['TMPDIR']):           
     16                    self.storage_path = os.environ['TMPDIR']
     17            except:
     18                #fail silently
     19                pass
     20            try:
     21                if os.path.isdir(os.environ['TEMP']):           
     22                    self.storage_path = os.environ['TEMP']
     23            except:
     24                #fail silently
     25                pass
     26       
     27        # If we still don't have a storage path we should error out here
     28        # more than likely this will not happen
     29        if not os.path.isdir(self.storage_path):
     30            raise \
     31                ImproperlyConfigured("Storage path: %s is not a valid directory" % self.storage_path)
     32       
    1233        self.file_prefix = settings.SESSION_COOKIE_NAME   
    1334        super(SessionStore, self).__init__(session_key)
    1435   
Back to Top