From: <am...@us...> - 2009-05-17 20:41:57
|
Revision: 6354 http://jython.svn.sourceforge.net/jython/?rev=6354&view=rev Author: amak Date: 2009-05-17 20:41:51 +0000 (Sun, 17 May 2009) Log Message: ----------- Improving error reporting for unsupported socket options. Modified Paths: -------------- trunk/jython/Lib/socket.py Modified: trunk/jython/Lib/socket.py =================================================================== --- trunk/jython/Lib/socket.py 2009-05-16 05:15:28 UTC (rev 6353) +++ trunk/jython/Lib/socket.py 2009-05-17 20:41:51 UTC (rev 6354) @@ -192,7 +192,7 @@ SO_SNDTIMEO = -512 SO_TYPE = -1024 SO_USELOOPBACK = -2048 - + __all__ = ['AF_UNSPEC', 'AF_INET', 'AF_INET6', 'AI_PASSIVE', 'SOCK_DGRAM', 'SOCK_RAW', 'SOCK_RDM', 'SOCK_SEQPACKET', 'SOCK_STREAM', 'SOL_SOCKET', 'SO_BROADCAST', 'SO_ERROR', 'SO_KEEPALIVE', 'SO_LINGER', 'SO_OOBINLINE', @@ -205,6 +205,16 @@ 'SHUT_RD', 'SHUT_WR', 'SHUT_RDWR', ] +def _constant_to_name(const_value): + sock_module = sys.modules['socket'] + try: + for name in dir(sock_module): + if getattr(sock_module, name) is const_value: + return name + return "Unknown" + finally: + sock_module = None + class _nio_impl: timeout = None @@ -235,7 +245,7 @@ return struct.pack('ii', enabled, linger_time) return result else: - raise error(errno.ENOPROTOOPT, "Level %d option not supported on socket(%s): %d" % (level, str(self.jsocket), option)) + raise error(errno.ENOPROTOOPT, "Socket option '%s' (level '%s') not supported on socket(%s)" % (_constant_to_name(option), _constant_to_name(level), str(self.jsocket))) def setsockopt(self, level, option, value): if self.options.has_key( (level, option) ): @@ -245,7 +255,7 @@ else: getattr(self.jsocket, "set%s" % self.options[ (level, option) ])(value) else: - raise error(errno.ENOPROTOOPT, "Level %d option not supported on socket(%s): %d" % (level, str(self.jsocket), option)) + raise error(errno.ENOPROTOOPT, "Socket option '%s' (level '%s') not supported on socket(%s)" % (_constant_to_name(option), _constant_to_name(level), str(self.jsocket))) def close(self): self.jsocket.close() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |