(original) (raw)
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 <victor.stinner@gmail.com> wrote:
2013/8/21 Victor Stinner <victor.stinner@gmail.com>:
> Should I add a portable helper to theAdd the two following functions to the socket module:
\> socket module (socket.get/set\_inheritable)?
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)
Add the two following methods to the socket class:
\> Or add 2 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
Python-Dev@python.org
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)