diff --git a/appengine/flexible_python37_and_earlier/datastore/README.md b/appengine/flexible_python37_and_earlier/datastore/README.md deleted file mode 100644 index 5676c53aab9..00000000000 --- a/appengine/flexible_python37_and_earlier/datastore/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# Python Google Cloud Datastore sample for Google App Engine Flexible Environment - -[![Open in Cloud Shell][shell_img]][shell_link] - -[shell_img]: http://gstatic.com/cloudssh/images/open-btn.png -[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=appengine/flexible_python37_and_earlier/datastore/README.md - -This sample demonstrates how to use [Google Cloud Datastore](https://cloud.google.com/datastore/) on [Google App Engine Flexible Environment](https://cloud.google.com/appengine). - -## Setup - -Before you can run or deploy the sample, you will need to enable the Cloud Datastore API in the [Google Developers Console](https://console.developers.google.com/project/_/apiui/apiview/datastore/overview). - -## Running locally - -Refer to the [top-level README](../README.md) for instructions on running and deploying. - -When running locally, you can use the [Google Cloud SDK](https://cloud.google.com/sdk) to provide authentication to use Google Cloud APIs: - - $ gcloud init - -Starting your application: - - $ python main.py diff --git a/appengine/flexible_python37_and_earlier/datastore/app.yaml b/appengine/flexible_python37_and_earlier/datastore/app.yaml deleted file mode 100644 index ca76f83fc3b..00000000000 --- a/appengine/flexible_python37_and_earlier/datastore/app.yaml +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2021 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -runtime: python -env: flex -entrypoint: gunicorn -b :$PORT main:app - -runtime_config: - python_version: 3 diff --git a/appengine/flexible_python37_and_earlier/datastore/main.py b/appengine/flexible_python37_and_earlier/datastore/main.py deleted file mode 100644 index ac1cec4ee5b..00000000000 --- a/appengine/flexible_python37_and_earlier/datastore/main.py +++ /dev/null @@ -1,91 +0,0 @@ -# Copyright 2015 Google LLC. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import datetime -import logging -import socket - -from flask import Flask, request -from google.cloud import datastore - - -app = Flask(__name__) - - -def is_ipv6(addr): - """Checks if a given address is an IPv6 address.""" - try: - socket.inet_pton(socket.AF_INET6, addr) - return True - except OSError: - return False - - -# [START gae_flex_datastore_app] -@app.route("/") -def index(): - ds = datastore.Client() - - user_ip = request.remote_addr - - # Keep only the first two octets of the IP address. - if is_ipv6(user_ip): - user_ip = ":".join(user_ip.split(":")[:2]) - else: - user_ip = ".".join(user_ip.split(".")[:2]) - - entity = datastore.Entity(key=ds.key("visit")) - entity.update( - { - "user_ip": user_ip, - "timestamp": datetime.datetime.now(tz=datetime.timezone.utc), - } - ) - - ds.put(entity) - query = ds.query(kind="visit", order=("-timestamp",)) - - results = [] - for x in query.fetch(limit=10): - try: - results.append("Time: {timestamp} Addr: {user_ip}".format(**x)) - except KeyError: - print("Error with result format, skipping entry.") - - output = "Last 10 visits:\n{}".format("\n".join(results)) - - return output, 200, {"Content-Type": "text/plain; charset=utf-8"} - - -# [END gae_flex_datastore_app] - - -@app.errorhandler(500) -def server_error(e): - logging.exception("An error occurred during a request.") - return ( - """ - An internal error occurred:
{}
- See logs for full stacktrace. - """.format( - e - ), - 500, - ) - - -if __name__ == "__main__": - # This is used when running locally. Gunicorn is used to run the - # application on Google App Engine. See entrypoint in app.yaml. - app.run(host="127.0.0.1", port=8080, debug=True) diff --git a/appengine/flexible_python37_and_earlier/datastore/main_test.py b/appengine/flexible_python37_and_earlier/datastore/main_test.py deleted file mode 100644 index 6b17c44ca79..00000000000 --- a/appengine/flexible_python37_and_earlier/datastore/main_test.py +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright 2015 Google LLC. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import main - - -def test_index(): - main.app.testing = True - client = main.app.test_client() - - r = client.get("/", environ_base={"REMOTE_ADDR": "127.0.0.1"}) - assert r.status_code == 200 - assert "Last 10 visits" in r.data.decode("utf-8") diff --git a/appengine/flexible_python37_and_earlier/datastore/noxfile_config.py b/appengine/flexible_python37_and_earlier/datastore/noxfile_config.py deleted file mode 100644 index 1665dd736f8..00000000000 --- a/appengine/flexible_python37_and_earlier/datastore/noxfile_config.py +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright 2023 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Default TEST_CONFIG_OVERRIDE for python repos. - -# You can copy this file into your directory, then it will be imported from -# the noxfile.py. - -# The source of truth: -# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py - -TEST_CONFIG_OVERRIDE = { - # You can opt out from the test for specific Python versions. - # Skipping for Python 3.9 due to pyarrow compilation failure. - "ignored_versions": ["2.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"], - # Old samples are opted out of enforcing Python type hints - # All new samples should feature them - "enforce_type_hints": False, - # An envvar key for determining the project id to use. Change it - # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a - # build specific Cloud project. You can also use your own string - # to use your own Cloud project. - "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", - # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', - # A dictionary you want to inject into your test. Don't put any - # secrets here. These values will override predefined values. - "envs": {}, -} diff --git a/appengine/flexible_python37_and_earlier/datastore/requirements-test.txt b/appengine/flexible_python37_and_earlier/datastore/requirements-test.txt deleted file mode 100644 index 15d066af319..00000000000 --- a/appengine/flexible_python37_and_earlier/datastore/requirements-test.txt +++ /dev/null @@ -1 +0,0 @@ -pytest==8.2.0 diff --git a/appengine/flexible_python37_and_earlier/datastore/requirements.txt b/appengine/flexible_python37_and_earlier/datastore/requirements.txt deleted file mode 100644 index ff3c9dcce0c..00000000000 --- a/appengine/flexible_python37_and_earlier/datastore/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -Flask==3.0.3; python_version > '3.6' -Flask==2.3.3; python_version < '3.7' -google-cloud-datastore==2.20.2 -gunicorn==23.0.0 -Werkzeug==3.0.3