@@ -66,6 +66,8 @@ def validate_any(s):
66
66
67
67
def validate_path_exists (s ):
68
68
"""If s is a path, return s, else False"""
69
+ if s is None :
70
+ return None
69
71
if os .path .exists (s ):
70
72
return s
71
73
else :
@@ -172,50 +174,54 @@ def validate_maskedarray(v):
172
174
' please delete it from your matplotlibrc file' )
173
175
174
176
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 ):
176
186
def __init__ (self , n ):
177
187
self .n = n
178
188
179
189
def __call__ (self , s ):
180
190
"""return a seq of n floats or raise"""
181
191
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
191
194
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 :
195
201
return [float (val ) for val in s ]
202
+ except ValueError :
203
+ raise ValueError ('Could not convert all entries to floats' )
196
204
197
205
198
- class validate_nseq_int :
206
+ class validate_nseq_int ( object ) :
199
207
def __init__ (self , n ):
200
208
self .n = n
201
209
202
210
def __call__ (self , s ):
203
211
"""return a seq of n ints or raise"""
204
212
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
214
215
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 :
218
222
return [int (val ) for val in s ]
223
+ except ValueError :
224
+ raise ValueError ('Could not convert all entries to ints' )
219
225
220
226
221
227
def validate_color (s ):
@@ -263,10 +269,10 @@ def validate_colorlist(s):
263
269
def validate_stringlist (s ):
264
270
'return a list'
265
271
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 ( )]
267
273
else :
268
274
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 ]
270
276
271
277
272
278
validate_orientation = ValidateInStrings (
@@ -517,7 +523,7 @@ def __call__(self, s):
517
523
518
524
519
525
## font props
520
- 'font.family' : ['sans-serif' , validate_stringlist ], # used by text object
526
+ 'font.family' : [[ 'sans-serif' ] , validate_stringlist ], # used by text object
521
527
'font.style' : ['normal' , six .text_type ],
522
528
'font.variant' : ['normal' , six .text_type ],
523
529
'font.stretch' : ['normal' , six .text_type ],
@@ -776,14 +782,14 @@ def __call__(self, s):
776
782
'keymap.home' : [['h' , 'r' , 'home' ], validate_stringlist ],
777
783
'keymap.back' : [['left' , 'c' , 'backspace' ], validate_stringlist ],
778
784
'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 ],
785
791
'keymap.xscale' : [['k' , 'L' ], validate_stringlist ],
786
- 'keymap.all_axes' : ['a' , validate_stringlist ],
792
+ 'keymap.all_axes' : [[ 'a' ] , validate_stringlist ],
787
793
788
794
# sample data
789
795
'examples.directory' : ['' , six .text_type ],
@@ -797,21 +803,21 @@ def __call__(self, s):
797
803
# Path to FFMPEG binary. If just binary name, subprocess uses $PATH.
798
804
'animation.ffmpeg_path' : ['ffmpeg' , six .text_type ],
799
805
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 ],
802
808
# Path to AVConv binary. If just binary name, subprocess uses $PATH.
803
809
'animation.avconv_path' : ['avconv' , six .text_type ],
804
810
# Additional arguments for avconv movie writer (using pipes)
805
- 'animation.avconv_args' : ['' , validate_stringlist ],
811
+ 'animation.avconv_args' : [[] , validate_stringlist ],
806
812
# Path to MENCODER binary. If just binary name, subprocess uses $PATH.
807
813
'animation.mencoder_path' : ['mencoder' , six .text_type ],
808
814
# Additional arguments for mencoder movie writer (using pipes)
809
- 'animation.mencoder_args' : ['' , validate_stringlist ],
815
+ 'animation.mencoder_args' : [[] , validate_stringlist ],
810
816
# Path to convert binary. If just binary name, subprocess uses $PATH
811
817
'animation.convert_path' : ['convert' , six .text_type ],
812
818
# Additional arguments for mencoder movie writer (using pipes)
813
819
814
- 'animation.convert_args' : ['' , validate_stringlist ]}
820
+ 'animation.convert_args' : [[] , validate_stringlist ]}
815
821
816
822
817
823
if __name__ == '__main__' :
0 commit comments