/usr/lib/python2.7/dist-packages/sx/pisa3/pisa_wsgi.py is in python-pisa 3.0.32-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | # -*- coding: UTF-8 -*-
#############################################
## (C)opyright by Dirk Holtwick, 2008 ##
## All rights reserved ##
#############################################
__version__ = "$Revision: 103 $"
__author__ = "$Author: holtwick $"
__date__ = "$Date: 2007-10-31 17:08:54 +0100 (Mi, 31 Okt 2007) $"
__svnid__ = "$Id: pisa.py 103 2007-10-31 16:08:54Z holtwick $"
import ho.pisa as pisa
import StringIO
import logging
log = logging.getLogger("ho.pisa.wsgi")
class Filter(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
script_name = environ.get('SCRIPT_NAME', '')
path_info = environ.get('PATH_INFO', '')
sent = []
written_response = StringIO.StringIO()
def replacement_start_response(status, headers, exc_info=None):
if not self.should_filter(status, headers):
return start_response(status, headers, exc_info)
else:
sent[:] = [status, headers, exc_info]
return written_response.write
app_iter = self.app(environ, replacement_start_response)
if not sent:
return app_iter
status, headers, exc_info = sent
try:
for chunk in app_iter:
written_response.write(chunk)
finally:
if hasattr(app_iter, 'close'):
app_iter.close()
body = written_response.getvalue()
status, headers, body = self.filter(
script_name, path_info, environ, status, headers, body)
start_response(status, headers, exc_info)
return [body]
def should_filter(self, status, headers):
print headers
def filter(self, status, headers, body):
raise NotImplementedError
class HTMLFilter(Filter):
def should_filter(self, status, headers):
if not status.startswith('200'):
return False
for name, value in headers:
if name.lower() == 'content-type':
return value.startswith('text/html')
return False
class PisaMiddleware(HTMLFilter):
def filter(self,
script_name,
path_info,
environ,
status,
headers,
body):
topdf = environ.get("pisa.topdf", "")
if topdf:
dst = StringIO.StringIO()
result = pisa.CreatePDF(
body,
dst,
show_error_as_pdf=True,
)
headers = [
("content-type", "application/pdf"),
("content-disposition", "attachment; filename=" + topdf)
]
body = dst.getvalue()
return status, headers, body
|