HTMLをエンコード/デコードサービスを公開しました。
非常にシンプルなサービスですが、pythonで作成した初の実用アプリです。アプリIDの取得から、コーディング、公開まで1時間ほどで出来てしまいました。慣れてしまえば、Pythonの開発効率は相当高そうです。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | #!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright 2007 Google Inc. # # 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. # from google.appengine.ext import webapp from google.appengine.ext.webapp import util class MainHandler(webapp.RequestHandler): def post(self): self.get() def get(self): raw = encoded = "" if self.request.get("encode"): encoded = self.encode(self.encode(self.request.get("raw"))) raw = self.encode(self.request.get("raw")) if self.request.get("decode"): encoded = self.encode(self.request.get("encoded")) raw = self.encode(self.decode(self.request.get("encoded"))) self.response.out.write(u""" <html> <head> <title>HTML Encoder/Decoder</title> </head> <body> <h1>HTML Encoder/Decoder</h1> 左側のテキストフィールドにHTMLを入力しencodeボタンをクリックしてください。<br> エンコード済みのHTMLが右側のテキストフィールドに表示されます。<br> エンコード対象は、&,<,>,"の4文字です。 <form action="/" method="post"><input type="hidden" name="phpMyAdmin" value="cfc2644bd9c947213a0141747c2608b0" /> <textarea name="raw" style="float:left;width:350px;height:200px">%s</textarea> <div style="float:left;margin-top:70px"> <input name="encode" type="submit" value=" >>> encode >>> "><br> <input name="decode" type="submit" value=" <<< decode <<< "> </div> <textarea name="encoded" style="float:left;width:350px;height:200px">%s</textarea> </form><br clear="all"> Developed by <a href="http://php6.jp/python">python練習帳</a> </body> </html> """ % (raw, encoded)) def encode(self, html): html = html.replace('&','&') html = html.replace('<','<') html = html.replace('>','>') html = html.replace('"','"') return html def decode(self, html): html = html.replace('&', '&') html = html.replace('<', '<') html = html.replace('>', '>') html = html.replace('"', '"') return html def main(): application = webapp.WSGIApplication([('/', MainHandler)], debug=True) util.run_wsgi_app(application) if __name__ == '__main__': main() |