This file is indexed.

/usr/lib/python3/dist-packages/matplotlib/rcsetup.py is in python3-matplotlib 2.1.1-2ubuntu3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
"""
The rcsetup module contains the default values and the validation code for
customization using matplotlib's rc settings.

Each rc setting is assigned a default value and a function used to validate
any attempted changes to that setting. The default values and validation
functions are defined in the rcsetup module, and are used to construct the
rcParams global object which stores the settings and is referenced throughout
matplotlib.

These default values should be consistent with the default matplotlibrc file
that actually reflects the values given here. Any additions or deletions to the
parameter set listed here should also be visited to the
:file:`matplotlibrc.template` in matplotlib's root source directory.
"""
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

import six

from collections import Iterable, Mapping
from functools import reduce
import operator
import os
import warnings
import re

from matplotlib.cbook import mplDeprecation, deprecated, ls_mapper
from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
from matplotlib.colors import is_color_like


# Don't let the original cycler collide with our validating cycler
from cycler import Cycler, cycler as ccycler

# interactive_bk = ['gtk', 'gtkagg', 'gtkcairo', 'qt4agg',
#                  'tkagg', 'wx', 'wxagg', 'webagg']
# The capitalized forms are needed for ipython at present; this may
# change for later versions.

interactive_bk = ['GTK', 'GTKAgg', 'GTKCairo', 'MacOSX',
                  'Qt4Agg', 'Qt5Agg', 'TkAgg', 'WX', 'WXAgg',
                  'GTK3Cairo', 'GTK3Agg', 'WebAgg', 'nbAgg']


non_interactive_bk = ['agg', 'cairo', 'gdk',
                      'pdf', 'pgf', 'ps', 'svg', 'template']
all_backends = interactive_bk + non_interactive_bk


class ValidateInStrings(object):
    def __init__(self, key, valid, ignorecase=False):
        'valid is a list of legal strings'
        self.key = key
        self.ignorecase = ignorecase

        def func(s):
            if ignorecase:
                return s.lower()
            else:
                return s
        self.valid = {func(k): k for k in valid}

    def __call__(self, s):
        if self.ignorecase:
            s = s.lower()
        if s in self.valid:
            return self.valid[s]
        raise ValueError('Unrecognized %s string "%s": valid strings are %s'
                         % (self.key, s, list(six.itervalues(self.valid))))


def _listify_validator(scalar_validator, allow_stringlist=False):
    def f(s):
        if isinstance(s, six.string_types):
            try:
                return [scalar_validator(v.strip()) for v in s.split(',')
                        if v.strip()]
            except Exception:
                if allow_stringlist:
                    # Sometimes, a list of colors might be a single string
                    # of single-letter colornames. So give that a shot.
                    return [scalar_validator(v.strip()) for v in s if v.strip()]
                else:
                    raise
        # We should allow any generic sequence type, including generators,
        # Numpy ndarrays, and pandas data structures.  However, unordered
        # sequences, such as sets, should be allowed but discouraged unless the
        # user desires pseudorandom behavior.
        elif isinstance(s, Iterable) and not isinstance(s, Mapping):
            # The condition on this list comprehension will preserve the
            # behavior of filtering out any empty strings (behavior was
            # from the original validate_stringlist()), while allowing
            # any non-string/text scalar values such as numbers and arrays.
            return [scalar_validator(v) for v in s
                    if not isinstance(v, six.string_types) or v]
        else:
            raise ValueError("{!r} must be of type: string or non-dictionary "
                             "iterable".format(s))
    # Cast `str` to keep Py2 happy despite `unicode_literals`.
    try:
        f.__name__ = str("{}list".format(scalar_validator.__name__))
    except AttributeError:  # class instance.
        f.__name__ = str("{}List".format(type(scalar_validator).__name__))
    f.__doc__ = scalar_validator.__doc__
    return f


def validate_any(s):
    return s
validate_anylist = _listify_validator(validate_any)


def validate_path_exists(s):
    """If s is a path, return s, else False"""
    if s is None:
        return None
    if os.path.exists(s):
        return s
    else:
        raise RuntimeError('"%s" should be a path but it does not exist' % s)


def validate_bool(b):
    """Convert b to a boolean or raise"""
    if isinstance(b, six.string_types):
        b = b.lower()
    if b in ('t', 'y', 'yes', 'on', 'true', '1', 1, True):
        return True
    elif b in ('f', 'n', 'no', 'off', 'false', '0', 0, False):
        return False
    else:
        raise ValueError('Could not convert "%s" to boolean' % b)


def validate_bool_maybe_none(b):
    'Convert b to a boolean or raise'
    if isinstance(b, six.string_types):
        b = b.lower()
    if b is None or b == 'none':
        return None
    if b in ('t', 'y', 'yes', 'on', 'true', '1', 1, True):
        return True
    elif b in ('f', 'n', 'no', 'off', 'false', '0', 0, False):
        return False
    else:
        raise ValueError('Could not convert "%s" to boolean' % b)


def deprecate_axes_hold(value):
    if value is None:
        return None  # converted to True where accessed in figure.py,
                     # axes/_base.py
    warnings.warn("axes.hold is deprecated, will be removed in 3.0",
                  mplDeprecation)
    return validate_bool(value)


def validate_float(s):
    """convert s to float or raise"""
    try:
        return float(s)
    except ValueError:
        raise ValueError('Could not convert "%s" to float' % s)
validate_floatlist = _listify_validator(validate_float)


def validate_float_or_None(s):
    """convert s to float, None or raise"""
    # values directly from the rc file can only be strings,
    # so we need to recognize the string "None" and convert
    # it into the object. We will be case-sensitive here to
    # avoid confusion between string values of 'none', which
    # can be a valid string value for some other parameters.
    if s is None or s == 'None':
        return None
    try:
        return float(s)
    except ValueError:
        raise ValueError('Could not convert "%s" to float or None' % s)


def validate_string_or_None(s):
    """convert s to string or raise"""
    if s is None:
        return None
    try:
        return six.text_type(s)
    except ValueError:
        raise ValueError('Could not convert "%s" to string' % s)


def validate_axisbelow(s):
    try:
        return validate_bool(s)
    except ValueError:
        if isinstance(s, six.string_types):
            s = s.lower()
            if s.startswith('line'):
                return 'line'
    raise ValueError('%s cannot be interpreted as'
                     ' True, False, or "line"' % s)


def validate_dpi(s):
    """confirm s is string 'figure' or convert s to float or raise"""
    if s == 'figure':
        return s
    try:
        return float(s)
    except ValueError:
        raise ValueError('"%s" is not string "figure" or'
            ' could not convert "%s" to float' % (s, s))


def validate_int(s):
    """convert s to int or raise"""
    try:
        return int(s)
    except ValueError:
        raise ValueError('Could not convert "%s" to int' % s)


