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