From 02cd1fa8a00a97f531845ad7533aaf25130a8772 Mon Sep 17 00:00:00 2001 From: Kris Wilson Date: Wed, 13 May 2020 00:34:23 -0700 Subject: [PATCH] Traitlets type handling fixup. --- notebook/notebookapp.py | 14 +++++++++----- notebook/tests/test_notebookapp_integration.py | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/notebook/notebookapp.py b/notebook/notebookapp.py index 87ba0ee9f..62f0e7658 100755 --- a/notebook/notebookapp.py +++ b/notebook/notebookapp.py @@ -787,7 +787,7 @@ class NotebookApp(JupyterApp): help=_("The UNIX socket the notebook server will listen on.") ) - sock_mode = Integer(int('0600', 8), config=True, + sock_mode = Unicode('0600', config=True, help=_("The permissions mode for UNIX socket creation (default: 0600).") ) @@ -796,18 +796,22 @@ class NotebookApp(JupyterApp): value = proposal['value'] try: converted_value = int(value.encode(), 8) - # Ensure the mode is at least user readable/writable. assert all(( + # Ensure the mode is at least user readable/writable. bool(converted_value & stat.S_IRUSR), bool(converted_value & stat.S_IWUSR), + # And isn't out of bounds. + converted_value <= 2 ** 12 )) except ValueError: - raise TraitError('invalid --sock-mode value: %s' % value) + raise TraitError( + 'invalid --sock-mode value: %s, please specify as e.g. "0600"' % value + ) except AssertionError: raise TraitError( 'invalid --sock-mode value: %s, must have u+rw (0600) at a minimum' % value ) - return converted_value + return value port_retries = Integer(50, config=True, help=_("The number of additional ports to try if the specified port is not available.") @@ -1635,7 +1639,7 @@ class NotebookApp(JupyterApp): def _bind_http_server_unix(self): try: - sock = bind_unix_socket(self.sock, mode=self.sock_mode) + sock = bind_unix_socket(self.sock, mode=int(self.sock_mode.encode(), 8)) self.http_server.add_socket(sock) except socket.error as e: if e.errno == errno.EADDRINUSE: diff --git a/notebook/tests/test_notebookapp_integration.py b/notebook/tests/test_notebookapp_integration.py index 3a5b6b2bf..1ae7e3536 100644 --- a/notebook/tests/test_notebookapp_integration.py +++ b/notebook/tests/test_notebookapp_integration.py @@ -23,7 +23,7 @@ def test_shutdown_sock_server_integration(): complete = False for line in iter(p.stderr.readline, b''): - print(line) + print(line.decode()) if url in line: complete = True break