rolne’s Class Methods

class rolne.rolne(in_list=None, in_tuple=None, ancestor=None, NS=None)
append(name, value=None, sublist=None, seq=None)

Add one name/value entry to the main context of the rolne.

If you are wanting to “append” another rolne, see the ‘extend’ method instead.

Example of use:

>>> # setup an example rolne first
>>> my_var = rolne()
>>> my_var.append("item", "zing")
>>> my_var["item", "zing"].append("size", "4")
>>> my_var["item", "zing"].append("color", "red")
>>> print my_var
%rolne:
item = zing
    size = 4
    color = red

>>> my_var.append("item", "zing")
>>> my_var["item", "zing", -1].append("size", "2")
>>> my_var["item", "zing", -1].append("color", "blue")
>>> print my_var
%rolne:
item = zing
    size = 4
    color = red
item = zing
    size = 2
    color = blue

New in version 0.1.1.

Parameters:
  • name – The key name of the name/value pair.
  • value – The key value of the name/value pair. If not passed, then the value is assumed to be None.
  • sublist – An optional parameter that also appends a subtending list of entries. It is not recommended that this parameter be used.
append_index(name, value=None, sublist=None, seq=None)

Add one name/value entry to the main context of the rolne and return the index number for the new entry.

If you are wanting to “append” another rolne, see the ‘extend’ method instead.

Example of use:

>>> # setup an example rolne first
>>> my_var = rolne()
>>> index = my_var.append_index("item", "zing")
>>> print index
0
>>> my_var["item", "zing", index].append("size", "4")
>>> my_var["item", "zing", index].append("color", "red")
>>> print my_var
%rolne:
item = zing
    size = 4
    color = red

>>> index = my_var.append_index("item", "zing")
>>> print index
1
>>> my_var["item", "zing", index].append("size", "2")
>>> my_var["item", "zing", index].append("color", "blue")
>>> print my_var
%rolne:
item = zing
    size = 4
    color = red
item = zing
    size = 2
    color = blue

New in version 0.1.4.

Parameters:
  • name – The key name of the name/value pair.
  • value – The key value of the name/value pair. If not passed, then the value is assumed to be None.
  • sublist – An optional parameter that also appends a subtending list of entries. It is not recommended that this parameter be used.
Returns:

An integer representing the index of the newly inserted name/pair.

append_seq(name, value=None, sublist=None, seq=None)

Add one name/value entry to the current context of the rolne and return the new sequence string.

If you are wanting to “append” another rolne, see the ‘extend’ method instead.

Example of use:

>>> # setup an example rolne first
>>> my_var = rolne()
>>> my_var.append("item", "zing")
>>> my_var["item", "zing"].append("size", "4")
>>> my_var["item", "zing"].append("color", "red")
>>> print my_var
%rolne:
item = zing
    size = 4
    color = red

>>> my_var.append("item", "zing")
>>> my_var["item", "zing", -1].append("size", "2")
>>> my_var["item", "zing", -1].append("color", "blue")
>>> print my_var
%rolne:
item = zing
    size = 4
    color = red
item = zing
    size = 2
    color = blue

New in version 0.1.1.

Parameters:
  • name – The key name of the name/value pair.
  • value – The key value of the name/value pair. If not passed, then the value is assumed to be None.
  • sublist – An optional parameter that also appends a subtending list of entries. It is not recommended that this parameter be used.
find(*argv)

Locate a single rolne entry.

This function is very similar to simply doing a dictionary-style lookup. For example:

new_rolne = my_var.find(“test”, “zoom”, 4)

is effectively the same as:

new_rolne = my_var[“test”, “zoom”, 4]

The biggest difference is that if entry at [“test”, “zoom”, 4] does not exist, the dictionary-style lookup generates a key error. Whereas this method simply returns None.

Example of use:

