3.1. ReOBJ package

3.1.1. Submodules

3.1.2. ReOBJ.MainCode module

Main ReBASE module

Author:

peter1000

Github:

https://github.com/peter1000

Copyright:
  1. 2014 All Rights Reserved

All `ReBASE classes - subclasses`:

Warning

for all ReBASE classes disabled methods

  • any class.copy()

    • e.g.: xy = myrlist.copy()
  • any class.clear()

    • e.g.: myrlist.clear()
  • any __setattr__()

  • any __delattr__()

  • any __add__()

  • can be dumped with json: but will lose any extra data like: key_order (list) or/and any extra_data dict

  • can be pickled

  • additional methods:

    • set_extra_data(), update_extra_data(), replace_extra_data(): Sets/updates key/value to the additional dictionary: extra_data

    • copy_recursively(): recursively copy: Supports recursively intermediate ReDICT, ReLIST, ReTUPLE, dicts, lists and tuples (and their subclasses: depending on there implementation though)

      • this will also copy any ReDICT / ReLIST / ReTUPLE / ReMATRIX extra_data dict and any key_order (list) and any extra_key_order (list)
    • copy_recursively_to_python_native_types(): recursively copy: changing all ReOBJ to native python types.

      • RdictIO, RdictFO, RdictFO2: to python `OrderedDict obj keeping their order (see also argument: use_extra_key_order)

      • all other ReDICT: objects will be replaced by normal python dict objs

      • all ReLIST obj will be replaced by normal python list objs

      • all ReTUPLE obj will be replaced by normal python tuple objs

      • all ReMATRIX obj will be replaced by normal python list of tuple objs

        Warning

        ReMATRIX tuple items (rows) are not recursively copied so there should be no dict, list ect.. just basic types

      Supports recursively intermediate ReDICT, ReLIST, ReTUPLE, dicts, lists and tuples (and their subclasses: depending on there implementation though)

      Note

      any ReOBJ set: extra_data will be lost

    • topickle(): returns a new pickled dumps byte string from the obj

    • tojson(): returns a new json dumps string from the obj

    • tojson_keeporder(): returns a new json dumps string from the obj keeping the order of any RdictIO, RdictFO, RdictFO2

      • this uses first the: copy_recursively_to_python_native_types()

Warning

comparisons do not take into consideration any key_order (list) or extra_data dict

class ReOBJ.MainCode.Edict

Bases: ReOBJ.MainCode.ReBase, builtins.dict

An extended dictionary: E(xtended) like a normal python dict but with the additional methods of the ReBase class

Raises:ReOBJ.ProjectErr.Err
static frompickle(in_pickle_dumps)

Create a new Edict from a pickled dumps.

Arg:
in_pickle_dumps (bytes): a pickled Edict dumps
Returns:a new Rdict object
Return type:obj
class ReOBJ.MainCode.Elist

Bases: ReOBJ.MainCode.ReBase, builtins.list

An extended list: E(xtended) like a normal python list but with the additional methods of the ReBase class

Raises:ReOBJ.ProjectErr.Err
static frompickle(in_pickle_dumps)

Create a new Elist from a pickled dumps.

Arg:
in_pickle_dumps (bytes): a pickled Elist dumps
Returns:a new Elist object
Return type:obj
class ReOBJ.MainCode.Etuple

Bases: ReOBJ.MainCode.ReBase, builtins.tuple

An extended tuple: E(xtended) like a normal python tuple but with the additional methods of the ReBase class

Raises:ReOBJ.ProjectErr.Err
static frompickle(in_pickle_dumps)

Create a new Etuple from a pickled dumps.

Arg:
in_pickle_dumps (bytes): a pickled Etuple dumps
Returns:a new Etuple object
Return type:obj
class ReOBJ.MainCode.Lmatrix(column_names, list_tuple__of_tuples, unique_column_names=True)

Bases: ReOBJ.MainCode.ReBase, builtins.list

An extended MATRIX (List-Of-Tuples): E(xtended) with the additional methods of the ReBase class

Tuple items (rows) should only be simple objects: no nested list, dictionary: this is not enforces but not all other methods support such:

e.g.: copy_recursively_to_python_native_types()
Arg:
column_names (tuple): strings of column names list_tuple__of_tuples (list or tuple): items (tuples - rows) must have the same number of values as there are column_names unique_column_names (bool): if True all column names must be unique: some methods require this
Raises:ReOBJ.ProjectErr.Err
__setitem__(idx, row_tuple)

Called to implement assignment to self[idx].

Arg:
row_tuple (tuple): tuple must have the same number of items as: the original tuple_column_names
Raises:IndexError – : if out of idx
append(row_tuple)

Append row_tuple

Arg:
row_tuple (tuple): tuple must have the same number of items as: the original tuple_column_names
extend(other_matrix)

Extend row_tuple

Arg:
other_matrix: must have same number of column names
static frompickle(in_pickle_dumps)

Create a new Lmatrix from a pickled dumps.

Arg:
in_pickle_dumps (bytes): a pickled Lmatrix dumps
Returns:a new Lmatrix object
Return type:obj
insert(idx, row_tuple)

Insert row_tuple

Arg:
idx (int): where to insert row_tuple (tuple): tuple must have the same number of items as: the original tuple_column_names
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:ReOBJ.Err
set_extra_data(key, value)

Sets/updates key/value to the additional dictionary: extra_data

this_column_values(column_name)

Returns the items of all rows for the column

Arg:
column_name (string):
Returns:all items of the column for all rows
Return type:list
update_extra_data(new_extra_data_dict)

Updates/Extends the additional dictionary: extra_data

class ReOBJ.MainCode.LmatrixF(column_names, list_tuple__of_tuples, unique_column_names=True)

Bases: ReOBJ.MainCode.Lmatrix

A restricted MATRIX (List-Of-Tuples): F(ix)

Similar to Lmatrix but after creation/initialization no new items can be added There are some other differences too.

This is quite similar to using a Tuple-of-Tuples: but we keep it a subclass of Lmatrix

  • can only be initialized but is fix afterwards
  • new items (tuple-rows) can not be added
  • item (tuple-rows) can not be changed / replaced
  • item (tuple-rows) can not be deleted

Tuple items should only be simple objects: no nested list, dictionary: this is not enforces but not all other methods support such:

e.g.: copy_recursively_to_python_native_types()
Arg:
column_names (tuple): strings of column names list_tuple__of_tuples (list or tuple): items (tuples - rows) must have the same number of values as there are column_names unique_column_names (bool): if True all column names must be unique: some methods require this
Raises:ReOBJ.ProjectErr.Err
append(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

extend(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

static frompickle(in_pickle_dumps)

Create a new LmatrixF from a pickled dumps.

Arg:
in_pickle_dumps (bytes): a pickled LmatrixF dumps
Returns:a new LmatrixF object
Return type:obj
insert(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

pop(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

remove(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

class ReOBJ.MainCode.Rdict

Bases: ReOBJ.MainCode.ReBase, builtins.dict

A restricted dictionary:

  • new keys can be added
  • item values can be changed
  • item can not be deleted
Raises:MethodDeactivatedErr, KeyError, AttributeError, ReOBJ.ProjectErr.Err
__reduce__()

Return state information for pickling

classmethod fromkeys(key_name_list, value=None)

Create a new Rdict with keys from key_name_list and values set to value.

Arg:
key_name_list (list): a list with key names value (any): each item will be set to the same initial value
Returns:a new Rdict object
Return type:obj
static frompickle(in_pickle_dumps)

Create a new Rdict from a pickled dumps.

Arg:
in_pickle_dumps (bytes): a pickled Rdict dumps
Returns:a new Rdict object
Return type:obj
pop(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

popitem(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

setdefault(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

update(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

class ReOBJ.MainCode.RdictF

Bases: ReOBJ.MainCode.Rdict

A restricted dictionary: F(ix)

Similar to Rdict but after creation/initialization no new keys can be added There are some other differences too.

  • can only be initialized but is fix afterwards
  • new keys can not be added
  • item values can be changed
  • item can not be deleted
Raises:MethodDeactivatedErr, KeyError, AttributeError, ReOBJ.ProjectErr.Err
__setitem__(key, value)

Called to implement assignment to self[key].

Restriction: after RdictF creation no new keys can be set.

Raises:KeyError – if key is not found
static frompickle(in_pickle_dumps)

Create a new RdictF from a pickled dumps.

Arg:
in_pickle_dumps (bytes): a pickled RdictF dumps
Returns:a new RdictF object
Return type:obj
get(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

class ReOBJ.MainCode.RdictFO(key_value_list, use_tuple_values, init_extra_key_order=True)

Bases: ReOBJ.MainCode.RdictIO

A restricted dictionary: F(ix) O(rder)

Similar to RdictIO but after creation/initialization no new keys can be added There are some other differences too.

  • can only be initialized but is fix afterwards: key_order list has the key order as in the key_value_list argument

  • new keys can not be added

  • item values can be changed

    Note

    keep in mind that values might be tuples: depending ont tuple_values

  • item can not be deleted

for arguments see: RdictIO()

Raises:MethodDeactivatedErr, KeyError, AttributeError, ReOBJ.ProjectErr.Err
__setitem__(key, value)

Called to implement assignment to self[key].

Restriction: after RdictFO creation no new keys can be set.

Raises:KeyError – if key is not found
static frompickle(in_pickle_dumps)

Create a new RdictFO from a pickled dumps.

Arg:
in_pickle_dumps (bytes): a pickled RdictFO dumps
Returns:a new RdictFO object
Return type:obj
get(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

class ReOBJ.MainCode.RdictFO2(key_value_list, use_tuple_values, init_extra_key_order=True)

Bases: ReOBJ.MainCode.RdictFO

A restricted dictionary: F(ix) O(rder)

Similar to RdictFO but after creation/initialization values can not be changed

  • can only be initialized but is fix afterwards: key_order list has the key order as in the key_value_list argument
  • new keys can not be added
  • item values can not be changed
  • item can not be deleted

for arguments see: RdictIO()

Raises:MethodDeactivatedErr, KeyError, AttributeError, ReOBJ.ProjectErr.Err
static frompickle(in_pickle_dumps)

Create a new RdictFO2 from a pickled dumps.

Arg:
in_pickle_dumps (bytes): a pickled RdictFO2 dumps
Returns:a new RdictFO2 object
Return type:obj
class ReOBJ.MainCode.RdictIO(key_value_list, use_tuple_values, init_extra_key_order=True)

Bases: ReOBJ.MainCode.Rdict

A restricted dictionary: I(nsertion) O(rder)

Similar to Rdict but the order of the keys insertion are tracked in a list: key_order There are some other differences too.

  • new keys can be added

  • item values can be changed

    Note

    keep in mind that values might be tuples: depending ont tuple_values

  • item can not be deleted

Parameters:
  • list_of_key_value_tuples (list) –

    of tuples

    • first tuple item is: dict key
    • other tuple item
      • depends on tuple_values setting
  • use_tuple_values

    bool

    • if True: output will be a tuple with all values except the first (dict key)
      • Example with single values
        rdictio_obj = RdictIO2([
           ('jack', 4098),
           ('hair', 'brown'),
           ('eyes', 'blue'),
        ], True)
        
        # output tuples
        rdictio_obj:  {'eyes': ('blue',), 'jack': (4098,), 'hair': ('brown',)}
        
      • this is usually used with multiple values tuples like
        rdictio_obj = RdictIO2([
           ('jack', 4098, 'dummy_func'),
           ('hair', 'brown', 'dummy_func'),
           ('eyes', 'blue', 'dummy_func'),
        ], True)
        
        # output tuples
        rdictio_obj:  {'eyes': ('blue', 'dummy_func'), 'hair': ('brown', 'dummy_func'), 'jack': (4098, 'dummy_func')}
        
    • if False: the first (dict key), the second will be the value
      • only used with key-value-pair tuples like in a normal python dict
        rdictio_obj = RdictIO2([
           ('jack', 4098),
           ('hair', 'brown'),
           ('eyes', 'blue'),
        ], False)
        
        # output
        rdictio_obj:  {'hair': 'brown', 'eyes': 'blue', 'jack': 4098}
        
      • if True: the extra_key_order (list) will be initialize with a copy of the key_order (list)
      • if False: the extra_key_order (list) will be an empty list
Raises:

MethodDeactivatedErr, KeyError, AttributeError, ReOBJ.ProjectErr.Err

__reduce__()

Return state information for pickling

__setitem__(key, value)

Called to implement assignment to self[key].

NOTE: Speedtest: defining __setitem__ is the main slowdown

appendto_extra_key_value_order(new_key)

Appends the new_key with the the user defined extra_key_order (list)

  • Checks that each key is also in the default: key_order (list)
Parameters:new_key (obj) – append a new key to the user defined keys order (may be also just a subset of the RdictIO keys)
Raises:ReOBJ.Err: if the `new_key` is not found in the default `key_order (list)`
fromkeys(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

static frompickle(in_pickle_dumps)

Create a new RdictIO from a pickled dumps.

Arg:
in_pickle_dumps (bytes): a pickled RdictIO dumps
Returns:a new RdictIO object
Return type:obj
replace_extra_key_order(new_extra_key_order_list)

Replaces the extra_key_order (list) with the new_extra_key_order

  • Checks that each key is also in the default: key_order (list)
Parameters:new_extra_key_order_list (list) – user defined keys order (may be also just a subset of the RdictIO keys)
Raises:ReOBJ.Err: if any key from new_extra_key_order is not found in the default `key_order (list)`
set_extra_data(key, value)

Sets/updates key/value to the additional dictionary: extra_data

update_extra_data(new_extra_data_dict)

Updates/Extends the additional dictionary: extra_data

yield_extra_key_value_order()

Returns a generator: (keys, values) over the extra_key_order (list)

Yields:(keys, value) in the order of the extra_key_order (list)
yield_key_value_order()

Returns a generator: (keys, values) over the key_order (list)

Yields:(keys, value) in the order of the key_order (list)
class ReOBJ.MainCode.ReBase

Bases: builtins.object

Common Base of ReOBJ

Raises:MethodDeactivatedErr, KeyError, AttributeError, ReOBJ.ProjectErr.Err
static __add__(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

static __delattr__(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

static __setattr__(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

static clear(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

static copy(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

copy_recursively()

Create a recursively copy of the ReOBJ obj

  • copy_recursively(): recursively copy: Supports recursively intermediate ReDICT, ReLIST, ReTUPLE, dicts, lists and tuples (and their subclasses: depending on there implementation though)

    • this will also copy any ReDICT / ReLIST / ReTUPLE / ReMATRIX extra_data dict and any key_order (list) and any extra_key_order (list)
Returns:copy of the ReOBJ
  • all ReOBJ are copied inclusive any set: extra_data
Return type:obj
copy_recursively_to_python_native_types(use_extra_key_order=False)

Return a recursively copy: changing all ReOBJ to native python types.

  • RdictIO, RdictFO, RdictFO2: to python `OrderedDict obj keeping their order (see also argument: use_extra_key_order)
  • all other ReDICT: objects will be replaced by normal python dict objs
  • all ReLIST obj will be replaced by normal python list objs
  • all ReTUPLE obj will be replaced by normal python tuple objs
  • all ReMATRIX obj will be replaced by normal python list of tuple objs

