Package: ndg-httpsclient Version: 0.3.2-1 Tags: patch User: [email protected] Usertags: origin-ubuntu ubuntu-patch vivid
Hello, I reviewed ndg-httpsclient for entering Ubuntu main. For that I enabled running the tests during package build. One of the tests fails with | ====================================================================== | ERROR: test03_open_fails_unknown_loc (__main__.Urllib2TestCase) | ---------------------------------------------------------------------- | Traceback (most recent call last): | File "ndg/httpsclient/test/test_urllib2.py", line 35, in test03_open_fails_unknown_loc | self.failUnlessRaises(URLError, opener.open, Constants.TEST_URI2) | File "/usr/lib/python2.7/unittest/case.py", line 612, in deprecated_func | return original_func(*args, **kwargs) | File "/usr/lib/python2.7/unittest/case.py", line 473, in assertRaises | callableObj(*args, **kwargs) | File "/usr/lib/python2.7/urllib2.py", line 431, in open | response = self._open(req, data) | File "/usr/lib/python2.7/urllib2.py", line 449, in _open | '_open', req) | File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain | result = func(*args) | File "/«PKGBUILDDIR»/ndg/httpsclient/https.py", line 121, in https_open | return self.do_open(customHTTPSContextConnection, req) | File "/usr/lib/python2.7/urllib2.py", line 1196, in do_open | h.close() | File "/«PKGBUILDDIR»/ndg/httpsclient/https.py", line 84, in close | self.sock.close() | AttributeError: 'NoneType' object has no attribute 'close' It looks like self.sock in HTTPSConnection is an internal variable which gets lazily initialized in connect(), so I think it's fair to check it for None in close(). It might be that I misunderstood the intent and the test case is wrong instead. The included patch checks for None in close() and fixes the AttributeError, now the tests all work. Thanks for considering, Martin -- Martin Pitt | http://www.piware.de Ubuntu Developer (www.ubuntu.com) | Debian Developer (www.debian.org)
diff -u ndg-httpsclient-0.3.2/debian/changelog ndg-httpsclient-0.3.2/debian/changelog --- ndg-httpsclient-0.3.2/debian/changelog +++ ndg-httpsclient-0.3.2/debian/changelog @@ -1,3 +1,13 @@ +ndg-httpsclient (0.3.2-1ubuntu2) vivid; urgency=medium + + * Run tests during package build: + - Add python-openssl and openssl build dependencies. + - debian/rules: Start test server and run test_urllib2.py. + * Add fix_socket_close.diff: Fix AttributeError when destructing an + un-opened Connection object. Exposed by test03_open_fails_unknown_loc. + + -- Martin Pitt <[email protected]> Tue, 21 Apr 2015 10:52:29 +0100 + ndg-httpsclient (0.3.2-1ubuntu1) vivid; urgency=medium * Build using pybuild. diff -u ndg-httpsclient-0.3.2/debian/control ndg-httpsclient-0.3.2/debian/control --- ndg-httpsclient-0.3.2/debian/control +++ ndg-httpsclient-0.3.2/debian/control @@ -5,7 +5,9 @@ Build-Depends: debhelper (>= 7), dh-python, + openssl, python-all, + python-openssl, python-setuptools, quilt, Standards-Version: 3.9.5 diff -u ndg-httpsclient-0.3.2/debian/patches/series ndg-httpsclient-0.3.2/debian/patches/series --- ndg-httpsclient-0.3.2/debian/patches/series +++ ndg-httpsclient-0.3.2/debian/patches/series @@ -1,0 +2 @@ +fix_socket_close.diff diff -u ndg-httpsclient-0.3.2/debian/rules ndg-httpsclient-0.3.2/debian/rules --- ndg-httpsclient-0.3.2/debian/rules +++ ndg-httpsclient-0.3.2/debian/rules @@ -4,0 +5,4 @@ + +override_dh_auto_test: + (cd ndg/httpsclient/test; scripts/openssl_https_server.sh) & + PYTHONPATH=. python ndg/httpsclient/test/test_urllib2.py only in patch2: unchanged: --- ndg-httpsclient-0.3.2.orig/debian/patches/fix_socket_close.diff +++ ndg-httpsclient-0.3.2/debian/patches/fix_socket_close.diff @@ -0,0 +1,45 @@ +Description: Fix AttributeError when destructing an un-opened Connection object + If we did not open the socket yet in connect(), and self.sock is still None, + don't try to close it in close(). + +Author: Martin Pitt <[email protected]> + +ERROR: test03_open_fails_unknown_loc (__main__.Urllib2TestCase) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "ndg/httpsclient/test/test_urllib2.py", line 35, in test03_open_fails_unknown_loc + self.failUnlessRaises(URLError, opener.open, Constants.TEST_URI2) + File "/usr/lib/python2.7/unittest/case.py", line 612, in deprecated_func + return original_func(*args, **kwargs) + File "/usr/lib/python2.7/unittest/case.py", line 473, in assertRaises + callableObj(*args, **kwargs) + File "/usr/lib/python2.7/urllib2.py", line 431, in open + response = self._open(req, data) + File "/usr/lib/python2.7/urllib2.py", line 449, in _open + '_open', req) + File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain + result = func(*args) + File "/«PKGBUILDDIR»/ndg/httpsclient/https.py", line 121, in https_open + return self.do_open(customHTTPSContextConnection, req) + File "/usr/lib/python2.7/urllib2.py", line 1196, in do_open + h.close() + File "/«PKGBUILDDIR»/ndg/httpsclient/https.py", line 84, in close + self.sock.close() +AttributeError: 'NoneType' object has no attribute 'close' + + +Index: ndg-httpsclient-0.3.2/ndg/httpsclient/https.py +=================================================================== +--- ndg-httpsclient-0.3.2.orig/ndg/httpsclient/https.py ++++ ndg-httpsclient-0.3.2/ndg/httpsclient/https.py +@@ -81,7 +81,9 @@ class HTTPSConnection(HTTPConnection): + + def close(self): + """Close socket and shut down SSL connection""" +- self.sock.close() ++ if self.sock is not None: ++ self.sock.close() ++ self.sock = None + + + class HTTPSContextHandler(AbstractHTTPHandler):
signature.asc
Description: Digital signature

