# HG changeset patch # User paulb # Date 1077748223 0 # Node ID d697616382a8dd4281cad77c2bbbc1515da07aa2 # Parent 48c16f2d21a74d8bf1e6211ae1f0c2465fb3637a [project @ 2004-02-25 22:30:23 by paulb] Added query string and fields support, although the nature of such support needs to be resolved. diff -r 48c16f2d21a7 -r d697616382a8 WebStack/BaseHTTPRequestHandler.py --- a/WebStack/BaseHTTPRequestHandler.py Wed Feb 25 22:29:56 2004 +0000 +++ b/WebStack/BaseHTTPRequestHandler.py Wed Feb 25 22:30:23 2004 +0000 @@ -132,16 +132,66 @@ return self.trans.path + def get_query_string(self): + + """ + A framework-specific method which gets the query string from the path in + the request. + """ + + t = self.trans.path.split("?") + if len(t) == 1: + return "" + else: + + # NOTE: Overlook erroneous usage of "?" characters in the path. + + return "?".join(t[1:]) + # Higher level request-related methods. + def get_fields_from_path(self): + + """ + A framework-specific method which extracts the form fields from the + path specified in the transaction. The underlying framework may refuse + to supply fields from the path if handling a POST transaction. + + The returned object should employ the cgi.FieldStorage interface. + """ + + # NOTE: Since the cgi.FieldStorage class employed in this implementation + # NOTE: will only provide fields from the path for GET transactions, the + # NOTE: environment is adjusted to persuade it to give the desired + # NOTE: output. + + return FieldStorage(headers=self.get_headers(), environ={"REQUEST_METHOD" : "GET", + "QUERY_STRING" : self.get_query_string()}, keep_blank_values=1) + + def get_fields_from_body(self): + + """ + A framework-specific method which extracts the form fields from the + message body in the transaction. + + The returned object should employ the cgi.FieldStorage interface. + """ + + return FieldStorage(fp=self.get_request_stream(), headers=self.get_headers(), + environ={"REQUEST_METHOD" : "POST"}, keep_blank_values=1) + def get_fields(self): """ A framework-specific method which extracts the form fields from the - transaction. + transaction. Typically, the origin of the form fields will be affected + by the method specified in the transaction. + + The returned object should employ the cgi.FieldStorage interface. """ - return FieldStorage(self.get_request_stream(), keep_blank_values=1) + return FieldStorage(fp=self.get_request_stream(), headers=self.get_headers(), + environ={"REQUEST_METHOD" : self.get_request_method()}, keep_blank_values=1) def get_user(self): diff -r 48c16f2d21a7 -r d697616382a8 WebStack/Generic.py --- a/WebStack/Generic.py Wed Feb 25 22:29:56 2004 +0000 +++ b/WebStack/Generic.py Wed Feb 25 22:30:23 2004 +0000 @@ -201,11 +201,48 @@ raise NotImplementedError, "get_path_info" + def get_query_string(self): + + """ + A framework-specific method which gets the query string from the path in + the request. + """ + + raise NotImplementedError, "get_query_string" + + # Higher level request-related methods. + + def get_fields_from_path(self): + + """ + A framework-specific method which extracts the form fields from the + path specified in the transaction. The underlying framework may refuse + to supply fields from the path if handling a POST transaction. + + The returned object should employ the cgi.FieldStorage interface. + """ + + raise NotImplementedError, "get_fields_from_path" + + def get_fields_from_body(self): + + """ + A framework-specific method which extracts the form fields from the + message body in the transaction. + + The returned object should employ the cgi.FieldStorage interface. + """ + + raise NotImplementedError, "get_fields_from_body" + def get_fields(self): """ A framework-specific method which extracts the form fields from the - transaction. + transaction. Typically, the origin of the form fields will be affected + by the method specified in the transaction. + + The returned object should employ the cgi.FieldStorage interface. """ raise NotImplementedError, "get_fields" diff -r 48c16f2d21a7 -r d697616382a8 WebStack/ModPython.py --- a/WebStack/ModPython.py Wed Feb 25 22:29:56 2004 +0000 +++ b/WebStack/ModPython.py Wed Feb 25 22:30:23 2004 +0000 @@ -102,13 +102,56 @@ return self.trans.path_info + def get_query_string(self): + + """ + A framework-specific method which gets the query string from the path in + the request. + """ + + return self.trans.args + # Higher level request-related methods. + def get_fields_from_path(self): + + """ + A framework-specific method which extracts the form fields from the + path specified in the transaction. The underlying framework may refuse + to supply fields from the path if handling a POST transaction. + + The returned object should employ the cgi.FieldStorage interface. + + The mod_python.util.FieldStorage class should get fields from the path + in all situations, although it may then redefine such fields if + identically-named fields are then specified in the body of a POST + transaction. + """ + + return self.get_fields() + + def get_fields_from_body(self): + + """ + A framework-specific method which extracts the form fields from the + message body in the transaction. + + The returned object should employ the cgi.FieldStorage interface. + + The mod_python.util.FieldStorage class may augment the fields from the + body with fields found in the path. + """ + + return self.get_fields() + def get_fields(self): """ A framework-specific method which extracts the form fields from the - transaction. + transaction. Typically, the origin of the form fields will be affected + by the method specified in the transaction. + + The returned object should employ the cgi.FieldStorage interface. """ return FieldStorage(self.trans, keep_blank_values=1) diff -r 48c16f2d21a7 -r d697616382a8 WebStack/Twisted.py --- a/WebStack/Twisted.py Wed Feb 25 22:29:56 2004 +0000 +++ b/WebStack/Twisted.py Wed Feb 25 22:30:23 2004 +0000 @@ -91,9 +91,7 @@ A framework-specific method which gets the entire path from the request. """ - # NOTE: The path and "path info" are mostly equivalent for Twisted. - - return self.get_path_info() + return self.trans.uri def get_path_info(self): @@ -105,18 +103,64 @@ return "/%s" % "/".join(self.trans.postpath) + def get_query_string(self): + + """ + A framework-specific method which gets the query string from the path in + the request. + """ + + t = self.get_path().split("?") + if len(t) == 1: + return "" + else: + + # NOTE: Overlook erroneous usage of "?" characters in the path. + + return "?".join(t[1:]) + # Higher level request-related methods. + def get_fields_from_path(self): + + """ + A framework-specific method which extracts the form fields from the + path specified in the transaction. The underlying framework may refuse + to supply fields from the path if handling a POST transaction. + + The returned object should employ the cgi.FieldStorage interface. + """ + + # NOTE: May need a wrapper around this object. + + return self.trans.args + + def get_fields_from_body(self): + + """ + A framework-specific method which extracts the form fields from the + message body in the transaction. + + The returned object should employ the cgi.FieldStorage interface. + """ + + # NOTE: May need a wrapper around this object. + + return self.trans.args + def get_fields(self): """ A framework-specific method which extracts the form fields from the - transaction. + transaction. Typically, the origin of the form fields will be affected + by the method specified in the transaction. + + The returned object should employ the cgi.FieldStorage interface. """ - # NOTE: Discard multiple field values. + # NOTE: May need a wrapper around this object. - return dict([(key, value[0]) for (key, value) in self.trans.args.items()]) + return self.trans.args def get_user(self): diff -r 48c16f2d21a7 -r d697616382a8 WebStack/Webware.py --- a/WebStack/Webware.py Wed Feb 25 22:29:56 2004 +0000 +++ b/WebStack/Webware.py Wed Feb 25 22:30:23 2004 +0000 @@ -112,13 +112,54 @@ return "/" + self.trans.request().pathInfo() + def get_query_string(self): + + """ + A framework-specific method which gets the query string from the path in + the request. + """ + + return self.trans.request().queryString() + # Higher level request-related methods. + def get_fields_from_path(self): + + """ + A framework-specific method which extracts the form fields from the + path specified in the transaction. The underlying framework may refuse + to supply fields from the path if handling a POST transaction. + + The returned object should employ the cgi.FieldStorage interface. + + The result of this method is dependent on the WebUtils.FieldStorage + module's FieldStorage class. + """ + + return self.trans.request().fields() + + def get_fields_from_body(self): + + """ + A framework-specific method which extracts the form fields from the + message body in the transaction. + + The returned object should employ the cgi.FieldStorage interface. + + The result of this method is dependent on the WebUtils.FieldStorage + module's FieldStorage class. + """ + + return self.trans.request().fields() + def get_fields(self): """ A framework-specific method which extracts the form fields from the - transaction. + transaction. Typically, the origin of the form fields will be affected + by the method specified in the transaction. + + The returned object should employ the cgi.FieldStorage interface. """ return self.trans.request().fields()