summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2011-05-29 01:24:43 -0400
committerChris McDonough <chrism@plope.com>2011-05-29 01:24:43 -0400
commit3488ebdb257f2b0784def1aa90e56c6a6581bb9d (patch)
tree84e32355357fe40af7345efaf945e81de0d1dfb5
parentce9b9baba16799041e6a4e819eef894ae9ff516d (diff)
downloadpyramid-3488ebdb257f2b0784def1aa90e56c6a6581bb9d.tar.gz
pyramid-3488ebdb257f2b0784def1aa90e56c6a6581bb9d.tar.bz2
pyramid-3488ebdb257f2b0784def1aa90e56c6a6581bb9d.zip
preemptively drop 2.4 support
-rw-r--r--pyramid/config.py8
-rw-r--r--pyramid/exceptions.py47
-rw-r--r--pyramid/router.py2
-rw-r--r--pyramid/tests/test_exceptions.py14
4 files changed, 21 insertions, 50 deletions
diff --git a/pyramid/config.py b/pyramid/config.py
index a20f93a90..1013456ec 100644
--- a/pyramid/config.py
+++ b/pyramid/config.py
@@ -2702,7 +2702,7 @@ class MultiView(object):
return view
if view.__predicated__(context, request):
return view
- raise PredicateMismatch(self.name).exception
+ raise PredicateMismatch(self.name)
def __permitted__(self, context, request):
view = self.match(context, request)
@@ -2721,7 +2721,7 @@ class MultiView(object):
return view(context, request)
except PredicateMismatch:
continue
- raise PredicateMismatch(self.name).exception
+ raise PredicateMismatch(self.name)
def wraps_view(wrapped):
def inner(self, view):
@@ -2844,7 +2844,7 @@ class ViewDeriver(object):
return view(context, request)
msg = getattr(request, 'authdebug_message',
'Unauthorized: %s failed permission check' % view)
- raise Forbidden(msg, result=result).exception
+ raise Forbidden(msg, result=result)
_secured_view.__call_permissive__ = view
_secured_view.__permitted__ = _permitted
_secured_view.__permission__ = permission
@@ -2894,7 +2894,7 @@ class ViewDeriver(object):
if all((predicate(context, request) for predicate in predicates)):
return view(context, request)
raise PredicateMismatch(
- 'predicate mismatch for view %s' % view).exception
+ 'predicate mismatch for view %s' % view)
def checker(context, request):
return all((predicate(context, request) for predicate in
predicates))
diff --git a/pyramid/exceptions.py b/pyramid/exceptions.py
index 8705ed1fb..168426a9c 100644
--- a/pyramid/exceptions.py
+++ b/pyramid/exceptions.py
@@ -122,8 +122,6 @@ from zope.configuration.exceptions import ConfigurationError as ZCE
from zope.interface import implements
from pyramid.interfaces import IExceptionResponse
-newstyle_exceptions = issubclass(Exception, object)
-
def no_escape(value):
if value is None:
return ''
@@ -135,37 +133,10 @@ def no_escape(value):
return value
class HTTPException(Exception):
- implements(IExceptionResponse)
- """
- Exception used on pre-Python-2.5, where new-style classes cannot be used as
- an exception.
- """
-
- def __init__(self, message, wsgi_response):
- self.message = message
- Exception.__init__(self, message)
- self.__dict__['wsgi_response'] = wsgi_response
-
- def exception(self):
- return self
-
- exception = property(exception)
-
- # for old style exceptions
- if not newstyle_exceptions: #pragma NO COVERAGE
- def __getattr__(self, attr):
- if not attr.startswith('_'):
- return getattr(self.wsgi_response, attr)
- else:
- raise AttributeError(attr)
-
- def __setattr__(self, attr, value):
- if attr.startswith('_') or attr in ('args',):
- self.__dict__[attr] = value
- else:
- setattr(self.wsgi_response, attr, value)
+ pass
class WSGIHTTPException(Response, HTTPException):
+ implements(IExceptionResponse)
## You should set in subclasses:
# code = 200
@@ -193,6 +164,10 @@ class WSGIHTTPException(Response, HTTPException):
# - explicitly sets self.message = detail to prevent whining by Python
# 2.6.5+ Exception.message
#
+ # - its base class of HTTPException is no longer a Python 2.4 compatibility
+ # shim; it's purely a base class that inherits from Exception. This
+ # implies that this class' ``exception`` property always returns
+ # ``self`` (only for bw compat at this point).
code = None
title = None
explanation = ''
@@ -292,10 +267,8 @@ ${body}''')
wsgi_response = property(wsgi_response)
def exception(self):
- if newstyle_exceptions:
- return self
- else:
- return HTTPException(self.detail, self)
+ # bw compat
+ return self
exception = property(exception)
@@ -1063,7 +1036,7 @@ def abort(status_code, **kw):
abort(404) # raises an HTTPNotFound exception.
"""
exc = status_map[status_code](**kw)
- raise exc.exception
+ raise exc
def redirect(url, code=302, **kw):
@@ -1076,7 +1049,7 @@ def redirect(url, code=302, **kw):
"""
exc = status_map[code]
- raise exc(location=url, **kw).exception
+ raise exc(location=url, **kw)
def default_exceptionresponse_view(context, request):
if not isinstance(context, Exception):
diff --git a/pyramid/router.py b/pyramid/router.py
index 069db52bc..b8a8639aa 100644
--- a/pyramid/router.py
+++ b/pyramid/router.py
@@ -153,7 +153,7 @@ class Router(object):
logger and logger.debug(msg)
else:
msg = request.path_info
- raise NotFound(msg).exception
+ raise NotFound(msg)
else:
response = view_callable(context, request)
diff --git a/pyramid/tests/test_exceptions.py b/pyramid/tests/test_exceptions.py
index 3f303e3df..e3e44c9f2 100644
--- a/pyramid/tests/test_exceptions.py
+++ b/pyramid/tests/test_exceptions.py
@@ -31,19 +31,17 @@ class Test_abort(unittest.TestCase):
def test_status_404(self):
from pyramid.exceptions import HTTPNotFound
- self.assertRaises(HTTPNotFound().exception.__class__,
- self._callFUT, 404)
+ self.assertRaises(HTTPNotFound, self._callFUT, 404)
def test_status_201(self):
from pyramid.exceptions import HTTPCreated
- self.assertRaises(HTTPCreated().exception.__class__,
- self._callFUT, 201)
+ self.assertRaises(HTTPCreated, self._callFUT, 201)
def test_extra_kw(self):
from pyramid.exceptions import HTTPNotFound
try:
self._callFUT(404, headers=[('abc', 'def')])
- except HTTPNotFound().exception.__class__, exc:
+ except HTTPNotFound, exc:
self.assertEqual(exc.headers['abc'], 'def')
else: # pragma: no cover
raise AssertionError
@@ -57,7 +55,7 @@ class Test_redirect(unittest.TestCase):
from pyramid.exceptions import HTTPFound
try:
self._callFUT('http://example.com')
- except HTTPFound().exception.__class__, exc:
+ except HTTPFound, exc:
self.assertEqual(exc.location, 'http://example.com')
self.assertEqual(exc.status, '302 Found')
@@ -65,7 +63,7 @@ class Test_redirect(unittest.TestCase):
from pyramid.exceptions import HTTPMovedPermanently
try:
self._callFUT('http://example.com', 301)
- except HTTPMovedPermanently().exception.__class__, exc:
+ except HTTPMovedPermanently, exc:
self.assertEqual(exc.location, 'http://example.com')
self.assertEqual(exc.status, '301 Moved Permanently')
@@ -73,7 +71,7 @@ class Test_redirect(unittest.TestCase):
from pyramid.exceptions import HTTPFound
try:
self._callFUT('http://example.com', headers=[('abc', 'def')])
- except HTTPFound().exception.__class__, exc:
+ except HTTPFound, exc:
self.assertEqual(exc.location, 'http://example.com')
self.assertEqual(exc.status, '302 Found')
self.assertEqual(exc.headers['abc'], 'def')