summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2012-02-22 22:00:53 -0500
committerChris McDonough <chrism@plope.com>2012-02-22 22:00:53 -0500
commitf2f67edd97b9525ae6c6a20a09a9afa9189c018e (patch)
treee967551af84d923de15b83145bae5fd4b65a5183
parentfae09cd18a64efb32150dd0587995ed96cfc9523 (diff)
downloadpyramid-f2f67edd97b9525ae6c6a20a09a9afa9189c018e.tar.gz
pyramid-f2f67edd97b9525ae6c6a20a09a9afa9189c018e.tar.bz2
pyramid-f2f67edd97b9525ae6c6a20a09a9afa9189c018e.zip
move init_mimetypes to response module
-rw-r--r--pyramid/response.py12
-rw-r--r--pyramid/static.py13
-rw-r--r--pyramid/tests/test_response.py54
-rw-r--r--pyramid/tests/test_static.py21
4 files changed, 51 insertions, 49 deletions
diff --git a/pyramid/response.py b/pyramid/response.py
index 2642d7769..1dccb7ae8 100644
--- a/pyramid/response.py
+++ b/pyramid/response.py
@@ -10,6 +10,18 @@ from webob import Response as _Response
from zope.interface import implementer
from pyramid.interfaces import IResponse
+def init_mimetypes(mimetypes):
+ # this is a function so it can be unittested
+ if hasattr(mimetypes, 'init'):
+ mimetypes.init()
+ return True
+ return False
+
+# See http://bugs.python.org/issue5853 which is a recursion bug
+# that seems to effect Python 2.6, Python 2.6.1, and 2.6.2 (a fix
+# has been applied on the Python 2 trunk).
+init_mimetypes(mimetypes)
+
_BLOCK_SIZE = 4096 * 64 # 256K
@implementer(IResponse)
diff --git a/pyramid/static.py b/pyramid/static.py
index fbe60b1dd..dfb602ee0 100644
--- a/pyramid/static.py
+++ b/pyramid/static.py
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
-import mimetypes
import os
from os.path import (
@@ -33,18 +32,6 @@ from pyramid.traversal import traversal_path_info
slash = text_('/')
-def init_mimetypes(mimetypes):
- # this is a function so it can be unittested
- if hasattr(mimetypes, 'init'):
- mimetypes.init()
- return True
- return False
-
-# See http://bugs.python.org/issue5853 which is a recursion bug
-# that seems to effect Python 2.6, Python 2.6.1, and 2.6.2 (a fix
-# has been applied on the Python 2 trunk).
-init_mimetypes(mimetypes)
-
class static_view(object):
""" An instance of this class is a callable which can act as a
:app:`Pyramid` :term:`view callable`; this view will serve
diff --git a/pyramid/tests/test_response.py b/pyramid/tests/test_response.py
index c5df1fc05..03d96c1c4 100644
--- a/pyramid/tests/test_response.py
+++ b/pyramid/tests/test_response.py
@@ -63,22 +63,27 @@ class TestFileIter(unittest.TestCase):
inst.close()
self.assertTrue(f.closed)
-class Dummy(object):
- pass
-
-class DummyConfigurator(object):
- def __init__(self):
- self.adapters = []
-
- def add_response_adapter(self, wrapped, type_or_iface):
- self.adapters.append((wrapped, type_or_iface))
+class Test_patch_mimetypes(unittest.TestCase):
+ def _callFUT(self, module):
+ from pyramid.response import init_mimetypes
+ return init_mimetypes(module)
+
+ def test_has_init(self):
+ class DummyMimetypes(object):
+ def init(self):
+ self.initted = True
+ module = DummyMimetypes()
+ result = self._callFUT(module)
+ self.assertEqual(result, True)
+ self.assertEqual(module.initted, True)
+
+ def test_missing_init(self):
+ class DummyMimetypes(object):
+ pass
+ module = DummyMimetypes()
+ result = self._callFUT(module)
+ self.assertEqual(result, False)
-class DummyVenusian(object):
- def __init__(self):
- self.attached = []
-
- def attach(self, wrapped, fn, category=None):
- self.attached.append((wrapped, fn, category))
class TestResponseAdapter(unittest.TestCase):
def setUp(self):
@@ -125,3 +130,22 @@ class TestResponseAdapter(unittest.TestCase):
dec(foo)
self.assertEqual(dummy_venusian.attached,
[(foo, dec.register, 'pyramid')])
+
+class Dummy(object):
+ pass
+
+class DummyConfigurator(object):
+ def __init__(self):
+ self.adapters = []
+
+ def add_response_adapter(self, wrapped, type_or_iface):
+ self.adapters.append((wrapped, type_or_iface))
+
+class DummyVenusian(object):
+ def __init__(self):
+ self.attached = []
+
+ def attach(self, wrapped, fn, category=None):
+ self.attached.append((wrapped, fn, category))
+
+
diff --git a/pyramid/tests/test_static.py b/pyramid/tests/test_static.py
index 70932143e..7f94df990 100644
--- a/pyramid/tests/test_static.py
+++ b/pyramid/tests/test_static.py
@@ -364,27 +364,6 @@ class Test_static_view_use_subpath_True(unittest.TestCase):
response = inst(context, request)
self.assertEqual(response.status, '404 Not Found')
-class Test_patch_mimetypes(unittest.TestCase):
- def _callFUT(self, module):
- from pyramid.static import init_mimetypes
- return init_mimetypes(module)
-
- def test_has_init(self):
- class DummyMimetypes(object):
- def init(self):
- self.initted = True
- module = DummyMimetypes()
- result = self._callFUT(module)
- self.assertEqual(result, True)
- self.assertEqual(module.initted, True)
-
- def test_missing_init(self):
- class DummyMimetypes(object):
- pass
- module = DummyMimetypes()
- result = self._callFUT(module)
- self.assertEqual(result, False)
-
class DummyContext:
pass