Package madgraph :: Package iolibs :: Module file_writers :: Class FileWriter
[hide private]
[frames] | no frames]

Class FileWriter

source code

object --+    
         |    
      file --+
             |
            FileWriter
Known Subclasses:

Generic Writer class. All writers should inherit from this class.

Nested Classes [hide private]
  FileWriterError
Exception raised if an error occurs in the definition or the execution of a Writer.
  FilePreProcessingError
Exception raised if an error occurs in the handling of the preprocessor tags '##' in the template file.
Instance Methods [hide private]
file object
__init__(self, name, opt='w')
Initialize file to write to
source code
 
write_line(self, line)
Write a line with proper indent and splitting of long lines for the language in question.
source code
 
write_comment_line(self, line)
Write a comment line, with correct indent and line splits, for the language in question
source code
 
write_comments(self, lines)
Write set of comment lines, with correct indent and line splits, for the language in question
source code
None
writelines(self, lines, context={}, formatting=True)
Extends the regular file.writeline() function to write out nicely formatted code.
source code
 
preprocess_template(self, input_lines, context={})
This class takes care of applying the pre-processing statements starting with ## in the template .inc files, using the contextual variables specified in the dictionary 'context' given in input with the variable names given as keys and their respective value as values.
source code

Inherited from file: __delattr__, __enter__, __exit__, __getattribute__, __iter__, __new__, __repr__, __setattr__, close, fileno, flush, isatty, next, read, readinto, readline, readlines, seek, tell, truncate, write, xreadlines

Inherited from object: __format__, __hash__, __reduce__, __reduce_ex__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  supported_preprocessor_commands = ['if']
  preprocessor_command_re = re.compile(r'\s*(?P<command>if)\s*\(...
  preprocessor_endif_re = re.compile(r'\s*\}\s*(?P<endif>else)?\...
Properties [hide private]

Inherited from file: closed, encoding, errors, mode, name, newlines, softspace

Inherited from object: __class__

Method Details [hide private]

__init__(self, name, opt='w')
(Constructor)

source code 

Initialize file to write to

Returns: file object
Overrides: object.__init__

writelines(self, lines, context={}, formatting=True)

source code 

Extends the regular file.writeline() function to write out nicely formatted code. When defining a context, then the lines will be preprocessed to apply possible conditional statements on the content of the template depending on the contextual variables specified.

Returns: None
Overrides: file.writelines

Class Variable Details [hide private]

preprocessor_command_re

Value:
re.compile(r'\s*(?P<command>if)\s*\(\s*(?P<body>.*)\s*\)\s*\{\s*')

preprocessor_endif_re

Value:
re.compile(r'\s*\}\s*(?P<endif>else)?\s*(\((?P<body>.*)\))?\s*(?P<new_\
block>\{)?\s*')