##// END OF EJS Templates
this should address the failure in #2732...
Greg Caporaso -
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):
@@ -192,7 +192,8 b' class FileLinks(FileLink):'
192 def _get_display_formatter(self,
192 def _get_display_formatter(self,
193 dirname_output_format,
193 dirname_output_format,
194 fname_output_format,
194 fname_output_format,
195 fp_format):
195 fp_format,
196 fp_cleaner=None):
196 """ generate built-in formatter function
197 """ generate built-in formatter function
197
198
198 this is used to define both the notebook and terminal built-in
199 this is used to define both the notebook and terminal built-in
@@ -232,6 +233,8 b' class FileLinks(FileLink):'
232 result.append(dirname_output_line)
233 result.append(dirname_output_line)
233 for fname in display_fnames:
234 for fname in display_fnames:
234 fp = fp_format % (dirname,fname)
235 fp = fp_format % (dirname,fname)
236 if fp_cleaner != None:
237 fp = fp_cleaner(fp)
235 try:
238 try:
236 # output can include both a filepath and a filename...
239 # output can include both a filepath and a filename...
237 fname_output_line = fname_output_format % (fp, fname)
240 fname_output_line = fname_output_format % (fp, fname)
@@ -251,10 +254,21 b' class FileLinks(FileLink):'
251 fname_output_format = \
254 fname_output_format = \
252 self.result_html_prefix + spacer + self.html_link_str + self.result_html_suffix
255 self.result_html_prefix + spacer + self.html_link_str + self.result_html_suffix
253 fp_format = self.url_prefix + '%s/%s'
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 return self._get_display_formatter(dirname_output_format,
268 return self._get_display_formatter(dirname_output_format,
256 fname_output_format,
269 fname_output_format,
257 fp_format)
270 fp_format,
271 fp_cleaner)
258
272
259 def _get_terminal_display_formatter(self,
273 def _get_terminal_display_formatter(self,
260 spacer=" "):
274 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 "&nbsp;&nbsp;<a href='files/%s' target='_blank'>%s</a><br>" % (tf2.name,split(tf2.name)[1]),
96 "&nbsp;&nbsp;<a href='files/%s' target='_blank'>%s</a><br>" %\
94 "&nbsp;&nbsp;<a href='files/%s' target='_blank'>%s</a><br>" % (tf1.name,split(tf1.name)[1])]
97 (tf2.name.replace("\\","/"),split(tf2.name)[1]),
98 "&nbsp;&nbsp;<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