Skip to content

Fix bug in comm based server side validation, #319

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

Merged
merged 1 commit into from
Jan 15, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions ipywidgets/widgets/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from contextlib import contextmanager
import collections
import sys

from IPython.core.getipython import get_ipython
from ipykernel.comm import Comm
Expand Down Expand Up @@ -461,16 +462,20 @@ def _trait_from_json(x, self):

def _ipython_display_(self, **kwargs):
"""Called when `IPython.display.display` is called on the widget."""
def loud_error(message):
self.log.warn(message)
sys.stderr.write('%s\n' % message)

# Show view.
if self._view_name is not None:
validated = validate_version()
validated = Widget._version_validated

# Before the user tries to display a widget. Validate that the
# widget front-end is what is expected.
if validated is None:
self.log.warn('Widget Javascript not detected. It may not be installed properly.')
loud_error('Widget Javascript not detected. It may not be installed properly.')
elif not validated:
self.log.warn('The installed widget Javascript is the wrong version.')
loud_error('The installed widget Javascript is the wrong version.')

self._send({"method": "display"})
self._handle_displayed(**kwargs)
Expand All @@ -480,14 +485,11 @@ def _send(self, msg, buffers=None):
self.comm.send(data=msg, buffers=buffers)


_version_validated = None
Widget._version_validated = None
def handle_version_comm_opened(comm, msg):
"""Called when version comm is opened, because the front-end wants to
validate the version."""
def handle_version_message(msg):
_version_validated = msg['content']['data']['validated']
Widget._version_validated = msg['content']['data']['validated']
comm.on_msg(handle_version_message)
comm.send({'version': '4.1.0dev'})

def validate_version():
return _version_validated