def validate_int_or_None(s):
    """if not None, tries to validate as an int"""
    if s=='None':
        s = None
    if s is None:
        return None
    try:
        return int(s)
    except ValueError:
        raise ValueError('Could not convert "%s" to int' % s)


def validate_fonttype(s):
    """
    confirm that this is a Postscript of PDF font type that we know how to
    convert to
    """
    fonttypes = {'type3':    3,
                 'truetype': 42}
    try:
        fonttype = validate_int(s)
    except ValueError:
        try:
            return fonttypes[s.lower()]
        except KeyError:
            raise ValueError(
                'Supported Postscript/PDF font types are %s' % list(fonttypes))
    else:
        if fonttype not in six.itervalues(fonttypes):
            raise ValueError(
                'Supported Postscript/PDF font types are %s' %
                list(six.itervalues(fonttypes)))
        return fonttype


_validate_standard_backends = ValidateInStrings(
    'backend', all_backends, ignorecase=True)


def validate_backend(s):
    if s.startswith('module://'):
        return s
    else:
        return _validate_standard_backends(s)


validate_qt4 = ValidateInStrings('backend.qt4', ['PyQt4', 'PySide', 'PyQt4v2'])
validate_qt5 = ValidateInStrings('backend.qt5', ['PyQt5', 'PySide2'])


def validate_toolbar(s):
    validator = ValidateInStrings(
                'toolbar',
                ['None', 'toolbar2', 'toolmanager'],
                ignorecase=True)
    return validator(s)


_seq_err_msg = ('You must supply exactly {n} values, you provided {num} '
                'values: {s}')

_str_err_msg = ('You must supply exactly {n} comma-separated values, you '
                'provided {num} comma-separated values: {s}')


class validate_nseq_float(object):
    def __init__(self, n=None, allow_none=False):
        self.n = n
        self.allow_none = allow_none

    def __call__(self, s):
        """return a seq of n floats or raise"""
        if isinstance(s, six.string_types):
            s = [x.strip() for x in s.split(',')]
            err_msg = _str_err_msg
        else:
            err_msg = _seq_err_msg

        if self.n is not None and len(s) != self.n:
            raise ValueError(err_msg.format(n=self.n, num=len(s), s=s))

        try:
            return [float(val)
                    if not self.allow_none or val is not None
                    else val
                    for val in s]
        except ValueError:
            raise ValueError('Could not convert all entries to floats')


class validate_nseq_int(object):
    def __init__(self, n=None):
        self.n = n

    def __call__(self, s):
        """return a seq of n ints or raise"""
        if isinstance(s, six.string_types):
            s = [x.strip() for x in s.split(',')]
            err_msg = _str_err_msg
        else:
            err_msg = _seq_err_msg

        if self.n is not None and len(s) != self.n:
            raise ValueError(err_msg.format(n=self.n, num=len(s), s=s))

        try:
            return [int(val) for val in s]
        except ValueError:
            raise ValueError('Could not convert all entries to ints')


def validate_color_or_inherit(s):
    'return a valid color arg'
    if s == 'inherit':
        return s
    return validate_color(s)


def validate_color_or_auto(s):
    if s == 'auto':
        return s
    return validate_color(s)


def validate_color_for_prop_cycle(s):
    # Special-case the N-th color cycle syntax, this obviously can not
    # go in the color cycle.
    if isinstance(s, bytes):
        match = re.match(b'^C[0-9]$', s)
        if match is not None:
            raise ValueError('Can not put cycle reference ({cn!r}) in '
                             'prop_cycler'.format(cn=s))
    elif isinstance(s, six.string_types):
        match = re.match('^C[0-9]$', s)
        if match is not None:
            raise ValueError('Can not put cycle reference ({cn!r}) in '
                             'prop_cycler'.format(cn=s))
    return validate_color(s)


def validate_color(s):
    'return a valid color arg'
    try:
        if s.lower() == 'none':
            return 'none'
    except AttributeError:
        pass

    if isinstance(s, six.string_types):
        if len(s) == 6 or len(s) == 8:
            stmp = '#' + s
            if is_color_like(stmp):
                return stmp

    if is_color_like(s):
        return s

    # If it is still valid, it must be a tuple.
    colorarg = s
    msg = ''
    if s.find(',') >= 0:
        # get rid of grouping symbols
        stmp = ''.join([c for c in s if c.isdigit() or c == '.' or c == ','])
        vals = stmp.split(',')
        if len(vals) not in [3, 4]:
            msg = '\nColor tuples must be of length 3 or 4'
        else:
            try:
                colorarg = [float(val) for val in vals]
            except ValueError:
                msg = '\nCould not convert all entries to floats'

    if not msg and is_color_like(colorarg):
        return colorarg

    raise ValueError('%s does not look like a color arg%s' % (s, msg))


def deprecate_axes_colorcycle(value):
    warnings.warn("axes.color_cycle is deprecated.  Use axes.prop_cycle "
                  "instead. Will be removed in 2.1.0",
                  mplDeprecation)
    return validate_colorlist(value)


validate_colorlist = _listify_validator(validate_color, allow_stringlist=True)
validate_colorlist.__doc__ = 'return a list of colorspecs'

validate_stringlist = _listify_validator(six.text_type)
validate_stringlist.__doc__ = 'return a list'

validate_orientation = ValidateInStrings(
    'orientation', ['landscape', 'portrait'])


def validate_aspect(s):
    if s in ('auto', 'equal'):
        return s
    try:
        return float(s)
    except ValueError:
        raise ValueError('not a valid aspect specification')


def validate_fontsize(s):
    fontsizes = ['xx-small', 'x-small', 'small', 'medium', 'large',
                 'x-large', 'xx-large', 'smaller', 'larger']
    if isinstance(s, six.string_types):
        s = s.lower()
    if s in fontsizes:
        return s
    try:
        return float(s)
    except ValueError:
        raise ValueError("%s is not a valid font size. Valid font sizes "
                         "are %s." % (s, ", ".join(fontsizes)))


validate_fontsizelist = _listify_validator(validate_fontsize)


def validate_font_properties(s):
    parse_fontconfig_pattern(s)
    return s


validate_fontset = ValidateInStrings(
    'fontset',
    ['dejavusans', 'dejavuserif', 'cm', 'stix', 'stixsans', 'custom'])

validate_mathtext_default = ValidateInStrings(
    'default',
    "rm cal it tt sf bf default bb frak circled scr regular".split())

validate_verbose = ValidateInStrings(
    'verbose',
    ['silent', 'helpful', 'debug', 'debug-annoying'])

_validate_alignment = ValidateInStrings(
    'alignment',
    ['center', 'top', 'bottom', 'baseline',
     'center_baseline'])

