@@ -217,6 +217,16 @@ def __init__(self,
217217 super (ImageFile , self ).__init__ (value , filter , auto_set , entries ,
218218 exists , ** metadata )
219219
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+
220230 def grab_exts (self ):
221231 # TODO: file type validation
222232 exts = []
@@ -243,11 +253,11 @@ def validate(self, object, name, value):
243253 """
244254 validated_value = super (ImageFile , self ).validate (object , name , value )
245255 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 ):
248258 raise TraitError (
249259 args = "{} is not included in allowed types: {}" .format (
250- validated_value , ', ' .join (self . _exts )))
260+ validated_value , ', ' .join (_exts )))
251261 return validated_value
252262
253263
@@ -322,15 +332,11 @@ def validate(self, object, name, value):
322332
323333 newvalue = value
324334
335+ inner_trait = self .inner_traits ()[0 ]
325336 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 )):
334340 newvalue = [value ]
335341 value = super (MultiPath , self ).validate (object , name , newvalue )
336342
0 commit comments