_make_msgfunction: convert to class
authorZac Medico <zmedico@gentoo.org>
Fri, 18 Nov 2011 05:33:37 +0000 (21:33 -0800)
committerZac Medico <zmedico@gentoo.org>
Fri, 18 Nov 2011 05:33:37 +0000 (21:33 -0800)
pym/portage/elog/messages.py

index 98d6206d057f19de95979e4c26de16c8662ef23c..ba2ed466bb38d620469b27b691b67c2c6e85e104 100644 (file)
@@ -172,13 +172,17 @@ _functions = { "einfo": ("INFO", "GOOD"),
                "eerror": ("ERROR", "BAD"),
 }
 
-def _make_msgfunction(level, color):
-       def _elog(msg, phase="other", key=None, out=None):
-               """ Display and log a message assigned to the given key/cpv 
-                   (or unassigned if no key is given).
+class _make_msgfunction(object):
+       __slots__ = ('_color', '_level')
+       def __init__(self, level, color):
+               self._level = level
+               self._color = color
+       def __call__(self, msg, phase="other", key=None, out=None):
+               """
+               Display and log a message assigned to the given key/cpv.
                """ 
-               _elog_base(level, msg,  phase=phase, key=key, color=color, out=out)
-       return _elog
+               _elog_base(self._level, msg,  phase=phase,
+                       key=key, color=self._color, out=out)
 
 for f in _functions:
        setattr(sys.modules[__name__], f, _make_msgfunction(_functions[f][0], _functions[f][1]))