From e9a78083c0c23fc00b9e20b68288522fe77a22a3 Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Wed, 24 Feb 2010 20:55:31 +0000 Subject: [PATCH] Fix for Issue7540 ; urllib2 will raise a TypeError when you try to add_data to a existing req object already having data. --- Lib/test/test_urllib2.py | 1 + Lib/urllib2.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index c0366dd18fc..ef59cfa798c 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -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/", diff --git a/Lib/urllib2.py b/Lib/urllib2.py index 122f777ce4a..8b26971757d 100644 --- a/Lib/urllib2.py +++ b/Lib/urllib2.py @@ -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):