diff options
Diffstat (limited to 'paste/httpexceptions.py')
-rw-r--r-- | paste/httpexceptions.py | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/paste/httpexceptions.py b/paste/httpexceptions.py index 85e7c84..0b68c2d 100644 --- a/paste/httpexceptions.py +++ b/paste/httpexceptions.py @@ -74,7 +74,7 @@ References: """ -import types +import six from paste.wsgilib import catch_errors_app from paste.response import has_header, header_value, replace_header from paste.request import resolve_relative_url @@ -178,9 +178,9 @@ class HTTPException(Exception): assert isinstance(headers, (type(None), list)), ( "headers must be None or a list: %r" % headers) - assert isinstance(detail, (type(None), basestring)), ( + assert isinstance(detail, (type(None), six.binary_type, six.text_type)), ( "detail must be None or a string: %r" % detail) - assert isinstance(comment, (type(None), basestring)), ( + assert isinstance(comment, (type(None), six.binary_type, six.text_type)), ( "comment must be None or a string: %r" % comment) self.headers = headers or tuple() for req in self.required_headers: @@ -206,9 +206,10 @@ class HTTPException(Exception): if self.headers: for (k, v) in self.headers: args[k.lower()] = escfunc(v) - for key, value in args.items(): - if isinstance(value, unicode): - args[key] = value.encode('utf8', 'xmlcharrefreplace') + if six.PY2: + for key, value in args.items(): + if isinstance(value, six.text_type): + args[key] = value.encode('utf8', 'xmlcharrefreplace') return template % args def plain(self, environ): @@ -237,7 +238,7 @@ class HTTPException(Exception): else: replace_header(headers, 'content-type', 'text/plain') content = self.plain(environ) - if isinstance(content, unicode): + if isinstance(content, six.text_type): content = content.encode('utf8') cur_content_type = ( header_value(headers, 'content-type') @@ -593,8 +594,8 @@ class HTTPVersionNotSupported(HTTPServerError): __all__ = ['HTTPException', 'HTTPRedirection', 'HTTPError' ] _exceptions = {} -for name, value in globals().items(): - if (isinstance(value, (type, types.ClassType)) and +for name, value in six.iteritems(dict(globals())): + if (isinstance(value, (type, six.class_types)) and issubclass(value, HTTPException) and value.code): _exceptions[value.code] = value @@ -637,7 +638,7 @@ class HTTPExceptionHandler(object): []).append(HTTPException) try: return self.application(environ, start_response) - except HTTPException, exc: + except HTTPException as exc: return exc(environ, start_response) def middleware(*args, **kw): |