Commit 56255f73 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki Committed by Jérome Perrin

py2/py3: rewrite Base_viewSecurity with py2/py3 compatible way of print().

parent 68c3f84b
...@@ -6,18 +6,18 @@ u = getSecurityManager().getUser() ...@@ -6,18 +6,18 @@ u = getSecurityManager().getUser()
user_value = u.getUserValue() user_value = u.getUserValue()
if user_value is None: if user_value is None:
print 'User ID:', u.getId() print('User ID: %s' % u.getId())
else: else:
print 'User ID:', u.getId(), user_value.getPath() print('User ID: %s %s' % (u.getId(), user_value.getPath()))
login_value = u.getLoginValue() login_value = u.getLoginValue()
if login_value is None: if login_value is None:
print 'Login:', u.getUserName() print('Login: %s' % u.getUserName())
else: else:
print 'Login:', u.getUserName(), login_value.getPath() print('Login: %s %s' % (u.getUserName(), login_value.getPath()))
print 'Is owner:', u.allowed(context,('Owner',)) print('Is owner: %s' % u.allowed(context,('Owner',)))
print 'User roles:', u.getRoles() print('User roles: %s' % u.getRoles())
print 'User roles in context:', u.getRolesInContext(context) print('User roles in context: %s' % u.getRolesInContext(context))
print 'Permissions:' print('Permissions:')
for permission in [ for permission in [
'Access contents information', 'Access contents information',
'Add portal content', 'Add portal content',
...@@ -26,25 +26,25 @@ for permission in [ ...@@ -26,25 +26,25 @@ for permission in [
'View', 'View',
'Manage portal', 'Manage portal',
]: ]:
print " ", permission, u.has_permission(permission, context) print(" %s %s" % (permission, u.has_permission(permission, context)))
print print('')
try: try:
print "User groups:\n", pformat(sorted(u.getGroups())) print("User groups:\n%s" % pformat(sorted(u.getGroups())))
except AttributeError: except AttributeError:
print 'no getGroups' print('no getGroups')
print print('')
print 'Local roles on document:\n', pformat(context.get_local_roles()) print('Local roles on document:\n%s' % pformat(context.get_local_roles()))
print ''' print('''
---------------- ----------------
Security mapping Security mapping
----------------''' ----------------''')
if u.getId() is not None: if u.getId() is not None:
try: try:
print context.Base_viewSecurityMappingAsUser(u.getId()) print(context.Base_viewSecurityMappingAsUser(u.getId()))
except Unauthorized: except Unauthorized:
print "user doesn't have permission to security mapping in this context" print("user doesn't have permission to security mapping in this context")
return printed return printed
...@@ -16,12 +16,12 @@ for method_id, base_category_list in getSecurityCategoryMapping(): ...@@ -16,12 +16,12 @@ for method_id, base_category_list in getSecurityCategoryMapping():
security_category_dict.setdefault(tuple(base_category_list), []).extend( security_category_dict.setdefault(tuple(base_category_list), []).extend(
getattr(context, method_id)(base_category_list, login, context, '')) getattr(context, method_id)(base_category_list, login, context, ''))
except Exception: # XXX: it is not possible to log message with traceback from python script except Exception: # XXX: it is not possible to log message with traceback from python script
print 'It was not possible to invoke method %s with base_category_list %s'%(method_id, base_category_list) print('It was not possible to invoke method %s with base_category_list %s'%(method_id, base_category_list))
for base_category_list, category_value_list in security_category_dict.items(): for base_category_list, category_value_list in security_category_dict.items():
print 'base_category_list:', base_category_list print('base_category_list: %s' % (base_category_list,))
for category_dict in category_value_list: for category_dict in category_value_list:
print '-> category_dict:', category_dict print('-> category_dict: %s' % category_dict)
print '-->', group_id_list_generator(category_order=base_category_list, print('--> %s' % group_id_list_generator(category_order=base_category_list,
**category_dict) **category_dict))
return printed return printed
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment