7
7
from .domwidget import DOMWidget
8
8
from .valuewidget import ValueWidget
9
9
from .widget import register
10
- from traitlets import Unicode , CUnicode , Bytes , Bool
11
- from .trait_types import bytes_serialization
10
+ from traitlets import Unicode , CUnicode , Bool
11
+ from .trait_types import CByteMemoryView
12
12
13
13
14
14
@register
@@ -23,7 +23,7 @@ class _Media(DOMWidget, ValueWidget, CoreWidget):
23
23
"""
24
24
25
25
# Define the custom state properties to sync with the front-end
26
- value = Bytes (help = "The media data as a byte string ." ).tag (sync = True , ** bytes_serialization )
26
+ value = CByteMemoryView (help = "The media data as a memory view of bytes ." ).tag (sync = True )
27
27
28
28
@classmethod
29
29
def _from_file (cls , tag , filename , ** kwargs ):
@@ -116,12 +116,13 @@ def _get_repr(self, cls):
116
116
117
117
# Return value first like a ValueWidget
118
118
signature = []
119
- sig_value = repr (self .value )
120
- prefix , rest = sig_value .split ("'" , 1 )
121
- content = rest [:- 1 ]
122
- if len (content ) > 100 :
123
- sig_value = "{}'{}...'" .format (prefix , content [0 :100 ])
124
- signature .append ('{}={}' .format ('value' , sig_value ))
119
+
120
+ # strip off the starting b' and ending ' so we can truncate if needed
121
+ sig_value = repr (self .value [:100 ].tobytes ())[2 :- 1 ]
122
+
123
+ if self .value .nbytes > 100 :
124
+ sig_value += '...'
125
+ signature .append ("{}=b'{}'" .format ('value' , sig_value ))
125
126
126
127
for key in super (cls , self )._repr_keys ():
127
128
if key == 'value' :
0 commit comments