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