[ python-Feature Requests-567972 ] Missing 4 socket object properties

SourceForge.net noreply at sourceforge.net
Wed Jul 20 16:47:13 CEST 2005


Feature Requests item #567972, was opened at 2002-06-12 12:56
Message generated for change (Comment added) made by grahamh
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=567972&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 7
Submitted By: Graham Horler (grahamh)
Assigned to: Martin v. Löwis (loewis)
Summary: Missing 4 socket object properties

Initial Comment:
The C socketmodule has a struct PySocketSockObject, 
with family, type and proto members.

These would be terribly helpful to have access to in 
Python, when implementing some generic socket helper 
functions.

The "blocking" flag could also be made available, but 
would require some extra coding.

(I'm using Python 2.1.3 under Linux 2.4.16, so I cannot 
extend the socket class itself ((as in py2.2)), and don't 
want to slow down sockets with a complete wrapper, as I 
use them heavily.)

Thanks, Graham.

----------------------------------------------------------------------

>Comment By: Graham Horler (grahamh)
Date: 2005-07-20 15:47

Message:
Logged In: YES 
user_id=543663

The patch applies, compiles, runs OK for me (thanks).

However it does not add access to the blocking flag.
Under Linux I can go:
    fcntl.fcntl(fd, fcntl.F_GETFL) & os.O_NDELAY != 0
But this is not portable, and is probably repeating code.

Also the 3 added members are not available from an instance
of the _socketobject wrapper, you have to go
mysock._sock.family.
(The _socketobject wrapper in socket.py is a little bizarre
IMVHO.)
Perhaps they could be added using instances of property().


----------------------------------------------------------------------

Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-07-17 14:49

Message:
Logged In: YES 
user_id=1188172

Attaching a patch which implements the three members of
_socket.socket.

Please review.

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2002-06-15 14:21

Message:
Logged In: YES 
user_id=21627

Sounds good. Would you like to produce a patch implementing
this feature?

----------------------------------------------------------------------

Comment By: Graham Horler (grahamh)
Date: 2002-06-12 13:00

Message:
Logged In: YES 
user_id=543663

Oh yes, the repr of a socket object includes the missing info, 
so to get hold of the family, I go:
  int(repr(sock).split(' ')[3].split('=')[1][:-1])

Similar for type and protocol, not nice!


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=567972&group_id=5470


More information about the Python-bugs-list mailing list