comparison env/lib/python3.7/site-packages/prov/__init__.py @ 2:6af9afd405e9 draft

"planemo upload commit 0a63dd5f4d38a1f6944587f52a8cd79874177fc1"
author shellac
date Thu, 14 May 2020 14:56:58 -0400
parents 26e78fe6e8c4
children
comparison
equal deleted inserted replaced
1:75ca89e9b81c 2:6af9afd405e9
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.")