From: Eric Snow on
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
From: Steven D'Aprano on
On Tue, 10 Aug 2010 10:40:54 -0700, Eric Snow wrote:

> 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?




--
Steven
From: Eric Snow on
On Aug 11, 5:34 am, Steven D'Aprano <st...(a)REMOVE-THIS-
cybersource.com.au> wrote:
> On Tue, 10 Aug 2010 10:40:54 -0700, Eric Snow wrote:
> > 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?
>
> --
> Steven

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