src/reportlab/lib/validators.py
author rptlab
Tue, 30 Apr 2013 14:28:14 +0100
branchpy33
changeset 3723 99aa837b6703
parent 3721 0c93dd8ff567
child 3731 b233dd0577ff
permissions -rw-r--r--
second stage of port to Python 3.3; working hello world
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3625
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
     1
#Copyright ReportLab Europe Ltd. 2000-2004
1559
2bb75ab0d0aa Added __version__
rgbecker
parents: 1391
diff changeset
     2
#see license.txt for license details
2332
2a7ab4405e18 Remove $Header:, fix CopyRight & history
rgbecker
parents: 2321
diff changeset
     3
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/lib/validators.py
2321
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2174
diff changeset
     4
__version__=''' $Id$ '''
3029
eded59f94021 adding docstrings to lib
andy
parents: 2964
diff changeset
     5
__doc__="""Standard verifying functions used by attrmap."""
908
3564ccbf97e6 Added future validators module (stripped off from shapes.py).
dinu_gherman
parents:
diff changeset
     6
2616
e3f68f895246 codec validator for diagra
andy
parents: 2575
diff changeset
     7
import string, sys, codecs
2115
27659c242d23 Attempt at allowing isBoolean(True)
rgbecker
parents: 1963
diff changeset
     8
from types import *
945
4c7026f40785 New Scheme Validators
rgbecker
parents: 941
diff changeset
     9
_SequenceTypes = (ListType,TupleType)
4c7026f40785 New Scheme Validators
rgbecker
parents: 941
diff changeset
    10
_NumberTypes = (FloatType,IntType)
908
3564ccbf97e6 Added future validators module (stripped off from shapes.py).
dinu_gherman
parents:
diff changeset
    11
from reportlab.lib import colors
2120
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
    12
if sys.hexversion<0x2030000:
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
    13
    True = 1
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
    14
    False = 0
908
3564ccbf97e6 Added future validators module (stripped off from shapes.py).
dinu_gherman
parents:
diff changeset
    15
3625
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
    16
class Percentage(float):
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
    17
    pass
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
    18
945
4c7026f40785 New Scheme Validators
rgbecker
parents: 941
diff changeset
    19
class Validator:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    20
    "base validator class"
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    21
    def __call__(self,x):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    22
        return self.test(x)
