##// END OF EJS Templates
Pass down include and exclude as kwarg to repr_mimebundle
Matthias Bussonnier -
Show More
@@ -147,7 +147,7 b' class DisplayFormatter(Configurable):'
147 147 # object handled itself, don't proceed
148 148 return {}, {}
149 149
150 format_dict, md_dict = self.mimebundle_formatter(obj)
150 format_dict, md_dict = self.mimebundle_formatter(obj, include=include, exclude=exclude)
151 151
152 152 if format_dict or md_dict:
153 153 if include:
@@ -937,6 +937,35 b' class MimeBundleFormatter(BaseFormatter):'
937 937 return r, {}
938 938 return r
939 939
940 @catch_format_error
941 def __call__(self, obj, include=None, exclude=None):
942 """Compute the format for an object.
943
944 Identical to parent's method but we pass extra parameters to the method.
945
946 Unlike other _repr_*_ `_repr_mimebundle_` should allow extra kwargs, in
947 particular `include` and `exclude`.
948 """
949 if self.enabled:
950 # lookup registered printer
951 try:
952 printer = self.lookup(obj)
953 except KeyError:
954 pass
955 else:
956 return printer(obj)
957 # Finally look for special method names
958 method = get_real_method(obj, self.print_method)
959
960 if method is not None:
961 d = {}
962 d['include'] = include
963 d['exclude'] = include
964 return method(**d)
965 return None
966 else:
967 return None
968
940 969
941 970 FormatterABC.register(BaseFormatter)
942 971 FormatterABC.register(PlainTextFormatter)
@@ -440,7 +440,7 b' def test_json_as_string_deprecated():'
440 440
441 441 def test_repr_mime():
442 442 class HasReprMime(object):
443 def _repr_mimebundle_(self):
443 def _repr_mimebundle_(self, include=None, exclude=None):
444 444 return {
445 445 'application/json+test.v2': {
446 446 'x': 'y'
@@ -477,7 +477,7 b' def test_repr_mime():'
477 477
478 478 def test_repr_mime_meta():
479 479 class HasReprMimeMeta(object):
480 def _repr_mimebundle_(self):
480 def _repr_mimebundle_(self, include=None, exclude=None):
481 481 data = {
482 482 'image/png': 'base64-image-data',
483 483 }
General Comments 0
You need to be logged in to leave comments. Login now