smart_list Package

smart_list Package

This module contains the SmartList type, as well as its ListProxy child, which together implement a list whose sublists reflect changes made to the main list, and vice-versa.

list_proxy Module

class mwparserfromhell.smart_list.list_proxy.ListProxy(parent, sliceinfo)[source]

Implement the list interface by getting elements from a parent.

This is created by a SmartList object when slicing. It does not actually store the list at any time; instead, whenever the list is needed, it builds it dynamically using the _render() method.

append(item)[source]

Append object to the end of the list.

count(item)[source]

Return number of occurrences of value.

extend(item)[source]

Extend list by appending elements from the iterable.

index(item, start=None, stop=None)[source]

Return first index of value.

Raises ValueError if the value is not present.

insert(index, item)[source]

Insert object before index.

pop(index=None)[source]

Remove and return item at index (default last).

Raises IndexError if list is empty or index is out of range.

remove(item)[source]

Remove first occurrence of value.

Raises ValueError if the value is not present.

reverse()[source]

Reverse IN PLACE.

sort(key=None, reverse=None)[source]

Stable sort IN PLACE.

smart_list Module

class mwparserfromhell.smart_list.smart_list.SmartList(iterable=None)[source]

Implements the list interface with special handling of sublists.

When a sublist is created (by list[i:j]), any changes made to this list (such as the addition, removal, or replacement of elements) will be reflected in the sublist, or vice-versa, to the greatest degree possible. This is implemented by having sublists - instances of the ListProxy type - dynamically determine their elements by storing their slice info and retrieving that slice from the parent. Methods that change the size of the list also change the slice info. For example:

>>> parent = SmartList([0, 1, 2, 3])
>>> parent
[0, 1, 2, 3]
>>> child = parent[2:]
>>> child
[2, 3]
>>> child.append(4)
>>> child
[2, 3, 4]
>>> parent
[0, 1, 2, 3, 4]
append(item)[source]

Append object to the end of the list.

extend(item)[source]

Extend list by appending elements from the iterable.

insert(index, item)[source]

Insert object before index.

pop(index=None)[source]

Remove and return item at index (default last).

Raises IndexError if list is empty or index is out of range.

remove(item)[source]

Remove first occurrence of value.

Raises ValueError if the value is not present.

reverse()[source]

Reverse IN PLACE.

sort(key=None, reverse=None)[source]

Stable sort IN PLACE.

utils Module