@@ -25,29 +25,29 @@ def map_constructor(loader, node):
2525 raise
2626
2727
28- if pyyaml .safe_dump is pyyaml .dump :
29- # PyYAML v4.x
30- SafeDumper = pyyaml .dumper .Dumper
31- DangerDumper = pyyaml .dumper .DangerDumper
28+ _loaders = [getattr (pyyaml .loader , x ) for x in pyyaml .loader .__all__ ]
29+ _dumpers = [getattr (pyyaml .dumper , x ) for x in pyyaml .dumper .__all__ ]
30+ try :
31+ _cyaml = pyyaml .cyaml .__all__
32+ except AttributeError :
33+ pass
3234else :
33- SafeDumper = pyyaml .dumper .SafeDumper
34- DangerDumper = pyyaml .dumper .Dumper
35-
36- pyyaml .add_representer (dict , map_representer , Dumper = SafeDumper )
37- pyyaml .add_representer (OrderedDict , map_representer , Dumper = SafeDumper )
38- pyyaml .add_representer (dict , map_representer , Dumper = DangerDumper )
39- pyyaml .add_representer (OrderedDict , map_representer , Dumper = DangerDumper )
35+ _loaders += [getattr (pyyaml .cyaml , x ) for x in _cyaml if x .endswith ("Loader" )]
36+ _dumpers += [getattr (pyyaml .cyaml , x ) for x in _cyaml if x .endswith ("Dumper" )]
4037
38+ Dumper = None
39+ for Dumper in _dumpers :
40+ pyyaml .add_representer (dict , map_representer , Dumper = Dumper )
41+ pyyaml .add_representer (OrderedDict , map_representer , Dumper = Dumper )
4142
4243Loader = None
4344if not _std_dict_is_order_preserving :
44- for loader_name in pyyaml .loader .__all__ :
45- Loader = getattr (pyyaml .loader , loader_name )
45+ for Loader in _loaders :
4646 pyyaml .add_constructor ("tag:yaml.org,2002:map" , map_constructor , Loader = Loader )
4747
4848
4949# Merge PyYAML namespace into ours.
5050# This allows users a drop-in replacement:
5151# import oyaml as yaml
52- del map_constructor , map_representer , SafeDumper , DangerDumper , Loader
52+ del map_constructor , map_representer , Loader , Dumper
5353from yaml import *
0 commit comments