1+ # vim: set sw=4 expandtab :
12 #
23 # Copyright 2004 Apache Software Foundation
34 #
@@ -141,27 +142,35 @@ def __init__(self, req, sid=None, secret=None, lock=1,
141142 if config .has_key ("mod_python.session.cookie_name" ):
142143 session_cookie_name = config .get ("mod_python.session.cookie_name" , COOKIE_NAME )
143144 else :
144- # For backwards compatability only.
145+ # For backwards compatability with versions
146+ # of mod_python prior to 3.3.
145147 session_cookie_name = config .get ("session_cookie_name" , COOKIE_NAME )
146148
147149 if not self ._sid :
148150 # check to see if cookie exists
149151 if secret :
150- cookies = Cookie .get_cookies (req , Class = Cookie .SignedCookie ,
151- secret = self ._secret )
152+ cookie = Cookie .get_cookie (req , session_cookie_name ,
153+ Class = Cookie .SignedCookie ,
154+ secret = self ._secret ,
155+ mismatch = Cookie .Cookie .IGNORE )
152156 else :
153- cookies = Cookie .get_cookies (req )
157+ cookie = Cookie .get_cookie (req , session_cookie_name )
158+
159+ if cookie :
160+ self ._sid = cookie .value
154161
155- if cookies .has_key (session_cookie_name ):
156- self ._sid = cookies [session_cookie_name ].value
157-
158162 if self ._sid :
159- # Validate the sid *before* locking the session
160- # _check_sid will raise an apache.SERVER_RETURN exception
161163 if not _check_sid (self ._sid ):
162- self ._req .log_error ("mod_python.Session warning: The session id contains invalid characters, valid characters are only 0-9 and a-f" ,
163- apache .APLOG_WARNING )
164- raise apache .SERVER_RETURN , apache .HTTP_INTERNAL_SERVER_ERROR
164+ if sid :
165+ # Supplied explicitly by user of the class,
166+ # raise an exception and make the user code
167+ # deal with it.
168+ raise ValueError ("Invalid Session ID: sid=%s" % sid )
169+ else :
170+ # Derived from the cookie sent by browser,
171+ # wipe it out so it gets replaced with a
172+ # correct value.
173+ self ._sid = None
165174
166175 self .init_lock ()
167176
@@ -194,7 +203,8 @@ def make_cookie(self):
194203 if config .has_key ("mod_python.session.cookie_name" ):
195204 session_cookie_name = config .get ("mod_python.session.cookie_name" , COOKIE_NAME )
196205 else :
197- # For backwards compatability only.
206+ # For backwards compatability with versions
207+ # of mod_python prior to 3.3.
198208 session_cookie_name = config .get ("session_cookie_name" , COOKIE_NAME )
199209
200210 if self ._secret :
@@ -208,7 +218,8 @@ def make_cookie(self):
208218 if config .has_key ("mod_python.session.application_path" ):
209219 c .path = config ["mod_python.session.application_path" ]
210220 elif config .has_key ("ApplicationPath" ):
211- # For backwards compatability only.
221+ # For backwards compatability with versions
222+ # of mod_python prior to 3.3.
212223 c .path = config ["ApplicationPath" ]
213224 else :
214225 # the path where *Handler directive was specified
@@ -342,14 +353,16 @@ def __init__(self, req, dbm=None, sid=0, secret=None, dbmtype=anydbm,
342353 if opts .has_key ("mod_python.dbm_session.database_filename" ):
343354 dbm = opts ["mod_python.dbm_session.database_filename" ]
344355 elif opts .has_key ("session_dbm" ):
345- # For backwards compatability only.
356+ # For backwards compatability with versions
357+ # of mod_python prior to 3.3.
346358 dbm = opts ["session_dbm" ]
347359 elif opts .has_key ("mod_python.dbm_session.database_directory" ):
348360 dbm = os .path .join (opts .get ('mod_python.dbm_session.database_directory' , tempdir ), 'mp_sess.dbm' )
349361 elif opts .has_key ("mod_python.session.database_directory" ):
350362 dbm = os .path .join (opts .get ('mod_python.session.database_directory' , tempdir ), 'mp_sess.dbm' )
351363 else :
352- # For backwards compatability only.
364+ # For backwards compatability with versions
365+ # of mod_python prior to 3.3.
353366 dbm = os .path .join (opts .get ('session_directory' , tempdir ), 'mp_sess.dbm' )
354367
355368 self ._dbmfile = dbm
@@ -427,7 +440,8 @@ def __init__(self, req, sid=0, secret=None, timeout=0, lock=1,
427440 if opts .has_key ('mod_python.file_session.enable_fast_cleanup' ):
428441 self ._fast_cleanup = true_or_false (opts .get ('mod_python.file_session.enable_fast_cleanup' , DFT_FAST_CLEANUP ))
429442 else :
430- # For backwards compatability only.
443+ # For backwards compatability with versions
444+ # of mod_python prior to 3.3.
431445 self ._fast_cleanup = true_or_false (opts .get ('session_fast_cleanup' , DFT_FAST_CLEANUP ))
432446 else :
433447 self ._fast_cleanup = fast_cleanup
@@ -436,29 +450,33 @@ def __init__(self, req, sid=0, secret=None, timeout=0, lock=1,
436450 if opts .has_key ('mod_python.file_session.verify_session_timeout' ):
437451 self ._verify_cleanup = true_or_false (opts .get ('mod_python.file_session.verify_session_timeout' , DFT_VERIFY_CLEANUP ))
438452 else :
439- # For backwards compatability only.
453+ # For backwards compatability with versions
454+ # of mod_python prior to 3.3.
440455 self ._verify_cleanup = true_or_false (opts .get ('session_verify_cleanup' , DFT_VERIFY_CLEANUP ))
441456 else :
442457 self ._verify_cleanup = verify_cleanup
443458
444459 if opts .has_key ('mod_python.file_session.cleanup_grace_period' ):
445460 self ._grace_period = int (opts .get ('mod_python.file_session.cleanup_grace_period' , DFT_GRACE_PERIOD ))
446461 else :
447- # For backwards compatability only.
462+ # For backwards compatability with versions
463+ # of mod_python prior to 3.3.
448464 self ._grace_period = int (opts .get ('session_grace_period' , DFT_GRACE_PERIOD ))
449465
450466 if opts .has_key ('mod_python.file_session.cleanup_time_limit' ):
451467 self ._cleanup_time_limit = int (opts .get ('mod_python.file_session.cleanup_time_limit' ,DFT_CLEANUP_TIME_LIMIT ))
452468 else :
453- # For backwards compatability only.
469+ # For backwards compatability with versions
470+ # of mod_python prior to 3.3.
454471 self ._cleanup_time_limit = int (opts .get ('session_cleanup_time_limit' ,DFT_CLEANUP_TIME_LIMIT ))
455472
456473 if opts .has_key ('mod_python.file_session.database_directory' ):
457474 self ._sessdir = os .path .join (opts .get ('mod_python.file_session.database_directory' , tempdir ), 'mp_sess' )
458475 elif opts .has_key ('mod_python.session.database_directory' ):
459476 self ._sessdir = os .path .join (opts .get ('mod_python.session.database_directory' , tempdir ), 'mp_sess' )
460477 else :
461- # For backwards compatability only.
478+ # For backwards compatability with versions
479+ # of mod_python prior to 3.3.
462480 self ._sessdir = os .path .join (opts .get ('session_directory' , tempdir ), 'mp_sess' )
463481
464482 # FIXME
@@ -756,7 +774,8 @@ def Session(req, sid=0, secret=None, timeout=0, lock=1):
756774 if opts .has_key ('mod_python.session.session_type' ):
757775 sess_type = opts ['mod_python.session.session_type' ]
758776 elif opts .has_key ('session' ):
759- # For backwards compatability only.
777+ # For backwards compatability with versions
778+ # of mod_python prior to 3.3.
760779 sess_type = opts ['session' ]
761780 else :
762781 # no session class in config so get the default for the platform
0 commit comments