From 1ad034d1365d9711ae3e56e5b1444f627ab98627 Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Fri, 6 Aug 2021 20:42:30 +0200 Subject: [PATCH] [mod] #186: Apply pyupgrade --- duniterpy/api/bma/tx.py | 4 +- duniterpy/api/client.py | 10 +-- duniterpy/api/endpoint.py | 22 +++---- duniterpy/api/errors.py | 2 +- duniterpy/documents/block.py | 66 ++++++++----------- duniterpy/documents/block_id.py | 8 +-- duniterpy/documents/certification.py | 12 ++-- duniterpy/documents/document.py | 6 +- duniterpy/documents/identity.py | 30 +++------ duniterpy/documents/membership.py | 30 ++++----- duniterpy/documents/peer.py | 18 ++--- duniterpy/documents/revocation.py | 14 ++-- duniterpy/documents/transaction.py | 56 ++++++++-------- duniterpy/documents/ws2p/heads.py | 4 +- duniterpy/grammars/output.py | 16 ++--- duniterpy/key/ascii_armor.py | 10 +-- duniterpy/key/crc_pubkey.py | 8 +-- duniterpy/key/signing_key.py | 14 ++-- examples/listen_ws2p.py | 2 +- .../load_cleartext_ascii_armor_message.py | 4 +- examples/load_credentials_file.py | 2 +- .../load_encrypted_ascii_armor_message.py | 4 +- examples/load_scuttlebutt_file.py | 2 +- examples/request_data_elasticsearch.py | 4 +- examples/request_web_socket_block.py | 2 +- examples/request_ws2p.py | 2 +- examples/save_and_load_private_key_file.py | 4 +- .../save_and_load_private_key_file_ewif.py | 2 +- .../save_and_load_private_key_file_pubsec.py | 2 +- .../save_and_load_private_key_file_wif.py | 2 +- examples/save_binary_encrypted_message.py | 2 +- examples/save_binary_signed_message.py | 2 +- .../save_cleartext_ascii_armor_message.py | 6 +- .../save_encrypted_ascii_armor_message.py | 6 +- examples/save_revoke_document.py | 2 +- examples/send_certification.py | 2 +- examples/send_transaction.py | 2 +- tests/key/test_signing_key.py | 2 +- 38 files changed, 162 insertions(+), 224 deletions(-) diff --git a/duniterpy/api/bma/tx.py b/duniterpy/api/bma/tx.py index b46cf62c..17fe68ca 100644 --- a/duniterpy/api/bma/tx.py +++ b/duniterpy/api/bma/tx.py @@ -181,7 +181,7 @@ def blocks(client: Client, pubkey: str, start: int, end: int) -> dict: :return: """ return client.get( - MODULE + "/history/%s/blocks/%s/%s" % (pubkey, start, end), + MODULE + f"/history/{pubkey}/blocks/{start}/{end}", schema=HISTORY_SCHEMA, ) @@ -197,5 +197,5 @@ def times(client: Client, pubkey: str, start: int, end: int) -> dict: :return: """ return client.get( - MODULE + "/history/%s/times/%s/%s" % (pubkey, start, end), schema=HISTORY_SCHEMA + MODULE + f"/history/{pubkey}/times/{start}/{end}", schema=HISTORY_SCHEMA ) diff --git a/duniterpy/api/client.py b/duniterpy/api/client.py index fbffc341..f0264c02 100644 --- a/duniterpy/api/client.py +++ b/duniterpy/api/client.py @@ -70,9 +70,7 @@ def parse_error(text: str) -> dict: data = json.loads(text) jsonschema.validate(data, ERROR_SCHEMA) except (TypeError, json.decoder.JSONDecodeError) as e: - raise jsonschema.ValidationError( - "Could not parse json : {0}".format(str(e)) - ) from e + raise jsonschema.ValidationError(f"Could not parse json : {str(e)}") from e return data @@ -92,7 +90,7 @@ def parse_response(response: str, schema: dict) -> Any: return data except (TypeError, json.decoder.JSONDecodeError) as exception: raise jsonschema.ValidationError( - "Could not parse json : {0}".format(str(exception)) + f"Could not parse json : {str(exception)}" ) from exception @@ -341,9 +339,7 @@ class Client: self.endpoint = _endpoint if isinstance(self.endpoint, endpoint.UnknownEndpoint): - raise NotImplementedError( - "{0} endpoint in not supported".format(self.endpoint.api) - ) + raise NotImplementedError(f"{self.endpoint.api} endpoint in not supported") self.proxy = proxy diff --git a/duniterpy/api/endpoint.py b/duniterpy/api/endpoint.py index c6f0e077..d82977ba 100644 --- a/duniterpy/api/endpoint.py +++ b/duniterpy/api/endpoint.py @@ -111,7 +111,7 @@ class UnknownEndpoint(Endpoint): """ doc = self.api for p in self.properties: - doc += " {0}".format(p) + doc += f" {p}" return doc def conn_handler(self, proxy: str = None) -> ConnectionHandler: @@ -124,9 +124,7 @@ class UnknownEndpoint(Endpoint): return ConnectionHandler("", "", "", 0, "") def __str__(self) -> str: - return "{0} {1}".format( - self.api, " ".join(["{0}".format(p) for p in self.properties]) - ) + return "{} {}".format(self.api, " ".join([f"{p}" for p in self.properties])) def __eq__(self, other: Any) -> bool: if not isinstance(other, UnknownEndpoint): @@ -185,10 +183,10 @@ class BMAEndpoint(Endpoint): :return: """ return BMAEndpoint.API + "{DNS}{IPv4}{IPv6}{PORT}".format( - DNS=(" {0}".format(self.host) if self.host else ""), - IPv4=(" {0}".format(self.ipv4) if self.ipv4 else ""), - IPv6=(" {0}".format(self.ipv6) if self.ipv6 else ""), - PORT=(" {0}".format(self.port) if self.port else ""), + DNS=(f" {self.host}" if self.host else ""), + IPv4=(f" {self.ipv4}" if self.ipv4 else ""), + IPv6=(f" {self.ipv6}" if self.ipv6 else ""), + PORT=(f" {self.port}" if self.port else ""), ) def conn_handler(self, proxy: str = None) -> ConnectionHandler: @@ -204,7 +202,7 @@ class BMAEndpoint(Endpoint): ) elif self.ipv6: conn_handler = ConnectionHandler( - "http", "ws", "[{0}]".format(self.ipv6), self.port, "", proxy + "http", "ws", f"[{self.ipv6}]", self.port, "", proxy ) else: conn_handler = ConnectionHandler( @@ -301,7 +299,7 @@ class SecuredBMAEndpoint(BMAEndpoint): ) elif self.ipv6: conn_handler = ConnectionHandler( - "https", "wss", "[{0}]".format(self.ipv6), self.port, self.path, proxy + "https", "wss", f"[{self.ipv6}]", self.port, self.path, proxy ) else: conn_handler = ConnectionHandler( @@ -667,7 +665,7 @@ class GVAEndpoint(Endpoint): conn_handler = ConnectionHandler( scheme_http, scheme_ws, - "[{0}]".format(self.ipv6), + f"[{self.ipv6}]", self.port, self.path, proxy, @@ -727,7 +725,7 @@ def endpoint(value: Any) -> Any: if value.startswith(api + " "): result = cls.from_inline(value) else: - raise TypeError("Cannot convert {0} to endpoint".format(value)) + raise TypeError(f"Cannot convert {value} to endpoint") return result diff --git a/duniterpy/api/errors.py b/duniterpy/api/errors.py index 1721292e..e1b6dd5d 100644 --- a/duniterpy/api/errors.py +++ b/duniterpy/api/errors.py @@ -25,7 +25,7 @@ class DuniterError(Exception): :param data: Error informations """ - super().__init__("Error code {0} - {1}".format(data["ucode"], data["message"])) + super().__init__("Error code {} - {}".format(data["ucode"], data["message"])) self.ucode = data["ucode"] self.message = data["message"] diff --git a/duniterpy/documents/block.py b/duniterpy/documents/block.py index 57c31a85..7a298daf 100644 --- a/duniterpy/documents/block.py +++ b/duniterpy/documents/block.py @@ -87,18 +87,12 @@ class Block(Document): re_mediantime = re.compile("MedianTime: ([0-9]+)\n") re_universaldividend = re.compile("UniversalDividend: ([0-9]+)\n") re_unitbase = re.compile("UnitBase: ([0-9]+)\n") - re_issuer = re.compile( - "Issuer: ({pubkey_regex})\n".format(pubkey_regex=PUBKEY_REGEX) - ) + re_issuer = re.compile(f"Issuer: ({PUBKEY_REGEX})\n") re_issuers_frame = re.compile("IssuersFrame: ([0-9]+)\n") re_issuers_frame_var = re.compile("IssuersFrameVar: (0|-?[1-9]\\d{0,18})\n") re_different_issuers_count = re.compile("DifferentIssuersCount: ([0-9]+)\n") - re_previoushash = re.compile( - "PreviousHash: ({block_hash_regex})\n".format(block_hash_regex=BLOCK_HASH_REGEX) - ) - re_previousissuer = re.compile( - "PreviousIssuer: ({pubkey_regex})\n".format(pubkey_regex=PUBKEY_REGEX) - ) + re_previoushash = re.compile(f"PreviousHash: ({BLOCK_HASH_REGEX})\n") + re_previousissuer = re.compile(f"PreviousIssuer: ({PUBKEY_REGEX})\n") re_parameters = re.compile( "Parameters: ([0-9]+\\.[0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):\ ([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+\\.[0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+\\.[0-9]+):\ @@ -111,12 +105,10 @@ class Block(Document): re_leavers = re.compile("Leavers:\n") re_revoked = re.compile("Revoked:\n") re_excluded = re.compile("Excluded:\n") - re_exclusion = re.compile("({pubkey_regex})\n".format(pubkey_regex=PUBKEY_REGEX)) + re_exclusion = re.compile(f"({PUBKEY_REGEX})\n") re_certifications = re.compile("Certifications:\n") re_transactions = re.compile("Transactions:\n") - re_hash = re.compile( - "InnerHash: ({block_hash_regex})\n".format(block_hash_regex=BLOCK_HASH_REGEX) - ) + re_hash = re.compile(f"InnerHash: ({BLOCK_HASH_REGEX})\n") re_nonce = re.compile("Nonce: ([0-9]+)\n") fields_parsers = { @@ -222,7 +214,7 @@ class Block(Document): ) if self.version < documents_versions: raise MalformedDocumentError( - "Block version is too low : {0} < {1}".format( + "Block version is too low : {} < {}".format( self.version, documents_versions ) ) @@ -510,9 +502,7 @@ class Block(Document): tx_lines = "" header_data = Transaction.re_header.match(lines[n]) if header_data is None: - raise MalformedDocumentError( - "Compact transaction ({0})".format(lines[n]) - ) + raise MalformedDocumentError(f"Compact transaction ({lines[n]})") issuers_num = int(header_data.group(2)) inputs_num = int(header_data.group(3)) unlocks_num = int(header_data.group(4)) @@ -597,65 +587,65 @@ MedianTime: {mediantime} mediantime=self.mediantime, ) if self.ud: - doc += "UniversalDividend: {0}\n".format(self.ud) + doc += f"UniversalDividend: {self.ud}\n" - doc += "UnitBase: {0}\n".format(self.unit_base) + doc += f"UnitBase: {self.unit_base}\n" - doc += "Issuer: {0}\n".format(self.issuer) + doc += f"Issuer: {self.issuer}\n" - doc += """IssuersFrame: {0} -IssuersFrameVar: {1} -DifferentIssuersCount: {2} + doc += """IssuersFrame: {} +IssuersFrameVar: {} +DifferentIssuersCount: {} """.format( self.issuers_frame, self.issuers_frame_var, self.different_issuers_count ) if self.number == 0 and self.parameters is not None: str_params = ":".join([str(p) for p in self.parameters]) - doc += "Parameters: {0}\n".format(str_params) + doc += f"Parameters: {str_params}\n" else: - doc += "PreviousHash: {0}\n\ -PreviousIssuer: {1}\n".format( + doc += "PreviousHash: {}\n\ +PreviousIssuer: {}\n".format( self.prev_hash, self.prev_issuer ) - doc += "MembersCount: {0}\n".format(self.members_count) + doc += f"MembersCount: {self.members_count}\n" doc += "Identities:\n" for identity in self.identities: - doc += "{0}\n".format(identity.inline()) + doc += f"{identity.inline()}\n" doc += "Joiners:\n" for joiner in self.joiners: - doc += "{0}\n".format(joiner.inline()) + doc += f"{joiner.inline()}\n" doc += "Actives:\n" for active in self.actives: - doc += "{0}\n".format(active.inline()) + doc += f"{active.inline()}\n" doc += "Leavers:\n" for leaver in self.leavers: - doc += "{0}\n".format(leaver.inline()) + doc += f"{leaver.inline()}\n" doc += "Revoked:\n" for revokation in self.revoked: - doc += "{0}\n".format(revokation.inline()) + doc += f"{revokation.inline()}\n" doc += "Excluded:\n" for exclude in self.excluded: - doc += "{0}\n".format(exclude) + doc += f"{exclude}\n" doc += "Certifications:\n" for cert in self.certifications: - doc += "{0}\n".format(cert.inline()) + doc += f"{cert.inline()}\n" doc += "Transactions:\n" for transaction in self.transactions: - doc += "{0}".format(transaction.compact()) + doc += f"{transaction.compact()}" - doc += "InnerHash: {0}\n".format(self.inner_hash) + doc += f"InnerHash: {self.inner_hash}\n" - doc += "Nonce: {0}\n".format(self.nonce) + doc += f"Nonce: {self.nonce}\n" return doc @@ -734,7 +724,7 @@ Nonce: {nonce} if self.signature is None: raise Exception("Signature is None, can not verify signature") - content_to_verify = "InnerHash: {0}\nNonce: {1}\n".format( + content_to_verify = "InnerHash: {}\nNonce: {}\n".format( self.inner_hash, self.nonce ) diff --git a/duniterpy/documents/block_id.py b/duniterpy/documents/block_id.py index eebee167..2791f56c 100644 --- a/duniterpy/documents/block_id.py +++ b/duniterpy/documents/block_id.py @@ -33,9 +33,7 @@ class BlockID: block_number_regex=BLOCK_NUMBER_REGEX, block_hash_regex=BLOCK_HASH_REGEX ) ) - re_hash = re.compile( - "({block_hash_regex})".format(block_hash_regex=BLOCK_HASH_REGEX) - ) + re_hash = re.compile(f"({BLOCK_HASH_REGEX})") def __init__(self, number: int, sha_hash: str) -> None: assert type(number) is int @@ -68,7 +66,7 @@ class BlockID: return cls(number, sha_hash) def __str__(self) -> str: - return "{0}-{1}".format(self.number, self.sha_hash) + return f"{self.number}-{self.sha_hash}" def __eq__(self, other: object) -> bool: if not isinstance(other, BlockID): @@ -116,6 +114,6 @@ def get_block_id(value: Union[str, BlockID, None]) -> BlockID: elif value is None: result = BlockID.empty() else: - raise TypeError("Cannot convert {0} to BlockID".format(type(value))) + raise TypeError(f"Cannot convert {type(value)} to BlockID") return result diff --git a/duniterpy/documents/certification.py b/duniterpy/documents/certification.py index 8ed73bcb..dfd5225d 100644 --- a/duniterpy/documents/certification.py +++ b/duniterpy/documents/certification.py @@ -49,12 +49,8 @@ class Certification(Document): ) ) re_type = re.compile("Type: (Certification)") - re_issuer = re.compile( - "Issuer: ({pubkey_regex})\n".format(pubkey_regex=PUBKEY_REGEX) - ) - re_cert_block_id = re.compile( - "CertTimestamp: ({block_id_regex})\n".format(block_id_regex=BLOCK_ID_REGEX) - ) + re_issuer = re.compile(f"Issuer: ({PUBKEY_REGEX})\n") + re_cert_block_id = re.compile(f"CertTimestamp: ({BLOCK_ID_REGEX})\n") fields_parsers = { **Document.fields_parsers, @@ -153,7 +149,7 @@ class Certification(Document): """ cert_data = Certification.re_inline.match(inline) if cert_data is None: - raise MalformedDocumentError("Certification ({0})".format(inline)) + raise MalformedDocumentError(f"Certification ({inline})") pubkey_from = cert_data.group(1) pubkey_to = cert_data.group(2) block_number = int(cert_data.group(3)) @@ -235,6 +231,6 @@ CertTimestamp: {block_id} :return: """ - return "{0}:{1}:{2}:{3}".format( + return "{}:{}:{}:{}".format( self.pubkey_from, self.pubkey_to, self.block_id.number, self.signature ) diff --git a/duniterpy/documents/document.py b/duniterpy/documents/document.py index 0d16d797..d81fcf15 100644 --- a/duniterpy/documents/document.py +++ b/duniterpy/documents/document.py @@ -35,7 +35,7 @@ class MalformedDocumentError(Exception): :param field_name: Name of the wrong field """ - super().__init__("Could not parse field {0}".format(field_name)) + super().__init__(f"Could not parse field {field_name}") # required to type hint cls in classmethod @@ -45,9 +45,7 @@ DocumentType = TypeVar("DocumentType", bound="Document") class Document: re_version = re.compile("Version: ([0-9]+)\n") re_currency = re.compile("Currency: ([^\n]+)\n") - re_signature = re.compile( - "({signature_regex})\n".format(signature_regex=SIGNATURE_REGEX) - ) + re_signature = re.compile(f"({SIGNATURE_REGEX})\n") fields_parsers: Dict[str, Pattern] = { "Version": re_version, diff --git a/duniterpy/documents/identity.py b/duniterpy/documents/identity.py index 50d3d572..b473e936 100644 --- a/duniterpy/documents/identity.py +++ b/duniterpy/documents/identity.py @@ -47,30 +47,16 @@ class Identity(Document): ) ) re_type = re.compile("Type: (Identity)") - re_issuer = re.compile( - "Issuer: ({pubkey_regex})\n".format(pubkey_regex=PUBKEY_REGEX) - ) - re_unique_id = re.compile("UniqueID: ({uid_regex})\n".format(uid_regex=UID_REGEX)) + re_issuer = re.compile(f"Issuer: ({PUBKEY_REGEX})\n") + re_unique_id = re.compile(f"UniqueID: ({UID_REGEX})\n") re_uid = re.compile("UID:([^\n]+)\n") - re_meta_ts = re.compile( - "META:TS:({block_id_regex})\n".format(block_id_regex=BLOCK_ID_REGEX) - ) - re_block_id = re.compile( - "Timestamp: ({block_id_regex})\n".format(block_id_regex=BLOCK_ID_REGEX) - ) + re_meta_ts = re.compile(f"META:TS:({BLOCK_ID_REGEX})\n") + re_block_id = re.compile(f"Timestamp: ({BLOCK_ID_REGEX})\n") - re_idty_issuer = re.compile( - "IdtyIssuer: ({pubkey_regex})\n".format(pubkey_regex=PUBKEY_REGEX) - ) - re_idty_unique_id = re.compile( - "IdtyUniqueID: ({uid_regex})\n".format(uid_regex=UID_REGEX) - ) - re_idty_block_id = re.compile( - "IdtyTimestamp: ({block_id_regex})\n".format(block_id_regex=BLOCK_ID_REGEX) - ) - re_idty_signature = re.compile( - "IdtySignature: ({signature_regex})\n".format(signature_regex=SIGNATURE_REGEX) - ) + re_idty_issuer = re.compile(f"IdtyIssuer: ({PUBKEY_REGEX})\n") + re_idty_unique_id = re.compile(f"IdtyUniqueID: ({UID_REGEX})\n") + re_idty_block_id = re.compile(f"IdtyTimestamp: ({BLOCK_ID_REGEX})\n") + re_idty_signature = re.compile(f"IdtySignature: ({SIGNATURE_REGEX})\n") fields_parsers = { **Document.fields_parsers, diff --git a/duniterpy/documents/membership.py b/duniterpy/documents/membership.py index 767fb0b4..f92dad8a 100644 --- a/duniterpy/documents/membership.py +++ b/duniterpy/documents/membership.py @@ -58,17 +58,11 @@ class Membership(Document): ) ) re_type = re.compile("Type: (Membership)") - re_issuer = re.compile( - "Issuer: ({pubkey_regex})\n".format(pubkey_regex=PUBKEY_REGEX) - ) - re_block = re.compile( - "Block: ({block_id_regex})\n".format(block_id_regex=BLOCK_ID_REGEX) - ) + re_issuer = re.compile(f"Issuer: ({PUBKEY_REGEX})\n") + re_block = re.compile(f"Block: ({BLOCK_ID_REGEX})\n") re_membership_type = re.compile("Membership: (IN|OUT)") re_userid = re.compile("UserID: ([^\n]+)\n") - re_certts = re.compile( - "CertTS: ({block_id_regex})\n".format(block_id_regex=BLOCK_ID_REGEX) - ) + re_certts = re.compile(f"CertTS: ({BLOCK_ID_REGEX})\n") fields_parsers = { **Document.fields_parsers, @@ -135,7 +129,7 @@ class Membership(Document): """ data = Membership.re_inline.match(inline) if data is None: - raise MalformedDocumentError("Inline membership ({0})".format(inline)) + raise MalformedDocumentError(f"Inline membership ({inline})") issuer = data.group(1) signature = data.group(2) membership_block_id = BlockID.from_str(data.group(3)) @@ -215,14 +209,14 @@ class Membership(Document): :return: """ - return """Version: {0} + return """Version: {} Type: Membership -Currency: {1} -Issuer: {2} -Block: {3} -Membership: {4} -UserID: {5} -CertTS: {6} +Currency: {} +Issuer: {} +Block: {} +Membership: {} +UserID: {} +CertTS: {} """.format( self.version, self.currency, @@ -238,7 +232,7 @@ CertTS: {6} Return inline string format of the Membership instance :return: """ - return "{0}:{1}:{2}:{3}:{4}".format( + return "{}:{}:{}:{}:{}".format( self.issuer, self.signature, self.membership_block_id, diff --git a/duniterpy/documents/peer.py b/duniterpy/documents/peer.py index c5dae7ab..8431f393 100644 --- a/duniterpy/documents/peer.py +++ b/duniterpy/documents/peer.py @@ -48,12 +48,8 @@ class Peer(Document): """ re_type = re.compile("Type: (Peer)") - re_pubkey = re.compile( - "PublicKey: ({pubkey_regex})\n".format(pubkey_regex=PUBKEY_REGEX) - ) - re_block = re.compile( - "Block: ([0-9]+-{block_hash_regex})\n".format(block_hash_regex=BLOCK_HASH_REGEX) - ) + re_pubkey = re.compile(f"PublicKey: ({PUBKEY_REGEX})\n") + re_block = re.compile(f"Block: ([0-9]+-{BLOCK_HASH_REGEX})\n") re_endpoints = re.compile("(Endpoints:)\n") fields_parsers = { @@ -145,18 +141,18 @@ class Peer(Document): :return: """ - doc = """Version: {0} + doc = """Version: {} Type: Peer -Currency: {1} -PublicKey: {2} -Block: {3} +Currency: {} +PublicKey: {} +Block: {} Endpoints: """.format( self.version, self.currency, self.pubkey, self.block_id ) for _endpoint in self.endpoints: - doc += "{0}\n".format(_endpoint.inline()) + doc += f"{_endpoint.inline()}\n" return doc diff --git a/duniterpy/documents/revocation.py b/duniterpy/documents/revocation.py index 44aa8bfa..70d2bdd4 100644 --- a/duniterpy/documents/revocation.py +++ b/duniterpy/documents/revocation.py @@ -45,16 +45,10 @@ class Revocation(Document): ) re_type = re.compile("Type: (Revocation)") - re_issuer = re.compile( - "Issuer: ({pubkey_regex})\n".format(pubkey_regex=PUBKEY_REGEX) - ) + re_issuer = re.compile(f"Issuer: ({PUBKEY_REGEX})\n") re_uniqueid = re.compile("IdtyUniqueID: ([^\n]+)\n") - re_block_id = re.compile( - "IdtyTimestamp: ({block_id_regex})\n".format(block_id_regex=BLOCK_ID_REGEX) - ) - re_idtysignature = re.compile( - "IdtySignature: ({signature_regex})\n".format(signature_regex=SIGNATURE_REGEX) - ) + re_block_id = re.compile(f"IdtyTimestamp: ({BLOCK_ID_REGEX})\n") + re_idtysignature = re.compile(f"IdtySignature: ({SIGNATURE_REGEX})\n") fields_parsers = { **Document.fields_parsers, @@ -165,7 +159,7 @@ class Revocation(Document): :return: """ - return "{0}:{1}".format(self.pubkey, self.signature) + return f"{self.pubkey}:{self.signature}" def raw(self) -> str: """ diff --git a/duniterpy/documents/transaction.py b/duniterpy/documents/transaction.py index ff0a45ea..9220f1da 100644 --- a/duniterpy/documents/transaction.py +++ b/duniterpy/documents/transaction.py @@ -152,7 +152,7 @@ class InputSource: :return: """ - return "{0}:{1}:{2}:{3}:{4}".format( + return "{}:{}:{}:{}:{}".format( self.amount, self.base, self.source, self.origin_id, self.index ) @@ -218,7 +218,7 @@ class OutputSource: :return: """ - return "{0}:{1}:{2}".format( + return "{}:{}:{}".format( self.amount, self.base, pypeg2.compose(self.condition, output.Condition) ) @@ -300,7 +300,7 @@ class SIGParameter: :return: """ - return "SIG({0})".format(self.index) + return f"SIG({self.index})" # required to type hint cls in classmethod @@ -359,7 +359,7 @@ class XHXParameter: :return: """ - return "XHX({0})".format(self.integer) + return f"XHX({self.integer})" # required to type hint cls in classmethod @@ -458,7 +458,7 @@ class Unlock: :return: """ - return "{0}:{1}".format( + return "{}:{}".format( self.index, " ".join([str(parameter) for parameter in self.parameters]) ) @@ -506,12 +506,8 @@ class Transaction(Document): re_header = re.compile( "TX:([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([01]):([0-9]+)\n" ) - re_compact_block_id = re.compile( - "({block_id_regex})\n".format(block_id_regex=BLOCK_ID_REGEX) - ) - re_block_id = re.compile( - "Blockstamp: ({block_id_regex})\n".format(block_id_regex=BLOCK_ID_REGEX) - ) + re_compact_block_id = re.compile(f"({BLOCK_ID_REGEX})\n") + re_block_id = re.compile(f"Blockstamp: ({BLOCK_ID_REGEX})\n") re_locktime = re.compile("Locktime: ([0-9]+)\n") re_issuers = re.compile("Issuers:\n") re_inputs = re.compile("Inputs:\n") @@ -519,7 +515,7 @@ class Transaction(Document): re_outputs = re.compile("Outputs:\n") re_compact_comment = re.compile("([^\n]+)\n") re_comment = re.compile("Comment: ([^\n]*)\n") - re_pubkey = re.compile("({pubkey_regex})\n".format(pubkey_regex=PUBKEY_REGEX)) + re_pubkey = re.compile(f"({PUBKEY_REGEX})\n") fields_parsers = { **Document.fields_parsers, @@ -633,7 +629,7 @@ class Transaction(Document): tx_data = tx_data.copy() tx_data["currency"] = currency for data_list in ("issuers", "outputs", "inputs", "unlocks", "signatures"): - tx_data["multiline_{0}".format(data_list)] = "\n".join(tx_data[data_list]) + tx_data[f"multiline_{data_list}"] = "\n".join(tx_data[data_list]) return cls.from_signed_raw( """Version: {version} Type: Transaction @@ -841,35 +837,35 @@ Comment: {comment} :return: """ - doc = """Version: {0} + doc = """Version: {} Type: Transaction -Currency: {1} +Currency: {} """.format( self.version, self.currency ) - doc += "Blockstamp: {0}\n".format(self.block_id) + doc += f"Blockstamp: {self.block_id}\n" - doc += "Locktime: {0}\n".format(self.locktime) + doc += f"Locktime: {self.locktime}\n" doc += "Issuers:\n" for p in self.issuers: - doc += "{0}\n".format(p) + doc += f"{p}\n" doc += "Inputs:\n" for i in self.inputs: - doc += "{0}\n".format(i.inline()) + doc += f"{i.inline()}\n" doc += "Unlocks:\n" for u in self.unlocks: - doc += "{0}\n".format(u.inline()) + doc += f"{u.inline()}\n" doc += "Outputs:\n" for o in self.outputs: - doc += "{0}\n".format(o.inline()) + doc += f"{o.inline()}\n" doc += "Comment: " - doc += "{0}\n".format(self.comment) + doc += f"{self.comment}\n" return doc @@ -887,7 +883,7 @@ Currency: {1} PUBLIC_KEY:AMOUNT ... COMMENT""" - doc = "TX:{0}:{1}:{2}:{3}:{4}:{5}:{6}\n".format( + doc = "TX:{}:{}:{}:{}:{}:{}:{}\n".format( self.version, len(self.issuers), len(self.inputs), @@ -896,20 +892,20 @@ Currency: {1} "1" if self.comment != "" else "0", self.locktime, ) - doc += "{0}\n".format(self.block_id) + doc += f"{self.block_id}\n" for pubkey in self.issuers: - doc += "{0}\n".format(pubkey) + doc += f"{pubkey}\n" for i in self.inputs: - doc += "{0}\n".format(i.inline()) + doc += f"{i.inline()}\n" for u in self.unlocks: - doc += "{0}\n".format(u.inline()) + doc += f"{u.inline()}\n" for o in self.outputs: - doc += "{0}\n".format(o.inline()) + doc += f"{o.inline()}\n" if self.comment != "": - doc += "{0}\n".format(self.comment) + doc += f"{self.comment}\n" for signature in self.signatures: - doc += "{0}\n".format(signature) + doc += f"{signature}\n" return doc diff --git a/duniterpy/documents/ws2p/heads.py b/duniterpy/documents/ws2p/heads.py index fc79f48c..15e83141 100644 --- a/duniterpy/documents/ws2p/heads.py +++ b/duniterpy/documents/ws2p/heads.py @@ -73,7 +73,7 @@ class Head: raise MalformedDocumentError("Head") from AttributeError def __str__(self) -> str: - return "HEAD" if self.version == 0 else "HEAD:{}".format(str(self.version)) + return "HEAD" if self.version == 0 else f"HEAD:{str(self.version)}" @attr.s() @@ -124,7 +124,7 @@ class HeadV0(Head): ), ) ) - return "{0}:{1}".format(str(self.api), ":".join(values)) + return "{}:{}".format(str(self.api), ":".join(values)) def check_signature(self, pubkey: str) -> bool: """ diff --git a/duniterpy/grammars/output.py b/duniterpy/grammars/output.py index 39642772..11bbfa13 100644 --- a/duniterpy/grammars/output.py +++ b/duniterpy/grammars/output.py @@ -101,7 +101,7 @@ class SIG: :param attr_of: Attribute of... :return: """ - return "SIG({0})".format(self.pubkey) + return f"SIG({self.pubkey})" # required to type hint cls in classmethod @@ -160,7 +160,7 @@ class CSV: :param grammar: Grammar :param attr_of: Attribute of... """ - return "CSV({0})".format(self.time) + return f"CSV({self.time})" # required to type hint cls in classmethod @@ -219,7 +219,7 @@ class CLTV: :param grammar: Grammar :param attr_of: Attribute of... """ - return "CLTV({0})".format(self.timestamp) + return f"CLTV({self.timestamp})" # required to type hint cls in classmethod @@ -278,7 +278,7 @@ class XHX: :param grammar: Grammar :param attr_of: Attribute of... """ - return "XHX({0})".format(self.sha_hash) + return f"XHX({self.sha_hash})" # required to type hint cls in classmethod @@ -314,7 +314,7 @@ class Operator(Keyword): :param grammar: Grammar :param attr_of: Attribute of... """ - return "{0}".format(self.name) + return f"{self.name}" # required to type hint cls in classmethod @@ -391,7 +391,7 @@ class Condition: :param attr_of: Attribute of... """ if type(self.left) is Condition: - left = "({0})".format( + left = "({})".format( parser.compose(self.left, grammar=grammar, attr_of=attr_of) ) else: @@ -400,13 +400,13 @@ class Condition: if getattr(self, "op", None): if type(self.right) is Condition: - right = "({0})".format( + right = "({})".format( parser.compose(self.right, grammar=grammar, attr_of=attr_of) ) else: right = parser.compose(self.right, grammar=grammar, attr_of=attr_of) op = parser.compose(self.op, grammar=grammar, attr_of=attr_of) - result = "{0} {1} {2}".format(left, op, right) + result = f"{left} {op} {right}" else: result = left return result diff --git a/duniterpy/key/ascii_armor.py b/duniterpy/key/ascii_armor.py index db031dbd..bd942bd2 100644 --- a/duniterpy/key/ascii_armor.py +++ b/duniterpy/key/ascii_armor.py @@ -171,7 +171,7 @@ class AsciiArmor: :param text: Text to clean up :return: """ - clean_text = str() + clean_text = "" for line in text.splitlines(True): # remove trailing spaces (0x20) and tabs (0x09) @@ -187,7 +187,7 @@ class AsciiArmor: :param text: Text to dash-escape :return: """ - dash_escaped_text = str() + dash_escaped_text = "" for line in text.splitlines(True): # add dash '-' (0x2D) and space ' ' (0x20) as prefix @@ -203,7 +203,7 @@ class AsciiArmor: :param dash_escaped_line: Dash escaped text line :return: """ - text = str() + text = "" regex_dash_escape_prefix = re.compile("^" + DASH_ESCAPE_PREFIX) # if prefixed by a dash escape prefix... if regex_dash_escape_prefix.match(dash_escaped_line): @@ -219,7 +219,7 @@ class AsciiArmor: :return: """ - return "Version: {version}".format(version=VERSION_FIELD_VALUE) + return f"Version: {VERSION_FIELD_VALUE}" @staticmethod def _get_comment_field(comment: str) -> str: @@ -229,7 +229,7 @@ class AsciiArmor: :param comment: Comment text :return: """ - return "Comment: {comment}".format(comment=comment) + return f"Comment: {comment}" @staticmethod def _get_signature_block( diff --git a/duniterpy/key/crc_pubkey.py b/duniterpy/key/crc_pubkey.py index 498e2a15..fdec9b40 100644 --- a/duniterpy/key/crc_pubkey.py +++ b/duniterpy/key/crc_pubkey.py @@ -31,9 +31,7 @@ class CRCPubkey: Class to implement a crc on a pubkey """ - re_crc_pubkey = re.compile( - "({pubkey_regex}):([A-Za-z0-9]{{3}})".format(pubkey_regex=PUBKEY_REGEX) - ) + re_crc_pubkey = re.compile(f"({PUBKEY_REGEX}):([A-Za-z0-9]{{3}})") def __init__(self, pubkey: str, crc: str) -> None: """ @@ -55,7 +53,7 @@ class CRCPubkey: """ data = CRCPubkey.re_crc_pubkey.match(crc_pubkey) if data is None: - raise Exception("Could not parse CRC public key {0}".format(crc_pubkey)) + raise Exception(f"Could not parse CRC public key {crc_pubkey}") pubkey = data.group(1) crc = data.group(2) return cls(pubkey, crc) @@ -89,4 +87,4 @@ class CRCPubkey: Return string representation of instance :return: """ - return "{:}:{:}".format(self.pubkey, self.crc) + return f"{self.pubkey}:{self.crc}" diff --git a/duniterpy/key/signing_key.py b/duniterpy/key/signing_key.py index 2600fce7..84fa05d9 100644 --- a/duniterpy/key/signing_key.py +++ b/duniterpy/key/signing_key.py @@ -89,7 +89,7 @@ class SigningKey(libnacl.sign.Signer): :return: """ # capture credentials from file - with open(path, "r") as fh: + with open(path) as fh: lines = fh.readlines() assert len(lines) > 1 salt = lines[0].strip() @@ -114,7 +114,7 @@ class SigningKey(libnacl.sign.Signer): :param str path: Hexadecimal seed file path """ - with open(path, "r") as fh: + with open(path) as fh: seedhex = fh.read() return SigningKey.from_seedhex(seedhex) @@ -174,7 +174,7 @@ class SigningKey(libnacl.sign.Signer): :param path: Path to WIF file """ - with open(path, "r") as fh: + with open(path) as fh: pubsec_content = fh.read() # line patterns @@ -235,7 +235,7 @@ sec: {signkey}""".format( :param path: Path to WIF of EWIF file :param password: Password needed for EWIF file """ - with open(path, "r") as fh: + with open(path) as fh: wif_content = fh.read() # check data field @@ -278,7 +278,7 @@ sec: {signkey}""".format( :param path: Path to WIF file """ - with open(path, "r") as fh: + with open(path) as fh: wif_content = fh.read() # check data field @@ -356,7 +356,7 @@ Data: {data}""".format( :param path: Path to EWIF file :param password: Password of the encrypted seed """ - with open(path, "r") as fh: + with open(path) as fh: wif_content = fh.read() # check data field @@ -488,7 +488,7 @@ Data: {data}""".format( :param path: Path to Scuttlebutt secret file """ - with open(path, "r") as fh: + with open(path) as fh: ssb_content = fh.read() # check data field diff --git a/examples/listen_ws2p.py b/examples/listen_ws2p.py index d45a8469..b4bf3016 100644 --- a/examples/listen_ws2p.py +++ b/examples/listen_ws2p.py @@ -94,7 +94,7 @@ def listen_ws2p(): print("Connection closed.") except jsonschema.ValidationError as e: - print("{:}:{:}".format(str(e.__class__.__name__), str(e))) + print(f"{str(e.__class__.__name__)}:{str(e)}") if __name__ == "__main__": diff --git a/examples/load_cleartext_ascii_armor_message.py b/examples/load_cleartext_ascii_armor_message.py index 0e607c60..65d6f9a4 100644 --- a/examples/load_cleartext_ascii_armor_message.py +++ b/examples/load_cleartext_ascii_armor_message.py @@ -27,11 +27,11 @@ def load_cleartext_ascii_armor_message(): pubkeyBase58 = input("Enter public key of the message issuer: ") # Load cleartext ascii armor message from a file - with open(CLEARTEXT_AA_MESSAGE_PATH, "r") as file_handler: + with open(CLEARTEXT_AA_MESSAGE_PATH) as file_handler: ascii_armor_block = file_handler.read() print( - "Cleartext Ascii Armor Message loaded from file ./{0}".format( + "Cleartext Ascii Armor Message loaded from file ./{}".format( CLEARTEXT_AA_MESSAGE_PATH ) ) diff --git a/examples/load_credentials_file.py b/examples/load_credentials_file.py index e4dec58f..b20ad93b 100644 --- a/examples/load_credentials_file.py +++ b/examples/load_credentials_file.py @@ -33,7 +33,7 @@ def load_credentials_file(signing_key_instance=None): ) # type: SigningKey # print pubkey - print("Public key from credentials file: {}".format(signing_key_instance.pubkey)) + print(f"Public key from credentials file: {signing_key_instance.pubkey}") if __name__ == "__main__": diff --git a/examples/load_encrypted_ascii_armor_message.py b/examples/load_encrypted_ascii_armor_message.py index e2476084..fbf2eeb3 100644 --- a/examples/load_encrypted_ascii_armor_message.py +++ b/examples/load_encrypted_ascii_armor_message.py @@ -38,11 +38,11 @@ def load_encrypted_ascii_armor_message(): signing_key = SigningKey.from_credentials(salt, password) # Load ascii armor encrypted message from a file - with open(ENCRYPTED_AA_MESSAGE_PATH, "r") as file_handler: + with open(ENCRYPTED_AA_MESSAGE_PATH) as file_handler: ascii_armor_block = file_handler.read() print( - "Encrypted Ascii Armor Message loaded from file {0}".format( + "Encrypted Ascii Armor Message loaded from file {}".format( ENCRYPTED_AA_MESSAGE_PATH ) ) diff --git a/examples/load_scuttlebutt_file.py b/examples/load_scuttlebutt_file.py index bc07090b..43903adb 100644 --- a/examples/load_scuttlebutt_file.py +++ b/examples/load_scuttlebutt_file.py @@ -33,7 +33,7 @@ def load_scuttlebutt_file(signing_key_insance=None): ) # type: SigningKey # print pubkey - print("Public key from scuttlebutt file: {}".format(signing_key_instance.pubkey)) + print(f"Public key from scuttlebutt file: {signing_key_instance.pubkey}") if __name__ == "__main__": diff --git a/examples/request_data_elasticsearch.py b/examples/request_data_elasticsearch.py index 98dcb1dd..17e8ccc9 100644 --- a/examples/request_data_elasticsearch.py +++ b/examples/request_data_elasticsearch.py @@ -56,8 +56,8 @@ def request_data_elasticsearch(): pubkey = input("\nEnter a public key to get the user profile: ") # Get the profil of a public key (direct REST GET request) - print("\nGET user/profile/{0}/_source:".format(pubkey)) - response = client.get("user/profile/{0}/_source".format(pubkey.strip(" \n"))) + print(f"\nGET user/profile/{pubkey}/_source:") + response = client.get("user/profile/{}/_source".format(pubkey.strip(" \n"))) print(response) diff --git a/examples/request_web_socket_block.py b/examples/request_web_socket_block.py index a9df4e01..0c4009f8 100644 --- a/examples/request_web_socket_block.py +++ b/examples/request_web_socket_block.py @@ -55,7 +55,7 @@ def request_web_socket_block(): print(json.dumps(data, indent=2)) except jsonschema.ValidationError as e: - print("{:}:{:}".format(str(e.__class__.__name__), str(e))) + print(f"{str(e.__class__.__name__)}:{str(e)}") if __name__ == "__main__": diff --git a/examples/request_ws2p.py b/examples/request_ws2p.py index d4b22b4c..28280e34 100644 --- a/examples/request_ws2p.py +++ b/examples/request_ws2p.py @@ -162,7 +162,7 @@ def request_ws2p(): print("Response: " + json.dumps(response, indent=2)) except jsonschema.ValidationError as e: - print("{:}:{:}".format(str(e.__class__.__name__), str(e))) + print(f"{str(e.__class__.__name__)}:{str(e)}") if __name__ == "__main__": diff --git a/examples/save_and_load_private_key_file.py b/examples/save_and_load_private_key_file.py index 95adb9f0..f4439222 100644 --- a/examples/save_and_load_private_key_file.py +++ b/examples/save_and_load_private_key_file.py @@ -59,9 +59,7 @@ def save_and_load_private_key_file(): signer.save_private_key(PRIVATE_KEYS_FILE_PATH) # document saved - print( - "Private keys for public key %s saved in %s" % (pubkey, PRIVATE_KEYS_FILE_PATH) - ) + print(f"Private keys for public key {pubkey} saved in {PRIVATE_KEYS_FILE_PATH}") # load private keys from file loaded_signer = SigningKey.from_private_key( diff --git a/examples/save_and_load_private_key_file_ewif.py b/examples/save_and_load_private_key_file_ewif.py index 07e23157..5f2b3d55 100644 --- a/examples/save_and_load_private_key_file_ewif.py +++ b/examples/save_and_load_private_key_file_ewif.py @@ -79,7 +79,7 @@ def save_and_load_private_key_file_ewif(): % (loaded_signer.pubkey, PRIVATE_KEY_FILE_PATH) ) - except IOError as error: + except OSError as error: print(error) return diff --git a/examples/save_and_load_private_key_file_pubsec.py b/examples/save_and_load_private_key_file_pubsec.py index 701f235e..8a11df65 100644 --- a/examples/save_and_load_private_key_file_pubsec.py +++ b/examples/save_and_load_private_key_file_pubsec.py @@ -74,7 +74,7 @@ def save_and_load_private_key_file_pubsec(): % (loaded_signer.pubkey, PRIVATE_KEY_FILE_PATH) ) - except IOError as error: + except OSError as error: print(error) return diff --git a/examples/save_and_load_private_key_file_wif.py b/examples/save_and_load_private_key_file_wif.py index 78c218c0..c3e2147e 100644 --- a/examples/save_and_load_private_key_file_wif.py +++ b/examples/save_and_load_private_key_file_wif.py @@ -76,7 +76,7 @@ def save_and_load_private_key_file_wif(): % (loaded_signer.pubkey, PRIVATE_KEY_FILE_PATH) ) - except IOError as error: + except OSError as error: print(error) return diff --git a/examples/save_binary_encrypted_message.py b/examples/save_binary_encrypted_message.py index 3075d251..a5159ab5 100644 --- a/examples/save_binary_encrypted_message.py +++ b/examples/save_binary_encrypted_message.py @@ -37,7 +37,7 @@ def save_binary_encrypted_message(): with open(ENCRYPTED_MESSAGE_FILENAME, "wb") as file_handler: file_handler.write(encrypted_message) - print("Encrypted message saved in file ./{0}".format(ENCRYPTED_MESSAGE_FILENAME)) + print(f"Encrypted message saved in file ./{ENCRYPTED_MESSAGE_FILENAME}") if __name__ == "__main__": diff --git a/examples/save_binary_signed_message.py b/examples/save_binary_signed_message.py index 37e5b9b8..ae7b5020 100644 --- a/examples/save_binary_signed_message.py +++ b/examples/save_binary_signed_message.py @@ -55,7 +55,7 @@ def save_binary_signed_message(): with open(SIGNED_MESSAGE_FILENAME, "wb") as file_handler: file_handler.write(signed_message) - print("Signed message saved in file ./{0}".format(SIGNED_MESSAGE_FILENAME)) + print(f"Signed message saved in file ./{SIGNED_MESSAGE_FILENAME}") if __name__ == "__main__": diff --git a/examples/save_cleartext_ascii_armor_message.py b/examples/save_cleartext_ascii_armor_message.py index 00f68ec6..8a60fcbd 100644 --- a/examples/save_cleartext_ascii_armor_message.py +++ b/examples/save_cleartext_ascii_armor_message.py @@ -40,9 +40,9 @@ def save_cleartext_ascii_armor_message(): print("Enter your message (Ctrl-D below last line to end):") message = sys.stdin.read() - print("Message signed by puplic key : {pubkey}".format(pubkey=signing_key.pubkey)) + print(f"Message signed by puplic key : {signing_key.pubkey}") - comment = "generated by Duniterpy {0}".format(__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 @@ -53,7 +53,7 @@ def save_cleartext_ascii_armor_message(): file_handler.write(aa_cleartext_message) print( - "Cleartext Ascii Armor Message saved in file ./{0}".format( + "Cleartext Ascii Armor Message saved in file ./{}".format( CLEARTEXT_AA_MESSAGE_PATH ) ) diff --git a/examples/save_encrypted_ascii_armor_message.py b/examples/save_encrypted_ascii_armor_message.py index c464b019..e055fc86 100644 --- a/examples/save_encrypted_ascii_armor_message.py +++ b/examples/save_encrypted_ascii_armor_message.py @@ -41,9 +41,9 @@ def save_encrypted_ascii_armor_message(): # Enter the message message = input("Enter your message: ") - print("Message signed by puplic key : {pubkey}".format(pubkey=signing_key.pubkey)) + print(f"Message signed by puplic key : {signing_key.pubkey}") - comment = "generated by Duniterpy {0}".format(__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, @@ -58,7 +58,7 @@ def save_encrypted_ascii_armor_message(): file_handler.write(encrypted_message) print( - "Encrypted Ascii Armor Message saved in file {0}".format( + "Encrypted Ascii Armor Message saved in file {}".format( ENCRYPTED_AA_MESSAGE_PATH ) ) diff --git a/examples/save_revoke_document.py b/examples/save_revoke_document.py index b34325f6..b66773b8 100644 --- a/examples/save_revoke_document.py +++ b/examples/save_revoke_document.py @@ -120,7 +120,7 @@ def save_revoke_document(): # create our Identity document to sign the revocation document identity = get_identity_document(client, current_block, pubkey) if identity is None: - print("Identity not found for pubkey {0}".format(pubkey)) + print(f"Identity not found for pubkey {pubkey}") # Close client aiohttp session return diff --git a/examples/send_certification.py b/examples/send_certification.py index f9a41b2c..c804028f 100644 --- a/examples/send_certification.py +++ b/examples/send_certification.py @@ -103,7 +103,7 @@ def send_certification(): # create our Identity document to sign the Certification document identity = get_identity_document(client, current_block, pubkey_to) if identity is None: - print("Identity not found for pubkey {0}".format(pubkey_to)) + print(f"Identity not found for pubkey {pubkey_to}") # Close client aiohttp session return diff --git a/examples/send_transaction.py b/examples/send_transaction.py index afa6ab3c..e9c8b53c 100644 --- a/examples/send_transaction.py +++ b/examples/send_transaction.py @@ -85,7 +85,7 @@ def get_transaction_document( OutputSource( amount=source["amount"], base=source["base"], - condition="SIG({0})".format(to_pubkey), + condition=f"SIG({to_pubkey})", ) ] diff --git a/tests/key/test_signing_key.py b/tests/key/test_signing_key.py index 16aed9d0..3bfbb900 100644 --- a/tests/key/test_signing_key.py +++ b/tests/key/test_signing_key.py @@ -99,7 +99,7 @@ class TestSigningKey(unittest.TestCase): # create a dummy credentials file with open(TEST_FILE_PATH, "w") as fh: - fh.write("{}\n{}\n".format(salt, password)) + fh.write(f"{salt}\n{password}\n") # same key from credentials sign_key_test = SigningKey.from_credentials(salt, password) -- GitLab