[Zope-dev] Re: Zope2 porting..module Zope2
Tres Seaver
tseaver at palladion.com
Mon Jun 9 00:11:30 EDT 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
ranjith kannikara wrote:
> During the porting of Zope2 to python2.5 We are now porting the
> module Zope2 which was having 4
> failures and 1 error. All of these were due to the change in the
> hierarchy of exception classes. The failures were arised due to the
> failure of the function 'SetStatus' in / **
> /lib/python/ZPublisher/HTTPResponse.py to set the status. In the above
> function there is one checking
> if( isinstance(status, types.ClassType) and issubclass(status, Exception)):
> status = status.__name__ #status is being set here..
>
> in which status is actually the zException class and it is new style
> class in python2.5 , therefore this condition always fails and the
> status is set to arbitrary value 500.
> We tried removing this first condition ( ie using
> if(issubclass(status, types.ClassType ) ) and it didn't show any new
> failures or errors in either python2.4 or 2.5 . And the 4 failures
> also got vanished. We tried to make out the significance of that first
> checking but couldn't.
>
> What is the significance of this checking ? ( so that the code can be
> edited to adopt the
> checking in someother way for python2.5 )
> Or Can it be just avoided?
Just to clarify, are you proposing the following patch?
- --- lib/python/ZPublisher/HTTPResponse.py (revision 87245)
+++ lib/python/ZPublisher/HTTPResponse.py (working copy)
@@ -217,8 +217,7 @@
# It has already been determined.
return
- - if (isinstance(status, types.ClassType)
- - and issubclass(status, Exception)):
+ if issubclass(status, Exception):
status = status.__name__
if isinstance(status, str):
@@ -722,8 +721,9 @@
else:
t, v, tb = sys.exc_info()
- - if t == 'Unauthorized' or t == Unauthorized or (
- - isinstance(t, types.ClassType) and issubclass(t,
Unauthorized)):
+ if (t == 'Unauthorized' or
+ t == Unauthorized or
+ issubclass(t, Unauthorized)):
t = 'Unauthorized'
self._unauthorized()
If so, -1: that pattern landed initially in a commit in early 2001, and
is due to the fact that the 'issubclass' test blows up when used on a
non-class type. An alternative patch allows for both new and old-style
classes::
- --- lib/python/ZPublisher/HTTPResponse.py (revision 87245)
+++ lib/python/ZPublisher/HTTPResponse.py (working copy)
@@ -217,7 +217,7 @@
# It has already been determined.
return
- - if (isinstance(status, types.ClassType)
+ if (isinstance(status, (type, types.ClassType))
and issubclass(status, Exception)):
status = status.__name__
@@ -723,7 +723,8 @@
t, v, tb = sys.exc_info()
if t == 'Unauthorized' or t == Unauthorized or (
- - isinstance(t, types.ClassType) and issubclass(t,
Unauthorized)):
+ isinstance(t, (type, types.ClassType)) and
+ issubclass(t, Unauthorized)):
t = 'Unauthorized'
self._unauthorized()
Tres.
- --
===================================================================
Tres Seaver +1 540-429-0999 tseaver at palladion.com
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFITK1y+gerLs4ltQ4RAoq+AKCy51L4n3PrhsSYPSOkEFgk/hEBNwCgzRO/
2u74sy1iRBS2+kkHQ3c7tSQ=
=sJ60
-----END PGP SIGNATURE-----
More information about the Zope-Dev
mailing list