Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Batch 3] Porting Notebook PRs #98

Merged
merged 7 commits into from
Sep 25, 2019
8 changes: 4 additions & 4 deletions jupyter_server/files/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from base64 import decodebytes

from tornado import web
from tornado import gen, web

from jupyter_server.base.handlers import JupyterHandler

Expand Down Expand Up @@ -46,9 +46,9 @@ def get(self, path, include_body=True):
_, name = path.rsplit('/', 1)
else:
name = path

model = cm.get(path, type='file', content=include_body)

model = yield gen.maybe_future(cm.get(path, type='file', content=include_body))
if self.get_argument("download", False):
self.set_attachment_header(name)

Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/prometheus/log_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from notebook.prometheus.metrics import HTTP_REQUEST_DURATION_SECONDS
from jupyter_server.prometheus.metrics import HTTP_REQUEST_DURATION_SECONDS


def prometheus_log_method(handler):
Expand Down
12 changes: 10 additions & 2 deletions jupyter_server/serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,12 @@ def _token_changed(self, change):
@default('allow_remote_access')
def _default_allow_remote(self):
"""Disallow remote access if we're listening only on loopback addresses"""

# if blank, self.ip was configured to "*" meaning bind to all interfaces,
# see _valdate_ip
if self.ip == "":
return True

try:
addr = ipaddress.ip_address(self.ip)
except ValueError:
Expand Down Expand Up @@ -1330,14 +1336,16 @@ def display_url(self):
url += '/'
else:
if self.ip in ('', '0.0.0.0'):
ip = "(%s or 127.0.0.1)" % socket.gethostname()
ip = "%s" % socket.gethostname()
else:
ip = self.ip
url = self._url(ip)
if self.token:
# Don't log full token if it came from config
token = self.token if self._token_generated else '...'
url = url_concat(url, {'token': token})
url = (url_concat(url, {'token': token})
+ '\n or '
+ url_concat(self._url('127.0.0.1'), {'token': token}))
return url

@property
Expand Down
6 changes: 4 additions & 2 deletions jupyter_server/services/contents/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,12 @@ def post(self, path=''):

cm = self.contents_manager

if cm.file_exists(path):
file_exists = yield gen.maybe_future(cm.file_exists(path))
if file_exists:
raise web.HTTPError(400, "Cannot POST to files, use PUT instead.")

if not cm.dir_exists(path):
dir_exists = yield gen.maybe_future(cm.dir_exists(path))
if not dir_exists:
raise web.HTTPError(404, "No such directory: %s" % path)

model = self.get_json_body()
Expand Down
6 changes: 4 additions & 2 deletions jupyter_server/services/kernels/kernelmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from jupyter_server._tz import utcnow, isoformat
from ipython_genutils.py3compat import getcwd

from notebook.prometheus.metrics import KERNEL_CURRENTLY_RUNNING_TOTAL
from jupyter_server.prometheus.metrics import KERNEL_CURRENTLY_RUNNING_TOTAL


class MappingKernelManager(MultiKernelManager):
Expand Down Expand Up @@ -415,9 +415,11 @@ def record_activity(msg_list):
msg = session.deserialize(fed_msg_list)

msg_type = msg['header']['msg_type']
self.log.debug("activity on %s: %s", kernel_id, msg_type)
if msg_type == 'status':
kernel.execution_state = msg['content']['execution_state']
self.log.debug("activity on %s: %s (%s)", kernel_id, msg_type, kernel.execution_state)
else:
self.log.debug("activity on %s: %s", kernel_id, msg_type)

kernel._activity_stream.on_recv(record_activity)

Expand Down
3 changes: 3 additions & 0 deletions jupyter_server/terminal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def initialize(webapp, root_dir, connection_url, settings):
shell = settings.get('shell_command',
[os.environ.get('SHELL') or default_shell]
)
# Enable login mode - to automatically source the /etc/profile script
if os.name != 'nt':
shell.append('-l')
terminal_manager = webapp.settings['terminal_manager'] = NamedTermManager(
shell_command=shell,
extra_env={'JUPYTER_SERVER_ROOT': root_dir,
Expand Down