##// END OF EJS Templates
s/os.path.sep/os.sep/
MinRK -
Show More
@@ -299,7 +299,7 b' class AuthenticatedFileHandler(IPythonHandler, web.StaticFileHandler):'
299 or the UF_HIDDEN flag as reported by stat
299 or the UF_HIDDEN flag as reported by stat
300 """
300 """
301 inside_root = absolute_path[len(absolute_root):]
301 inside_root = absolute_path[len(absolute_root):]
302 if any(part.startswith('.') for part in inside_root.split(os.path.sep)):
302 if any(part.startswith('.') for part in inside_root.split(os.sep)):
303 raise web.HTTPError(403)
303 raise web.HTTPError(403)
304
304
305 # check UF_HIDDEN on any location up to root
305 # check UF_HIDDEN on any location up to root
@@ -367,7 +367,7 b' class FileFindHandler(web.StaticFileHandler):'
367 if isinstance(path, basestring):
367 if isinstance(path, basestring):
368 path = [path]
368 path = [path]
369 self.roots = tuple(
369 self.roots = tuple(
370 os.path.abspath(os.path.expanduser(p)) + os.path.sep for p in path
370 os.path.abspath(os.path.expanduser(p)) + os.sep for p in path
371 )
371 )
372 self.default_filename = default_filename
372 self.default_filename = default_filename
373
373
@@ -385,7 +385,7 b' class FileFindHandler(web.StaticFileHandler):'
385
385
386 # os.path.abspath strips a trailing /
386 # os.path.abspath strips a trailing /
387 # it needs to be temporarily added back for requests to root/
387 # it needs to be temporarily added back for requests to root/
388 if not (abspath + os.path.sep).startswith(roots):
388 if not (abspath + os.sep).startswith(roots):
389 raise HTTPError(403, "%s is not in root static directory", path)
389 raise HTTPError(403, "%s is not in root static directory", path)
390
390
391 cls._static_paths[path] = abspath
391 cls._static_paths[path] = abspath
@@ -470,7 +470,7 b' class FileFindHandler(web.StaticFileHandler):'
470 if isinstance(static_paths, basestring):
470 if isinstance(static_paths, basestring):
471 static_paths = [static_paths]
471 static_paths = [static_paths]
472 roots = tuple(
472 roots = tuple(
473 os.path.abspath(os.path.expanduser(p)) + os.path.sep for p in static_paths
473 os.path.abspath(os.path.expanduser(p)) + os.sep for p in static_paths
474 )
474 )
475
475
476 try:
476 try:
@@ -504,8 +504,8 b' class FileFindHandler(web.StaticFileHandler):'
504 ``static_url_prefix`` removed. The return value should be
504 ``static_url_prefix`` removed. The return value should be
505 filesystem path relative to ``static_path``.
505 filesystem path relative to ``static_path``.
506 """
506 """
507 if os.path.sep != "/":
507 if os.sep != "/":
508 url_path = url_path.replace("/", os.path.sep)
508 url_path = url_path.replace("/", os.sep)
509 return url_path
509 return url_path
510
510
511 class TrailingSlashHandler(web.RequestHandler):
511 class TrailingSlashHandler(web.RequestHandler):
@@ -102,12 +102,12 b' class APITest(NotebookTestBase):'
102 nbdir = self.notebook_dir.name
102 nbdir = self.notebook_dir.name
103
103
104 for d in self.dirs:
104 for d in self.dirs:
105 d.replace('/', os.path.sep)
105 d.replace('/', os.sep)
106 if not os.path.isdir(pjoin(nbdir, d)):
106 if not os.path.isdir(pjoin(nbdir, d)):
107 os.mkdir(pjoin(nbdir, d))
107 os.mkdir(pjoin(nbdir, d))
108
108
109 for d, name in self.dirs_nbs:
109 for d, name in self.dirs_nbs:
110 d = d.replace('/', os.path.sep)
110 d = d.replace('/', os.sep)
111 with io.open(pjoin(nbdir, d, '%s.ipynb' % name), 'w') as f:
111 with io.open(pjoin(nbdir, d, '%s.ipynb' % name), 'w') as f:
112 nb = new_notebook(name=name)
112 nb = new_notebook(name=name)
113 write(nb, f, format='ipynb')
113 write(nb, f, format='ipynb')
@@ -172,7 +172,7 b' class APITest(NotebookTestBase):'
172 self.assertEqual(resp.json()['name'], name)
172 self.assertEqual(resp.json()['name'], name)
173 assert os.path.isfile(pjoin(
173 assert os.path.isfile(pjoin(
174 self.notebook_dir.name,
174 self.notebook_dir.name,
175 path.replace('/', os.path.sep),
175 path.replace('/', os.sep),
176 name,
176 name,
177 ))
177 ))
178
178
@@ -27,7 +27,7 b' class FilesTest(NotebookTestBase):'
27
27
28 nbdir = self.notebook_dir.name
28 nbdir = self.notebook_dir.name
29 for d in dirs:
29 for d in dirs:
30 path = pjoin(nbdir, d.replace('/', os.path.sep))
30 path = pjoin(nbdir, d.replace('/', os.sep))
31 if not os.path.exists(path):
31 if not os.path.exists(path):
32 os.mkdir(path)
32 os.mkdir(path)
33 with open(pjoin(path, 'foo'), 'w') as f:
33 with open(pjoin(path, 'foo'), 'w') as f:
@@ -37,7 +37,7 b' class FilesTest(NotebookTestBase):'
37 url = self.base_url()
37 url = self.base_url()
38
38
39 for d in not_hidden:
39 for d in not_hidden:
40 path = pjoin(nbdir, d.replace('/', os.path.sep))
40 path = pjoin(nbdir, d.replace('/', os.sep))
41 r = requests.get(url_path_join(url, 'files', d, 'foo'))
41 r = requests.get(url_path_join(url, 'files', d, 'foo'))
42 r.raise_for_status()
42 r.raise_for_status()
43 self.assertEqual(r.content, b'foo')
43 self.assertEqual(r.content, b'foo')
@@ -45,7 +45,7 b' class FilesTest(NotebookTestBase):'
45 self.assertEqual(r.status_code, 403)
45 self.assertEqual(r.status_code, 403)
46
46
47 for d in hidden:
47 for d in hidden:
48 path = pjoin(nbdir, d.replace('/', os.path.sep))
48 path = pjoin(nbdir, d.replace('/', os.sep))
49 for foo in ('foo', '.foo'):
49 for foo in ('foo', '.foo'):
50 r = requests.get(url_path_join(url, 'files', d, foo))
50 r = requests.get(url_path_join(url, 'files', d, foo))
51 self.assertEqual(r.status_code, 403)
51 self.assertEqual(r.status_code, 403)
@@ -38,7 +38,7 b' def url_path_join(*pieces):'
38
38
39 def path2url(path):
39 def path2url(path):
40 """Convert a local file path to a URL"""
40 """Convert a local file path to a URL"""
41 pieces = [ quote(p) for p in path.split(os.path.sep) ]
41 pieces = [ quote(p) for p in path.split(os.sep) ]
42 # preserve trailing /
42 # preserve trailing /
43 if pieces[-1] == '':
43 if pieces[-1] == '':
44 pieces[-1] = '/'
44 pieces[-1] = '/'
General Comments 0
You need to be logged in to leave comments. Login now