def validate_whiskers(s):
    if s == 'range':
        return 'range'
    else:
        try:
            v = validate_nseq_float(2)(s)
            return v
        except (TypeError, ValueError):
            try:
                v = float(s)
                return v
            except ValueError:
                raise ValueError("Not a valid whisker value ['range', float, "
                                 "(float, float)]")


def update_savefig_format(value):
    # The old savefig.extension could also have a value of "auto", but
    # the new savefig.format does not.  We need to fix this here.
    value = six.text_type(value)
    if value == 'auto':
        value = 'png'
    return value


validate_ps_papersize = ValidateInStrings(
    'ps_papersize',
    ['auto', 'letter', 'legal', 'ledger',
    'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'a10',
    'b0', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8', 'b9', 'b10',
    ], ignorecase=True)


def validate_ps_distiller(s):
    if isinstance(s, six.string_types):
        s = s.lower()
    if s in ('none', None):
        return None
    elif s in ('false', False):
        return False
    elif s in ('ghostscript', 'xpdf'):
        return s
    else:
        raise ValueError('matplotlibrc ps.usedistiller must either be none, '
                         'ghostscript or xpdf')

validate_joinstyle = ValidateInStrings('joinstyle',
                                       ['miter', 'round', 'bevel'],
                                       ignorecase=True)
validate_joinstylelist = _listify_validator(validate_joinstyle)

validate_capstyle = ValidateInStrings('capstyle',
                                      ['butt', 'round', 'projecting'],
                                      ignorecase=True)
validate_capstylelist = _listify_validator(validate_capstyle)

validate_fillstyle = ValidateInStrings('markers.fillstyle',
                                       ['full', 'left', 'right', 'bottom',
                                        'top', 'none'])
validate_fillstylelist = _listify_validator(validate_fillstyle)

_validate_negative_linestyle = ValidateInStrings('negative_linestyle',
                                                 ['solid', 'dashed'],
                                                 ignorecase=True)


@deprecated('2.1',
            addendum=(" See 'validate_negative_linestyle_legacy' " +
                      "deprecation warning for more information."))
def validate_negative_linestyle(s):
    return _validate_negative_linestyle(s)


@deprecated('2.1',
            addendum=(" The 'contour.negative_linestyle' rcParam now " +
                      "follows the same validation as the other rcParams " +
                      "that are related to line style."))
def validate_negative_linestyle_legacy(s):
    try:
        res = validate_negative_linestyle(s)
        return res
    except ValueError:
        dashes = validate_nseq_float(2)(s)
        return (0, dashes)  # (offset, (solid, blank))


def validate_corner_mask(s):
    if s == 'legacy':
        return s
    else:
        return validate_bool(s)


validate_legend_loc = ValidateInStrings(
    'legend_loc',
    ['best',
     'upper right',
     'upper left',
     'lower left',
     'lower right',
     'right',
     'center left',
     'center right',
     'lower center',
     'upper center',
     'center'], ignorecase=True)


def deprecate_svg_image_noscale(value):
    warnings.warn("svg.image_noscale is deprecated. Set "
                  "image.interpolation to 'none' instead.",
                  mplDeprecation)


def deprecate_svg_embed_char_paths(value):
    warnings.warn("svg.embed_char_paths is deprecated.  Use "
                  "svg.fonttype instead.",
                  mplDeprecation)


validate_svg_fonttype = ValidateInStrings('svg.fonttype',
                                          ['none', 'path', 'svgfont'])


def validate_hinting(s):
    if s in (True, False):
        return s
    if s.lower() in ('auto', 'native', 'either', 'none'):
        return s.lower()
    raise ValueError("hinting should be 'auto', 'native', 'either' or 'none'")

validate_pgf_texsystem = ValidateInStrings('pgf.texsystem',
                                           ['xelatex', 'lualatex', 'pdflatex'])

validate_movie_writer = ValidateInStrings('animation.writer',
    ['ffmpeg', 'ffmpeg_file',
     'avconv', 'avconv_file',
     'mencoder', 'mencoder_file',
     'imagemagick', 'imagemagick_file',
     'html'])

validate_movie_frame_fmt = ValidateInStrings('animation.frame_format',
    ['png', 'jpeg', 'tiff', 'raw', 'rgba'])

validate_axis_locator = ValidateInStrings('major', ['minor', 'both', 'major'])

validate_movie_html_fmt = ValidateInStrings('animation.html',
    ['html5', 'jshtml', 'none'])

def validate_bbox(s):
    if isinstance(s, six.string_types):
        s = s.lower()
        if s == 'tight':
            return s
        if s == 'standard':
            return None
        raise ValueError("bbox should be 'tight' or 'standard'")
    elif s is not None:
        # Backwards compatibility. None is equivalent to 'standard'.
        raise ValueError("bbox should be 'tight' or 'standard'")
    return s

def validate_sketch(s):
    if isinstance(s, six.string_types):
        s = s.lower()
    if s == 'none' or s is None:
        return None
    if isinstance(s, six.string_types):
        result = tuple([float(v.strip()) for v in s.split(',')])
    elif isinstance(s, (list, tuple)):
        result = tuple([float(v) for v in s])
    if len(result) != 3:
        raise ValueError("path.sketch must be a tuple (scale, length, randomness)")
    return result

class ValidateInterval(object):
    """
    Value must be in interval
    """
    def __init__(self, vmin, vmax, closedmin=True, closedmax=True):
        self.vmin = vmin
        self.vmax = vmax
        self.cmin = closedmin
        self.cmax = closedmax

    def __call__(self, s):
        try:
            s = float(s)
        except ValueError:
            raise RuntimeError('Value must be a float; found "%s"' % s)

        if self.cmin and s < self.vmin:
            raise RuntimeError('Value must be >= %f; found "%f"' %
                               (self.vmin, s))
        elif not self.cmin and s <= self.vmin:
            raise RuntimeError('Value must be > %f; found "%f"' %
                               (self.vmin, s))

        if self.cmax and s > self.vmax:
            raise RuntimeError('Value must be <= %f; found "%f"' %
                               (self.vmax, s))
        elif not self.cmax and s >= self.vmax:
            raise RuntimeError('Value must be < %f; found "%f"' %
                               (self.vmax, s))
        return s

validate_grid_axis = ValidateInStrings('axes.grid.axis', ['x', 'y', 'both'])


def validate_hatch(s):
    """
    Validate a hatch pattern.
    A hatch pattern string can have any sequence of the following
    characters: ``\\ / | - + * . x o O``.

    """
    if not isinstance(s, six.string_types):
        raise ValueError("Hatch pattern must be a string")
    unknown = set(s) - {'\\', '/', '|', '-', '+', '*', '.', 'x', 'o', 'O'}
    if unknown:
        raise ValueError("Unknown hatch symbol(s): %s" % list(unknown))
    return s
validate_hatchlist = _listify_validator(validate_hatch)
validate_dashlist = _listify_validator(validate_nseq_float(allow_none=True))

