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

Class Includer

source code

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, include_regex='^%include\\s"([^"]+)"', max_nest_level=100, output=None)
Create a new Includer object.
source code
 
__iter__(self) source code
string
next(self)
A file object is its own iterator.
source code
 
close(self)
Close the includer, preventing any further I/O operations.
source code
int
fileno(self)
Get the file descriptor.
source code
 
isatty(self)
Determine whether the file being processed is a TTY or not.
source code
 
seek(self, pos, mode=0)
Seek to the specified file offset in the include-processed file.
source code
int
tell(self)
Get the current file offset.
source code
 
read(self, n=-1)
Read n bytes from the open file.
source code
str
readline(self, length=-1)
Read the next line from the file.
source code
array
readlines(self, sizehint=0)
Read all remaining lines in the file.
source code
 
truncate(self, size=None)
Not supported, since Includer objects are read-only.
source code
 
write(self, s)
Not supported, since Includer objects are read-only.
source code
 
writelines(self, iterable)
Not supported, since Includer objects are read-only.
source code
 
flush(self)
No-op.
source code
string
getvalue(self)
Retrieve the entire contents of the file, which includes expanded, at any time before the close() method is called.
source code
 
__process_includes(self, file_in, filename, is_url, file_out) source code
 
__open(self, name_to_open, enclosing_file, enclosing_file_is_url) source code

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

Properties [hide private]
  name
Get the name of the file being processed.

Inherited from object: __class__

Method Details [hide private]

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

source code 
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__

next(self)

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

fileno(self)

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

isatty(self)

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

seek(self, pos, mode=0)

source code 
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)

source code 
Get the current file offset.
Returns: int
current file offset

read(self, n=-1)

source code 
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)

source code 
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)

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

getvalue(self)

source code 
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

Property Details [hide private]

name

Get the name of the file being processed.
Get Method:
unreachable.name(self) - Get the name of the file being processed.