weakish / weakishScripts
Tiny/Weakish/Useless/Toy scripts and config files. Except where otherwise noted, content on this repo is licensed under version 2 of the GNU General Public License.
Clone this repository (size: 4.7 MB): HTTPS / SSH
$ hg clone http://bitbucket.org/weakish/weakishscripts/
reStructuredText render on Google App Engine
This small web application renders user's input in reStructuredText into HTML. It's a port of Jiri Barton's mod_python version to Google App Engine.
You can check it out at http://weakish.appspot.com/rest.py
Source
It's very dirty. :-(
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | #!/usr/bin/env python
#
# Copyright 2007 Google Inc.
# Copyright 2008 Weakish Jiang
#
# 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.
#
# Based on the guestbook sample in Google App Engine start guide and
# reST render written by Jiri Barton <jbar@hosting4u.cz>
import cgi
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from docutils.core import publish_string
class MainPage(webapp.RequestHandler):
def get(self):
self.response.out.write("""
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title>reST renderer</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>reST to HTML conversion</h1>
<form action="/sign" method="post">
<label>Type some reST into the box below:</label>
<br /><br />
<textarea name="content" rows="20" cols="80"></textarea>
<br /><br />
<input type="submit" value="Render" />
</form>
<hr />
<p><a href="http://bitbucket.org/weakish/weakishscripts/wiki/reSTRenderOnGAE" title="about this reSt render app">about...</a></p>
</body>
</html>
""")
class Guestbook(webapp.RequestHandler):
def post(self):
self.response.out.write("""
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title>reST renderer</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>reST to HTML conversion</h1>
""")
self.response.out.write('<h1>Preview:</h1>')
self.response.out.write(render(self.request.get('content')))
self.response.out.write("""
<hr />
<form action="/sign" method="post">
<label>Type some reST into the box below:</label>
<br /><br />
<textarea name="content" rows="20" cols="80">""")
self.response.out.write(cgi.escape(self.request.get('content')))
self.response.out.write("""
</textarea><br /><br />
<input type="submit" value="Render" />
</form>
</body>
<hr />
<p><a href="http://bitbucket.org/weakish/weakishscripts/wiki/reSTRenderOnGAE" title="about this reSt render app">about...</a></p>
</html>
""")
application = webapp.WSGIApplication(
[('/rest.py', MainPage),
('/sign', Guestbook)],
debug=True)
def render(content=''):
return publish_string(
source=content,
settings_overrides={'_disable_config': True, 'file_insertion_enabled': 0, 'raw_enabled': 0},
writer_name='html')
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
|
You can upload it with the name rest.py to your Google App and add the follwoing lines to your app.yaml:
This revision is from 2009-12-03 12:41
