buffer.py 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 InputFilesDescription
  10. from hapic.description import OutputBodyDescription
  11. from hapic.description import OutputStreamDescription
  12. from hapic.description import OutputFileDescription
  13. from hapic.description import OutputHeadersDescription
  14. from hapic.description import ErrorDescription
  15. from hapic.exception import AlreadyDecoratedException
  16. class DecorationBuffer(object):
  17. def __init__(self) -> None:
  18. self._description = ControllerDescription()
  19. def clear(self):
  20. self._description = ControllerDescription()
  21. def get_description(self) -> ControllerDescription:
  22. return self._description
  23. @property
  24. def input_path(self) -> InputPathDescription:
  25. return self._description.input_path
  26. @input_path.setter
  27. def input_path(self, description: InputPathDescription) -> None:
  28. if self._description.input_path is not None:
  29. raise AlreadyDecoratedException()
  30. self._description.input_path = description
  31. @property
  32. def input_query(self) -> InputQueryDescription:
  33. return self._description.input_query
  34. @input_query.setter
  35. def input_query(self, description: InputQueryDescription) -> None:
  36. if self._description.input_query is not None:
  37. raise AlreadyDecoratedException()
  38. self._description.input_query = description
  39. @property
  40. def input_body(self) -> InputBodyDescription:
  41. return self._description.input_body
  42. @input_body.setter
  43. def input_body(self, description: InputBodyDescription) -> None:
  44. if self._description.input_body is not None:
  45. raise AlreadyDecoratedException()
  46. self._description.input_body = description
  47. @property
  48. def input_headers(self) -> InputHeadersDescription:
  49. return self._description.input_headers
  50. @input_headers.setter
  51. def input_headers(self, description: InputHeadersDescription) -> None:
  52. if self._description.input_headers is not None:
  53. raise AlreadyDecoratedException()
  54. self._description.input_headers = description
  55. @property
  56. def input_forms(self) -> InputFormsDescription:
  57. return self._description.input_forms
  58. @input_forms.setter
  59. def input_forms(self, description: InputFormsDescription) -> None:
  60. if self._description.input_forms is not None:
  61. raise AlreadyDecoratedException()
  62. self._description.input_forms = description
  63. @property
  64. def input_files(self) -> InputFilesDescription:
  65. return self._description.input_files
  66. @input_files.setter
  67. def input_files(self, description: InputFilesDescription) -> None:
  68. if self._description.input_files is not None:
  69. raise AlreadyDecoratedException()
  70. self._description.input_files = description
  71. @property
  72. def output_body(self) -> OutputBodyDescription:
  73. return self._description.output_body
  74. @output_body.setter
  75. def output_body(self, description: OutputBodyDescription) -> None:
  76. if self._description.output_body is not None:
  77. raise AlreadyDecoratedException()
  78. self._description.output_body = description
  79. @property
  80. def output_stream(self) -> OutputStreamDescription:
  81. return self._description.output_stream
  82. @output_stream.setter
  83. def output_stream(self, description: OutputStreamDescription) -> None:
  84. if self._description.output_stream is not None:
  85. raise AlreadyDecoratedException()
  86. self._description.output_stream = description
  87. @property
  88. def output_file(self) -> OutputFileDescription:
  89. return self._description.output_file
  90. @output_file.setter
  91. def output_file(self, description: OutputFileDescription) -> None:
  92. if self._description.output_file is not None:
  93. raise AlreadyDecoratedException()
  94. self._description.output_file = description
  95. @property
  96. def output_headers(self) -> OutputHeadersDescription:
  97. return self._description.output_headers
  98. @output_headers.setter
  99. def output_headers(self, description: OutputHeadersDescription) -> None:
  100. if self._description.output_headers is not None:
  101. raise AlreadyDecoratedException()
  102. self._description.output_headers = description
  103. @property
  104. def errors(self) -> typing.List[ErrorDescription]:
  105. return self._description.errors
  106. def add_error(self, description: ErrorDescription) -> None:
  107. self._description.errors.append(description)