summaryrefslogtreecommitdiff
path: root/python2
diff options
context:
space:
mode:
authorJoe Gregorio <jcgregorio@google.com>2011-02-11 01:03:22 -0500
committerJoe Gregorio <jcgregorio@google.com>2011-02-11 01:03:22 -0500
commitb6c90c4cd431e213b7425f41b7c51f7dead51294 (patch)
treed3a536b58ce2c30d6957d6dc095976fdcc2ed29f /python2
parent585ccbe1fe8d4f9b749f387d1791d8da3e44d0e6 (diff)
downloadhttplib2-b6c90c4cd431e213b7425f41b7c51f7dead51294.tar.gz
Further fixes for issue 96. Adds tests and also fixes it for Python 3
Diffstat (limited to 'python2')
-rw-r--r--python2/httplib2/__init__.py7
-rwxr-xr-xpython2/httplib2test.py27
2 files changed, 28 insertions, 6 deletions
diff --git a/python2/httplib2/__init__.py b/python2/httplib2/__init__.py
index f01e931..2b4848f 100644
--- a/python2/httplib2/__init__.py
+++ b/python2/httplib2/__init__.py
@@ -871,7 +871,12 @@ the same interface as FileCache."""
conn.close()
raise ServerNotFoundError("Unable to find the server at %s" % conn.host)
except socket.error, e:
- if e.errno == errno.ECONNREFUSED: # Connection refused
+ err = 0
+ if hasattr(e, 'args'):
+ err = getattr(e, 'args')[0]
+ else:
+ err = e.errno
+ if err == errno.ECONNREFUSED: # Connection refused
raise
except httplib.HTTPException:
# Just because the server closed the connection doesn't apparently mean
diff --git a/python2/httplib2test.py b/python2/httplib2test.py
index 5a81a70..50222f2 100755
--- a/python2/httplib2test.py
+++ b/python2/httplib2test.py
@@ -15,15 +15,16 @@ __history__ = """ """
__version__ = "0.1 ($Rev: 118 $)"
-import sys
-import unittest
+import StringIO
+import base64
import httplib
import httplib2
import os
-import urlparse
+import socket
+import sys
import time
-import base64
-import StringIO
+import unittest
+import urlparse
# Python 2.3 support
if not hasattr(unittest.TestCase, 'assertTrue'):
@@ -166,6 +167,22 @@ class HttpTest(unittest.TestCase):
self.assertTrue(content.startswith("Unable to find"))
self.assertEqual(response.status, 400)
+ def testGetConnectionRefused(self):
+ self.http.force_exception_to_status_code = False
+ try:
+ self.http.request("http://localhost:7777/")
+ self.fail("An socket.error exception must be thrown on Connection Refused.")
+ except socket.error:
+ pass
+
+ # Now test with exceptions turned off
+ self.http.force_exception_to_status_code = True
+
+ (response, content) = self.http.request("http://localhost:7777/")
+ self.assertEqual(response['content-type'], 'text/plain')
+ self.assertTrue("Connection refused" in content)
+ self.assertEqual(response.status, 400)
+
def testGetIRI(self):
if sys.version_info >= (2,3):
uri = urlparse.urljoin(base, u"reflector/reflector.cgi?d=\N{CYRILLIC CAPITAL LETTER DJE}")