From: Brian Warner Date: Tue, 4 Sep 2012 22:44:51 +0000 (-0700) Subject: Apply David-Sarah's recommended changes. Closes #974 X-Git-Tag: allmydata-tahoe-1.10a1~57 X-Git-Url: https://git.rkrishnan.org/simplejson/%22news.html/frontends/quickstart.html?a=commitdiff_plain;h=15c95c2e1201d3988769fe672c172309a203780e;p=tahoe-lafs%2Ftahoe-lafs.git Apply David-Sarah's recommended changes. Closes #974 --- diff --git a/src/allmydata/scripts/common_http.py b/src/allmydata/scripts/common_http.py index 7ffa41bd..7b965525 100644 --- a/src/allmydata/scripts/common_http.py +++ b/src/allmydata/scripts/common_http.py @@ -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: diff --git a/src/allmydata/test/test_cli.py b/src/allmydata/test/test_cli.py index e846a77a..e3d0f4c6 100644 --- a/src/allmydata/test/test_cli.py +++ b/src/allmydata/test/test_cli.py @@ -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