Skip to content

Commit 02cd1fa

Browse files
committed
Traitlets type handling fixup.
1 parent 1af8283 commit 02cd1fa

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

notebook/notebookapp.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ def _validate_ip(self, proposal):
787787
help=_("The UNIX socket the notebook server will listen on.")
788788
)
789789

790-
sock_mode = Integer(int('0600', 8), config=True,
790+
sock_mode = Unicode('0600', config=True,
791791
help=_("The permissions mode for UNIX socket creation (default: 0600).")
792792
)
793793

@@ -796,18 +796,22 @@ def _validate_sock_mode(self, proposal):
796796
value = proposal['value']
797797
try:
798798
converted_value = int(value.encode(), 8)
799-
# Ensure the mode is at least user readable/writable.
800799
assert all((
800+
# Ensure the mode is at least user readable/writable.
801801
bool(converted_value & stat.S_IRUSR),
802802
bool(converted_value & stat.S_IWUSR),
803+
# And isn't out of bounds.
804+
converted_value <= 2 ** 12
803805
))
804806
except ValueError:
805-
raise TraitError('invalid --sock-mode value: %s' % value)
807+
raise TraitError(
808+
'invalid --sock-mode value: %s, please specify as e.g. "0600"' % value
809+
)
806810
except AssertionError:
807811
raise TraitError(
808812
'invalid --sock-mode value: %s, must have u+rw (0600) at a minimum' % value
809813
)
810-
return converted_value
814+
return value
811815

812816
port_retries = Integer(50, config=True,
813817
help=_("The number of additional ports to try if the specified port is not available.")
@@ -1635,7 +1639,7 @@ def _bind_http_server(self):
16351639

16361640
def _bind_http_server_unix(self):
16371641
try:
1638-
sock = bind_unix_socket(self.sock, mode=self.sock_mode)
1642+
sock = bind_unix_socket(self.sock, mode=int(self.sock_mode.encode(), 8))
16391643
self.http_server.add_socket(sock)
16401644
except socket.error as e:
16411645
if e.errno == errno.EADDRINUSE:

notebook/tests/test_notebookapp_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_shutdown_sock_server_integration():
2323

2424
complete = False
2525
for line in iter(p.stderr.readline, b''):
26-
print(line)
26+
print(line.decode())
2727
if url in line:
2828
complete = True
2929
break

0 commit comments

Comments
 (0)