1 from sys import version_info 2 3 if version_info[0] <= 2: 4 int2oct = chr 5 ints2octs = lambda s: ''.join([ int2oct(x) for x in s ]) 6 null = '' 7 oct2int = ord 8 octs2ints = lambda s: [ oct2int(x) for x in s ] 9 str2octs = lambda x: x 10 octs2str = lambda x: x 11 isOctetsType = lambda s: isinstance(s, str) 12 else: 13 ints2octs = bytes 14 int2oct = lambda x: ints2octs((x,)) 15 null = ints2octs() 16 oct2int = lambda x: x 17 octs2ints = lambda s: [ x for x in s ] 18 str2octs = lambda x: x.encode() 19 octs2str = lambda x: x.decode() 20 isOctetsType = lambda s: isinstance(s, bytes) 21