Permalink
Browse files

move init_mimetypes to response module

  • Loading branch information...
1 parent fae09cd commit f2f67edd97b9525ae6c6a20a09a9afa9189c018e @mcdonc mcdonc committed Feb 23, 2012
Showing with 51 additions and 49 deletions.
  1. +12 −0 pyramid/response.py
  2. +0 −13 pyramid/static.py
  3. +39 −15 pyramid/tests/test_response.py
  4. +0 −21 pyramid/tests/test_static.py
View
@@ -10,6 +10,18 @@
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)
View
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
-import mimetypes
import os
from os.path import (
@@ -33,18 +32,6 @@
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
@@ -63,22 +63,27 @@ def test_close(self):
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 @@ def foo(): pass
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))
+
+
@@ -364,27 +364,6 @@ def test_not_found(self):
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

0 comments on commit f2f67ed

Please sign in to comment.