Ticket #10899: easy_session_manipulation.diff
File easy_session_manipulation.diff, 3.9 KB (added by , 16 years ago) |
---|
-
test/client.py
class Client(object): 166 166 self.cookies = SimpleCookie() 167 167 self.exc_info = None 168 168 self.errors = StringIO() 169 self._session_cache = None 169 170 170 171 def store_exc_info(self, **kwargs): 171 172 """ … … class Client(object): 177 178 """ 178 179 Obtains the current session variables. 179 180 """ 180 if 'django.contrib.sessions' in settings.INSTALLED_APPS: 181 engine = import_module(settings.SESSION_ENGINE) 182 cookie = self.cookies.get(settings.SESSION_COOKIE_NAME, None) 183 if cookie: 184 return engine.SessionStore(cookie.value) 185 return {} 181 if self._session_cache == None: 182 if 'django.contrib.sessions' in settings.INSTALLED_APPS: 183 engine = import_module(settings.SESSION_ENGINE) 184 cookie = self.cookies.get(settings.SESSION_COOKIE_NAME, None) 185 if cookie: 186 self._session_cache = engine.SessionStore(cookie.value) 187 else: 188 self._session_cache = engine.SessionStore() 189 self._session_cache.save() # make load() work so the cookie isn't worthless 190 self.cookies[settings.SESSION_COOKIE_NAME] = self._session_cache.session_key 191 else: 192 self._session_cache = {} 193 return self._session_cache 194 def _session_save(self): 195 if self._session_cache: 196 self._session_cache.save() 197 self._session_cache = None 198 186 199 session = property(_session) 187 200 188 201 def request(self, **request): … … class Client(object): 268 281 """ 269 282 Requests a response from the server using GET. 270 283 """ 284 self._session_save() 271 285 parsed = urlparse(path) 272 286 r = { 273 287 'CONTENT_TYPE': 'text/html; charset=utf-8', … … class Client(object): 288 302 """ 289 303 Requests a response from the server using POST. 290 304 """ 305 self._session_save() 291 306 if content_type is MULTIPART_CONTENT: 292 307 post_data = encode_multipart(BOUNDARY, data) 293 308 else: … … class Client(object): 319 334 """ 320 335 Request a response from the server using HEAD. 321 336 """ 337 self._session_save() 322 338 parsed = urlparse(path) 323 339 r = { 324 340 'CONTENT_TYPE': 'text/html; charset=utf-8', … … class Client(object): 338 354 """ 339 355 Request a response from the server using OPTIONS. 340 356 """ 357 self._session_save() 341 358 parsed = urlparse(path) 342 359 r = { 343 360 'PATH_INFO': urllib.unquote(parsed[2]), … … class Client(object): 357 374 """ 358 375 Send a resource to the server using PUT. 359 376 """ 377 self._session_save() 360 378 if content_type is MULTIPART_CONTENT: 361 379 post_data = encode_multipart(BOUNDARY, data) 362 380 else: … … class Client(object): 382 400 """ 383 401 Send a DELETE request to the server. 384 402 """ 403 self._session_save() 385 404 parsed = urlparse(path) 386 405 r = { 387 406 'PATH_INFO': urllib.unquote(parsed[2]), … … class Client(object): 404 423 are incorrect, or the user is inactive, or if the sessions framework is 405 424 not available. 406 425 """ 426 self._session_save() 407 427 user = authenticate(**credentials) 408 428 if user and user.is_active \ 409 429 and 'django.contrib.sessions' in settings.INSTALLED_APPS: … … class Client(object): 442 462 443 463 Causes the authenticated user to be logged out. 444 464 """ 465 self._session_cache = None 445 466 session = import_module(settings.SESSION_ENGINE).SessionStore() 446 467 session_cookie = self.cookies.get(settings.SESSION_COOKIE_NAME) 447 468 if session_cookie: