type(socket) != SocketType
Irmen de Jong
irmen at NOSPAMREMOVETHISxs4all.nl
Sat Jun 15 23:10:37 CEST 2002
I have to detect if a certain socket object is a regular socket,
or a M2Crypto SSL socket. I do this by checking type(sock),
and then checking if this is a regular socket type. Why this way?
because the systems that run my code do not necessarily have
M2Crypto installed, and thus I cannot compare the socket to
any class/type from M2Crypto, nor just go ahead and catch SSL
exceptions (simply because they are not defined!).
There is a problem, however.
With Python 2.2.1 on Windows, type(socket) != SocketType:
>>> from socket import *
>>> type(s) is SocketTye
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'SocketTye' is not defined
>>> type(s) is SocketType
>>> type(s)== SocketType
I find this most unfortunate, because the docs on the socket module
explicitly state that type(socket)=SocketType.
BTW on Linux, all is fine.
Any clues how to fix things on windows?
Thanks a lot,
More information about the Python-list