tensorbay.utility.user#

Basic concepts of user-defined objects.

class tensorbay.utility.user.UserSequence(*args, **kwds)[source]#

Bases: Sequence[tensorbay.utility.user._T], tensorbay.utility.repr.ReprMixin

UserSequence is a user-defined wrapper around sequence objects.

index(value, start=0, stop=9223372036854775807)[source]#

Return the first index of the value.

Parameters
  • value (tensorbay.utility.user._T) – The value to be found.

  • start (int) – The start index of the subsequence.

  • stop (int) – The end index of the subsequence.

Returns

The First index of value.

Return type

int

count(value)[source]#

Return the number of occurrences of value.

Parameters

value (tensorbay.utility.user._T) – The value to be counted the number of occurrences.

Returns

The number of occurrences of value.

Return type

int

class tensorbay.utility.user.UserMutableSequence(*args, **kwds)[source]#

Bases: MutableSequence[tensorbay.utility.user._T], tensorbay.utility.user.UserSequence[tensorbay.utility.user._T]

UserMutableSequence is a user-defined wrapper around mutable sequence objects.

insert(index, value)[source]#

Insert object before index.

Parameters
  • index (int) – Position of the mutable sequence.

  • value (tensorbay.utility.user._T) – Element to be inserted into the mutable sequence.

Return type

None

append(value)[source]#

Append object to the end of the mutable sequence.

Parameters

value (tensorbay.utility.user._T) – Element to be appended to the mutable sequence.

Return type

None

clear()[source]#

Remove all items from the mutable sequence.

Return type

None

extend(values)[source]#

Extend mutable sequence by appending elements from the iterable.

Parameters

values (Iterable[tensorbay.utility.user._T]) – Elements to be Extended into the mutable sequence.

Return type

None

reverse()[source]#

Reverse the items of the mutable sequence in place.

Return type

None

pop(index=- 1)[source]#

Return the item at index (default last) and remove it from the mutable sequence.

Parameters

index (int) – Position of the mutable sequence.

Returns

Element to be removed from the mutable sequence.

Return type

tensorbay.utility.user._T

remove(value)[source]#

Remove the first occurrence of value.

Parameters

value (tensorbay.utility.user._T) – Element to be removed from the mutable sequence.

Return type

None

class tensorbay.utility.user.UserMapping(*args, **kwds)[source]#

Bases: Mapping[tensorbay.utility.user._K, tensorbay.utility.user._V], tensorbay.utility.repr.ReprMixin

UserMapping is a user-defined wrapper around mapping objects.

get(key: tensorbay.utility.user._K) Optional[tensorbay.utility.user._V][source]#
get(key: tensorbay.utility.user._K, default: Union[tensorbay.utility.user._V, tensorbay.utility.user._T] = None) Union[tensorbay.utility.user._V, tensorbay.utility.user._T]

Return the value for the key if it is in the dict, else default.

Parameters
  • key – The key for dict, which can be any immutable type.

  • default – The value to be returned if key is not in the dict.

Returns

The value for the key if it is in the dict, else default.

items()[source]#

Return a new view of the (key, value) pairs in dict.

Returns

The (key, value) pairs in dict.

Return type

AbstractSet[Tuple[tensorbay.utility.user._K, tensorbay.utility.user._V]]

keys()[source]#

Return a new view of the keys in dict.

Returns

The keys in dict.

Return type

AbstractSet[tensorbay.utility.user._K]

values()[source]#

Return a new view of the values in dict.

Returns

The values in dict.

Return type

ValuesView[tensorbay.utility.user._V]

class tensorbay.utility.user.UserMutableMapping(*args, **kwds)[source]#

Bases: MutableMapping[tensorbay.utility.user._K, tensorbay.utility.user._V], tensorbay.utility.user.UserMapping[tensorbay.utility.user._K, tensorbay.utility.user._V]

UserMutableMapping is a user-defined wrapper around mutable mapping objects.

clear()[source]#

Remove all items from the mutable mapping object.

Return type

None

pop(key: tensorbay.utility.user._K) tensorbay.utility.user._V[source]#
pop(key: tensorbay.utility.user._K, default: Union[tensorbay.utility.user._V, tensorbay.utility.user._T] = <object object>) Union[tensorbay.utility.user._V, tensorbay.utility.user._T]

Remove specified item and return the corresponding value.

Parameters
  • key – The key for dict, which can be any immutable type.

  • default – The value to be returned if the key is not in the dict and it is given.

Returns

Value to be removed from the mutable mapping object.

popitem()[source]#

Remove and return a (key, value) pair as a tuple.

Pairs are returned in LIFO (last-in, first-out) order.

Returns

A (key, value) pair as a tuple.

Return type

Tuple[tensorbay.utility.user._K, tensorbay.utility.user._V]

setdefault(key, default=None)[source]#

Set the value of the item with the specified key.

If the key is in the dict, return the corresponding value. If not, insert the key with a value of default and return default.

Parameters
  • key (tensorbay.utility.user._K) – The key for dict, which can be any immutable type.

  • default (Optional[tensorbay.utility.user._V]) – The value to be set if the key is not in the dict.

Returns

The value for key if it is in the dict, else default.

Return type

tensorbay.utility.user._V

update(__m: Mapping[tensorbay.utility.user._K, tensorbay.utility.user._V], **kwargs: tensorbay.utility.user._V) None[source]#
update(__m: Iterable[Tuple[tensorbay.utility.user._K, tensorbay.utility.user._V]], **kwargs: tensorbay.utility.user._V) None
update(**kwargs: tensorbay.utility.user._V) None

Update the dict.

Parameters
  • __m – A dict object, a generator object yielding a (key, value) pair or other object which has a .keys() method.

  • **kwargs – The value to be added to the mutable mapping.