Handle python3's socket.SOCK_NONBLOCK more cleanly

Use the fact that python2 doesn't mix socket.SOCK_NONBLOCK in with
socket .type attributes to add a helper method that does the right
thing for both, and use it when reading back a socket's type.