Welcome. Use this text box to input your dirty-formatted python code, and get a nice, well ordered file.
18 |If you have made syntax mistakes, It will complain and not give you the cookie ;)
19 |├── favicon.ico ├── README.mk ├── app.yaml ├── index.yaml ├── staticfiles ├── zen.css └── staila.css ├── templates ├── zen.html └── formater.html ├── main.py └── pythontidy.py /favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanantoniofm/pythoniter/HEAD/favicon.ico -------------------------------------------------------------------------------- /README.mk: -------------------------------------------------------------------------------- 1 | # Pythoniter 2 | 3 | 4 | Small web Python code formatter. 5 | Implemented using Google Appengine, with StrinIO and based on pythontidy 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app.yaml: -------------------------------------------------------------------------------- 1 | application: pythoniter 2 | version: 1 3 | runtime: python27 4 | api_version: 1 5 | threadsafe: yes 6 | 7 | handlers: 8 | - url: /favicon\.ico 9 | static_files: favicon.ico 10 | upload: favicon\.ico 11 | 12 | - url: /staticfiles 13 | static_dir: staticfiles 14 | 15 | - url: .* 16 | script: main.app 17 | - url: /down 18 | script: main.app 19 | 20 | libraries: 21 | - name: webapp2 22 | version: "2.5.1" 23 | - name: jinja2 24 | version: "2.6" 25 | 26 | -------------------------------------------------------------------------------- /index.yaml: -------------------------------------------------------------------------------- 1 | indexes: 2 | 3 | # AUTOGENERATED 4 | 5 | # This index.yaml is automatically updated whenever the dev_appserver 6 | # detects that a new type of query is run. If you want to manage the 7 | # index.yaml file manually, remove the above marker line (the line 8 | # saying "# AUTOGENERATED"). If you want to manage some indexes 9 | # manually, move them above the marker line. The index.yaml file is 10 | # automatically uploaded to the admin console when you next deploy 11 | # your application using appcfg.py. 12 | 13 | -------------------------------------------------------------------------------- /staticfiles/zen.css: -------------------------------------------------------------------------------- 1 | 2 | 3 | body{ 4 | text-align:center; 5 | margin:0 auto; 6 | background-color:#EEE9D6; //soft bone white 7 | } 8 | 9 | button{ 10 | color: white; 11 | background-color: black; 12 | font: 13px Helvetica, arial, freesans, clean, sans-serif; 13 | } 14 | 15 | textarea{ 16 | width: 100%; 17 | height: 95%; 18 | padding: 10px 100px; 19 | color: #073642; 20 | background-color: #eee9d6; 21 | outline:none; 22 | border: 0; 23 | font: 14px Helvetica, arial, freesans, clean, sans-serif; 24 | 25 | } 26 | 27 | #zenbar{ 28 | color:#657b83; 29 | text-decoration: none; 30 | } 31 | 32 | #zenbar a{ 33 | color:#073642; 34 | text-decoration: none; 35 | } 36 | 37 | .mini{ 38 | font-size:small; 39 | font-family:Arial, Sans-Serif; 40 | margin: 0 0 9%; 41 | } 42 | -------------------------------------------------------------------------------- /staticfiles/staila.css: -------------------------------------------------------------------------------- 1 | body{ 2 | text-align:center; 3 | margin:0 auto; 4 | background-color:#EEE9D6; //soft bone white 5 | } 6 | 7 | h2{ 8 | margin: 10% auto 2%; 9 | } 10 | 11 | #container{ 12 | width: 90%; 13 | text-align: left; 14 | margin: 0 auto; 15 | color: #576E74; 16 | } 17 | 18 | .mini{ 19 | font-size:small; 20 | font-family:Arial, Sans-Serif; 21 | margin: 0 0 9%; 22 | } 23 | textarea{ 24 | width: 100%; 25 | padding: 10px 30px; 26 | margin: auto; 27 | } 28 | 29 | #errorConsole{ 30 | padding: 0.25% 2.5%; 31 | color:#93a1a1; //kinda light grey-blueish 32 | background-color:#002A38; //dark blueish 33 | } 34 | 35 | .error{ 36 | color:#DD312F; //red 37 | } 38 | 39 | //Other Colors 40 | // orange : #ca4711 41 | // yellow: #b58a00 42 | // magenta:#d63581 43 | // violet: #6b71c7 44 | // blue : #258bd3 45 | // cyan : #2ba098 46 | // green : #859A01 47 | -------------------------------------------------------------------------------- /templates/zen.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |Error example
24 |Welcome. Use this text box to input your dirty-formatted python code, and get a nice, well ordered file.
18 |If you have made syntax mistakes, It will complain and not give you the cookie ;)
19 |Error example
39 |Powered by: Juan Antonio FM || Google Appengine
44 | 45 | 46 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright 2007 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | import os 18 | import webapp2 19 | import jinja2 20 | import logging 21 | 22 | import StringIO 23 | import pythontidy as pt 24 | template_path=os.path.dirname(__file__) + "/templates" 25 | jinja_environment = jinja2.Environment( 26 | loader=jinja2.FileSystemLoader(template_path)) 27 | logging.debug("The path for templates is") 28 | logging.debug(template_path) 29 | 30 | class MainHandler(webapp2.RequestHandler): 31 | 32 | def renderAndWrite(self, values, template="formater.html"): 33 | """render values in the template""" 34 | template = jinja_environment.get_template(template) 35 | self.response.out.write(template.render(values)) 36 | 37 | def formater(self, pythonshit): 38 | #- receive text in string format 39 | #- convert it to file-like object 40 | inf = StringIO.StringIO() 41 | ouf = StringIO.StringIO() 42 | inf.write(pythonshit) 43 | inf.seek(0) 44 | #- pass it through the tidyer 45 | pt.tidy_up(inf, ouf) 46 | pythonshit = ouf.getvalue() 47 | #- return the output as string 48 | return pythonshit 49 | 50 | def post(self): 51 | """get receive text and prettyprint it""" 52 | #- take the text from the request 53 | txt = self.request.get('chorizo') 54 | #- send it to the formater 55 | bonitico = self.formater(txt) 56 | #- and show a website with the pretty code 57 | self.renderAndWrite({"codechunk": bonitico}) 58 | 59 | def get(self): 60 | """shows just atext box for input""" 61 | self.renderAndWrite({"codechunk" : "Aqui pegar tu python fulero"}) 62 | 63 | 64 | class DownHandler(MainHandler): 65 | def post(self): 66 | self.renderAndWrite({"codechunk" : 67 | self.formater( 68 | self.request.get('chorizo'))}) 69 | 70 | def get(self): 71 | self.response.out.write("""Visit this using POST to upload your code, and 72 | download it as a file""") 73 | 74 | 75 | class ZenHandler(MainHandler): 76 | def post(self): 77 | self.renderAndWrite({"codechunk" : 78 | self.formater( 79 | self.request.get('chorizo'))}, 80 | "zen.html") 81 | 82 | def get(self): 83 | self.renderAndWrite({"codechunk" : "Here goes your Python"}, 84 | "zen.html") 85 | 86 | 87 | 88 | app = webapp2.WSGIApplication([ 89 | ('/', MainHandler), 90 | ('/zen', ZenHandler), 91 | ('/down', DownHandler) 92 | ], debug=True) 93 | -------------------------------------------------------------------------------- /pythontidy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # PythonTidy.py 5 | # 2006 Oct 27 . ccr 6 | 7 | '''PythonTidy.py cleans up, regularizes, and reformats the text of 8 | Python scripts. 9 | 10 | =========================================== 11 | Copyright © 2006 Charles Curtis Rhode 12 | =========================================== 13 | 14 | This program is free software; you can redistribute it and/or modify 15 | it under the terms of the GNU General Public License as published by 16 | the Free Software Foundation; either version 2 of the License, or (at 17 | your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, but 20 | WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program; if not, write to the Free Software 26 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 27 | USA. 28 | 29 | =========================================== 30 | Charles Curtis Rhode, 31 | 1518 N 3rd, Sheboygan, WI 53081 32 | mailto:CRhode@LacusVeris.com?subject=PythonTidy 33 | =========================================== 34 | 35 | This script reads Python code from standard input and writes a revised 36 | version to standard output. 37 | 38 | Alternatively, it may be invoked with file names as arguments: 39 | 40 | o python PythonTidy.py input output 41 | 42 | Suffice it to say that *input* defaults to \'-\', the standard input, 43 | and *output* defaults to \'-\', the standard output. 44 | 45 | It means to encapsulate the wisdom revealed in: 46 | 47 | o Rossum, Guido van, and Barry Warsaw. "PEP 8: Style Guide for Python 48 | Code." 23 Mar. 2006. Python.org. 28 Nov. 2006 49 |