[Zope-Checkins] SVN: Zope/trunk/ Use a better __repr__ for User
objects.
Florent Guillaume
fg at nuxeo.com
Wed Nov 9 14:53:08 EST 2005
Log message for revision 40006:
Use a better __repr__ for User objects.
(NullUnrestrictedUser had a non-string repr that made it impossible to
debug properly.)
Changed:
U Zope/trunk/doc/CHANGES.txt
U Zope/trunk/lib/python/AccessControl/User.py
U Zope/trunk/lib/python/AccessControl/tests/testUserFolder.py
-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt 2005-11-09 19:39:45 UTC (rev 40005)
+++ Zope/trunk/doc/CHANGES.txt 2005-11-09 19:53:08 UTC (rev 40006)
@@ -86,6 +86,8 @@
Other
+ - AccessControl.User: Use a better __repr__.
+
- ZSQLMethod.manage_main: Moved the error message that warns of a
non-existing or closed database connection next to the Connection ID
dropdown and present it using red to increase its visibility.
Modified: Zope/trunk/lib/python/AccessControl/User.py
===================================================================
--- Zope/trunk/lib/python/AccessControl/User.py 2005-11-09 19:39:45 UTC (rev 40005)
+++ Zope/trunk/lib/python/AccessControl/User.py 2005-11-09 19:53:08 UTC (rev 40006)
@@ -276,7 +276,8 @@
def __len__(self): return 1
def __str__(self): return self.getUserName()
- __repr__=__str__
+ def __repr__(self):
+ return '<%s %r>' % (self.__class__.__name__, self.getUserName())
class SimpleUser(BasicUser):
Modified: Zope/trunk/lib/python/AccessControl/tests/testUserFolder.py
===================================================================
--- Zope/trunk/lib/python/AccessControl/tests/testUserFolder.py 2005-11-09 19:39:45 UTC (rev 40005)
+++ Zope/trunk/lib/python/AccessControl/tests/testUserFolder.py 2005-11-09 19:53:08 UTC (rev 40006)
@@ -275,7 +275,22 @@
f = User('chris', '123', ['Manager'], [])
self.assertEqual(f.getDomains(), ())
+ def testRepr(self):
+ f = User('flo', '123', ['Manager'], [])
+ self.assertEqual(repr(f), "<User 'flo'>")
+ def testReprSpecial(self):
+ from AccessControl.User import NullUnrestrictedUser
+ from AccessControl.User import nobody
+ from AccessControl.User import system
+ # NullUnrestrictedUser is used when there is no emergency user
+ self.assertEqual(repr(NullUnrestrictedUser()),
+ "<NullUnrestrictedUser (None, None)>")
+ self.assertEqual(repr(nobody),
+ "<SpecialUser 'Anonymous User'>")
+ self.assertEqual(repr(system),
+ "<UnrestrictedUser 'System Processes'>")
+
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(UserFolderTests))
More information about the Zope-Checkins
mailing list