type(socket) != SocketType
Irmen de Jong
irmen at NOSPAMREMOVETHISxs4all.nl
Sat Jun 15 17:10:37 EDT 2002
Hello
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 *
>>> s=socket(AF_INET,SOCK_STREAM)
>>> type(s)
<type 'instance'>
>>> SocketType
<type '_socket.socket'>
>>> type(s) is SocketTye
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'SocketTye' is not defined
>>> type(s) is SocketType
0
>>> type(s)== SocketType
0
>>>
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,
Irmen
More information about the Python-list
mailing list