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(self): 77 78 """ 79 A framework-specific method which gets the entire path from the request. 80 """ 81 82 return self.trans.uri 83 84 def get_path_info(self): 85 86 """ 87 A framework-specific method which gets the "path info" (the part of the 88 URL after the resource name handling the current request) from the 89 request. 90 """ 91 92 return self.trans.path_info 93 94 # Higher level request-related methods. 95 96 def get_fields(self): 97 98 """ 99 A framework-specific method which extracts the form fields from the 100 transaction. 101 """ 102 103 return FieldStorage(self.trans, keep_blank_values=1) 104 105 def get_agent_information(self): 106 107 """ 108 A framework-specific method which extracts agent information from 109 the transaction. 110 """ 111 112 return None 113 114 # Response-related methods. 115 116 def get_response_stream(self): 117 118 """ 119 A framework-specific method which returns the response stream for 120 the transaction. 121 """ 122 123 return self.trans 124 125 def set_content_type(self, content_type): 126 127 """ 128 A framework-specific method which sets the 'content_type' for the 129 response. 130 """ 131 132 self.trans.content_type = self.format_content_type(content_type) 133 134 # vim: tabstop=4 expandtab shiftwidth=4