[Zope-Checkins] SVN: Zope/trunk/lib/python/ZPublisher/ Add a 'method' key to the HTTPRequest.other, containing the uppercased REQUEST_METHOD. This makes HTTPRequest a little bit more compatible with Zope3 IHTTPRequest.

Martijn Pieters mj at zopatista.com
Fri Mar 16 11:01:03 EDT 2007


Log message for revision 73217:
  Add a 'method' key to the HTTPRequest.other, containing the uppercased REQUEST_METHOD. This makes HTTPRequest a little bit more compatible with Zope3 IHTTPRequest.

Changed:
  U   Zope/trunk/lib/python/ZPublisher/HTTPRequest.py
  U   Zope/trunk/lib/python/ZPublisher/tests/testHTTPRequest.py

-=-
Modified: Zope/trunk/lib/python/ZPublisher/HTTPRequest.py
===================================================================
--- Zope/trunk/lib/python/ZPublisher/HTTPRequest.py	2007-03-16 13:35:02 UTC (rev 73216)
+++ Zope/trunk/lib/python/ZPublisher/HTTPRequest.py	2007-03-16 15:01:01 UTC (rev 73217)
@@ -331,6 +331,7 @@
         if script: script="%s/%s" % (server_url,script)
         else:      script=server_url
         other['URL']=self.script=script
+        other['method'] = environ.get('REQUEST_METHOD', 'GET').upper()
 
         ################################################################
         # Cookie values should *not* be appended to existing form

Modified: Zope/trunk/lib/python/ZPublisher/tests/testHTTPRequest.py
===================================================================
--- Zope/trunk/lib/python/ZPublisher/tests/testHTTPRequest.py	2007-03-16 13:35:02 UTC (rev 73216)
+++ Zope/trunk/lib/python/ZPublisher/tests/testHTTPRequest.py	2007-03-16 15:01:01 UTC (rev 73217)
@@ -739,7 +739,26 @@
         from zope.publisher.base import DebugFlags
         self.assertEqual(getDebug(request), '1')
         self.assert_(isinstance(getDebugFromZope3(request), DebugFlags))
+        
+    def testMethod(self):
+        TEST_ENVIRON = {
+            'REQUEST_METHOD': 'GET',
+            'SERVER_NAME': 'localhost',
+            'SERVER_PORT': '80',
+            }
+        from StringIO import StringIO
+        from ZPublisher.HTTPRequest import HTTPRequest
+        s = StringIO('')
 
+        env = TEST_ENVIRON.copy()
+        request = HTTPRequest(s, env, None)
+        self.assertEqual(request.method, 'GET')
+        
+        env = TEST_ENVIRON.copy()
+        env['REQUEST_METHOD'] = 'post'
+        request = HTTPRequest(s, env, None)
+        self.assertEqual(request.method, 'POST')
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(AuthCredentialsTestsa, 'test'))



More information about the Zope-Checkins mailing list