<s> import threading <EOL> class PathServer : <EOL> def __init__ ( self , channel ) : <EOL> self . channel = channel <EOL> self . C2P = { } <EOL> self . next_id = <NUM_LIT:0> <EOL> threading . Thread ( target = self . serve ) . start ( ) <EOL> def p2c ( self , path ) : <EOL> id = self . next_id <EOL> self . next_id += <NUM_LIT:1> <EOL> self . C2P [ id ] = path <EOL> return id <EOL> def command_LIST ( self , id , * args ) : <EOL> path = self . C2P [ id ] <EOL> answer = [ ( self . p2c ( p ) , p . basename ) for p in path . listdir ( * args ) ] <EOL> self . channel . send ( answer ) <EOL> def command_DEL ( self , id ) : <EOL> del self . C2P [ id ] <EOL> def command_GET ( self , id , spec ) : <EOL> path = self . C2P [ id ] <EOL> self . channel . send ( path . _getbyspec ( spec ) ) <EOL> def command_READ ( self , id ) : <EOL> path = self . C2P [ id ] <EOL> self . channel . send ( path . read ( ) ) <EOL> def command_JOIN ( self , id , resultid , * args ) : <EOL> path = self . C2P [ id ] <EOL> assert resultid not in self . C2P <EOL> self . C2P [ resultid ] = path . join ( * args ) <EOL> def command_DIRPATH ( self , id , resultid ) : <EOL> path = self . C2P [ id ] <EOL> assert resultid not in self . C2P <EOL> self . C2P [ resultid ] = path . dirpath ( ) <EOL> def serve ( self ) : <EOL> try : <EOL> while <NUM_LIT:1> : <EOL> msg = self . channel . receive ( ) <EOL> meth = getattr ( self , '<STR_LIT>' + msg [ <NUM_LIT:0> ] ) <EOL> meth ( * msg [ <NUM_LIT:1> : ] ) <EOL> except EOFError : <EOL> pass <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import py <EOL> gw = py . execnet . PopenGateway ( ) <EOL> channel = gw . _channelfactory . new ( ) <EOL> srv = PathServer ( channel ) <EOL> c = gw . remote_exec ( """<STR_LIT>""" ) <EOL> c . send ( channel ) <EOL> c . send ( srv . p2c ( py . path . local ( '<STR_LIT>' ) ) ) <EOL> print c . receive ( ) </s>
