From 4eed8a16d8fb223e355f209b70e741c40e94868a Mon Sep 17 00:00:00 2001 From: Joe Gregorio Date: Sun, 3 Mar 2013 20:29:45 -0500 Subject: Catch an edge case in imports. Reviewed in https://codereview.appspot.com/7454047/. --- python2/httplib2/__init__.py | 4 ++-- python2/httplib2test_appengine.py | 29 +++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/python2/httplib2/__init__.py b/python2/httplib2/__init__.py index 1643cf3..c62afad 100644 --- a/python2/httplib2/__init__.py +++ b/python2/httplib2/__init__.py @@ -1072,7 +1072,7 @@ try: raise ImportError # Bail out; we're not actually running on App Engine. from google.appengine.api.urlfetch import fetch from google.appengine.api.urlfetch import InvalidURLError - except ImportError: + except (ImportError, AttributeError): from google3.apphosting.api import apiproxy_stub_map if apiproxy_stub_map.apiproxy.GetStub('urlfetch') is None: raise ImportError # Bail out; we're not actually running on App Engine. @@ -1118,7 +1118,7 @@ try: 'http': AppEngineHttpConnection, 'https': AppEngineHttpsConnection } -except ImportError: +except (ImportError, AttributeError): pass diff --git a/python2/httplib2test_appengine.py b/python2/httplib2test_appengine.py index ea36f39..0c0bdc2 100644 --- a/python2/httplib2test_appengine.py +++ b/python2/httplib2test_appengine.py @@ -28,7 +28,7 @@ testbed = testbed.Testbed() testbed.activate() testbed.init_urlfetch_stub() -from google.appengine.runtime import DeadlineExceededError +import google.appengine.api import httplib2 @@ -37,11 +37,6 @@ class AppEngineHttpTest(unittest.TestCase): if os.path.exists(cacheDirName): [os.remove(os.path.join(cacheDirName, file)) for file in os.listdir(cacheDirName)] - if sys.version_info < (2, 6): - disable_cert_validation = True - else: - disable_cert_validation = False - def test(self): h = httplib2.Http() response, content = h.request("http://bitworking.org") @@ -71,12 +66,30 @@ class AppEngineHttpTest(unittest.TestCase): # except DeadlineExceededError: # pass - - def test_proxy_info_ignored(self): h = httplib2.Http(proxy_info='foo.txt') response, content = h.request("http://bitworking.org") self.assertEquals(response.status, 200) + +class AberrationsTest(unittest.TestCase): + def setUp(self): + self.orig_apiproxy_stub_map = google.appengine.api.apiproxy_stub_map + + # Force apiproxy_stub_map to None to trigger the test condition. + google.appengine.api.apiproxy_stub_map = None + reload(httplib2) + + def tearDown(self): + google.appengine.api.apiproxy_stub_map = self.orig_apiproxy_stub_map + reload(httplib2) + + def test(self): + self.assertNotEqual(httplib2.SCHEME_TO_CONNECTION['https'], + httplib2.AppEngineHttpsConnection) + self.assertNotEqual(httplib2.SCHEME_TO_CONNECTION['http'], + httplib2.AppEngineHttpConnection) + + if __name__ == '__main__': unittest.main() -- cgit v1.2.1