Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/prov/__init__.py @ 1:56ad4e20f292 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:32:28 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:d30785e31577 | 1:56ad4e20f292 |
---|---|
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.") |