command_interpreter.utils – Utilities

Utility functionalities

vdat.command_interpreter.utils.id_(*args)[source]

Identity function: returns the input unchanged

If the input is one element only, extract it from args

Examples

>>> id_()
()
>>> id_(5)
5
>>> id_(3, 4)
(3, 4)
>>> a, b, c = id_(2, 3, 4)
>>> print(a, b, c)
2 3 4
vdat.command_interpreter.utils.flip(func)[source]

Flip the order of the arguments in the function

Can also be used a decorator

Parameters:
func : callable

function to replace

Returns:
callable
vdat.command_interpreter.utils.multiwrap(*decorators)[source]

Create a decorator combining the given decorators

class vdat.command_interpreter.utils.SliceLike(str_or_int, *args)[source]

A slice like object, but it’s not usable as slice.

If the input argument is a string of : or , separated integers parse it assuming [start]:[stop][:step]. start, stop, and step must be integers or None; the latter is optional and cannot be zero.

It’s possible to use the in statement to check if a value is in the slice with the following logic:

  • if start is not given, it checks that the value is less than stop
  • if stop is not given, it checks that the value is greater or equal than start
  • if neither start not stop are given and step is not given or one, returns True
  • if step is not 1, it checks that the value is equal to start + n*step with integer n.
  • if start is not given and step is not 1, returns False; undefined behaviour.
Parameters:
str_or_int, args : string or one/two/three integers

if the first argument is a string is parsed as if it’s a : or , separated one and all the elements are converted to None (if empty) or to integers. In this case no other arguments are allowed. If the arguments are integers are interpreted as:

SliceLike(stop)

SliceLike(start, stop[, step])

Raises:
CISliceError

if the initialisation fails

Attributes:
start

Start of the slice (read only)

stop

Stop of the slice (read only)

step

Step of the slice (read only)

start

Start of the slice (read only)

stop

Stop of the slice (read only)

step

Step of the slice (read only)

range()[source]

Create and returns a range using the elements of the slice.

If start is None, set it to 0, if stop is None, it fails and when step is None set it to 1.

Returns:
a range or a xrange object (python 3 / python 2)
vdat.command_interpreter.utils.abstractproperty(func)