Skip to content
Snippets Groups Projects
Commit 105e9a32 authored by Moul's avatar Moul
Browse files

[mod] #146: examples: Use f-string

Change format() and "%" formats to f-string format
Strings cleanups
parent 476f5e71
No related branches found
No related tags found
1 merge request!166#146: Use f-string
Pipeline #13808 waiting for manual action
Showing
with 29 additions and 59 deletions
......@@ -31,7 +31,7 @@ def create_public_key():
key = SigningKey.from_credentials(salt, password)
# Display your public key
print("Public key for your credentials: %s" % key.pubkey)
print(f"Public key for your credentials: {key.pubkey}")
if __name__ == "__main__":
......
......@@ -70,7 +70,7 @@ def listen_ws2p():
# HANDSHAKE #######################################################
try:
# Resolve handshake
print("Handshake...")
print("Handshake")
handshake(ws, signing_key, CURRENCY)
except jsonschema.ValidationError as exception:
print(exception.message)
......@@ -83,7 +83,7 @@ def listen_ws2p():
loop = True
# Iterate on each message received...
while loop:
print("Waiting message, press CTRL-C to stop...")
print("Waiting message, press CTRL-C to stop")
# Wait and capture next message
data = ws.receive_json()
print("Message received:")
......
......@@ -30,11 +30,7 @@ def load_cleartext_ascii_armor_message():
with open(CLEARTEXT_AA_MESSAGE_PATH) as file_handler:
ascii_armor_block = file_handler.read()
print(
"Cleartext Ascii Armor Message loaded from file ./{}".format(
CLEARTEXT_AA_MESSAGE_PATH
)
)
print(f"Cleartext Ascii Armor Message loaded from file {CLEARTEXT_AA_MESSAGE_PATH}")
result = AsciiArmor.parse(ascii_armor_block, None, [pubkeyBase58])
print(
......
......@@ -41,12 +41,7 @@ def load_encrypted_ascii_armor_message():
with open(ENCRYPTED_AA_MESSAGE_PATH) as file_handler:
ascii_armor_block = file_handler.read()
print(
"Encrypted Ascii Armor Message loaded from file {}".format(
ENCRYPTED_AA_MESSAGE_PATH
)
)
print(f"Encrypted Ascii Armor Message loaded from file {ENCRYPTED_AA_MESSAGE_PATH}")
print(AsciiArmor.parse(ascii_armor_block, signing_key, [pubkeyBase58]))
......
......@@ -28,9 +28,6 @@ BMAS_ENDPOINT = "BMAS g1-test.duniter.org 443"
def request_available_nodes():
"""
Main code
"""
# Create Client from endpoint string in Duniter format
client = Client(BMAS_ENDPOINT)
......
......@@ -40,13 +40,9 @@ async def coroutine(function, *args, **kwargs):
async def request_data_async():
"""
Main code (asynchronous requests)
You can send one millions request with aiohttp:
https://pawelmhm.github.io/asyncio/python/aiohttp/2016/04/22/asyncio-aiohttp.html
But don't do that on one server, it's DDOS!
"""
# Create Client from endpoint string in Duniter format
client = Client(BMAS_ENDPOINT)
......
......@@ -54,10 +54,11 @@ def request_data_elasticsearch():
# prompt entry
pubkey = input("\nEnter a public key to get the user profile: ")
pubkey = pubkey.strip(" \n")
# Get the profil of a public key (direct REST GET request)
print(f"\nGET user/profile/{pubkey}/_source:")
response = client.get("user/profile/{}/_source".format(pubkey.strip(" \n")))
response = client.get(f"user/profile/{pubkey}/_source")
print(response)
......
......@@ -47,7 +47,7 @@ def request_web_socket_block():
loop = True
# Iterate on each message received...
while loop:
print("Waiting message...")
print("Waiting message")
# Wait and capture next message
data = ws.receive_json()
jsonschema.validate(data, bma.ws.WS_BLOCK_SCHEMA)
......
......@@ -68,8 +68,7 @@ def save_and_load_private_key_file():
# check public key from file
print(
"Public key %s loaded from file %s"
% (loaded_signer.pubkey, PRIVATE_KEYS_FILE_PATH)
f"Public key {loaded_signer.pubkey} loaded from file {PRIVATE_KEYS_FILE_PATH}"
)
......
......@@ -63,8 +63,7 @@ def save_and_load_private_key_file_ewif():
# document saved
print(
"Private key for public key %s saved in %s"
% (signer.pubkey, PRIVATE_KEY_FILE_PATH)
f"Private key for public key {signer.pubkey} saved in {PRIVATE_KEY_FILE_PATH}"
)
try:
......@@ -75,8 +74,7 @@ def save_and_load_private_key_file_ewif():
# check public key from file
print(
"Public key %s loaded from file %s"
% (loaded_signer.pubkey, PRIVATE_KEY_FILE_PATH)
f"Public key {loaded_signer.pubkey} loaded from file {PRIVATE_KEY_FILE_PATH}"
)
except OSError as error:
......
......@@ -60,8 +60,7 @@ def save_and_load_private_key_file_pubsec():
# document saved
print(
"Private key for public key %s saved in %s"
% (signer.pubkey, PRIVATE_KEY_FILE_PATH)
f"Private key for public key {signer.pubkey} saved in {PRIVATE_KEY_FILE_PATH}"
)
try:
......@@ -70,8 +69,7 @@ def save_and_load_private_key_file_pubsec():
# check public key from file
print(
"Public key %s loaded from file %s"
% (loaded_signer.pubkey, PRIVATE_KEY_FILE_PATH)
f"Public key {loaded_signer.pubkey} loaded from file {PRIVATE_KEY_FILE_PATH}"
)
except OSError as error:
......
......@@ -60,8 +60,7 @@ def save_and_load_private_key_file_wif():
# document saved
print(
"Private key for public key %s saved in %s"
% (signer.pubkey, PRIVATE_KEY_FILE_PATH)
f"Private key for public key {signer.pubkey} saved in {PRIVATE_KEY_FILE_PATH}"
)
try:
......@@ -72,8 +71,7 @@ def save_and_load_private_key_file_wif():
# check public key from file
print(
"Public key %s loaded from file %s"
% (loaded_signer.pubkey, PRIVATE_KEY_FILE_PATH)
f"Public key {loaded_signer.pubkey} loaded from file {PRIVATE_KEY_FILE_PATH}"
)
except OSError as error:
......
......@@ -37,7 +37,7 @@ def save_binary_encrypted_message():
with open(ENCRYPTED_MESSAGE_FILENAME, "wb") as file_handler:
file_handler.write(encrypted_message)
print(f"Encrypted message saved in file ./{ENCRYPTED_MESSAGE_FILENAME}")
print(f"Encrypted message saved in file {ENCRYPTED_MESSAGE_FILENAME}")
if __name__ == "__main__":
......
......@@ -37,7 +37,7 @@ def save_binary_signed_message():
key = SigningKey.from_credentials(salt, password)
# Display your public key
print("Public key for your credentials: %s" % key.pubkey)
print(f"Public key for your credentials: {key.pubkey}")
message = input("Enter your message: ")
......@@ -55,7 +55,7 @@ def save_binary_signed_message():
with open(SIGNED_MESSAGE_FILENAME, "wb") as file_handler:
file_handler.write(signed_message)
print(f"Signed message saved in file ./{SIGNED_MESSAGE_FILENAME}")
print(f"Signed message saved in file {SIGNED_MESSAGE_FILENAME}")
if __name__ == "__main__":
......
......@@ -42,7 +42,7 @@ def save_cleartext_ascii_armor_message():
print(f"Message signed by puplic key : {signing_key.pubkey}")
comment = f"generated by Duniterpy {__version__}"
comment = f"Generated by DuniterPy {__version__}"
# Dash escape the message and sign it
aa_cleartext_message = AsciiArmor.create(
message, None, [signing_key], None, signatures_comment=comment
......@@ -52,11 +52,7 @@ def save_cleartext_ascii_armor_message():
with open(CLEARTEXT_AA_MESSAGE_PATH, "w") as file_handler:
file_handler.write(aa_cleartext_message)
print(
"Cleartext Ascii Armor Message saved in file ./{}".format(
CLEARTEXT_AA_MESSAGE_PATH
)
)
print(f"Cleartext Ascii Armor Message saved in file {CLEARTEXT_AA_MESSAGE_PATH}")
if __name__ == "__main__":
......
......@@ -43,7 +43,7 @@ def save_encrypted_ascii_armor_message():
print(f"Message signed by puplic key: {signing_key.pubkey}")
comment = f"generated by Duniterpy {__version__}"
comment = f"Generated by DuniterPy {__version__}"
# Encrypt the message, only the recipient secret key will be able to decrypt the message
encrypted_message = AsciiArmor.create(
message,
......@@ -57,11 +57,7 @@ def save_encrypted_ascii_armor_message():
with open(ENCRYPTED_AA_MESSAGE_PATH, "w") as file_handler:
file_handler.write(encrypted_message)
print(
"Encrypted Ascii Armor Message saved in file {}".format(
ENCRYPTED_AA_MESSAGE_PATH
)
)
print(f"Encrypted Ascii Armor Message saved in file {ENCRYPTED_AA_MESSAGE_PATH}")
if __name__ == "__main__":
......
......@@ -134,7 +134,7 @@ def save_revoke_document():
fp.write(revocation_signed_raw_document)
# document saved
print("Revocation document saved in %s" % REVOCATION_DOCUMENT_FILE_PATH)
print(f"Revocation document saved in {REVOCATION_DOCUMENT_FILE_PATH}")
if __name__ == "__main__":
......
......@@ -135,7 +135,7 @@ def send_transaction():
response = client(bma.tx.sources, pubkey_from)
if len(response["sources"]) == 0:
print("no sources found for account %s" % pubkey_to)
print(f"no sources found for account {pubkey_to}")
return
# get the first source
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment