|
9 | 9 | import base64 |
10 | 10 | import datetime |
11 | 11 | import errno |
12 | | -import imp |
13 | 12 | import importlib |
14 | 13 | import io |
15 | 14 | import json |
|
99 | 98 | ipython notebook --profile=sympy # use the sympy profile |
100 | 99 | ipython notebook --certfile=mycert.pem # use SSL/TLS certificate |
101 | 100 | """ |
102 | | -DEPRECATED_WIDGET_WARNING = """ |
103 | | -console.warn("/static/widgets/js/ is deprecated, import from nbextensions/widgets/widgets/js/ instead."); |
104 | | -""" |
105 | | -MISSING_WIDGET_ERROR = """ |
106 | | -throw new Error('Python package `ipython_widgets` not installed. Please install it on the host.'); |
107 | | -""" |
108 | 101 |
|
109 | 102 | #----------------------------------------------------------------------------- |
110 | 103 | # Helper functions |
@@ -221,7 +214,7 @@ def init_handlers(self, settings): |
221 | 214 |
|
222 | 215 | # Order matters. The first handler to match the URL will handle the request. |
223 | 216 | handlers = [] |
224 | | - handlers.extend(self._create_widget_shim_handlers()) |
| 217 | + handlers.extend(self._create_widget_shim_handlers(settings)) |
225 | 218 | handlers.extend(load_handlers('tree.handlers')) |
226 | 219 | handlers.extend([(r"/login", settings['login_handler_class'])]) |
227 | 220 | handlers.extend([(r"/logout", settings['logout_handler_class'])]) |
@@ -270,43 +263,21 @@ def init_handlers(self, settings): |
270 | 263 | new_handlers.append((r'(.*)', Template404)) |
271 | 264 | return new_handlers |
272 | 265 |
|
273 | | - def _create_widget_shim_handlers(self): |
| 266 | + def _create_widget_shim_handlers(self, settings): |
274 | 267 | """Creates a handler that shims the loading of widgets |
275 | 268 | JS files for the old /static/widgets/js/*.js path.""" |
276 | | - # Add RESTful shim for the ipython_widgets |
277 | | - try: |
278 | | - ipythonwidgets = imp.find_module('ipython_widgets')[1] |
279 | | - widget_js = os.path.join(ipythonwidgets, 'static', 'widgets') |
280 | | - |
281 | | - class DeprecationHandler(IPythonHandler): |
282 | | - def get(self, url_path): |
283 | | - self.set_header("Content-Type", 'text/javascript') |
284 | | - |
285 | | - # Verify that the file requested exists. |
286 | | - local_file = os.path.join(widget_js, *url_path.split('/')) |
287 | | - if not os.path.isfile(local_file): |
288 | | - self.set_status(404) |
289 | | - self.finish("File doesn't exits") |
290 | | - |
291 | | - # Read the file and append the warning. |
292 | | - with open(local_file, 'r') as f: |
293 | | - contents = f.read() |
294 | | - self.finish(DEPRECATED_WIDGET_WARNING + contents) |
295 | | - self.log.warn('Deprecated widget Javascript path /static/widgets/js/*.js was used') |
296 | | - return [( |
297 | | - r'/deprecatedwidgets/(.*)', |
298 | | - DeprecationHandler |
299 | | - )] |
300 | | - except: # ipython_widgets is not installed |
301 | | - class ErrorHandler(IPythonHandler): |
302 | | - def get(self, *args, **kwargs): |
303 | | - self.set_header("Content-Type", 'text/javascript') |
304 | | - self.finish(MISSING_WIDGET_ERROR) |
305 | | - self.log.warn("Attempt to import widget javascript failed, `ipython_widgets` is not installed") |
306 | | - return [( |
307 | | - r'/deprecatedwidgets/(.*)', |
308 | | - ErrorHandler |
309 | | - )] |
| 269 | + class DeprecationHandler(IPythonHandler): |
| 270 | + def get(self, url_path): |
| 271 | + self.set_header("Content-Type", 'text/javascript') |
| 272 | + self.finish(""" |
| 273 | + console.warn('`/static/widgets/js` is deprecated. Use `/nbextensions/widgets/widgets/js` instead.'); |
| 274 | + define(['%s'], function(x) { console.log('...loaded...'); return x; }); |
| 275 | + """ % url_path_join(settings['base_url'], 'nbextensions', 'widgets', 'widgets', url_path)) |
| 276 | + self.log.warn('Deprecated widget Javascript path /static/widgets/js/*.js was used') |
| 277 | + return [( |
| 278 | + r'/deprecatedwidgets/(.*)', |
| 279 | + DeprecationHandler |
| 280 | + )] |
310 | 281 |
|
311 | 282 |
|
312 | 283 | class NbserverListApp(JupyterApp): |
|
0 commit comments