diff --git a/pyghmi/ipmi/command.py b/pyghmi/ipmi/command.py index 8d887075..b69266f1 100644 --- a/pyghmi/ipmi/command.py +++ b/pyghmi/ipmi/command.py @@ -753,7 +753,7 @@ class Command(object): fetchcmd = bytearray((channel, param, 0, 0)) fetched = self.xraw_command(0xc, 2, data=fetchcmd) fetchdata = fetched['data'] - if ord(fetchdata[0]) != 17: + if bytearray(fetchdata)[0] != 17: return None if len(fetchdata) == 5: # IPv4 address if prefixlen: @@ -770,7 +770,7 @@ class Command(object): return None return mac elif len(fetchdata) == 2: - return ord(fetchdata[1]) + return bytearray(fetchdata)[1] else: raise Exception("Unrecognized data format " + repr(fetchdata)) @@ -989,7 +989,8 @@ class Command(object): continue else: raise - chantype = ord(rsp['data'][1]) & 0b1111111 + chantype = bytearray(rsp['data'])[1] + chantype = chantype & 0b1111111 if chantype in (4, 6): try: # Some implementations denote an inactive channel @@ -1003,7 +1004,8 @@ class Command(object): # However some implementations may still have # ambiguous channel info, that will need to be # picked up on an OEM extension... - self._netchannel = ord(rsp['data'][0]) & 0b1111 + netchan = bytearray(rsp['data'])[0] + self._netchannel = netchan & 0b1111 break except exc.IpmiException as ie: # This means the attempt to fetch parameter 5 failed, diff --git a/pyghmi/ipmi/oem/lenovo/EfiDecompressor.py b/pyghmi/ipmi/oem/lenovo/EfiDecompressor.py index b5a35faa..d21356d2 100644 --- a/pyghmi/ipmi/oem/lenovo/EfiDecompressor.py +++ b/pyghmi/ipmi/oem/lenovo/EfiDecompressor.py @@ -1,10 +1,14 @@ # -*- coding: utf-8 -*- import struct +try: + range = xrange +except NameError: + pass class BitArray: def __init__(self, data): - self._Data = data + self._Data = bytearray(data) self._DataBitsLeft = len(data) * 8 @@ -20,7 +24,7 @@ class BitArray: result = 0 while bitsleftcount: curbitsleftcount = 8 - self._BitIdx - curdata = ord(self._Data[self._ByteIdx]) & self.mask( + curdata = self._Data[self._ByteIdx] & self.mask( curbitsleftcount) if curbitsleftcount >= bitsleftcount: @@ -68,7 +72,7 @@ def loadhuffmansyms(bits, symscountbits, zeroskipidx): # Allocate huffman codes to the length-ordered symbols huffsyms[0][2] = 0 - for idx in xrange(1, len(huffsyms)): + for idx in range(1, len(huffsyms)): huffsyms[idx][2] = (huffsyms[idx - 1][2] + 1) << ( huffsyms[idx][1] - huffsyms[idx - 1][1]) @@ -85,7 +89,7 @@ def buildhuffmantree(huffsyms): continue huffsubtree = hufftree - for bit in xrange(0, bitlen): + for bit in range(0, bitlen): lr = huffcode & (1 << (bitlen - bit - 1)) != 0 if bit < bitlen - 1: @@ -137,7 +141,7 @@ def loadcharlenhuffmansyms(bits, extra_hufftree): # Allocate huffman codes to the length-ordered symbols huffsyms[0][2] = 0 - for idx in xrange(1, len(huffsyms)): + for idx in range(1, len(huffsyms)): huffsyms[idx][2] = (huffsyms[idx - 1][2] + 1) << ( huffsyms[idx][1] - huffsyms[idx - 1][1]) @@ -148,7 +152,7 @@ def decompress(buf): (compressed_size, decompressed_size) = struct.unpack(" 0: - data = [] - data += LENOVO_ENTERPRISE - data += WRITE_COMMAND - for byte in hex_filehandle[:4]: - data += [ord(byte)] + data = bytearray() + data.extend(LENOVO_ENTERPRISE) + data.extend(WRITE_COMMAND) + data.extend(hex_filehandle[:4]) hex_offset = struct.pack("I', struct.pack('4B', *spd[325:329]))[0])[2:].rjust(8, '0') self.info['model'] = struct.pack('18B', *spd[329:347]).strip( - '\x00\xff ') + b'\x00\xff ') diff --git a/pyghmi/ipmi/sdr.py b/pyghmi/ipmi/sdr.py index 03e84e1d..92536ecd 100644 --- a/pyghmi/ipmi/sdr.py +++ b/pyghmi/ipmi/sdr.py @@ -700,7 +700,7 @@ class SDR(object): self.fw_minor, modtime) cachefilename = os.path.join(self.cachedir, cachefilename) if cachefilename and os.path.isfile(cachefilename): - with open(cachefilename, 'r') as cfile: + with open(cachefilename, 'rb') as cfile: csdrs = pickle.load(cfile) for sdrdata in csdrs: self.add_sdr(sdrdata) @@ -782,7 +782,7 @@ class SDR(object): if cachefilename: suffix = ''.join( random.choice(string.ascii_lowercase) for _ in range(12)) - with open(cachefilename + '.' + suffix, 'w') as cfile: + with open(cachefilename + '.' + suffix, 'wb') as cfile: pickle.dump(sdrraw, cfile) os.rename(cachefilename + '.' + suffix, cachefilename) diff --git a/pyghmi/util/webclient.py b/pyghmi/util/webclient.py index 2925b51b..bb20bc53 100644 --- a/pyghmi/util/webclient.py +++ b/pyghmi/util/webclient.py @@ -139,6 +139,10 @@ class SecureHTTPConnection(httplib.HTTPConnection, object): self.stdheaders[key] = value def set_basic_credentials(self, username, password): + if isinstance(username, bytes) and not isinstance(username, str): + username = username.decode('utf-8') + if isinstance(password, bytes) and not isinstance(password, str): + password = password.decode('utf-8') authinfo = ':'.join((username, password)) if not isinstance(authinfo, bytes): authinfo = authinfo.encode('utf-8')