cyberphone / json-canonicalization

JSON Canonicalization Scheme (JCS)
Other
98 stars 23 forks source link

[Python] Support for Python 2.7 #21

Closed AnasMK closed 3 years ago

AnasMK commented 3 years ago

Hey there,

Is there any support for Python 2.7

cyberphone commented 3 years ago

Hi @AnasMK, there once was support for Python 2.7 but I removed when the Python authors decided to halt the 2.7 branch. On the other hand, the existing implementation is very basic so it might very well run in 2.7 as well. The test programs would verify if that is the case. Regards, @cyberphone (Anders)

AnasMK commented 3 years ago

Hi @cyberphone, thank you, I really appreciate your quick replay.

I have tried to run tests using python 2.7, there were some syntax errors in Canonicalize.py I did these changes:

  1. had to remove bare asterisk argument in JSONEncoder constructor, not supported in 2.7
  2. had to change yeild from statement to for loop in 5 places
    • lines: 346, 425, 449, 451, 459
    • All of them have been replaced by this for loop
      for bar in foo: 
        yield bar

      After these changes verify-canonicalization.py produce this error:

      TypeError: Object of type 'unicode' is not JSON serializable

Any help to resolve this issue. Thank you.

AnasMK commented 3 years ago

Hi @cyberphone, If you have a local copy of the Python 2.7 branch, it will be much appreciated to upload it again :pray:.

cyberphone commented 3 years ago

It seems that I lost that branch during a restructuring. Usually I put unsupported stuff in the "historical" repo but this time not 😔

cyberphone commented 3 years ago

Hi @AnasMK I would consider porting https://github.com/gowebpki/jcs/blob/master/jcs.go as an alternative. This may be easier to follow: https://github.com/cyberphone/json-canonicalization/blob/master/dotnet/jsoncanonicalizer/JsonCanonicalizer.cs

AnasMK commented 3 years ago

Hi, Thanks for your support @cyberphone, I had successfully ported Python3 code to Python2.7.

For anyone is interested in Python 2.7 version I have pushed the code on this Forked repository

@cyberphone, Thank you again for your efforts with this repo.

cyberphone commented 3 years ago

Thanks and Congratulations! I will update my JCS info with your implementation.