Skip to content

Commit b14a1d5

Browse files
chore(gae): rename regions in standard/storage/appengine-client/main.py (#13055)
* chore(gae): add support for Python 3 to requirements-test.txt * chore(gae): rename regions in appengine-client/main.py * chore(gae): fix typo in region tag
1 parent 416f3c5 commit b14a1d5

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

appengine/standard/storage/appengine-client/main.py

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,29 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
# [START sample]
17+
# [START gae_storage_sample]
1818
"""A sample app that uses GCS client to operate on bucket and file."""
1919

20-
# [START imports]
20+
# [START gae_storage_imports]
2121
import os
2222

2323
import cloudstorage
2424
from google.appengine.api import app_identity
2525

2626
import webapp2
27+
# [END gae_storage_imports]
2728

28-
# [END imports]
29-
30-
# [START retries]
3129
cloudstorage.set_default_retry_params(
3230
cloudstorage.RetryParams(
3331
initial_delay=0.2, max_delay=5.0, backoff_factor=2, max_retry_period=15
3432
)
3533
)
36-
# [END retries]
3734

3835

3936
class MainPage(webapp2.RequestHandler):
4037
"""Main page for GCS demo application."""
4138

42-
# [START get_default_bucket]
39+
# [START gae_storage_get_default_bucket]
4340
def get(self):
4441
bucket_name = os.environ.get(
4542
"BUCKET_NAME", app_identity.get_default_gcs_bucket_name()
@@ -52,7 +49,7 @@ def get(self):
5249
)
5350
)
5451
self.response.write("Using bucket name: {}\n\n".format(bucket_name))
55-
# [END get_default_bucket]
52+
# [END gae_storage_get_default_bucket]
5653

5754
bucket = "/" + bucket_name
5855
filename = bucket + "/demo-testfile"
@@ -79,7 +76,7 @@ def get(self):
7976
self.delete_files()
8077
self.response.write("\n\nThe demo ran successfully!\n")
8178

82-
# [START write]
79+
# [START gae_storage_write]
8380
def create_file(self, filename):
8481
"""Create a file."""
8582

@@ -98,19 +95,17 @@ def create_file(self, filename):
9895
cloudstorage_file.write("abcde\n")
9996
cloudstorage_file.write("f" * 1024 * 4 + "\n")
10097
self.tmp_filenames_to_clean_up.append(filename)
98+
# [END gae_storage_write]
10199

102-
# [END write]
103-
104-
# [START read]
100+
# [START gae_storage_read]
105101
def read_file(self, filename):
106102
self.response.write("Abbreviated file content (first line and last 1K):\n")
107103

108104
with cloudstorage.open(filename) as cloudstorage_file:
109105
self.response.write(cloudstorage_file.readline())
110106
cloudstorage_file.seek(-1024, os.SEEK_END)
111107
self.response.write(cloudstorage_file.read())
112-
113-
# [END read]
108+
# [END gae_storage_read]
114109

115110
def stat_file(self, filename):
116111
self.response.write("File stat:\n")
@@ -126,7 +121,7 @@ def create_files_for_list_bucket(self, bucket):
126121
for f in filenames:
127122
self.create_file(f)
128123

129-
# [START list_bucket]
124+
# [START gae_storage_list_bucket]
130125
def list_bucket(self, bucket):
131126
"""Create several files and paginate through them."""
132127

@@ -147,8 +142,7 @@ def list_bucket(self, bucket):
147142
stats = cloudstorage.listbucket(
148143
bucket + "/foo", max_keys=page_size, marker=stat.filename
149144
)
150-
151-
# [END list_bucket]
145+
# [END gae_storage_list_bucket]
152146

153147
def list_bucket_directory_mode(self, bucket):
154148
self.response.write("Listbucket directory mode result:\n")
@@ -162,7 +156,6 @@ def list_bucket_directory_mode(self, bucket):
162156
self.response.write(" {}".format(subdir_file))
163157
self.response.write("\n")
164158

165-
# [START delete_files]
166159
def delete_files(self):
167160
self.response.write("Deleting files...\n")
168161
for filename in self.tmp_filenames_to_clean_up:
@@ -173,8 +166,5 @@ def delete_files(self):
173166
pass
174167

175168

176-
# [END delete_files]
177-
178-
179169
app = webapp2.WSGIApplication([("/", MainPage)], debug=True)
180-
# [END sample]
170+
# [END gae_storage_sample]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
# pin pytest to 4.6.11 for Python2.
22
pytest==4.6.11; python_version < '3.0'
33
WebTest==2.0.35; python_version < '3.0'
4+
# 2025-01-14 - Added support for Python 3
5+
pytest==8.3.2; python_version >= '3.0'
6+
WebTest==3.0.1; python_version >= '3.0'
7+
six==1.16.0
8+

0 commit comments

Comments
 (0)