(
        self,
        _kw=enforce,
        typ=None,
        pure=False,
        output=None,
        plug_ins=None,  # input=None,
    )
_kw: not used, forces keyword arguments in 2.7 (in 3 you can do (*, safe_load=..)
        typ: 'rt'/None -> RoundTripLoader/RoundTripDumper,  (default)
             'safe'    -> SafeLoader/SafeDumper,
             'unsafe'  -> normal/unsafe Loader/Dumper
             'base'    -> baseloader
        pure: if True only use Python modules
        input/output: needed to work as context manager
        plug_ins: a list of plug-in files
_kw: not used, forces keyword arguments in 2.7 (in 3 you can do (*, safe_load=..)
        typ: 'rt'/None -> RoundTripLoader/RoundTripDumper,  (default)
             'safe'    -> SafeLoader/SafeDumper,
             'unsafe'  -> normal/unsafe Loader/Dumper
             'base'    -> baseloader
        pure: if True only use Python modules
        input/output: needed to work as context manager
        plug_ins: a list of plug-in files
_kw : not used forces keyword arguments in 2 . 7 ( in 3 you can do ( * safe_load = .. ) typ : rt / None - > RoundTripLoader / RoundTripDumper ( default ) safe - > SafeLoader / SafeDumper unsafe - > normal / unsafe Loader / Dumper base - > baseloader pure : if True only use Python modules input / output : needed to work as context manager plug_ins : a list of plug - in files
def __init__(
        self,
        _kw=enforce,
        typ=None,
        pure=False,
        output=None,
        plug_ins=None,  # input=None,
    ):
        # type: (Any, Optional[Text], Any, Any, Any) -> None
        """
        _kw: not used, forces keyword arguments in 2.7 (in 3 you can do (*, safe_load=..)
        typ: 'rt'/None -> RoundTripLoader/RoundTripDumper,  (default)
             'safe'    -> SafeLoader/SafeDumper,
             'unsafe'  -> normal/unsafe Loader/Dumper
             'base'    -> baseloader
        pure: if True only use Python modules
        input/output: needed to work as context manager
        plug_ins: a list of plug-in files
        """
        if _kw is not enforce:
            raise TypeError(
                "{}.__init__() takes no positional argument but at least "
                "one was given ({!r})".format(self.__class__.__name__, _kw)
            )

        self.typ = ["rt"] if typ is None else (typ if isinstance(typ, list) else [typ])
        self.pure = pure

        # self._input = input
        self._output = output
        self._context_manager = None  # type: Any

        self.plug_ins = []  # type: List[Any]
        for pu in ([] if plug_ins is None else plug_ins) + self.official_plug_ins():
            file_name = pu.replace(os.sep, ".")
            self.plug_ins.append(import_module(file_name))
        self.Resolver = resolver.VersionedResolver  # type: Any
        self.allow_unicode = True
        self.Reader = None  # type: Any
        self.Representer = None  # type: Any
        self.Constructor = None  # type: Any
        self.Scanner = None  # type: Any
        self.Serializer = None  # type: Any
        self.default_flow_style = None  # type: Any
        typ_found = 1
        setup_rt = False
        if "rt" in self.typ:
            setup_rt = True
        elif "safe" in self.typ:
            self.Emitter = emitter.Emitter if pure or CEmitter is None else CEmitter
            self.Representer = representer.SafeRepresenter
            self.Parser = parser.Parser if pure or CParser is None else CParser
            self.Composer = composer.Composer
            self.Constructor = constructor.SafeConstructor
        elif "base" in self.typ:
            self.Emitter = emitter.Emitter
            self.Representer = representer.BaseRepresenter
            self.Parser = parser.Parser if pure or CParser is None else CParser
            self.Composer = composer.Composer
            self.Constructor = constructor.BaseConstructor
        elif "unsafe" in self.typ:
            self.Emitter = emitter.Emitter if pure or CEmitter is None else CEmitter
            self.Representer = representer.Representer
            self.Parser = parser.Parser if pure or CParser is None else CParser
            self.Composer = composer.Composer
            self.Constructor = constructor.Constructor
        else:
            setup_rt = True
            typ_found = 0
        if setup_rt:
            self.default_flow_style = False
            # no optimized rt-dumper yet
            self.Emitter = emitter.Emitter
            self.Serializer = serializer.Serializer
            self.Representer = representer.RoundTripRepresenter
            self.Scanner = scanner.RoundTripScanner
            # no optimized rt-parser yet
            self.Parser = parser.RoundTripParser
            self.Composer = composer.Composer
            self.Constructor = constructor.RoundTripConstructor
        del setup_rt
        self.stream = None
        self.canonical = None
        self.old_indent = None
        self.width = None
        self.line_break = None

        self.map_indent = None
        self.sequence_indent = None
        self.sequence_dash_offset = 0
        self.compact_seq_seq = None
        self.compact_seq_map = None
        self.sort_base_mapping_type_on_output = None  # default: sort

        self.top_level_colon_align = None
        self.prefix_colon = None
        self.version = None
        self.preserve_quotes = None
        self.allow_duplicate_keys = False  # duplicate keys in map, set
        self.encoding = "utf-8"
        self.explicit_start = None
        self.explicit_end = None
        self.tags = None
        self.default_style = None
        self.top_level_block_style_scalar_no_indent_error_1_1 = False
        # directives end indicator with single scalar document
        self.scalar_after_indicator = None
        # [a, b: 1, c: {d: 2}]  vs. [a, {b: 1}, {c: {d: 2}}]
        self.brace_single_entry_mapping_in_flow_sequence = False
        for module in self.plug_ins:
            if getattr(module, "typ", None) in self.typ:
                typ_found += 1
                module.init_typ(self)
                break
        if typ_found == 0:
            raise NotImplementedError(
                'typ "{}"not recognised (need to install plug-in?)'.format(self.typ)
            )
def __init__ ( self , _kw = enforce , typ = None , pure = False , output = None , plug_ins = None , # input=None, ) : # type: (Any, Optional[Text], Any, Any, Any) -> None if _kw is not enforce : raise TypeError ( "{}.__init__() takes no positional argument but at least " "one was given ({!r})" . format ( self . __class__ . __name__ , _kw ) ) self . typ = [ "rt" ] if typ is None else ( typ if isinstance ( typ , list ) else [ typ ] ) self . pure = pure # self._input = input self . _output = output self . _context_manager = None # type: Any self . plug_ins = [ ] # type: List[Any] for pu in ( [ ] if plug_ins is None else plug_ins ) + self . official_plug_ins ( ) : file_name = pu . replace ( os . sep , "." ) self . plug_ins . append ( import_module ( file_name ) ) self . Resolver = resolver . VersionedResolver # type: Any self . allow_unicode = True self . Reader = None # type: Any self . Representer = None # type: Any self . Constructor = None # type: Any self . Scanner = None # type: Any self . Serializer = None # type: Any self . default_flow_style = None # type: Any typ_found = 1 setup_rt = False if "rt" in self . typ : setup_rt = True elif "safe" in self . typ : self . Emitter = emitter . Emitter if pure or CEmitter is None else CEmitter self . Representer = representer . SafeRepresenter self . Parser = parser . Parser if pure or CParser is None else CParser self . Composer = composer . Composer self . Constructor = constructor . SafeConstructor elif "base" in self . typ : self . Emitter = emitter . Emitter self . Representer = representer . BaseRepresenter self . Parser = parser . Parser if pure or CParser is None else CParser self . Composer = composer . Composer self . Constructor = constructor . BaseConstructor elif "unsafe" in self . typ : self . Emitter = emitter . Emitter if pure or CEmitter is None else CEmitter self . Representer = representer . Representer self . Parser = parser . Parser if pure or CParser is None else CParser self . Composer = composer . Composer self . Constructor = constructor . Constructor else : setup_rt = True typ_found = 0 if setup_rt : self . default_flow_style = False # no optimized rt-dumper yet self . Emitter = emitter . Emitter self . Serializer = serializer . Serializer self . Representer = representer . RoundTripRepresenter self . Scanner = scanner . RoundTripScanner # no optimized rt-parser yet self . Parser = parser . RoundTripParser self . Composer = composer . Composer self . Constructor = constructor . RoundTripConstructor del setup_rt self . stream = None self . canonical = None self . old_indent = None self . width = None self . line_break = None self . map_indent = None self . sequence_indent = None self . sequence_dash_offset = 0 self . compact_seq_seq = None self . compact_seq_map = None self . sort_base_mapping_type_on_output = None # default: sort self . top_level_colon_align = None self . prefix_colon = None self . version = None self . preserve_quotes = None self . allow_duplicate_keys = False # duplicate keys in map, set self . encoding = "utf-8" self . explicit_start = None self . explicit_end = None self . tags = None self . default_style = None self . top_level_block_style_scalar_no_indent_error_1_1 = False # directives end indicator with single scalar document self . scalar_after_indicator = None # [a, b: 1, c: {d: 2}]  vs. [a, {b: 1}, {c: {d: 2}}] self . brace_single_entry_mapping_in_flow_sequence = False for module in self . plug_ins : if getattr ( module , "typ" , None ) in self . typ : typ_found += 1 module . init_typ ( self ) break if typ_found == 0 : raise NotImplementedError ( 'typ "{}"not recognised (need to install plug-in?)' . format ( self . typ ) )