_prop_validators = {
        'color': _listify_validator(validate_color_for_prop_cycle,
                                    allow_stringlist=True),
        'linewidth': validate_floatlist,
        'linestyle': validate_stringlist,
        'facecolor': validate_colorlist,
        'edgecolor': validate_colorlist,
        'joinstyle': validate_joinstylelist,
        'capstyle': validate_capstylelist,
        'fillstyle': validate_fillstylelist,
        'markerfacecolor': validate_colorlist,
        'markersize': validate_floatlist,
        'markeredgewidth': validate_floatlist,
        'markeredgecolor': validate_colorlist,
        'alpha': validate_floatlist,
        'marker': validate_stringlist,
        'hatch': validate_hatchlist,
        'dashes': validate_dashlist,
    }
_prop_aliases = {
        'c': 'color',
        'lw': 'linewidth',
        'ls': 'linestyle',
        'fc': 'facecolor',
        'ec': 'edgecolor',
        'mfc': 'markerfacecolor',
        'mec': 'markeredgecolor',
        'mew': 'markeredgewidth',
        'ms': 'markersize',
    }


def cycler(*args, **kwargs):
    """
    Creates a :class:`cycler.Cycler` object much like :func:`cycler.cycler`,
    but includes input validation.

    cycler(arg)
    cycler(label, itr)
    cycler(label1=itr1[, label2=itr2[, ...]])

    Form 1 simply copies a given `Cycler` object.

    Form 2 creates a `Cycler` from a label and an iterable.

    Form 3 composes a `Cycler` as an inner product of the
    pairs of keyword arguments. In other words, all of the
    iterables are cycled simultaneously, as if through zip().

    Parameters
    ----------
    arg : Cycler
        Copy constructor for Cycler.

    label : name
        The property key. Must be a valid `Artist` property.
        For example, 'color' or 'linestyle'. Aliases are allowed,
        such as 'c' for 'color' and 'lw' for 'linewidth'.

    itr : iterable
        Finite-length iterable of the property values. These values
        are validated and will raise a ValueError if invalid.

    Returns
    -------
    cycler : Cycler
        New :class:`cycler.Cycler` for the given properties

    """
    if args and kwargs:
        raise TypeError("cycler() can only accept positional OR keyword "
                        "arguments -- not both.")
    elif not args and not kwargs:
        raise TypeError("cycler() must have positional OR keyword arguments")

    if len(args) == 1:
        if not isinstance(args[0], Cycler):
            raise TypeError("If only one positional argument given, it must "
                            " be a Cycler instance.")
        return validate_cycler(args[0])
    elif len(args) == 2:
        pairs = [(args[0], args[1])]
    elif len(args) > 2:
        raise TypeError("No more than 2 positional arguments allowed")
    else:
        pairs = six.iteritems(kwargs)

    validated = []
    for prop, vals in pairs:
        norm_prop = _prop_aliases.get(prop, prop)
        validator = _prop_validators.get(norm_prop, None)
        if validator is None:
            raise TypeError("Unknown artist property: %s" % prop)
        vals = validator(vals)
        # We will normalize the property names as well to reduce
        # the amount of alias handling code elsewhere.
        validated.append((norm_prop, vals))

    return reduce(operator.add, (ccycler(k, v) for k, v in validated))


def validate_cycler(s):
    'return a Cycler object from a string repr or the object itself'
    if isinstance(s, six.string_types):
        try:
            # TODO: We might want to rethink this...
            # While I think I have it quite locked down,
            # it is execution of arbitrary code without
            # sanitation.
            # Combine this with the possibility that rcparams
            # might come from the internet (future plans), this
            # could be downright dangerous.
            # I locked it down by only having the 'cycler()' function
            # available.
            # UPDATE: Partly plugging a security hole.
            # I really should have read this:
            # http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html
            # We should replace this eval with a combo of PyParsing and
            # ast.literal_eval()
            if '.__' in s.replace(' ', ''):
                raise ValueError("'%s' seems to have dunder methods. Raising"
                                 " an exception for your safety")
            s = eval(s, {'cycler': cycler, '__builtins__': {}})
        except BaseException as e:
            raise ValueError("'%s' is not a valid cycler construction: %s" %
                             (s, e))
    # Should make sure what comes from the above eval()
    # is a Cycler object.
    if isinstance(s, Cycler):
        cycler_inst = s
    else:
        raise ValueError("object was not a string or Cycler instance: %s" % s)

    unknowns = cycler_inst.keys - (set(_prop_validators) | set(_prop_aliases))
    if unknowns:
        raise ValueError("Unknown artist properties: %s" % unknowns)

    # Not a full validation, but it'll at least normalize property names
    # A fuller validation would require v0.10 of cycler.
    checker = set()
    for prop in cycler_inst.keys:
        norm_prop = _prop_aliases.get(prop, prop)
        if norm_prop != prop and norm_prop in cycler_inst.keys:
            raise ValueError("Cannot specify both '{0}' and alias '{1}'"
                             " in the same prop_cycle".format(norm_prop, prop))
        if norm_prop in checker:
            raise ValueError("Another property was already aliased to '{0}'."
                             " Collision normalizing '{1}'.".format(norm_prop,
                                                                    prop))
        checker.update([norm_prop])

    # This is just an extra-careful check, just in case there is some
    # edge-case I haven't thought of.
    assert len(checker) == len(cycler_inst.keys)

    # Now, it should be safe to mutate this cycler
    for prop in cycler_inst.keys:
        norm_prop = _prop_aliases.get(prop, prop)
        cycler_inst.change_key(prop, norm_prop)

    for key, vals in cycler_inst.by_key().items():
        _prop_validators[key](vals)

    return cycler_inst


def validate_hist_bins(s):
    if isinstance(s, six.string_types) and s == 'auto':
        return s
    try:
        return int(s)
    except (TypeError, ValueError):
        pass

    try:
        return validate_floatlist(s)
    except ValueError:
        pass

    raise ValueError("'hist.bins' must be 'auto', an int or " +
                     "a sequence of floats")

def validate_animation_writer_path(p):
    # Make sure it's a string and then figure out if the animations
    # are already loaded and reset the writers (which will validate
    # the path on next call)
    if not isinstance(p, six.string_types):
        raise ValueError("path must be a (unicode) string")
    from sys import modules
    # set dirty, so that the next call to the registry will re-evaluate
    # the state.
    # only set dirty if already loaded. If not loaded, the load will
    # trigger the checks.
    if "matplotlib.animation" in modules:
        modules["matplotlib.animation"].writers.set_dirty()
    return p

# A validator dedicated to the named line styles, based on the items in
# ls_mapper, and a list of possible strings read from Line2D.set_linestyle
_validate_named_linestyle = ValidateInStrings('linestyle',
                                              list(six.iterkeys(ls_mapper)) +
                                              list(six.itervalues(ls_mapper)) +
                                              ['None', 'none', ' ', ''],
                                              ignorecase=True)


