@@ -66,6 +66,8 @@ def validate_any(s):
6666
6767def validate_path_exists (s ):
6868 """If s is a path, return s, else False"""
69+ if s is None :
70+ return None
6971 if os .path .exists (s ):
7072 return s
7173 else :
@@ -172,50 +174,54 @@ def validate_maskedarray(v):
172174 ' please delete it from your matplotlibrc file' )
173175
174176
175- class validate_nseq_float :
177+ _seq_err_msg = ('You must supply exactly {n:d} values, you provided '
178+ '{num:d} values: {s}' )
179+
180+ _str_err_msg = ('You must supply exactly {n:d} comma-separated values, '
181+ 'you provided '
182+ '{num:d} comma-separated values: {s}' )
183+
184+
185+ class validate_nseq_float (object ):
176186 def __init__ (self , n ):
177187 self .n = n
178188
179189 def __call__ (self , s ):
180190 """return a seq of n floats or raise"""
181191 if isinstance (s , six .string_types ):
182- ss = s .split (',' )
183- if len (ss ) != self .n :
184- raise ValueError (
185- 'You must supply exactly %d comma separated values' %
186- self .n )
187- try :
188- return [float (val ) for val in ss ]
189- except ValueError :
190- raise ValueError ('Could not convert all entries to floats' )
192+ s = s .split (',' )
193+ err_msg = _str_err_msg
191194 else :
192- assert type (s ) in (list , tuple )
193- if len (s ) != self .n :
194- raise ValueError ('You must supply exactly %d values' % self .n )
195+ err_msg = _seq_err_msg
196+
197+ if len (s ) != self .n :
198+ raise ValueError (err_msg .format (n = self .n , num = len (s ), s = s ))
199+
200+ try :
195201 return [float (val ) for val in s ]
202+ except ValueError :
203+ raise ValueError ('Could not convert all entries to floats' )
196204
197205
198- class validate_nseq_int :
206+ class validate_nseq_int ( object ) :
199207 def __init__ (self , n ):
200208 self .n = n
201209
202210 def __call__ (self , s ):
203211 """return a seq of n ints or raise"""
204212 if isinstance (s , six .string_types ):
205- ss = s .split (',' )
206- if len (ss ) != self .n :
207- raise ValueError (
208- 'You must supply exactly %d comma separated values' %
209- self .n )
210- try :
211- return [int (val ) for val in ss ]
212- except ValueError :
213- raise ValueError ('Could not convert all entries to ints' )
213+ s = s .split (',' )
214+ err_msg = _str_err_msg
214215 else :
215- assert type (s ) in (list , tuple )
216- if len (s ) != self .n :
217- raise ValueError ('You must supply exactly %d values' % self .n )
216+ err_msg = _seq_err_msg
217+
218+ if len (s ) != self .n :
219+ raise ValueError (err_msg .format (n = self .n , num = len (s ), s = s ))
220+
221+ try :
218222 return [int (val ) for val in s ]
223+ except ValueError :
224+ raise ValueError ('Could not convert all entries to ints' )
219225
220226
221227def validate_color (s ):
@@ -263,10 +269,10 @@ def validate_colorlist(s):
263269def validate_stringlist (s ):
264270 'return a list'
265271 if isinstance (s , six .string_types ):
266- return [v .strip () for v in s .split (',' )]
272+ return [six . text_type ( v .strip ()) for v in s .split (',' ) if v . strip ( )]
267273 else :
268274 assert type (s ) in [list , tuple ]
269- return [six .text_type (v ) for v in s ]
275+ return [six .text_type (v ) for v in s if v ]
270276
271277
272278validate_orientation = ValidateInStrings (
@@ -517,7 +523,7 @@ def __call__(self, s):
517523
518524
519525 ## font props
520- 'font.family' : ['sans-serif' , validate_stringlist ], # used by text object
526+ 'font.family' : [[ 'sans-serif' ] , validate_stringlist ], # used by text object
521527 'font.style' : ['normal' , six .text_type ],
522528 'font.variant' : ['normal' , six .text_type ],
523529 'font.stretch' : ['normal' , six .text_type ],
@@ -776,14 +782,14 @@ def __call__(self, s):
776782 'keymap.home' : [['h' , 'r' , 'home' ], validate_stringlist ],
777783 'keymap.back' : [['left' , 'c' , 'backspace' ], validate_stringlist ],
778784 'keymap.forward' : [['right' , 'v' ], validate_stringlist ],
779- 'keymap.pan' : ['p' , validate_stringlist ],
780- 'keymap.zoom' : ['o' , validate_stringlist ],
781- 'keymap.save' : [( 's' , 'ctrl+s' ) , validate_stringlist ],
782- 'keymap.quit' : [( 'ctrl+w' , 'cmd+w' ) , validate_stringlist ],
783- 'keymap.grid' : ['g' , validate_stringlist ],
784- 'keymap.yscale' : ['l' , validate_stringlist ],
785+ 'keymap.pan' : [[ 'p' ] , validate_stringlist ],
786+ 'keymap.zoom' : [[ 'o' ] , validate_stringlist ],
787+ 'keymap.save' : [[ 's' , 'ctrl+s' ] , validate_stringlist ],
788+ 'keymap.quit' : [[ 'ctrl+w' , 'cmd+w' ] , validate_stringlist ],
789+ 'keymap.grid' : [[ 'g' ] , validate_stringlist ],
790+ 'keymap.yscale' : [[ 'l' ] , validate_stringlist ],
785791 'keymap.xscale' : [['k' , 'L' ], validate_stringlist ],
786- 'keymap.all_axes' : ['a' , validate_stringlist ],
792+ 'keymap.all_axes' : [[ 'a' ] , validate_stringlist ],
787793
788794 # sample data
789795 'examples.directory' : ['' , six .text_type ],
@@ -797,21 +803,21 @@ def __call__(self, s):
797803 # Path to FFMPEG binary. If just binary name, subprocess uses $PATH.
798804 'animation.ffmpeg_path' : ['ffmpeg' , six .text_type ],
799805
800- ## Additional arguments for ffmpeg movie writer (using pipes)
801- 'animation.ffmpeg_args' : ['' , validate_stringlist ],
806+ # Additional arguments for ffmpeg movie writer (using pipes)
807+ 'animation.ffmpeg_args' : [[] , validate_stringlist ],
802808 # Path to AVConv binary. If just binary name, subprocess uses $PATH.
803809 'animation.avconv_path' : ['avconv' , six .text_type ],
804810 # Additional arguments for avconv movie writer (using pipes)
805- 'animation.avconv_args' : ['' , validate_stringlist ],
811+ 'animation.avconv_args' : [[] , validate_stringlist ],
806812 # Path to MENCODER binary. If just binary name, subprocess uses $PATH.
807813 'animation.mencoder_path' : ['mencoder' , six .text_type ],
808814 # Additional arguments for mencoder movie writer (using pipes)
809- 'animation.mencoder_args' : ['' , validate_stringlist ],
815+ 'animation.mencoder_args' : [[] , validate_stringlist ],
810816 # Path to convert binary. If just binary name, subprocess uses $PATH
811817 'animation.convert_path' : ['convert' , six .text_type ],
812818 # Additional arguments for mencoder movie writer (using pipes)
813819
814- 'animation.convert_args' : ['' , validate_stringlist ]}
820+ 'animation.convert_args' : [[] , validate_stringlist ]}
815821
816822
817823if __name__ == '__main__' :
0 commit comments