poidasmith / xlloop

XLLoop Excel Function (UDF) Server
104 stars 49 forks source link

Python 3 server? #37

Open mnar53 opened 6 years ago

mnar53 commented 6 years ago

xlloop.zip

I have a Python 2 server working well, but I'd like to move to Python 3 now that 3.7 seems very performant. Just went through an automatic conversion; the converted file starts the server correctly, but starting Excel and loading xlloop.xll does not load in Excel the defined Python functions. I guess there is some difference between SocketServer (2.7) and socketserver (3.7), but I'm not able to track them.

JS2018SJ commented 4 years ago

My experience: In xlloop.py:

  1. SocketServer => socketserver
  2. XLCodec.decode(): type == XL_TYPE_STR: ... return bytes.decode(socket.recv(len), 'utf8') XLCodec.decodeInt(): ord(l[0]) << 24 | ord(l[1]) << 16 | ord(l[2]) << 8 | ord(l[3]) => int.from_bytes(l, 'big')
  3. XLCodec.encode(): if isinstance(value, str): ... socket.send(value.encode())
  4. XlloopServer.start(): self.server = socketserver.ThreadingTCPServer(('localhost', self.port), XLLoopHandler)

then it seems working (Sorry I have customized code in the file and don't have time to cut a version).

JS2018SJ commented 4 years ago

the other fix include change isinstance(value, types.IntType) to isinstance(value, int) etc.

mnar53 commented 4 years ago

I've tried your fixes on a "clean" (basic) xlloop.py, and they work. I think did not change/add anything else, so maybe the resulting file may be of interest compared to the original Python 2 version. Thx.

xlloop3.zip