Since this is a new API and only applies to sockets, making them methods
sounds good. (I'd put the 'nt' test outside the method defs though so they
are tested only once per import.)


On Tue, Aug 20, 2013 at 4:57 PM, Victor Stinner <[email protected]>wrote:

> 2013/8/21 Victor Stinner <[email protected]>:
> > Should I add a portable helper to the
> > socket module (socket.get/set_inheritable)?
>
> Add the two following functions to the socket module:
>
> def get_inheritable(sock):
>     if os.name == 'nt':
>         return os.get_handle_inheritable(sock.fileno())
>     else:
>         return os.get_inheritable(sock.fileno())
>
> def set_inheritable(sock, inheritable):
>     if os.name == 'nt':
>         os.set_handle_inheritable(sock.fileno(), inheritable)
>     else:
>         os.set_inheritable(sock.fileno(), inheritable)
>
> Usage: socket.get_inheritable(sock) and socket.set_inheritable(sock, True)
>
> > Or add 2 methods to the socket class?
>
> Add the two following methods to the socket class:
>
>     def get_inheritable(self):
>         if os.name == 'nt':
>             return os.get_handle_inheritable(self.fileno())
>         else:
>             return os.get_inheritable(self.fileno())
>
>     def set_inheritable(self, inheritable):
>         if os.name == 'nt':
>             os.set_handle_inheritable(self.fileno(), inheritable)
>         else:
>             os.set_inheritable(self.fileno(), inheritable)
>
> Usage: s.get_inheritable() and sock.set_inheritable(True)
>
> Victor
> _______________________________________________
> Python-Dev mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> http://mail.python.org/mailman/options/python-dev/guido%40python.org
>



-- 
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to