>>> # setup an example rolne first
>>> my_var = rolne()
>>> my_var.append("item", "zing")
>>> my_var["item", "zing"].append("size", "4")
>>> my_var["item", "zing"].append("color", "red")
>>> my_var["item", "zing"]["color", "red"].append("intensity", "44%")
>>> my_var["item", "zing"].append("reverse", None)
>>> my_var.append("item", "broom")
>>> my_var["item", "broom", -1].append("size", "1")
>>> my_var["item", "broom", -1].append("title", 'The "big" thing')
>>> my_var.append("item", "broom")
>>> my_var["item", "broom", -1].append("size", "2")
>>> my_var["item", "broom", -1].append("title", 'Other thing')
>>> my_var.append("code_seq")
>>> my_var["code_seq", None].append("*", "r9")
>>> my_var["code_seq", None].append("*", "r3")
>>> my_var["code_seq", None].append("*", "r2")
>>> my_var["code_seq", None].append("*", "r3")
>>> my_var.append("system_title", "hello")
>>> #
>>> print my_var.find("item","broom",1)
%rolne:
size = 2
title = "Other thing"

>>> print my_var.find("item","broom",2)
None
>>> print my_var["code_seq", None].find("*","r3")
%rolne:
%empty

New in version 0.1.2.

Parameters:
  • name – The key name of the name/value pair.
  • value – The key value of the name/value pair. If not passed, then the value is assumed to be empty (None).
  • index – The index of the name/value pair. if not passed, then the index is assumed to be 0.
Returns:

Returns either a rolne that points to the located entry or None if that entry is not found.

name

Name property.

This property represents the name of the rolne in its current context. For a new or original rolne, the name is always None. That is because the root of a rolne cannot conceptually have its own name.

It is possible to both read and write to the name property. Any change to name is also seen in other contexts. It is strongly recommended that name be given an immutable value.

It is not possible to delete the name property.

Example of use:

>>> # setup an example rolne first
>>> my_var = rolne()
>>> my_var.append("item", "zing")
>>> my_var["item", "zing"].append("size", "4")
>>> my_var["item", "zing"].append("color", "red")
>>> my_var["item", "zing"]["color", "red"].append("intensity", "44%")
>>> my_var["item", "zing"].append("reverse", None)
>>> my_var.append("item", "broom")
>>> my_var["item", "broom", -1].append("size", "1")
>>> my_var["item", "broom", -1].append("title", 'The "big" thing')
>>> my_var.append("item", "broom")
>>> my_var["item", "broom", -1].append("size", "2")
>>> my_var["item", "broom", -1].append("title", 'Other thing')
>>> #
>>> print my_var.name
None
>>> temp = my_var["item", "broom", 2]
>>> print temp.name
item
>>> temp.name = "hello"
>>> print temp.name
hello
>>> print my_var["hello", "broom", 2].name
hello

New in version 0.2.1.

seq

Sequence property.

This property represents the sequence assigned to the rolne in its current context. For a new or original rolne, the seq is always None. That is because the root of a rolne cannot conceptually have a sequence.

You can both read and write seq. However, it is not possible to delete. If written, the given value is always converted to a string. TODO: test string conversion

New in version 0.2.1.

upsert(name, value=None, seq=None)

Add one name/value entry to the main context of the rolne, but only if an entry with that name does not already exist.

If the an entry with name exists, then the first entry found has it’s value changed.

NOTE: the upsert only updates the FIRST entry with the name found.

The method returns True if an insertion occurs, otherwise False.

Example of use:

>>> # setup an example rolne first
>>> my_var = rolne()
>>> my_var.upsert("item", "zing")
True
>>> my_var["item", "zing"].append("color", "blue")
>>> print my_var
%rolne:
item = zing
    color = blue

>>> my_var.upsert("item", "zing")
False
>>> print my_var
%rolne:
item = zing
    color = blue

>>> my_var.upsert("item", "broom")
False
>>> print my_var
%rolne:
item = broom
    color = blue

New in version 0.1.1.

Parameters:
  • name – The key name of the name/value pair.
  • value – The key value of the name/value pair. If not passed, then the value is assumed to be None.
Returns:

Returns True if the name/value was newly inserted. Otherwise, it returns False indicated that an update was done instead.

value

value property.

This property represents the value (of name/value) assigned to the rolne in its current context. For a new or original rolne, the seq is always None. That is because the root of a rolne cannot conceptually have a value.

You can both read and write value. If it is deleted, it is simply set to None.

New in version 0.2.1.