Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions appengine/standard_python37/cloud_debugger/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
runtime: python37
94 changes: 94 additions & 0 deletions appengine/standard_python37/cloud_debugger/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Copyright 2019 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.

# [START gae_python37_app]
from flask import Flask, request


# Enable cloud debugger
# Adjust logging level to INFO
try:
import googleclouddebugger
googleclouddebugger.enable()
import logging
logging.basicConfig(level=logging.INFO)
except ImportError:
pass

# If `entrypoint` is not defined in app.yaml, App Engine will look for an app
# called `app` in `main.py`.
app = Flask(__name__)


# There is a bug in the code.
class StringProcessor():
def __init__(self, string):
self._string = string

def Reverse(self):
if self._string is '':
return ''

chars = [c for c in self._string]
left = 0
right = len(chars) - 1
while True:
tmp = chars[left]
chars[left] = chars[right]
chars[right] = tmp
if left >= right:
break
left += 1
right -= 1

return ''.join(chars)


@app.route('/reverse_string', methods=['GET'])
def ReverseString():
try:
s = str(request.args.get('string'))
except Exception as e:
print(e)
return 'Not a valid string!'

current = StringProcessor(s).Reverse()
expected = s[::-1]
return '''
<table>
<tr><th>Program Output:</th><th>{}</th></tr>
<tr><th>Correct Output:</th><th>{}</th><tr>
</table>
'''.format(current, expected)



@app.route('/')
def Hello():
"""Return a friendly HTTP greeting."""
return '''
Hello! Enter a string to reverse it.
<form method="get" action="reverse_string">
<p><input type=text name=string value="abcd">
<p><input type=submit>
</form>
'''


if __name__ == '__main__':
# This is used when running locally only. When deploying to Google App
# Engine, a webserver process such as Gunicorn will serve the app. This
# can be configured by adding an `entrypoint` to app.yaml.
app.run(host='127.0.0.1', port=8080, debug=True)
# [END gae_python37_app]
2 changes: 2 additions & 0 deletions appengine/standard_python37/cloud_debugger/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask==1.1.1
google-python-cloud-debugger