paulb@1 | 1 | #!/usr/bin/env python |
paulb@1 | 2 | |
paulb@1 | 3 | """ |
paulb@1 | 4 | Twisted classes. |
paulb@403 | 5 | |
paulb@623 | 6 | Copyright (C) 2004, 2005, 2006, 2007 Paul Boddie <paul@boddie.org.uk> |
paulb@403 | 7 | |
paulb@403 | 8 | This library is free software; you can redistribute it and/or |
paulb@403 | 9 | modify it under the terms of the GNU Lesser General Public |
paulb@403 | 10 | License as published by the Free Software Foundation; either |
paulb@403 | 11 | version 2.1 of the License, or (at your option) any later version. |
paulb@403 | 12 | |
paulb@403 | 13 | This library is distributed in the hope that it will be useful, |
paulb@403 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
paulb@403 | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
paulb@403 | 16 | Lesser General Public License for more details. |
paulb@403 | 17 | |
paulb@403 | 18 | You should have received a copy of the GNU Lesser General Public |
paulb@403 | 19 | License along with this library; if not, write to the Free Software |
paulb@489 | 20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
paulb@1 | 21 | """ |
paulb@1 | 22 | |
paulb@463 | 23 | import WebStack.Generic |
paulb@463 | 24 | from WebStack.Helpers.Auth import UserInfo |
paulb@463 | 25 | from WebStack.Helpers.Request import Cookie, decode_value, filter_fields |
paulb@463 | 26 | from WebStack.Helpers.Response import ConvertingStream |
paulb@463 | 27 | from WebStack.Helpers.Session import SessionStore |
paulb@71 | 28 | from cgi import parse_qs |
paulb@1 | 29 | |
paulb@463 | 30 | class Transaction(WebStack.Generic.Transaction): |
paulb@1 | 31 | |
paulb@1 | 32 | """ |
paulb@1 | 33 | Twisted transaction interface. |
paulb@1 | 34 | """ |
paulb@1 | 35 | |
paulb@1 | 36 | def __init__(self, trans): |
paulb@1 | 37 | |
paulb@1 | 38 | "Initialise the transaction using the Twisted transaction 'trans'." |
paulb@1 | 39 | |
paulb@1 | 40 | self.trans = trans |
paulb@311 | 41 | self.content_type = None |
paulb@1 | 42 | |
paulb@239 | 43 | # Special objects retained throughout the transaction. |
paulb@239 | 44 | |
paulb@239 | 45 | self.session_store = None |
paulb@239 | 46 | |
paulb@239 | 47 | def commit(self): |
paulb@239 | 48 | |
paulb@239 | 49 | """ |
paulb@239 | 50 | A special method, synchronising the transaction with framework-specific |
paulb@239 | 51 | objects. |
paulb@239 | 52 | """ |
paulb@239 | 53 | |
paulb@239 | 54 | # Close the session store. |
paulb@239 | 55 | |
paulb@239 | 56 | if self.session_store is not None: |
paulb@239 | 57 | self.session_store.close() |
paulb@239 | 58 | |
paulb@338 | 59 | # Server-related methods. |
paulb@338 | 60 | |
paulb@338 | 61 | def get_server_name(self): |
paulb@338 | 62 | |
paulb@338 | 63 | "Returns the server name." |
paulb@338 | 64 | |
paulb@338 | 65 | return self.trans.getRequestHostname() |
paulb@338 | 66 | |
paulb@338 | 67 | def get_server_port(self): |
paulb@338 | 68 | |
paulb@338 | 69 | "Returns the server port as a string." |
paulb@338 | 70 | |
paulb@345 | 71 | return str(self.trans.getHost()[2]) |
paulb@338 | 72 | |
paulb@1 | 73 | # Request-related methods. |
paulb@1 | 74 | |
paulb@1 | 75 | def get_request_stream(self): |
paulb@1 | 76 | |
paulb@1 | 77 | """ |
paulb@186 | 78 | Returns the request stream for the transaction. |
paulb@1 | 79 | """ |
paulb@1 | 80 | |
paulb@5 | 81 | return self.trans.content |
paulb@1 | 82 | |
paulb@1 | 83 | def get_request_method(self): |
paulb@1 | 84 | |
paulb@1 | 85 | """ |
paulb@186 | 86 | Returns the request method. |
paulb@1 | 87 | """ |
paulb@1 | 88 | |
paulb@1 | 89 | return self.trans.method |
paulb@1 | 90 | |
paulb@1 | 91 | def get_headers(self): |
paulb@1 | 92 | |
paulb@1 | 93 | """ |
paulb@186 | 94 | Returns all request headers as a dictionary-like object mapping header |
paulb@186 | 95 | names to values. |
paulb@186 | 96 | |
paulb@91 | 97 | NOTE: If duplicate header names are permitted, then this interface will |
paulb@91 | 98 | NOTE: need to change. |
paulb@1 | 99 | """ |
paulb@1 | 100 | |
paulb@65 | 101 | return self.trans.received_headers |
paulb@65 | 102 | |
paulb@65 | 103 | def get_header_values(self, key): |
paulb@1 | 104 | |
paulb@65 | 105 | """ |
paulb@186 | 106 | Returns a list of all request header values associated with the given |
paulb@186 | 107 | 'key'. Note that according to RFC 2616, 'key' is treated as a |
paulb@186 | 108 | case-insensitive string. |
paulb@65 | 109 | """ |
paulb@65 | 110 | |
paulb@65 | 111 | # Twisted does not convert the header key to lower case (which is the |
paulb@65 | 112 | # stored representation). |
paulb@65 | 113 | |
paulb@65 | 114 | return self.convert_to_list(self.trans.received_headers.get(key.lower())) |
paulb@1 | 115 | |
paulb@1 | 116 | def get_content_type(self): |
paulb@1 | 117 | |
paulb@1 | 118 | """ |
paulb@186 | 119 | Returns the content type specified on the request, along with the |
paulb@186 | 120 | charset employed. |
paulb@1 | 121 | """ |
paulb@1 | 122 | |
paulb@1 | 123 | return self.parse_content_type(self.trans.getHeader("Content-Type")) |
paulb@1 | 124 | |
paulb@1 | 125 | def get_content_charsets(self): |
paulb@1 | 126 | |
paulb@1 | 127 | """ |
paulb@1 | 128 | Returns the character set preferences. |
paulb@1 | 129 | """ |
paulb@1 | 130 | |
paulb@1 | 131 | return self.parse_content_preferences(self.trans.getHeader("Accept-Language")) |
paulb@1 | 132 | |
paulb@1 | 133 | def get_content_languages(self): |
paulb@1 | 134 | |
paulb@1 | 135 | """ |
paulb@186 | 136 | Returns extracted language information from the transaction. |
paulb@1 | 137 | """ |
paulb@1 | 138 | |
paulb@1 | 139 | return self.parse_content_preferences(self.trans.getHeader("Accept-Charset")) |
paulb@1 | 140 | |
paulb@434 | 141 | def get_path(self, encoding=None): |
paulb@5 | 142 | |
paulb@5 | 143 | """ |
paulb@434 | 144 | Returns the entire path from the request as a Unicode object. Any "URL |
paulb@434 | 145 | encoded" character values in the part of the path before the query |
paulb@434 | 146 | string will be decoded and presented as genuine characters; the query |
paulb@434 | 147 | string will remain "URL encoded", however. |
paulb@434 | 148 | |
paulb@434 | 149 | If the optional 'encoding' is set, use that in preference to the default |
paulb@434 | 150 | encoding to convert the path into a form not containing "URL encoded" |
paulb@434 | 151 | character values. |
paulb@5 | 152 | """ |
paulb@5 | 153 | |
paulb@434 | 154 | path = self.get_path_without_query(encoding) |
paulb@434 | 155 | qs = self.get_query_string() |
paulb@434 | 156 | if qs: |
paulb@434 | 157 | return path + "?" + qs |
paulb@434 | 158 | else: |
paulb@434 | 159 | return path |
paulb@5 | 160 | |
paulb@434 | 161 | def get_path_without_query(self, encoding=None): |
paulb@162 | 162 | |
paulb@162 | 163 | """ |
paulb@434 | 164 | Returns the entire path from the request minus the query string as a |
paulb@434 | 165 | Unicode object containing genuine characters (as opposed to "URL |
paulb@434 | 166 | encoded" character values). |
paulb@434 | 167 | |
paulb@434 | 168 | If the optional 'encoding' is set, use that in preference to the default |
paulb@434 | 169 | encoding to convert the path into a form not containing "URL encoded" |
paulb@434 | 170 | character values. |
paulb@162 | 171 | """ |
paulb@162 | 172 | |
paulb@434 | 173 | return self.decode_path(self.trans.uri.split("?")[0], encoding) |
paulb@162 | 174 | |
paulb@434 | 175 | def get_path_info(self, encoding=None): |
paulb@1 | 176 | |
paulb@1 | 177 | """ |
paulb@186 | 178 | Returns the "path info" (the part of the URL after the resource name |
paulb@434 | 179 | handling the current request) from the request as a Unicode object |
paulb@434 | 180 | containing genuine characters (as opposed to "URL encoded" character |
paulb@434 | 181 | values). |
paulb@434 | 182 | |
paulb@434 | 183 | If the optional 'encoding' is set, use that in preference to the default |
paulb@434 | 184 | encoding to convert the path into a form not containing "URL encoded" |
paulb@434 | 185 | character values. |
paulb@1 | 186 | """ |
paulb@1 | 187 | |
paulb@623 | 188 | encoding = encoding or self.default_charset |
paulb@623 | 189 | |
paulb@439 | 190 | return decode_value("/%s" % "/".join(self.trans.postpath), encoding) |
paulb@1 | 191 | |
paulb@69 | 192 | def get_query_string(self): |
paulb@69 | 193 | |
paulb@69 | 194 | """ |
paulb@186 | 195 | Returns the query string from the path in the request. |
paulb@69 | 196 | """ |
paulb@69 | 197 | |
paulb@434 | 198 | t = self.trans.uri.split("?") |
paulb@69 | 199 | if len(t) == 1: |
paulb@69 | 200 | return "" |
paulb@69 | 201 | else: |
paulb@69 | 202 | |
paulb@69 | 203 | # NOTE: Overlook erroneous usage of "?" characters in the path. |
paulb@69 | 204 | |
paulb@69 | 205 | return "?".join(t[1:]) |
paulb@69 | 206 | |
paulb@1 | 207 | # Higher level request-related methods. |
paulb@1 | 208 | |
paulb@430 | 209 | def get_fields_from_path(self, encoding=None): |
paulb@69 | 210 | |
paulb@69 | 211 | """ |
paulb@249 | 212 | Extracts fields (or request parameters) from the path specified in the |
paulb@249 | 213 | transaction. The underlying framework may refuse to supply fields from |
paulb@430 | 214 | the path if handling a POST transaction. The optional 'encoding' |
paulb@430 | 215 | parameter specifies the character encoding of the query string for cases |
paulb@430 | 216 | where the default encoding is to be overridden. |
paulb@69 | 217 | |
paulb@71 | 218 | Returns a dictionary mapping field names to lists of values (even if a |
paulb@71 | 219 | single value is associated with any given field name). |
paulb@69 | 220 | """ |
paulb@69 | 221 | |
paulb@623 | 222 | encoding = encoding or self.default_charset |
paulb@623 | 223 | |
paulb@249 | 224 | fields = {} |
paulb@249 | 225 | for name, values in parse_qs(self.get_query_string(), keep_blank_values=1).items(): |
paulb@439 | 226 | name = decode_value(name, encoding) |
paulb@249 | 227 | fields[name] = [] |
paulb@249 | 228 | for value in values: |
paulb@439 | 229 | value = decode_value(value, encoding) |
paulb@430 | 230 | fields[name].append(value) |
paulb@249 | 231 | return fields |
paulb@69 | 232 | |
paulb@167 | 233 | def get_fields_from_body(self, encoding=None): |
paulb@69 | 234 | |
paulb@69 | 235 | """ |
paulb@249 | 236 | Extracts fields (or request parameters) from the message body in the |
paulb@249 | 237 | transaction. The optional 'encoding' parameter specifies the character |
paulb@249 | 238 | encoding of the message body for cases where no such information is |
paulb@249 | 239 | available, but where the default encoding is to be overridden. |
paulb@69 | 240 | |
paulb@73 | 241 | Returns a dictionary mapping field names to lists of values (even if a |
paulb@193 | 242 | single value is associated with any given field name). Each value is |
paulb@193 | 243 | either a Unicode object (representing a simple form field, for example) |
paulb@543 | 244 | or a WebStack.Helpers.Request.FileContent object (representing a file |
paulb@543 | 245 | upload form field). |
paulb@543 | 246 | |
paulb@543 | 247 | NOTE: Twisted does not currently support file uploads correctly and a |
paulb@543 | 248 | NOTE: Unicode object will be returned for such fields instead. |
paulb@69 | 249 | """ |
paulb@69 | 250 | |
paulb@249 | 251 | # There may not be a reliable means of extracting only the fields |
paulb@249 | 252 | # the message body using the API. Remove fields originating from the |
paulb@249 | 253 | # path in the mixture provided by the API. |
paulb@228 | 254 | |
paulb@249 | 255 | all_fields = self._get_fields(encoding) |
paulb@228 | 256 | fields_from_path = self.get_fields_from_path() |
paulb@249 | 257 | return filter_fields(all_fields, fields_from_path) |
paulb@224 | 258 | |
paulb@249 | 259 | def _get_fields(self, encoding=None): |
paulb@224 | 260 | encoding = encoding or self.get_content_type().charset or self.default_charset |
paulb@167 | 261 | fields = {} |
paulb@167 | 262 | for field_name, field_values in self.trans.args.items(): |
paulb@439 | 263 | field_name = decode_value(field_name, encoding) |
paulb@434 | 264 | |
paulb@228 | 265 | # Find the body values. |
paulb@228 | 266 | |
paulb@198 | 267 | if type(field_values) == type([]): |
paulb@198 | 268 | fields[field_name] = [] |
paulb@198 | 269 | |
paulb@198 | 270 | # Twisted stores plain strings. |
paulb@198 | 271 | |
paulb@198 | 272 | for field_str in field_values: |
paulb@439 | 273 | fields[field_name].append(decode_value(field_str, encoding)) |
paulb@198 | 274 | else: |
paulb@439 | 275 | fields[field_name] = decode_value(field_values, encoding) |
paulb@228 | 276 | |
paulb@167 | 277 | return fields |
paulb@1 | 278 | |
paulb@249 | 279 | def get_fields(self, encoding=None): |
paulb@249 | 280 | |
paulb@249 | 281 | """ |
paulb@249 | 282 | Extracts fields (or request parameters) from both the path specified in |
paulb@249 | 283 | the transaction as well as the message body. The optional 'encoding' |
paulb@249 | 284 | parameter specifies the character encoding of the message body for cases |
paulb@249 | 285 | where no such information is available, but where the default encoding |
paulb@249 | 286 | is to be overridden. |
paulb@249 | 287 | |
paulb@249 | 288 | Returns a dictionary mapping field names to lists of values (even if a |
paulb@249 | 289 | single value is associated with any given field name). Each value is |
paulb@249 | 290 | either a Unicode object (representing a simple form field, for example) |
paulb@543 | 291 | or a WebStack.Helpers.Request.FileContent object (representing a file |
paulb@543 | 292 | upload form field). |
paulb@543 | 293 | |
paulb@543 | 294 | NOTE: Twisted does not currently support file uploads correctly and a |
paulb@543 | 295 | NOTE: Unicode object will be returned for such fields instead. |
paulb@249 | 296 | |
paulb@249 | 297 | Where a given field name is used in both the path and message body to |
paulb@249 | 298 | specify values, the values from both sources will be combined into a |
paulb@249 | 299 | single list associated with that field name. |
paulb@249 | 300 | """ |
paulb@249 | 301 | |
paulb@249 | 302 | return self._get_fields(encoding) |
paulb@249 | 303 | |
paulb@45 | 304 | def get_user(self): |
paulb@1 | 305 | |
paulb@1 | 306 | """ |
paulb@186 | 307 | Extracts user information from the transaction. |
paulb@108 | 308 | |
paulb@108 | 309 | Returns a username as a string or None if no user is defined. |
paulb@1 | 310 | """ |
paulb@1 | 311 | |
paulb@128 | 312 | # Twisted makes headers lower case. |
paulb@128 | 313 | |
paulb@128 | 314 | if self.user is not None: |
paulb@128 | 315 | return self.user |
paulb@45 | 316 | |
paulb@49 | 317 | auth_header = self.get_headers().get("authorization") |
paulb@49 | 318 | if auth_header: |
paulb@49 | 319 | return UserInfo(auth_header).username |
paulb@49 | 320 | else: |
paulb@49 | 321 | return None |
paulb@1 | 322 | |
paulb@104 | 323 | def get_cookies(self): |
paulb@104 | 324 | |
paulb@104 | 325 | """ |
paulb@186 | 326 | Obtains cookie information from the request. |
paulb@104 | 327 | |
paulb@104 | 328 | Returns a dictionary mapping cookie names to cookie objects. |
paulb@104 | 329 | NOTE: Twisted does not seem to support this operation via methods. Thus, |
paulb@104 | 330 | NOTE: direct access has been employed to get the dictionary. |
paulb@104 | 331 | NOTE: Twisted also returns a plain string - a Cookie object is therefore |
paulb@104 | 332 | NOTE: introduced. |
paulb@104 | 333 | """ |
paulb@104 | 334 | |
paulb@258 | 335 | return self.process_cookies(self.trans.received_cookies, using_strings=1) |
paulb@104 | 336 | |
paulb@104 | 337 | def get_cookie(self, cookie_name): |
paulb@104 | 338 | |
paulb@104 | 339 | """ |
paulb@186 | 340 | Obtains cookie information from the request. |
paulb@104 | 341 | |
paulb@104 | 342 | Returns a cookie object for the given 'cookie_name' or None if no such |
paulb@104 | 343 | cookie exists. |
paulb@104 | 344 | NOTE: Twisted also returns a plain string - a Cookie object is therefore |
paulb@104 | 345 | NOTE: introduced. |
paulb@104 | 346 | """ |
paulb@104 | 347 | |
paulb@258 | 348 | value = self.trans.getCookie(self.encode_cookie_value(cookie_name)) |
paulb@258 | 349 | if value is not None: |
paulb@258 | 350 | return Cookie(cookie_name, self.decode_cookie_value(value)) |
paulb@258 | 351 | else: |
paulb@258 | 352 | return None |
paulb@104 | 353 | |
paulb@1 | 354 | # Response-related methods. |
paulb@1 | 355 | |
paulb@1 | 356 | def get_response_stream(self): |
paulb@1 | 357 | |
paulb@1 | 358 | """ |
paulb@186 | 359 | Returns the response stream for the transaction. |
paulb@1 | 360 | """ |
paulb@1 | 361 | |
paulb@224 | 362 | # Unicode can upset this operation. Using either the specified charset |
paulb@224 | 363 | # or a default encoding. |
paulb@167 | 364 | |
paulb@252 | 365 | encoding = self.get_response_stream_encoding() |
paulb@252 | 366 | return ConvertingStream(self.trans, encoding) |
paulb@252 | 367 | |
paulb@252 | 368 | def get_response_stream_encoding(self): |
paulb@252 | 369 | |
paulb@252 | 370 | """ |
paulb@252 | 371 | Returns the response stream encoding. |
paulb@252 | 372 | """ |
paulb@252 | 373 | |
paulb@167 | 374 | if self.content_type: |
paulb@224 | 375 | encoding = self.content_type.charset |
paulb@252 | 376 | else: |
paulb@252 | 377 | encoding = None |
paulb@252 | 378 | return encoding or self.default_charset |
paulb@1 | 379 | |
paulb@42 | 380 | def get_response_code(self): |
paulb@42 | 381 | |
paulb@42 | 382 | """ |
paulb@42 | 383 | Get the response code associated with the transaction. If no response |
paulb@42 | 384 | code is defined, None is returned. |
paulb@42 | 385 | """ |
paulb@42 | 386 | |
paulb@42 | 387 | # NOTE: Accessing the request attribute directly. |
paulb@42 | 388 | |
paulb@42 | 389 | return self.trans.code |
paulb@42 | 390 | |
paulb@42 | 391 | def set_response_code(self, response_code): |
paulb@42 | 392 | |
paulb@42 | 393 | """ |
paulb@42 | 394 | Set the 'response_code' using a numeric constant defined in the HTTP |
paulb@42 | 395 | specification. |
paulb@42 | 396 | """ |
paulb@42 | 397 | |
paulb@42 | 398 | self.trans.setResponseCode(response_code) |
paulb@42 | 399 | |
paulb@67 | 400 | def set_header_value(self, header, value): |
paulb@49 | 401 | |
paulb@49 | 402 | """ |
paulb@49 | 403 | Set the HTTP 'header' with the given 'value'. |
paulb@49 | 404 | """ |
paulb@49 | 405 | |
paulb@49 | 406 | self.trans.setHeader(self.format_header_value(header), self.format_header_value(value)) |
paulb@49 | 407 | |
paulb@1 | 408 | def set_content_type(self, content_type): |
paulb@1 | 409 | |
paulb@1 | 410 | """ |
paulb@186 | 411 | Sets the 'content_type' for the response. |
paulb@1 | 412 | """ |
paulb@1 | 413 | |
paulb@167 | 414 | # Remember the content type for encoding purposes later. |
paulb@167 | 415 | |
paulb@167 | 416 | self.content_type = content_type |
paulb@224 | 417 | self.trans.setHeader("Content-Type", str(content_type)) |
paulb@1 | 418 | |
paulb@104 | 419 | # Higher level response-related methods. |
paulb@104 | 420 | |
paulb@104 | 421 | def set_cookie(self, cookie): |
paulb@104 | 422 | |
paulb@104 | 423 | """ |
paulb@186 | 424 | Stores the given 'cookie' object in the response. |
paulb@104 | 425 | """ |
paulb@104 | 426 | |
paulb@258 | 427 | self.set_cookie_value(cookie.name, cookie.value, path=cookie.path, expires=cookie.expires) |
paulb@104 | 428 | |
paulb@104 | 429 | def set_cookie_value(self, name, value, path=None, expires=None): |
paulb@104 | 430 | |
paulb@104 | 431 | """ |
paulb@186 | 432 | Stores a cookie with the given 'name' and 'value' in the response. |
paulb@104 | 433 | |
paulb@104 | 434 | The optional 'path' is a string which specifies the scope of the cookie, |
paulb@104 | 435 | and the optional 'expires' parameter is a value compatible with the |
paulb@104 | 436 | time.time function, and indicates the expiry date/time of the cookie. |
paulb@104 | 437 | """ |
paulb@104 | 438 | |
paulb@258 | 439 | self.trans.addCookie(self.encode_cookie_value(name), |
paulb@258 | 440 | self.encode_cookie_value(value), expires=expires, path=path) |
paulb@104 | 441 | |
paulb@104 | 442 | def delete_cookie(self, cookie_name): |
paulb@104 | 443 | |
paulb@104 | 444 | """ |
paulb@186 | 445 | Adds to the response a request that the cookie with the given |
paulb@186 | 446 | 'cookie_name' be deleted/discarded by the client. |
paulb@104 | 447 | """ |
paulb@104 | 448 | |
paulb@108 | 449 | # Create a special cookie, given that we do not know whether the browser |
paulb@108 | 450 | # has been sent the cookie or not. |
paulb@108 | 451 | # NOTE: Magic discovered in Webware. |
paulb@108 | 452 | |
paulb@258 | 453 | self.trans.addCookie(self.encode_cookie_value(cookie_name), "", expires=0, path="/", max_age=0) |
paulb@104 | 454 | |
paulb@239 | 455 | # Session-related methods. |
paulb@239 | 456 | |
paulb@239 | 457 | def get_session(self, create=1): |
paulb@239 | 458 | |
paulb@239 | 459 | """ |
paulb@239 | 460 | Gets a session corresponding to an identifier supplied in the |
paulb@239 | 461 | transaction. |
paulb@239 | 462 | |
paulb@239 | 463 | If no session has yet been established according to information |
paulb@239 | 464 | provided in the transaction then the optional 'create' parameter |
paulb@239 | 465 | determines whether a new session will be established. |
paulb@239 | 466 | |
paulb@239 | 467 | Where no session has been established and where 'create' is set to 0 |
paulb@239 | 468 | then None is returned. In all other cases, a session object is created |
paulb@239 | 469 | (where appropriate) and returned. |
paulb@239 | 470 | """ |
paulb@239 | 471 | |
paulb@239 | 472 | # NOTE: Requires configuration. |
paulb@239 | 473 | |
paulb@239 | 474 | if self.session_store is None: |
paulb@239 | 475 | self.session_store = SessionStore(self, "WebStack-sessions") |
paulb@239 | 476 | return self.session_store.get_session(create) |
paulb@239 | 477 | |
paulb@239 | 478 | def expire_session(self): |
paulb@239 | 479 | |
paulb@239 | 480 | """ |
paulb@239 | 481 | Expires any session established according to information provided in the |
paulb@239 | 482 | transaction. |
paulb@239 | 483 | """ |
paulb@239 | 484 | |
paulb@239 | 485 | # NOTE: Requires configuration. |
paulb@239 | 486 | |
paulb@239 | 487 | if self.session_store is None: |
paulb@239 | 488 | self.session_store = SessionStore(self, "WebStack-sessions") |
paulb@239 | 489 | self.session_store.expire_session() |
paulb@239 | 490 | |
paulb@1 | 491 | # vim: tabstop=4 expandtab shiftwidth=4 |