Package gmisclib :: Module avio
[frames] | no frames]

Module avio

source code

Module to parse and create lines in "a=v;" format. Normally, the entry points are parse() and concoct().


Version: $Revision: 1.21 $

Classes
  BadFormatError
  writer
Write a file in a=v; format.
Functions
 
parse(s, sep=';')
Parses a line in a=v; a=v form into a dictionary.
source code
 
concoct(s)
Converts a dictionary to a line in the form a=v;a=v;#comment.
source code
tuple(list(dict), list(str))
read(fd, sep=';', line=None)
Read a file in a=v; format.
source code
 
test1() source code
tuple(dict, list(dict), list(str))
read_hdc(fd, sep=';', line=None)
This emulates fiatio.read().
source code
 
test2() source code
Variables
  __package__ = 'gmisclib'

Imports: die, g_encode, gpk_writer, fwd, back


Function Details

parse(s, sep=';')

source code 

Parses a line in a=v; a=v form into a dictionary. The line may be terminated by a '#' followed by an arbitrary comments. Both attributes and values are assumed to be encoded with the default g_encode encoder. (However, the comment is not assumed to be encoded.)

Parameters:
  • s - the string to be parsed.
  • sep - (optional) lets you choose the character that separates attribute-value pairs.
Returns:
dictionary containing a=v pairs. One special entry for comments: "_COMMENT".
Raises:

concoct(s)

source code 

Converts a dictionary to a line in the form a=v;a=v;#comment. It returns a string. The entries in the dictionary will be converted to a string representation by fwd().

read(fd, sep=';', line=None)

source code 

Read a file in a=v; format. If line is set, put the line number into a slot with the specified name.

Returns: tuple(list(dict), list(str))
(data, comments) where data=[{a:v, ...}, ...] and comments=[str, ...]
Raises:

read_hdc(fd, sep=';', line=None)

source code 

This emulates fiatio.read().

Returns: tuple(dict, list(dict), list(str))
(header, data, comments) where data=[{a:v, ...}, ...] and comments=[str, ...]