From ad2fac17a7b5ac129eff3e4ec87e5bfba2ac7c94 Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Wed, 12 May 2021 18:37:25 +0200 Subject: [PATCH] [enh] #162: sort imports in every files --- duniterpy/api/bma/__init__.py | 3 ++- duniterpy/api/bma/blockchain.py | 5 ++--- duniterpy/api/bma/network.py | 3 +-- duniterpy/api/bma/tx.py | 3 +-- duniterpy/api/bma/wot.py | 3 +-- duniterpy/api/client.py | 7 ++++--- duniterpy/api/endpoint.py | 3 ++- duniterpy/api/ws2p/__init__.py | 1 + duniterpy/api/ws2p/requests.py | 1 + duniterpy/documents/__init__.py | 10 +++++----- duniterpy/documents/block.py | 10 +++++----- duniterpy/documents/block_uid.py | 4 ++-- duniterpy/documents/certification.py | 11 +++++------ duniterpy/documents/crc_pubkey.py | 7 ++++--- duniterpy/documents/document.py | 2 +- duniterpy/documents/identity.py | 4 ++-- duniterpy/documents/membership.py | 4 ++-- duniterpy/documents/peer.py | 9 +++++---- duniterpy/documents/revocation.py | 4 ++-- duniterpy/documents/transaction.py | 11 ++++++----- duniterpy/documents/ws2p/heads.py | 13 +++++++------ duniterpy/documents/ws2p/messages.py | 3 +-- duniterpy/grammars/output.py | 6 +++--- duniterpy/helpers/blockchain.py | 1 + duniterpy/helpers/money.py | 5 +++-- duniterpy/helpers/network.py | 7 +++---- duniterpy/helpers/ws2p.py | 12 +++++++----- duniterpy/key/__init__.py | 4 ++-- duniterpy/key/ascii_armor.py | 7 ++++--- duniterpy/key/base58.py | 2 +- duniterpy/key/encryption_key.py | 8 ++++---- duniterpy/key/signing_key.py | 12 ++++++------ duniterpy/key/verifying_key.py | 3 ++- duniterpy/tools.py | 1 + examples/create_public_key.py | 1 + examples/listen_ws2p.py | 6 +++--- examples/request_available_nodes.py | 2 +- examples/request_data.py | 2 +- examples/request_data_graphql.py | 7 ++++--- examples/request_ws2p.py | 13 ++++++------- examples/save_and_load_private_key_file.py | 3 ++- examples/save_and_load_private_key_file_ewif.py | 3 ++- examples/save_and_load_private_key_file_pubsec.py | 3 ++- examples/save_and_load_private_key_file_wif.py | 3 ++- examples/save_cleartext_ascii_armor_message.py | 1 - examples/save_encrypted_ascii_armor_message.py | 2 +- examples/save_revoke_document.py | 2 +- examples/send_certification.py | 4 ++-- examples/send_transaction.py | 4 ++-- tests/api/bma/test_bma.py | 2 +- tests/api/bma/test_network.py | 2 +- tests/api/bma/test_tx.py | 5 +---- tests/api/bma/test_wot.py | 2 +- tests/api/ws2p/test_ws2p.py | 6 +++--- tests/documents/test_block.py | 2 +- tests/documents/test_certification.py | 7 ++++--- tests/documents/test_crc_pubkey.py | 1 + tests/documents/test_membership.py | 1 + tests/documents/test_transaction.py | 12 +++++++----- tests/documents/test_ws2p_heads.py | 2 +- tests/grammars/test_output.py | 2 +- tests/helpers/money.py | 7 ++++--- tests/helpers/ws2p.py | 2 +- tests/key/test_ascii_armor.py | 5 +++-- tests/key/test_encryption_key.py | 3 ++- tests/key/test_public_key.py | 5 +++-- tests/key/test_signing_key.py | 4 ++-- tests/key/test_verifying_key.py | 11 ++++++----- 68 files changed, 173 insertions(+), 153 deletions(-) diff --git a/duniterpy/api/bma/__init__.py b/duniterpy/api/bma/__init__.py index fdde5b5c..37d73b2d 100644 --- a/duniterpy/api/bma/__init__.py +++ b/duniterpy/api/bma/__init__.py @@ -16,7 +16,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import logging -from . import network, blockchain, tx, wot, node, ud, ws + +from . import blockchain, network, node, tx, ud, wot, ws __all__ = ["network", "blockchain", "tx", "wot", "node", "ud", "ws"] diff --git a/duniterpy/api/bma/blockchain.py b/duniterpy/api/bma/blockchain.py index 57faf3c2..fbe2b87b 100644 --- a/duniterpy/api/bma/blockchain.py +++ b/duniterpy/api/bma/blockchain.py @@ -16,11 +16,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import logging -from typing import Union - from http.client import HTTPResponse +from typing import Union -from duniterpy.api.client import Client, RESPONSE_HTTP +from duniterpy.api.client import RESPONSE_HTTP, Client logger = logging.getLogger("duniter/blockchain") diff --git a/duniterpy/api/bma/network.py b/duniterpy/api/bma/network.py index b29eb6e4..5fe4cf17 100644 --- a/duniterpy/api/bma/network.py +++ b/duniterpy/api/bma/network.py @@ -16,10 +16,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import logging - from http.client import HTTPResponse -from duniterpy.api.client import Client, RESPONSE_HTTP +from duniterpy.api.client import RESPONSE_HTTP, Client logger = logging.getLogger("duniter/network") diff --git a/duniterpy/api/bma/tx.py b/duniterpy/api/bma/tx.py index 06c9876a..9e6524ce 100644 --- a/duniterpy/api/bma/tx.py +++ b/duniterpy/api/bma/tx.py @@ -16,10 +16,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import logging - from http.client import HTTPResponse -from duniterpy.api.client import Client, RESPONSE_HTTP +from duniterpy.api.client import RESPONSE_HTTP, Client logger = logging.getLogger("duniter/tx") diff --git a/duniterpy/api/bma/wot.py b/duniterpy/api/bma/wot.py index 4c01fa4a..430365ce 100644 --- a/duniterpy/api/bma/wot.py +++ b/duniterpy/api/bma/wot.py @@ -16,10 +16,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import logging - from http.client import HTTPResponse -from duniterpy.api.client import Client, RESPONSE_HTTP +from duniterpy.api.client import RESPONSE_HTTP, Client logger = logging.getLogger("duniter/wot") diff --git a/duniterpy/api/client.py b/duniterpy/api/client.py index 709e4c4b..e61db0d1 100644 --- a/duniterpy/api/client.py +++ b/duniterpy/api/client.py @@ -17,14 +17,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. import copy import json import logging -from typing import Callable, Union, Any, Optional, Dict -from urllib import request, parse +from http.client import HTTPResponse +from typing import Any, Callable, Dict, Optional, Union +from urllib import parse, request import jsonschema from websocket import WebSocket -from http.client import HTTPResponse import duniterpy.api.endpoint as endpoint + from .errors import DuniterError logger = logging.getLogger("duniter") diff --git a/duniterpy/api/endpoint.py b/duniterpy/api/endpoint.py index 44ee2c69..acb3eb7d 100644 --- a/duniterpy/api/endpoint.py +++ b/duniterpy/api/endpoint.py @@ -16,9 +16,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import re -from typing import Any, Optional, TypeVar, Type, Dict +from typing import Any, Dict, Optional, Type, TypeVar import duniterpy.constants as constants + from ..documents import MalformedDocumentError diff --git a/duniterpy/api/ws2p/__init__.py b/duniterpy/api/ws2p/__init__.py index 45aa7e01..6a372e87 100644 --- a/duniterpy/api/ws2p/__init__.py +++ b/duniterpy/api/ws2p/__init__.py @@ -16,6 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import logging + from . import network, requests __all__ = ["network", "requests"] diff --git a/duniterpy/api/ws2p/requests.py b/duniterpy/api/ws2p/requests.py index 16792775..1fd61dc1 100644 --- a/duniterpy/api/ws2p/requests.py +++ b/duniterpy/api/ws2p/requests.py @@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. import json import re + from duniterpy.api.bma.blockchain import BLOCK_SCHEMA, BLOCKS_SCHEMA ERROR_RESPONSE_SCHEMA = { diff --git a/duniterpy/documents/__init__.py b/duniterpy/documents/__init__.py index 9ce20d1d..cfe5669e 100644 --- a/duniterpy/documents/__init__.py +++ b/duniterpy/documents/__init__.py @@ -17,18 +17,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. from .block import Block from .block_uid import BlockUID, block_uid -from .document import Document, MalformedDocumentError from .certification import Certification -from .revocation import Revocation +from .crc_pubkey import CRCPubkey +from .document import Document, MalformedDocumentError from .identity import Identity from .membership import Membership +from .revocation import Revocation from .transaction import ( - SimpleTransaction, - Transaction, InputSource, OutputSource, SIGParameter, + SimpleTransaction, + Transaction, Unlock, UnlockParameter, ) -from .crc_pubkey import CRCPubkey diff --git a/duniterpy/documents/block.py b/duniterpy/documents/block.py index 2c304758..1db0a77f 100644 --- a/duniterpy/documents/block.py +++ b/duniterpy/documents/block.py @@ -18,16 +18,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. import base64 import hashlib import re -from typing import TypeVar, Type, Optional, List, Sequence +from typing import List, Optional, Sequence, Type, TypeVar + +from ..constants import BLOCK_HASH_REGEX, PUBKEY_REGEX from .block_uid import BlockUID from .certification import Certification -from .revocation import Revocation -from .identity import Identity from .document import Document, MalformedDocumentError +from .identity import Identity from .membership import Membership +from .revocation import Revocation from .transaction import Transaction -from ..constants import PUBKEY_REGEX, BLOCK_HASH_REGEX - # required to type hint cls in classmethod BlockType = TypeVar("BlockType", bound="Block") diff --git a/duniterpy/documents/block_uid.py b/duniterpy/documents/block_uid.py index bf3f8162..33d7e3e5 100644 --- a/duniterpy/documents/block_uid.py +++ b/duniterpy/documents/block_uid.py @@ -16,10 +16,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import re -from typing import Union, TypeVar, Type +from typing import Type, TypeVar, Union +from ..constants import BLOCK_HASH_REGEX, BLOCK_ID_REGEX, EMPTY_HASH from .document import MalformedDocumentError -from ..constants import EMPTY_HASH, BLOCK_ID_REGEX, BLOCK_HASH_REGEX # required to type hint cls in classmethod BlockUIDType = TypeVar("BlockUIDType", bound="BlockUID") diff --git a/duniterpy/documents/certification.py b/duniterpy/documents/certification.py index 04714a82..776a4af1 100644 --- a/duniterpy/documents/certification.py +++ b/duniterpy/documents/certification.py @@ -18,19 +18,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. import base64 import logging import re -from typing import Optional, TypeVar, Type, Union +from typing import Optional, Type, TypeVar, Union -from .identity import Identity -from .block_uid import BlockUID from ..constants import ( - PUBKEY_REGEX, - SIGNATURE_REGEX, BLOCK_ID_REGEX, BLOCK_UID_REGEX, + PUBKEY_REGEX, + SIGNATURE_REGEX, UID_REGEX, ) +from .block_uid import BlockUID from .document import Document, MalformedDocumentError - +from .identity import Identity # required to type hint cls in classmethod CertificationType = TypeVar("CertificationType", bound="Certification") diff --git a/duniterpy/documents/crc_pubkey.py b/duniterpy/documents/crc_pubkey.py index 834c30ec..93b11d63 100644 --- a/duniterpy/documents/crc_pubkey.py +++ b/duniterpy/documents/crc_pubkey.py @@ -15,11 +15,12 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ -from typing import TypeVar, Type +import hashlib +import re +from typing import Type, TypeVar import base58 -import re -import hashlib + from ..constants import PUBKEY_REGEX from ..tools import ensure_str diff --git a/duniterpy/documents/document.py b/duniterpy/documents/document.py index f14a4d19..bccc1109 100644 --- a/duniterpy/documents/document.py +++ b/duniterpy/documents/document.py @@ -19,7 +19,7 @@ import base64 import hashlib import logging import re -from typing import TypeVar, Type, Any, List +from typing import Any, List, Type, TypeVar from ..constants import SIGNATURE_REGEX diff --git a/duniterpy/documents/identity.py b/duniterpy/documents/identity.py index aa8aaf17..9d2b8d34 100644 --- a/duniterpy/documents/identity.py +++ b/duniterpy/documents/identity.py @@ -16,10 +16,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import re -from typing import Optional, TypeVar, Type +from typing import Optional, Type, TypeVar +from ..constants import BLOCK_UID_REGEX, PUBKEY_REGEX, SIGNATURE_REGEX, UID_REGEX from .block_uid import BlockUID -from ..constants import PUBKEY_REGEX, SIGNATURE_REGEX, BLOCK_UID_REGEX, UID_REGEX from .document import Document, MalformedDocumentError # required to type hint cls in classmethod diff --git a/duniterpy/documents/membership.py b/duniterpy/documents/membership.py index 3e62f874..28beecb6 100644 --- a/duniterpy/documents/membership.py +++ b/duniterpy/documents/membership.py @@ -16,11 +16,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import re -from typing import TypeVar, Type, Optional +from typing import Optional, Type, TypeVar +from ..constants import BLOCK_UID_REGEX, PUBKEY_REGEX, SIGNATURE_REGEX from .block_uid import BlockUID from .document import Document, MalformedDocumentError -from ..constants import BLOCK_UID_REGEX, SIGNATURE_REGEX, PUBKEY_REGEX # required to type hint cls in classmethod MembershipType = TypeVar("MembershipType", bound="Membership") diff --git a/duniterpy/documents/peer.py b/duniterpy/documents/peer.py index 2a382e91..7e881f3a 100644 --- a/duniterpy/documents/peer.py +++ b/duniterpy/documents/peer.py @@ -16,12 +16,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import re -from typing import TypeVar, List, Type +from typing import List, Type, TypeVar + +from duniterpy.api.endpoint import Endpoint, endpoint -from duniterpy.api.endpoint import endpoint, Endpoint -from .document import Document, MalformedDocumentError -from .block_uid import BlockUID from ..constants import BLOCK_HASH_REGEX, PUBKEY_REGEX +from .block_uid import BlockUID +from .document import Document, MalformedDocumentError # required to type hint cls in classmethod PeerType = TypeVar("PeerType", bound="Peer") diff --git a/duniterpy/documents/revocation.py b/duniterpy/documents/revocation.py index 15cee33e..ee38b268 100644 --- a/duniterpy/documents/revocation.py +++ b/duniterpy/documents/revocation.py @@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. import base64 import re -from typing import Union, Type, TypeVar +from typing import Type, TypeVar, Union -from ..constants import PUBKEY_REGEX, SIGNATURE_REGEX, BLOCK_UID_REGEX +from ..constants import BLOCK_UID_REGEX, PUBKEY_REGEX, SIGNATURE_REGEX from .document import Document, MalformedDocumentError from .identity import Identity diff --git a/duniterpy/documents/transaction.py b/duniterpy/documents/transaction.py index 4f640070..ae8f499a 100644 --- a/duniterpy/documents/transaction.py +++ b/duniterpy/documents/transaction.py @@ -16,20 +16,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import re -from typing import TypeVar, List, Any, Type, Optional, Dict, Union, Tuple +from typing import Any, Dict, List, Optional, Tuple, Type, TypeVar, Union import pypeg2 from duniterpy.grammars.output import Condition -from .block_uid import BlockUID -from .document import Document, MalformedDocumentError + from ..constants import ( - PUBKEY_REGEX, - TRANSACTION_HASH_REGEX, BLOCK_ID_REGEX, BLOCK_UID_REGEX, + PUBKEY_REGEX, + TRANSACTION_HASH_REGEX, ) from ..grammars import output +from .block_uid import BlockUID +from .document import Document, MalformedDocumentError def reduce_base(amount: int, base: int) -> Tuple[int, int]: diff --git a/duniterpy/documents/ws2p/heads.py b/duniterpy/documents/ws2p/heads.py index 2016f793..799d2927 100644 --- a/duniterpy/documents/ws2p/heads.py +++ b/duniterpy/documents/ws2p/heads.py @@ -16,19 +16,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import re + import attr -from ..block_uid import BlockUID -from ..document import MalformedDocumentError from ...constants import ( - WS2P_PUBLIC_PREFIX_REGEX, - WS2P_PRIVATE_PREFIX_REGEX, - WS2P_HEAD_REGEX, + BLOCK_UID_REGEX, PUBKEY_REGEX, SIGNATURE_REGEX, + WS2P_HEAD_REGEX, + WS2P_PRIVATE_PREFIX_REGEX, + WS2P_PUBLIC_PREFIX_REGEX, WS2PID_REGEX, - BLOCK_UID_REGEX, ) +from ..block_uid import BlockUID +from ..document import MalformedDocumentError @attr.s() diff --git a/duniterpy/documents/ws2p/messages.py b/duniterpy/documents/ws2p/messages.py index d790a496..540b3ce4 100644 --- a/duniterpy/documents/ws2p/messages.py +++ b/duniterpy/documents/ws2p/messages.py @@ -16,11 +16,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import json - from typing import Optional from duniterpy.documents import Document -from duniterpy.key import VerifyingKey, SigningKey +from duniterpy.key import SigningKey, VerifyingKey from duniterpy.tools import get_ws2p_challenge diff --git a/duniterpy/grammars/output.py b/duniterpy/grammars/output.py index e754bfbe..1ffbaf28 100644 --- a/duniterpy/grammars/output.py +++ b/duniterpy/grammars/output.py @@ -15,11 +15,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ -from typing import Optional, TypeVar, Type, Any, Union +from typing import Any, Optional, Type, TypeVar, Union -from pypeg2 import re, attr, Keyword, Enum, contiguous, maybe_some, whitespace, K +from pypeg2 import Enum, K, Keyword, attr, contiguous, maybe_some, re, whitespace -from ..constants import PUBKEY_REGEX, HASH_REGEX +from ..constants import HASH_REGEX, PUBKEY_REGEX class Pubkey(str): diff --git a/duniterpy/helpers/blockchain.py b/duniterpy/helpers/blockchain.py index 46f4fdee..9afc47a8 100644 --- a/duniterpy/helpers/blockchain.py +++ b/duniterpy/helpers/blockchain.py @@ -29,6 +29,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. import json import pathlib + from ..documents import Block CHUNK_SIZE = 250 diff --git a/duniterpy/helpers/money.py b/duniterpy/helpers/money.py index 6f9076eb..910e4bcd 100644 --- a/duniterpy/helpers/money.py +++ b/duniterpy/helpers/money.py @@ -15,8 +15,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ -from typing import Union, Any -from duniterpy.grammars.output import SIG, CSV, CLTV, XHX, Condition +from typing import Any, Union + +from duniterpy.grammars.output import CLTV, CSV, SIG, XHX, Condition def output_available( diff --git a/duniterpy/helpers/network.py b/duniterpy/helpers/network.py index af151223..87e21f42 100644 --- a/duniterpy/helpers/network.py +++ b/duniterpy/helpers/network.py @@ -15,14 +15,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ -from typing import List, Dict, Any +from itertools import groupby +from typing import Any, Dict, List from duniterpy.api import bma from duniterpy.api.client import Client -from duniterpy.documents.peer import Peer, MalformedDocumentError +from duniterpy.documents.peer import MalformedDocumentError, Peer from duniterpy.documents.ws2p.heads import HeadV2 -from itertools import groupby - from duniterpy.key import VerifyingKey diff --git a/duniterpy/helpers/ws2p.py b/duniterpy/helpers/ws2p.py index 80e671f0..6c9828b6 100644 --- a/duniterpy/helpers/ws2p.py +++ b/duniterpy/helpers/ws2p.py @@ -15,14 +15,16 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ -import jsonschema +import logging from typing import Union -from duniterpy.api import ws2p, bma -from duniterpy.api.client import WSConnection, Client + +import jsonschema + +from duniterpy.api import bma, ws2p +from duniterpy.api.client import Client, WSConnection from duniterpy.api.endpoint import BMAEndpoint, SecuredBMAEndpoint, WS2PEndpoint -from duniterpy.documents.ws2p.messages import Connect, Ack, Ok +from duniterpy.documents.ws2p.messages import Ack, Connect, Ok from duniterpy.key import SigningKey -import logging def handshake(ws: WSConnection, signing_key: SigningKey, currency: str): diff --git a/duniterpy/key/__init__.py b/duniterpy/key/__init__.py index a3cf1acd..cc2ea0d9 100644 --- a/duniterpy/key/__init__.py +++ b/duniterpy/key/__init__.py @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ +from .ascii_armor import AsciiArmor +from .encryption_key import PublicKey, SecretKey from .signing_key import SigningKey from .verifying_key import VerifyingKey -from .encryption_key import SecretKey, PublicKey -from .ascii_armor import AsciiArmor diff --git a/duniterpy/key/ascii_armor.py b/duniterpy/key/ascii_armor.py index 154eab3e..3879ee39 100644 --- a/duniterpy/key/ascii_armor.py +++ b/duniterpy/key/ascii_armor.py @@ -16,12 +16,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import base64 +import re +from typing import Any, Dict, List, Optional + import libnacl from libnacl.version import version as libnacl_version -import re -from typing import Optional, List, Dict, Any -from duniterpy.key import SigningKey, PublicKey, VerifyingKey +from duniterpy.key import PublicKey, SigningKey, VerifyingKey # Headers constants BEGIN_MESSAGE_HEADER = "-----BEGIN DUNITER MESSAGE-----" diff --git a/duniterpy/key/base58.py b/duniterpy/key/base58.py index 5b1afe2c..b8a4172f 100644 --- a/duniterpy/key/base58.py +++ b/duniterpy/key/base58.py @@ -19,7 +19,7 @@ from typing import Union import base58 -from ..tools import ensure_str, ensure_bytes +from ..tools import ensure_bytes, ensure_str class Base58Encoder: diff --git a/duniterpy/key/encryption_key.py b/duniterpy/key/encryption_key.py index b575bca4..9157ebbd 100644 --- a/duniterpy/key/encryption_key.py +++ b/duniterpy/key/encryption_key.py @@ -15,14 +15,14 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ -from typing import Union, Optional +from hashlib import scrypt +from typing import Optional, Union import libnacl.public -from hashlib import scrypt -from .scrypt_params import ScryptParams -from .base58 import Base58Encoder from ..tools import ensure_bytes +from .base58 import Base58Encoder +from .scrypt_params import ScryptParams class SecretKey(libnacl.public.SecretKey): diff --git a/duniterpy/key/signing_key.py b/duniterpy/key/signing_key.py index 45696723..b1c798c8 100644 --- a/duniterpy/key/signing_key.py +++ b/duniterpy/key/signing_key.py @@ -17,21 +17,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. import base64 import re -from typing import Optional, Union, TypeVar, Type +from hashlib import scrypt +from typing import Optional, Type, TypeVar, Union import libnacl.sign import pyaes from libnacl.utils import load_key -from hashlib import scrypt -from .scrypt_params import ScryptParams -from .base58 import Base58Encoder from ..tools import ( + convert_seed_to_seedhex, + convert_seedhex_to_seed, ensure_bytes, xor_bytes, - convert_seedhex_to_seed, - convert_seed_to_seedhex, ) +from .base58 import Base58Encoder +from .scrypt_params import ScryptParams # required to type hint cls in classmethod SigningKeyType = TypeVar("SigningKeyType", bound="SigningKey") diff --git a/duniterpy/key/verifying_key.py b/duniterpy/key/verifying_key.py index 5577a18c..ce139059 100644 --- a/duniterpy/key/verifying_key.py +++ b/duniterpy/key/verifying_key.py @@ -18,11 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. import base64 from typing import Any -import libnacl.sign import libnacl.encode +import libnacl.sign from duniterpy.documents import Document from duniterpy.documents.block import Block + from .base58 import Base58Encoder diff --git a/duniterpy/tools.py b/duniterpy/tools.py index a613e642..c1ae4e9b 100644 --- a/duniterpy/tools.py +++ b/duniterpy/tools.py @@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. import uuid from typing import Union + from libnacl.encode import hex_decode, hex_encode diff --git a/examples/create_public_key.py b/examples/create_public_key.py index 8c088a65..808b72b6 100644 --- a/examples/create_public_key.py +++ b/examples/create_public_key.py @@ -16,6 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import getpass + from duniterpy.key import SigningKey ################################################ diff --git a/examples/listen_ws2p.py b/examples/listen_ws2p.py index 6a8c4f24..aaced06f 100644 --- a/examples/listen_ws2p.py +++ b/examples/listen_ws2p.py @@ -17,13 +17,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. import json import sys + import jsonschema from jsonschema import ValidationError -from duniterpy.key import SigningKey - -from duniterpy.helpers.ws2p import handshake, generate_ws2p_endpoint from duniterpy.api.client import Client +from duniterpy.helpers.ws2p import generate_ws2p_endpoint, handshake +from duniterpy.key import SigningKey # CONFIG ####################################### diff --git a/examples/request_available_nodes.py b/examples/request_available_nodes.py index e4a394bd..8965ca0e 100644 --- a/examples/request_available_nodes.py +++ b/examples/request_available_nodes.py @@ -15,8 +15,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ -from duniterpy.helpers import network from duniterpy.api.client import Client +from duniterpy.helpers import network # CONFIG ####################################### diff --git a/examples/request_data.py b/examples/request_data.py index f86b7a45..8f833d96 100644 --- a/examples/request_data.py +++ b/examples/request_data.py @@ -15,8 +15,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ -from duniterpy.api.client import Client, RESPONSE_HTTP from duniterpy.api import bma +from duniterpy.api.client import RESPONSE_HTTP, Client # CONFIG ####################################### diff --git a/examples/request_data_graphql.py b/examples/request_data_graphql.py index e9fa5f1f..554d5acb 100644 --- a/examples/request_data_graphql.py +++ b/examples/request_data_graphql.py @@ -1,10 +1,11 @@ -import sys import json +import sys -from duniterpy.api.client import Client -from graphql import get_introspection_query, build_client_schema, language, validate +from graphql import build_client_schema, get_introspection_query, language, validate from graphql.error import GraphQLSyntaxError +from duniterpy.api.client import Client + # CONFIG ####################################### # You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT] diff --git a/examples/request_ws2p.py b/examples/request_ws2p.py index 73c441b0..cdb79859 100644 --- a/examples/request_ws2p.py +++ b/examples/request_ws2p.py @@ -16,19 +16,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import json -import time import sys +import time +from typing import Any import jsonschema from jsonschema import ValidationError -from typing import Any -from duniterpy.tools import get_ws2p_challenge -from duniterpy.key import SigningKey - -from duniterpy.helpers.ws2p import handshake, generate_ws2p_endpoint -from duniterpy.api.ws2p import requests from duniterpy.api.client import Client, WSConnection +from duniterpy.api.ws2p import requests +from duniterpy.helpers.ws2p import generate_ws2p_endpoint, handshake +from duniterpy.key import SigningKey +from duniterpy.tools import get_ws2p_challenge # CONFIG ####################################### diff --git a/examples/save_and_load_private_key_file.py b/examples/save_and_load_private_key_file.py index 8e3c477f..14ebee8f 100644 --- a/examples/save_and_load_private_key_file.py +++ b/examples/save_and_load_private_key_file.py @@ -15,11 +15,12 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ -from duniterpy.key import SigningKey import getpass import os import sys +from duniterpy.key import SigningKey + if "XDG_CONFIG_HOME" in os.environ: home_path = os.environ["XDG_CONFIG_HOME"] elif "HOME" in os.environ: diff --git a/examples/save_and_load_private_key_file_ewif.py b/examples/save_and_load_private_key_file_ewif.py index 135ed202..196c6145 100644 --- a/examples/save_and_load_private_key_file_ewif.py +++ b/examples/save_and_load_private_key_file_ewif.py @@ -15,11 +15,12 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ -from duniterpy.key import SigningKey import getpass import os import sys +from duniterpy.key import SigningKey + if "XDG_CONFIG_HOME" in os.environ: home_path = os.environ["XDG_CONFIG_HOME"] elif "HOME" in os.environ: diff --git a/examples/save_and_load_private_key_file_pubsec.py b/examples/save_and_load_private_key_file_pubsec.py index afe41a37..774fa401 100644 --- a/examples/save_and_load_private_key_file_pubsec.py +++ b/examples/save_and_load_private_key_file_pubsec.py @@ -15,11 +15,12 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ -from duniterpy.key import SigningKey import getpass import os import sys +from duniterpy.key import SigningKey + if "XDG_CONFIG_HOME" in os.environ: home_path = os.environ["XDG_CONFIG_HOME"] elif "HOME" in os.environ: diff --git a/examples/save_and_load_private_key_file_wif.py b/examples/save_and_load_private_key_file_wif.py index fd78982d..a76f3872 100644 --- a/examples/save_and_load_private_key_file_wif.py +++ b/examples/save_and_load_private_key_file_wif.py @@ -15,11 +15,12 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ -from duniterpy.key import SigningKey import getpass import os import sys +from duniterpy.key import SigningKey + if "XDG_CONFIG_HOME" in os.environ: home_path = os.environ["XDG_CONFIG_HOME"] elif "HOME" in os.environ: diff --git a/examples/save_cleartext_ascii_armor_message.py b/examples/save_cleartext_ascii_armor_message.py index 2efb6c2d..405d9f5c 100644 --- a/examples/save_cleartext_ascii_armor_message.py +++ b/examples/save_cleartext_ascii_armor_message.py @@ -19,7 +19,6 @@ import getpass import sys from duniterpy import __version__ - from duniterpy.key import AsciiArmor, SigningKey # CONFIG ####################################### diff --git a/examples/save_encrypted_ascii_armor_message.py b/examples/save_encrypted_ascii_armor_message.py index d5cc6a1b..a1d8881f 100644 --- a/examples/save_encrypted_ascii_armor_message.py +++ b/examples/save_encrypted_ascii_armor_message.py @@ -16,8 +16,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import getpass -from duniterpy import __version__ +from duniterpy import __version__ from duniterpy.key import AsciiArmor, SigningKey # CONFIG ####################################### diff --git a/examples/save_revoke_document.py b/examples/save_revoke_document.py index 1496f7d4..12ffd84b 100644 --- a/examples/save_revoke_document.py +++ b/examples/save_revoke_document.py @@ -22,7 +22,7 @@ from typing import Optional from duniterpy.api import bma from duniterpy.api.client import Client -from duniterpy.documents import Revocation, BlockUID, Identity +from duniterpy.documents import BlockUID, Identity, Revocation from duniterpy.key import SigningKey if "XDG_CONFIG_HOME" in os.environ: diff --git a/examples/send_certification.py b/examples/send_certification.py index 0d50c041..2be1907e 100644 --- a/examples/send_certification.py +++ b/examples/send_certification.py @@ -15,13 +15,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ -import sys import getpass +import sys from typing import Optional from duniterpy.api import bma from duniterpy.api.client import Client -from duniterpy.documents import BlockUID, Identity, Certification +from duniterpy.documents import BlockUID, Certification, Identity from duniterpy.key import SigningKey # CONFIG ####################################### diff --git a/examples/send_transaction.py b/examples/send_transaction.py index f841adcd..e9e2c8f5 100644 --- a/examples/send_transaction.py +++ b/examples/send_transaction.py @@ -15,8 +15,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ -import sys import getpass +import sys from duniterpy.api import bma from duniterpy.api.client import Client @@ -24,8 +24,8 @@ from duniterpy.documents import BlockUID, Transaction from duniterpy.documents.transaction import ( InputSource, OutputSource, - Unlock, SIGParameter, + Unlock, ) from duniterpy.key import SigningKey diff --git a/tests/api/bma/test_bma.py b/tests/api/bma/test_bma.py index 8fee4314..9cdcd112 100644 --- a/tests/api/bma/test_bma.py +++ b/tests/api/bma/test_bma.py @@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. import unittest from duniterpy.api.client import API, parse_error -from duniterpy.api.endpoint import BMAEndpoint, SecuredBMAEndpoint, GVAEndpoint +from duniterpy.api.endpoint import BMAEndpoint, GVAEndpoint, SecuredBMAEndpoint class TestBmaApi(unittest.TestCase): diff --git a/tests/api/bma/test_network.py b/tests/api/bma/test_network.py index ac7f1543..32b8f5b6 100644 --- a/tests/api/bma/test_network.py +++ b/tests/api/bma/test_network.py @@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. import unittest import jsonschema -from jsonschema import ValidationError, SchemaError +from jsonschema import SchemaError, ValidationError from duniterpy.api.bma import network diff --git a/tests/api/bma/test_tx.py b/tests/api/bma/test_tx.py index 6f8c5f13..524f203c 100644 --- a/tests/api/bma/test_tx.py +++ b/tests/api/bma/test_tx.py @@ -20,10 +20,7 @@ import unittest import jsonschema from jsonschema import SchemaError, ValidationError -from duniterpy.api.bma.tx import ( - HISTORY_SCHEMA, - SOURCES_SCHEMA, -) +from duniterpy.api.bma.tx import HISTORY_SCHEMA, SOURCES_SCHEMA class TestBmaTx(unittest.TestCase): diff --git a/tests/api/bma/test_wot.py b/tests/api/bma/test_wot.py index 995088ba..e5cfa3ba 100644 --- a/tests/api/bma/test_wot.py +++ b/tests/api/bma/test_wot.py @@ -21,10 +21,10 @@ import jsonschema from jsonschema import SchemaError, ValidationError from duniterpy.api.bma.wot import ( - REQUIREMENTS_SCHEMA, CERTIFICATIONS_SCHEMA, LOOKUP_SCHEMA, MEMBERS_SCHEMA, + REQUIREMENTS_SCHEMA, ) diff --git a/tests/api/ws2p/test_ws2p.py b/tests/api/ws2p/test_ws2p.py index 9a5c39b5..784bf49a 100644 --- a/tests/api/ws2p/test_ws2p.py +++ b/tests/api/ws2p/test_ws2p.py @@ -20,15 +20,15 @@ import unittest import jsonschema -from duniterpy.api.client import parse_text from duniterpy.api.bma.network import WS2P_HEADS_SCHEMA +from duniterpy.api.client import parse_text from duniterpy.api.ws2p.requests import ( BLOCK_RESPONSE_SCHEMA, - ERROR_RESPONSE_SCHEMA, BLOCKS_RESPONSE_SCHEMA, + ERROR_RESPONSE_SCHEMA, REQUIREMENTS_RESPONSE_SCHEMA, ) -from duniterpy.documents import Identity, BlockUID +from duniterpy.documents import BlockUID, Identity from duniterpy.documents.ws2p.messages import DocumentMessage diff --git a/tests/documents/test_block.py b/tests/documents/test_block.py index 37446e1f..227eb4d9 100644 --- a/tests/documents/test_block.py +++ b/tests/documents/test_block.py @@ -15,8 +15,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ -import unittest import json +import unittest from duniterpy.documents.block import Block from duniterpy.documents.block_uid import BlockUID, block_uid diff --git a/tests/documents/test_certification.py b/tests/documents/test_certification.py index ddb4099f..8b4e802a 100644 --- a/tests/documents/test_certification.py +++ b/tests/documents/test_certification.py @@ -16,11 +16,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import unittest + +from duniterpy.constants import EMPTY_HASH +from duniterpy.documents.block import BlockUID from duniterpy.documents.certification import Certification -from duniterpy.documents.revocation import Revocation from duniterpy.documents.identity import Identity -from duniterpy.documents.block import BlockUID -from duniterpy.constants import EMPTY_HASH +from duniterpy.documents.revocation import Revocation selfcert_inlines = [ "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:\ diff --git a/tests/documents/test_crc_pubkey.py b/tests/documents/test_crc_pubkey.py index c7f5d3a0..cd0b0965 100644 --- a/tests/documents/test_crc_pubkey.py +++ b/tests/documents/test_crc_pubkey.py @@ -16,6 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import unittest + from duniterpy.documents.crc_pubkey import CRCPubkey diff --git a/tests/documents/test_membership.py b/tests/documents/test_membership.py index f39fde54..a03bbfc1 100644 --- a/tests/documents/test_membership.py +++ b/tests/documents/test_membership.py @@ -16,6 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import unittest + from duniterpy.documents.membership import Membership membership_inline = "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:\ diff --git a/tests/documents/test_transaction.py b/tests/documents/test_transaction.py index f2d82d67..9d17fdab 100644 --- a/tests/documents/test_transaction.py +++ b/tests/documents/test_transaction.py @@ -15,18 +15,20 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import unittest + import pypeg2 -from duniterpy.grammars import output + from duniterpy.documents import BlockUID from duniterpy.documents.transaction import ( - Transaction, - reduce_base, - SimpleTransaction, InputSource, OutputSource, - Unlock, SIGParameter, + SimpleTransaction, + Transaction, + Unlock, + reduce_base, ) +from duniterpy.grammars import output compact_change = """TX:10:1:1:1:1:1:0 13410-000041DF0CCA173F09B5FBA48F619D4BC934F12ADF1D0B798639EB2149C4A8CC diff --git a/tests/documents/test_ws2p_heads.py b/tests/documents/test_ws2p_heads.py index 9ce8c078..c2a28c28 100644 --- a/tests/documents/test_ws2p_heads.py +++ b/tests/documents/test_ws2p_heads.py @@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. import unittest -from duniterpy.documents.ws2p.heads import HeadV0, HeadV1, HeadV2, BlockUID +from duniterpy.documents.ws2p.heads import BlockUID, HeadV0, HeadV1, HeadV2 headv1_clear = "" diff --git a/tests/grammars/test_output.py b/tests/grammars/test_output.py index 51aef501..6d00c45f 100644 --- a/tests/grammars/test_output.py +++ b/tests/grammars/test_output.py @@ -19,7 +19,7 @@ import unittest import pypeg2 -from duniterpy.grammars.output import SIG, CLTV, CSV, XHX, Operator, Condition +from duniterpy.grammars.output import CLTV, CSV, SIG, XHX, Condition, Operator pubkey = "DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV" diff --git a/tests/helpers/money.py b/tests/helpers/money.py index 2ff81d14..ea2f426d 100644 --- a/tests/helpers/money.py +++ b/tests/helpers/money.py @@ -16,10 +16,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import unittest -from operator import eq, ne, lt, ge -from duniterpy.helpers.money import output_available -from duniterpy.grammars.output import SIG, XHX, CLTV, CSV +from operator import eq, ge, lt, ne + from duniterpy.documents.transaction import OutputSource +from duniterpy.grammars.output import CLTV, CSV, SIG, XHX +from duniterpy.helpers.money import output_available class TestHelpersMoney(unittest.TestCase): diff --git a/tests/helpers/ws2p.py b/tests/helpers/ws2p.py index 1d8523ee..1327be5e 100644 --- a/tests/helpers/ws2p.py +++ b/tests/helpers/ws2p.py @@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. import pytest +from duniterpy.api.endpoint import BMAEndpoint, SecuredBMAEndpoint, WS2PEndpoint from duniterpy.helpers.ws2p import generate_ws2p_endpoint -from duniterpy.api.endpoint import WS2PEndpoint, SecuredBMAEndpoint, BMAEndpoint def peering_no_ws2p(self): diff --git a/tests/key/test_ascii_armor.py b/tests/key/test_ascii_armor.py index d50205c1..ad045eeb 100644 --- a/tests/key/test_ascii_armor.py +++ b/tests/key/test_ascii_armor.py @@ -15,14 +15,15 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ +import unittest + from duniterpy.key import AsciiArmor, SigningKey from duniterpy.key.ascii_armor import ( BEGIN_MESSAGE_HEADER, BEGIN_SIGNATURE_HEADER, - END_SIGNATURE_HEADER, END_MESSAGE_HEADER, + END_SIGNATURE_HEADER, ) -import unittest class TestAsciiArmor(unittest.TestCase): diff --git a/tests/key/test_encryption_key.py b/tests/key/test_encryption_key.py index 339f94fd..146bee2d 100644 --- a/tests/key/test_encryption_key.py +++ b/tests/key/test_encryption_key.py @@ -15,9 +15,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ -from duniterpy.key import SecretKey import unittest +from duniterpy.key import SecretKey + class TestEncryptionKey(unittest.TestCase): def test_from_bob_to_alice(self): diff --git a/tests/key/test_public_key.py b/tests/key/test_public_key.py index ba1771a1..ace6d04e 100644 --- a/tests/key/test_public_key.py +++ b/tests/key/test_public_key.py @@ -15,10 +15,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ -from duniterpy.key import SigningKey, PublicKey -from duniterpy.key.scrypt_params import ScryptParams import unittest +from duniterpy.key import PublicKey, SigningKey +from duniterpy.key.scrypt_params import ScryptParams + class TestPublicKey(unittest.TestCase): def test_encrypt_seal(self): diff --git a/tests/key/test_signing_key.py b/tests/key/test_signing_key.py index 1bd9a4ae..67a1e448 100644 --- a/tests/key/test_signing_key.py +++ b/tests/key/test_signing_key.py @@ -16,10 +16,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import os +import unittest -from duniterpy.key import VerifyingKey, SigningKey, PublicKey +from duniterpy.key import PublicKey, SigningKey, VerifyingKey from duniterpy.key.scrypt_params import ScryptParams -import unittest TEST_FILE_PATH = "/tmp/test_file.txt" diff --git a/tests/key/test_verifying_key.py b/tests/key/test_verifying_key.py index 1ae08ab1..2ceb67bd 100644 --- a/tests/key/test_verifying_key.py +++ b/tests/key/test_verifying_key.py @@ -15,13 +15,14 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ -from duniterpy.key import VerifyingKey, SigningKey -from duniterpy.key.scrypt_params import ScryptParams -from duniterpy.documents.peer import Peer -from duniterpy.documents.ws2p.heads import HeadV0, HeadV1, HeadV2 +import unittest + from duniterpy.documents import Block +from duniterpy.documents.peer import Peer from duniterpy.documents.transaction import Transaction -import unittest +from duniterpy.documents.ws2p.heads import HeadV0, HeadV1, HeadV2 +from duniterpy.key import SigningKey, VerifyingKey +from duniterpy.key.scrypt_params import ScryptParams class TestVerifyingKey(unittest.TestCase): -- GitLab