Skip to content

Commit

Permalink
Don't rely on SERVER_SOFTWARE being set for AppEngine (#1704)
Browse files Browse the repository at this point in the history
  • Loading branch information
zevdg authored and sethmlarson committed Oct 18, 2019
1 parent cef15a1 commit 79e81f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
24 changes: 14 additions & 10 deletions src/urllib3/contrib/_appengine_environ.py
Expand Up @@ -6,27 +6,31 @@


def is_appengine():
return is_local_appengine() or is_prod_appengine() or is_prod_appengine_mvms()
return "APPENGINE_RUNTIME" in os.environ


def is_appengine_sandbox():
return is_appengine() and not is_prod_appengine_mvms()
"""Reports if the app is running in the first generation sandbox.
The second generation runtimes are technically still in a sandbox, but it
is much less restrictive, so generally you shouldn't need to check for it.
see https://cloud.google.com/appengine/docs/standard/runtimes
"""
return is_appengine() and os.environ["APPENGINE_RUNTIME"] == "python27"


def is_local_appengine():
return (
"APPENGINE_RUNTIME" in os.environ
and "Development/" in os.environ["SERVER_SOFTWARE"]
return is_appengine() and os.environ.get("SERVER_SOFTWARE", "").startswith(
"Development/"
)


def is_prod_appengine():
return (
"APPENGINE_RUNTIME" in os.environ
and "Google App Engine/" in os.environ["SERVER_SOFTWARE"]
and not is_prod_appengine_mvms()
return is_appengine() and os.environ.get("SERVER_SOFTWARE", "").startswith(
"Google App Engine/"
)


def is_prod_appengine_mvms():
return os.environ.get("GAE_VM", False) == "true"
"""Deprecated."""
return False
7 changes: 0 additions & 7 deletions src/urllib3/contrib/appengine.py
Expand Up @@ -108,13 +108,6 @@ def __init__(
"URLFetch is not available in this environment."
)

if is_prod_appengine_mvms():
raise AppEnginePlatformError(
"Use normal urllib3.PoolManager instead of AppEngineManager"
"on Managed VMs, as using URLFetch is not necessary in "
"this environment."
)

warnings.warn(
"urllib3 is using URLFetch on Google App Engine sandbox instead "
"of sockets. To use sockets directly instead of URLFetch see "
Expand Down

0 comments on commit 79e81f9

Please sign in to comment.