From af06957deffae41a1e11abe8a27be2c05d6bb7f6 Mon Sep 17 00:00:00 2001 From: Oskar Hladky Date: Wed, 17 Jan 2018 12:55:33 +0100 Subject: [PATCH] python3 compatibility --- .gitignore | 3 ++- __init__.py | 1 + cashaddress/convert.py | 18 +++++++++++------- setup.py | 6 +++--- 4 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 __init__.py diff --git a/.gitignore b/.gitignore index 53c37a1..78d276b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -dist \ No newline at end of file +dist +testing.py \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..fc80254 --- /dev/null +++ b/__init__.py @@ -0,0 +1 @@ +pass \ No newline at end of file diff --git a/cashaddress/convert.py b/cashaddress/convert.py index 52f7de0..fd243ee 100644 --- a/cashaddress/convert.py +++ b/cashaddress/convert.py @@ -1,5 +1,6 @@ from cashaddress.crypto import * from base58 import b58decode_check, b58encode_check +import sys class InvalidAddress(Exception): @@ -43,9 +44,14 @@ def cash_address(self): @staticmethod def code_list_to_string(code_list): - output = '' - for code in code_list: - output += chr(code) + if sys.version_info > (3, 0): + output = bytes() + for code in code_list: + output += bytes([code]) + else: + output = '' + for code in code_list: + output += chr(code) return output @staticmethod @@ -57,8 +63,6 @@ def _address_type(address_type, version): @staticmethod def from_string(address_string): - if not isinstance(address_string, str): - raise InvalidAddress('Expected string as input') if ':' not in address_string: return Address._legacy_string(address_string) else: @@ -72,8 +76,8 @@ def _legacy_string(address_string): raise InvalidAddress('Could not decode legacy address') version = Address._address_type('legacy', decoded[0])[0] payload = list() - for letter in str(decoded[1:]): - payload.append(ord(letter)) + for letter in decoded[1:]: + payload.append(letter) return Address(version, payload) @staticmethod diff --git a/setup.py b/setup.py index 1354d20..3b5c08b 100644 --- a/setup.py +++ b/setup.py @@ -2,14 +2,14 @@ from setuptools import find_packages setup(name='cashaddress', - version='1.0.0', + version='1.0.1', packages=find_packages(), install_requires=['base58==0.2.5'], description='Python tool for converty bitcoin cash legacy addresses', author='Oskar Hladky', author_email='oskyks1@gmail.com', url='https://github.com/oskyk/cashaddress', - download_url='https://github.com/oskyk/cashaddress/archive/1.0.0.tar.gz', - python_requires='>=2.7,<3', + download_url='https://github.com/oskyk/cashaddress/archive/1.0.1.tar.gz', + python_requires='>=2.7', keywords=['bitcoincash', 'bch', 'address', 'cashaddress', 'legacy', 'convert'] ) \ No newline at end of file