x3m_tm

Untitled

Jun 24th, 2021
683
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class NameNotFound(Exception):
  2.     pass
  3.  
  4.  
  5. class MustContainAtSymbol(Exception):
  6.     pass
  7.  
  8.  
  9. class TooManyAtSymbols(Exception):
  10.     pass
  11.  
  12.  
  13. class NameTooShortError(Exception):
  14.     pass
  15.  
  16.  
  17. class InvalidDomain(Exception):
  18.     pass
  19.  
  20.  
  21. ALLOWED_DOMAINS = ['.com', '.bg', '.org', '.net']
  22.  
  23.  
  24. def validate_email(email):
  25.     counter = 0
  26.     if '@' not in email:
  27.         counter += 1
  28.         raise MustContainAtSymbol('Email must contain @')
  29.     username, domain, *rest = email.split('@')
  30.     if len(rest) > 0:
  31.         counter += 1
  32.         raise TooManyAtSymbols('Тhe whole email must contain one and only one "@" symbol')
  33.     if len(username) <= 4:
  34.         counter += 1
  35.         raise NameTooShortError('Name must be more than 4 characters')
  36.  
  37.     if domain.split('.')[-1] not in ['com', 'bg', 'net', 'org']:
  38.         counter += 1
  39.         raise InvalidDomain(f"Domain must be one of the following: {', '.join(ALLOWED_DOMAINS)}")
  40.  
  41.     if counter == 0:
  42.         print(f'Email is valid')
  43.  
  44.  
  45. def main():
  46.     while True:
  47.         email = input()
  48.         if email == 'End':
  49.             break
  50.         validate_email(email)
  51.  
  52.  
  53. if __name__ == '__main__':
  54.     main()
  55.     print('success')
RAW Paste Data