@@ -136,6 +136,7 @@ def validate_float(s):
136136 raise ValueError ('Could not convert "%s" to float' % s )
137137validate_floatlist = _listify_validator (validate_float )
138138
139+
139140def validate_float_or_None (s ):
140141 """convert s to float, None or raise"""
141142 # values directly from the rc file can only be strings,
@@ -150,6 +151,7 @@ def validate_float_or_None(s):
150151 except ValueError :
151152 raise ValueError ('Could not convert "%s" to float or None' % s )
152153
154+
153155def validate_dpi (s ):
154156 """confirm s is string 'figure' or convert s to float or raise"""
155157 if s == 'figure' :
@@ -160,13 +162,15 @@ def validate_dpi(s):
160162 raise ValueError ('"%s" is not string "figure" or'
161163 ' could not convert "%s" to float' % (s , s ))
162164
165+
163166def validate_int (s ):
164167 """convert s to int or raise"""
165168 try :
166169 return int (s )
167170 except ValueError :
168171 raise ValueError ('Could not convert "%s" to int' % s )
169172
173+
170174def validate_int_or_None (s ):
171175 """if not None, tries to validate as an int"""
172176 if s == 'None' :
@@ -178,6 +182,7 @@ def validate_int_or_None(s):
178182 except ValueError :
179183 raise ValueError ('Could not convert "%s" to int' % s )
180184
185+
181186def validate_fonttype (s ):
182187 """
183188 confirm that this is a Postscript of PDF font type that we know how to
@@ -354,15 +359,19 @@ def validate_aspect(s):
354359
355360
356361def validate_fontsize (s ):
362+ fontsizes = ['xx-small' , 'x-small' , 'small' , 'medium' , 'large' ,
363+ 'x-large' , 'xx-large' , 'smaller' , 'larger' ]
357364 if isinstance (s , six .string_types ):
358365 s = s .lower ()
359- if s in ['xx-small' , 'x-small' , 'small' , 'medium' , 'large' , 'x-large' ,
360- 'xx-large' , 'smaller' , 'larger' ]:
366+ if s in fontsizes :
361367 return s
362368 try :
363369 return float (s )
364370 except ValueError :
365- raise ValueError ('not a valid font size' )
371+ raise ValueError ("%s is not a valid font size. Valid font sizes "
372+ "are %s." % (s , ", " .join (fontsizes )))
373+
374+
366375validate_fontsizelist = _listify_validator (validate_fontsize )
367376
368377
0 commit comments