Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update samples to support latest Google Cloud Python #656

Merged
merged 13 commits into from
Nov 15, 2016
2 changes: 1 addition & 1 deletion appengine/flexible/analytics/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Flask==0.11.1
gunicorn==19.6.0
requests[security]==2.11.1
requests[security]==2.12.0
1 change: 0 additions & 1 deletion appengine/flexible/datastore/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import datetime
import logging
import os
import socket

from flask import Flask, request
Expand Down
2 changes: 1 addition & 1 deletion appengine/flexible/datastore/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Flask==0.11.1
google-cloud-datastore==0.20.1
google-cloud-datastore==0.21.0
gunicorn==19.6.0
oauth2client==4.0.0
2 changes: 1 addition & 1 deletion appengine/flexible/endpoints/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ flask-cors==3.0.2
gunicorn==19.6.0
six==1.10.0
pyyaml==3.12
requests==2.11.1
requests==2.12.0
1 change: 1 addition & 0 deletions appengine/flexible/hello_world/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def server_error(e):
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.
Expand Down
2 changes: 1 addition & 1 deletion appengine/flexible/kinto/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
gunicorn==19.6.0
oauth2client==4.0.0
kinto==4.3.2
kinto==4.3.3
2 changes: 1 addition & 1 deletion appengine/flexible/mailgun/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Flask==0.11.1
gunicorn==19.6.0
requests[security]==2.11.1
requests[security]==2.12.0
2 changes: 1 addition & 1 deletion appengine/flexible/mailjet/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Flask==0.11.1
gunicorn==19.6.0
requests[security]==2.11.1
requests[security]==2.12.0
mailjet-rest==v1.2.2
2 changes: 1 addition & 1 deletion appengine/flexible/metadata/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Flask==0.11.1
gunicorn==19.6.0
requests[security]==2.11.1
requests[security]==2.12.0
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Flask==0.11.1
gunicorn==19.6.0
requests==2.11.1
requests==2.12.0
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Flask==0.11.1
gunicorn==19.6.0
requests==2.11.1
requests==2.12.0
1 change: 1 addition & 0 deletions appengine/flexible/numpy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def server_error(e):
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.
Expand Down
2 changes: 1 addition & 1 deletion appengine/flexible/pubsub/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Flask==0.11.1
google-cloud-pubsub==0.20.0
google-cloud-pubsub==0.21.0
gunicorn==19.6.0
oauth2client==4.0.0
2 changes: 1 addition & 1 deletion appengine/flexible/sendgrid/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Flask==0.11.1
sendgrid==3.6.2
sendgrid==3.6.3
gunicorn==19.6.0
2 changes: 1 addition & 1 deletion appengine/flexible/storage/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Flask==0.11.1
google-cloud-storage==0.20.0
google-cloud-storage==0.21.0
gunicorn==19.6.0
2 changes: 1 addition & 1 deletion appengine/standard/analytics/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Flask==0.11.1
requests==2.11.1
requests==2.12.0
requests-toolbelt==0.7.0
1 change: 1 addition & 0 deletions appengine/standard/app_identity/asserting/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def get(self):
self.response.headers['Content-Type'] = 'application/json'
self.response.write(json.dumps(result, indent=2))


app = webapp2.WSGIApplication([
('/', MainPage)
], debug=True)
Expand Down
1 change: 1 addition & 0 deletions appengine/standard/app_identity/incoming/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def get(self):

self.response.write('This is a protected page.')


app = webapp2.WSGIApplication([
('/', MainPage)
], debug=True)
Expand Down
1 change: 1 addition & 0 deletions appengine/standard/appstats/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def get(self):
value = memcache.get('example_key')
self.response.write('Value is: {}'.format(value))


app = webapp2.WSGIApplication([
('/', MainPage)
], debug=True)
Expand Down
1 change: 1 addition & 0 deletions appengine/standard/background/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def change_val(arg):
self.response.headers['Content-Type'] = 'text/plain'
self.response.write('Done')


app = webapp2.WSGIApplication([
('/', MainHandler),
('/dog', SetDogHandler),
Expand Down
1 change: 1 addition & 0 deletions appengine/standard/channel/chatactoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def get(self):
self.redirect(users.create_login_url(self.request.uri))
# [END create_channel_1]


jinja_environment = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))

