Skip to content

Commit

Permalink
Add __str__ and __repr_ for JWS
Browse files Browse the repository at this point in the history
Signed-off-by: Simo Sorce <simo@redhat.com>
  • Loading branch information
simo5 committed May 11, 2022
1 parent 7abf382 commit 0d7d54f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions jwcrypto/jws.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,3 +645,16 @@ def from_jose_token(cls, token):
obj = cls()
obj.deserialize(token)
return obj

def __str__(self):
try:
return self.serialize()
except Exception: # pylint: disable=broad-except
return self.__repr__()

def __repr__(self):
try:
return f'JWS.from_json_token("{self.serialize()}")'
except Exception: # pylint: disable=broad-except
payload = self.objects['payload'].decode('utf-8')
return f'JWS(payload={payload})'

0 comments on commit 0d7d54f

Please sign in to comment.