Message9549

Author jfroco
Recipients jfroco
Date 2015-02-23.02:56:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1424660183.18.0.261643241945.issue2273@psf.upfronthosting.co.za>
In-reply-to
Content
import socket
w = socket.socket()

Per definition socket(family=None, type=None, proto=None)

As type=None, next call is: return _socketobject(None, None, None)

_socketobject:
def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, _sock=None):

As type=None this is the value it will get, not the default value. 

>>> def a(b=1):
...     print b
...
>>> a(b=10)
10
>>> a()
1
>>> a(b=None)
None

So, type is still None when calling _realsocket, so self.proto = None


This causes w.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) to fail, as self.proto = None

Quick fix:

    def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, _sock=None):
        print "_socketobject: type %s" % type
        if not type:
            type = SOCK_STREAM
        if _sock is None:
            _sock = _realsocket(family, type, proto)
        self._sock = _sock
        for method in _delegate_methods:
            setattr(self, method, getattr(_sock, method))
History
Date User Action Args
2015-02-23 02:56:23jfrocosetrecipients: + jfroco
2015-02-23 02:56:23jfrocosetmessageid: <1424660183.18.0.261643241945.issue2273@psf.upfronthosting.co.za>
2015-02-23 02:56:23jfrocolinkissue2273 messages
2015-02-23 02:56:22jfrococreate