]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Apply David-Sarah's recommended changes. Closes #974
authorBrian Warner <warner@lothar.com>
Tue, 4 Sep 2012 22:44:51 +0000 (15:44 -0700)
committerBrian Warner <warner@lothar.com>
Tue, 4 Sep 2012 22:45:38 +0000 (15:45 -0700)
src/allmydata/scripts/common_http.py
src/allmydata/test/test_cli.py

index 7ffa41bddba37eb307eb3cf43ae6cb060d197cfa..7b965525deced23e202d361180943818e6ea78a6 100644 (file)
@@ -27,6 +27,13 @@ def parse_url(url, defaultPort=None):
         path = "/"
     return scheme, host, port, path
 
+class BadResponse(object):
+    def __init__(self, url, err):
+        self.status = -1
+        self.reason = "Error trying to connect to %s: %s" % (url, err)
+    def read(self):
+        return ""
+
 
 def do_http(method, url, body=""):
     if isinstance(body, str):
@@ -62,12 +69,8 @@ def do_http(method, url, body=""):
     try:
         c.endheaders()
     except socket_error, err:
-        class BadResponse(object):
-            status=-1
-            reason="Error trying to connect to %s: %s" % (url, err)
-            read=lambda _: ""
-        return BadResponse()
-        
+        return BadResponse(url, err)
+
     while True:
         data = body.read(8192)
         if not data:
index e846a77ac8d46c2022bd56da6f96be5e8c232311..e3d0f4c6fd8384d8204dd9fbe63e5028eba82f79 100644 (file)
@@ -3288,19 +3288,16 @@ class Errors(GridTestMixin, CLITestMixin, unittest.TestCase):
         self.set_up_grid()
 
         # Simulate a connection error
-        endheaders = allmydata.scripts.common_http.httplib.HTTPConnection.endheaders
-        def _fix_endheaders(*args):
-            allmydata.scripts.common_http.httplib.HTTPConnection.endheaders = endheaders
         def _socket_error(*args, **kwargs):
             raise socket_error('test error')
-        allmydata.scripts.common_http.httplib.HTTPConnection.endheaders = _socket_error
+        self.patch(allmydata.scripts.common_http.httplib.HTTPConnection,
+                   "endheaders", _socket_error)
 
         d = self.do_cli("mkdir")
         def _check_invalid((rc,stdout,stderr)):
             self.failIfEqual(rc, 0)
             self.failUnlessIn("Error trying to connect to http://127.0.0.1", stderr)
         d.addCallback(_check_invalid)
-        d.addCallback(_fix_endheaders)
         return d