paulb@1 | 1 | #!/usr/bin/env python |
paulb@1 | 2 | |
paulb@1 | 3 | """ |
paulb@1 | 4 | mod_python classes. |
paulb@1 | 5 | """ |
paulb@1 | 6 | |
paulb@1 | 7 | import Generic |
paulb@1 | 8 | from mod_python.util import FieldStorage |
paulb@1 | 9 | |
paulb@1 | 10 | class Transaction(Generic.Transaction): |
paulb@1 | 11 | |
paulb@1 | 12 | """ |
paulb@1 | 13 | mod_python transaction interface. |
paulb@1 | 14 | """ |
paulb@1 | 15 | |
paulb@1 | 16 | def __init__(self, trans): |
paulb@1 | 17 | |
paulb@1 | 18 | "Initialise the transaction using the mod_python transaction 'trans'." |
paulb@1 | 19 | |
paulb@1 | 20 | self.trans = trans |
paulb@1 | 21 | |
paulb@1 | 22 | # Request-related methods. |
paulb@1 | 23 | |
paulb@1 | 24 | def get_request_stream(self): |
paulb@1 | 25 | |
paulb@1 | 26 | """ |
paulb@1 | 27 | A framework-specific method which returns the request stream for |
paulb@1 | 28 | the transaction. |
paulb@1 | 29 | """ |
paulb@1 | 30 | |
paulb@1 | 31 | return self.trans |
paulb@1 | 32 | |
paulb@1 | 33 | def get_request_method(self): |
paulb@1 | 34 | |
paulb@1 | 35 | """ |
paulb@1 | 36 | A framework-specific method which gets the request method. |
paulb@1 | 37 | """ |
paulb@1 | 38 | |
paulb@1 | 39 | return self.trans.method |
paulb@1 | 40 | |
paulb@1 | 41 | def get_headers(self): |
paulb@1 | 42 | |
paulb@1 | 43 | """ |
paulb@1 | 44 | A framework-specific method which returns the request headers. |
paulb@1 | 45 | NOTE: Experimental, since framework support varies somewhat. |
paulb@1 | 46 | """ |
paulb@1 | 47 | |
paulb@1 | 48 | return self.trans.headers_in |
paulb@1 | 49 | |
paulb@1 | 50 | def get_content_type(self): |
paulb@1 | 51 | |
paulb@1 | 52 | """ |
paulb@1 | 53 | A framework-specific method which gets the content type specified on the |
paulb@1 | 54 | request, along with the charset employed. |
paulb@1 | 55 | """ |
paulb@1 | 56 | |
paulb@1 | 57 | return self.parse_content_type(self.trans.content_type) |
paulb@1 | 58 | |
paulb@1 | 59 | def get_content_charsets(self): |
paulb@1 | 60 | |
paulb@1 | 61 | """ |
paulb@1 | 62 | Returns the character set preferences. |
paulb@1 | 63 | """ |
paulb@1 | 64 | |
paulb@1 | 65 | return self.parse_content_preferences(self.trans.headers_in["Accept-Charset"]) |
paulb@1 | 66 | |
paulb@1 | 67 | def get_content_languages(self): |
paulb@1 | 68 | |
paulb@1 | 69 | """ |
paulb@1 | 70 | A framework-specific method which extracts language information from |
paulb@1 | 71 | the transaction. |
paulb@1 | 72 | """ |
paulb@1 | 73 | |
paulb@1 | 74 | return self.parse_content_preferences(self.trans.headers_in["Accept-Language"]) |
paulb@1 | 75 | |
paulb@5 | 76 | def get_path(self): |
paulb@5 | 77 | |
paulb@5 | 78 | """ |
paulb@5 | 79 | A framework-specific method which gets the entire path from the request. |
paulb@5 | 80 | """ |
paulb@5 | 81 | |
paulb@5 | 82 | return self.trans.uri |
paulb@5 | 83 | |
paulb@1 | 84 | def get_path_info(self): |
paulb@1 | 85 | |
paulb@1 | 86 | """ |
paulb@1 | 87 | A framework-specific method which gets the "path info" (the part of the |
paulb@1 | 88 | URL after the resource name handling the current request) from the |
paulb@1 | 89 | request. |
paulb@1 | 90 | """ |
paulb@1 | 91 | |
paulb@5 | 92 | raise self.trans.path_info |
paulb@1 | 93 | |
paulb@1 | 94 | # Higher level request-related methods. |
paulb@1 | 95 | |
paulb@1 | 96 | def get_fields(self): |
paulb@1 | 97 | |
paulb@1 | 98 | """ |
paulb@1 | 99 | A framework-specific method which extracts the form fields from the |
paulb@1 | 100 | transaction. |
paulb@1 | 101 | """ |
paulb@1 | 102 | |
paulb@1 | 103 | return FieldStorage(self.trans, keep_blank_values=1) |
paulb@1 | 104 | |
paulb@1 | 105 | def get_agent_information(self): |
paulb@1 | 106 | |
paulb@1 | 107 | """ |
paulb@1 | 108 | A framework-specific method which extracts agent information from |
paulb@1 | 109 | the transaction. |
paulb@1 | 110 | """ |
paulb@1 | 111 | |
paulb@1 | 112 | return None |
paulb@1 | 113 | |
paulb@1 | 114 | # Response-related methods. |
paulb@1 | 115 | |
paulb@1 | 116 | def get_response_stream(self): |
paulb@1 | 117 | |
paulb@1 | 118 | """ |
paulb@1 | 119 | A framework-specific method which returns the response stream for |
paulb@1 | 120 | the transaction. |
paulb@1 | 121 | """ |
paulb@1 | 122 | |
paulb@1 | 123 | return self.trans |
paulb@1 | 124 | |
paulb@1 | 125 | def set_content_type(self, content_type): |
paulb@1 | 126 | |
paulb@1 | 127 | """ |
paulb@1 | 128 | A framework-specific method which sets the 'content_type' for the |
paulb@1 | 129 | response. |
paulb@1 | 130 | """ |
paulb@1 | 131 | |
paulb@5 | 132 | self.trans.content_type = self.format_content_type(content_type) |
paulb@1 | 133 | |
paulb@1 | 134 | # vim: tabstop=4 expandtab shiftwidth=4 |