collective / collective.jsonmigrator

JSON based migrations for Plone
GNU General Public License v2.0
8 stars 21 forks source link

Make it actually work without simplejson #24

Closed dhavlik closed 7 years ago

dhavlik commented 7 years ago

There is no JSONDecodeError in python2 stdlib json module, so we created an alias for the ValueError in the try-except importerror-magic.

ale-rt commented 7 years ago

I am merging this because it fixes a bug.

[ale@emily ~]$ python2.7 -c "from json import JSONDecodeError"                                                                                                                                                    
Traceback (most recent call last):                                                                                                                                                                                
  File "<string>", line 1, in <module>                                                                                                                                                                            
ImportError: cannot import name JSONDecodeError

Anyway JSONDecodeError is present in python3.5.

[ale@emily ~]$ python3.5 -c "from json import JSONDecodeError"

For this reason a more proper version may be:

try:
    import json
except ImportError:
    import simplejson as json

try:
    JSONDecodeError = json.JSONDecodeError
except AttributeError:
    JSONDecodeError = ValueError