Utilities

class debrepo.utils.PluralFormatter[source]

Formatter syntax: {key|unit}, {key~sep}

The key is the index of the argument or the key of the keyword argument to interpret and interpolate. The value must be an integer.

The unit can be “base(suffix)” or “either/or”, e.g.:

  • antenna(e)
  • goose/geese
  • fox(es)

If unit is preceded by a *, take len(value) instead of value as the count (i.e., {key|*item(s)} will count the values at key instead of interpreting the value at key as the count directly).

In the second form, sep is a string with which to join the list indicated by key (and the value must be a valid argument to string.join()).

Examples:

>>> geese = [ 'goose1', 'goose2' ]
>>> FMT.format('Your geese are {0~ & }', geese)
'Your geese are goose1 & goose2'
>>> FMT.format('You still have {0|goose/geese}', len(geese))
'You still have 2 geese'
>>> geese = [ 'goose1' ]
>>> FMT.format('You still have {geese|*goose/geese}', geese=geese)
'You still have 1 goose'
debrepo.utils.FMT = <debrepo.utils.PluralFormatter object>

Instance of PluralFormatter exported for convenience