Skip to content

Commit

Permalink
Fixed #134: checking if the output stream is not expecting unicode st…
Browse files Browse the repository at this point in the history
…rings
  • Loading branch information
trungdong committed Apr 28, 2020
1 parent bf5c381 commit 2e19dcc
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/prov/serializers/provn.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from __future__ import absolute_import, division, print_function, unicode_literals

__author__ = 'Trung Dong Huynh'
__email__ = 'trungdong@donggiang.com'
__author__ = "Trung Dong Huynh"
__email__ = "trungdong@donggiang.com"

import io
import logging
logger = logging.getLogger(__name__)

from prov.serializers import Serializer

Expand All @@ -15,6 +12,7 @@ class ProvNSerializer(Serializer):
"""PROV-N serializer for ProvDocument
"""

def serialize(self, stream, **kwargs):
"""
Serializes a :class:`prov.model.ProvDocument` instance to a
Expand All @@ -23,8 +21,8 @@ def serialize(self, stream, **kwargs):
:param stream: Where to save the output.
"""
provn_content = self.document.get_provn()
if isinstance(stream, io.BytesIO):
provn_content = provn_content.encode('utf-8')
if not isinstance(stream, io.TextIOBase):
provn_content = provn_content.encode("utf-8")
stream.write(provn_content)

def deserialize(self, stream, **kwargs):
Expand Down

0 comments on commit 2e19dcc

Please sign in to comment.