Formatter¶
This file contains various stringification utilities.
- Formatter.number(number, decimals, dec_point, thousands_sep)¶
- Arguments
number (
float()
) – A number to formatdecimals (
int()
) – Count of decimals to print (defaults to 2)dec_point (
string()
) – Decimal point separator (defaults to “,”)thousands_sep (
string()
) – Thousand separator (defaults to “.”)
- Returns
A string representation of number, formatted accordingly.
- Formatter.int_zero(number, length)¶
- Arguments
number (
int()
) – Number to printlength (
int()
) – Number of digits to print
- Returns
a zero-padded string
- Formatter.size_i(value)¶
Treat value as a file size, and return a pretty formatted version with base 2 exponent.
- Arguments
value (
int()
) – A file size
- Returns
A string with a human-readable representation of file size, base-2 based.
- Formatter.size(value)¶
Treat value as a file size, and return a pretty formatted version with base 10 exponent.
- Arguments
value (
int()
) – A file size
- Returns
A string with a human-readable representation of file size, base-10 based.
- Formatter.rate(value, short)¶
Treat value as a file transfer rate, and return a pretty formatted version with base 10 exponent.
- Arguments
value (
int()
) – A file transfer rate, in byte/secshort (
bool()
) – Whether to use “bytes/sec” or “b/s” (default to false)
- Returns
A string with a human-readable representation of rate, base-10 based.
- Formatter.bitrate(value, short)¶
Treat value as a data transfer rate, and return a pretty formatted version with base 10 exponent.
- Arguments
value (
int()
) – A data transfer rate, in bit/sec
- Returns
A string with a human-readable representation of rate, base-10 based.
- Formatter.min_to_msec(value)¶
- Arguments
value (
int()
) – A number of minutes
- Returns
a number of seconds
- Formatter.uptime(value, simplified)¶
- Arguments
value (
int()
) – A number of secondssimplified (
bool()
) – Whether to express time in plain french or abbreviated
- Returns
a string containing time as a sentence
- Formatter.hms(value)¶
- Arguments
value (
int()
) – A number of seconds
- Returns
a string containing time as hh:mm:ss
- Formatter.mac(bytes)¶
- Arguments
bytes (
list()
) – A list of 6 integers between 0 and 255
- Returns
a string containing mac address as xx:xx:xx:xx:xx:xx
- Formatter.ipv4(bytes)¶
- Arguments
bytes (
list()
) – A list of 4 integers between 0 and 255
- Returns
a string containing IP address as xxx.xxx.xxx.xxx
- Formatter.date(timestamp, datePrefix)¶
- Arguments
timestamp (
int()
) – An unix timestampdatePrefix (
string()
) – A string to prepend for absolute dates
- Returns
a string
Stringifies a date in french, with
datePrefix
prepended, except when date is within 24 hours where a string like “aujourd’hui”, “demain” or “hier” will be returned.
- Formatter.time(timestamp)¶
- Arguments
timestamp (
int()
) – An unix timestamp
- Returns
a string formatted as “HHhmm”
- Formatter.duration(value)¶
- Arguments
value (
int()
) – A number of seconds
- Returns
a string containing time as a days/hours/minutes length
- Formatter.enumeration(list)¶
- Arguments
list (
list()
) – A list of strings
- Returns
a string enumerating strings in list as a french sentence.
enumeration(["a", "b"]) == "a et b"
enumeration(["a", "b", "c"]) == "a , b et c"
- Formatter.capitalize(str)¶
- Arguments
str (
string()
) – A string
- Returns
same string with first character uppercased
- Formatter.weekdays(monday, tuesday, wednesday, thursday, friday, saturday, sunday, short)¶
- Arguments
short (
bool()
) – whether to use 3-letter or full version of week day names
- Returns
shortest possible string enumerating all the true days.
weekdays(true, true) == "tous les lundis et mardis"
weekdays(false, false, false, false, false, true, true) == "le week-end"
weekdays(true, true, false, true, true, true, true) == "tous les jours sauf le mercredi"