[Zope-Checkins] CVS: Zope/lib/python/ZPublisher - HTTPResponse.py:1.74

Fred L. Drake, Jr. fred@zope.com
Thu, 17 Apr 2003 13:41:58 -0400


Update of /cvs-repository/Zope/lib/python/ZPublisher
In directory cvs.zope.org:/tmp/cvs-serv26221

Modified Files:
	HTTPResponse.py 
Log Message:
- give all nearly-anonymous exceptions local names
- modernize several type-checks
- remove unused imports


=== Zope/lib/python/ZPublisher/HTTPResponse.py 1.73 => 1.74 ===
--- Zope/lib/python/ZPublisher/HTTPResponse.py:1.73	Tue Mar 18 16:39:06 2003
+++ Zope/lib/python/ZPublisher/HTTPResponse.py	Thu Apr 17 13:41:57 2003
@@ -18,13 +18,16 @@
 import types, os, sys, re
 import zlib, struct
 from string import translate, maketrans
-from types import StringType, InstanceType, LongType, UnicodeType
 from BaseResponse import BaseResponse
 from zExceptions import Unauthorized
 from zExceptions.ExceptionFormatter import format_exception
 
 nl2sp = maketrans('\n',' ')
 
+BadRequest = 'BadRequest'
+InternalError = 'InternalError'
+NotFound = 'NotFound'
+
 
 # Enable APPEND_TRACEBACKS to make Zope append tracebacks like it used to,
 # but a better solution is to make standard_error_message display error_tb.
@@ -212,7 +215,7 @@
             # It has already been determined.
             return
 
-        if type(status) is types.StringType:
+        if isinstance(status, str):
             status = status.lower()
         if status_codes.has_key(status):
             status = status_codes[status]
@@ -280,16 +283,16 @@
         if not body:
             return self
 
-        if type(body) is types.TupleType and len(body) == 2:
+        if isinstance(body, tuple) and len(body) == 2:
             title,body = body
 
-        if type(body) is not types.StringType:
+        if not isinstance(body, str):
             if hasattr(body,'asHTML'):
                 body = body.asHTML()
 
-        if type(body) is UnicodeType:
+        if isinstance(body, unicode):
             body = self._encode_unicode(body)
-        elif type(body) is StringType:
+        elif isinstance(body, str):
             pass
         else:
             try:
@@ -432,7 +435,7 @@
         If base is None, or the document already has a base, do nothing."""
         if base is None:
             base = ''
-        elif not base.endswith('/'):          
+        elif not base.endswith('/'):
             base = base+'/'
         self.base = str(base)
 
@@ -622,7 +625,7 @@
 
     def notFoundError(self,entry='Unknown'):
         self.setStatus(404)
-        raise 'NotFound',self._error_html(
+        raise NotFound, self._error_html(
             "Resource not found",
             "Sorry, the requested resource does not exist." +
             "<p>Check the URL and try again.</p>" +
@@ -632,7 +635,7 @@
                                     # why reveal that it exists?
 
     def debugError(self,entry):
-        raise 'NotFound',self._error_html(
+        raise NotFound, self._error_html(
             "Debugging Notice",
             "Zope has encountered a problem publishing your object.<p>"
             "\n%s" % entry)
@@ -640,11 +643,11 @@
     def badRequestError(self,name):
         self.setStatus(400)
         if re.match('^[A-Z_0-9]+$',name):
-            raise 'InternalError', self._error_html(
+            raise InternalError, self._error_html(
                 "Internal Error",
                 "Sorry, an internal error occurred in this resource.")
 
-        raise 'BadRequest',self._error_html(
+        raise BadRequest, self._error_html(
             "Invalid request",
             "The parameter, <em>%s</em>, " % name +
             "was omitted from the request.<p>" +
@@ -708,7 +711,7 @@
         del stb
         self.setStatus(t)
         if self.status >= 300 and self.status < 400:
-            if type(v) == types.StringType and absuri_match(v) is not None:
+            if isinstance(v, str) and absuri_match(v) is not None:
                 if self.status == 300:
                     self.setStatus(302)
                 self.setHeader('location', v)
@@ -717,7 +720,7 @@
             else:
                 try:
                     l, b = v
-                    if (type(l) == types.StringType
+                    if (isinstance(l, str)
                         and absuri_match(l) is not None):
                         if self.status == 300:
                             self.setStatus(302)