
import tokenize;
import zmq;

context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://lo:32132")

while True:
    # Wait for next request from client
    message = socket.recv()

import re, sys, tokenize, zmq;
from StringIO import StringIO

def err(msg):
	sys.err.write(str(msg) + '\n')
	

class LexPyMQ(object):
	def __init__(self):
		self.zctx = zmq.Context()
		self.socket = self.zctx.socket(zmq.REP)

	def run(self):
		self.socket.bind("tcp://lo:32132")

		while True:
			msg = self.socket.recv_json(0)
			# there are definitely new lines in the code
			if not msg.get('python'):
				err('received non-python code')
			code = msg.get('body', '')
			self.socket.send_json(tokenize.generate_tokens(StringIO(code)))

if __name__ == '__main__':
	LexPyMQ().run()

Implement python lexer ZMQ service.
Implement python lexer ZMQ service.

  
- import tokenize;
- import zmq;
+ import re, sys, tokenize, zmq;
+ from StringIO import StringIO
  
- context = zmq.Context()
- socket = context.socket(zmq.REP)
- socket.bind("tcp://lo:32132")
+ def err(msg):
+ 	sys.err.write(str(msg) + '\n')
+ 	
  
+ class LexPyMQ(object):
+ 	def __init__(self):
+ 		self.zctx = zmq.Context()
+ 		self.socket = self.zctx.socket(zmq.REP)
+ 
+ 	def run(self):
+ 		self.socket.bind("tcp://lo:32132")
+ 
- while True:
+ 		while True:
-     # Wait for next request from client
-     message = socket.recv()
+ 			msg = self.socket.recv_json(0)
+ 			# there are definitely new lines in the code
+ 			if not msg.get('python'):
+ 				err('received non-python code')
+ 			code = msg.get('body', '')
+ 			self.socket.send_json(tokenize.generate_tokens(StringIO(code)))
+ 
+ if __name__ == '__main__':
+ 	LexPyMQ().run()
+ 
Implement python lexer ZMQ service.
## Code Before:

import tokenize;
import zmq;

context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://lo:32132")

while True:
    # Wait for next request from client
    message = socket.recv()
## Instruction:
Implement python lexer ZMQ service.
## Code After:

import re, sys, tokenize, zmq;
from StringIO import StringIO

def err(msg):
	sys.err.write(str(msg) + '\n')
	

class LexPyMQ(object):
	def __init__(self):
		self.zctx = zmq.Context()
		self.socket = self.zctx.socket(zmq.REP)

	def run(self):
		self.socket.bind("tcp://lo:32132")

		while True:
			msg = self.socket.recv_json(0)
			# there are definitely new lines in the code
			if not msg.get('python'):
				err('received non-python code')
			code = msg.get('body', '')
			self.socket.send_json(tokenize.generate_tokens(StringIO(code)))

if __name__ == '__main__':
	LexPyMQ().run()
