Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/prov/__init__.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 from __future__ import (absolute_import, division, print_function, | |
2 unicode_literals) | |
3 | |
4 __author__ = 'Trung Dong Huynh' | |
5 __email__ = 'trungdong@donggiang.com' | |
6 __version__ = '1.5.1' | |
7 | |
8 __all__ = ["Error", "model", "read"] | |
9 | |
10 | |
11 class Error(Exception): | |
12 """Base class for all errors in this package.""" | |
13 pass | |
14 | |
15 | |
16 def read(source, format=None): | |
17 """ | |
18 Convenience function returning a ProvDocument instance. | |
19 | |
20 It does a lazy format detection by simply using try/except for all known | |
21 formats. The deserializers should fail fairly early when data of the | |
22 wrong type is passed to them thus the try/except is likely cheap. One | |
23 could of course also do some more advanced format auto-detection but I am | |
24 not sure that is necessary. | |
25 | |
26 The downside is that no proper error messages will be produced, use the | |
27 format parameter to get the actual traceback. | |
28 """ | |
29 # Lazy imports to not globber the namespace. | |
30 from prov.model import ProvDocument | |
31 | |
32 from prov.serializers import Registry | |
33 Registry.load_serializers() | |
34 serializers = Registry.serializers.keys() | |
35 | |
36 if format: | |
37 return ProvDocument.deserialize(source=source, format=format.lower()) | |
38 | |
39 for format in serializers: | |
40 try: | |
41 return ProvDocument.deserialize(source=source, format=format) | |
42 except: | |
43 pass | |
44 else: | |
45 raise TypeError("Could not read from the source. To get a proper " | |
46 "error message, specify the format with the 'format' " | |
47 "parameter.") |