@@ -136,6 +136,7 @@ def validate_float(s):
136
136
raise ValueError ('Could not convert "%s" to float' % s )
137
137
validate_floatlist = _listify_validator (validate_float )
138
138
139
+
139
140
def validate_float_or_None (s ):
140
141
"""convert s to float, None or raise"""
141
142
# values directly from the rc file can only be strings,
@@ -150,6 +151,7 @@ def validate_float_or_None(s):
150
151
except ValueError :
151
152
raise ValueError ('Could not convert "%s" to float or None' % s )
152
153
154
+
153
155
def validate_dpi (s ):
154
156
"""confirm s is string 'figure' or convert s to float or raise"""
155
157
if s == 'figure' :
@@ -160,13 +162,15 @@ def validate_dpi(s):
160
162
raise ValueError ('"%s" is not string "figure" or'
161
163
' could not convert "%s" to float' % (s , s ))
162
164
165
+
163
166
def validate_int (s ):
164
167
"""convert s to int or raise"""
165
168
try :
166
169
return int (s )
167
170
except ValueError :
168
171
raise ValueError ('Could not convert "%s" to int' % s )
169
172
173
+
170
174
def validate_int_or_None (s ):
171
175
"""if not None, tries to validate as an int"""
172
176
if s == 'None' :
@@ -178,6 +182,7 @@ def validate_int_or_None(s):
178
182
except ValueError :
179
183
raise ValueError ('Could not convert "%s" to int' % s )
180
184
185
+
181
186
def validate_fonttype (s ):
182
187
"""
183
188
confirm that this is a Postscript of PDF font type that we know how to
@@ -354,15 +359,19 @@ def validate_aspect(s):
354
359
355
360
356
361
def validate_fontsize (s ):
362
+ fontsizes = ['xx-small' , 'x-small' , 'small' , 'medium' , 'large' ,
363
+ 'x-large' , 'xx-large' , 'smaller' , 'larger' ]
357
364
if isinstance (s , six .string_types ):
358
365
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 :
361
367
return s
362
368
try :
363
369
return float (s )
364
370
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
+
366
375
validate_fontsizelist = _listify_validator (validate_fontsize )
367
376
368
377
0 commit comments