From 5bcd54d313af1be6856e50a830a3f6c713d3576d 2014-12-27 23:11:42 From: Min RK Date: 2014-12-27 23:11:42 Subject: [PATCH] make FilesRedirectHandler redirect logic accessible from a static method instead of calling FRH.get(self), which doesn't work on Python 2 due to unbound method class checking. --- diff --git a/IPython/html/base/handlers.py b/IPython/html/base/handlers.py index eb2a7a7..618e218 100644 --- a/IPython/html/base/handlers.py +++ b/IPython/html/base/handlers.py @@ -464,7 +464,13 @@ class TrailingSlashHandler(web.RequestHandler): class FilesRedirectHandler(IPythonHandler): """Handler for redirecting relative URLs to the /files/ handler""" - def get(self, path=''): + + @staticmethod + def redirect_to_files(self, path): + """make redirect logic a reusable static method + + so it can be called from other handlers. + """ cm = self.contents_manager if cm.dir_exists(path): # it's a *directory*, redirect to /tree @@ -488,6 +494,9 @@ class FilesRedirectHandler(IPythonHandler): url = url_escape(url) self.log.debug("Redirecting %s to %s", self.request.path, url) self.redirect(url) + + def get(self, path=''): + return self.redirect_to_files(self, path) #----------------------------------------------------------------------------- diff --git a/IPython/html/notebook/handlers.py b/IPython/html/notebook/handlers.py index 1725b83..08ae98b 100644 --- a/IPython/html/notebook/handlers.py +++ b/IPython/html/notebook/handlers.py @@ -28,12 +28,12 @@ class NotebookHandler(IPythonHandler): except web.HTTPError as e: if e.status_code == 404 and 'files' in path.split('/'): # 404, but '/files/' in URL, let FilesRedirect take care of it - return FilesRedirectHandler.get(self, path) + return FilesRedirectHandler.redirect_to_files(self, path) else: raise if model['type'] != 'notebook': # not a notebook, redirect to files - return FilesRedirectHandler.get(self, path) + return FilesRedirectHandler.redirect_to_files(self, path) name = url_escape(path.rsplit('/', 1)[-1]) path = url_escape(path) self.write(self.render_template('notebook.html',