trungdong / prov

A Python library for W3C Provenance Data Model (PROV)
http://prov.readthedocs.io/
MIT License
120 stars 44 forks source link

Issue for PROV-N serializer when destination is specified #134

Closed jean-francois-sornay closed 4 years ago

jean-francois-sornay commented 4 years ago

I noticed an issue when I use the serialize function from the ProvDocument with the destination parameter set and the format parameter set as 'provn'. It creates an error.

For example, this returns a TypeError Exception :

from prov.model import ProvDocument
d = ProvDocument()
d.add_namespace('ex','example.com')
d.activity('ex:read')
d.serialize(destination='./test.provn', format='provn')

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "prov-1.5.3-py3.7.egg/prov/model.py", line 2404, in serialize
    serializer.serialize(stream, **args)
  File "prov-1.5.3-py3.7.egg/prov/serializers/provn.py", line 28, in serialize
    stream.write(provn_content)
TypeError: a bytes-like object is required, not 'str' 

I found that the stream condition isinstance() at line 26 of provn.py is not the right one. It should be if isinstance(stream, io.BufferedWriter): instead of if isinstance(stream, io.BytesIO):.