From 2c14293ebb7697521d90376123bd8a61c5b9244d Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Thu, 14 Nov 2019 14:23:02 -0600 Subject: [PATCH] Added customized Pane type errors --- panel/pane/base.py | 9 ++++++--- panel/pane/image.py | 12 ++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/panel/pane/base.py b/panel/pane/base.py index bdb4e4893f..23ebabfe58 100644 --- a/panel/pane/base.py +++ b/panel/pane/base.py @@ -69,14 +69,17 @@ class PaneBase(Reactive): def __init__(self, object=None, **params): applies = self.applies(object) if (isinstance(applies, bool) and not applies) and object is not None : - raise ValueError("%s pane does not support objects of type '%s'" % - (type(self).__name__, type(object).__name__)) - + self._type_error(object) + super(PaneBase, self).__init__(object=object, **params) kwargs = {k: v for k, v in params.items() if k in Layoutable.param} self.layout = self.default_layout(self, **kwargs) self.param.watch(self._update_pane, self._rerender_params) + def _type_error(self, object): + raise ValueError("%s pane does not support objects of type '%s'." % + (type(self).__name__, type(object).__name__)) + def __repr__(self, depth=0): cls = type(self).__name__ params = param_reprs(self, ['object']) diff --git a/panel/pane/image.py b/panel/pane/image.py index 308aa03bd4..163bb26a27 100644 --- a/panel/pane/image.py +++ b/panel/pane/image.py @@ -60,6 +60,12 @@ def _is_url(cls, obj): ) and lower_string.endswith('.'+cls.imgtype) return False + def _type_error(self, object): + if isinstance(object, string_types): + raise ValueError("%s pane cannot parse string that is not a filename " + "or URL." % type(self).__name__) + super(ImageBase, self)._type_error(object) + def _img(self): if hasattr(self.object, '_repr_{}_'.format(self.imgtype)): return getattr(self.object, '_repr_' + self.imgtype + '_')() @@ -175,6 +181,12 @@ def applies(cls, obj): return (super(SVG, cls).applies(obj) or (isinstance(obj, string_types) and obj.lstrip().startswith('