diff --git a/appengine/standard_python37/cloud_debugger/app.yaml b/appengine/standard_python37/cloud_debugger/app.yaml new file mode 100644 index 00000000000..a0b719d6dd4 --- /dev/null +++ b/appengine/standard_python37/cloud_debugger/app.yaml @@ -0,0 +1 @@ +runtime: python37 diff --git a/appengine/standard_python37/cloud_debugger/main.py b/appengine/standard_python37/cloud_debugger/main.py new file mode 100644 index 00000000000..0144f809fda --- /dev/null +++ b/appengine/standard_python37/cloud_debugger/main.py @@ -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 ''' +
Program Output: | {} |
---|---|
Correct Output: | {} |