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_info(self): 84 85 """ 86 A framework-specific method which gets the "path info" (the part of the 87 URL after the resource name handling the current request) from the 88 request. 89 """ 90 91 raise NotImplementedError, "get_path_info" 92 93 # Higher level request-related methods. 94 95 def get_fields(self): 96 97 """ 98 A framework-specific method which extracts the form fields from the 99 transaction. 100 """ 101 102 return self.trans.request().fields() 103 104 def get_agent_information(self): 105 106 """ 107 A framework-specific method which extracts agent information from 108 the transaction. 109 """ 110 111 return None 112 113 # Response-related methods. 114 115 def get_response_stream(self): 116 117 """ 118 A framework-specific method which returns the response stream for 119 the transaction. 120 """ 121 122 return self.trans.response() 123 124 def set_content_type(self, content_type): 125 126 """ 127 A framework-specific method which sets the 'content_type' for the 128 response. 129 """ 130 131 # Make sure that only ASCII is used in the header. 132 133 return self.trans.response().setHeader("Content-Type", content_type.encode("US-ASCII")) 134 135 # vim: tabstop=4 expandtab shiftwidth=4