diff --git a/IPython/lib/display.py b/IPython/lib/display.py
index 87d4088..59825b2 100644
--- a/IPython/lib/display.py
+++ b/IPython/lib/display.py
@@ -85,6 +85,10 @@ class FileLink(object):
result_html_suffix : text to append at the end of link
[default: '
']
"""
+ if isdir(path):
+ raise ValueError,\
+ ("Cannot display a directory as a FileLink object. "
+ "Use FileLinks to display '%s'." % path)
self.path = path
self.url_prefix = url_prefix
self.result_html_prefix = result_html_prefix
@@ -111,12 +115,6 @@ class FileLink(object):
"""return absolute path to file
"""
return abspath(self.path)
-
-# Create an alias for formatting a single directory name as a link.
-# Right now this is the same as a formatting for a single file, but
-# we'll encourage users to reference these with a different class in
-# case we want to change this in the future.
-DirectoryLink = FileLink
class FileLinks(FileLink):
"""Class for embedding local file links in an IPython session, based on path
@@ -176,11 +174,11 @@ class FileLinks(FileLink):
self.included_suffixes = included_suffixes
# remove trailing slashs for more consistent output formatting
path = path.rstrip('/')
- FileLink.__init__(self,
- path,
- url_prefix,
- result_html_prefix,
- result_html_suffix)
+
+ self.path = path
+ self.url_prefix = url_prefix
+ self.result_html_prefix = result_html_prefix
+ self.result_html_suffix = result_html_suffix
self.notebook_display_formatter = \
notebook_display_formatter or self._get_notebook_display_formatter()
diff --git a/IPython/lib/tests/test_display.py b/IPython/lib/tests/test_display.py
index b2d790d..e0c33fb 100644
--- a/IPython/lib/tests/test_display.py
+++ b/IPython/lib/tests/test_display.py
@@ -31,16 +31,18 @@ from IPython.lib import display
#--------------------------
def test_instantiation_FileLink():
- """Test classes can be instantiated"""
+ """FileLink: Test class can be instantiated"""
fl = display.FileLink('example.txt')
def test_warning_on_non_existant_path_FileLink():
- """Calling _repr_html_ on non-existant files returns a warning"""
+ """FileLink: Calling _repr_html_ on non-existant files returns a warning
+ """
fl = display.FileLink('example.txt')
nt.assert_true(fl._repr_html_().startswith('Path (example.txt)'))
def test_existing_path_FileLink():
- """ Calling _repr_html_ functions as expected on existing filepath """
+ """FileLink: Calling _repr_html_ functions as expected on existing filepath
+ """
tf = NamedTemporaryFile()
fl = display.FileLink(tf.name)
actual = fl._repr_html_()
@@ -48,7 +50,8 @@ def test_existing_path_FileLink():
nt.assert_equal(actual,expected)
def test_existing_path_FileLink_repr():
- """ Calling repr() functions as expected on existing filepath """
+ """FileLink: Calling repr() functions as expected on existing filepath
+ """
tf = NamedTemporaryFile()
fl = display.FileLink(tf.name)
actual = repr(fl)
@@ -60,16 +63,19 @@ def test_existing_path_FileLink_repr():
#--------------------------
def test_instantiation_FileLinks():
- """Test classes can be instantiated"""
+ """FileLinks: Test class can be instantiated
+ """
fls = display.FileLinks('example')
def test_warning_on_non_existant_path_FileLinks():
- """Calling _repr_html_ on non-existant files returns a warning"""
+ """FileLinks: Calling _repr_html_ on non-existant files returns a warning
+ """
fls = display.FileLinks('example')
nt.assert_true(fls._repr_html_().startswith('Path (example)'))
def test_existing_path_FileLinks():
- """ Calling _repr_html_ functions as expected on existing directory """
+ """FileLinks: Calling _repr_html_ functions as expected on existing dir
+ """
td = mkdtemp()
tf1 = NamedTemporaryFile(dir=td)
tf2 = NamedTemporaryFile(dir=td)
@@ -85,7 +91,7 @@ def test_existing_path_FileLinks():
nt.assert_equal(actual,expected)
def test_existing_path_FileLinks_alt_formatter():
- """ Calling _repr_html_ functions as expected with an alternative formatter
+ """FileLinks: Calling _repr_html_ functions as expected w/ an alt formatter
"""
td = mkdtemp()
tf1 = NamedTemporaryFile(dir=td)
@@ -102,7 +108,7 @@ def test_existing_path_FileLinks_alt_formatter():
nt.assert_equal(actual,expected)
def test_existing_path_FileLinks_repr():
- """ Calling repr() functions as expected on existing directory """
+ """FileLinks: Calling repr() functions as expected on existing directory """
td = mkdtemp()
tf1 = NamedTemporaryFile(dir=td)
tf2 = NamedTemporaryFile(dir=td)
@@ -116,7 +122,7 @@ def test_existing_path_FileLinks_repr():
nt.assert_equal(actual,expected)
def test_existing_path_FileLinks_repr_alt_formatter():
- """ Calling repr() functions as expected with an alternative formatter
+ """FileLinks: Calling repr() functions as expected w/ alt formatter
"""
td = mkdtemp()
tf1 = NamedTemporaryFile(dir=td)
@@ -132,23 +138,3 @@ def test_existing_path_FileLinks_repr_alt_formatter():
# We compare the sorted list of links here as that's more reliable
nt.assert_equal(actual,expected)
-#--------------------------
-# DirectoryLink tests
-#--------------------------
-
-def test_instantiation_DirectoryLink():
- """Test classes can be instantiated"""
- dl = display.DirectoryLink('example')
-
-def test_warning_on_non_existant_path_DirectoryLink():
- """Calling _repr_html_ on non-existant files returns a warning"""
- dl = display.DirectoryLink('example')
- nt.assert_true(dl._repr_html_().startswith('Path (example)'))
-
-def test_existing_path_DirectoryLink():
- """ Calling _repr_html_ functions as expected on existing directory """
- td = mkdtemp()
- dl = display.DirectoryLink(td)
- actual = dl._repr_html_()
- expected = "%s
" % (td,td)
- nt.assert_equal(actual,expected)