Package DebTorrent :: Module inifile
[hide private]
[frames] | no frames]

Module inifile

source code

Functions to read/write a Windows-style INI file

format:
   aa = "bb"
   cc = 11
   
   [eee]
   ff = "gg"
decodes to:
   d = { '': {'aa':'bb','cc':'11'}, 'eee': {'ff':'gg'} }
the encoder can also take this as input:
   d = { 'aa': 'bb, 'cc': 11, 'eee': {'ff':'gg'} }
though it will only decode in the above format. Keywords must be strings. Values that are strings are written surrounded by quotes, and the decoding routine automatically strips any quotes from the values. Booleans are written as integers. Anything other than strings, integers, and floats may have unpredictable results.

Functions [hide private]
boolean
ini_write(f, d, comment='')
Write the ini file.
source code
 
errfunc(lineno, line, err)
Display an error message when reading the ini file fails.
source code
dictionary
ini_read(f)
Read the ini file.
source code
Variables [hide private]
logging.Logger logger = logging.getLogger('DebTorrent.inifile')
the logger to send all log messages to for this module

Imports: cStringIO.StringIO, types.DictType, types.StringType, logging, types.BooleanType


Function Details [hide private]

ini_write(f, d, comment='')

source code 
Write the ini file.
Parameters:
  • f (string) - the file name to write
  • d (dictionary) - the data to write to the ini file
  • comment (string) - a comment to write at the top of the file, hash marks will be prefixed (optional, default is no comment)
Returns: boolean
whether the write succeeded

errfunc(lineno, line, err)

source code 
Display an error message when reading the ini file fails.
Parameters:
  • lineno (int) - the line number that caused the error
  • line (string) - the line that caused the error
  • err (string) - the error that was generated

ini_read(f)

source code 
Read the ini file.
Parameters:
  • f (string) - the file name to read
Returns: dictionary
the data read from the ini file