paulb@1 | 1 | #!/usr/bin/env python |
paulb@1 | 2 | |
paulb@1 | 3 | """ |
paulb@1 | 4 | Webware classes. |
paulb@403 | 5 | |
paulb@562 | 6 | Copyright (C) 2004, 2005, 2006 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@71 | 24 | from cgi import parse_qs |
paulb@85 | 25 | import StringIO |
paulb@463 | 26 | from WebStack.Helpers import Environment |
paulb@463 | 27 | from WebStack.Helpers.Request import Cookie, get_body_field_or_file, decode_value, filter_fields |
paulb@463 | 28 | from WebStack.Helpers.Response import ConvertingStream |
paulb@1 | 29 | |
paulb@463 | 30 | class Transaction(WebStack.Generic.Transaction): |
paulb@1 | 31 | |
paulb@1 | 32 | """ |
paulb@1 | 33 | Webware 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 Webware transaction 'trans'." |
paulb@1 | 39 | |
paulb@1 | 40 | self.trans = trans |
paulb@311 | 41 | self.content_type = None |
paulb@1 | 42 | |
paulb@338 | 43 | # Server-related methods. |
paulb@338 | 44 | |
paulb@338 | 45 | def get_server_name(self): |
paulb@338 | 46 | |
paulb@338 | 47 | "Returns the server name." |
paulb@338 | 48 | |
paulb@338 | 49 | return self.trans.request().serverURL().split("/")[0].split(":")[0] |
paulb@338 | 50 | |
paulb@338 | 51 | def get_server_port(self): |
paulb@338 | 52 | |
paulb@338 | 53 | "Returns the server port as a string." |
paulb@338 | 54 | |
paulb@338 | 55 | host_and_port = self.trans.request().serverURL().split("/")[0].split(":") |
paulb@338 | 56 | if len(host_and_port) > 1: |
paulb@338 | 57 | return host_and_port[1] |
paulb@338 | 58 | else: |
paulb@338 | 59 | return "80" |
paulb@338 | 60 | |
paulb@1 | 61 | # Request-related methods. |
paulb@1 | 62 | |
paulb@1 | 63 | def get_request_stream(self): |
paulb@1 | 64 | |
paulb@1 | 65 | """ |
paulb@186 | 66 | Returns the request stream for the transaction. |
paulb@1 | 67 | """ |
paulb@1 | 68 | |
paulb@85 | 69 | request = self.trans.request() |
paulb@85 | 70 | try: |
paulb@85 | 71 | stream = request.rawInput(rewind=1) |
paulb@85 | 72 | if stream is None: |
paulb@85 | 73 | return StringIO.StringIO("") |
paulb@85 | 74 | |
paulb@85 | 75 | # NOTE: Dubious catch-all situation, but it is difficult to control |
paulb@85 | 76 | # NOTE: cases where Webware's internals themselves fail. |
paulb@85 | 77 | |
paulb@85 | 78 | except: |
paulb@1 | 79 | return StringIO.StringIO("") |
paulb@1 | 80 | |
paulb@1 | 81 | return stream |
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.request().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@91 | 101 | # Use the Webware environment and some assumptions about variable names. |
paulb@91 | 102 | # NOTE: Using lower case for the header names. |
paulb@1 | 103 | |
paulb@91 | 104 | env = self.trans.request().environ() |
paulb@108 | 105 | return Environment.get_headers(env) |
paulb@1 | 106 | |
paulb@65 | 107 | def get_header_values(self, key): |
paulb@65 | 108 | |
paulb@65 | 109 | """ |
paulb@186 | 110 | Returns a list of all request header values associated with the given |
paulb@186 | 111 | 'key'. Note that according to RFC 2616, 'key' is treated as a |
paulb@186 | 112 | case-insensitive string. |
paulb@65 | 113 | """ |
paulb@65 | 114 | |
paulb@91 | 115 | # Use the Webware environment and some assumptions about variable names. |
paulb@65 | 116 | |
paulb@91 | 117 | env = self.trans.request().environ() |
paulb@91 | 118 | cgi_key = "HTTP_" + key.replace("-", "_").upper() |
paulb@91 | 119 | if env.has_key(cgi_key): |
paulb@91 | 120 | return [env[cgi_key]] |
paulb@91 | 121 | else: |
paulb@91 | 122 | return [] |
paulb@65 | 123 | |
paulb@1 | 124 | def get_content_type(self): |
paulb@1 | 125 | |
paulb@1 | 126 | """ |
paulb@186 | 127 | Returns the content type specified on the request, along with the |
paulb@186 | 128 | charset employed. |
paulb@1 | 129 | """ |
paulb@1 | 130 | |
paulb@1 | 131 | return self.parse_content_type(self.trans.request().contentType()) |
paulb@1 | 132 | |
paulb@1 | 133 | def get_content_charsets(self): |
paulb@1 | 134 | |
paulb@1 | 135 | """ |
paulb@1 | 136 | Returns the character set preferences. |
paulb@1 | 137 | NOTE: Requires enhancements to HTTPRequest. |
paulb@1 | 138 | """ |
paulb@1 | 139 | |
paulb@1 | 140 | return self.trans.request().contentCharsets() |
paulb@1 | 141 | |
paulb@1 | 142 | def get_content_languages(self): |
paulb@1 | 143 | |
paulb@1 | 144 | """ |
paulb@186 | 145 | Returns extracted language information from the transaction. |
paulb@1 | 146 | NOTE: Requires enhancements to HTTPRequest. |
paulb@1 | 147 | """ |
paulb@1 | 148 | |
paulb@1 | 149 | return self.trans.request().contentLanguages() |
paulb@1 | 150 | |
paulb@434 | 151 | def get_path(self, encoding=None): |
paulb@5 | 152 | |
paulb@5 | 153 | """ |
paulb@434 | 154 | Returns the entire path from the request as a Unicode object. Any "URL |
paulb@434 | 155 | encoded" character values in the part of the path before the query |
paulb@434 | 156 | string will be decoded and presented as genuine characters; the query |
paulb@434 | 157 | string will remain "URL encoded", however. |
paulb@434 | 158 | |
paulb@434 | 159 | If the optional 'encoding' is set, use that in preference to the default |
paulb@434 | 160 | encoding to convert the path into a form not containing "URL encoded" |
paulb@434 | 161 | character values. |
paulb@5 | 162 | """ |
paulb@5 | 163 | |
paulb@434 | 164 | path = self.get_path_without_query(encoding) |
paulb@434 | 165 | qs = self.get_query_string() |
paulb@434 | 166 | if qs: |
paulb@434 | 167 | return path + "?" + qs |
paulb@434 | 168 | else: |
paulb@434 | 169 | return path |
paulb@5 | 170 | |
paulb@434 | 171 | def get_path_without_query(self, encoding=None): |
paulb@162 | 172 | |
paulb@162 | 173 | """ |
paulb@434 | 174 | Returns the entire path from the request minus the query string as a |
paulb@434 | 175 | Unicode object containing genuine characters (as opposed to "URL |
paulb@434 | 176 | encoded" character values). |
paulb@434 | 177 | |
paulb@434 | 178 | If the optional 'encoding' is set, use that in preference to the default |
paulb@434 | 179 | encoding to convert the path into a form not containing "URL encoded" |
paulb@434 | 180 | character values. |
paulb@162 | 181 | """ |
paulb@162 | 182 | |
paulb@434 | 183 | return self.decode_path(self.trans.request().uri().split("?")[0], encoding) |
paulb@162 | 184 | |
paulb@434 | 185 | def get_path_info(self, encoding=None): |
paulb@1 | 186 | |
paulb@1 | 187 | """ |
paulb@186 | 188 | Returns the "path info" (the part of the URL after the resource name |
paulb@434 | 189 | handling the current request) from the request as a Unicode object |
paulb@434 | 190 | containing genuine characters (as opposed to "URL encoded" character |
paulb@434 | 191 | values). |
paulb@434 | 192 | |
paulb@434 | 193 | If the optional 'encoding' is set, use that in preference to the default |
paulb@434 | 194 | encoding to convert the path into a form not containing "URL encoded" |
paulb@434 | 195 | character values. |
paulb@1 | 196 | """ |
paulb@1 | 197 | |
paulb@316 | 198 | path_info = self.trans.request().pathInfo() |
paulb@316 | 199 | context_name = self.trans.request().contextName() |
paulb@316 | 200 | if path_info.startswith(context_name): |
paulb@434 | 201 | real_path_info = path_info[len(context_name):] |
paulb@216 | 202 | else: |
paulb@434 | 203 | real_path_info = path_info |
paulb@439 | 204 | return decode_value(real_path_info, encoding) |
paulb@1 | 205 | |
paulb@69 | 206 | def get_query_string(self): |
paulb@69 | 207 | |
paulb@69 | 208 | """ |
paulb@186 | 209 | Returns the query string from the path in the request. |
paulb@69 | 210 | """ |
paulb@69 | 211 | |
paulb@69 | 212 | return self.trans.request().queryString() |
paulb@69 | 213 | |
paulb@1 | 214 | # Higher level request-related methods. |
paulb@1 | 215 | |
paulb@430 | 216 | def get_fields_from_path(self, encoding=None): |
paulb@69 | 217 | |
paulb@69 | 218 | """ |
paulb@249 | 219 | Extracts fields (or request parameters) from the path specified in the |
paulb@249 | 220 | transaction. The underlying framework may refuse to supply fields from |
paulb@430 | 221 | the path if handling a POST transaction. The optional 'encoding' |
paulb@430 | 222 | parameter specifies the character encoding of the query string for cases |
paulb@430 | 223 | where the default encoding is to be overridden. |
paulb@69 | 224 | |
paulb@71 | 225 | Returns a dictionary mapping field names to lists of values (even if a |
paulb@71 | 226 | single value is associated with any given field name). |
paulb@69 | 227 | """ |
paulb@69 | 228 | |
paulb@249 | 229 | fields = {} |
paulb@249 | 230 | for name, values in parse_qs(self.get_query_string(), keep_blank_values=1).items(): |
paulb@439 | 231 | name = decode_value(name, encoding) |
paulb@249 | 232 | fields[name] = [] |
paulb@249 | 233 | for value in values: |
paulb@439 | 234 | value = decode_value(value, encoding) |
paulb@430 | 235 | fields[name].append(value) |
paulb@249 | 236 | return fields |
paulb@69 | 237 | |
paulb@167 | 238 | def get_fields_from_body(self, encoding=None): |
paulb@69 | 239 | |
paulb@69 | 240 | """ |
paulb@249 | 241 | Extracts fields (or request parameters) from the message body in the |
paulb@249 | 242 | transaction. The optional 'encoding' parameter specifies the character |
paulb@249 | 243 | encoding of the message body for cases where no such information is |
paulb@249 | 244 | available, but where the default encoding is to be overridden. |
paulb@69 | 245 | |
paulb@73 | 246 | Returns a dictionary mapping field names to lists of values (even if a |
paulb@193 | 247 | single value is associated with any given field name). Each value is |
paulb@193 | 248 | either a Unicode object (representing a simple form field, for example) |
paulb@543 | 249 | or a WebStack.Helpers.Request.FileContent object (representing a file |
paulb@543 | 250 | upload form field). |
paulb@69 | 251 | """ |
paulb@69 | 252 | |
paulb@249 | 253 | all_fields = self._get_fields(encoding) |
paulb@249 | 254 | fields_from_path = self.get_fields_from_path() |
paulb@249 | 255 | return filter_fields(all_fields, fields_from_path) |
paulb@249 | 256 | |
paulb@249 | 257 | def _get_fields(self, encoding=None): |
paulb@224 | 258 | encoding = encoding or self.get_content_type().charset or self.default_charset |
paulb@73 | 259 | fields = {} |
paulb@439 | 260 | |
paulb@167 | 261 | for field_name, field_values in self.trans.request().fields().items(): |
paulb@439 | 262 | field_name = decode_value(field_name, encoding) |
paulb@439 | 263 | |
paulb@167 | 264 | if type(field_values) == type([]): |
paulb@167 | 265 | fields[field_name] = [] |
paulb@198 | 266 | for field_str in field_values: |
paulb@460 | 267 | fields[field_name].append(get_body_field_or_file(field_str, encoding)) |
paulb@73 | 268 | else: |
paulb@460 | 269 | fields[field_name] = [get_body_field_or_file(field_values, encoding)] |
paulb@439 | 270 | |
paulb@73 | 271 | return fields |
paulb@1 | 272 | |
paulb@249 | 273 | def get_fields(self, encoding=None): |
paulb@249 | 274 | |
paulb@249 | 275 | """ |
paulb@249 | 276 | Extracts fields (or request parameters) from both the path specified in |
paulb@249 | 277 | the transaction as well as the message body. The optional 'encoding' |
paulb@249 | 278 | parameter specifies the character encoding of the message body for cases |
paulb@249 | 279 | where no such information is available, but where the default encoding |
paulb@249 | 280 | is to be overridden. |
paulb@249 | 281 | |
paulb@249 | 282 | Returns a dictionary mapping field names to lists of values (even if a |
paulb@249 | 283 | single value is associated with any given field name). Each value is |
paulb@249 | 284 | either a Unicode object (representing a simple form field, for example) |
paulb@543 | 285 | or a WebStack.Helpers.Request.FileContent object (representing a file |
paulb@543 | 286 | upload form field). |
paulb@249 | 287 | |
paulb@249 | 288 | Where a given field name is used in both the path and message body to |
paulb@249 | 289 | specify values, the values from both sources will be combined into a |
paulb@249 | 290 | single list associated with that field name. |
paulb@249 | 291 | """ |
paulb@249 | 292 | |
paulb@249 | 293 | return self._get_fields(encoding) |
paulb@249 | 294 | |
paulb@45 | 295 | def get_user(self): |
paulb@1 | 296 | |
paulb@1 | 297 | """ |
paulb@186 | 298 | Extracts user information from the transaction. |
paulb@108 | 299 | |
paulb@108 | 300 | Returns a username as a string or None if no user is defined. |
paulb@1 | 301 | """ |
paulb@1 | 302 | |
paulb@49 | 303 | # NOTE: Webware relies entirely on a CGI-style environment where the |
paulb@49 | 304 | # NOTE: actual headers are not available. Therefore, the Web server must |
paulb@49 | 305 | # NOTE: itself be set up to provide user support. |
paulb@49 | 306 | |
paulb@128 | 307 | if self.user is not None: |
paulb@128 | 308 | return self.user |
paulb@128 | 309 | |
paulb@49 | 310 | try: |
paulb@49 | 311 | return self.trans.request().remoteUser() |
paulb@49 | 312 | except KeyError, exc: |
paulb@49 | 313 | return None |
paulb@1 | 314 | |
paulb@115 | 315 | def get_cookies(self): |
paulb@115 | 316 | |
paulb@115 | 317 | """ |
paulb@186 | 318 | Obtains cookie information from the request. |
paulb@115 | 319 | |
paulb@115 | 320 | Returns a dictionary mapping cookie names to cookie objects. |
paulb@115 | 321 | """ |
paulb@115 | 322 | |
paulb@258 | 323 | return self.process_cookies(self.trans.request().cookies(), using_strings=1) |
paulb@115 | 324 | |
paulb@115 | 325 | def get_cookie(self, cookie_name): |
paulb@115 | 326 | |
paulb@115 | 327 | """ |
paulb@186 | 328 | Obtains cookie information from the request. |
paulb@115 | 329 | |
paulb@115 | 330 | Returns a cookie object for the given 'cookie_name' or None if no such |
paulb@115 | 331 | cookie exists. |
paulb@115 | 332 | """ |
paulb@115 | 333 | |
paulb@115 | 334 | try: |
paulb@258 | 335 | value = self.trans.request().cookie(self.encode_cookie_value(cookie_name)) |
paulb@258 | 336 | return Cookie(cookie_name, self.decode_cookie_value(value)) |
paulb@115 | 337 | except KeyError: |
paulb@115 | 338 | return None |
paulb@115 | 339 | |
paulb@1 | 340 | # Response-related methods. |
paulb@1 | 341 | |
paulb@1 | 342 | def get_response_stream(self): |
paulb@1 | 343 | |
paulb@1 | 344 | """ |
paulb@186 | 345 | Returns the response stream for the transaction. |
paulb@1 | 346 | """ |
paulb@1 | 347 | |
paulb@224 | 348 | # Unicode can upset this operation. Using either the specified charset |
paulb@224 | 349 | # or a default encoding. |
paulb@167 | 350 | |
paulb@252 | 351 | encoding = self.get_response_stream_encoding() |
paulb@252 | 352 | return ConvertingStream(self.trans.response(), encoding) |
paulb@252 | 353 | |
paulb@252 | 354 | def get_response_stream_encoding(self): |
paulb@252 | 355 | |
paulb@252 | 356 | """ |
paulb@252 | 357 | Returns the response stream encoding. |
paulb@252 | 358 | """ |
paulb@252 | 359 | |
paulb@167 | 360 | if self.content_type: |
paulb@224 | 361 | encoding = self.content_type.charset |
paulb@252 | 362 | else: |
paulb@252 | 363 | encoding = None |
paulb@252 | 364 | return encoding or self.default_charset |
paulb@1 | 365 | |
paulb@42 | 366 | def get_response_code(self): |
paulb@42 | 367 | |
paulb@42 | 368 | """ |
paulb@42 | 369 | Get the response code associated with the transaction. If no response |
paulb@42 | 370 | code is defined, None is returned. |
paulb@42 | 371 | """ |
paulb@42 | 372 | |
paulb@42 | 373 | # NOTE: Webware treats the response code as just another header. |
paulb@42 | 374 | |
paulb@42 | 375 | status = self.trans.response().header("Status", None) |
paulb@42 | 376 | try: |
paulb@42 | 377 | if status is not None: |
paulb@42 | 378 | return int(status) |
paulb@42 | 379 | else: |
paulb@42 | 380 | return None |
paulb@42 | 381 | except ValueError: |
paulb@42 | 382 | return None |
paulb@42 | 383 | |
paulb@42 | 384 | def set_response_code(self, response_code): |
paulb@42 | 385 | |
paulb@42 | 386 | """ |
paulb@42 | 387 | Set the 'response_code' using a numeric constant defined in the HTTP |
paulb@42 | 388 | specification. |
paulb@42 | 389 | """ |
paulb@42 | 390 | |
paulb@42 | 391 | self.trans.response().setStatus(response_code) |
paulb@42 | 392 | |
paulb@67 | 393 | def set_header_value(self, header, value): |
paulb@49 | 394 | |
paulb@49 | 395 | """ |
paulb@49 | 396 | Set the HTTP 'header' with the given 'value'. |
paulb@49 | 397 | """ |
paulb@49 | 398 | |
paulb@49 | 399 | self.trans.response().setHeader(self.format_header_value(header), self.format_header_value(value)) |
paulb@49 | 400 | |
paulb@1 | 401 | def set_content_type(self, content_type): |
paulb@1 | 402 | |
paulb@1 | 403 | """ |
paulb@186 | 404 | Sets the 'content_type' for the response. |
paulb@1 | 405 | """ |
paulb@1 | 406 | |
paulb@167 | 407 | # Remember the content type for encoding purposes later. |
paulb@167 | 408 | |
paulb@167 | 409 | self.content_type = content_type |
paulb@224 | 410 | return self.trans.response().setHeader("Content-Type", str(content_type)) |
paulb@1 | 411 | |
paulb@115 | 412 | # Higher level response-related methods. |
paulb@115 | 413 | |
paulb@115 | 414 | def set_cookie(self, cookie): |
paulb@115 | 415 | |
paulb@115 | 416 | """ |
paulb@186 | 417 | Stores the given 'cookie' object in the response. |
paulb@115 | 418 | """ |
paulb@115 | 419 | |
paulb@258 | 420 | self.set_cookie_value(cookie.name, cookie.value) |
paulb@258 | 421 | #self.trans.response().addCookie(cookie) |
paulb@115 | 422 | |
paulb@115 | 423 | def set_cookie_value(self, name, value, path=None, expires=None): |
paulb@115 | 424 | |
paulb@115 | 425 | """ |
paulb@186 | 426 | Stores a cookie with the given 'name' and 'value' in the response. |
paulb@115 | 427 | |
paulb@115 | 428 | The optional 'path' is a string which specifies the scope of the cookie, |
paulb@115 | 429 | and the optional 'expires' parameter is a value compatible with the |
paulb@115 | 430 | time.time function, and indicates the expiry date/time of the cookie. |
paulb@115 | 431 | """ |
paulb@115 | 432 | |
paulb@258 | 433 | self.trans.response().setCookie(self.encode_cookie_value(name), |
paulb@258 | 434 | self.encode_cookie_value(value), path, expires) |
paulb@115 | 435 | |
paulb@115 | 436 | def delete_cookie(self, cookie_name): |
paulb@115 | 437 | |
paulb@115 | 438 | """ |
paulb@186 | 439 | Adds to the response a request that the cookie with the given |
paulb@186 | 440 | 'cookie_name' be deleted/discarded by the client. |
paulb@115 | 441 | """ |
paulb@115 | 442 | |
paulb@258 | 443 | self.trans.response().delCookie(self.encode_cookie_value(cookie_name)) |
paulb@115 | 444 | |
paulb@183 | 445 | # Session-related methods. |
paulb@183 | 446 | |
paulb@183 | 447 | def get_session(self, create=1): |
paulb@183 | 448 | |
paulb@183 | 449 | """ |
paulb@186 | 450 | Gets a session corresponding to an identifier supplied in the |
paulb@186 | 451 | transaction. |
paulb@183 | 452 | |
paulb@183 | 453 | If no session has yet been established according to information |
paulb@183 | 454 | provided in the transaction then the optional 'create' parameter |
paulb@183 | 455 | determines whether a new session will be established. |
paulb@183 | 456 | |
paulb@183 | 457 | Where no session has been established and where 'create' is set to 0 |
paulb@183 | 458 | then None is returned. In all other cases, a session object is created |
paulb@183 | 459 | (where appropriate) and returned. |
paulb@183 | 460 | """ |
paulb@183 | 461 | |
paulb@280 | 462 | # NOTE: create and hasSession() not used. |
paulb@183 | 463 | |
paulb@280 | 464 | return Session(self.trans.session()) |
paulb@183 | 465 | |
paulb@183 | 466 | def expire_session(self): |
paulb@183 | 467 | |
paulb@183 | 468 | """ |
paulb@186 | 469 | Expires any session established according to information provided in the |
paulb@186 | 470 | transaction. |
paulb@183 | 471 | """ |
paulb@183 | 472 | |
paulb@183 | 473 | self.trans.request().setSessionExpired(1) |
paulb@183 | 474 | |
paulb@183 | 475 | class Session: |
paulb@183 | 476 | |
paulb@183 | 477 | "A more dictionary-like session object than the one Webware provides." |
paulb@183 | 478 | |
paulb@183 | 479 | def __init__(self, session): |
paulb@183 | 480 | self.session = session |
paulb@183 | 481 | |
paulb@183 | 482 | def items(self): |
paulb@183 | 483 | return self.session.values().items() |
paulb@183 | 484 | |
paulb@183 | 485 | def __getattr__(self, name): |
paulb@183 | 486 | return getattr(self.__dict__["session"], name) |
paulb@183 | 487 | |
paulb@280 | 488 | def __delitem__(self, name): |
paulb@280 | 489 | del self.session[name] |
paulb@280 | 490 | |
paulb@280 | 491 | def __setitem__(self, name, value): |
paulb@280 | 492 | self.session[name] = value |
paulb@280 | 493 | |
paulb@280 | 494 | def __getitem__(self, name): |
paulb@280 | 495 | return self.session[name] |
paulb@280 | 496 | |
paulb@1 | 497 | # vim: tabstop=4 expandtab shiftwidth=4 |