11import math
22import struct
33
4- # Python 2 compat
5- try :
6- int_types = (int , long ,)
7- byte_iter = bytearray
8- except NameError :
9- int_types = (int ,)
10- byte_iter = lambda x : x
11-
12- try :
13- from itertools import zip_longest
14- except ImportError :
15- from itertools import izip_longest as zip_longest
4+ from itertools import zip_longest
165
176
187class RecordBase :
@@ -336,7 +325,7 @@ def render(self, raw_value):
336325 raw_value = unpacked_num
337326
338327 # Mask and shift like a normal number
339- if isinstance (raw_value , int_types ):
328+ if isinstance (raw_value , int ):
340329 raw_value = (raw_value >> self .bit_offset ) & ((1 << self .bits ) - 1 )
341330
342331 return raw_value
@@ -376,7 +365,7 @@ def format(value):
376365 @classmethod
377366 def calculate (cls , byte_arr , crc = 0 ):
378367 """Compute CRC for input bytes."""
379- for byte in byte_iter ( byte_arr ) :
368+ for byte in byte_arr :
380369 # Taken verbatim from FIT SDK docs
381370 tmp = cls .CRC_TABLE [crc & 0xF ]
382371 crc = (crc >> 4 ) & 0x0FFF
@@ -390,10 +379,7 @@ def calculate(cls, byte_arr, crc=0):
390379
391380def parse_string (string ):
392381 try :
393- try :
394- s = string [:string .index (0x00 )]
395- except TypeError : # Python 2 compat
396- s = string [:string .index ('\x00 ' )]
382+ s = string [:string .index ('\x00 ' )]
397383 except ValueError :
398384 # FIT specification defines the 'string' type as follows: "Null
399385 # terminated string encoded in UTF-8 format".
0 commit comments