]> granicus.if.org Git - python/commitdiff
Fix for Issue7540 ; urllib2 will raise a TypeError when you try to add_data to
authorSenthil Kumaran <orsenthil@gmail.com>
Wed, 24 Feb 2010 20:55:31 +0000 (20:55 +0000)
committerSenthil Kumaran <orsenthil@gmail.com>
Wed, 24 Feb 2010 20:55:31 +0000 (20:55 +0000)
a existing req object already having data.

Lib/test/test_urllib2.py
Lib/urllib2.py

index c0366dd18fcc55c2ff4e8e3915e617a0e1fcff3d..ef59cfa798c2572c2aec113e13944b49831f0a5b 100644 (file)
@@ -1209,6 +1209,7 @@ class RequestTests(unittest.TestCase):
         self.get.add_data("spam")
         self.assertTrue(self.get.has_data())
         self.assertEqual("POST", self.get.get_method())
+        self.assertRaises(TypeError,self.get.add_data, "more spam")
 
     def test_get_full_url(self):
         self.assertEqual("http://www.python.org/~jeremy/",
index 122f777ce4a393e12d521ce7b846eb1c78229127..8b26971757d3733f10447f4642d13ec64e00b5f4 100644 (file)
@@ -226,6 +226,9 @@ class Request:
     # XXX these helper methods are lame
 
     def add_data(self, data):
+        if self.has_data():
+            raise TypeError("Request Obj already contains data: %s" %
+                            self.data)
         self.data = data
 
     def has_data(self):