@@ -468,6 +468,26 @@ def compare_versions(a, b):
468
468
else : return False
469
469
else : return False
470
470
471
+
472
+ ##########################
473
+ # to go to rcdefaults.py
474
+ #
475
+
476
+ class ValidateInStrings :
477
+ def __init__ (self , key , valid , ignorecase = False ):
478
+ 'valid is a list of legal strings'
479
+ self .key = key
480
+ self .ignorecase = ignorecase
481
+ def func (s ):
482
+ if ignorecase : return s .lower ()
483
+ else : return s
484
+ self .valid = dict ([(func (k ),k ) for k in valid ])
485
+
486
+ def __call__ (self , s ):
487
+ if self .ignorecase : s = s .lower ()
488
+ if s in self .valid : return self .valid [s ]
489
+ raise ValueError ('Unrecognized %s string "%s": valid strings are %s' % (self .key , s , self .valid .values ()))
490
+
471
491
def validate_path_exists (s ):
472
492
'If s is a path, return s, else False'
473
493
if os .path .exists (s ): return s
@@ -494,36 +514,19 @@ def validate_int(s):
494
514
except ValueError :
495
515
raise ValueError ('Could not convert "%s" to int' % s )
496
516
497
- def validate_backend (s , fail_on_err = True ):
498
- s = s .lower ()
499
- backends = ['Agg2' , 'Agg' , 'Aqt' , 'Cairo' , 'CocoaAgg' , 'EMF' , 'GD' , 'GDK' ,
500
- 'GTK' , 'GTKAgg' , 'GTKCairo' , 'FltkAgg' , 'Paint' , 'Pdf' , 'PS' ,
501
- 'QtAgg' , 'Qt4Agg' , 'SVG' , 'Template' , 'TkAgg' , 'WX' , 'WXAgg' ]
502
- for i in backends :
503
- if s == i .lower (): return i
504
- if fail_on_err : raise ValueError ('Backend must be %s, or %s' % \
505
- ', ' .join ((backends [:- 1 ], backends [- 1 ])))
506
- else : return None
507
-
508
- def validate_numerix (s ):
509
- 'return "Numeric" or "numarray" or "numpy" or raise'
510
- sl = s .lower ()
511
- if sl == 'numeric' : return 'Numeric'
512
- elif sl == 'numarray' : return 'numarray'
513
- elif sl == 'numpy' : return 'numpy'
514
- else :
515
- raise ValueError ('Numerix must be Numeric, numarray, or numpy' )
517
+ validate_backend = ValidateInStrings ('backend' ,[
518
+ 'Agg2' , 'Agg' , 'Aqt' , 'Cairo' , 'CocoaAgg' , 'EMF' , 'GD' , 'GDK' ,
519
+ 'GTK' , 'GTKAgg' , 'GTKCairo' , 'FltkAgg' , 'Paint' , 'Pdf' , 'PS' ,
520
+ 'QtAgg' , 'Qt4Agg' , 'SVG' , 'Template' , 'TkAgg' , 'WX' , 'WXAgg' ,
521
+ ], ignorecase = True )
516
522
517
- def validate_toolbar (s ):
518
- """
519
- return toolbar string 'None', 'classic', 'toolbar2'
520
- """
521
- s = s .lower ()
522
- if s == 'none' : return 'None'
523
- elif s == 'classic' : return s
524
- elif s == 'toolbar2' : return s
525
- else :
526
- raise ValueError ('toolbar must be None | classic | toolbar2' )
523
+ validate_numerix = ValidateInStrings ('numerix' ,[
524
+ 'Numeric' ,'numarray' ,'numpy' ,
525
+ ], ignorecase = True )
526
+
527
+ validate_toolbar = ValidateInStrings ('toolbar' ,[
528
+ 'None' ,'classic' ,'toolbar2' ,
529
+ ], ignorecase = True )
527
530
528
531
class validate_nseq_float :
529
532
def __init__ (self , n ):
@@ -585,6 +588,10 @@ def validate_comma_sep_str(s):
585
588
except ValueError :
586
589
raise ValueError ('Could not convert all entries to strings' )
587
590
591
+ validate_orientation = ValidateInStrings ('orientation' ,[
592
+ 'landscape' , 'portrait' ,
593
+ ])
594
+
588
595
def validate_latex_preamble (s ):
589
596
'return a list'
590
597
preamble_list = validate_comma_sep_str (s )
@@ -599,22 +606,6 @@ def validate_latex_preamble(s):
599
606
return preamble_list
600
607
601
608
602
- class ValidateInStrings :
603
- def __init__ (self , valid , ignorecase = False ):
604
- 'valid is a list of legal strings'
605
- self .ignorecase = ignorecase
606
- def func (s ):
607
- if ignorecase : return s .lower ()
608
- else : return s
609
- self .validd = dict ([(func (k ),1 ) for k in valid ])
610
-
611
- def __call__ (self , s ):
612
- if self .ignorecase : s = s .lower ()
613
- if s in self .validd : return s
614
- raise ValueError ('Unrecognized string "%s": valid strings are %s' % (s , self .validd .keys ()))
615
-
616
-
617
- validate_orientation = ValidateInStrings (['landscape' , 'portrait' ])
618
609
619
610
def validate_aspect (s ):
620
611
if s in ('auto' , 'equal' ):
@@ -633,13 +624,15 @@ def validate_fontsize(s):
633
624
except ValueError :
634
625
raise ValueError ('not a valid font size' )
635
626
636
- validate_verbose = ValidateInStrings (Verbose .levels )
627
+ validate_verbose = ValidateInStrings ('verbose' ,[
628
+ 'silent' , 'helpful' , 'debug' , 'debug-annoying' ,
629
+ ])
637
630
638
- validate_ps_papersize = ValidateInStrings ([
639
- 'auto' , 'letter' , 'legal' , 'ledger' ,
640
- 'a0' , 'a1' , 'a2' ,'a3' , 'a4' , 'a5' , 'a6' , 'a7' , 'a8' , 'a9' , 'a10' ,
641
- 'b0' , 'b1' , 'b2' , 'b3' , 'b4' , 'b5' , 'b6' , 'b7' , 'b8' , 'b9' , 'b10' ,
642
- ], ignorecase = True )
631
+ validate_ps_papersize = ValidateInStrings ('ps_papersize' , [
632
+ 'auto' , 'letter' , 'legal' , 'ledger' ,
633
+ 'a0' , 'a1' , 'a2' ,'a3' , 'a4' , 'a5' , 'a6' , 'a7' , 'a8' , 'a9' , 'a10' ,
634
+ 'b0' , 'b1' , 'b2' , 'b3' , 'b4' , 'b5' , 'b6' , 'b7' , 'b8' , 'b9' , 'b10' ,
635
+ ], ignorecase = True )
643
636
644
637
def validate_ps_distiller (s ):
645
638
s = s .lower ()
@@ -715,17 +708,17 @@ def validate_usetex(s):
715
708
else :
716
709
return bl
717
710
718
- validate_joinstyle = ValidateInStrings (['miter' , 'round' , 'bevel' ], ignorecase = True )
711
+ validate_joinstyle = ValidateInStrings ('joinstyle' , ['miter' , 'round' , 'bevel' ], ignorecase = True )
719
712
720
- validate_capstyle = ValidateInStrings (['butt' , 'round' , 'projecting' ], ignorecase = True )
713
+ validate_capstyle = ValidateInStrings ('capstyle' , ['butt' , 'round' , 'projecting' ], ignorecase = True )
721
714
722
715
def validate_linecol_linestyle (s ):
723
716
try :
724
717
dashes = validate_nseq_float (2 )(s )
725
718
warnings .warn ("Deprecated negative_linestyle specification; use 'solid' or 'dashed'" )
726
719
return (0 , dashes ) # (offset, (solid, blank))
727
720
except ValueError :
728
- V = ValidateInStrings (['solid' , 'dashed' ], ignorecase = True )
721
+ V = ValidateInStrings ('linecol_linestyle' , ['solid' , 'dashed' ], ignorecase = True )
729
722
return (V (s ))
730
723
731
724
class ValidateInterval :
0 commit comments