Package pyrobase :: Module fmt
[hide private]
[frames] | no frames]

Module fmt

source code

Data Formatting.

Copyright (c) 2009, 2011 The PyroScope Project <pyroscope.project@gmail.com>

Functions [hide private]
 
human_size(size)
Return a human-readable representation of a byte size.
source code
 
iso_datetime(timestamp=None)
Convert UNIX timestamp to ISO datetime string.
source code
 
iso_datetime_optional(timestamp)
Convert UNIX timestamp to ISO datetime string, or "never".
source code
 
human_duration(time1, time2=None, precision=0, short=False)
Return a human-readable representation of a time delta.
source code
 
to_unicode(text)
Return a decoded unicode string.
source code
 
to_utf8(text)
Enforce UTF8 encoding.
source code
 
to_console(text)
Return a byte string intended for console output.
source code
Variables [hide private]
  log = logging.getLogger(__name__)
  __package__ = 'pyrobase'
Function Details [hide private]

human_size(size)

source code 

Return a human-readable representation of a byte size.

Parameters:
  • size - Number of bytes as an integer or string.
Returns:
String of length 10 with the formatted result.

iso_datetime(timestamp=None)

source code 

Convert UNIX timestamp to ISO datetime string.

Parameters:
  • timestamp - UNIX epoch value (default: the current time).
Returns:
Timestamp formatted as "YYYY-mm-dd HH:MM:SS".

iso_datetime_optional(timestamp)

source code 

Convert UNIX timestamp to ISO datetime string, or "never".

Parameters:
  • timestamp - UNIX epoch value.
Returns:
Timestamp formatted as "YYYY-mm-dd HH:MM:SS", or "never" for false values.

human_duration(time1, time2=None, precision=0, short=False)

source code 

Return a human-readable representation of a time delta.

Parameters:
  • time1 - Relative time value.
  • time2 - Time base (None for now; 0 for a duration in time1).
  • precision - How many time units to return (0 = all).
  • short - Use abbreviations, and right-justify the result to always the same length.
Returns:
Formatted duration.

to_unicode(text)

source code 

Return a decoded unicode string. False values are returned untouched.