You could also strip the mail, givenName, sn here so you don't have to do those `(foo is None) or (foo.strip() == "")` checks later.