Skip to content

Commit 5a6587f

Browse files
feat: upgrade sample style (Self-Service) (GoogleCloudPlatform#9943)
* feat: upgrade sample style (Self-Service) * linting * linting * Update main.py * Update bq_copy_across_locations.py * backout failing samples * Update main.py * Update main.py * Update jobs.py * Update jobs.py --------- Co-authored-by: Maciej Strzelczyk <strzelczyk@google.com>
1 parent d6e9786 commit 5a6587f

137 files changed

Lines changed: 550 additions & 580 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

appengine/flexible/datastore/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def is_ipv6(addr):
2828
try:
2929
socket.inet_pton(socket.AF_INET6, addr)
3030
return True
31-
except socket.error:
31+
except OSError:
3232
return False
3333

3434

appengine/flexible/disk/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def is_ipv6(addr):
2727
try:
2828
socket.inet_pton(socket.AF_INET6, addr)
2929
return True
30-
except socket.error:
30+
except OSError:
3131
return False
3232

3333

@@ -45,9 +45,9 @@ def index():
4545
user_ip = '.'.join(user_ip.split('.')[:2])
4646

4747
with open('/tmp/seen.txt', 'a') as f:
48-
f.write('{}\n'.format(user_ip))
48+
f.write(f'{user_ip}\n')
4949

50-
with open('/tmp/seen.txt', 'r') as f:
50+
with open('/tmp/seen.txt') as f:
5151
seen = f.read()
5252

5353
output = """

appengine/flexible/metadata/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def index():
5050
# Websocket connections must be made directly to this instance, so the
5151
# external IP address of this instance is needed.
5252
external_ip = get_external_ip()
53-
return 'External IP: {}'.format(external_ip)
53+
return f'External IP: {external_ip}'
5454

5555

5656
@app.errorhandler(500)

appengine/flexible/multiple_services/gateway-service/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def say_hello(service):
4141
url = app.config['SERVICE_MAP'][service]
4242
res = requests.get(url + '/hello')
4343
responses.append(res.content)
44-
return '\n'.encode().join(responses)
44+
return b'\n'.join(responses)
4545

4646

4747
@app.route('/<path>')

appengine/flexible/multiple_services/gateway-service/services_config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ def map_services(environment):
4545
def production_url(service_name):
4646
"""Generates url for a service when deployed to App Engine."""
4747
project_id = os.getenv('GOOGLE_CLOUD_PROJECT')
48-
project_url = '{}.appspot.com'.format(project_id)
48+
project_url = f'{project_id}.appspot.com'
4949
if service_name == 'default':
50-
return 'https://{}'.format(project_url)
50+
return f'https://{project_url}'
5151
else:
52-
return 'https://{}-dot-{}'.format(service_name, project_url)
52+
return f'https://{service_name}-dot-{project_url}'
5353

5454

5555
def local_url(port):
5656
"""Generates url for a service when running locally"""
57-
return 'http://localhost:{}'.format(str(port))
57+
return f'http://localhost:{str(port)}'

appengine/flexible/numpy/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ def calculate():
2626
x = np.array([[1, 2], [3, 4]])
2727
y = np.array([[5, 6], [7, 8]])
2828

29-
return_str += 'x: {} , y: {}<br />'.format(str(x), str(y))
29+
return_str += f'x: {str(x)} , y: {str(y)}<br />'
3030

3131
# Multiply matrices
32-
return_str += 'x dot y : {}'.format(str(np.dot(x, y)))
32+
return_str += f'x dot y : {str(np.dot(x, y))}'
3333
return return_str
3434

3535

appengine/flexible/pubsub/main_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_push_endpoint(client):
4545
data=json.dumps({
4646
"message": {
4747
"data": base64.b64encode(
48-
u'Test message'.encode('utf-8')
48+
b'Test message'
4949
).decode('utf-8')
5050
}
5151
})

appengine/flexible/storage/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# [START gae_flex_storage_app]
1616
import logging
1717
import os
18-
from typing import Union
1918

2019
from flask import Flask, request
2120
from google.cloud import storage
@@ -67,7 +66,7 @@ def upload() -> str:
6766

6867

6968
@app.errorhandler(500)
70-
def server_error(e: Union[Exception, int]) -> str:
69+
def server_error(e: Exception | int) -> str:
7170
logging.exception("An error occurred during a request.")
7271
return (
7372
"""

appengine/flexible/tasks/create_app_engine_queue_task.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from __future__ import print_function
1615

1716
import argparse
1817

@@ -72,7 +71,7 @@ def create_task(project, queue, location, payload=None, in_seconds=None):
7271
# Use the client to build and send the task.
7372
response = client.create_task(parent=parent, task=task)
7473

75-
print('Created task {}'.format(response.name))
74+
print(f'Created task {response.name}')
7675
return response
7776
# [END cloud_tasks_appengine_create_task]
7877

appengine/flexible/tasks/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
def example_task_handler():
2525
"""Log the request payload."""
2626
payload = request.get_data(as_text=True) or '(empty payload)'
27-
print('Received task with payload: {}'.format(payload))
27+
print(f'Received task with payload: {payload}')
2828
return render_template("index.html", payload=payload)
2929
# [END cloud_tasks_appengine_quickstart]
3030

0 commit comments

Comments
 (0)