From 83320afa97cf62e8fb01102ffbf974229a243012 Mon Sep 17 00:00:00 2001 From: Ask Solem Date: Mon, 15 Aug 2011 12:41:49 +0100 Subject: [PATCH] Adds utils reprkwargs + reprcall --- kombu/utils/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kombu/utils/__init__.py b/kombu/utils/__init__.py index 943b4814..dffe67da 100644 --- a/kombu/utils/__init__.py +++ b/kombu/utils/__init__.py @@ -3,6 +3,8 @@ import sys from time import sleep from uuid import UUID, uuid4 as _uuid4, _uuid_generate_random +from kombu.utils.encoding import safe_repr as _safe_repr + try: import ctypes except: @@ -257,3 +259,13 @@ class cached_property(object): def deleter(self, fdel): return self.__class__(self.__get, self.__set, fdel) + + +def reprkwargs(kwargs, sep=', ', fmt="%s=%s"): + return sep.join(fmt % (k, _safe_repr(v)) for k, v in kwargs.iteritems()) + + +def reprcall(name, args=(), kwargs=(), sep=', '): + return "%s(%s%s%s)" % (name, sep.join(map(_safe_repr, args)), + (args and kwargs) and sep or "", + reprkwargs(kwargs, sep))