Mercurial > repos > shellac > guppy_basecaller
annotate env/lib/python3.7/site-packages/oyaml.py @ 4:79f47841a781 draft
"planemo upload commit 2a0fe2cc28b09e101d37293e53e82f61762262ec"
| author | shellac | 
|---|---|
| date | Thu, 14 May 2020 16:47:39 -0400 | 
| parents | 26e78fe6e8c4 | 
| children | 
| rev | line source | 
|---|---|
| 
0
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
1 import platform | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
2 import sys | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
3 from collections import OrderedDict | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
4 | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
5 import yaml as pyyaml | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
6 | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
7 | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
8 _items = "viewitems" if sys.version_info < (3,) else "items" | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
9 _std_dict_is_order_preserving = sys.version_info >= (3, 7) or ( | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
10 sys.version_info >= (3, 6) and platform.python_implementation() == "CPython" | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
11 ) | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
12 | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
13 | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
14 def map_representer(dumper, data): | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
15 return dumper.represent_dict(getattr(data, _items)()) | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
16 | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
17 | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
18 def map_constructor(loader, node): | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
19 loader.flatten_mapping(node) | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
20 pairs = loader.construct_pairs(node) | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
21 try: | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
22 return OrderedDict(pairs) | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
23 except TypeError: | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
24 loader.construct_mapping(node) # trigger any contextual error | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
25 raise | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
26 | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
27 | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
28 if pyyaml.safe_dump is pyyaml.dump: | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
29 # PyYAML v4.x | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
30 SafeDumper = pyyaml.dumper.Dumper | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
31 DangerDumper = pyyaml.dumper.DangerDumper | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
32 else: | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
33 SafeDumper = pyyaml.dumper.SafeDumper | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
34 DangerDumper = pyyaml.dumper.Dumper | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
35 | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
36 pyyaml.add_representer(dict, map_representer, Dumper=SafeDumper) | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
37 pyyaml.add_representer(OrderedDict, map_representer, Dumper=SafeDumper) | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
38 pyyaml.add_representer(dict, map_representer, Dumper=DangerDumper) | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
39 pyyaml.add_representer(OrderedDict, map_representer, Dumper=DangerDumper) | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
40 | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
41 | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
42 Loader = None | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
43 if not _std_dict_is_order_preserving: | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
44 for loader_name in pyyaml.loader.__all__: | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
45 Loader = getattr(pyyaml.loader, loader_name) | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
46 pyyaml.add_constructor("tag:yaml.org,2002:map", map_constructor, Loader=Loader) | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
47 | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
48 | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
49 # Merge PyYAML namespace into ours. | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
50 # This allows users a drop-in replacement: | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
51 # import oyaml as yaml | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
52 del map_constructor, map_representer, SafeDumper, DangerDumper, Loader | 
| 
 
26e78fe6e8c4
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
 
shellac 
parents:  
diff
changeset
 | 
53 from yaml import * | 
