ErrorMatcher.py 1.5 KB

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