Supports recursively intermediate ReDICT, ReLIST, ReTUPLE, dicts, lists and tuples (and their subclasses: depending on there implementation though)

Note

any ReOBJ set: extra_data will be lost

  • if True: the OrderedDict will be based on the extra_key_order (list)
  • if False: it will be base on the default key_order (list)
Returns:recursive copy of the obj with ReOBJs replaced by python native objs
Return type:obj
static deactivated_(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

replace_extra_data(new_extra_data_dict)

Replaces the extra_data (dict) with the dict

if extra_data did not exist it will be created

set_extra_data(key, value)

Sets/updates key/value to the additional dictionary: extra_data

In subclasses which use and init which sets always extra_data this method should be overwritten removing the: if

tojson(ensure_ascii=False, indent=' ')

Returns a new json dumps string from the obj

  • If ensure_ascii is True, the output is guaranteed to have all incoming non-ASCII characters escaped.
  • If ensure_ascii is False, these characters will be output as-is.
Returns:a pickled ReOBJ dumps
Return type:bytes
tojson_keeporder(use_extra_key_order=False, ensure_ascii=False, indent=' ')

Returns a new json dumps string from the obj keeping the order using first: copy_recursively_to_python_native_types()

  • RdictIO, RdictFO, RdictFO2: will keep their order (see also argument: use_extra_key_order)

    • if True: the OrderedDict will be based on the extra_key_order (list)
    • if False: it will be base on the default key_order (list)
Returns:a pickled ReOBJ dumps
Return type:bytes
topickle()

Returns a new pickled dumps byte string from the obj

Returns:a pickled ReOBJ dumps
Return type:bytes
update_extra_data(new_extra_data_dict)

Updates/Extends the additional dictionary: extra_data

In subclasses which use and init which sets always extra_data this method should be overwritten removing the: if

class ReOBJ.MainCode.Rlist

Bases: ReOBJ.MainCode.ReBase, builtins.list

A restricted list:

  • new items can be added
  • item values can be changed
  • item can not be deleted
Raises:MethodDeactivatedErr, ReOBJ.ProjectErr.Err
static frompickle(in_pickle_dumps)

Create a new Rlist from a pickled dumps.

Arg:
in_pickle_dumps (bytes): a pickled Rlist dumps
Returns:a new Rlist object
Return type:obj
pop(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

remove(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

class ReOBJ.MainCode.RlistF

Bases: ReOBJ.MainCode.Rlist

A restricted list: F(ix)

Similar to Rlist but after creation/initialization no new items can be added There are some other differences too.

  • can only be initialized but is fix afterwards
  • new items can not be added
  • item values can be changed
  • item can not be deleted
Raises:MethodDeactivatedErr, ReOBJ.ProjectErr.Err
append(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

extend(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

static frompickle(in_pickle_dumps)

Create a new RlistF from a pickled dumps.

Arg:
in_pickle_dumps (bytes): a pickled RlistF dumps
Returns:a new RlistF object
Return type:obj
insert(*args, **kwargs)

Helper method used to raise MethodDeactivatedErr

3.1.3. ReOBJ.ProjectErr module

Project Error

exception ReOBJ.ProjectErr.Err(error_type, info)

Bases: builtins.Exception

Prints an own raised ProjectError

Parameters:
  • errorType (str) – Error type: to specify mostly from which part the error comes: e.g. CONFIG
  • info (str) – text info to print as message
exception ReOBJ.ProjectErr.MethodDeactivatedErr

Bases: builtins.Exception

Prints an own raised Deactivated Err

3.1.4. ReOBJ.Version module

Version And Diverse Info

Module CONSTANTS:

__version__ str - the released version (last release)

RELEASE_DATE str - the date of the last release

SHORT_VERSION str - the main version is the: __version__ stripped of the last part: e.g. used by sphinx conf.py

TESTED_HOST_OS str - Keeps track of the HOST SYSTEM used to develop/test

__title__ str -

__copyright__ str -

__license__ str -

__author__ str -

3.1.5. Module contents

(c) 2014 peter1000 https://github.com/peter1000 All Rights Reserved

ReOBJ is distributed under the terms of the BSD 3-clause license. Consult LICENSE.rst or http://opensource.org/licenses/BSD-3-Clause.

Table Of Contents

Previous topic

3. ReOBJ

This Page