More Py2 fixes

This commit is contained in:
NoDRM 2023-08-03 20:14:33 +02:00
parent bc089ee46d
commit d388ae72fd
3 changed files with 16 additions and 8 deletions

View File

@ -243,6 +243,11 @@ if iswindows:
# replace any non-ASCII values with 0xfffd # replace any non-ASCII values with 0xfffd
for i in range(0,len(buffer)): for i in range(0,len(buffer)):
if sys.version_info[0] == 2:
if buffer[i]>u"\u007f":
#print "swapping char "+str(i)+" ("+buffer[i]+")"
buffer[i] = u"\ufffd"
else:
if buffer[i]>"\u007f": if buffer[i]>"\u007f":
#print "swapping char "+str(i)+" ("+buffer[i]+")" #print "swapping char "+str(i)+" ("+buffer[i]+")"
buffer[i] = "\ufffd" buffer[i] = "\ufffd"

View File

@ -33,7 +33,7 @@ def checksumPid(s):
for i in (0,1): for i in (0,1):
b = crc & 0xff b = crc & 0xff
pos = (b // l) ^ (b % l) pos = (b // l) ^ (b % l)
res += letters[pos%l] res += bytes(bytearray([letters[pos%l]]))
crc >>= 8 crc >>= 8
return res return res
@ -43,16 +43,19 @@ def pidFromSerial(s, l):
arr1 = [0]*l arr1 = [0]*l
for i in range(len(s)): for i in range(len(s)):
if sys.version_info[0] == 2:
arr1[i%l] ^= ord(s[i])
else:
arr1[i%l] ^= s[i] arr1[i%l] ^= s[i]
crc_bytes = [crc >> 24 & 0xff, crc >> 16 & 0xff, crc >> 8 & 0xff, crc & 0xff] crc_bytes = [crc >> 24 & 0xff, crc >> 16 & 0xff, crc >> 8 & 0xff, crc & 0xff]
for i in range(l): for i in range(l):
arr1[i] ^= crc_bytes[i&3] arr1[i] ^= crc_bytes[i&3]
pid = '' pid = b""
for i in range(l): for i in range(l):
b = arr1[i] & 0xff b = arr1[i] & 0xff
pid+=letters[(b >> 7) + ((b >> 5 & 3) ^ (b & 0x1f))] pid+=bytes(bytearray([letters[(b >> 7) + ((b >> 5 & 3) ^ (b & 0x1f))]]))
return pid return pid

View File

@ -113,7 +113,7 @@ def checksumPid(s):
for i in (0,1): for i in (0,1):
b = crc & 0xff b = crc & 0xff
pos = (b // l) ^ (b % l) pos = (b // l) ^ (b % l)
res += letters[pos%l] res += bytes(bytearray([letters[pos%l]]))
crc >>= 8 crc >>= 8
return res return res