Skip to content

Commit

Permalink
chore(gae): delete region tags from standard/migration/urlfetch and r…
Browse files Browse the repository at this point in the history
…emove Python 2 refs (#13092)

* chore(gae): add support for Python 3 to requirements-test.txt

* docs(gae): delete region tags from standard/migration/urlfetch/async/main.py

* chore(gae): add support for Python 3 to requirements-test.txt

* docs(gae): delete region tags from standard/migration/urlfetch/requests/main.py

* docs(gae): update README.md files to a current Python 3 sample, and remove Python 2 references
  • Loading branch information
eapl-gemugami authored Jan 23, 2025
1 parent ea307c0 commit 4f6ffd1
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 33 deletions.
10 changes: 2 additions & 8 deletions appengine/standard/migration/urlfetch/async/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## App Engine async urlfetch Replacement

The runtime for App Engine standard for Python 2.7 includes the `urlfetch`
The runtime for App Engine standard for Python 3 includes the `urlfetch`
library, which is used to make HTTP(S) requests. There are several related
capabilities provided by that library:

Expand All @@ -10,13 +10,7 @@ capabilities provided by that library:

The sample in this directory provides a way to make asynchronous web requests
using only generally available Python libraries that work in either App Engine
standard for Python runtime, version 2.7 or 3.7. The sample code is the same
for each environment.

To deploy and run this sample in App Engine standard for Python 2.7:

pip install -t lib -r requirements.txt
gcloud app deploy
standard for Python runtime, version 3.7.

To deploy and run this sample in App Engine standard for Python 3.7:

Expand Down
9 changes: 0 additions & 9 deletions appengine/standard/migration/urlfetch/async/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# [START app]
import logging
from time import sleep

from flask import Flask
from flask import make_response
# [START imports]
from requests_futures.sessions import FuturesSession

# [END imports]


TIMEOUT = 10 # Wait this many seconds for background calls to finish
app = Flask(__name__)


@app.route("/") # Fetch and return remote page asynchronously
def get_async():
# [START requests_get]
session = FuturesSession()
url = "http://www.google.com/humans.txt"

Expand All @@ -41,7 +36,6 @@ def get_async():
resp = make_response(rpc.result().text)
resp.headers["Content-type"] = "text/plain"
return resp
# [END requests_get]


@app.route("/callback") # Fetch and return remote pages using callback
Expand Down Expand Up @@ -103,6 +97,3 @@ def server_error(e):
),
500,
)


# [END app]
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# pin pytest to 4.6.11 for Python2.
pytest==4.6.11; python_version < '3.0'

# pytest==8.3.4 and six==1.17.0 for Python3.
pytest==8.3.4; python_version >= '3.0'
six==1.17.0
10 changes: 2 additions & 8 deletions appengine/standard/migration/urlfetch/requests/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## App Engine simple urlfetch Replacement

The runtime for App Engine standard for Python 2.7 includes the `urlfetch`
The runtime for App Engine standard for Python 3 includes the `urlfetch`
library, which is used to make HTTP(S) requests. There are several related
capabilities provided by that library:

Expand All @@ -10,13 +10,7 @@ capabilities provided by that library:

The sample in this directory provides a way to make straightforward web requests
using only generally available Python libraries that work in either App Engine
standard for Python runtime, version 2.7 or 3.7. The sample code is the same
for each environment.

To deploy and run this sample in App Engine standard for Python 2.7:

pip install -t lib -r requirements.txt
gcloud app deploy
standard for Python runtime, version 3.7.

To deploy and run this sample in App Engine standard for Python 3.7:

Expand Down
8 changes: 0 additions & 8 deletions appengine/standard/migration/urlfetch/requests/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# [START app]
import logging

from flask import Flask

# [START imports]
import requests

# [END imports]

app = Flask(__name__)


@app.route("/")
def index():
# [START requests_get]
url = "http://www.google.com/humans.txt"
response = requests.get(url)
response.raise_for_status()
return response.text
# [END requests_get]


@app.errorhandler(500)
Expand All @@ -49,9 +44,6 @@ def server_error(e):
)


# [END app]


if __name__ == "__main__":
# This is used when running locally.
app.run(host="127.0.0.1", port=8080, debug=True)
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# pin pytest to 4.6.11 for Python2.
pytest==4.6.11; python_version < '3.0'

# pytest==8.3.4 and six==1.17.0 for Python3.
pytest==8.3.4; python_version >= '3.0'
six==1.17.0

0 comments on commit 4f6ffd1

Please sign in to comment.