diff --git a/IPython/html/base/handlers.py b/IPython/html/base/handlers.py index e9b9c85..8d67501 100644 --- a/IPython/html/base/handlers.py +++ b/IPython/html/base/handlers.py @@ -299,7 +299,7 @@ class AuthenticatedFileHandler(IPythonHandler, web.StaticFileHandler): or the UF_HIDDEN flag as reported by stat """ inside_root = absolute_path[len(absolute_root):] - if any(part.startswith('.') for part in inside_root.split(os.path.sep)): + if any(part.startswith('.') for part in inside_root.split(os.sep)): raise web.HTTPError(403) # check UF_HIDDEN on any location up to root @@ -367,7 +367,7 @@ class FileFindHandler(web.StaticFileHandler): if isinstance(path, basestring): path = [path] self.roots = tuple( - os.path.abspath(os.path.expanduser(p)) + os.path.sep for p in path + os.path.abspath(os.path.expanduser(p)) + os.sep for p in path ) self.default_filename = default_filename @@ -385,7 +385,7 @@ class FileFindHandler(web.StaticFileHandler): # os.path.abspath strips a trailing / # it needs to be temporarily added back for requests to root/ - if not (abspath + os.path.sep).startswith(roots): + if not (abspath + os.sep).startswith(roots): raise HTTPError(403, "%s is not in root static directory", path) cls._static_paths[path] = abspath @@ -470,7 +470,7 @@ class FileFindHandler(web.StaticFileHandler): if isinstance(static_paths, basestring): static_paths = [static_paths] roots = tuple( - os.path.abspath(os.path.expanduser(p)) + os.path.sep for p in static_paths + os.path.abspath(os.path.expanduser(p)) + os.sep for p in static_paths ) try: @@ -504,8 +504,8 @@ class FileFindHandler(web.StaticFileHandler): ``static_url_prefix`` removed. The return value should be filesystem path relative to ``static_path``. """ - if os.path.sep != "/": - url_path = url_path.replace("/", os.path.sep) + if os.sep != "/": + url_path = url_path.replace("/", os.sep) return url_path class TrailingSlashHandler(web.RequestHandler): diff --git a/IPython/html/services/notebooks/tests/test_notebooks_api.py b/IPython/html/services/notebooks/tests/test_notebooks_api.py index c75903a..33238bc 100644 --- a/IPython/html/services/notebooks/tests/test_notebooks_api.py +++ b/IPython/html/services/notebooks/tests/test_notebooks_api.py @@ -102,12 +102,12 @@ class APITest(NotebookTestBase): nbdir = self.notebook_dir.name for d in self.dirs: - d.replace('/', os.path.sep) + d.replace('/', os.sep) if not os.path.isdir(pjoin(nbdir, d)): os.mkdir(pjoin(nbdir, d)) for d, name in self.dirs_nbs: - d = d.replace('/', os.path.sep) + d = d.replace('/', os.sep) with io.open(pjoin(nbdir, d, '%s.ipynb' % name), 'w') as f: nb = new_notebook(name=name) write(nb, f, format='ipynb') @@ -172,7 +172,7 @@ class APITest(NotebookTestBase): self.assertEqual(resp.json()['name'], name) assert os.path.isfile(pjoin( self.notebook_dir.name, - path.replace('/', os.path.sep), + path.replace('/', os.sep), name, )) diff --git a/IPython/html/tests/test_files.py b/IPython/html/tests/test_files.py index cdc3cc1..78de40c 100644 --- a/IPython/html/tests/test_files.py +++ b/IPython/html/tests/test_files.py @@ -27,7 +27,7 @@ class FilesTest(NotebookTestBase): nbdir = self.notebook_dir.name for d in dirs: - path = pjoin(nbdir, d.replace('/', os.path.sep)) + path = pjoin(nbdir, d.replace('/', os.sep)) if not os.path.exists(path): os.mkdir(path) with open(pjoin(path, 'foo'), 'w') as f: @@ -37,7 +37,7 @@ class FilesTest(NotebookTestBase): url = self.base_url() for d in not_hidden: - path = pjoin(nbdir, d.replace('/', os.path.sep)) + path = pjoin(nbdir, d.replace('/', os.sep)) r = requests.get(url_path_join(url, 'files', d, 'foo')) r.raise_for_status() self.assertEqual(r.content, b'foo') @@ -45,7 +45,7 @@ class FilesTest(NotebookTestBase): self.assertEqual(r.status_code, 403) for d in hidden: - path = pjoin(nbdir, d.replace('/', os.path.sep)) + path = pjoin(nbdir, d.replace('/', os.sep)) for foo in ('foo', '.foo'): r = requests.get(url_path_join(url, 'files', d, foo)) self.assertEqual(r.status_code, 403) diff --git a/IPython/html/utils.py b/IPython/html/utils.py index 18a7941..7748de9 100644 --- a/IPython/html/utils.py +++ b/IPython/html/utils.py @@ -38,7 +38,7 @@ def url_path_join(*pieces): def path2url(path): """Convert a local file path to a URL""" - pieces = [ quote(p) for p in path.split(os.path.sep) ] + pieces = [ quote(p) for p in path.split(os.sep) ] # preserve trailing / if pieces[-1] == '': pieces[-1] = '/'