def _validate_linestyle(ls):
    """
    A validator for all possible line styles, the named ones *and*
    the on-off ink sequences.
    """
    # Look first for a valid named line style, like '--' or 'solid'
    if isinstance(ls, six.string_types):
        try:
            return _validate_named_linestyle(ls)
        except (UnicodeDecodeError, KeyError):
            # On Python 2, string-like *ls*, like for example
            # 'solid'.encode('utf-16'), may raise a unicode error.
            raise ValueError("the linestyle string {!r} is not a valid "
                             "string.".format(ls))

    if isinstance(ls, (bytes, bytearray)):
        # On Python 2, a string-like *ls* should already have lead to a
        # successful return or to raising an exception. On Python 3, we have
        # to manually raise an exception in the case of a byte-like *ls*.
        # Otherwise, if *ls* is of even-length, it will be passed to the
        # instance of validate_nseq_float, which will return an absurd on-off
        # ink sequence...
        raise ValueError("linestyle {!r} neither looks like an on-off ink "
                         "sequence nor a valid string.".format(ls))

    # Look for an on-off ink sequence (in points) *of even length*.
    # Offset is set to None.
    try:
        if len(ls) % 2 != 0:
            raise ValueError("the linestyle sequence {!r} is not of even "
                             "length.".format(ls))

        return (None, validate_nseq_float()(ls))

    except (ValueError, TypeError):
        # TypeError can be raised inside the instance of validate_nseq_float,
        # by wrong types passed to float(), like NoneType.
        raise ValueError("linestyle {!r} is not a valid on-off ink "
                         "sequence.".format(ls))