945
4c7026f40785 New Scheme Validators
rgbecker
parents: 941
diff changeset
    23
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    24
    def __str__(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    25
        return getattr(self,'_str',self.__class__.__name__)
908
3564ccbf97e6 Added future validators module (stripped off from shapes.py).
dinu_gherman
parents:
diff changeset
    26
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    27
    def normalize(self,x):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    28
        return x
931
07db840b3db6 Changed validator functions into classes.
dinu_gherman
parents: 909
diff changeset
    29
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    30
    def normalizeTest(self,x):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    31
        try:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    32
            self.normalize(x)
2120
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
    33
            return True
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    34
        except:
2120
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
    35
            return False
908
3564ccbf97e6 Added future validators module (stripped off from shapes.py).
dinu_gherman
parents:
diff changeset
    36
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
    37
class _isAnything(Validator):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    38
    def test(self,x):
2120
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
    39
        return True
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
    40
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
    41
class _isNothing(Validator):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    42
    def test(self,x):
2120
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
    43
        return False
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
    44
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
    45
class _isBoolean(Validator):
2115
27659c242d23 Attempt at allowing isBoolean(True)
rgbecker
parents: 1963
diff changeset
    46
    if sys.hexversion>=0x2030000:
27659c242d23 Attempt at allowing isBoolean(True)
rgbecker
parents: 1963
diff changeset
    47
        def test(self,x):
27659c242d23 Attempt at allowing isBoolean(True)
rgbecker
parents: 1963
diff changeset
    48
            if type(x) in (IntType,BooleanType): return x in (0,1)
27659c242d23 Attempt at allowing isBoolean(True)
rgbecker
parents: 1963
diff changeset
    49
            return self.normalizeTest(x)
27659c242d23 Attempt at allowing isBoolean(True)
rgbecker
parents: 1963
diff changeset
    50
    else:
27659c242d23 Attempt at allowing isBoolean(True)
rgbecker
parents: 1963
diff changeset
    51
        def test(self,x):
27659c242d23 Attempt at allowing isBoolean(True)
rgbecker
parents: 1963
diff changeset
    52
            if type(x) is IntType: return x in (0,1)
27659c242d23 Attempt at allowing isBoolean(True)
rgbecker
parents: 1963
diff changeset
    53
            return self.normalizeTest(x)
931
07db840b3db6 Changed validator functions into classes.
dinu_gherman
parents: 909
diff changeset
    54
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    55
    def normalize(self,x):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    56
        if x in (0,1): return x
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    57
        try:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    58
            S = string.upper(x)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    59
        except:
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3645
diff changeset
    60
            raise ValueError('Must be boolean')
2120
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
    61
        if S in ('YES','TRUE'): return True
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
    62
        if S in ('NO','FALSE',None): return False
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3645
diff changeset
    63
        raise ValueError('Must be boolean')
909
a5ee7d2bdb17 Extracted validator functions into lib.validators.
dinu_gherman
parents: 908
diff changeset
    64
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
    65
class _isString(Validator):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    66
    def test(self,x):
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3645
diff changeset
    67
        return isinstance(x,str)
931
07db840b3db6 Changed validator functions into classes.
dinu_gherman
parents: 909
diff changeset
    68
2616
e3f68f895246 codec validator for diagra
andy
parents: 2575
diff changeset
    69
class _isCodec(Validator):
e3f68f895246 codec validator for diagra
andy
parents: 2575
diff changeset
    70
    def test(self,x):
e3f68f895246 codec validator for diagra
andy
parents: 2575
diff changeset
    71
        if type(x) not in (StringType, UnicodeType):
e3f68f895246 codec validator for diagra
andy
parents: 2575
diff changeset
    72
            return False
e3f68f895246 codec validator for diagra
andy
parents: 2575
diff changeset
    73
        try:
e3f68f895246 codec validator for diagra
andy
parents: 2575
diff changeset
    74
            a,b,c,d = codecs.lookup(x)
e3f68f895246 codec validator for diagra
andy
parents: 2575
diff changeset
    75
            return True
e3f68f895246 codec validator for diagra
andy
parents: 2575
diff changeset
    76
        except LookupError:
e3f68f895246 codec validator for diagra
andy
parents: 2575
diff changeset
    77
            return False
e3f68f895246 codec validator for diagra
andy
parents: 2575
diff changeset
    78
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
    79
class _isNumber(Validator):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    80
    def test(self,x):
2120
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
    81
        if type(x) in _NumberTypes: return True
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    82
        return self.normalizeTest(x)
931
07db840b3db6 Changed validator functions into classes.
dinu_gherman
parents: 909
diff changeset
    83
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    84
    def normalize(self,x):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    85
        try:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    86
            return float(x)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    87
        except:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    88
            return int(x)
908
3564ccbf97e6 Added future validators module (stripped off from shapes.py).
dinu_gherman
parents:
diff changeset
    89
1055
30ca3865f6ed Added isInt and changed SequenceOf and OneOf to be more friendly
rgbecker
parents: 1022
diff changeset
    90
class _isInt(Validator):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    91
    def test(self,x):
2120
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
    92
        if type(x) not in (IntType,StringType): return False
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    93
        return self.normalizeTest(x)
1055
30ca3865f6ed Added isInt and changed SequenceOf and OneOf to be more friendly
rgbecker
parents: 1022
diff changeset
    94
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    95
    def normalize(self,x):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    96
        return int(x)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
    97
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
    98
class _isNumberOrNone(_isNumber):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    99
    def test(self,x):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   100
        return x is None or isNumber(x)
908
3564ccbf97e6 Added future validators module (stripped off from shapes.py).
dinu_gherman
parents:
diff changeset
   101
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   102
    def normalize(self,x):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   103
        if x is None: return x
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   104
        return _isNumber.normalize(x)
908
3564ccbf97e6 Added future validators module (stripped off from shapes.py).
dinu_gherman
parents:
diff changeset
   105
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
   106
class _isListOfNumbersOrNone(Validator):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   107
    "ListOfNumbersOrNone validator class."
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   108
    def test(self, x):
2120
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
   109
        if x is None: return True
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   110
        return isListOfNumbers(x)
931
07db840b3db6 Changed validator functions into classes.
dinu_gherman
parents: 909
diff changeset
   111
3198
683ca9eb6b18 reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents: 3029
diff changeset
   112
class isNumberInRange(_isNumber):
683ca9eb6b18 reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents: 3029
diff changeset
   113
    def __init__(self, min, max):
683ca9eb6b18 reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents: 3029
diff changeset
   114
        self.min = min
683ca9eb6b18 reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents: 3029
diff changeset
   115
        self.max = max
683ca9eb6b18 reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents: 3029
diff changeset
   116
683ca9eb6b18 reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents: 3029
diff changeset
   117
    def test(self, x):
683ca9eb6b18 reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents: 3029
diff changeset
   118
        try:
683ca9eb6b18 reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents: 3029
diff changeset
   119
            n = self.normalize(x)
683ca9eb6b18 reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents: 3029
diff changeset
   120
            if self.min <= n <= self.max:
683ca9eb6b18 reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents: 3029
diff changeset
   121
                return True
683ca9eb6b18 reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents: 3029
diff changeset
   122
        except ValueError:
683ca9eb6b18 reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents: 3029
diff changeset
   123
            pass
683ca9eb6b18 reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents: 3029
diff changeset
   124
        return False
3219
b28d6eef8227 reportlab: add support for String anchor 'numeric'
rgbecker
parents: 3198
diff changeset
   125
3198
683ca9eb6b18 reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents: 3029
diff changeset
   126
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
   127
class _isListOfShapes(Validator):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   128
    "ListOfShapes validator class."
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   129
    def test(self, x):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   130
        from reportlab.graphics.shapes import Shape
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   131
        if type(x) in _SequenceTypes:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   132
            answer = 1
2775
b6a79c190a5e validators.py: fix bug in isListOfShapes
rgbecker
parents: 2616
diff changeset
   133
            for e in x:
b6a79c190a5e validators.py: fix bug in isListOfShapes
rgbecker
parents: 2616
diff changeset
   134
                if not isinstance(e, Shape):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   135
                    answer = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   136
            return answer
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   137
        else:
2120
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
   138
            return False
931
07db840b3db6 Changed validator functions into classes.
dinu_gherman
parents: 909
diff changeset
   139
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
   140
class _isListOfStringsOrNone(Validator):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   141
    "ListOfStringsOrNone validator class."
931
07db840b3db6 Changed validator functions into classes.
dinu_gherman
parents: 909
diff changeset
   142
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   143
    def test(self, x):
2120
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
   144
        if x is None: return True
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   145
        return isListOfStrings(x)
931
07db840b3db6 Changed validator functions into classes.
dinu_gherman
parents: 909
diff changeset
   146
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
   147
class _isTransform(Validator):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   148
    "Transform validator class."
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   149
    def test(self, x):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   150
        if type(x) in _SequenceTypes:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   151
            if len(x) == 6:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   152
                for element in x:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   153
                    if not isNumber(element):
2120
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
   154
                        return False
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
   155
                return True
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   156
            else:
2120
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
   157
                return False
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   158
        else:
2120
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
   159
            return False
908
3564ccbf97e6 Added future validators module (stripped off from shapes.py).
dinu_gherman
parents:
diff changeset
   160
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
   161
class _isColor(Validator):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   162
    "Color validator class."
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   163
    def test(self, x):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   164
        return isinstance(x, colors.Color)
908
3564ccbf97e6 Added future validators module (stripped off from shapes.py).
dinu_gherman
parents:
diff changeset
   165
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
   166
class _isColorOrNone(Validator):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   167
    "ColorOrNone validator class."
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   168
    def test(self, x):
2120
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
   169
        if x is None: return True
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   170
        return isColor(x)
908
3564ccbf97e6 Added future validators module (stripped off from shapes.py).
dinu_gherman
parents:
diff changeset
   171
3339
26eb637a7f55 validators.py: add isNormalDate
rgbecker
parents: 3326
diff changeset
   172
from reportlab.lib.normalDate import NormalDate
26eb637a7f55 validators.py: add isNormalDate
rgbecker
parents: 3326
diff changeset
   173
class _isNormalDate(Validator):
26eb637a7f55 validators.py: add isNormalDate
rgbecker
parents: 3326
diff changeset
   174
    def test(self,x):
26eb637a7f55 validators.py: add isNormalDate
rgbecker
parents: 3326
diff changeset
   175
        if isinstance(x,NormalDate):
26eb637a7f55 validators.py: add isNormalDate
rgbecker
parents: 3326
diff changeset
   176
            return True
3418
25f506eaf3c1 validators.py: fix _isNormalDate
rgbecker
parents: 3357
diff changeset
   177
        return x is not None and self.normalizeTest(x)
3339
26eb637a7f55 validators.py: add isNormalDate
rgbecker
parents: 3326
diff changeset
   178
26eb637a7f55 validators.py: add isNormalDate
rgbecker
parents: 3326
diff changeset
   179
    def normalize(self,x):
26eb637a7f55 validators.py: add isNormalDate
rgbecker
parents: 3326
diff changeset
   180
        return NormalDate(x)
26eb637a7f55 validators.py: add isNormalDate
rgbecker
parents: 3326
diff changeset
   181
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
   182
class _isValidChild(Validator):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   183
    "ValidChild validator class."
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   184
    def test(self, x):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   185
        """Is this child allowed in a drawing or group?
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   186
        I.e. does it descend from Shape or UserNode?
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   187
        """
931
07db840b3db6 Changed validator functions into classes.
dinu_gherman
parents: 909
diff changeset
   188
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   189
        from reportlab.graphics.shapes import UserNode, Shape
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   190
        return isinstance(x, UserNode) or isinstance(x, Shape)
931
07db840b3db6 Changed validator functions into classes.
dinu_gherman
parents: 909
diff changeset
   191
1083
cb535e133d57 Added isValidChildOrNone
rgbecker
parents: 1059
diff changeset
   192
class _isValidChildOrNone(_isValidChild):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   193
    def test(self,x):
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2573
diff changeset
   194
        return _isValidChild.test(self,x) or x is None
1083
cb535e133d57 Added isValidChildOrNone
rgbecker
parents: 1059
diff changeset
   195
1391
35552052df99 Added a _isCallable + a couple of new vaildators
rgbecker
parents: 1385
diff changeset
   196
class _isCallable(Validator):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   197
    def test(self, x):
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3219
diff changeset
   198
        return hasattr(x,'__call__')
1391
35552052df99 Added a _isCallable + a couple of new vaildators
rgbecker
parents: 1385
diff changeset
   199
931
07db840b3db6 Changed validator functions into classes.
dinu_gherman
parents: 909
diff changeset
   200
class OneOf(Validator):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   201
    """Make validator functions for list of choices.
931
07db840b3db6 Changed validator functions into classes.
dinu_gherman
parents: 909
diff changeset
   202
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   203
    Usage:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   204
    f = reportlab.lib.validators.OneOf('happy','sad')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   205
    or
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   206
    f = reportlab.lib.validators.OneOf(('happy','sad'))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   207
    f('sad'),f('happy'), f('grumpy')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   208
    (1,1,0)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   209
    """
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   210
    def __init__(self, enum,*args):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   211
        if type(enum) in [ListType,TupleType]:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   212
            if args!=():
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3645
diff changeset
   213
                raise ValueError("Either all singleton args or a single sequence argument")
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   214
            self._enum = tuple(enum)+args
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   215
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   216
            self._enum = (enum,)+args
908
3564ccbf97e6 Added future validators module (stripped off from shapes.py).
dinu_gherman
parents:
diff changeset
   217
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   218
    def test(self, x):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   219
        return x in self._enum
931
07db840b3db6 Changed validator functions into classes.
dinu_gherman
parents: 909
diff changeset
   220
945
4c7026f40785 New Scheme Validators
rgbecker
parents: 941
diff changeset
   221
class SequenceOf(Validator):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   222
    def __init__(self,elemTest,name=None,emptyOK=1, NoneOK=0, lo=0,hi=0x7fffffff):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   223
        self._elemTest = elemTest
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   224
        self._emptyOK = emptyOK
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   225
        self._NoneOK = NoneOK
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   226
        self._lo, self._hi = lo, hi
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   227
        if name: self._str = name
908
3564ccbf97e6 Added future validators module (stripped off from shapes.py).
dinu_gherman
parents:
diff changeset
   228
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   229
    def test(self, x):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   230
        if type(x) not in _SequenceTypes:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   231
            if x is None: return self._NoneOK
2120
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
   232
            return False
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   233
        if x==[] or x==():
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   234
            return self._emptyOK
2120
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
   235
        elif not self._lo<=len(x)<=self._hi: return False
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   236
        for e in x:
2120
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
   237
            if not self._elemTest(e): return False
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
   238
        return True
908
3564ccbf97e6 Added future validators module (stripped off from shapes.py).
dinu_gherman
parents:
diff changeset
   239
1385
5d88aaeb63af Fixed EitherOr
rgbecker
parents: 1365
diff changeset
   240
class EitherOr(Validator):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   241
    def __init__(self,tests,name=None):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   242
        if type(tests) not in _SequenceTypes: tests = (tests,)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   243
        self._tests = tests
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   244
        if name: self._str = name
1385
5d88aaeb63af Fixed EitherOr
rgbecker
parents: 1365
diff changeset
   245
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   246
    def test(self, x):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   247
        for t in self._tests:
2120
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
   248
            if t(x): return True
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
   249
        return False
1385
5d88aaeb63af Fixed EitherOr
rgbecker
parents: 1365
diff changeset
   250
1197
d7ce043c87b4 Added NoneOr and various specialized validators
rgbecker
parents: 1083
diff changeset
   251
class NoneOr(Validator):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   252
    def __init__(self,elemTest,name=None):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   253
        self._elemTest = elemTest
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   254
        if name: self._str = name
1197
d7ce043c87b4 Added NoneOr and various specialized validators
rgbecker
parents: 1083
diff changeset
   255
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   256
    def test(self, x):
2120
211d3391bd9d Allow for True/False
rgbecker
parents: 2115
diff changeset
   257
        if x is None: return True
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   258
        return self._elemTest(x)
1197
d7ce043c87b4 Added NoneOr and various specialized validators
rgbecker
parents: 1083
diff changeset
   259
2424
101cf0c8500e validators.py: better auto support
rgbecker
parents: 2421
diff changeset
   260
class Auto(Validator):
2426
fac927fa6f7c Auto Legends
rgbecker
parents: 2424
diff changeset
   261
    def __init__(self,**kw):
fac927fa6f7c Auto Legends
rgbecker
parents: 2424
diff changeset
   262
        self.__dict__.update(kw)
fac927fa6f7c Auto Legends
rgbecker
parents: 2424
diff changeset
   263
2424
101cf0c8500e validators.py: better auto support
rgbecker
parents: 2421
diff changeset
   264
    def test(self,x):
2426
fac927fa6f7c Auto Legends
rgbecker
parents: 2424
diff changeset
   265
        return x is self.__class__ or isinstance(x,self.__class__)
2424
101cf0c8500e validators.py: better auto support
rgbecker
parents: 2421
diff changeset
   266
2421
3d4a0d0858a0 validators.py: forgot to check in with AutoOr
rgbecker
parents: 2341
diff changeset
   267
class AutoOr(NoneOr):
3d4a0d0858a0 validators.py: forgot to check in with AutoOr
rgbecker
parents: 2341
diff changeset
   268
    def test(self,x):
2426
fac927fa6f7c Auto Legends
rgbecker
parents: 2424
diff changeset
   269
        return isAuto(x) or self._elemTest(x)
2421
3d4a0d0858a0 validators.py: forgot to check in with AutoOr
rgbecker
parents: 2341
diff changeset
   270
1248
d0c16c9d621a Added isInstanceOf
rgbecker
parents: 1246
diff changeset
   271
class isInstanceOf(Validator):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   272
    def __init__(self,klass=None):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   273
        self._klass = klass
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   274
    def test(self,x):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   275
        return isinstance(x,self._klass)
1248
d0c16c9d621a Added isInstanceOf
rgbecker
parents: 1246
diff changeset
   276
2573
273f77e79536 new pattern matcher - partially done
andy
parents: 2547
diff changeset
   277
class matchesPattern(Validator):
273f77e79536 new pattern matcher - partially done
andy
parents: 2547
diff changeset
   278
    """Matches value, or its string representation, against regex"""
273f77e79536 new pattern matcher - partially done
andy
parents: 2547
diff changeset
   279
    def __init__(self, pattern):
273f77e79536 new pattern matcher - partially done
andy
parents: 2547
diff changeset
   280
        self._pattern = re.compile(pattern)
273f77e79536 new pattern matcher - partially done
andy
parents: 2547
diff changeset
   281
273f77e79536 new pattern matcher - partially done
andy
parents: 2547
diff changeset
   282
    def test(self,x):
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3645
diff changeset
   283
        print('testing %s against %s' % (x, self._pattern))
2573
273f77e79536 new pattern matcher - partially done
andy
parents: 2547
diff changeset
   284
        if type(x) is StringType:
273f77e79536 new pattern matcher - partially done
andy
parents: 2547
diff changeset
   285
            text = x
273f77e79536 new pattern matcher - partially done
andy
parents: 2547
diff changeset
   286
        else:
273f77e79536 new pattern matcher - partially done
andy
parents: 2547
diff changeset
   287
            text = str(x)
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3219
diff changeset
   288
        return (self._pattern.match(text) != None)
2573
273f77e79536 new pattern matcher - partially done
andy
parents: 2547
diff changeset
   289
2547
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   290
class DerivedValue:
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   291
    """This is used for magic values which work themselves out.
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   292
    An example would be an "inherit" property, so that one can have
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   293
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   294
      drawing.chart.categoryAxis.labels.fontName = inherit
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   295
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   296
    and pick up the value from the top of the drawing.
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   297
    Validators will permit this provided that a value can be pulled
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   298
    in which satisfies it.  And the renderer will have special
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   299
    knowledge of these so they can evaluate themselves.
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   300
    """
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   301
    def getValue(self, renderer, attr):
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   302
        """Override this.  The renderers will pass the renderer,
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   303
        and the attribute name.  Algorithms can then backtrack up
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   304
        through all the stuff the renderer provides, including
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   305
        a correct stack of parent nodes."""
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   306
        return None
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   307
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   308
class Inherit(DerivedValue):
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   309
    def __repr__(self):
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   310
        return "inherit"
3219
b28d6eef8227 reportlab: add support for String anchor 'numeric'
rgbecker
parents: 3198
diff changeset
   311
2547
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   312
    def getValue(self, renderer, attr):
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   313
        return renderer.getStateValue(attr)
3219
b28d6eef8227 reportlab: add support for String anchor 'numeric'
rgbecker
parents: 3198
diff changeset
   314
inherit = Inherit()
2547
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   315
3219
b28d6eef8227 reportlab: add support for String anchor 'numeric'
rgbecker
parents: 3198
diff changeset
   316
class NumericAlign(str):
b28d6eef8227 reportlab: add support for String anchor 'numeric'
rgbecker
parents: 3198
diff changeset
   317
    '''for creating the numeric string value for anchors etc etc
b28d6eef8227 reportlab: add support for String anchor 'numeric'
rgbecker
parents: 3198
diff changeset
   318
    dp is the character to align on (the last occurrence will be used)
b28d6eef8227 reportlab: add support for String anchor 'numeric'
rgbecker
parents: 3198
diff changeset
   319
    dpLen is the length of characters after the dp
b28d6eef8227 reportlab: add support for String anchor 'numeric'
rgbecker
parents: 3198
diff changeset
   320
    '''
b28d6eef8227 reportlab: add support for String anchor 'numeric'
rgbecker
parents: 3198
diff changeset
   321
    def __new__(cls,dp='.',dpLen=0):
b28d6eef8227 reportlab: add support for String anchor 'numeric'
rgbecker
parents: 3198
diff changeset
   322
        self = str.__new__(cls,'numeric')
b28d6eef8227 reportlab: add support for String anchor 'numeric'
rgbecker
parents: 3198
diff changeset
   323
        self._dp=dp
b28d6eef8227 reportlab: add support for String anchor 'numeric'
rgbecker
parents: 3198
diff changeset
   324
        self._dpLen = dpLen
b28d6eef8227 reportlab: add support for String anchor 'numeric'
rgbecker
parents: 3198
diff changeset
   325
        return self
2547
9d13685212f2 datacharts synchronised
andy
parents: 2426
diff changeset
   326
2424
101cf0c8500e validators.py: better auto support
rgbecker
parents: 2421
diff changeset
   327
isAuto = Auto()
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
   328
isBoolean = _isBoolean()
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
   329
isString = _isString()
2616
e3f68f895246 codec validator for diagra
andy
parents: 2575
diff changeset
   330
isCodec = _isCodec()
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
   331
isNumber = _isNumber()
1055
30ca3865f6ed Added isInt and changed SequenceOf and OneOf to be more friendly
rgbecker
parents: 1022
diff changeset
   332
isInt = _isInt()
1365
2ad55cb39128 Added isNoneOrInt
rgbecker
parents: 1353
diff changeset
   333
isNoneOrInt = NoneOr(isInt,'isNoneOrInt')
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
   334
isNumberOrNone = _isNumberOrNone()
1807
b7c571a2e141 Minor enhancements to SpiderChart/Label
rgbecker
parents: 1694
diff changeset
   335
isTextAnchor = OneOf('start','middle','end','boxauto')
945
4c7026f40785 New Scheme Validators
rgbecker
parents: 941
diff changeset
   336
isListOfNumbers = SequenceOf(isNumber,'isListOfNumbers')
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
   337
isListOfNumbersOrNone = _isListOfNumbersOrNone()
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
   338
isListOfShapes = _isListOfShapes()
945
4c7026f40785 New Scheme Validators
rgbecker
parents: 941
diff changeset
   339
isListOfStrings = SequenceOf(isString,'isListOfStrings')
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
   340
isListOfStringsOrNone = _isListOfStringsOrNone()
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
   341
isTransform = _isTransform()
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
   342
isColor = _isColor()
1022
2a7cdced12e3 Added isListofColors.
dinu_gherman
parents: 948
diff changeset
   343
isListOfColors = SequenceOf(isColor,'isListOfColors')
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
   344
isColorOrNone = _isColorOrNone()
1694
1f1031671ae6 Added isShape & isNoneOrShape
rgbecker
parents: 1683
diff changeset
   345
isShape = isValidChild = _isValidChild()
1f1031671ae6 Added isShape & isNoneOrShape
rgbecker
parents: 1683
diff changeset
   346
isNoneOrShape = isValidChildOrNone = _isValidChildOrNone()
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
   347
isAnything = _isAnything()
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 945
diff changeset
   348
isNothing = _isNothing()
1059
f0abeaa8e232 Added isXYCoord and isBoxAnchor validators
uid22986
parents: 1055
diff changeset
   349
isXYCoord = SequenceOf(isNumber,lo=2,hi=2,emptyOK=0)
2174
dc5ab1ba37c8 Allow autox/y boxanchor
rgbecker
parents: 2120
diff changeset
   350
isBoxAnchor = OneOf('nw','n','ne','w','c','e','sw','s','se', 'autox', 'autoy')
1197
d7ce043c87b4 Added NoneOr and various specialized validators
rgbecker
parents: 1083
diff changeset
   351
isNoneOrString = NoneOr(isString,'NoneOrString')
1199
5528c92307b2 Allowd SequenceOf to have NoneOK arg
rgbecker
parents: 1197
diff changeset
   352
isNoneOrListOfNoneOrStrings=SequenceOf(isNoneOrString,'isNoneOrListOfNoneOrStrings',NoneOK=1)
1353
0de5adb7beac Added isListOfNoneOrString
rgbecker
parents: 1248
diff changeset
   353
isListOfNoneOrString=SequenceOf(isNoneOrString,'isListOfNoneOrString',NoneOK=0)
1199
5528c92307b2 Allowd SequenceOf to have NoneOK arg
rgbecker
parents: 1197
diff changeset
   354
isNoneOrListOfNoneOrNumbers=SequenceOf(isNumberOrNone,'isNoneOrListOfNoneOrNumbers',NoneOK=1)
1391
35552052df99 Added a _isCallable + a couple of new vaildators
rgbecker
parents: 1385
diff changeset
   355
isCallable = _isCallable()
3645
388ffb1a42df graphics/charts: added CustomDrawChanger class
robin
parents: 3631
diff changeset
   356
isNoneOrCallable = NoneOr(isCallable)
1391
35552052df99 Added a _isCallable + a couple of new vaildators
rgbecker
parents: 1385
diff changeset
   357
isStringOrCallable=EitherOr((isString,isCallable),'isStringOrCallable')
1694
1f1031671ae6 Added isShape & isNoneOrShape
rgbecker
parents: 1683
diff changeset
   358
isStringOrCallableOrNone=NoneOr(isStringOrCallable,'isStringOrCallableNone')
1963
ac30760d5586 Added isStringOrNone
rgbecker
parents: 1941
diff changeset
   359
isStringOrNone=NoneOr(isString,'isStringOrNone')
3339
26eb637a7f55 validators.py: add isNormalDate
rgbecker
parents: 3326
diff changeset
   360
isNormalDate=_isNormalDate()