1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/WebStack/ModPython.py Tue Jan 27 23:38:38 2004 +0000
1.3 @@ -0,0 +1,128 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +mod_python classes.
1.8 +"""
1.9 +
1.10 +import Generic
1.11 +from mod_python.util import FieldStorage
1.12 +
1.13 +class Transaction(Generic.Transaction):
1.14 +
1.15 + """
1.16 + mod_python transaction interface.
1.17 + """
1.18 +
1.19 + def __init__(self, trans):
1.20 +
1.21 + "Initialise the transaction using the mod_python transaction 'trans'."
1.22 +
1.23 + self.trans = trans
1.24 +
1.25 + # Request-related methods.
1.26 +
1.27 + def get_request_stream(self):
1.28 +
1.29 + """
1.30 + A framework-specific method which returns the request stream for
1.31 + the transaction.
1.32 + """
1.33 +
1.34 + return self.trans
1.35 +
1.36 + def get_request_method(self):
1.37 +
1.38 + """
1.39 + A framework-specific method which gets the request method.
1.40 + """
1.41 +
1.42 + return self.trans.method
1.43 +
1.44 + def get_headers(self):
1.45 +
1.46 + """
1.47 + A framework-specific method which returns the request headers.
1.48 + NOTE: Experimental, since framework support varies somewhat.
1.49 + """
1.50 +
1.51 + return self.trans.headers_in
1.52 +
1.53 + def get_content_type(self):
1.54 +
1.55 + """
1.56 + A framework-specific method which gets the content type specified on the
1.57 + request, along with the charset employed.
1.58 + """
1.59 +
1.60 + return self.parse_content_type(self.trans.content_type)
1.61 +
1.62 + def get_content_charsets(self):
1.63 +
1.64 + """
1.65 + Returns the character set preferences.
1.66 + """
1.67 +
1.68 + return self.parse_content_preferences(self.trans.headers_in["Accept-Charset"])
1.69 +
1.70 + def get_content_languages(self):
1.71 +
1.72 + """
1.73 + A framework-specific method which extracts language information from
1.74 + the transaction.
1.75 + """
1.76 +
1.77 + return self.parse_content_preferences(self.trans.headers_in["Accept-Language"])
1.78 +
1.79 + def get_path_info(self):
1.80 +
1.81 + """
1.82 + A framework-specific method which gets the "path info" (the part of the
1.83 + URL after the resource name handling the current request) from the
1.84 + request.
1.85 + """
1.86 +
1.87 + raise NotImplementedError, "get_path_info"
1.88 +
1.89 + # Higher level request-related methods.
1.90 +
1.91 + def get_fields(self):
1.92 +
1.93 + """
1.94 + A framework-specific method which extracts the form fields from the
1.95 + transaction.
1.96 + """
1.97 +
1.98 + return FieldStorage(self.trans, keep_blank_values=1)
1.99 +
1.100 + def get_agent_information(self):
1.101 +
1.102 + """
1.103 + A framework-specific method which extracts agent information from
1.104 + the transaction.
1.105 + """
1.106 +
1.107 + return None
1.108 +
1.109 + # Response-related methods.
1.110 +
1.111 + def get_response_stream(self):
1.112 +
1.113 + """
1.114 + A framework-specific method which returns the response stream for
1.115 + the transaction.
1.116 + """
1.117 +
1.118 + return self.trans
1.119 +
1.120 + def set_content_type(self, content_type):
1.121 +
1.122 + """
1.123 + A framework-specific method which sets the 'content_type' for the
1.124 + response.
1.125 + """
1.126 +
1.127 + # Make sure that only ASCII is used in the header.
1.128 +
1.129 + self.trans.content_type = content_type.encode("US-ASCII")
1.130 +
1.131 +# vim: tabstop=4 expandtab shiftwidth=4