# HG changeset patch # User paulb # Date 1077985791 0 # Node ID 7fb29894dfa0369610ce086f54dcbb4fff9e2d3d # Parent 4253af446d74fbf9d10f00a74ec8c8d1bf4e8a72 [project @ 2004-02-28 16:29:51 by paulb] Fixed the fields from path retrieval, using cgi.parse_qs extensively for want of better framework support. diff -r 4253af446d74 -r 7fb29894dfa0 WebStack/BaseHTTPRequestHandler.py --- a/WebStack/BaseHTTPRequestHandler.py Wed Feb 25 22:30:35 2004 +0000 +++ b/WebStack/BaseHTTPRequestHandler.py Sat Feb 28 16:29:51 2004 +0000 @@ -7,7 +7,7 @@ import Generic from Helpers.Request import MessageBodyStream from Helpers.Auth import UserInfo -from cgi import FieldStorage +from cgi import parse_qs, FieldStorage from StringIO import StringIO class Transaction(Generic.Transaction): @@ -128,9 +128,9 @@ request. """ - # NOTE: No attempt is made to deduce the "path info". + # Remove the query string from the end of the path. - return self.trans.path + return self.trans.path.split("?")[0] def get_query_string(self): @@ -157,16 +157,11 @@ 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. + Returns a dictionary mapping field names to lists of values (even if a + single value is associated with any given field name). """ - # 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) + return parse_qs(self.get_query_string(), keep_blank_values=1) def get_fields_from_body(self): diff -r 4253af446d74 -r 7fb29894dfa0 WebStack/Generic.py --- a/WebStack/Generic.py Wed Feb 25 22:30:35 2004 +0000 +++ b/WebStack/Generic.py Sat Feb 28 16:29:51 2004 +0000 @@ -219,7 +219,8 @@ 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. + Returns a dictionary mapping field names to lists of values (even if a + single value is associated with any given field name). """ raise NotImplementedError, "get_fields_from_path" diff -r 4253af446d74 -r 7fb29894dfa0 WebStack/ModPython.py --- a/WebStack/ModPython.py Wed Feb 25 22:30:35 2004 +0000 +++ b/WebStack/ModPython.py Sat Feb 28 16:29:51 2004 +0000 @@ -5,7 +5,7 @@ """ import Generic -from mod_python.util import FieldStorage +from mod_python.util import parse_qs, FieldStorage from mod_python import apache class Transaction(Generic.Transaction): @@ -120,15 +120,11 @@ 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. + Returns a dictionary mapping field names to lists of values (even if a + single value is associated with any given field name). """ - return self.get_fields() + return parse_qs(self.get_query_string(), 1) # keep_blank_values=1 def get_fields_from_body(self): diff -r 4253af446d74 -r 7fb29894dfa0 WebStack/Twisted.py --- a/WebStack/Twisted.py Wed Feb 25 22:30:35 2004 +0000 +++ b/WebStack/Twisted.py Sat Feb 28 16:29:51 2004 +0000 @@ -6,6 +6,7 @@ import Generic from Helpers.Auth import UserInfo +from cgi import parse_qs class Transaction(Generic.Transaction): @@ -128,12 +129,11 @@ 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. + Returns a dictionary mapping field names to lists of values (even if a + single value is associated with any given field name). """ - # NOTE: May need a wrapper around this object. - - return self.trans.args + return parse_qs(self.get_query_string(), keep_blank_values=1) def get_fields_from_body(self): diff -r 4253af446d74 -r 7fb29894dfa0 WebStack/Webware.py --- a/WebStack/Webware.py Wed Feb 25 22:30:35 2004 +0000 +++ b/WebStack/Webware.py Sat Feb 28 16:29:51 2004 +0000 @@ -5,6 +5,7 @@ """ import Generic +from cgi import parse_qs class Transaction(Generic.Transaction): @@ -130,13 +131,11 @@ 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. + Returns a dictionary mapping field names to lists of values (even if a + single value is associated with any given field name). """ - return self.trans.request().fields() + return parse_qs(self.get_query_string(), keep_blank_values=1) def get_fields_from_body(self):