import asyncio # We will do something similar to ‹p4_tcp›, but this time we will # use a UNIX socket. UNIX sockets exist in the filesystem and need # to be given a (file)name. Additionally, instead of simply echoing # the text back, we will use Caesar cipher (rotate the characters) # with right shift (the intuitive one) of 13. We will have to # explicitly remove the socket once we are done with it, as it will # stay in the filesystem otherwise. async def handle_client( reader, writer ): pass # print( "server received", ... ) pass # print( "server sending", ... ) async def client( msg, path ): pass # print( "client sending", ... ) pass # print( "client received", ... ) async def unix_rot( path ): pass def test_main() -> None: import sys from io import StringIO import os stdout = sys.stdout out = StringIO() sys.stdout = out path = "./tmp.socket" data = asyncio.run( unix_rot( path ) ) assert data == [ 'uryyb', 'jbeyq' ], data sys.stdout = stdout output_ = out.getvalue() print( output_ ) output = output_.split('\n') assert 'client sending hello' in output[ 0 : 3 ] assert 'client sending world' in output[ 0 : 3 ] assert 'server received hello' in output[ 1 : 3 ] assert 'server sending uryyb' in output assert 'server received world' in output assert 'server sending jbeyq' in output assert not os.path.exists( path ) if __name__ == "__main__": test_main()