You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2012/11/13 03:58:59 UTC
svn commit: r1408567 - in /libcloud/trunk: CHANGES libcloud/common/base.py
libcloud/storage/drivers/s3.py
Author: tomaz
Date: Tue Nov 13 02:58:58 2012
New Revision: 1408567
URL: http://svn.apache.org/viewvc?rev=1408567&view=rev
Log:
Fix a bug which caused the connection to not be closed when using Python
2.6 and calling get_object on an object which doesn't exist in the S3
driver.
Contributed by John Carr, part of LIBCLOUD-257.
Modified:
libcloud/trunk/CHANGES
libcloud/trunk/libcloud/common/base.py
libcloud/trunk/libcloud/storage/drivers/s3.py
Modified: libcloud/trunk/CHANGES
URL: http://svn.apache.org/viewvc/libcloud/trunk/CHANGES?rev=1408567&r1=1408566&r2=1408567&view=diff
==============================================================================
--- libcloud/trunk/CHANGES (original)
+++ libcloud/trunk/CHANGES Tue Nov 13 02:58:58 2012
@@ -70,6 +70,11 @@ Changes with Apache Libcloud in developm
- Add a new local storage driver.
[Mahendra M]
+ - Fix a bug which caused the connection to not be closed when using Python
+ 2.6 and calling get_object on an object which doesn't exist in the S3
+ driver. ; LIBCLOUD-257
+ [John Carr]
+
*) DNS
- Update 'if type' checks in the update_record methods to behave correctly
Modified: libcloud/trunk/libcloud/common/base.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/common/base.py?rev=1408567&r1=1408566&r2=1408567&view=diff
==============================================================================
--- libcloud/trunk/libcloud/common/base.py (original)
+++ libcloud/trunk/libcloud/common/base.py Tue Nov 13 02:58:58 2012
@@ -44,6 +44,23 @@ from libcloud.httplib_ssl import Libclou
LibcloudHTTPConnection = httplib.HTTPConnection
+class HTTPResponse(httplib.HTTPResponse):
+ # On python 2.6 some calls can hang because HEAD isn't quite properly
+ # supported.
+ # In particular this happens on S3 when calls are made to get_object to
+ # objects that don't exist.
+ # This applies the behaviour from 2.7, fixing the hangs.
+ def read(self, amt=None):
+ if self.fp is None:
+ return ''
+
+ if self._method == 'HEAD':
+ self.close()
+ return ''
+
+ return httplib.HTTPResponse.read(self, amt)
+
+
class Response(object):
"""
A Base Response class to derive from.
@@ -267,9 +284,14 @@ class LoggingConnection():
ht += "\r\n0\r\n"
else:
ht += u(body)
- rr = httplib.HTTPResponse(sock=fakesock(ht),
- method=r._method,
- debuglevel=r.debuglevel)
+
+ if sys.version_info >= (2, 6) and sys.version_info < (2, 7):
+ cls = HTTPResponse
+ else:
+ cls = httplib.HTTPResponse
+
+ rr = cls(sock=fakesock(ht), method=r._method,
+ debuglevel=r.debuglevel)
rr.begin()
rv += ht
rv += ("\n# -------- end %d:%d response ----------\n"
Modified: libcloud/trunk/libcloud/storage/drivers/s3.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/storage/drivers/s3.py?rev=1408567&r1=1408566&r2=1408567&view=diff
==============================================================================
--- libcloud/trunk/libcloud/storage/drivers/s3.py (original)
+++ libcloud/trunk/libcloud/storage/drivers/s3.py Tue Nov 13 02:58:58 2012
@@ -221,9 +221,6 @@ class S3StorageDriver(StorageDriver):
return container
def get_object(self, container_name, object_name):
- # TODO: Figure out what is going on when the object or container
- # does not exist- it seems that Amazon just keeps the connection open
- # and doesn't return a response.
container = self.get_container(container_name=container_name)
response = self.connection.request('/%s/%s' % (container_name,
object_name),