[Python-bugs-list] [ python-Bugs-531145 ] socket.sslerror is not a socket.error

SourceForge.net noreply@sourceforge.net
Tue, 04 Feb 2003 08:19:26 -0800


Bugs item #531145, was opened at 2002-03-17 23:14
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=531145&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Bastian Kleineidam (calvin)
Assigned to: Nobody/Anonymous (nobody)
Summary: socket.sslerror is not a socket.error

Initial Comment:
Python 2.1.2 (#1, Mar 16 2002, 00:56:55) 
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "copyright", "credits" or "license" for more
information.
>>> import socket
>>> socket.sslerror
<class socket.sslerror at 0x809c39c>
>>> try: raise socket.sslerror
... except socket.error: pass
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
socket.sslerror
>>> 


----------------------------------------------------------------------

Comment By: Michael Stone (mbrierst)
Date: 2003-02-04 16:19

Message:
Logged In: YES 
user_id=670441

If this behavior is desired, the patch below implements it.  If it's not desired, this bug sould be closed.

It isn't much work at all.  test_socket and test_socket_ssl still pass fine.  The following case will work after this patch, all other combinations will work as before:

>>> try: raise socket.sslerror
... except socket.error: print 'caught'
caught
>>>

patch (I cannot attach the file in sourceforge for some reason):
Index: dist/src/Modules/socketmodule.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.h,v
retrieving revision 1.8
diff -c -r1.8 socketmodule.h
*** dist/src/Modules/socketmodule.h	13 Jun 2002 15:07:44 -0000	1.8
--- dist/src/Modules/socketmodule.h	4 Feb 2003 16:05:27 -0000
***************
*** 140,145 ****
--- 140,146 ----
  /* C API for usage by other Python modules */
  typedef struct {
  	PyTypeObject *Sock_Type;
+         PyObject *Sock_Error;
  } PySocketModule_APIObject;
  
  /* XXX The net effect of the following appears to be to define a function
Index: dist/src/Modules/socketmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.c,v
retrieving revision 1.251
diff -c -r1.251 socketmodule.c
*** dist/src/Modules/socketmodule.c	6 Jan 2003 12:41:26 -0000	1.251
--- dist/src/Modules/socketmodule.c	4 Feb 2003 16:05:43 -0000
***************
*** 3117,3122 ****
--- 3117,3123 ----
  PySocketModule_APIObject PySocketModuleAPI =
  {
  	&sock_type,
+         NULL,
  };
  
  
***************
*** 3178,3183 ****
--- 3179,3185 ----
  		return;
  
  	/* Export C API */
+         PySocketModuleAPI.Sock_Error = socket_error;
  	if (PyModule_AddObject(m, PySocket_CAPI_NAME,
  	       PyCObject_FromVoidPtr((void *)&PySocketModuleAPI, NULL)
  				 ) != 0)
Index: dist/src/Modules/_ssl.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_ssl.c,v
retrieving revision 1.9
diff -c -r1.9 _ssl.c
*** dist/src/Modules/_ssl.c	27 Jan 2003 22:19:21 -0000	1.9
--- dist/src/Modules/_ssl.c	4 Feb 2003 16:05:45 -0000
***************
*** 543,549 ****
  	SSLeay_add_ssl_algorithms();
  
  	/* Add symbols to module dict */
! 	PySSLErrorObject = PyErr_NewException("socket.sslerror", NULL, NULL);
  	if (PySSLErrorObject == NULL)
  		return;
  	PyDict_SetItemString(d, "sslerror", PySSLErrorObject);
--- 543,549 ----
  	SSLeay_add_ssl_algorithms();
  
  	/* Add symbols to module dict */
! 	PySSLErrorObject = PyErr_NewException("socket.sslerror", PySocketModule.Sock_Error, NULL);
  	if (PySSLErrorObject == NULL)
  		return;
  	PyDict_SetItemString(d, "sslerror", PySSLErrorObject);


----------------------------------------------------------------------

Comment By: Bastian Kleineidam (calvin)
Date: 2002-11-11 17:12

Message:
Logged In: YES 
user_id=9205

Yes, I want socket.sslerror to be a subclass of
socket.error. It simplifies code layout (see my previous
answer) and it follows the documentation.
And yes, its work, but only a little :)

----------------------------------------------------------------------

Comment By: Gerhard Häring (ghaering)
Date: 2002-10-05 00:05

Message:
Logged In: YES 
user_id=163326

So do you propose to make socket.sslerror a subclass of
socket.error. Is this desirable? I'm not sure. Is it work? Yes.

----------------------------------------------------------------------

Comment By: Bastian Kleineidam (calvin)
Date: 2002-03-18 20:23

Message:
Logged In: YES 
user_id=9205

The documentation says for socket.error: "This exception is
raised for socket- or address-related errors." I think
socket.sslerror is such an error, because then you can write

try: sock.write("") # could be ssl-socket
except socket.error: pass

The other way would be
_exceptions = [socket.error]
if hasattr(socket, "sslerror"):
    _exceptions.append(socket.sslerror)
try: sock.write("")
except _exceptions: pass

Anyway, I assume this is a minor "bug".

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2002-03-18 10:44

Message:
Logged In: YES 
user_id=21627

Why is this a bug?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=531145&group_id=5470