based on internal repository c9a2ac8 2019-01-03 16:04:57 +0100 tagged rev-master-2.0.0
25 lines
651 B
Python
25 lines
651 B
Python
"""
|
|
@package pmsco.helpers
|
|
helper classes
|
|
|
|
a collection of small and generic code bits mostly collected from the www.
|
|
|
|
"""
|
|
|
|
|
|
class BraceMessage(object):
|
|
"""
|
|
a string formatting proxy class useful for logging and exceptions.
|
|
|
|
use BraceMessage("{0} {1}", "formatted", "message")
|
|
in place of "{0} {1}".format("formatted", "message").
|
|
the advantage is that the format method is called only if the string is actually used.
|
|
"""
|
|
def __init__(self, fmt, *args, **kwargs):
|
|
self.fmt = fmt
|
|
self.args = args
|
|
self.kwargs = kwargs
|
|
|
|
def __str__(self):
|
|
return self.fmt.format(*self.args, **self.kwargs)
|