More Py2 fixes
This commit is contained in:
parent
bc089ee46d
commit
d388ae72fd
|
@ -243,9 +243,14 @@ if iswindows:
|
|||
|
||||
# replace any non-ASCII values with 0xfffd
|
||||
for i in range(0,len(buffer)):
|
||||
if buffer[i]>"\u007f":
|
||||
#print "swapping char "+str(i)+" ("+buffer[i]+")"
|
||||
buffer[i] = "\ufffd"
|
||||
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":
|
||||
#print "swapping char "+str(i)+" ("+buffer[i]+")"
|
||||
buffer[i] = "\ufffd"
|
||||
# return utf-8 encoding of modified username
|
||||
#print "modified username:"+buffer.value
|
||||
return buffer.value.encode('utf-8')
|
||||
|
|
|
@ -33,7 +33,7 @@ def checksumPid(s):
|
|||
for i in (0,1):
|
||||
b = crc & 0xff
|
||||
pos = (b // l) ^ (b % l)
|
||||
res += letters[pos%l]
|
||||
res += bytes(bytearray([letters[pos%l]]))
|
||||
crc >>= 8
|
||||
|
||||
return res
|
||||
|
@ -43,16 +43,19 @@ def pidFromSerial(s, l):
|
|||
|
||||
arr1 = [0]*l
|
||||
for i in range(len(s)):
|
||||
arr1[i%l] ^= s[i]
|
||||
if sys.version_info[0] == 2:
|
||||
arr1[i%l] ^= ord(s[i])
|
||||
else:
|
||||
arr1[i%l] ^= s[i]
|
||||
|
||||
crc_bytes = [crc >> 24 & 0xff, crc >> 16 & 0xff, crc >> 8 & 0xff, crc & 0xff]
|
||||
for i in range(l):
|
||||
arr1[i] ^= crc_bytes[i&3]
|
||||
|
||||
pid = ''
|
||||
pid = b""
|
||||
for i in range(l):
|
||||
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
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ def checksumPid(s):
|
|||
for i in (0,1):
|
||||
b = crc & 0xff
|
||||
pos = (b // l) ^ (b % l)
|
||||
res += letters[pos%l]
|
||||
res += bytes(bytearray([letters[pos%l]]))
|
||||
crc >>= 8
|
||||
return res
|
||||
|
||||
|
|
Loading…
Reference in New Issue