Skip to content

Commit

Permalink
example: Minor reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
real-or-random committed Dec 18, 2024
1 parent f92973d commit 97ebb30
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions python/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ async def receive(self):
return item


#
# Helper functions
#


def pphex(thing):
"""Pretty print an object with bytes as hex strings"""

def hexlify(thing):
if isinstance(thing, bytes):
return thing.hex()
if isinstance(thing, dict):
return {k: hexlify(v) for k, v in thing.items()}
if hasattr(thing, "_asdict"): # NamedTuple
return hexlify(thing._asdict())
if isinstance(thing, List):
return [hexlify(v) for v in thing]
return thing

pprint.pp(hexlify(thing))


#
# Protocol parties
#
Expand Down Expand Up @@ -269,22 +291,5 @@ def main():
print(recovery_data.hex())


def pphex(thing):
"""Pretty print an object with bytes as hex strings"""

def hexlify(thing):
if isinstance(thing, bytes):
return thing.hex()
if isinstance(thing, dict):
return {k: hexlify(v) for k, v in thing.items()}
if hasattr(thing, "_asdict"): # NamedTuple
return hexlify(thing._asdict())
if isinstance(thing, List):
return [hexlify(v) for v in thing]
return thing

pprint.pp(hexlify(thing))


if __name__ == "__main__":
sys.exit(main())

0 comments on commit 97ebb30

Please sign in to comment.