# a map from key -> value, converter
defaultParams = {
    'backend':           ['Agg', validate_backend],  # agg is certainly
                                                      # present
    'backend_fallback':  [True, validate_bool],  # agg is certainly present
    'backend.qt4':       ['PyQt4', validate_qt4],
    'backend.qt5':       ['PyQt5', validate_qt5],
    'webagg.port':       [8988, validate_int],
    'webagg.open_in_browser': [True, validate_bool],
    'webagg.port_retries': [50, validate_int],
    'nbagg.transparent':       [True, validate_bool],
    'toolbar':           ['toolbar2', validate_toolbar],
    'datapath':          [None, validate_path_exists],  # handled by
                                                        # _get_data_path_cached
    'interactive':       [False, validate_bool],
    'timezone':          ['UTC', six.text_type],

    # the verbosity setting
    'verbose.level': ['silent', validate_verbose],
    'verbose.fileo': ['sys.stdout', six.text_type],

    # line props
    'lines.linewidth':       [1.5, validate_float],  # line width in points
    'lines.linestyle':       ['-', _validate_linestyle],  # solid line
    'lines.color':           ['C0', validate_color],  # first color in color cycle
    'lines.marker':          ['None', six.text_type],  # marker name
    'lines.markeredgewidth': [1.0, validate_float],
    'lines.markersize':      [6, validate_float],    # markersize, in points
    'lines.antialiased':     [True, validate_bool],  # antialiased (no jaggies)
    'lines.dash_joinstyle':  ['round', validate_joinstyle],
    'lines.solid_joinstyle': ['round', validate_joinstyle],
    'lines.dash_capstyle':   ['butt', validate_capstyle],
    'lines.solid_capstyle':  ['projecting', validate_capstyle],
    'lines.dashed_pattern':  [[3.7, 1.6], validate_nseq_float(allow_none=True)],
    'lines.dashdot_pattern': [[6.4, 1.6, 1, 1.6],
                              validate_nseq_float(allow_none=True)],
    'lines.dotted_pattern':  [[1, 1.65], validate_nseq_float(allow_none=True)],
    'lines.scale_dashes':  [True, validate_bool],

    # marker props
    'markers.fillstyle': ['full', validate_fillstyle],

    ## patch props
    'patch.linewidth':   [1.0, validate_float],     # line width in points
    'patch.edgecolor':   ['k', validate_color],
    'patch.force_edgecolor' : [False, validate_bool],
    'patch.facecolor':   ['C0', validate_color],    # first color in cycle
    'patch.antialiased': [True, validate_bool],     # antialiased (no jaggies)

    ## hatch props
    'hatch.color': ['k', validate_color],
    'hatch.linewidth': [1.0, validate_float],

    ## Histogram properties
    'hist.bins': [10, validate_hist_bins],

    ## Boxplot properties
    'boxplot.notch': [False, validate_bool],
    'boxplot.vertical': [True, validate_bool],
    'boxplot.whiskers': [1.5, validate_whiskers],
    'boxplot.bootstrap': [None, validate_int_or_None],
    'boxplot.patchartist': [False, validate_bool],
    'boxplot.showmeans': [False, validate_bool],
    'boxplot.showcaps': [True, validate_bool],
    'boxplot.showbox': [True, validate_bool],
    'boxplot.showfliers': [True, validate_bool],
    'boxplot.meanline': [False, validate_bool],

    'boxplot.flierprops.color': ['k', validate_color],
    'boxplot.flierprops.marker': ['o', six.text_type],
    'boxplot.flierprops.markerfacecolor': ['none', validate_color_or_auto],
    'boxplot.flierprops.markeredgecolor': ['k', validate_color],
    'boxplot.flierprops.markersize': [6, validate_float],
    'boxplot.flierprops.linestyle': ['none', _validate_linestyle],
    'boxplot.flierprops.linewidth': [1.0, validate_float],

    'boxplot.boxprops.color': ['k', validate_color],
    'boxplot.boxprops.linewidth': [1.0, validate_float],
    'boxplot.boxprops.linestyle': ['-', _validate_linestyle],

    'boxplot.whiskerprops.color': ['k', validate_color],
    'boxplot.whiskerprops.linewidth': [1.0, validate_float],
    'boxplot.whiskerprops.linestyle': ['-', _validate_linestyle],

    'boxplot.capprops.color': ['k', validate_color],
    'boxplot.capprops.linewidth': [1.0, validate_float],
    'boxplot.capprops.linestyle': ['-', _validate_linestyle],

    'boxplot.medianprops.color': ['C1', validate_color],
    'boxplot.medianprops.linewidth': [1.0, validate_float],
    'boxplot.medianprops.linestyle': ['-', _validate_linestyle],

    'boxplot.meanprops.color': ['C2', validate_color],
    'boxplot.meanprops.marker': ['^', six.text_type],
    'boxplot.meanprops.markerfacecolor': ['C2', validate_color],
    'boxplot.meanprops.markeredgecolor': ['C2', validate_color],
    'boxplot.meanprops.markersize': [6, validate_float],
    'boxplot.meanprops.linestyle': ['--', _validate_linestyle],
    'boxplot.meanprops.linewidth': [1.0, validate_float],

    ## font props
    'font.family':     [['sans-serif'], validate_stringlist],  # used by text object
    'font.style':      ['normal', six.text_type],
    'font.variant':    ['normal', six.text_type],
    'font.stretch':    ['normal', six.text_type],
    'font.weight':     ['normal', six.text_type],
    'font.size':       [10, validate_float],      # Base font size in points
    'font.serif':      [['DejaVu Serif', 'Bitstream Vera Serif',
                         'Computer Modern Roman',
                         'New Century Schoolbook', 'Century Schoolbook L',
                         'Utopia', 'ITC Bookman', 'Bookman',
                         'Nimbus Roman No9 L', 'Times New Roman',
                         'Times', 'Palatino', 'Charter', 'serif'],
                        validate_stringlist],
    'font.sans-serif': [['DejaVu Sans', 'Bitstream Vera Sans',
                         'Computer Modern Sans Serif',
                         'Lucida Grande', 'Verdana', 'Geneva', 'Lucid',
                         'Arial', 'Helvetica', 'Avant Garde', 'sans-serif'],
                        validate_stringlist],
    'font.cursive':    [['Apple Chancery', 'Textile', 'Zapf Chancery',
                         'Sand', 'Script MT', 'Felipa', 'cursive'],
                        validate_stringlist],
    'font.fantasy':    [['Comic Sans MS', 'Chicago', 'Charcoal', 'Impact'
                         'Western', 'Humor Sans', 'xkcd', 'fantasy'],
                        validate_stringlist],
    'font.monospace':  [['DejaVu Sans Mono', 'Bitstream Vera Sans Mono',
                         'Computer Modern Typewriter',
                         'Andale Mono', 'Nimbus Mono L', 'Courier New',
                         'Courier', 'Fixed', 'Terminal', 'monospace'],
                        validate_stringlist],

    # text props
    'text.color':          ['k', validate_color],     # black
    'text.usetex':         [False, validate_bool],
    'text.latex.unicode':  [False, validate_bool],
    'text.latex.preamble': [[''], validate_stringlist],
    'text.latex.preview':  [False, validate_bool],
    'text.dvipnghack':     [None, validate_bool_maybe_none],
    'text.hinting':        ['auto', validate_hinting],
    'text.hinting_factor': [8, validate_int],
    'text.antialiased':    [True, validate_bool],

    'mathtext.cal':            ['cursive', validate_font_properties],
    'mathtext.rm':             ['sans', validate_font_properties],
    'mathtext.tt':             ['monospace', validate_font_properties],
    'mathtext.it':             ['sans:italic', validate_font_properties],
    'mathtext.bf':             ['sans:bold', validate_font_properties],
    'mathtext.sf':             ['sans', validate_font_properties],
    'mathtext.fontset':        ['dejavusans', validate_fontset],
    'mathtext.default':        ['it', validate_mathtext_default],
    'mathtext.fallback_to_cm': [True, validate_bool],

    'image.aspect':        ['equal', validate_aspect],  # equal, auto, a number
    'image.interpolation': ['nearest', six.text_type],
    'image.cmap':          ['viridis', six.text_type],        # one of gray, jet, etc
    'image.lut':           [256, validate_int],  # lookup table
    'image.origin':        ['upper', six.text_type],  # lookup table
    'image.resample':      [True, validate_bool],
    # Specify whether vector graphics backends will combine all images on a
    # set of axes into a single composite image
    'image.composite_image': [True, validate_bool],

    # contour props
    'contour.negative_linestyle': ['dashed', _validate_linestyle],
    'contour.corner_mask':        [True, validate_corner_mask],

    # errorbar props
    'errorbar.capsize':      [0, validate_float],

    # axes props
    'axes.axisbelow':        ['line', validate_axisbelow],
    'axes.hold':             [None, deprecate_axes_hold],
    'axes.facecolor':        ['w', validate_color],  # background color; white
    'axes.edgecolor':        ['k', validate_color],  # edge color; black
    'axes.linewidth':        [0.8, validate_float],  # edge linewidth

    'axes.spines.left':      [True, validate_bool],  # Set visibility of axes
    'axes.spines.right':     [True, validate_bool],  # 'spines', the lines
    'axes.spines.bottom':    [True, validate_bool],  # around the chart
    'axes.spines.top':       [True, validate_bool],  # denoting data boundary

    'axes.titlesize':        ['large', validate_fontsize],  # fontsize of the
                                                            # axes title
    'axes.titleweight':      ['normal', six.text_type],  # font weight of axes title
    'axes.titlepad':         [6.0, validate_float],  # pad from axes top to title in points
    'axes.grid':             [False, validate_bool],   # display grid or not
    'axes.grid.which':       ['major', validate_axis_locator],  # set wether the gid are by
                                                                # default draw on 'major'
                                                                # 'minor' or 'both' kind of
                                                                # axis locator
    'axes.grid.axis':        ['both', validate_grid_axis], # grid type.
                                                      # Can be 'x', 'y', 'both'
    'axes.labelsize':        ['medium', validate_fontsize],  # fontsize of the
                                                             # x any y labels
    'axes.labelpad':         [4.0, validate_float], # space between label and axis
    'axes.labelweight':      ['normal', six.text_type],  # fontsize of the x any y labels
    'axes.labelcolor':       ['k', validate_color],    # color of axis label
    'axes.formatter.limits': [[-7, 7], validate_nseq_int(2)],
                               # use scientific notation if log10
                               # of the axis range is smaller than the
                               # first or larger than the second
    'axes.formatter.use_locale': [False, validate_bool],
                               # Use the current locale to format ticks
    'axes.formatter.use_mathtext': [False, validate_bool],
    'axes.formatter.min_exponent': [0, validate_int],  # minimum exponent to format in scientific notation
    'axes.formatter.useoffset': [True, validate_bool],
    'axes.formatter.offset_threshold': [4, validate_int],
    'axes.unicode_minus': [True, validate_bool],
    'axes.color_cycle': [
        ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728',
         '#9467bd', '#8c564b', '#e377c2', '#7f7f7f',
         '#bcbd22', '#17becf'],
                         deprecate_axes_colorcycle],  # cycle of plot
                                                      # line colors
    # This entry can be either a cycler object or a
    # string repr of a cycler-object, which gets eval()'ed
    # to create the object.
    'axes.prop_cycle': [
        ccycler('color',
                ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728',
                 '#9467bd', '#8c564b', '#e377c2', '#7f7f7f',
                 '#bcbd22', '#17becf']),
        validate_cycler],
    # If 'data', axes limits are set close to the data.
    # If 'round_numbers' axes limits are set to the nearest round numbers.
    'axes.autolimit_mode': [
        'data',
        ValidateInStrings('autolimit_mode', ['data', 'round_numbers'])],
    'axes.xmargin': [0.05, ValidateInterval(0, 1,
                                            closedmin=True,
                                            closedmax=True)],  # margin added to xaxis
    'axes.ymargin': [0.05, ValidateInterval(0, 1,
                                            closedmin=True,
                                            closedmax=True)],# margin added to yaxis

    'polaraxes.grid': [True, validate_bool],  # display polar grid or
                                                     # not
    'axes3d.grid': [True, validate_bool],  # display 3d grid

    # scatter props
    'scatter.marker': ['o', six.text_type],

    # TODO validate that these are valid datetime format strings
    'date.autoformatter.year': ['%Y', six.text_type],
    'date.autoformatter.month': ['%Y-%m', six.text_type],
    'date.autoformatter.day': ['%Y-%m-%d', six.text_type],
    'date.autoformatter.hour': ['%m-%d %H', six.text_type],
    'date.autoformatter.minute': ['%d %H:%M', six.text_type],
    'date.autoformatter.second': ['%H:%M:%S', six.text_type],
    'date.autoformatter.microsecond': ['%M:%S.%f', six.text_type],

    #legend properties
    'legend.fancybox': [True, validate_bool],
    'legend.loc': ['best', validate_legend_loc],
    # the number of points in the legend line
    'legend.numpoints': [1, validate_int],
    # the number of points in the legend line for scatter
    'legend.scatterpoints': [1, validate_int],
    'legend.fontsize': ['medium', validate_fontsize],
     # the relative size of legend markers vs. original
    'legend.markerscale': [1.0, validate_float],
    'legend.shadow': [False, validate_bool],
     # whether or not to draw a frame around legend
    'legend.frameon': [True, validate_bool],
     # alpha value of the legend frame
    'legend.framealpha': [0.8, validate_float_or_None],

    ## the following dimensions are in fraction of the font size
    'legend.borderpad': [0.4, validate_float],  # units are fontsize
    # the vertical space between the legend entries
    'legend.labelspacing': [0.5, validate_float],
    # the length of the legend lines
    'legend.handlelength': [2., validate_float],
    # the length of the legend lines
    'legend.handleheight': [0.7, validate_float],
    # the space between the legend line and legend text
    'legend.handletextpad': [.8, validate_float],
    # the border between the axes and legend edge
    'legend.borderaxespad': [0.5, validate_float],
    # the border between the axes and legend edge
    'legend.columnspacing': [2., validate_float],
    'legend.facecolor': ['inherit', validate_color_or_inherit],
    'legend.edgecolor': ['0.8', validate_color_or_inherit],

    # tick properties
    'xtick.top':         [False, validate_bool],   # draw ticks on the top side
    'xtick.bottom':      [True, validate_bool],   # draw ticks on the bottom side
    'xtick.major.size':  [3.5, validate_float],    # major xtick size in points
    'xtick.minor.size':  [2, validate_float],    # minor xtick size in points
    'xtick.major.width': [0.8, validate_float],  # major xtick width in points
    'xtick.minor.width': [0.6, validate_float],  # minor xtick width in points
    'xtick.major.pad':   [3.5, validate_float],    # distance to label in points
    'xtick.minor.pad':   [3.4, validate_float],    # distance to label in points
    'xtick.color':       ['k', validate_color],  # color of the xtick labels
    'xtick.minor.visible':   [False, validate_bool],    # visibility of the x axis minor ticks
    'xtick.minor.top':   [True, validate_bool],  # draw x axis top minor ticks
    'xtick.minor.bottom':    [True, validate_bool],    # draw x axis bottom minor ticks
    'xtick.major.top':   [True, validate_bool],  # draw x axis top major ticks
    'xtick.major.bottom':    [True, validate_bool],    # draw x axis bottom major ticks

    # fontsize of the xtick labels
    'xtick.labelsize':   ['medium', validate_fontsize],
    'xtick.direction':   ['out', six.text_type],            # direction of xticks
    'xtick.alignment': ["center", _validate_alignment],

    'ytick.left':        [True, validate_bool],  # draw ticks on the left side
    'ytick.right':       [False, validate_bool],  # draw ticks on the right side
    'ytick.major.size':  [3.5, validate_float],     # major ytick size in points
    'ytick.minor.size':  [2, validate_float],     # minor ytick size in points
    'ytick.major.width': [0.8, validate_float],   # major ytick width in points
    'ytick.minor.width': [0.6, validate_float],   # minor ytick width in points
    'ytick.major.pad':   [3.5, validate_float],     # distance to label in points
    'ytick.minor.pad':   [3.4, validate_float],     # distance to label in points
    'ytick.color':       ['k', validate_color],   # color of the ytick labels
    'ytick.minor.visible':   [False, validate_bool],    # visibility of the y axis minor ticks
    'ytick.minor.left':   [True, validate_bool],  # draw y axis left minor ticks
    'ytick.minor.right':    [True, validate_bool],    # draw y axis right minor ticks
    'ytick.major.left':   [True, validate_bool],  # draw y axis left major ticks
    'ytick.major.right':    [True, validate_bool],    # draw y axis right major ticks

    # fontsize of the ytick labels
    'ytick.labelsize':   ['medium', validate_fontsize],
    'ytick.direction':   ['out', six.text_type],            # direction of yticks
    'ytick.alignment': ["center_baseline", _validate_alignment],


    'grid.color':        ['#b0b0b0', validate_color],  # grid color
    'grid.linestyle':    ['-', _validate_linestyle],  # solid
    'grid.linewidth':    [0.8, validate_float],     # in points
    'grid.alpha':        [1.0, validate_float],


    ## figure props
    # figure title
    'figure.titlesize':   ['large', validate_fontsize],
    'figure.titleweight': ['normal', six.text_type],

    # figure size in inches: width by height
    'figure.figsize':    [[6.4, 4.8], validate_nseq_float(2)],
    'figure.dpi':        [100, validate_float],  # DPI
    'figure.facecolor':  ['w', validate_color],  # facecolor; white
    'figure.edgecolor':  ['w', validate_color],  # edgecolor; white
    'figure.frameon':    [True, validate_bool],
    'figure.autolayout': [False, validate_bool],
    'figure.max_open_warning': [20, validate_int],

    'figure.subplot.left': [0.125, ValidateInterval(0, 1, closedmin=True,
                                                       closedmax=True)],
    'figure.subplot.right': [0.9, ValidateInterval(0, 1, closedmin=True,
                                                     closedmax=True)],
    'figure.subplot.bottom': [0.11, ValidateInterval(0, 1, closedmin=True,
                                                     closedmax=True)],
    'figure.subplot.top': [0.88, ValidateInterval(0, 1, closedmin=True,
                                                     closedmax=True)],
    'figure.subplot.wspace': [0.2, ValidateInterval(0, 1, closedmin=True,
                                                     closedmax=False)],
    'figure.subplot.hspace': [0.2, ValidateInterval(0, 1, closedmin=True,
                                                     closedmax=False)],

    ## Saving figure's properties
    'savefig.dpi':         ['figure', validate_dpi],  # DPI
    'savefig.facecolor':   ['w', validate_color],  # facecolor; white
    'savefig.edgecolor':   ['w', validate_color],  # edgecolor; white
    'savefig.frameon':     [True, validate_bool],
    'savefig.orientation': ['portrait', validate_orientation],  # edgecolor;
                                                                 #white
    'savefig.jpeg_quality': [95, validate_int],
    # value checked by backend at runtime
    'savefig.format':     ['png', update_savefig_format],
    # options are 'tight', or 'standard'. 'standard' validates to None.
    'savefig.bbox':       ['standard', validate_bbox],
    'savefig.pad_inches': [0.1, validate_float],
    # default directory in savefig dialog box
    'savefig.directory': ['~', six.text_type],
    'savefig.transparent': [False, validate_bool],

    # Maintain shell focus for TkAgg
    'tk.window_focus':  [False, validate_bool],

    # Set the papersize/type
    'ps.papersize':     ['letter', validate_ps_papersize],
    'ps.useafm':        [False, validate_bool],  # Set PYTHONINSPECT
    # use ghostscript or xpdf to distill ps output
    'ps.usedistiller':  [False, validate_ps_distiller],
    'ps.distiller.res': [6000, validate_int],     # dpi
    'ps.fonttype':      [3, validate_fonttype],  # 3 (Type3) or 42 (Truetype)
    # compression level from 0 to 9; 0 to disable
    'pdf.compression':  [6, validate_int],
    # ignore any color-setting commands from the frontend
    'pdf.inheritcolor': [False, validate_bool],
    # use only the 14 PDF core fonts embedded in every PDF viewing application
    'pdf.use14corefonts': [False, validate_bool],
    'pdf.fonttype':     [3, validate_fonttype],  # 3 (Type3) or 42 (Truetype)

    'pgf.debug':     [False, validate_bool],  # output debug information
    # choose latex application for creating pdf files (xelatex/lualatex)
    'pgf.texsystem': ['xelatex', validate_pgf_texsystem],
    # use matplotlib rc settings for font configuration
    'pgf.rcfonts':   [True, validate_bool],
    # provide a custom preamble for the latex process
    'pgf.preamble':  [[''], validate_stringlist],

    # write raster image data directly into the svg file
    'svg.image_inline':     [True, validate_bool],
    # suppress scaling of raster data embedded in SVG
    'svg.image_noscale':    [False, deprecate_svg_image_noscale],
    # True to save all characters as paths in the SVG
    'svg.embed_char_paths': [True, deprecate_svg_embed_char_paths],
    'svg.fonttype':         ['path', validate_svg_fonttype],
    'svg.hashsalt':         [None, validate_string_or_None],

    # set this when you want to generate hardcopy docstring
    'docstring.hardcopy': [False, validate_bool],
    # where plugin directory is locate
    'plugins.directory':  ['.matplotlib_plugins', six.text_type],

    'path.simplify': [True, validate_bool],
    'path.simplify_threshold': [1.0 / 9.0, ValidateInterval(0.0, 1.0)],
    'path.snap': [True, validate_bool],
    'path.sketch': [None, validate_sketch],
    'path.effects': [[], validate_any],
    'agg.path.chunksize': [0, validate_int],       # 0 to disable chunking;

    # key-mappings (multi-character mappings should be a list/tuple)
    'keymap.fullscreen':   [('f', 'ctrl+f'), validate_stringlist],
    'keymap.home':         [['h', 'r', 'home'], validate_stringlist],
    'keymap.back':         [['left', 'c', 'backspace'], validate_stringlist],
    'keymap.forward':      [['right', 'v'], validate_stringlist],
    'keymap.pan':          [['p'], validate_stringlist],
    'keymap.zoom':         [['o'], validate_stringlist],
    'keymap.save':         [['s', 'ctrl+s'], validate_stringlist],
    'keymap.quit':         [['ctrl+w', 'cmd+w', 'q'], validate_stringlist],
    'keymap.quit_all':     [['W', 'cmd+W', 'Q'], validate_stringlist],
    'keymap.grid':         [['g'], validate_stringlist],
    'keymap.grid_minor':   [['G'], validate_stringlist],
    'keymap.yscale':       [['l'], validate_stringlist],
    'keymap.xscale':       [['k', 'L'], validate_stringlist],
    'keymap.all_axes':     [['a'], validate_stringlist],

    # sample data
    'examples.directory': ['', six.text_type],

    # Animation settings
    'animation.html':         ['none', validate_movie_html_fmt],
    # Limit, in MB, of size of base64 encoded animation in HTML
    # (i.e. IPython notebook)
    'animation.embed_limit':  [20, validate_float],
    'animation.writer':       ['ffmpeg', validate_movie_writer],
    'animation.codec':        ['h264', six.text_type],
    'animation.bitrate':      [-1, validate_int],
    # Controls image format when frames are written to disk
    'animation.frame_format': ['png', validate_movie_frame_fmt],
    # Additional arguments for HTML writer
    'animation.html_args':    [[], validate_stringlist],
    # Path to FFMPEG binary. If just binary name, subprocess uses $PATH.
    'animation.ffmpeg_path':  ['ffmpeg', validate_animation_writer_path],

    # Additional arguments for ffmpeg movie writer (using pipes)
    'animation.ffmpeg_args':   [[], validate_stringlist],
    # Path to AVConv binary. If just binary name, subprocess uses $PATH.
    'animation.avconv_path':   ['avconv', validate_animation_writer_path],
    # Additional arguments for avconv movie writer (using pipes)
    'animation.avconv_args':   [[], validate_stringlist],
    # Path to MENCODER binary. If just binary name, subprocess uses $PATH.
    'animation.mencoder_path': ['mencoder', validate_animation_writer_path],
    # Additional arguments for mencoder movie writer (using pipes)
    'animation.mencoder_args': [[], validate_stringlist],
     # Path to convert binary. If just binary name, subprocess uses $PATH
    'animation.convert_path':  ['convert', validate_animation_writer_path],
     # Additional arguments for mencoder movie writer (using pipes)

    'animation.convert_args':  [[], validate_stringlist],

    # Classic (pre 2.0) compatibility mode
    # This is used for things that are hard to make backward compatible
    # with a sane rcParam alone.  This does *not* turn on classic mode
    # altogether.  For that use `matplotlib.style.use('classic')`.
    '_internal.classic_mode': [False, validate_bool]
}


if __name__ == '__main__':
    rc = defaultParams
    rc['datapath'][0] = '/'
    for key in rc:
        if not rc[key][1](rc[key][0]) == rc[key][0]:
            print("%s: %s != %s" % (key, rc[key][1](rc[key][0]), rc[key][0]))