Warning
The documentation of this module is very incomplete.
This module bundles all file format object models. An object model is a group of classes whose instances can hold the information contained in a file whose format is described in a particular way (xml, xsd, and possibly others).
Bases: type
This metaclass is an abstract base class for transforming a file format description into classes which can be directly used to manipulate files in this format.
A file format is implemented as a particular class (a subclass of FileFormat) with class members corresponding to different (bit)struct types, enum types, basic types, and aliases.
Find filename in given filepaths, and open it. Raises IOError if file cannot be opened.
Parameters: |
|
---|
Bases: object
This class is the base class for all file formats. It implements a number of useful functions such as walking over directory trees (walkData()) and a default attribute naming function (name_attribute()). It also implements the base class for representing file data (FileFormat.Data).
Override this with a list of archive formats that may contain files of the format.
Bases: pyffi.utils.graph.GlobalNode
Base class for representing data in a particular format. Override this class to implement reading and writing.
Quickly checks whether the stream appears to contain data of a particular format. Resets stream to original position. Call this function if you simply wish to check that a file is of a particular format without having to parse it completely.
Override this method.
Parameters: | stream (file) – The file to inspect. |
---|---|
Returns: | True if stream is of particular format, False otherwise. |
Read data of particular format from stream. Override this method.
Parameters: | stream (file) – The file to read from. |
---|
User version (additional version field) of the data.
Version of the data.
Write data of particular format to stream. Override this method.
Parameters: | stream (file) – The file to write to. |
---|
Override this with a regular expression (the result of a re.compile call) for the file extension of the format you are implementing.
Converts an attribute name, as in the description file, into a name usable by python.
Parameters: | name (str) – The attribute name. |
---|---|
Returns: | Reformatted attribute name, useable by python. |
>>> FileFormat.name_attribute('tHis is A Silly naME')
't_his_is_a_silly_na_m_e'
>>> FileFormat.name_attribute('Test:Something')
'test_something'
>>> FileFormat.name_attribute('unknown?')
'unknown'
Converts a class name, as in the xsd file, into a name usable by python.
Parameters: | name (str) – The class name. |
---|---|
Returns: | Reformatted class name, useable by python. |
>>> FileFormat.name_class('this IS a sillyNAME')
'ThisIsASillyNAME'
Intelligently split a name into parts:
>>> FileFormat.name_parts("hello_world")
['hello', 'world']
>>> FileFormat.name_parts("HELLO_WORLD")
['HELLO', 'WORLD']
>>> FileFormat.name_parts("HelloWorld")
['Hello', 'World']
>>> FileFormat.name_parts("helloWorld")
['hello', 'World']
>>> FileFormat.name_parts("xs:NMTOKEN")
['xs', 'NMTOKEN']
>>> FileFormat.name_parts("xs:NCName")
['xs', 'N', 'C', 'Name']
>>> FileFormat.name_parts('this IS a sillyNAME')
['this', 'IS', 'a', 'silly', 'N', 'A', 'M', 'E']
>>> FileFormat.name_parts('tHis is A Silly naME')
['t', 'His', 'is', 'A', 'Silly', 'na', 'M', 'E']
Converts version string into an integer. This default implementation simply returns zero at all times, and works for formats that are not versioned.
Override for versioned formats.
Parameters: | version_str (str) – The version string. |
---|---|
Returns: | A version integer. |
A generator which yields all files in directory top whose filename matches the regular expression RE_FILENAME. The argument top can also be a file instead of a directory. Errors coming from os.walk are ignored.
Note that the caller is not responsible for closing the stream.
This function is for instance used by pyffi.spells to implement modifying a file after reading and parsing.
Parameters: |
|
---|
A generator which yields the data of all files in directory top whose filename matches the regular expression RE_FILENAME. The argument top can also be a file instead of a directory. Errors coming from os.walk are ignored.
Note that the caller is not responsible for closing the stream.
This function is for instance used by pyffi.spells to implement modifying a file after reading and parsing.
Parameters: |
|
---|