Package yum :: Module parser :: Class ConfigPreProcessor
[hide private]
[frames] | no frames]

Class ConfigPreProcessor

source code

ConfigParser Include Pre-Processor

File-like Object capable of pre-processing include= lines for a ConfigParser.

The readline function expands lines matching include=(url) into lines from the url specified. Includes may occur in included files as well.

Suggested Usage:

   cfg = ConfigParser.ConfigParser()
   fileobj = confpp( fileorurl )
   cfg.readfp(fileobj)
Instance Methods [hide private]
 
__init__(self, configfile, vars=None) source code
 
readline(self, size=0)
Implementation of File-Like Object readline function.
source code
 
_absurl(self, url)
Returns an absolute url for the (possibly) relative url specified.
source code
 
_pushfile(self, url)
Opens the url specified, pushes it on the stack, and returns a file like object.
source code
 
_popfile(self)
Pop a file off the stack signaling completion of including that file.
source code
 
_isalreadyincluded(self, tuple)
Checks if the tuple describes an include that was already done.
source code
 
geturl(self) source code
Method Details [hide private]

readline(self, size=0)

source code 

Implementation of File-Like Object readline function. This should be the only function called by ConfigParser according to the python docs. We maintain a stack of real FLOs and delegate readline calls to the FLO on top of the stack. When EOF occurs on the topmost FLO, it is popped off the stack and the next FLO takes over. include= lines found anywhere cause a new FLO to be opened and pushed onto the top of the stack. Finally, we return EOF when the bottom-most (configfile arg to __init__) FLO returns EOF.

Very Technical Pseudo Code:

   def confpp.readline() [this is called by ConfigParser]
       open configfile, push on stack
       while stack has some stuff on it
           line = readline from file on top of stack
           pop and continue if line is EOF
           if line starts with 'include=' then
               error if file is recursive or duplicate
               otherwise open file, push on stack
               continue
           else
               return line
       
       return EOF

_absurl(self, url)

source code 

Returns an absolute url for the (possibly) relative url specified. The base url used to resolve the missing bits of url is the url of the file currently being included (i.e. the top of the stack).

_pushfile(self, url)

source code 

Opens the url specified, pushes it on the stack, and returns a file like object. Returns None if the url has previously been included. If the file can not be opened this function exits.

_isalreadyincluded(self, tuple)

source code 

Checks if the tuple describes an include that was already done. This does not necessarily have to be recursive