diff --git a/.travis.yml b/.travis.yml index 5fe22ef..86ea484 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ jobs: script: - black --check -l 120 . --exclude=".*_pb2.py" - mypy --ignore-missing-imports --disallow-untyped-defs ./exonum_client ./examples - - pylint exonum_client --max-line-length=120 --disable=fixme,bad-continuation,too-few-public-methods; exit $(($? & 3)) + - pylint exonum_client --max-line-length=120 --disable=fixme,bad-continuation,too-few-public-methods - name: docs install: - pip install sphinx diff --git a/examples/deploy.py b/examples/deploy.py index 765fefc..0c339b0 100644 --- a/examples/deploy.py +++ b/examples/deploy.py @@ -35,7 +35,7 @@ def run() -> None: instance_id = start_service(client, service_name, instance_name) - # If no exception has occured during the previous calls, the service + # If no exception has occurred during the previous calls, the service # has started successfully: print(f"Service instance '{instance_name}' (artifact '{service_name}') started with ID {instance_id}.") except RuntimeError as err: @@ -119,7 +119,7 @@ def send_request(client: ExonumClient, endpoint: str, data: bytes) -> None: response = client.post_service("supervisor", endpoint, json_request, private=True) if response.status_code != 200: - error_msg = f"Error occured during the request to the '{endpoint}' endpoint: {response.content}" + error_msg = f"Error occurred during the request to the '{endpoint}' endpoint: {response.content!r}" raise RuntimeError(error_msg) # Wait for 10 seconds. diff --git a/examples/transactions.py b/examples/transactions.py index 13ca84c..efd359b 100644 --- a/examples/transactions.py +++ b/examples/transactions.py @@ -154,7 +154,7 @@ def get_balance(client: ExonumClient, key: PublicKey) -> int: def ensure_status_code(response: requests.Response) -> None: """Raises an error if the status code is not 200.""" if response.status_code != 200: - raise RuntimeError(f"Received non-ok response: {response.content}") + raise RuntimeError(f"Received non-ok response: {response.content!r}") def ensure_transaction_success(client: ExonumClient, tx_hash: str) -> None: diff --git a/exonum_client/client.py b/exonum_client/client.py index 8c2a106..44b4a9d 100644 --- a/exonum_client/client.py +++ b/exonum_client/client.py @@ -148,12 +148,18 @@ def send_transaction(self, message: ExonumMessage) -> str: Result of the WebSocket request. If a transaction is correct and it is accepted, it will contain a JSON with a hash of the transaction. """ + body_raw = message.signed_raw() + if body_raw is None: + logger.critical("Attempt to send an unsigned message through websocket.") + raise RuntimeError("Attempt to send an unsigned message.") + data = json.dumps({"type": "transaction", "payload": {"tx_body": body_raw.hex()}}) + ws_client = WebSocket() ws_client.connect(self._address) - data = json.dumps({"type": "transaction", "payload": {"tx_body": message.signed_raw().hex()}}) ws_client.send(data) response = ws_client.recv() ws_client.close() + return response @@ -200,12 +206,12 @@ def __init__(self, hostname: str, public_api_port: int = 80, private_api_port: i def __repr__(self) -> str: """ Conversion to a string. """ - d = dict() - - d["object"] = f"<{self.__class__.__name__} instance at {id(self)}>" - d["host"] = self.hostname - d["public_port"] = self.public_api_port - d["private_port"] = self.private_api_port + d = { + "object": f"<{self.__class__.__name__} instance at {id(self)}>", + "host": self.hostname, + "public_port": str(self.public_api_port), + "private_port": str(self.private_api_port), + } return json.dumps(d, indent=2) @@ -634,7 +640,7 @@ def get_peers(self) -> requests.Response: """ return _get(self._system_private_endpoint("peers")) - def set_consensus_interaction(self, enabled: True) -> requests.Response: + def set_consensus_interaction(self, enabled: bool = True) -> requests.Response: """ Performs a POST request to the '{system_base_path}/consensus_enabled' to switch consensus interaction of the node on or off. @@ -716,7 +722,7 @@ def _get_proto_sources(self, params: Optional[Dict[str, str]] = None) -> List[Pr response.status_code, json.dumps(response.json(), indent=2), ) - raise RuntimeError("Unsuccessfully attempted to retrieve Protobuf sources: {}".format(response.content)) + raise RuntimeError("Unsuccessfully attempted to retrieve Protobuf sources: {!r}".format(response.content)) logger.debug("Protobuf sources retrieved successfully.") proto_files = [ diff --git a/exonum_client/proofs/map_proof/errors.py b/exonum_client/proofs/map_proof/errors.py index f54a3fe..8064fde 100644 --- a/exonum_client/proofs/map_proof/errors.py +++ b/exonum_client/proofs/map_proof/errors.py @@ -65,7 +65,7 @@ def malformed_entry(cls, entry: Any, additional_info: Any = None) -> "MalformedM @classmethod def invalid_key_size(cls, key: bytes) -> "MalformedMapProofError": - error_msg = f"Invalid key '{key}' for raw MapProof, expected size {KEY_SIZE}, actual {len(key)}" + error_msg = f"Invalid key '{key!r}' for raw MapProof, expected size {KEY_SIZE}, actual {len(key)}" error_data = {"kind": cls.ErrorKind.INVALID_KEY_SIZE, "key": key} diff --git a/requirements.txt b/requirements.txt index e788b04..8d16442 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,7 +19,7 @@ lazy-object-proxy==1.4.2 MarkupSafe==1.1.1 mccabe==0.6.1 more-itertools==7.2.0 -mypy==0.730 +mypy==0.740 mypy-extensions==0.4.1 packaging==19.2 pkginfo==1.5.0.1