mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-05 03:38:12 +08:00
implement BaseMessage.__repr__
Take advantage of the information contained in signature/parameter objects to represent positional and keyword arguments properly. Fall back to using the funcsigs module on Python 2.
This commit is contained in:
@@ -11,3 +11,4 @@ Flask-Script
|
||||
Flask-SQLAlchemy
|
||||
Flask-Migrate
|
||||
python-fedora
|
||||
funcsigs # Python2 only
|
||||
|
||||
@@ -25,6 +25,11 @@
|
||||
"""Generic messaging functions."""
|
||||
|
||||
import re
|
||||
try:
|
||||
from inspect import signature
|
||||
except ImportError:
|
||||
from funcsigs import signature
|
||||
|
||||
from rida import logger
|
||||
|
||||
|
||||
@@ -36,6 +41,17 @@ class BaseMessage(object):
|
||||
"""
|
||||
self.msg_id = msg_id
|
||||
|
||||
def __repr__(self):
|
||||
init_sig = signature(self.__init__)
|
||||
|
||||
args_strs = (
|
||||
"{}={!r}".format(name, getattr(self, name))
|
||||
if param.default != param.empty
|
||||
else repr(getattr(self, name))
|
||||
for name, param in init_sig.parameters.items())
|
||||
|
||||
return "{}({})".format(type(self).__name__, ', '.join(args_strs))
|
||||
|
||||
@staticmethod
|
||||
def from_fedmsg(topic, msg):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user