# HG changeset patch # User k0s # Date 1265587395 18000 # Node ID 051d4d39b4b9c0b516ef555c28fcc9dd3fae1ae6 # Parent 805cadc2b82583c76a5453bdac8bab8fb16b6dab * separate out get_response to its own function * keep track of raw content_type for later usage (muahaha) diff -r 805cadc2b825 -r 051d4d39b4b9 contenttransformer/app.py --- a/contenttransformer/app.py Sun Feb 07 18:52:40 2010 -0500 +++ b/contenttransformer/app.py Sun Feb 07 19:03:15 2010 -0500 @@ -1,6 +1,7 @@ import os import sys from fnmatch import fnmatch +from mimetypes import guess_type from paste.fileapp import FileApp from pkg_resources import iter_entry_points @@ -23,8 +24,9 @@ filename = os.path.basename(path) for pattern, transformer_name in self.types: if fnmatch(filename, pattern): + content_type, _ = guess_type(filename) content = file(path).read() - return self.transformers[transformer_name](content) + return self.transformers[transformer_name](content, content_type) return FileApp(path) diff -r 805cadc2b825 -r 051d4d39b4b9 contenttransformer/transformers.py --- a/contenttransformer/transformers.py Sun Feb 07 18:52:40 2010 -0500 +++ b/contenttransformer/transformers.py Sun Feb 07 19:03:15 2010 -0500 @@ -4,8 +4,9 @@ class Transformer(object): """abstract base class for transformer objects""" - def __init__(self, content): + def __init__(self, content, content_type): self.content = content + self.content_type = content_type def transform(self, request): """returns a tuple of (body, content-type)""" @@ -13,8 +14,15 @@ def __call__(self, environ, start_response): request = Request(environ) + response = self.get_response(request) + return response(environ, start_response) + + def get_response(self, request): + if request.GET.get('format') == 'raw': + return Response(content_type=self.content_type, body=self.content) content_type, body = self.transform(request) - return Response(content_type=content_type, body=body)(environ, start_response) + return Response(content_type=content_type, body=body) + class Graphviz(Transformer): def transform(self, request): diff -r 805cadc2b825 -r 051d4d39b4b9 setup.py --- a/setup.py Sun Feb 07 18:52:40 2010 -0500 +++ b/setup.py Sun Feb 07 19:03:15 2010 -0500 @@ -1,7 +1,7 @@ from setuptools import setup, find_packages import sys, os -version = "0.2" +version = "0.3" setup(name='contenttransformer', version=version,