Expand Down
1 change: 1 addition & 0 deletions appengine/standard/endpoints/multiapi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def bookmark(self, request):
# [END books]
# [END multiclass]


# [START api_server]
api = endpoints.api_server([api_collection])
# [END api_server]
2 changes: 1 addition & 1 deletion appengine/standard/firebase/firetactoe/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
flask==0.11.1
requests==2.11.1
requests==2.12.0
requests_toolbelt==0.7.0
oauth2client==4.0.0
functools32==3.2.3-2; python_version < "3"
1 change: 1 addition & 0 deletions appengine/standard/hello_world/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.write('Hello, World!')


app = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
1 change: 1 addition & 0 deletions appengine/standard/localtesting/env_vars_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ def testEnvVars(self):
self.assertEqual(os.environ['MY_CONFIG_SETTING'], 'example')
# [END env_example]


if __name__ == '__main__':
unittest.main()
1 change: 1 addition & 0 deletions appengine/standard/localtesting/login_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ def testLogin(self):
# [END test]
# [END login_example]


if __name__ == '__main__':
unittest.main()
1 change: 1 addition & 0 deletions appengine/standard/localtesting/mail_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ def testMailSent(self):
self.assertEqual('alice@example.com', messages[0].to)
# [END mail_example]


if __name__ == '__main__':
unittest.main()
1 change: 1 addition & 0 deletions appengine/standard/localtesting/task_queue_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@ def testTaskAddedByDeferred(self):
self.assertEqual(result, 3)
# [END deferred]


if __name__ == '__main__':
unittest.main()
1 change: 1 addition & 0 deletions appengine/standard/mail/handle_bounced_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ def receive(self, bounce_message):
logging.info('Bounce notification: %s', bounce_message.notification)
# [END bounce_handler]


app = webapp2.WSGIApplication([LogBounceHandler.mapping()], debug=True)
1 change: 1 addition & 0 deletions appengine/standard/mail/handle_incoming_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def receive(self, mail_message):
plaintext = body.decode()
logging.info("Plain text body of length %d.", len(plaintext))


# [START app]
app = webapp2.WSGIApplication([LogSenderHandler.mapping()], debug=True)
# [END app]
2 changes: 1 addition & 1 deletion appengine/standard/mailjet/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Flask==0.11.1
requests==2.11.1
requests==2.12.0
requests-toolbelt==0.7.0
mailjet-rest==v1.2.2
1 change: 1 addition & 0 deletions appengine/standard/memcache/best_practices/batch/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def get(self):
self.response.write(tvalues)
# [END batch]


app = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
1 change: 1 addition & 0 deletions appengine/standard/modules/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def get(self):
pass
# [END access_another_module]


