type enforcement in _ssl.sslwrap

E

Eric Snow

ssl.SSLSocket.__init__ makes a call to _ssl.sslwrap (in the C
module). That in turn makes a call to PyArg_ParseTuple, which casts
the first arg of _ssl.sslwrap into a PySocketModule.Sock_Type
object.

My problem is that I am trying to pass in an object that implements
the Socket interface, but does not inherit from _socket.socket, like
you do with file-like objects. Is there a way to make this work, or
is the PyArg_ParseTuple call going to stop me. Would I need to have
_ssl.sslwrap do something differently with its args?

-eric
 
S

Steven D'Aprano

ssl.SSLSocket.__init__ makes a call to _ssl.sslwrap (in the C module).
That in turn makes a call to PyArg_ParseTuple, which casts the first arg
of _ssl.sslwrap into a PySocketModule.Sock_Type object.

My problem is that I am trying to pass in an object that implements the
Socket interface, but does not inherit from _socket.socket, like you do
with file-like objects. Is there a way to make this work, or is the
PyArg_ParseTuple call going to stop me.

I don't know. What happens when you try it?
 
E

Eric Snow

I don't know. What happens when you try it?

When I pass my socket object in to ssl.wrap_socket I get the following
exception:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
...
File "/usr/local/lib/python2.7/ssl.py", line 342, in wrap_socket
ciphers=ciphers)
File "/usr/local/lib/python2.7/ssl.py", line 119, in __init__
ciphers)
TypeError: must be _socket.socket, not ClientSocket

I looked at what is going on there and found the call to
_ssl.sslwrap. I tracked it down in the C source and found the call to
PyArg_ParseTuple.

-eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top