@@ -217,6 +217,16 @@ def __init__(self,
217
217
super (ImageFile , self ).__init__ (value , filter , auto_set , entries ,
218
218
exists , ** metadata )
219
219
220
+ def info (self ):
221
+ existing = 'n existing' if self .exists else ''
222
+ comma = ',' if self .exists and not self .allow_compressed else ''
223
+ uncompressed = ' uncompressed' if not self .allow_compressed else ''
224
+ with_ext = ' (valid extensions: [{}])' .format (
225
+ ', ' .join (self .grab_exts ())) if self .types else ''
226
+ return 'a{existing}{comma}{uncompressed} file{with_ext}' .format (
227
+ existing = existing , comma = comma , uncompressed = uncompressed ,
228
+ with_ext = with_ext )
229
+
220
230
def grab_exts (self ):
221
231
# TODO: file type validation
222
232
exts = []
@@ -243,11 +253,11 @@ def validate(self, object, name, value):
243
253
"""
244
254
validated_value = super (ImageFile , self ).validate (object , name , value )
245
255
if validated_value and self .types :
246
- self . _exts = self .grab_exts ()
247
- if not any (validated_value .endswith (x ) for x in self . _exts ):
256
+ _exts = self .grab_exts ()
257
+ if not any (validated_value .endswith (x ) for x in _exts ):
248
258
raise TraitError (
249
259
args = "{} is not included in allowed types: {}" .format (
250
- validated_value , ', ' .join (self . _exts )))
260
+ validated_value , ', ' .join (_exts )))
251
261
return validated_value
252
262
253
263
@@ -322,15 +332,11 @@ def validate(self, object, name, value):
322
332
323
333
newvalue = value
324
334
335
+ inner_trait = self .inner_traits ()[0 ]
325
336
if not isinstance (value , list ) \
326
- or (self .inner_traits () and
327
- isinstance (self .inner_traits ()[0 ].trait_type ,
328
- traits .List ) and not
329
- isinstance (self .inner_traits ()[0 ].trait_type ,
330
- InputMultiPath ) and
331
- isinstance (value , list ) and
332
- value and not
333
- isinstance (value [0 ], list )):
337
+ or (isinstance (inner_trait .trait_type , traits .List ) and
338
+ not isinstance (inner_trait .trait_type , InputMultiPath ) and
339
+ not isinstance (value [0 ], list )):
334
340
newvalue = [value ]
335
341
value = super (MultiPath , self ).validate (object , name , newvalue )
336
342
0 commit comments