Module shipyard :: Class Parser
[hide private]
[frames] | no frames]

Class Parser

source code

object --+
         |
        Parser

Reader for Shipyard files

Instance Methods [hide private]
 
__init__(self, keys=None, defaults=None, keep_linebreaks=True, comment='#', continuation=' ', encode=True)
Constructor
source code
 
fill_record(self, record)
Add missing keys to a record
source code
 
parse(self, inpt, factory=None)
Iterator that returns the next record each time it is called
source code
 
get_list(self, inpt, factory=None)
Returns a list of all records
source code
 
get_dict(self, inpt, key, factory=None)
Returns a dict of all records
source code

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, keys=None, defaults=None, keep_linebreaks=True, comment='#', continuation=' ', encode=True)
(Constructor)

source code 
Constructor
Parameters:
  • keys (list of strings) - list of keys this parser accepts
  • defaults (dict) - default values for records
  • keep_linebreaks (bool) - if True linebreaks in continuation lines are kept
  • comment (string) - mark that starts a comment line
  • continuation (string) - mark that starts a continuation line
  • encode (bool) - True if coding marks should evaluated
Overrides: object.__init__

fill_record(self, record)

source code 
Add missing keys to a record
Parameters:
  • record (dict) - record zu fill

parse(self, inpt, factory=None)

source code 
Iterator that returns the next record each time it is called
Parameters:
  • inpt (iterable containing strings (e.g. a file)) - input to parse
  • factory (callable to create the return values.) - If factory is not None, for every record the result of factory(**record) is returned
Raises:

See Also: Parser.get_list()

get_list(self, inpt, factory=None)

source code 
Returns a list of all records
Parameters:
  • inpt (iterable containing strings (e.g. a file)) - input to parse
  • factory (callable to create the return values.) - If factory is not None, for every record the result of factory(**record) is returned
Raises:

See Also: Parser.parse()

get_dict(self, inpt, key, factory=None)

source code 
Returns a dict of all records
Parameters:
  • inpt (iterable containing strings (e.g. a file)) - input to parse
  • key (string) - name of the field used as key for the result dict
  • factory (callable to create the return values.) - If factory is not None, for every record the result of factory(**record) is returned
Raises:

See Also: Parser.parse()