LCONF.lconf_classes

Overview

Most of this code is based on the ReOBJ package. see LICENSE for more info

These Classes are used for the final default/parsed LCONF object.

Note

after the initialization all of them are in some ways changeable

  • some allow also adding new keys, appending items

Classes

class LCONF.lconf_classes.LconfBlk(data, key_order_list, key_empty_replacementvalue)

(Blk)Block Class: LCONF Block-Name class

Has additional attributes:

  • key_order (list) the keys in order but exclusive Default-Comment/Empty Lines

  • key_empty_replacementvalue (dict) all keys which have Empty-KeyValuePair-ReplacementValue

Parameters:
  • data – (dict)
  • key_order_list – (list) ordered data dictionary keys but exclusive Default-Comment/Empty Lines
  • key_empty_replacementvalue – (dict) all keys which have Empty-KeyValuePair-ReplacementValue
set_class__dict__item(key, value)

Sets the class __dict__: key to value: if key did not exist it is added

Parameters:
  • key – (str)
  • value – (any)
class LCONF.lconf_classes.LconfBlkI(data, block_names_list, min_required_blocks, max_allowed_blocks)

(Blk)Block (I)dentifier Class: LCONF Repeated-Block-Identifier class

Has additional attributes:

  • key_order (list) the keys (block_names) in order as added - see param block_names_list

  • min_required_blocks (int) - see param min_required_blocks

  • max_allowed_blocks (int) - see param max_allowed_blocks

  • has_comments (bool): defaults to False

    • this must be set to True: if it is init with comments: this is needed when a Blk is prepared
Parameters:
  • data – (dict)
  • block_names_list – (list)
  • min_required_blocks

    (int) number of minimum required blocks when a LCONF text/source is parsed`

    • 0 or greater
    • to not define it: set it to -1
  • max_allowed_blocks

    (int) number of maximum required blocks when a LCONF text/source is parsed`

    • 1 or greater
    • to not define it: set it to -1
__setitem__(block_name, blk_obj)

Called to implement assignment to self[key]. If block_name is not in key_order it will be added.

Parameters:
  • block_name
  • blk_obj
set_class__dict__item(key, value)

Sets the class __dict__: key to value: if key did not exist it is added

Parameters:
  • key – (str)
  • value – (any)
class LCONF.lconf_classes.LconfKVList(data, use_oneline)

(K)ey(V)alueList Class: LCONF Key :: Value-List and Key-Value-List class

Has additional attributes:

  • use_oneline (bool) will be initialized: default option to emit it as oneline or multiline list

    • useful in case the list has many default values or very long values
Parameters:
  • data – (list)
  • use_oneline

    (bool)

    • Set it to True: if the default list should be a oneline list Key :: Value-List
    • Set it to False: if the default list should be a multiline list Key-Value-List
set_class__dict__item(key, value)

Sets the class __dict__: key to value: if key did not exist it is added

Parameters:
  • key – (str)
  • value – (any)
class LCONF.lconf_classes.LconfKVMap(data, key_order_list, key_empty_replacementvalue)

(K)ey(V)alue(Map)ping Class: LCONF Key-Value-Mappings class

Has additional attributes:

  • key_order (list) the keys in order but exclusive Default-Comment/Empty Lines

  • key_empty_replacementvalue (dict) all keys which have Empty-KeyValuePair-ReplacementValue

Parameters:
  • data – (dict)
  • key_order_list – (list) ordered data dictionary keys but exclusive Default-Comment/Empty Lines
  • key_empty_replacementvalue – (dict) all keys which have Empty-KeyValuePair-ReplacementValue
set_class__dict__item(key, value)

Sets the class __dict__: key to value: if key did not exist it is added

Parameters:
  • key – (str)
  • value – (any)
class LCONF.lconf_classes.LconfRoot(data, key_order_list, key_empty_replacementvalue)

Lconf(M)ain/Root Class: LCONF Main/LconfRoot obj class

Has additional attributes:

  • key_order (list) the keys in order but exclusive Default-Comment/Empty Lines

  • key_empty_replacementvalue (dict) all keys which have Empty-KeyValuePair-ReplacementValue

  • section_name (str) defaults to ‘missing section name’

  • is_parsed (bool) defaults to False

  • has_comments (bool) defaults to False

    • this must be set to True: if it is init with comments: this helps that one does not need to check for comments later on
Parameters:
  • data – (dict)
  • key_order_list – (list) ordered data dictionary keys but exclusive Default-Comment/Empty Lines
  • key_empty_replacementvalue – (dict) all keys which have Empty-KeyValuePair-ReplacementValue
static frompickle(in_pickle_dumps)

Create a new LconfRoot from a pickled dumps.

Parameters:in_pickle_dumps – (bytes) a pickled LconfRoot dumps
Returns:(obj) a new LconfRoot object
Raises Err:
set_class__dict__item(key, value)

Sets the class __dict__: key to value: if key did not exist it is added

Parameters:
  • key – (str)
  • value – (any)
class LCONF.lconf_classes.LconfListOT(data, column_names, column_names_idx_lookup, column_names_counted, column_replace_missing)

List(O)f(T)uples Class: LCONF List-Of-Tuples class

Tuple items (rows) should only be simple objects: no nested list, dictionary ect..

Note

to replace column_names use the replace_column_names() as it also updates related things

Has additional attributes:

  • column_names (tuple): will be initialized: with column_names
  • column_names_idx_lookup (dict): will be initialized: column_name, to tuple_idx mapping
  • column_names_counted (int): will be initialized: with the number of column_names
  • column_replace_missing (tuple)
Parameters:
  • data – list) items (tuples - rows) must have the same number of values as there are column_names
  • column_names – (tuple) strings of column names: must be unique names
  • column_names_idx_lookup – (dict) column_name, to tuple_idx mapping
  • column_names_counted – (int) number of column_names
  • column_replace_missing

    (tuple)

    • if not empty: then for each column one replacement value must be defined
      these are values which will replace missing column items

    Note

    this will ALSO run through any transform functions

replace_column_names(new_column_names_tuple)

Replaces the column_names (tuple) with the new_column_names_tuple

Parameters:new_column_names_tuple – (tuple) must have the same number of names as the current column_names
Raises Err:
set_class__dict__item(key, value)

Sets the class __dict__: key to value: if key did not exist it is added

Parameters:
  • key – (str)
  • value – (any)
this_column_values(column_name)

Returns the items of all rows for the column

Parameters:column_name – (string)
Returns:(list) all items of the column for all rows
Raises Err:

This Page