summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHartmut Goebel <h.goebel@crazy-compilers.com>2019-01-19 20:33:02 +0100
committerHartmut Goebel <h.goebel@crazy-compilers.com>2019-01-19 20:33:02 +0100
commitcc1e04b00f7f4f3dc085bcff666548510ef597da (patch)
treed34fbc4037ad5dacc44ba6bbaf81aac617b70e1b
parent602cde1ebff40544c66ae769426825b5fc400167 (diff)
Add '_Key.__repr__()' to eliminate redundant code in subclasses.
-rw-r--r--gnunet/__init__.py7
-rw-r--r--gnunet/crypto.py3
2 files changed, 4 insertions, 6 deletions
diff --git a/gnunet/__init__.py b/gnunet/__init__.py
index 5bae6f0..4ba5bd7 100644
--- a/gnunet/__init__.py
+++ b/gnunet/__init__.py
@@ -28,9 +28,10 @@ class _Key:
def __str__(self):
return strings.data_to_string(self._data)
+ def __repr__(self):
+ cls = self.__class__
+ return "%s.%s(%r)" % (cls.__module__, cls.__name__, str(self))
+
class HashCode(_Key):
__bits__ = 512
-
- def __repr__(self):
- return "gnunet.HashCode('" + str(self) + "')"
diff --git a/gnunet/crypto.py b/gnunet/crypto.py
index 253f46e..5a82c0d 100644
--- a/gnunet/crypto.py
+++ b/gnunet/crypto.py
@@ -4,6 +4,3 @@ import gnunet.strings as strings
class EcdsaPublicKey(_Key):
__bits__ = 256
-
- def __repr__(self):
- return "gnunet.crypto.EcdsaPublicKey('" + str(self) + "')"