diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/planemo/lib/python3.7/site-packages/prov/serializers/__init__.py	Fri Jul 31 00:32:28 2020 -0400
@@ -0,0 +1,84 @@
+from __future__ import (absolute_import, division, print_function,
+                        unicode_literals)
+
+from prov import Error
+
+__author__ = 'Trung Dong Huynh'
+__email__ = 'trungdong@donggiang.com'
+
+__all__ = [
+    'get'
+]
+
+
+class Serializer(object):
+    """Serializer for PROV documents."""
+
+    document = None
+    """PROV document to serialise."""
+
+    def __init__(self, document=None):
+        """
+        Constructor.
+
+        :param document: Document to serialize.
+        """
+        self.document = document
+
+    def serialize(self, stream, **kwargs):
+        """
+        Abstract method for serializing.
+
+        :param stream: Stream object to serialize the document into.
+        """
+
+    def deserialize(self, stream, **kwargs):
+        """
+        Abstract method for deserializing.
+
+        :param stream: Stream object to deserialize the document from.
+        """
+
+
+class DoNotExist(Error):
+    """Exception for the case a serializer is not available."""
+    pass
+
+
+class Registry:
+    """Registry of serializers."""
+
+    serializers = None
+    """Property caching all available serializers in a dict."""
+
+    @staticmethod
+    def load_serializers():
+        """Loads all available serializers into the registry."""
+        from prov.serializers.provjson import ProvJSONSerializer
+        from prov.serializers.provn import ProvNSerializer
+        from prov.serializers.provxml import ProvXMLSerializer
+        from prov.serializers.provrdf import ProvRDFSerializer
+
+        Registry.serializers = {
+            'json': ProvJSONSerializer,
+            'rdf': ProvRDFSerializer,
+            'provn': ProvNSerializer,
+            'xml': ProvXMLSerializer
+        }
+
+
+def get(format_name):
+    """
+    Returns the serializer class for the specified format. Raises a DoNotExist
+    """
+    # Lazily initialize the list of serializers to avoid cyclic imports
+    if Registry.serializers is None:
+        Registry.load_serializers()
+    try:
+        return Registry.serializers[format_name]
+    except KeyError:
+        raise DoNotExist(
+            'No serializer available for the format "%s"' % format_name
+        )
+
+