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

Class FileWriter

source code

 object --+            
          |            
_io._IOBase --+        
              |        
 _io._RawIOBase --+    
                  |    
         _io.FileIO --+
                      |
                     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]
 
__init__(self, name, opt='w')
Initialize file to write to
source code
int
write(self, line)
Write array of bytes b, return number written.
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
 
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 _io.FileIO: __getattribute__, __new__, __repr__, close, fileno, isatty, read, readable, readall, readinto, seek, seekable, tell, truncate, writable

Inherited from _io._IOBase: __enter__, __exit__, __iter__, flush, next, readline, readlines

Inherited from _io._IOBase (private): _checkClosed, _checkReadable, _checkSeekable, _checkWritable

Inherited from object: __delattr__, __format__, __hash__, __reduce__, __reduce_ex__, __setattr__, __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 _io.FileIO: closed, closefd, mode

Inherited from object: __class__

Method Details [hide private]

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

source code 

Initialize file to write to

Overrides: object.__init__

write(self, line)

source code 

Write array of bytes b, return number written.

Only makes one system call, so not all of the data may be written. The number of bytes actually written is returned. In non-blocking mode, returns None if the write would block.

Returns: int
Overrides: _io.FileIO.write
(inherited documentation)

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.

Overrides: _io._IOBase.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*')