ValidationRule.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import json
  4. from alipay.aop.api.constant.ParamConstants import *
  5. class ValidationRule(object):
  6. def __init__(self):
  7. self._error_msg = None
  8. self._rule_text = None
  9. @property
  10. def error_msg(self):
  11. return self._error_msg
  12. @error_msg.setter
  13. def error_msg(self, value):
  14. self._error_msg = value
  15. @property
  16. def rule_text(self):
  17. return self._rule_text
  18. @rule_text.setter
  19. def rule_text(self, value):
  20. self._rule_text = value
  21. def to_alipay_dict(self):
  22. params = dict()
  23. if self.error_msg:
  24. if hasattr(self.error_msg, 'to_alipay_dict'):
  25. params['error_msg'] = self.error_msg.to_alipay_dict()
  26. else:
  27. params['error_msg'] = self.error_msg
  28. if self.rule_text:
  29. if hasattr(self.rule_text, 'to_alipay_dict'):
  30. params['rule_text'] = self.rule_text.to_alipay_dict()
  31. else:
  32. params['rule_text'] = self.rule_text
  33. return params
  34. @staticmethod
  35. def from_alipay_dict(d):
  36. if not d:
  37. return None
  38. o = ValidationRule()
  39. if 'error_msg' in d:
  40. o.error_msg = d['error_msg']
  41. if 'rule_text' in d:
  42. o.rule_text = d['rule_text']
  43. return o