diff options
| author | Chris McDonough <chrism@plope.com> | 2011-11-18 05:48:57 -0500 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2011-11-18 05:48:57 -0500 |
| commit | 69cc84c19acdff6e12b2e166248bb35293ed2e5a (patch) | |
| tree | 0cc7b1c9905c9d903986c06c32e5df127dacef3a | |
| parent | 4f47e7cd2fea3f656fd17e6180c6ee30c0753bd2 (diff) | |
| parent | 0e5441806857e3c1ef59d1b2075d6e4238587804 (diff) | |
| download | pyramid-69cc84c19acdff6e12b2e166248bb35293ed2e5a.tar.gz pyramid-69cc84c19acdff6e12b2e166248bb35293ed2e5a.tar.bz2 pyramid-69cc84c19acdff6e12b2e166248bb35293ed2e5a.zip | |
Merge branch 'kdienes-master'
| -rw-r--r-- | CONTRIBUTORS.txt | 2 | ||||
| -rw-r--r-- | pyramid/static.py | 4 | ||||
| -rw-r--r-- | pyramid/tests/fixtures/static/arcs.svg.tgz | 73 | ||||
| -rw-r--r-- | pyramid/tests/test_static.py | 18 |
4 files changed, 96 insertions, 1 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 2654801c3..a449333cb 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -156,3 +156,5 @@ Contributors - Ken Manheimer, 2011/11/07 - Reed O'Brien, 2011/11/07 + +- Klee Dienes, 2011/10/30 diff --git a/pyramid/static.py b/pyramid/static.py index 50a8b918b..ba4ac0fa1 100644 --- a/pyramid/static.py +++ b/pyramid/static.py @@ -43,10 +43,12 @@ class _FileResponse(Response): def __init__(self, path, cache_max_age): super(_FileResponse, self).__init__(conditional_response=True) self.last_modified = getmtime(path) - content_type = mimetypes.guess_type(path, strict=False)[0] + content_type, content_encoding = mimetypes.guess_type(path, + strict=False) if content_type is None: content_type = 'application/octet-stream' self.content_type = content_type + self.content_encoding = content_encoding content_length = getsize(path) self.app_iter = _FileIter(open(path, 'rb'), content_length) # assignment of content_length must come after assignment of app_iter diff --git a/pyramid/tests/fixtures/static/arcs.svg.tgz b/pyramid/tests/fixtures/static/arcs.svg.tgz new file mode 100644 index 000000000..376c42ac8 --- /dev/null +++ b/pyramid/tests/fixtures/static/arcs.svg.tgz @@ -0,0 +1,73 @@ +<?xml version="1.0"?> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" + "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> +<svg xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + id="canvas" + width="2000" + height="2000" + onload="init()"> + + <style type="text/css"> + .ellipse + { + stroke: red; + stroke-width: 2; + fill: blue; + fill-opacity: 0.1; + } + + .axes + { + stroke: blue; + stroke-width: 1; + } + </style> + + <script> + <![CDATA[ + var COLS = 4; + var ROWS = 4; + var RX = 80; + var RY = 30; + + function init() + { + var canvas = document.getElementById("canvas"); + + var angleStep = 360.0/(COLS*ROWS); + var spacing = 2*Math.max(RX, RY)+10; + for (var c = 0; c < COLS; ++c) { + for (var r = 0; r < ROWS; ++r) { + var ellipse = createEllipse((c+ COLS*r)*angleStep, spacing*(c+0.5), spacing*(r+0.5), RX, RY); + canvas.appendChild(ellipse); + } + } + } + + function createEllipse(phi, x, y, rx, ry) + { + var degPerRad = Math.PI/180.0; + var e1x = rx*Math.cos(phi*degPerRad); + var e1y = rx*Math.sin(phi*degPerRad); + var e2x = ry*Math.cos((phi+90)*degPerRad); + var e2y = ry*Math.sin((phi+90)*degPerRad); + + var axes = document.createElementNS("http://www.w3.org/2000/svg", "path"); + axes.setAttribute("class", "axes"); + axes.setAttribute("d", "M"+x+","+y+" l"+e1x+","+e1y+"M"+x+","+y+" l"+e2x+","+e2y); + var ellipse = document.createElementNS("http://www.w3.org/2000/svg", "path"); + ellipse.setAttribute("class", "ellipse"); + ellipse.setAttribute("d", "M" + (x+e1x) + "," + (y+e1y) + + "A" + rx + "," + ry + " " + phi + " 0,1 " + (x+e2x) + "," + (y+e2y) + + "A" + rx + "," + ry + " " + phi + " 1,1 " + (x+e1x) + "," + (y+e1y) +"z"); + + var group = document.createElementNS("http://www.w3.org/2000/svg", "g"); + group.appendChild(axes); + group.appendChild(ellipse); + return group; + } + + ]]> + </script> +</svg> diff --git a/pyramid/tests/test_static.py b/pyramid/tests/test_static.py index a04a47397..bd2c2adef 100644 --- a/pyramid/tests/test_static.py +++ b/pyramid/tests/test_static.py @@ -160,6 +160,24 @@ class Test_static_view_use_subpath_False(unittest.TestCase): response = inst(context, request) self.assertEqual(response.status, '404 Not Found') + def test_resource_with_content_encoding(self): + inst = self._makeOne('pyramid.tests:fixtures/static') + request = self._makeRequest({'PATH_INFO':'/arcs.svg.tgz'}) + context = DummyContext() + response = inst(context, request) + self.assertEqual(response.status, '200 OK') + self.assertEqual(response.content_type, 'application/x-tar') + self.assertEqual(response.content_encoding, 'gzip') + + def test_resource_no_content_encoding(self): + inst = self._makeOne('pyramid.tests:fixtures/static') + request = self._makeRequest({'PATH_INFO':'/index.html'}) + context = DummyContext() + response = inst(context, request) + self.assertEqual(response.status, '200 OK') + self.assertEqual(response.content_type, 'text/html') + self.assertEqual(response.content_encoding, None) + class Test_static_view_use_subpath_True(unittest.TestCase): def _getTargetClass(self): from pyramid.static import static_view |
