import cgi import webapp2 form = """ <form method="post"> <textarea name="text" style="height: 100px; width: 400px;">%(userdata)s</textarea> <br> <input type="submit"> </form> """ def escape_html(s): return cgi.escape(s, quote = True) def rot13(userinput): output = '' for i in userinput: if i >= 'a' and i <= 'm' or (i >= 'A' and i <= 'M'): char_num = ord(i) + 13 output = output + chr(char_num) elif i >= 'N' and i <= 'z' or (i >= 'N' and i <= 'Z'): char_num = ord(i) - 13 output = output + chr(char_num) else: output = output + escape_html(i) return output class MainPage(webapp2.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('Hello, webapp World!') class ROT13Handler(webapp2.RequestHandler): def write_form(self, userdata=""): self.response.out.write(form % {'userdata': userdata}) def get(self): self.write_form() def post(self): user_input = self.request.get('text') form_output = rot13(user_input) self.write_form(form_output) app = webapp2.WSGIApplication([('/', MainPage), ('/unit2/rot13', ROT13Handler)], debug=True)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question