Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/prov/serializers/__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 from prov import Error | |
5 | |
6 __author__ = 'Trung Dong Huynh' | |
7 __email__ = 'trungdong@donggiang.com' | |
8 | |
9 __all__ = [ | |
10 'get' | |
11 ] | |
12 | |
13 | |
14 class Serializer(object): | |
15 """Serializer for PROV documents.""" | |
16 | |
17 document = None | |
18 """PROV document to serialise.""" | |
19 | |
20 def __init__(self, document=None): | |
21 """ | |
22 Constructor. | |
23 | |
24 :param document: Document to serialize. | |
25 """ | |
26 self.document = document | |
27 | |
28 def serialize(self, stream, **kwargs): | |
29 """ | |
30 Abstract method for serializing. | |
31 | |
32 :param stream: Stream object to serialize the document into. | |
33 """ | |
34 | |
35 def deserialize(self, stream, **kwargs): | |
36 """ | |
37 Abstract method for deserializing. | |
38 | |
39 :param stream: Stream object to deserialize the document from. | |
40 """ | |
41 | |
42 | |
43 class DoNotExist(Error): | |
44 """Exception for the case a serializer is not available.""" | |
45 pass | |
46 | |
47 | |
48 class Registry: | |
49 """Registry of serializers.""" | |
50 | |
51 serializers = None | |
52 """Property caching all available serializers in a dict.""" | |
53 | |
54 @staticmethod | |
55 def load_serializers(): | |
56 """Loads all available serializers into the registry.""" | |
57 from prov.serializers.provjson import ProvJSONSerializer | |
58 from prov.serializers.provn import ProvNSerializer | |
59 from prov.serializers.provxml import ProvXMLSerializer | |
60 from prov.serializers.provrdf import ProvRDFSerializer | |
61 | |
62 Registry.serializers = { | |
63 'json': ProvJSONSerializer, | |
64 'rdf': ProvRDFSerializer, | |
65 'provn': ProvNSerializer, | |
66 'xml': ProvXMLSerializer | |
67 } | |
68 | |
69 | |
70 def get(format_name): | |
71 """ | |
72 Returns the serializer class for the specified format. Raises a DoNotExist | |
73 """ | |
74 # Lazily initialize the list of serializers to avoid cyclic imports | |
75 if Registry.serializers is None: | |
76 Registry.load_serializers() | |
77 try: | |
78 return Registry.serializers[format_name] | |
79 except KeyError: | |
80 raise DoNotExist( | |
81 'No serializer available for the format "%s"' % format_name | |
82 ) | |
83 | |
84 |