Skip to content

Commit

Permalink
TODO/tweak to PKey.__repr__
Browse files Browse the repository at this point in the history
  • Loading branch information
bitprophet committed May 25, 2023
1 parent 72898db commit fd06863
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion paramiko/pkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,18 @@ def __init__(self, msg=None, data=None):
"""
pass

# TODO: arguably this might want to be __str__ instead? ehh
# TODO: ditto the interplay between showing class name (currently we just
# say PKey writ large) and algorithm (usually == class name, but not
# always, also sometimes shows certificate-ness)
# TODO: if we do change it, we also want to tweak eg AgentKey, as it
# currently displays agent-ness with a suffix
def __repr__(self):
comment = ""
# Works for AgentKey, may work for others?
if hasattr(self, "comment") and self.comment:
comment = f", comment={self.comment!r}"
return f"{self.__class__.__name__}(alg={self.algorithm_name}, bits={self.get_bits()}, fp={self.fingerprint}{comment})" # noqa
return f"PKey(alg={self.algorithm_name}, bits={self.get_bits()}, fp={self.fingerprint}{comment})" # noqa

# TODO 4.0: just merge into __bytes__ (everywhere)
def asbytes(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def repr_shows_pkey_repr(self):
source = InMemoryPrivateKey("foo", pkey)
assert (
repr(source)
== "InMemoryPrivateKey(pkey=Ed25519Key(alg=ED25519, bits=256, fp=SHA256:J6VESFdD3xSChn8y9PzWzeF+1tl892mOy2TqkMLO4ow))" # noqa
== "InMemoryPrivateKey(pkey=PKey(alg=ED25519, bits=256, fp=SHA256:J6VESFdD3xSChn8y9PzWzeF+1tl892mOy2TqkMLO4ow))" # noqa
)

def repr_appends_agent_flag_when_AgentKey(self):
Expand All @@ -413,7 +413,7 @@ def repr_appends_agent_flag_when_AgentKey(self):
source = InMemoryPrivateKey("foo", pkey)
assert (
repr(source)
== "InMemoryPrivateKey(pkey=AgentKey(alg=ED25519, bits=256, fp=SHA256:J6VESFdD3xSChn8y9PzWzeF+1tl892mOy2TqkMLO4ow)) [agent]" # noqa
== "InMemoryPrivateKey(pkey=PKey(alg=ED25519, bits=256, fp=SHA256:J6VESFdD3xSChn8y9PzWzeF+1tl892mOy2TqkMLO4ow)) [agent]" # noqa
)

class OnDiskPrivateKey_:
Expand Down

0 comments on commit fd06863

Please sign in to comment.