<s> import coro <EOL> import coro . http <EOL> import coro . backdoor <EOL> import sys <EOL> W = sys . stderr . write <EOL> class grid_handler : <EOL> def __init__ ( self , w , h ) : <EOL> self . w = w <EOL> self . h = h <EOL> self . grid = [ [ '<STR_LIT:.>' for x in range ( w ) ] for y in range ( h ) ] <EOL> self . pos = [ w / <NUM_LIT:2> , h / <NUM_LIT:2> ] <EOL> self . grid [ self . pos [ <NUM_LIT:1> ] ] [ self . pos [ <NUM_LIT:0> ] ] = '<STR_LIT:X>' <EOL> def match ( self , request ) : <EOL> return request . path . startswith ( '<STR_LIT>' ) <EOL> def handle_request ( self , request ) : <EOL> if request . path == '<STR_LIT>' : <EOL> request [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> request . set_deflate ( ) <EOL> request . push ( open ( '<STR_LIT>' , '<STR_LIT:rb>' ) . read ( ) ) <EOL> request . done ( ) <EOL> return <EOL> request [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> request . set_deflate ( ) <EOL> if request . file : <EOL> data = request . file . read ( ) <EOL> pairs = [ x . split ( '<STR_LIT:=>' ) for x in data . split ( '<STR_LIT:&>' ) ] <EOL> for k , v in pairs : <EOL> if k == '<STR_LIT>' : <EOL> x0 , y0 = self . pos <EOL> x1 , y1 = self . pos <EOL> if v == '<STR_LIT:left>' : <EOL> x1 = max ( x0 - <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> elif v == '<STR_LIT:right>' : <EOL> x1 = min ( x0 + <NUM_LIT:1> , self . w - <NUM_LIT:1> ) <EOL> elif v == '<STR_LIT>' : <EOL> y1 = max ( y0 - <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> elif v == '<STR_LIT>' : <EOL> y1 = min ( y0 + <NUM_LIT:1> , self . h - <NUM_LIT:1> ) <EOL> else : <EOL> pass <EOL> self . grid [ y0 ] [ x0 ] = '<STR_LIT:*>' <EOL> self . grid [ y1 ] [ x1 ] = '<STR_LIT:X>' <EOL> self . pos = [ x1 , y1 ] <EOL> else : <EOL> pass <EOL> l = [ ] <EOL> for y in self . grid : <EOL> l . append ( '<STR_LIT>' . join ( y ) ) <EOL> request . push ( '<STR_LIT>' ) <EOL> request . push ( '<STR_LIT:\n>' . join ( l ) ) <EOL> request . push ( '<STR_LIT>' ) <EOL> request . push ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> request . done ( ) <EOL> server = coro . http . server ( ) <EOL> server . push_handler ( grid_handler ( <NUM_LIT:50> , <NUM_LIT:30> ) ) <EOL> server . push_handler ( coro . http . handlers . coro_status_handler ( ) ) <EOL> server . push_handler ( coro . http . handlers . favicon_handler ( ) ) <EOL> coro . spawn ( server . start , ( '<STR_LIT>' , <NUM_LIT> ) ) <EOL> coro . spawn ( coro . backdoor . serve , unix_path = '<STR_LIT>' ) <EOL> coro . event_loop ( <NUM_LIT> ) </s>
