1   
 2   
 3   
 4   
 5   
 6  import os 
 7  import code_creator 
11          """Constructor. 
12   
13          @param parent: Parent code creator. 
14          @type parent: L{code_creator_t} 
15          """ 
16          code_creator.code_creator_t.__init__( self )  
17          self._creators = [] 
 18           
21      creators = property(_get_creators, 
22                          doc="""A list of children nodes. 
23                          @type: list of L{code_creator_t}""") 
24   
26          """Add a creator to the list of children creators. 
27   
28          @param creator: Creator object 
29          @type creator: L{code_creator_t} 
30          @param index: Desired position of the creator or None to append it to the end of the list 
31          @type index: int 
32          """ 
33          creator.parent = self 
34          if index or index == 0: 
35              self._creators.insert( index, creator ) 
36          else: 
37              self._creators.append( creator ) 
 38   
40          """Add a creators to the list of children creators. 
41   
42          @param creators: list of creators object 
43          @type creator: L{code_creator_t} 
44          @param index: Desired position of the creator or None to append it to the end of the list 
45          @type index: int 
46          """ 
47          for pos, creator in enumerate( creators ): 
48              if index or index == 0: 
49                  self.adopt_creator( creator, index + pos ) 
50              else: 
51                  self.adopt_creator( creator ) 
 52   
54          """Remove a children code creator object. 
55   
56          @precondition: creator must be a children of self 
57          @param creator: The creator node to remove 
58          @type creator: L{code_creator_t} 
59          """ 
60          creator.parent = None 
61          del self._creators[ self._creators.index( creator ) ]     
 62   
63      @staticmethod 
65          """Concatenate the code from a list of code creators. 
66   
67          @param creators: A list with code creators 
68          @type creators: list of L{code_creator_t} 
69          @rtype: str 
70          """ 
71          internals = map( lambda expr: expr.create(), creators ) 
72          internals = filter(None, internals ) 
73          internals = map( lambda code: code_creator.code_creator_t.indent( code ) 
74                           , internals ) 
75          for index in range( len( internals ) - 1): 
76              internals[index] = internals[index] + os.linesep 
77          return os.linesep.join( internals ) 
 78