app = webapp2.WSGIApplication([
('/', GetModuleInfoHandler),
('/access_backend', GetBackendHandler),
Expand Down
1 change: 1 addition & 0 deletions appengine/standard/ndb/async/app_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ def get(self):
self.response.out.write('Content of the page')
future.get_result()


app = webapp2.WSGIApplication([('/', MyRequestHandler)])
1 change: 1 addition & 0 deletions appengine/standard/ndb/async/app_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ def get(self):

self.response.out.write('Content of the page')


app = webapp2.WSGIApplication([('/', MyRequestHandler)])
2 changes: 1 addition & 1 deletion appengine/standard/sendgrid/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sendgrid==3.6.2
sendgrid==3.6.3
2 changes: 1 addition & 1 deletion appengine/standard/urlfetch/requests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Flask==0.11.1
requests==2.11.1
requests==2.12.0
requests-toolbelt==0.7.0
1 change: 1 addition & 0 deletions appengine/standard/xmpp/xmpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def post(self):
message.reply("Greetings!")
# [END chat]


app = webapp2.WSGIApplication([
('/_ah/xmpp/message/chat/', XMPPHandler),
('/_ah/xmpp/subscribe', SubscribeHandler),
Expand Down
1 change: 1 addition & 0 deletions bigquery/api/list_datasets_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def main(project_id):
list_datasets(bigquery, project_id)
list_projects(bigquery)


if __name__ == '__main__':
parser = argparse.ArgumentParser(
description=__doc__,
Expand Down
1 change: 1 addition & 0 deletions bigquery/api/load_data_by_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def main(project_id, dataset_id, table_name, schema_path, data_path):
table_name)
# [END main]


if __name__ == '__main__':
parser = argparse.ArgumentParser(
description=__doc__,
Expand Down
2 changes: 1 addition & 1 deletion bigquery/cloud-client/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
google-cloud-bigquery==0.20.0
google-cloud-bigquery==0.21.0
55 changes: 7 additions & 48 deletions bigquery/cloud-client/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,7 @@
def list_projects():
bigquery_client = bigquery.Client()

projects = []
page_token = None

while True:
results, page_token = bigquery_client.list_projects(
page_token=page_token)
projects.extend(results)

if not page_token:
break

for project in projects:
for project in bigquery_client.list_projects():
print(project.project_id)


Expand All @@ -57,18 +46,7 @@ def list_datasets(project=None):
"""
bigquery_client = bigquery.Client(project=project)

datasets = []
page_token = None

while True:
results, page_token = bigquery_client.list_datasets(
page_token=page_token)
datasets.extend(results)

if not page_token:
break

for dataset in datasets:
for dataset in bigquery_client.list_datasets():
print(dataset.name)


Expand Down Expand Up @@ -98,17 +76,7 @@ def list_tables(dataset_name, project=None):
print('Dataset {} does not exist.'.format(dataset_name))
return

tables = []
page_token = None

while True:
results, page_token = dataset.list_tables(page_token=page_token)
tables.extend(results)

if not page_token:
break

for table in tables:
for table in dataset.list_tables():
print(table.name)


Expand Down Expand Up @@ -157,19 +125,10 @@ def list_rows(dataset_name, table_name, project=None):
# Reload the table so that the schema is available.
table.reload()

rows = []
page_token = None

# Load at most 25 results. You can change this to `while True` and change
# the max_results argument to load more rows from BigQuery, but note
# that this can take some time. It's preferred to use a query.
while len(rows) < 25:
results, total_rows, page_token = table.fetch_data(
max_results=25, page_token=page_token)
rows.extend(results)

if not page_token:
break
# Load at most 25 results. You can change the max_results argument to load
# more rows from BigQuery, but note that this can take some time. It's
# preferred to use a query.
rows = list(table.fetch_data(max_results=25))

# Use format to create a simple table.
format_string = '{!s:<16} ' * len(table.schema)
Expand Down
4 changes: 2 additions & 2 deletions bigquery/dml/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
flake8==3.0.4
google-cloud-bigquery==0.20.0
flake8==3.2.0
google-cloud-bigquery==0.21.0
PyMySQL==0.7.9
six==1.10.0
SQLAlchemy==1.1.3
2 changes: 1 addition & 1 deletion bigtable/hello/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
google-cloud-bigtable==0.20.0
google-cloud-bigtable==0.21.0
Original file line number Diff line number Diff line change
@@ -1 +1 @@
google-cloud-datastore==0.20.1
google-cloud-datastore==0.21.0
2 changes: 1 addition & 1 deletion compute/auth/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
requests==2.11.1
requests==2.12.0
google-api-python-client==1.5.5
2 changes: 1 addition & 1 deletion compute/encryption/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cryptography==1.5.3
requests==2.11.1
requests==2.12.0
2 changes: 1 addition & 1 deletion compute/metadata/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
requests==2.11.1
requests==2.12.0
2 changes: 1 addition & 1 deletion compute/xmpp_wikibot/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Flask==0.11.1
requests==2.11.1
requests==2.12.0
sleekxmpp==1.3.1
six==1.10.0
1 change: 1 addition & 0 deletions dataproc/list_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def main(project_id, zone):
result = list_clusters(dataproc, project_id)
print(result)


if __name__ == '__main__':
parser = argparse.ArgumentParser(
description=__doc__,
Expand Down
2 changes: 1 addition & 1 deletion dataproc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
google-api-python-client==1.5.5
google-cloud==0.20.0
google-cloud==0.21.0
2 changes: 1 addition & 1 deletion datastore/cloud-client/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
google-cloud-datastore==0.20.1
google-cloud-datastore==0.21.0
Loading