VirtualMailManager/EmailAddress.py
changeset 116 949c5db6447a
parent 108 fb88585f17fe
child 133 2d5c4745efec
equal deleted inserted replaced
115:21f264a88ab2 116:949c5db6447a
    18     __slots__ = ('_localpart', '_domainname')
    18     __slots__ = ('_localpart', '_domainname')
    19     def __init__(self, address):
    19     def __init__(self, address):
    20         self._localpart = None
    20         self._localpart = None
    21         self._domainname = None
    21         self._domainname = None
    22         self.__chkAddress(address)
    22         self.__chkAddress(address)
    23     
    23 
    24     def __eq__(self, other):
    24     def __eq__(self, other):
    25         if hasattr(other, '_localpart') and hasattr(other, '_domainname'):
    25         if isinstance(other, self.__class__):
    26             return self._localpart == other._localpart\
    26             return self._localpart == other._localpart\
    27                     and self._domainname == other._domainname
    27                     and self._domainname == other._domainname
    28         else:
    28         return NotImplemented
    29             return NotImplemented
       
    30 
    29 
    31     def __ne__(self, other):
    30     def __ne__(self, other):
    32         if hasattr(other, '_localpart') and hasattr(other, '_domainname'):
    31         if isinstance(other, self.__class__):
    33             return not self._localpart == other._localpart\
    32             return self._localpart != other._localpart\
    34                     and self._domainname == other._domainname
    33                     or self._domainname != other._domainname
    35         else:
    34         return NotImplemented
    36             return NotImplemented
       
    37 
    35 
    38     def __repr__(self):
    36     def __repr__(self):
    39         return "EmailAddress('%s@%s')" % (self._localpart, self._domainname)
    37         return "EmailAddress('%s@%s')" % (self._localpart, self._domainname)
    40 
    38 
    41     def __str__(self):
    39     def __str__(self):
    58         localpart = self.__chkLocalpart(localpart)
    56         localpart = self.__chkLocalpart(localpart)
    59         self._localpart, self._domainname = localpart, domain
    57         self._localpart, self._domainname = localpart, domain
    60 
    58 
    61     def __chkLocalpart(self, localpart):
    59     def __chkLocalpart(self, localpart):
    62         """Validates the local part of an e-mail address.
    60         """Validates the local part of an e-mail address.
    63         
    61 
    64         Keyword arguments:
    62         Keyword arguments:
    65         localpart -- of the e-mail address that should be validated (str)
    63         localpart -- of the e-mail address that should be validated (str)
    66         """
    64         """
    67         if len(localpart) < 1:
    65         if len(localpart) < 1:
    68             raise VMMEAE(_(u'No localpart specified.'),
    66             raise VMMEAE(_(u'No localpart specified.'),