daily pastebin goal
33%
SHARE
TWEET

Untitled

a guest Oct 12th, 2017 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Author:
  2.  
  3. def __init__(self, id, firstname, lastname):
  4.     self._validateid(id, "ID")
  5.     self._validate_author(firstname, "First Name")
  6.     self._validate_author(lastname, "Last Name")
  7.  
  8.     self._id = id
  9.     self._firstname = firstname
  10.     self._lastname = lastname
  11.  
  12. def _validateid(self, id, error_message):
  13.     if id < 1:
  14.         raise ValueError(error_message + " is invalid")
  15.  
  16. def _validate_author(self, parameter, error_message):
  17.     if not parameter:
  18.         raise TypeError(error_message + " is missing")
  19.  
  20. @property
  21. def iden(self):
  22.     return self._id
  23.  
  24. @property
  25. def first_name(self):
  26.     return self._firstname
  27.  
  28. @property
  29. def last_name(self):
  30.     return self._lastname
  31.    
  32. def __lt__(self, other):
  33.     if isinstance(other, Author):
  34.         return (self.iden, self.first_name.lower(), self.last_name.lower()) < (other.iden, other.first_name.lower(), other.last_name.lower())
  35.     return NotImplemented
  36.  
  37. def __le__(self, other):
  38.     if isinstance(other, Author):
  39.         return (self.iden, self.first_name.lower(), self.last_name.lower()) <= (other.iden, other.first_name.lower(), other.last_name.lower())
  40.     return NotImplemented
  41.  
  42. def __eq__(self, other):
  43.     if isinstance(other, Author):
  44.         return (self.iden, self.first_name.lower(), self.last_name.lower()) == (other.iden, other.first_name.lower(), other.last_name.lower())
  45.     return NotImplemented
  46.  
  47. def __ne__(self, other):
  48.     if isinstance(other, Author):
  49.         return (self.iden, self.first_name.lower(), self.last_name.lower()) != (other.iden, other.first_name.lower(), other.last_name.lower())
  50.     return NotImplemented
  51.  
  52. def __ge__(self, other):
  53.     if isinstance(other, Author):
  54.         return (self.iden, self.first_name.lower(), self.last_name.lower()) >= (other.iden, other.first_name.lower(), other.last_name.lower())
  55.     return NotImplemented
  56.  
  57. def __gt__(self, other):
  58.     if isinstance(other, Author):
  59.         return (self.iden, self.first_name.lower(), self.last_name.lower()) > (other.iden, other.first_name.lower(), other.last_name.lower())
  60.     return NotImplemented
  61.  
  62. def __hash__(self):
  63.     return hash((self.iden, self.first_name.lower(), self.last_name.lower()))
RAW Paste Data
Top