Return error codes from getaddrinfo.
Dear all, I'm seeking enlightenment on the error codes returned by the socket.getaddrinfo() function. Consider the following on python 2.5 on Windows
import urllib urllib.urlopen("http://nonexistent") [snip traceback] IOError: [Errno socket error] (11001, 'getaddrinfo failed')
So the error number is 11001. But when I try to find a symbolic constant in the errno module corresponding to this error number, I can't find one.
import errno errno.errorcode[11] 'EAGAIN' errno.errorcode[11001] Traceback (most recent call last): File "<stdin>", line 1, in <module> KeyError: 11001
Looking through the C source for the socket module doesn't provide any clarity (although my C is a little rusty). That module has a special function, set_gaierror(), for handling error returns from getaddrinfo. But I can't see if or how the resulting error codes relate to the errno module. Is there supposed to be symbolic constants in the errno module corresponding to getaddrinfo errors? I want jython to use the same errno symbolic constants as cpython, to ease portability of code. Regards, Alan.
Is there supposed to be symbolic constants in the errno module corresponding to getaddrinfo errors?
No. On Windows, there is a separate set of error codes, winerror.h If you google for "winerror 11001", you find quickly that it is "host not found".
I want jython to use the same errno symbolic constants as cpython, to ease portability of code.
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. Regards, Martin
[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.
[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.
Do these examples make it clearer why and in what way I want the jython errno symbolic constants to be the same as cpython?
I fully understood that, already in your original message. All I was saying is that this will be very difficult to achieve. It would be much easier if you don't take the code of the standard library and the application as given, but instead accept that people may have to change the error conditions somewhat when porting to Jython. Ideally, such porting would allow to still run the same code on CPython, and ideally, you would then provide patches for the Python library to make it run unmodified on Jython (rather than trying to arrange to make the *current* library run unmodified). Regards, Martin
participants (2)
-
"Martin v. Löwis"
-
Alan Kennedy