< a/s/l
Hamentashen >

[Comments] (3) Socket Question: Okay, here's something interesting. Python's socket documentation for the socket.shutdown method mentions three constants: SHUT_RD, SHUT_WR, and SHUT_RDWR. However, nowhere I can find does Python actually define these constants. It's obvious what they are because they're ripped off from C/Unix constants of the same names, and those always start numbered from zero. But it seems really weird that the socket library would forget to define these constants even though it defines a million other constants. Am I missing someplace where those constants are defined?

Filed under:

Comments:

Posted by Fredrik at Fri Mar 25 2005 01:29

"Am I missing someplace where those constants are defined?"

Python 2.4.

Posted by Leonard at Fri Mar 25 2005 01:36

I walked right into that one. Did they just forget to put them into the previous versions?

Posted by Fredrik at Fri Mar 25 2005 01:57

The "how" values have always been documented to be 0, 1, and 2, since the early days of sockets. Using constants is a new thing, and the exact names vary between different platforms. The SHUT names used in Python are taken from the Open Group Unix specs; the Windows API uses different names, which is why you'll find this in the Python source code:

#ifdef SHUT_RD
PyModule_AddIntConstant(m, "SHUT_RD", SHUT_RD);
#elif defined(SD_RECEIVE)
PyModule_AddIntConstant(m, "SHUT_RD", SD_RECEIVE);
#else
PyModule_AddIntConstant(m, "SHUT_RD", 0);
#endif



[Main] [Edit]

Unless otherwise noted, all content licensed by Leonard Richardson
under a Creative Commons License.