From 793263db9dc3ff1c069b0e667c2c7322e39da0c9 Mon Sep 17 00:00:00 2001 From: Joel Bender Date: Fri, 28 Apr 2017 09:24:50 -0400 Subject: [PATCH] rip out the _ord hack, struct.unpack is faster in py2 and ever so slightly slower in py3, not different enough to justify the hack --- modpypes/app.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/modpypes/app.py b/modpypes/app.py index b8a1064..b7ae5a6 100644 --- a/modpypes/app.py +++ b/modpypes/app.py @@ -7,6 +7,7 @@ Application """ import sys +import struct from bacpypes.debugging import bacpypes_debugging, ModuleLogger @@ -21,17 +22,6 @@ _debug = 0 _log = ModuleLogger(globals()) -# -# _ord -# - -if sys.version_info[0] == 2: - _ord = lambda s: ord(s) -elif sys.version_info[0] == 3: - _ord = lambda s: s -else: - raise RuntimeError("unrecognized Python version") - # # ModbusException # @@ -80,8 +70,8 @@ def stream_to_packet(data): if len(data) < 6: return None - # note funky _ord function, a noop in Python3 - pktlen = (_ord(data[4]) << 8) + _ord(data[5]) + 6 + # unpack the length + pktlen = struct.unpack(">H", data[4:6])[0] + 6 if (len(data) < pktlen): return None