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