Module includer :: Class Includer
[hide private]
[frames] | no frames]

Class Includer



object --+
         |
        Includer

An Includer object preprocesses a path or file-like object, expanding include references. The resulting Includer object is a file-like object, offering the same methods and capabilities as an open file.

By default, Includer supports this include syntax:
   %include "path"
   %include "url"

However, the include directive syntax is controlled by a regular expression, so it can be configured.

See the module documentation for details.

Instance Methods [hide private]
 
__init__(self, source, includeRegex='^%include\s"([^"]+)"', maxNestLevel=100, outputFile=None)
Create a new Includer object.
 
name(self)
Get the name of the file being processed.
 
__iter__(self)
string
next(self)
A file object is its own iterator.
 
close(self)
Close the includer, preventing any further I/O operations.
int
fileno(self)
Get the file descriptor.
 
isatty(self)
Determine whether the file being processed is a TTY or not.
 
seek(self, pos, mode=0)
Seek to the specified file offset in the include-processed file.
int
tell(self)
Get the current file offset.
 
read(self, n=-1)
Read n bytes from the open file.
 
readline(self, length=-1)
Read the next line from the file.
array
readlines(self, sizehint=0)
Read all remaining lines in the file.
 
truncate(self, size=None)
Not supported, since Includer objects are read-only.
 
write(self, s)
Not supported, since Includer objects are read-only.
 
writelines(self, iterable)
Not supported, since Includer objects are read-only.
 
flush(self)
No-op.
string
getvalue(self)
Retrieve the entire contents of the file, which includes expanded, at any time before the close() method is called.
 
_processIncludes(self, fileIn, filename, isURL, fileOut)
 
_open(self, nameToOpen, enclosingFile, enclosingFileIsURL)

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, source, includeRegex='^%include\s"([^"]+)"', maxNestLevel=100, outputFile=None)
(Constructor)

 
Create a new Includer object.
Parameters:
  • source (open file-like object, path name, or URL) - the source to read and expand.
  • includeRegex (string) - Regular expression defining the include syntax. Must contain a single parenthetical group that can be used to extract the included file or URL.
  • maxNestLevel (int) - Maximum include nesting level. Exceeding this level causing the Includer to throw an IncludeError
  • outputFile - string
  • outputFile - Save the expanded output to outputFile, which specifies a path name.
Raises:
Overrides: object.__init__

name(self)

 
Get the name of the file being processed.
Decorators:
  • @property

next(self)

 
A file object is its own iterator.
Returns: string
the next line from the file
Raises:

fileno(self)

 
Get the file descriptor. Returns the descriptor of the file being read.
Returns: int
the file descriptor of the file being read

isatty(self)

 
Determine whether the file being processed is a TTY or not.
Returns:
True/False

seek(self, pos, mode=0)

 
Seek to the specified file offset in the include-processed file.
Parameters:
  • pos (int) - file offset
  • mode (int) - Seek mode (0=seek from top of file, 1=seek relative to current file position, 2=seek from bottom of file)

tell(self)

 
Get the current file offset. Note that seeking to a file offset is not supported.
Returns: int
current file offset

read(self, n=-1)

 
Read n bytes from the open file.
Parameters:
  • n (int) - Number of bytes to read. A negative number instructs the method to read all remaining bytes.
Returns:
the bytes read

readline(self, length=-1)

 
Read the next line from the file.
Parameters:
  • length (int) - a length hint, or negative if you don't care

readlines(self, sizehint=0)

 
Read all remaining lines in the file.
Returns: array
array of lines

getvalue(self)

 
Retrieve the entire contents of the file, which includes expanded, at any time before the close() method is called.
Returns: string
a single string containing the contents of the file