Package qm :: Package test :: Package classes :: Module python_label
[hide private]
[frames] | no frames]

Source Code for Module qm.test.classes.python_label

 1  ######################################################################## 
 2  # 
 3  # File:   python_label.py 
 4  # Author: Mark Mitchell 
 5  # Date:   06/11/2002 
 6  # 
 7  # Contents: 
 8  #   PythonLabel 
 9  # 
10  # Copyright (c) 2002 by CodeSourcery, LLC.  All rights reserved.  
11  # 
12  ######################################################################## 
13   
14  ######################################################################## 
15  # Imports 
16  ######################################################################## 
17   
18  from   qm.label   import * 
19  import re 
20   
21  ######################################################################## 
22  # Classes 
23  ######################################################################## 
24   
25 -class PythonLabel(Label):
26 """A 'PythonLabel' is a 'Label' that uses the 'a.b.c' naming scheme. 27 28 A 'PythonLabel' is a 'Label' whose separator character is the period 29 and whose components consist of lower-case letters, numerals, and 30 underscores. These labels have the property that they can be easily 31 mapped to filenames on most operating systems; all valid labels are 32 valid filenames (replacing '.' with '/') and two different labels 33 will always map to two different filenames.""" 34 35 _sep = '.' 36 """The separator character used to separate components.""" 37 38 __valid_label_regexp = re.compile("[-a-z0-9_%s]+$" % _sep) 39 """A compiled regular expression that matches valid labels.""" 40
41 - def IsValid(self, label, is_component):
42 """Returns true if this label is not valid. 43 44 returns -- True if this label is not valid.""" 45 46 if not Label.IsValid(self, label, is_component): 47 # If the label does not meet the basic validity 48 # requirements, reject it. 49 return 0 50 elif not self.__valid_label_regexp.match(label): 51 # If the label contains invalid characters, reject it. 52 return 0 53 54 return 1
55