iotaledger / pyota-ccurl

C Curl extension for PyOTA
MIT License
3 stars 8 forks source link

Make compatible with Python 2.7 #11

Closed etiennekruger closed 7 years ago

etiennekruger commented 7 years ago

This commit adds some conditional C code to ensure that the module works under Python 2.7 as well as Python 3. Trits are treated as PyInt under Python 2.7 but PyLong under Python 3 because Python 3 handles all Python integers as PyLong.

Fixes #4.

etiennekruger commented 7 years ago

For testing I made the change below in https://github.com/iotaledger/iota.lib.py and ran the full PyOTA test suite under Python 2.7.

diff --git a/src/iota/crypto/__init__.py b/src/iota/crypto/__init__.py
index 63ca830..4cfe576 100644
--- a/src/iota/crypto/__init__.py
+++ b/src/iota/crypto/__init__.py
@@ -5,8 +5,11 @@ from __future__ import absolute_import, division, print_function, \

 # Load curl library.
 # If a compiled c extension is available, we will prefer to load that
-# (once implemented).
-from .pycurl import *
+# and fall back to the pure Python implementation if not.
+try:
+    from ccurl import *
+except ImportError:
+    from .pycurl import *

 FRAGMENT_LENGTH = 2187