Package grizzled :: Package file :: Module includer :: Class Includer
[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
 
__init__(self, source, include_regex='^%include\s"([^"]+)"', max_nest_level=100, output=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.
str
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.

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

Properties

Inherited from object: __class__

Method Details

__init__(self, source, include_regex='^%include\s"([^"]+)"', max_nest_level=100, output=None)
(Constructor)

 
Create a new Includer object.
Parameters:
  • source (file or str) - The source to be read and expanded. May be an open file-like object, a path name, or a URL string.
  • include_regex (str) - Regular expression defining the include syntax. Must contain a single parenthetical group that can be used to extract the included file or URL.
  • max_nest_level (int) - Maximum include nesting level. Exceeding this level will cause Includer to throw an IncludeError.
  • output (str or file) - A string (path name) or file-like object to which to save the expanded output.
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 or False

seek(self, pos, mode=0)

 
Seek to the specified file offset in the include-processed file.
Parameters:
  • pos (int) - file offset
  • mode (int) - the seek mode, as specified to a Python file's seek() method

tell(self)

 
Get the current file offset.
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
Returns: str
the line read

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