Package mrv :: Package automation :: Module attributes
[hide private]
[frames] | no frames]

Source Code for Module mrv.automation.attributes

 1  # -*- coding: utf-8 -*- 
 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   
8 -class RegexStringAttr( Attribute ):
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
18 - def compatabilityRate( self, value ):
19 """:return: rate of base class provided that the regex matches, 0 otherwise""" 20 rate = Attribute.compatabilityRate( self, value ) # get default rate 21 if not rate: 22 return rate 23 24 if self.regex.match( str(value) ): # apply regex 25 return rate 26 27 return 0
28