Changeset 8a0c67f
- Timestamp:
- May 19, 2010 4:16:56 AM (15 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
- Children:
- 7ee16b3
- Parents:
- 89e2138
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/compose.py
r89e2138 r8a0c67f 16 16 class constraint: 17 17 """ 18 This is just a struct to hold constraint fields, really18 This is mainly a struct to hold constraint fields and convert to XML output 19 19 """ 20 20 def __init__(self, name=None, required=False, accepts=None, provides=None, … … 44 44 def constraints_from_xml(string=None, file=None, filename=None, 45 45 top="constraints"): 46 """ 47 Pull constraints from an xml file. Only constraints in the top element are 48 recognized. A constraint consists of a constraint element with one name, 49 one required, and multiple accepts nd provides elements. Each contains a 50 string. A list of constraints is returned. 51 """ 46 52 class parser: 53 """ 54 A little class to encapsulate some state used to parse the constraints. 55 The methods are all bound to the analogous handlers in an XML parser. 56 It collects the constraints in self.constraint. 57 """ 47 58 def __init__(self, top): 48 59 self.top = top … … 53 64 54 65 def start_element(self, name, attrs): 66 # Clear any collected strings (from inside elements) 55 67 self.chars = None 56 68 self.key = str(name) 57 69 70 # See if we've entered the containing context 58 71 if name == self.top: 59 72 self.in_top = True 60 73 74 # Entering a constraint, create the object which also acts as a 75 # flag to indicate we're collecting constraint data. 61 76 if self.in_top: 62 77 if name == 'constraint': … … 65 80 def end_element(self, name): 66 81 if self.current: 82 # In a constraint and leaving an element. Clean up any string 83 # we've collected and process elements we know. 67 84 if self.chars is not None: 68 85 self.chars = self.chars.strip() … … 80 97 self.current.provides.append(self.chars) 81 98 elif name == 'constraint': 99 # Leaving this constraint. Record it and clear the flag 82 100 self.constraints.append(self.current) 83 101 self.current = None … … 86 104 "Unexpected element in constraint: %s" % name 87 105 elif name == self.top: 106 # We've left the containing context 88 107 self.in_top = False 89 108 90 109 91 110 def char_data(self, data): 111 # Collect strings if we're in the overall context 92 112 if self.in_top: 93 113 if self.chars is None: self.chars = data 94 114 else: self.chars += data 95 115 116 # Beginning of constraints_from_xml. Connect up the parser and call it 117 # properly for the kind of input supplied. 96 118 p = parser(top=top) 97 119 xp = xml.parsers.expat.ParserCreate()
Note: See TracChangeset
for help on using the changeset viewer.