summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pyramid/config.py46
-rw-r--r--pyramid/tests/test_config.py31
-rw-r--r--pyramid/tests/test_configuration.py4
-rw-r--r--pyramid/tests/test_view.py15
-rw-r--r--pyramid/tests/test_wsgi.py2
-rw-r--r--pyramid/wsgi.py8
6 files changed, 83 insertions, 23 deletions
diff --git a/pyramid/config.py b/pyramid/config.py
index 11770624d..1f4b85de0 100644
--- a/pyramid/config.py
+++ b/pyramid/config.py
@@ -46,15 +46,6 @@ from pyramid.interfaces import IView
from pyramid.interfaces import IViewClassifier
from pyramid.interfaces import IViewMapperFactory
-try:
- from pyramid import chameleon_text
-except TypeError: # pragma: no cover
- chameleon_text = None # pypy
-try:
- from pyramid import chameleon_zpt
-except TypeError: # pragma: no cover
- chameleon_zpt = None # pypy
-
from pyramid import renderers
from pyramid.authorization import ACLAuthorizationPolicy
from pyramid.compat import all
@@ -89,9 +80,6 @@ from pyramid.view import default_exceptionresponse_view
from pyramid.view import render_view_to_response
from pyramid.view import is_response
-MAX_ORDER = 1 << 30
-DEFAULT_PHASH = md5().hexdigest()
-
DEFAULT_RENDERERS = (
('.mak', mako_renderer_factory),
('.mako', mako_renderer_factory),
@@ -99,10 +87,20 @@ DEFAULT_RENDERERS = (
('string', renderers.string_renderer_factory),
)
-if chameleon_text:
- DEFAULT_RENDERERS += (('.pt', chameleon_zpt.renderer_factory),)
-if chameleon_zpt:
+try:
+ from pyramid import chameleon_text
DEFAULT_RENDERERS += (('.txt', chameleon_text.renderer_factory),)
+except TypeError: # pragma: no cover
+ pass # pypy
+
+try:
+ from pyramid import chameleon_zpt
+ DEFAULT_RENDERERS += (('.pt', chameleon_zpt.renderer_factory),)
+except TypeError: # pragma: no cover
+ pass #pypy
+
+MAX_ORDER = 1 << 30
+DEFAULT_PHASH = md5().hexdigest()
def action_method(wrapped):
""" Wrapper to provide the right conflict info report data when a method
@@ -303,7 +301,9 @@ class Configurator(object):
)
def _set_settings(self, mapping):
- settings = Settings(mapping or {})
+ if not mapping:
+ mapping = {}
+ settings = Settings(mapping)
self.registry.settings = settings
return settings
@@ -2798,8 +2798,11 @@ class ViewDeriver(object):
# this is a little silly but we don't want to decorate the original
# function with attributes that indicate accept, order, and phash,
# so we use a wrapper
- if ( (accept is None) and (order == MAX_ORDER) and
- (phash == DEFAULT_PHASH) ):
+ if (
+ (accept is None) and
+ (order == MAX_ORDER) and
+ (phash == DEFAULT_PHASH)
+ ):
return view # defaults
def attr_view(context, request):
return view(context, request)
@@ -2949,7 +2952,6 @@ def requestonly(view, attr=None):
return False
args = argspec[0]
- defaults = argspec[3]
if hasattr(fn, 'im_func'):
# it's an instance method
@@ -2962,7 +2964,11 @@ def requestonly(view, attr=None):
if len(args) == 1:
return True
- elif args[0] == 'request':
+ defaults = argspec[3]
+ if defaults is None:
+ defaults = ()
+
+ if args[0] == 'request':
if len(args) - len(defaults) == 1:
return True
diff --git a/pyramid/tests/test_config.py b/pyramid/tests/test_config.py
index 8b57e4c74..a862e2255 100644
--- a/pyramid/tests/test_config.py
+++ b/pyramid/tests/test_config.py
@@ -85,6 +85,16 @@ class ConfiguratorTests(unittest.TestCase):
self.failUnless(config.registry.getUtility(IRendererFactory, '.mak'))
self.failUnless(config.registry.getUtility(IRendererFactory, '.mako'))
+ def test__set_settings_as_None(self):
+ config = self._makeOne()
+ settings = config._set_settings(None)
+ self.failUnless(settings)
+
+ def test__set_settings_as_dictwithvalues(self):
+ config = self._makeOne()
+ settings = config._set_settings({'a':'1'})
+ self.assertEqual(settings['a'], '1')
+
def test_begin(self):
from pyramid.config import Configurator
config = Configurator()
@@ -3648,6 +3658,21 @@ class TestViewDeriver(unittest.TestCase):
self.failIf(result is view)
self.assertEqual(result(None, None), 'OK')
+ def test_attr_wrapped_view_branching_default_phash(self):
+ from pyramid.config import DEFAULT_PHASH
+ def view(context, request):
+ return 'OK'
+ deriver = self._makeOne(phash=DEFAULT_PHASH)
+ result = deriver(view)
+ self.assertEqual(result, view)
+
+ def test_attr_wrapped_view_branching_nondefault_phash(self):
+ def view(context, request):
+ return 'OK'
+ deriver = self._makeOne(phash='nondefault')
+ result = deriver(view)
+ self.assertNotEqual(result, view)
+
class TestDefaultViewMapper(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
@@ -4397,6 +4422,12 @@ class Test_requestonly(unittest.TestCase):
""" """
self.assertTrue(self._callFUT(foo))
+ def test_newstyle_class_init_firstname_request_with_secondname(self):
+ class foo(object):
+ def __init__(self, request, two):
+ """ """
+ self.assertFalse(self._callFUT(foo))
+
def test_newstyle_class_init_noargs(self):
class foo(object):
def __init__():
diff --git a/pyramid/tests/test_configuration.py b/pyramid/tests/test_configuration.py
index 786c7539b..688a597f6 100644
--- a/pyramid/tests/test_configuration.py
+++ b/pyramid/tests/test_configuration.py
@@ -17,5 +17,9 @@ class ConfiguratorTests(unittest.TestCase):
config = self._makeOne()
self.assertEqual(config.autocommit, True)
+ def test_package_is_not_None(self):
+ import pyramid
+ config = self._makeOne(package='pyramid')
+ self.assertEqual(config.package, pyramid)
diff --git a/pyramid/tests/test_view.py b/pyramid/tests/test_view.py
index c7d90a2af..0e88351b1 100644
--- a/pyramid/tests/test_view.py
+++ b/pyramid/tests/test_view.py
@@ -399,6 +399,14 @@ class Test_append_slash_notfound_view(BaseTest, unittest.TestCase):
response = self._callFUT(context, request)
self.assertEqual(response.status, '404 Not Found')
+ def test_no_route_matches(self):
+ request = self._makeRequest(PATH_INFO='/abc')
+ context = ExceptionResponse()
+ mapper = self._registerMapper(request.registry, True)
+ mapper.routelist[0].val = None
+ response = self._callFUT(context, request)
+ self.assertEqual(response.status, '404 Not Found')
+
def test_matches(self):
request = self._makeRequest(PATH_INFO='/abc')
context = ExceptionResponse()
@@ -447,9 +455,16 @@ class Test_default_exceptionresponse_view(unittest.TestCase):
result = self._callFUT(context, None)
self.failUnless(result is context)
+ def test_is_not_exception_context_is_false_still_chosen(self):
+ request = DummyRequest()
+ request.exception = 0
+ result = self._callFUT(None, request)
+ self.failUnless(result is None)
+
def test_is_not_exception_no_request_exception(self):
context = object()
request = DummyRequest()
+ request.exception = None
result = self._callFUT(context, request)
self.failUnless(result is context)
diff --git a/pyramid/tests/test_wsgi.py b/pyramid/tests/test_wsgi.py
index f1bc2f35c..f63667352 100644
--- a/pyramid/tests/test_wsgi.py
+++ b/pyramid/tests/test_wsgi.py
@@ -30,7 +30,7 @@ class WSGIApp2Tests(unittest.TestCase):
self.assertEqual(response, dummyapp)
self.assertEqual(request.environ['PATH_INFO'], '/subpath')
self.assertEqual(request.environ['SCRIPT_NAME'], '/foo/b/view_name')
-
+
def test_decorator_with_subpath_no_view_name(self):
context = DummyContext()
request = DummyRequest()
diff --git a/pyramid/wsgi.py b/pyramid/wsgi.py
index a647175db..e988a000e 100644
--- a/pyramid/wsgi.py
+++ b/pyramid/wsgi.py
@@ -63,9 +63,13 @@ def wsgiapp2(wrapped):
def decorator(context, request):
traversed = request.traversed
- vroot_path = request.virtual_root_path or ()
+ vroot_path = request.virtual_root_path
+ if not vroot_path:
+ vroot_path = ()
view_name = request.view_name
- subpath = request.subpath or ()
+ subpath = request.subpath
+ if not subpath:
+ subpath = ()
script_tuple = traversed[len(vroot_path):]
script_list = [ quote_path_segment(name) for name in script_tuple ]
if view_name: