loader.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # coding: utf-8
  2. from ruamel.yaml.reader import Reader
  3. from ruamel.yaml.scanner import Scanner, RoundTripScanner
  4. from ruamel.yaml.parser import Parser, RoundTripParser
  5. from ruamel.yaml.composer import Composer
  6. from ruamel.yaml.constructor import (
  7. BaseConstructor,
  8. SafeConstructor,
  9. Constructor,
  10. RoundTripConstructor,
  11. )
  12. from ruamel.yaml.resolver import VersionedResolver
  13. from typing import Any, Dict, List, Union, Optional # NOQA
  14. from ruamel.yaml.compat import StreamTextType, VersionType # NOQA
  15. __all__ = ['BaseLoader', 'SafeLoader', 'Loader', 'RoundTripLoader']
  16. class BaseLoader(Reader, Scanner, Parser, Composer, BaseConstructor, VersionedResolver):
  17. def __init__(
  18. self,
  19. stream: StreamTextType,
  20. version: Optional[VersionType] = None,
  21. preserve_quotes: Optional[bool] = None,
  22. ) -> None:
  23. self.comment_handling = None
  24. Reader.__init__(self, stream, loader=self)
  25. Scanner.__init__(self, loader=self)
  26. Parser.__init__(self, loader=self)
  27. Composer.__init__(self, loader=self)
  28. BaseConstructor.__init__(self, loader=self)
  29. VersionedResolver.__init__(self, version, loader=self)
  30. class SafeLoader(Reader, Scanner, Parser, Composer, SafeConstructor, VersionedResolver):
  31. def __init__(
  32. self,
  33. stream: StreamTextType,
  34. version: Optional[VersionType] = None,
  35. preserve_quotes: Optional[bool] = None,
  36. ) -> None:
  37. self.comment_handling = None
  38. Reader.__init__(self, stream, loader=self)
  39. Scanner.__init__(self, loader=self)
  40. Parser.__init__(self, loader=self)
  41. Composer.__init__(self, loader=self)
  42. SafeConstructor.__init__(self, loader=self)
  43. VersionedResolver.__init__(self, version, loader=self)
  44. class Loader(Reader, Scanner, Parser, Composer, Constructor, VersionedResolver):
  45. def __init__(
  46. self,
  47. stream: StreamTextType,
  48. version: Optional[VersionType] = None,
  49. preserve_quotes: Optional[bool] = None,
  50. ) -> None:
  51. self.comment_handling = None
  52. Reader.__init__(self, stream, loader=self)
  53. Scanner.__init__(self, loader=self)
  54. Parser.__init__(self, loader=self)
  55. Composer.__init__(self, loader=self)
  56. Constructor.__init__(self, loader=self)
  57. VersionedResolver.__init__(self, version, loader=self)
  58. class RoundTripLoader(
  59. Reader,
  60. RoundTripScanner,
  61. RoundTripParser,
  62. Composer,
  63. RoundTripConstructor,
  64. VersionedResolver,
  65. ):
  66. def __init__(
  67. self,
  68. stream: StreamTextType,
  69. version: Optional[VersionType] = None,
  70. preserve_quotes: Optional[bool] = None,
  71. ) -> None:
  72. # self.reader = Reader.__init__(self, stream)
  73. self.comment_handling = None # issue 385
  74. Reader.__init__(self, stream, loader=self)
  75. RoundTripScanner.__init__(self, loader=self)
  76. RoundTripParser.__init__(self, loader=self)
  77. Composer.__init__(self, loader=self)
  78. RoundTripConstructor.__init__(self, preserve_quotes=preserve_quotes, loader=self)
  79. VersionedResolver.__init__(self, version, loader=self)