From c14acc0fae8b7c19988dfe3352a297ec22d624e9 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Mon, 14 Aug 2017 10:38:16 +0200 Subject: [PATCH] [mod] don't use exception when not needed --- src/yunohost/user.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/yunohost/user.py b/src/yunohost/user.py index ee0655291..deb5de077 100644 --- a/src/yunohost/user.py +++ b/src/yunohost/user.py @@ -115,11 +115,8 @@ def user_create(auth, username, firstname, lastname, mail, password, }) # Validate uniqueness of username in system users - try: - pwd.getpwnam(username) - except KeyError: - pass - else: + all_existing_usernames = {x.pw_name for x in pwd.getpwall()} + if username in all_existing_usernames: raise MoulinetteError(errno.EEXIST, m18n.n('system_username_exists')) # Check that the mail domain exists