code: def autocomplete(self, sources):
          
          email_pattern = re.compile(EMAIL_ADDRESS_REGEX)
  
          identities = self.__select_autocomplete_identities(sources)
  
          for uuid, ids in identities.items():
              # Among the identities (with the same priority) selected
              # to complete the profile, it will choose the longest 'name'.
              # If no name is available, it will use the field 'username'.
              name = None
              email = None
  
              for identity in ids:
                  oldname = name
  
                  if not name:
                      name = identity.name or identity.username
                  elif identity.name and len(identity.name) > len(name):
                      name = identity.name
  
                  # Do not set email addresses on the name field
                  if name and email_pattern.match(name):
                      name = oldname
  
                  if not email and identity.email:
                      email = identity.email
  
              kw = {
                  'name': name,
                  'email': email
              }
  
              try:
                  api.edit_profile(self.db, uuid, **kw)
                  self.display('autoprofile.tmpl', identity=identity)
              except (NotFoundError, InvalidValueError) as e:
                  self.error(str(e))
                  return e.code
  
          return CMD_SUCCESS
docs: Autocomplete unique identities profiles.
  
          Autocomplete unique identities profiles using the information
          of their identities. The selection of the data used to fill
          the profile is prioritized using a list of sources.