From ad73122e27e08218c397fbcf9d931082e9a0e249 Mon Sep 17 00:00:00 2001
From: Vincent Texier <vit@free.fr>
Date: Mon, 21 Jun 2021 18:23:31 +0200
Subject: [PATCH] [enh] #95 optimize code

---
 duniterpy/documents/certification.py | 10 +++++-----
 duniterpy/documents/document.py      | 11 ++++++-----
 duniterpy/documents/revocation.py    |  9 ++++-----
 duniterpy/documents/transaction.py   |  2 +-
 4 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/duniterpy/documents/certification.py b/duniterpy/documents/certification.py
index d1a0c12b..b0c93bc5 100644
--- a/duniterpy/documents/certification.py
+++ b/duniterpy/documents/certification.py
@@ -220,14 +220,14 @@ CertTimestamp: {timestamp}
         """
         if not isinstance(self.identity, Identity):
             raise MalformedDocumentError(
-                "Identity is a pubkey or None, can not create raw format"
+                "Identity is not defined or properly defined. Can not create raw format"
             )
         if self.signature is None:
-            raise MalformedDocumentError("Signature is None, can not create raw format")
+            raise MalformedDocumentError(
+                "Signature is not defined, can not create signed raw format"
+            )
 
-        raw = self.raw()
-        signed_raw = raw + self.signature + "\n"
-        return signed_raw
+        return f"{self.raw()}{self.signature}\n"
 
     def inline(self) -> str:
         """
diff --git a/duniterpy/documents/document.py b/duniterpy/documents/document.py
index 22e14651..0d16d797 100644
--- a/duniterpy/documents/document.py
+++ b/duniterpy/documents/document.py
@@ -105,10 +105,11 @@ class Document:
         :return:
         """
         if self.signature is None:
-            raise MalformedDocumentError("Signature is None, can not create raw format")
-        raw = self.raw()
-        signed_raw = raw + self.signature + "\n"
-        return signed_raw
+            raise MalformedDocumentError(
+                "Signature is not defined, can not create signed raw format"
+            )
+
+        return f"{self.raw()}{self.signature}\n"
 
     @property
     def sha_hash(self) -> str:
@@ -128,7 +129,7 @@ class Document:
         :return:
         """
         if self.signature is None:
-            raise Exception("Signature is None, can not check signature")
+            raise Exception("Signature is not defined, can not check signature")
 
         verifying_key = VerifyingKey(pubkey)
 
diff --git a/duniterpy/documents/revocation.py b/duniterpy/documents/revocation.py
index 1b12f71d..0bb43542 100644
--- a/duniterpy/documents/revocation.py
+++ b/duniterpy/documents/revocation.py
@@ -198,7 +198,7 @@ IdtySignature: {signature}
         """
         Sign the current document
 
-        :param key: List of libnacl key instances
+        :param key: Libnacl key instance
         :return:
         """
         if not isinstance(self.identity, Identity):
@@ -215,10 +215,9 @@ IdtySignature: {signature}
         """
         if not isinstance(self.identity, Identity):
             raise MalformedDocumentError(
-                "Identity is a pubkey or None, can not create raw format"
+                "Identity is not defined or properly defined. Can not create raw format"
             )
         if self.signature is None:
             raise MalformedDocumentError("Signature is None, can not create raw format")
-        raw = self.raw()
-        signed_raw = raw + self.signature + "\n"
-        return signed_raw
+
+        return f"{self.raw()}{self.signature}\n"
diff --git a/duniterpy/documents/transaction.py b/duniterpy/documents/transaction.py
index c1a3d6d1..eba7def4 100644
--- a/duniterpy/documents/transaction.py
+++ b/duniterpy/documents/transaction.py
@@ -960,7 +960,7 @@ Currency: {1}
 
     def check_signatures(self, pubkeys: List[str]):
         """
-        Check if the signatures matches pubkeys
+        Check if the signatures matches the pubkeys
 
         :param pubkeys: List of Base58 public keys
 
-- 
GitLab