URL: https://github.com/freeipa/freeipa/pull/275 Author: martbab Title: #275: Enhance __repr__ method of Principal Action: synchronized
To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/275/head:pr275 git checkout pr275
From 53a2e9d5b64c15dfd4b65069316a957c977aafb0 Mon Sep 17 00:00:00 2001 From: Martin Babinsky <mbabi...@redhat.com> Date: Mon, 28 Nov 2016 10:22:26 +0100 Subject: [PATCH] Enhance __repr__ method of Principal `__repr__` now returns more descriptive string containing the actual principal name while keeping the ability to reconstruct the object from it. This makes principal names visible in debug logs, easing troubleshooting a bit. https://fedorahosted.org/freeipa/ticket/6505 --- ipapython/kerberos.py | 4 ++++ ipatests/test_ipapython/test_kerberos.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/ipapython/kerberos.py b/ipapython/kerberos.py index a8ebc04..3d3530c 100644 --- a/ipapython/kerberos.py +++ b/ipapython/kerberos.py @@ -181,3 +181,7 @@ def __str__(self): principal_string = u'@'.join([principal_string, realm]) return principal_string + + def __repr__(self): + return "{0.__module__}.{0.__name__}('{1}')".format( + self.__class__, self) diff --git a/ipatests/test_ipapython/test_kerberos.py b/ipatests/test_ipapython/test_kerberos.py index 7e1eca4..284d8c2 100644 --- a/ipatests/test_ipapython/test_kerberos.py +++ b/ipatests/test_ipapython/test_kerberos.py @@ -82,6 +82,8 @@ def test_principals(valid_principal): assert getattr(princ, name) == value assert unicode(princ) == principal_name + assert repr(princ) == "ipapython.kerberos.Principal('{}')".format( + principal_name) def test_multiple_unescaped_ats_raise_error():
-- Manage your subscription for the Freeipa-devel mailing list: https://www.redhat.com/mailman/listinfo/freeipa-devel Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code