<s> import json <EOL> import traceback <EOL> import zmq <EOL> import mayaserver <EOL> def runserver ( ) : <EOL> sock = zmq . Context ( ) . socket ( zmq . REP ) <EOL> sock . bind ( '<STR_LIT>' ) <EOL> while True : <EOL> recved = sock . recv ( ) <EOL> try : <EOL> func , arg = json . loads ( recved ) <EOL> code = mayaserver . SUCCESS <EOL> response = None <EOL> if func == '<STR_LIT>' : <EOL> exec arg in globals ( ) , globals ( ) <EOL> elif func == '<STR_LIT>' : <EOL> response = eval ( arg , globals ( ) , globals ( ) ) <EOL> else : <EOL> code = mayaserver . INVALID_METHOD <EOL> response = func <EOL> pickled = json . dumps ( [ code , response ] ) <EOL> except Exception : <EOL> pickled = json . dumps ( [ <EOL> mayaserver . UNHANDLED_ERROR , <EOL> '<STR_LIT>' . join ( traceback . format_exc ( ) ) ] ) <EOL> sock . send ( pickled ) </s>
