Advertisement
mbazs

Bloodtype holder class

Mar 17th, 2018
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. class GeneralHolder:
  2.     def __init__(self, node, textname):
  3.         self.node = node
  4.         self.textname = textname
  5.         self.value = node.findtext(textname)
  6.  
  7.     def __eq__(self, other):
  8.         return self.__value.upper() == other.upper()
  9.  
  10.     @property
  11.     def value(self):
  12.         return self.__value
  13.  
  14.     @value.setter
  15.     def value(self, v):
  16.         self.__value = v
  17.         self.node.find(self.textname).text = v
  18.  
  19.     def like(self, ls):
  20.         return ls.upper() in self.__value.upper()
  21.  
  22.  
  23. class BtHolder(GeneralHolder):
  24.     BLOODTYPES = {"O", "A", "B", "A1", "A1B", "non-A1", "non-A1B", "AB"}
  25.  
  26.     #def __eq__(self, other):
  27.     #    return self.__value.upper() == other.upper()
  28.  
  29.     @property
  30.     def value(self):
  31.         return self.__value
  32.  
  33.     @value.setter
  34.     def value(self, v):
  35.         if v not in self.BLOODTYPES:
  36.             raise AttributeError("bad bloodtype value: " + v + ", candidates are: " + str(sorted(self.BLOODTYPES)))
  37.         self.__value = v
  38.         self.node.find(self.textname).text = v
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement