Feature Requests item #567972, was opened at 2002-06-12 11:56 Message generated for change (Comment added) made by gbrandl 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: Closed >Resolution: Accepted Priority: 5 Submitted By: Graham Horler (grahamh) >Assigned to: Georg Brandl (gbrandl) 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: Georg Brandl (gbrandl) Date: 2006-03-17 19:17 Message: Logged In: YES user_id=849994 Committed as rev. 43126. ---------------------------------------------------------------------- Comment By: Georg Brandl (birkenfeld) Date: 2005-08-24 20:05 Message: Logged In: YES user_id=1188172 Attaching new patch. Following changes: - getfamily(), gettype(), getproto() functions of _socketobject which map to - family, type, proto members of socket._sock - timeout member of socket._sock - documentation update - test suite update Please review. ---------------------------------------------------------------------- Comment By: Martin v. Löwis (loewis) Date: 2005-08-24 15:24 Message: Logged In: YES user_id=21627 grahamh, I take it that your answer to the question "would you like to implement a patch?", is "no". I agree with parts of the review: these things should be added to the _socketobject. Also, socket objects have one more attribute, sock_timeout, which might be worth exposing. I also wonder what style of API should be used. All other state access goes through get-methods(), which all start with get except for fileno(). Adding properties would introduce another API style, so -1. As for blocking: this sounds like a different feature request, as this is not a member of struct PySocketSockObject. So I would close this request as soon as the three attributes are implemented; if you then still want the getblocking() method, you should write another feature request. In addition, this patch lacks documentation and test suite changes. Unassigning myself, as I won't take any further action for the moment. ---------------------------------------------------------------------- Comment By: Graham Horler (grahamh) Date: 2005-07-20 14: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: Georg Brandl (birkenfeld) Date: 2005-07-17 13: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 13: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 12: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 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com