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