compatibility update for Python 3.6

This commit is contained in:
2021-04-14 00:59:02 +00:00
parent c63d2dd4bb
commit d111d402db
3 changed files with 53 additions and 8 deletions

View File

@@ -933,6 +933,8 @@ class Bytes:
A colletion of Bits with convenient properties for working with binary data
"""
import sys
def __init__(self, var=None, byteorder="big"):
"""
var: a supported variant (object)
@@ -1135,10 +1137,23 @@ class Bytes:
"""
Return the hex-string representation of self
"""
hexvalue = bytes(self).hex()
if sep is None or bytes_per_sep is None or bytes_per_sep == 0:
return bytes(self).hex()
return hexvalue
else:
return bytes(self).hex(sep=sep, bytes_per_sep=bytes_per_sep)
if bytes_per_sep > 1:
hexvalue = hexvalue[::-1] # reverse the hex string
sep = sep[::-1]
i = 0
retvalue = ""
while i < len(hexvalue):
if i > 0:
retvalue = retvalue + sep
retvalue = retvalue + hexvalue[i:(abs(bytes_per_sep * 2) + i)]
i += abs(bytes_per_sep * 2)
if bytes_per_sep > 1:
retvalue = retvalue[::-1]
return retvalue
@property
def bytes(self):