diff --git a/silkaj/auth.py b/silkaj/auth.py index 85af75561d808c7dcfdf8947c594ee5f8309287f..a659df693671af217cf8e87a14b378aab1a3fbc0 100644 --- a/silkaj/auth.py +++ b/silkaj/auth.py @@ -26,7 +26,7 @@ from silkaj.tools import message_exit from silkaj.tui import display_pubkey_and_checksum SEED_HEX_PATTERN = "^[0-9a-fA-F]{64}$" -PUBSEC_PUBKEY_PATTERN = "pub: ({0})".format(PUBKEY_PATTERN) +PUBSEC_PUBKEY_PATTERN = f"pub: ({PUBKEY_PATTERN})" PUBSEC_SIGNKEY_PATTERN = "sec: ([1-9A-HJ-NP-Za-km-z]{87,90})" diff --git a/silkaj/blockchain_tools.py b/silkaj/blockchain_tools.py index 5c4b2731e7c212b5aff385e0fcfcda10a9c39e40..ed8c04fae3ca313c47cb5875ca22ce35069955d5 100644 --- a/silkaj/blockchain_tools.py +++ b/silkaj/blockchain_tools.py @@ -18,7 +18,7 @@ from duniterpy.api.bma import blockchain from silkaj.network_tools import ClientInstance -class BlockchainParams(object): +class BlockchainParams: __instance = None def __new__(cls): @@ -34,7 +34,7 @@ class BlockchainParams(object): return await client(blockchain.parameters) -class HeadBlock(object): +class HeadBlock: __instance = None def __new__(cls): diff --git a/silkaj/blocks.py b/silkaj/blocks.py index 212e6f6653e6c2db5dc600575b7370ba5fd1c9cd..ed8f49fc80288d5348277bf3f442ddd82c3626f8 100644 --- a/silkaj/blocks.py +++ b/silkaj/blocks.py @@ -104,7 +104,7 @@ def verify_block_signature(invalid_blocks_signatures, block): def display_result(from_block, to_block, invalid_blocks_signatures): - result = "Within {0}-{1} range, ".format(from_block, to_block) + result = f"Within {from_block}-{to_block} range, " if invalid_blocks_signatures: result += "blocks with a wrong signature: " result += " ".join(str(n) for n in invalid_blocks_signatures) diff --git a/silkaj/cert.py b/silkaj/cert.py index c8a01c9bd3471b77a979c4c374532b5d535814f9..db675b4c08d00868884dee6dc125fe5d759ca321 100644 --- a/silkaj/cert.py +++ b/silkaj/cert.py @@ -84,7 +84,7 @@ async def send_certification(ctx, uid_pubkey_to_certify): if response.status == 200: print("Certification successfully sent.") else: - print("Error while publishing certification: {0}".format(await response.text())) + print(f"Error while publishing certification: {await response.text()}") await client.close() diff --git a/silkaj/cli_tools.py b/silkaj/cli_tools.py index cfe5cfefa0433ac7531f96bc2f940106fc025c4d..5aa0c6c8bf7530f9c98ce004426e94534453e928 100644 --- a/silkaj/cli_tools.py +++ b/silkaj/cli_tools.py @@ -26,7 +26,7 @@ class MutuallyExclusiveOption(Option): " NOTE: This argument is mutually exclusive with " " arguments: [" + ex_str + "]." ) - super(MutuallyExclusiveOption, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def handle_parse_result(self, ctx, opts, args): if self.mutually_exclusive.intersection(opts) and self.name in opts: @@ -35,4 +35,4 @@ class MutuallyExclusiveOption(Option): "arguments `{}`.".format(self.name, ", ".join(self.mutually_exclusive)) ) - return super(MutuallyExclusiveOption, self).handle_parse_result(ctx, opts, args) + return super().handle_parse_result(ctx, opts, args) diff --git a/silkaj/commands.py b/silkaj/commands.py index b0647a429fd7c5aedfad48cdbb76e2c8b487e4b9..9f07a5e67571a9d22569f7b34efe1f72127fe3bc 100644 --- a/silkaj/commands.py +++ b/silkaj/commands.py @@ -80,7 +80,7 @@ def power(nbr, pow=0): while nbr >= 10: nbr /= 10 pow += 1 - return "{0:.1f} × 10^{1}".format(nbr, pow) + return f"{nbr:.1f} × 10^{pow}" @command( @@ -100,11 +100,11 @@ async def difficulties(): await client.close() except (aiohttp.WSServerHandshakeError, ValueError) as e: - print("Websocket block {0} : {1}".format(type(e).__name__, str(e))) + print(f"Websocket block {type(e).__name__} : {str(e)}") except (aiohttp.ClientError, gaierror, TimeoutError) as e: - print("{0} : {1}".format(str(e), BMAS_ENDPOINT)) + print(f"{str(e)} : {BMAS_ENDPOINT}") except jsonschema.ValidationError as e: - print("{:}:{:}".format(str(e.__class__.__name__), str(e))) + print(f"{str(e.__class__.__name__)}:{str(e)}") def display_diffi(current, diffi): @@ -120,9 +120,9 @@ def display_diffi(current, diffi): d["Σ diffi"] = d.pop("level") system("cls||clear") print( - "Current block: n°{0}, generated on {1}\n\ -Generation of next block n°{2} possible by at least {3}/{4} members\n\ -Common Proof-of-Work difficulty level: {5}, hash starting with `{6}`\n{7}".format( + "Current block: n°{}, generated on {}\n\ +Generation of next block n°{} possible by at least {}/{} members\n\ +Common Proof-of-Work difficulty level: {}, hash starting with `{}`\n{}".format( current["number"], from_timestamp(current["time"], tz="local").format(ALL), diffi["block"], @@ -182,7 +182,7 @@ async def list_blocks(number, detailed): await sleep(ASYNC_SLEEP) await client.close() print( - "Last {0} blocks from n°{1} to n°{2}".format( + "Last {} blocks from n°{} to n°{}".format( number, current_nbr - number + 1, current_nbr ), end=" ", @@ -213,7 +213,7 @@ async def list_blocks(number, detailed): issued["percent"] = issued["blocks"] / number * 100 sorted_list = sorted(list_issued, key=itemgetter("blocks"), reverse=True) print( - "from {0} issuers\n{1}".format( + "from {} issuers\n{}".format( len(list_issued), tabulate( sorted_list, @@ -237,7 +237,7 @@ async def argos_info(): if ep["port"] == "443": href = "href=https://%s/" % ep["domain"] else: - href = "href=http://%s:%s/" % (ep["domain"], ep["port"]) + href = "href=http://{}:{}/".format(ep["domain"], ep["port"]) current_time = from_timestamp(head_block["time"], tz="local") mediantime = from_timestamp(head_block["medianTime"], tz="local") print( diff --git a/silkaj/crypto_tools.py b/silkaj/crypto_tools.py index 727d54c05253b9ebff8e79485dba4a91069bf25b..60ae6e54ac3c77584828c011373f498bba535055 100644 --- a/silkaj/crypto_tools.py +++ b/silkaj/crypto_tools.py @@ -21,10 +21,10 @@ import base58 from silkaj.constants import PUBKEY_PATTERN from silkaj.tools import message_exit -PUBKEY_DELIMITED_PATTERN = "^{0}$".format(PUBKEY_PATTERN) +PUBKEY_DELIMITED_PATTERN = f"^{PUBKEY_PATTERN}$" CHECKSUM_SIZE = 3 CHECKSUM_PATTERN = f"[1-9A-HJ-NP-Za-km-z]{{{CHECKSUM_SIZE}}}" -PUBKEY_CHECKSUM_PATTERN = "^{0}:{1}$".format(PUBKEY_PATTERN, CHECKSUM_PATTERN) +PUBKEY_CHECKSUM_PATTERN = f"^{PUBKEY_PATTERN}:{CHECKSUM_PATTERN}$" def is_pubkey_and_check(pubkey): diff --git a/silkaj/membership.py b/silkaj/membership.py index 225dd46307f845afda17b0bda0859f7f0665e885..e650ee9b56f80c4b3eed89e32862aeacbb455afd 100644 --- a/silkaj/membership.py +++ b/silkaj/membership.py @@ -89,7 +89,7 @@ async def send_membership(ctx): if response.status == 200: print("Membership successfully sent") else: - print("Error while publishing membership: {0}".format(await response.text())) + print(f"Error while publishing membership: {await response.text()}") logging.debug(await response.text()) await client.close() diff --git a/silkaj/money.py b/silkaj/money.py index 4a291f762663d528e5a8c95d934f17476333a85e..86bc4b308dc4147322dcb0e5476c2a3c70a513cb 100644 --- a/silkaj/money.py +++ b/silkaj/money.py @@ -108,7 +108,7 @@ async def show_amount_from_pubkey(label, inputs_balance): display.append( [ "Total relative to M/N", - "{0} x M/N".format(round(totalAmountInput / average, 2)), + f"{round(totalAmountInput / average, 2)} x M/N", ] ) echo(tabulate(display, tablefmt="fancy_grid")) @@ -185,7 +185,7 @@ async def get_sources(pubkey): return listinput, amount -class UDValue(object): +class UDValue: __instance = None def __new__(cls): diff --git a/silkaj/network_tools.py b/silkaj/network_tools.py index d7d583665133422e3788a8f08841f02c883ff6b7..c2f6fe42ae24e2101e0a39adb19a0131e14d29a3 100644 --- a/silkaj/network_tools.py +++ b/silkaj/network_tools.py @@ -30,7 +30,7 @@ def singleton(class_): @singleton -class EndPoint(object): +class EndPoint: def __init__(self): ep = dict() try: @@ -60,6 +60,6 @@ class EndPoint(object): @singleton -class ClientInstance(object): +class ClientInstance: def __init__(self): self.client = Client(EndPoint().BMA_ENDPOINT) diff --git a/silkaj/tools.py b/silkaj/tools.py index 887ed5f8961daf79ecc1c7648fd257c68c905619..78d19a3ef9ecd28185e3ad26ee121e9d784c4af9 100644 --- a/silkaj/tools.py +++ b/silkaj/tools.py @@ -21,7 +21,7 @@ from silkaj.blockchain_tools import BlockchainParams from silkaj.constants import FAILURE_EXIT_STATUS, G1_SYMBOL, GTEST_SYMBOL -class CurrencySymbol(object): +class CurrencySymbol: __instance = None def __new__(cls): diff --git a/silkaj/tx.py b/silkaj/tx.py index 5270f8fcc792ab50709013c8fc51719250be8a0b..ce294fed97dbf999c779b52557c87c342f7e0f42 100644 --- a/silkaj/tx.py +++ b/silkaj/tx.py @@ -60,7 +60,7 @@ NBR_ISSUERS = 1 "-a", multiple=True, type=click.FloatRange(MINIMAL_ABSOLUTE_TX_AMOUNT), - help="Quantitative amount(s):\n-a <amount>\nMinimum amount is {0}".format( + help="Quantitative amount(s):\n-a <amount>\nMinimum amount is {}".format( MINIMAL_ABSOLUTE_TX_AMOUNT ), cls=cli_tools.MutuallyExclusiveOption, @@ -211,7 +211,7 @@ def compute_amounts(amounts, multiplicator): if (multiplicator != CENT_MULT_TO_UNIT) and ( computed_amount < (MINIMAL_ABSOLUTE_TX_AMOUNT * CENT_MULT_TO_UNIT) ): - tools.message_exit("Error: amount {0} is too low.".format(amount)) + tools.message_exit(f"Error: amount {amount} is too low.") amounts_list.append(round(computed_amount)) return amounts_list @@ -229,7 +229,7 @@ def check_transaction_values( # we check output numbers and leave one line for the backchange. if len(outputAddresses) > (MAX_OUTPUTS - 1): tools.message_exit( - "Error : there should be less than {0} outputs.".format(MAX_OUTPUTS - 1) + f"Error : there should be less than {MAX_OUTPUTS - 1} outputs." ) for i, outputAddress in enumerate(outputAddresses): if ct.check_pubkey_format(outputAddress): @@ -421,7 +421,7 @@ async def generate_and_send_transaction( print("Transaction successfully sent.") else: tools.message_exit( - "Error while publishing transaction: {0}".format(await response.text()) + f"Error while publishing transaction: {await response.text()}" ) @@ -508,7 +508,7 @@ def generate_output(listoutput, unitbase, rest, recipient_address): OutputSource( amount=str(outputAmount), base=unitbase, - condition="SIG({0})".format(recipient_address), + condition=f"SIG({recipient_address})", ) ) unitbase = unitbase - 1 diff --git a/silkaj/tx_history.py b/silkaj/tx_history.py index c9f1554d1d50737f9b3782e1ab271e141f84c582..b661acdfc1fd5c36a38185ec3ad84d256f2ac974 100644 --- a/silkaj/tx_history.py +++ b/silkaj/tx_history.py @@ -122,8 +122,8 @@ async def generate_table( table_titles = [ "Date", "Issuers/Recipients", - "Amounts {}".format(currency_symbol), - "Amounts UD{}".format(currency_symbol), + f"Amounts {currency_symbol}", + f"Amounts UD{currency_symbol}", "Comment", ] txs_table.insert(0, table_titles) @@ -151,7 +151,7 @@ async def parse_received_tx( for received_tx in received_txs: tx_list = list() tx_list.append(from_timestamp(received_tx.time, tz="local").format(ALL_DIGITAL)) - tx_list.append(str()) + tx_list.append("") for i, issuer in enumerate(received_tx.issuers): tx_list[1] += prefix(None, None, i) + assign_idty_from_pubkey( issuer, identities, full_pubkey @@ -190,9 +190,9 @@ async def parse_sent_tx(sent_txs_table, sent_txs, pubkey, ud_value, uids, full_p amounts = str(total_amount / 100) amounts_ud = str(round(total_amount / ud_value, 2)) else: - tx_list.append(str()) - amounts = str() - amounts_ud = str() + tx_list.append("") + amounts = "" + amounts_ud = "" for i, output in enumerate(outputs): if output_available(output.condition, ne, pubkey): @@ -252,7 +252,7 @@ def assign_idty_from_pubkey(pubkey, identities, full_pubkey): idty = display_pubkey_and_checksum(pubkey, short=not full_pubkey) for identity in identities: if pubkey == identity["pubkey"]: - idty = "{0} - {1}".format( + idty = "{} - {}".format( identity["uid"], display_pubkey_and_checksum(pubkey, short=not full_pubkey), ) diff --git a/silkaj/wot.py b/silkaj/wot.py index 70c556a65f7c913cdf96637dbb971fc9d85e67d3..41a2a18e6d862c591edd002216eb2dbadb48bb8f 100644 --- a/silkaj/wot.py +++ b/silkaj/wot.py @@ -86,7 +86,7 @@ async def received_sent_certifications(uid_pubkey): ) = get_sent_certifications(signed, time_first_block, params) nbr_sent_certs = len(certifications["sent"]) if "sent" in certifications else 0 print( - "{0} ({1}) from block #{2}\nreceived {3} and sent {4}/{5} certifications:\n{6}\n{7}\n".format( + "{} ({}) from block #{}\nreceived {} and sent {}/{} certifications:\n{}\n{}\n".format( identity["uid"], display_pubkey_and_checksum(pubkey, True), identity["meta"]["timestamp"][:15] + "…", diff --git a/tests/test_unit_tx.py b/tests/test_unit_tx.py index e9052a24d1dacb11a9d3272707a16f9963f61325..a60d1f8ff1085c60dd184e26de3afcd7cb4491ad 100644 --- a/tests/test_unit_tx.py +++ b/tests/test_unit_tx.py @@ -192,7 +192,7 @@ def test_compute_amounts_errors(capsys): trial[1], ) assert pytest_exit.type == SystemExit - expected_error = "Error: amount {0} is too low.\n".format(trial[0][0]) + expected_error = f"Error: amount {trial[0][0]} is too low.\n" assert capsys.readouterr().out == expected_error @@ -1288,10 +1288,10 @@ async def test_generate_and_send_transaction( assert display.find("Generate Change Transaction") != -1 else: assert display.find("Generate Transaction:") != -1 - assert display.find(" - From: {0}".format(issuers)) != -1 + assert display.find(f" - From: {issuers}") != -1 for tx_amount, outputAddress in zip(tx_amounts, outputAddresses): assert display.find( - " - To: {0}\n - Amount: {1}".format( + " - To: {}\n - Amount: {}".format( outputAddress, tx_amount / 100 ) ) diff --git a/tests/test_verify_blocks.py b/tests/test_verify_blocks.py index 03f381e23e1ccd265337a98d687fad982ddcf1e7..2bff53a7e7f6c3c6add76eb72dc6857405c21cf4 100644 --- a/tests/test_verify_blocks.py +++ b/tests/test_verify_blocks.py @@ -79,7 +79,7 @@ def test_verify_blocks_signatures(from_block, to_block, monkeypatch): assert result.exit_code == SUCCESS_EXIT_STATUS if to_block == 0: to_block = HEAD_BLOCK - expected = "Within {0}-{1} range, ".format(from_block, to_block) + expected = f"Within {from_block}-{to_block} range, " if from_block == 1 or from_block == HEAD_BLOCK - 1: expected += "no blocks with a wrong signature." else: @@ -155,7 +155,7 @@ def test_verify_block_signature(signature, block_raw): [(0, 5, []), (100, 500, [53]), (470, 2341, [243, 453])], ) def test_display_result(from_block, to_block, invalid_blocks_signatures, capsys): - expected = "Within {0}-{1} range, ".format(from_block, to_block) + expected = f"Within {from_block}-{to_block} range, " if invalid_blocks_signatures: expected += "blocks with a wrong signature: " expected += " ".join(str(n) for n in invalid_blocks_signatures)