buffer.py 4.3KB

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