comparison env/lib/python3.7/site-packages/prov/__init__.py @ 5:9b1c78e6ba9c draft default tip

"planemo upload commit 6c0a8142489327ece472c84e558c47da711a9142"
author shellac
date Mon, 01 Jun 2020 08:59:25 -0400
parents 79f47841a781
children
comparison
equal deleted inserted replaced
4:79f47841a781 5:9b1c78e6ba9c
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.")