dumper.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. # coding: utf-8
  2. from ruamel.yaml.emitter import Emitter
  3. from ruamel.yaml.serializer import Serializer
  4. from ruamel.yaml.representer import (
  5. Representer,
  6. SafeRepresenter,
  7. BaseRepresenter,
  8. RoundTripRepresenter,
  9. )
  10. from ruamel.yaml.resolver import Resolver, BaseResolver, VersionedResolver
  11. from typing import Any, Dict, List, Union, Optional # NOQA
  12. from ruamel.yaml.compat import StreamType, VersionType # NOQA
  13. __all__ = ['BaseDumper', 'SafeDumper', 'Dumper', 'RoundTripDumper']
  14. class BaseDumper(Emitter, Serializer, BaseRepresenter, BaseResolver):
  15. def __init__(
  16. self: Any,
  17. stream: StreamType,
  18. default_style: Any = None,
  19. default_flow_style: Any = None,
  20. canonical: Optional[bool] = None,
  21. indent: Optional[int] = None,
  22. width: Optional[int] = None,
  23. allow_unicode: Optional[bool] = None,
  24. line_break: Any = None,
  25. encoding: Any = None,
  26. explicit_start: Optional[bool] = None,
  27. explicit_end: Optional[bool] = None,
  28. version: Any = None,
  29. tags: Any = None,
  30. block_seq_indent: Any = None,
  31. top_level_colon_align: Any = None,
  32. prefix_colon: Any = None,
  33. ) -> None:
  34. # NOQA
  35. Emitter.__init__(
  36. self,
  37. stream,
  38. canonical=canonical,
  39. indent=indent,
  40. width=width,
  41. allow_unicode=allow_unicode,
  42. line_break=line_break,
  43. block_seq_indent=block_seq_indent,
  44. dumper=self,
  45. )
  46. Serializer.__init__(
  47. self,
  48. encoding=encoding,
  49. explicit_start=explicit_start,
  50. explicit_end=explicit_end,
  51. version=version,
  52. tags=tags,
  53. dumper=self,
  54. )
  55. BaseRepresenter.__init__(
  56. self,
  57. default_style=default_style,
  58. default_flow_style=default_flow_style,
  59. dumper=self,
  60. )
  61. BaseResolver.__init__(self, loadumper=self)
  62. class SafeDumper(Emitter, Serializer, SafeRepresenter, Resolver):
  63. def __init__(
  64. self,
  65. stream: StreamType,
  66. default_style: Any = None,
  67. default_flow_style: Any = None,
  68. canonical: Optional[bool] = None,
  69. indent: Optional[int] = None,
  70. width: Optional[int] = None,
  71. allow_unicode: Optional[bool] = None,
  72. line_break: Any = None,
  73. encoding: Any = None,
  74. explicit_start: Optional[bool] = None,
  75. explicit_end: Optional[bool] = None,
  76. version: Any = None,
  77. tags: Any = None,
  78. block_seq_indent: Any = None,
  79. top_level_colon_align: Any = None,
  80. prefix_colon: Any = None,
  81. ) -> None:
  82. # NOQA
  83. Emitter.__init__(
  84. self,
  85. stream,
  86. canonical=canonical,
  87. indent=indent,
  88. width=width,
  89. allow_unicode=allow_unicode,
  90. line_break=line_break,
  91. block_seq_indent=block_seq_indent,
  92. dumper=self,
  93. )
  94. Serializer.__init__(
  95. self,
  96. encoding=encoding,
  97. explicit_start=explicit_start,
  98. explicit_end=explicit_end,
  99. version=version,
  100. tags=tags,
  101. dumper=self,
  102. )
  103. SafeRepresenter.__init__(
  104. self,
  105. default_style=default_style,
  106. default_flow_style=default_flow_style,
  107. dumper=self,
  108. )
  109. Resolver.__init__(self, loadumper=self)
  110. class Dumper(Emitter, Serializer, Representer, Resolver):
  111. def __init__(
  112. self,
  113. stream: StreamType,
  114. default_style: Any = None,
  115. default_flow_style: Any = None,
  116. canonical: Optional[bool] = None,
  117. indent: Optional[int] = None,
  118. width: Optional[int] = None,
  119. allow_unicode: Optional[bool] = None,
  120. line_break: Any = None,
  121. encoding: Any = None,
  122. explicit_start: Optional[bool] = None,
  123. explicit_end: Optional[bool] = None,
  124. version: Any = None,
  125. tags: Any = None,
  126. block_seq_indent: Any = None,
  127. top_level_colon_align: Any = None,
  128. prefix_colon: Any = None,
  129. ) -> None:
  130. # NOQA
  131. Emitter.__init__(
  132. self,
  133. stream,
  134. canonical=canonical,
  135. indent=indent,
  136. width=width,
  137. allow_unicode=allow_unicode,
  138. line_break=line_break,
  139. block_seq_indent=block_seq_indent,
  140. dumper=self,
  141. )
  142. Serializer.__init__(
  143. self,
  144. encoding=encoding,
  145. explicit_start=explicit_start,
  146. explicit_end=explicit_end,
  147. version=version,
  148. tags=tags,
  149. dumper=self,
  150. )
  151. Representer.__init__(
  152. self,
  153. default_style=default_style,
  154. default_flow_style=default_flow_style,
  155. dumper=self,
  156. )
  157. Resolver.__init__(self, loadumper=self)
  158. class RoundTripDumper(Emitter, Serializer, RoundTripRepresenter, VersionedResolver):
  159. def __init__(
  160. self,
  161. stream: StreamType,
  162. default_style: Any = None,
  163. default_flow_style: Optional[bool] = None,
  164. canonical: Optional[int] = None,
  165. indent: Optional[int] = None,
  166. width: Optional[int] = None,
  167. allow_unicode: Optional[bool] = None,
  168. line_break: Any = None,
  169. encoding: Any = None,
  170. explicit_start: Optional[bool] = None,
  171. explicit_end: Optional[bool] = None,
  172. version: Any = None,
  173. tags: Any = None,
  174. block_seq_indent: Any = None,
  175. top_level_colon_align: Any = None,
  176. prefix_colon: Any = None,
  177. ) -> None:
  178. # NOQA
  179. Emitter.__init__(
  180. self,
  181. stream,
  182. canonical=canonical,
  183. indent=indent,
  184. width=width,
  185. allow_unicode=allow_unicode,
  186. line_break=line_break,
  187. block_seq_indent=block_seq_indent,
  188. top_level_colon_align=top_level_colon_align,
  189. prefix_colon=prefix_colon,
  190. dumper=self,
  191. )
  192. Serializer.__init__(
  193. self,
  194. encoding=encoding,
  195. explicit_start=explicit_start,
  196. explicit_end=explicit_end,
  197. version=version,
  198. tags=tags,
  199. dumper=self,
  200. )
  201. RoundTripRepresenter.__init__(
  202. self,
  203. default_style=default_style,
  204. default_flow_style=default_flow_style,
  205. dumper=self,
  206. )
  207. VersionedResolver.__init__(self, loader=self)