aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Yu <stinky2nine@users.noreply.github.com>2018-09-28 11:18:37 -0400
committerGitHub <noreply@github.com>2018-09-28 11:18:37 -0400
commitfc738882a84efd3c88abe5c494805332b212840c (patch)
tree55bb5f96d6b78144741d28c25ce46f19cee0366e
parentf501e15c25eced7a7f0e2f305387357983def72a (diff)
downloadplatform_external_python_httplib2-fc738882a84efd3c88abe5c494805332b212840c.tar.gz
platform_external_python_httplib2-fc738882a84efd3c88abe5c494805332b212840c.tar.bz2
platform_external_python_httplib2-fc738882a84efd3c88abe5c494805332b212840c.zip
CLEANUP: Refactor Google App Engine runtime environment detection. (#120)
* CLEANUP: Refactor Google App Engine runtime environment detection. * Revert apiproxy_stub_map.apiproxy.GetStub. * Reorder imports.
-rw-r--r--python2/httplib2/__init__.py29
1 files changed, 15 insertions, 14 deletions
diff --git a/python2/httplib2/__init__.py b/python2/httplib2/__init__.py
index 019b864..f60ad6e 100644
--- a/python2/httplib2/__init__.py
+++ b/python2/httplib2/__init__.py
@@ -1453,6 +1453,7 @@ SCHEME_TO_CONNECTION = {
def _new_fixed_fetch(validate_certificate):
+
def fixed_fetch(
url,
payload=None,
@@ -1462,8 +1463,6 @@ def _new_fixed_fetch(validate_certificate):
follow_redirects=True,
deadline=None,
):
- if deadline is None:
- deadline = socket.getdefaulttimeout()
return fetch(
url,
payload=payload,
@@ -1536,30 +1535,32 @@ class AppEngineHttpsConnection(httplib.HTTPSConnection):
self._fetch = _new_fixed_fetch(not disable_ssl_certificate_validation)
-# Use a different connection object for Google App Engine
+# Use a different connection object for Google App Engine Standard Environment.
+def is_gae_instance():
+ server_software = os.environ.get('SERVER_SOFTWARE', '')
+ if (server_software.startswith('Google App Engine/') or
+ server_software.startswith('Development/') or
+ server_software.startswith('testutil/')):
+ return True
+ return False
+
+
try:
- server_software = os.environ.get("SERVER_SOFTWARE")
- if not server_software:
- raise NotRunningAppEngineEnvironment()
- elif not (
- server_software.startswith("Google App Engine/")
- or server_software.startswith("Development/")
- ):
+ if not is_gae_instance():
raise NotRunningAppEngineEnvironment()
from google.appengine.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.
+ raise ImportError
+
from google.appengine.api.urlfetch import fetch
- from google.appengine.api.urlfetch import InvalidURLError
# Update the connection classes to use the Googel App Engine specific ones.
SCHEME_TO_CONNECTION = {
"http": AppEngineHttpConnection,
"https": AppEngineHttpsConnection,
}
-except (ImportError, AttributeError, NotRunningAppEngineEnvironment):
+except (ImportError, NotRunningAppEngineEnvironment):
pass