buffer.py 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # -*- coding: utf-8 -*-
  2. import typing
  3. from hapic.description import ControllerDescription
  4. from hapic.description import InputPathDescription
  5. from hapic.description import InputQueryDescription
  6. from hapic.description import InputBodyDescription
  7. from hapic.description import InputHeadersDescription
  8. from hapic.description import InputFormsDescription
  9. from hapic.description import OutputBodyDescription
  10. from hapic.description import OutputHeadersDescription
  11. from hapic.description import ErrorDescription
  12. from hapic.exception import AlreadyDecoratedException
  13. class DecorationBuffer(object):
  14. def __init__(self) -> None:
  15. self._description = ControllerDescription()
  16. def clear(self):
  17. self._description = ControllerDescription()
  18. def get_description(self) -> ControllerDescription:
  19. return self._description
  20. @property
  21. def input_path(self) -> InputPathDescription:
  22. return self._description.input_path
  23. @input_path.setter
  24. def input_path(self, description: InputPathDescription) -> None:
  25. if self._description.input_path is not None:
  26. raise AlreadyDecoratedException()
  27. self._description.input_path = description
  28. @property
  29. def input_query(self) -> InputQueryDescription:
  30. return self._description.input_query
  31. @input_query.setter
  32. def input_query(self, description: InputQueryDescription) -> None:
  33. if self._description.input_query is not None:
  34. raise AlreadyDecoratedException()
  35. self._description.input_query = description
  36. @property
  37. def input_body(self) -> InputBodyDescription:
  38. return self._description.input_body
  39. @input_body.setter
  40. def input_body(self, description: InputBodyDescription) -> None:
  41. if self._description.input_body is not None:
  42. raise AlreadyDecoratedException()
  43. self._description.input_body = description
  44. @property
  45. def input_headers(self) -> InputHeadersDescription:
  46. return self._description.input_headers
  47. @input_headers.setter
  48. def input_headers(self, description: InputHeadersDescription) -> None:
  49. if self._description.input_headers is not None:
  50. raise AlreadyDecoratedException()
  51. self._description.input_headers = description
  52. @property
  53. def input_forms(self) -> InputFormsDescription:
  54. return self._description.input_forms
  55. @input_forms.setter
  56. def input_forms(self, description: InputFormsDescription) -> None:
  57. if self._description.input_forms is not None:
  58. raise AlreadyDecoratedException()
  59. self._description.input_forms = description
  60. @property
  61. def output_body(self) -> OutputBodyDescription:
  62. return self._description.output_body
  63. @output_body.setter
  64. def output_body(self, description: OutputBodyDescription) -> None:
  65. if self._description.output_body is not None:
  66. raise AlreadyDecoratedException()
  67. self._description.output_body = description
  68. @property
  69. def output_headers(self) -> OutputHeadersDescription:
  70. return self._description.output_headers
  71. @output_headers.setter
  72. def output_headers(self, description: OutputHeadersDescription) -> None:
  73. if self._description.output_headers is not None:
  74. raise AlreadyDecoratedException()
  75. self._description.output_headers = description
  76. @property
  77. def errors(self) -> typing.List[ErrorDescription]:
  78. return self._description.errors
  79. def add_error(self, description: ErrorDescription) -> None:
  80. self._description.errors.append(description)