This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Missing 4 socket object properties
Type: enhancement Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: georg.brandl, georg.brandl, loewis, pysquared
Priority: normal Keywords:

Created on 2002-06-12 11:56 by pysquared, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
socket-attrs-2.diff georg.brandl, 2005-08-24 20:05 2nd version of patch
Messages (8)
msg53559 - (view) Author: Graham Horler (pysquared) Date: 2002-06-12 11:56
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.
msg53560 - (view) Author: Graham Horler (pysquared) Date: 2002-06-12 12:00
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!
msg53561 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2002-06-15 13:21
Logged In: YES 
user_id=21627

Sounds good. Would you like to produce a patch implementing
this feature?
msg53562 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-07-17 13:49
Logged In: YES 
user_id=1188172

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

Please review.
msg53563 - (view) Author: Graham Horler (pysquared) Date: 2005-07-20 14:47
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().
msg53564 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2005-08-24 15:24
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.
msg53565 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-08-24 20:05
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.
msg53566 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-03-17 19:17
Logged In: YES 
user_id=849994

Committed as rev. 43126.
History
Date User Action Args
2022-04-10 16:05:24adminsetgithub: 36734
2002-06-12 11:56:43pysquaredcreate