Skip to content

Commit 5f8e4fc

Browse files
committed
Update the appengine sample to use the Python 2.7 runtime.
Reviewed in https://codereview.appspot.com/9394043.
1 parent b8b6fea commit 5f8e4fc

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
lines changed

samples/appengine/app.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
application: jcg-testing-01
1+
application: app-id-goes-here
22
version: 2
3-
runtime: python
3+
runtime: python27
4+
threadsafe: true
45
api_version: 1
56

67
handlers:
78
- url: .*
8-
script: main.py
9+
script: main.app
910

11+
libraries:
12+
- name: jinja2
13+
version: "latest"
14+
- name: webapp2
15+
version: "latest"

samples/appengine/main.py

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,19 @@
3030
import os
3131
import pickle
3232

33-
from apiclient.discovery import build
34-
from oauth2client.appengine import oauth2decorator_from_clientsecrets
35-
from oauth2client.client import AccessTokenRefreshError
33+
from apiclient import discovery
34+
from oauth2client import appengine
35+
from oauth2client import client
3636
from google.appengine.api import memcache
37-
from google.appengine.ext import webapp
38-
from google.appengine.ext.webapp import template
39-
from google.appengine.ext.webapp.util import run_wsgi_app
4037

38+
import webapp2
39+
import jinja2
40+
41+
42+
JINJA_ENVIRONMENT = jinja2.Environment(
43+
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
44+
autoescape=True,
45+
extensions=['jinja2.ext.autoescape'])
4146

4247
# CLIENT_SECRETS, name of a file containing the OAuth 2.0 information for this
4348
# application, including client_id and client_secret, which are found
@@ -63,25 +68,25 @@
6368

6469

6570
http = httplib2.Http(memcache)
66-
service = build("plus", "v1", http=http)
67-
decorator = oauth2decorator_from_clientsecrets(
71+
service = discovery.build("plus", "v1", http=http)
72+
decorator = appengine.oauth2decorator_from_clientsecrets(
6873
CLIENT_SECRETS,
6974
scope='https://www.googleapis.com/auth/plus.me',
7075
message=MISSING_CLIENT_SECRETS_MESSAGE)
7176

72-
class MainHandler(webapp.RequestHandler):
77+
class MainHandler(webapp2.RequestHandler):
7378

7479
@decorator.oauth_aware
7580
def get(self):
76-
path = os.path.join(os.path.dirname(__file__), 'grant.html')
7781
variables = {
7882
'url': decorator.authorize_url(),
7983
'has_credentials': decorator.has_credentials()
8084
}
81-
self.response.out.write(template.render(path, variables))
85+
template = JINJA_ENVIRONMENT.get_template('grant.html')
86+
self.response.write(template.render(variables))
8287

8388

84-
class AboutHandler(webapp.RequestHandler):
89+
class AboutHandler(webapp2.RequestHandler):
8590

8691
@decorator.oauth_required
8792
def get(self):
@@ -90,22 +95,16 @@ def get(self):
9095
user = service.people().get(userId='me').execute(http=http)
9196
text = 'Hello, %s!' % user['displayName']
9297

93-
path = os.path.join(os.path.dirname(__file__), 'welcome.html')
94-
self.response.out.write(template.render(path, {'text': text }))
95-
except AccessTokenRefreshError:
98+
template = JINJA_ENVIRONMENT.get_template('welcome.html')
99+
self.response.write(template.render({'text': text }))
100+
except client.AccessTokenRefreshError:
96101
self.redirect('/')
97102

98103

99-
def main():
100-
application = webapp.WSGIApplication(
101-
[
102-
('/', MainHandler),
103-
('/about', AboutHandler),
104-
(decorator.callback_path, decorator.callback_handler()),
105-
],
106-
debug=True)
107-
run_wsgi_app(application)
108-
109-
110-
if __name__ == '__main__':
111-
main()
104+
app = webapp2.WSGIApplication(
105+
[
106+
('/', MainHandler),
107+
('/about', AboutHandler),
108+
(decorator.callback_path, decorator.callback_handler()),
109+
],
110+
debug=True)

0 commit comments

Comments
 (0)