[Python-Dev] Return error codes from getaddrinfo.

Alan Kennedy python-dev at xhaus.com
Thu Jun 28 09:59:37 CEST 2007


[Alan]
>>I want jython to use the same errno symbolic constants as cpython, to 
>>ease portability of code.

[Martin]
> That will be very difficult to achieve, as Python is (deliberately)
> not even consistent across systems. Instead, it reports what the
> platform reports, so you should do the same in Java.

I think I need to explain myself more clearly; I'm looking for the 
errno.SYMBOLIC_CONSTANT for errors returned by the getaddrinfo function.

Take the following lines from the cpython 2.5 httplib.

Line 998 - 1014
# -=-=-=-=-=-=
while True:
     try:
         buf = self._ssl.read(self._bufsize)
     except socket.sslerror, err:
         if (err[0] == socket.SSL_ERROR_WANT_READ
             or err[0] == socket.SSL_ERROR_WANT_WRITE):
             continue
         if (err[0] == socket.SSL_ERROR_ZERO_RETURN
             or err[0] == socket.SSL_ERROR_EOF):
             break
         raise
     except socket.error, err:
         if err[0] == errno.EINTR:
             continue
         if err[0] == errno.EBADF:
             # XXX socket was closed?
             break
         raise
# -=-=-=-=-=-=-=

How can that code work on jython, other than if

A: The jython errno module contains definitions for EINTR and EBADF
B: The socket module raises the exceptions with the correct 
errno.SYMBOLIC_CONSTANTS, in the same circumstances as the cpython module.

(The actual integers don't matter, but thanks anyway to the three 
separate people who informed me that googling "11001" was the solution 
to my problem).

And then there are the non-portable uses of error numbers, like this 
snippet from the 2.5 httplib:

Lines 706-711
#-=-=-=-=-=-=
     try:
         self.sock.sendall(str)
     except socket.error, v:
         if v[0] == 32:      # Broken pipe
             self.close()
         raise
#-=-=-=-=-=-=

Do these examples make it clearer why and in what way I want the jython 
errno symbolic constants to be the same as cpython?

Thanks,

Alan.


More information about the Python-Dev mailing list