Skip to content

Commit cf284b9

Browse files
committed
More annoying compatibility fixes
I really want this all to work on python 2.4-3.x. Python doesn't make it too easy though.
1 parent 0e5db74 commit cf284b9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

hpilo_fw.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,22 @@
1010
import configparser as ConfigParser
1111
from io import BytesIO, StringIO
1212
b = lambda x: bytes(x, 'ascii')
13+
GZIP_CONSTANT = '\x1f\x8b'.encode('latin-1')
1314
else:
1415
import urllib2
1516
import ConfigParser
1617
from cStringIO import StringIO as StringIO
1718
BytesIO = StringIO
1819
b = lambda x: x
20+
GZIP_CONSTANT = '\x1f\x8b'
1921

2022
_config = None
2123
def config():
2224
global _config
2325
if not _config:
24-
conf = _download('https://raw.github.com/seveas/python-hpilo/master/firmware.conf').decode('ascii')
26+
conf = _download('https://raw.github.com/seveas/python-hpilo/master/firmware.conf')
27+
if PY3:
28+
conf = conf.decode('ascii')
2529
parser = ConfigParser.ConfigParser()
2630
parser.readfp(StringIO(conf))
2731
_config = {}
@@ -63,10 +67,10 @@ def download(ilo, path=None):
6367
tarball = scexe.split(b('\n'), skip)[-1]
6468

6569
# Now uncompress it
66-
if tarball[:2] != '\x1f\x8b':
70+
if tarball[:2] != GZIP_CONSTANT:
6771
raise ValueError("Downloaded scexe file seems corrupt")
6872

69-
tf = tarfile.open(fileobj=BytesIO(tarball), mode='r:gz')
73+
tf = tarfile.open(name="bogus_name_for_old_python_versions", fileobj=BytesIO(tarball), mode='r:gz')
7074
tf.extract(conf[ilo]['file'], path)
7175

7276
if __name__ == '__main__':

0 commit comments

Comments
 (0)