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