Show More
@@ -5,7 +5,7 b' Authors : MinRK, gregcaporaso, dannystaple' | |||||
5 | import urllib |
|
5 | import urllib | |
6 |
|
6 | |||
7 | from os.path import exists, isfile, splitext, abspath, join, isdir |
|
7 | from os.path import exists, isfile, splitext, abspath, join, isdir | |
8 | from os import walk |
|
8 | from os import walk, sep | |
9 |
|
9 | |||
10 |
|
10 | |||
11 | class YouTubeVideo(object): |
|
11 | class YouTubeVideo(object): | |
@@ -196,7 +196,8 b' class FileLinks(FileLink):' | |||||
196 | def _get_display_formatter(self, |
|
196 | def _get_display_formatter(self, | |
197 | dirname_output_format, |
|
197 | dirname_output_format, | |
198 | fname_output_format, |
|
198 | fname_output_format, | |
199 |
fp_format |
|
199 | fp_format, | |
|
200 | fp_cleaner=None): | |||
200 | """ generate built-in formatter function |
|
201 | """ generate built-in formatter function | |
201 |
|
202 | |||
202 | this is used to define both the notebook and terminal built-in |
|
203 | this is used to define both the notebook and terminal built-in | |
@@ -236,6 +237,8 b' class FileLinks(FileLink):' | |||||
236 | result.append(dirname_output_line) |
|
237 | result.append(dirname_output_line) | |
237 | for fname in display_fnames: |
|
238 | for fname in display_fnames: | |
238 | fp = fp_format % (dirname,fname) |
|
239 | fp = fp_format % (dirname,fname) | |
|
240 | if fp_cleaner is not None: | |||
|
241 | fp = fp_cleaner(fp) | |||
239 | try: |
|
242 | try: | |
240 | # output can include both a filepath and a filename... |
|
243 | # output can include both a filepath and a filename... | |
241 | fname_output_line = fname_output_format % (fp, fname) |
|
244 | fname_output_line = fname_output_format % (fp, fname) | |
@@ -255,10 +258,21 b' class FileLinks(FileLink):' | |||||
255 | fname_output_format = \ |
|
258 | fname_output_format = \ | |
256 | self.result_html_prefix + spacer + self.html_link_str + self.result_html_suffix |
|
259 | self.result_html_prefix + spacer + self.html_link_str + self.result_html_suffix | |
257 | fp_format = self.url_prefix + '%s/%s' |
|
260 | fp_format = self.url_prefix + '%s/%s' | |
|
261 | if sep == "\\": | |||
|
262 | # Working on a platform where the path separator is "\", so | |||
|
263 | # must convert these to "/" for generating a URI | |||
|
264 | def fp_cleaner(fp): | |||
|
265 | # Replace all occurences of backslash ("\") with a forward | |||
|
266 | # slash ("/") - this is necessary on windows when a path is | |||
|
267 | # provided as input, but we must link to a URI | |||
|
268 | return fp.replace('\\','/') | |||
|
269 | else: | |||
|
270 | fp_cleaner = None | |||
258 |
|
271 | |||
259 | return self._get_display_formatter(dirname_output_format, |
|
272 | return self._get_display_formatter(dirname_output_format, | |
260 | fname_output_format, |
|
273 | fname_output_format, | |
261 |
fp_format |
|
274 | fp_format, | |
|
275 | fp_cleaner) | |||
262 |
|
276 | |||
263 | def _get_terminal_display_formatter(self, |
|
277 | def _get_terminal_display_formatter(self, | |
264 | spacer=" "): |
|
278 | spacer=" "): |
@@ -15,6 +15,7 b'' | |||||
15 | from __future__ import print_function |
|
15 | from __future__ import print_function | |
16 | from tempfile import NamedTemporaryFile, mkdtemp |
|
16 | from tempfile import NamedTemporaryFile, mkdtemp | |
17 | from os.path import split |
|
17 | from os.path import split | |
|
18 | from os import sep | |||
18 |
|
19 | |||
19 | # Third-party imports |
|
20 | # Third-party imports | |
20 | import nose.tools as nt |
|
21 | import nose.tools as nt | |
@@ -89,9 +90,13 b' def test_existing_path_FileLinks():' | |||||
89 | actual = fl._repr_html_() |
|
90 | actual = fl._repr_html_() | |
90 | actual = actual.split('\n') |
|
91 | actual = actual.split('\n') | |
91 | actual.sort() |
|
92 | actual.sort() | |
|
93 | # the links should always have forward slashes, even on windows, so replace | |||
|
94 | # backslashes with forward slashes here | |||
92 | expected = ["%s/<br>" % td, |
|
95 | expected = ["%s/<br>" % td, | |
93 |
" <a href='files/%s' target='_blank'>%s</a><br>" % |
|
96 | " <a href='files/%s' target='_blank'>%s</a><br>" %\ | |
94 | " <a href='files/%s' target='_blank'>%s</a><br>" % (tf1.name,split(tf1.name)[1])] |
|
97 | (tf2.name.replace("\\","/"),split(tf2.name)[1]), | |
|
98 | " <a href='files/%s' target='_blank'>%s</a><br>" %\ | |||
|
99 | (tf1.name.replace("\\","/"),split(tf1.name)[1])] | |||
95 | expected.sort() |
|
100 | expected.sort() | |
96 | # We compare the sorted list of links here as that's more reliable |
|
101 | # We compare the sorted list of links here as that's more reliable | |
97 | nt.assert_equal(actual,expected) |
|
102 | nt.assert_equal(actual,expected) |
General Comments 0
You need to be logged in to leave comments.
Login now