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