Mercurial > hg > clwapp
changeset 2:79a43cbdf584
fix unicode stuff
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 20 Dec 2011 11:34:10 -0800 |
parents | 2f45e6ae75fc |
children | 672addc0c4be |
files | clwapp/clwapp.py setup.py |
diffstat | 2 files changed, 6 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/clwapp/clwapp.py +++ b/clwapp/clwapp.py @@ -10,16 +10,17 @@ SYSTEM OR EXPOSE SENSITIVE DATA! subpro the shell is restricted, but programs that can alter your system can be exploited. clwapp works well with programs that display information (provided their access is restricted from secure information), and less well with programs that change the state of the server. *NEVER* use with Popen(shell=True) unless you are sure of your security. """ +import os import subprocess import utils from webob import Request, Response, exc class View(object): ### class level variables @@ -32,34 +33,35 @@ class View(object): setattr(self, key, kw.get(key, self.defaults[key])) self.response_functions = { 'GET': self.get } ### methods dealing with HTTP def __call__(self, environ, start_response): self.request = Request(environ) res = self.make_response(self.request.method) return res(environ, start_response) - + def make_response(self, method): return self.response_functions.get(method, self.error)() def get_response(self, text, content_type='text/html'): res = Response(content_type=content_type, body=text) res.content_length = len(res.body) return res def get(self): """ return response to a GET requst """ args = self.command + self.request.GET.keys() process = subprocess.Popen(args, stdout=subprocess.PIPE) output = process.communicate()[0] - title = ' '.join(args) + output = output.decode('utf-8', errors='ignore') + title = ' '.join([os.path.basename(args[0])] + args[1:]) return self.get_response("""<html><head><title>%s</title></head><body><pre> %s </pre></body></html> """ % (title, output) ) def error(self): """deal with non-supported methods""" return exc.HTTPMethodNotAllowed("Only %r operations are allowed" % self.response_functions.keys()) - +
--- a/setup.py +++ b/setup.py @@ -1,12 +1,12 @@ from setuptools import setup, find_packages import sys, os -version = "0.1" +version = "0.1.1" setup(name='clwapp', version=version, description="Command Line Web APP", long_description="""gives the output from a command line application TTW """, classifiers=[], # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers author='Jeff Hammel',