1
2 """Contains specialized attributes that judge value based on different criteria,
3 allowing more elaborate typechecking"""
4 __docformat__ = "restructuredtext"
5
6 from mrv.dge import Attribute
7
9 """Attribute that accepts string values matching a given regular expression"""
10
11 - def __init__( self, regexstring, *args, **kwargs ):
12 """Initialize the attribute with a glob filter
13 :param regexstring: i.e. .*\..* or .*\.py or ^base_.*\.pyo"""
14 import re
15 self.regex = re.compile( regexstring )
16 Attribute.__init__( self, *args, **kwargs )
17
19 """:return: rate of base class provided that the regex matches, 0 otherwise"""
20 rate = Attribute.compatabilityRate( self, value )
21 if not rate:
22 return rate
23
24 if self.regex.match( str(value) ):
25 return rate
26
27 return 0
28