[patch] fix up error reporting from pycurl

Martin Pool mbp at sourcefrog.net
Thu Mar 16 20:07:22 GMT 2006


This is pretty small - it just makes sure that pycurl errors are
reported in the way the other transports expect.  This wasn't being
tested properly in pqm because the build environment doesn't have
python2.4-pycurl.

-- 
Martin
-------------- next part --------------
=== modified file 'a/bzrlib/tests/test_http.py'
--- a/bzrlib/tests/test_http.py	
+++ b/bzrlib/tests/test_http.py	
@@ -137,7 +137,7 @@
     def _get_pycurl_maybe(self):
         try:
             from bzrlib.transport.http._pycurl import PyCurlTransport
-            self._transport = PyCurlTransport
+            return PyCurlTransport
         except DependencyNotPresent:
             raise TestSkipped('pycurl not present')
 

=== modified file 'a/bzrlib/transport/http/_pycurl.py'
--- a/bzrlib/transport/http/_pycurl.py	
+++ b/bzrlib/transport/http/_pycurl.py	
@@ -18,6 +18,7 @@
 
 # TODO: test reporting of http errors
 
+import os
 from StringIO import StringIO
 
 import bzrlib
@@ -68,9 +69,10 @@
             return False
         elif code in (200, 302): # "ok", "found"
             return True
+        elif code == 0:
+            self._raise_curl_connection_error(curl)
         else:
-            raise TransportError('http error %d probing for %s' %
-                    (code, curl.getinfo(pycurl.EFFECTIVE_URL)))
+            self._raise_curl_http_error(curl)
         
     def _get(self, relpath, ranges):
         curl = pycurl.Curl()
@@ -95,9 +97,22 @@
         elif code == 206 and (ranges is not None):
             sio.seek(0)
             return code, sio
+        elif code == 0:
+            self._raise_curl_connection_error(curl)
         else:
-            raise TransportError('http error %d acccessing %s' % 
-                    (code, curl.getinfo(pycurl.EFFECTIVE_URL)))
+            self._raise_curl_http_error(curl)
+
+    def _raise_curl_connection_error(self, curl):
+        curl_errno = curl.getinfo(pycurl.OS_ERRNO)
+        url = curl.getinfo(pycurl.EFFECTIVE_URL)
+        raise ConnectionError('curl connection error (%s) on %s'
+                              % (os.strerror(curl_errno), url))
+
+    def _raise_curl_http_error(self, curl):
+        code = curl.getinfo(pycurl.HTTP_CODE)
+        url = curl.getinfo(pycurl.EFFECTIVE_URL)
+        raise TransportError('http error %d probing for %s' %
+                             (code, url))
 
     def _set_curl_options(self, curl):
         """Set options for all requests"""

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: Digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060316/81978859/attachment.pgp 


More information about the bazaar mailing list