Skip to content

Commit

Permalink
lib: fix crit-recode fix for Python 2
Browse files Browse the repository at this point in the history
The recent fix to make Jenkins run crit-recode again broke
Python 2 support (because Python 2 based CI was not running).

This should fix the Python 2 based test run.

Signed-off-by: Adrian Reber <areber@redhat.com>
  • Loading branch information
adrianreber authored and avagin committed Sep 3, 2021
1 parent 228e510 commit b82f222
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 9 additions & 2 deletions lib/py/images/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import struct
import os
import array
import sys

from . import magic
from . import pb
Expand Down Expand Up @@ -284,9 +285,15 @@ def dump(self, entries, f):
size = len(pb_str)
f.write(struct.pack('i', size))
f.write(pb_str)
f.write(base64.decodebytes(str.encode(item['extra'])))
if (sys.version_info > (3, 0)):
f.write(base64.decodebytes(str.encode(item['extra'])))
else:
f.write(base64.decodebytes(item['extra']))
else:
f.write(base64.decodebytes(str.encode(item['extra'])))
if (sys.version_info > (3, 0)):
f.write(base64.decodebytes(str.encode(item['extra'])))
else:
f.write(base64.decodebytes(item['extra']))

def dumps(self, entries):
f = io.BytesIO('')
Expand Down
11 changes: 9 additions & 2 deletions lib/py/images/pb2dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import quopri
import socket
import sys
from ipaddress import IPv4Address, IPv6Address, ip_address

from google.protobuf.descriptor import FieldDescriptor as FD
Expand Down Expand Up @@ -246,11 +247,17 @@ def encode_dev(field, value):


def encode_base64(value):
return base64.encodebytes(value).decode()
if (sys.version_info > (3, 0)):
return base64.encodebytes(value).decode()
else:
return base64.encodebytes(value)


def decode_base64(value):
return base64.decodebytes(str.encode(value))
if (sys.version_info > (3, 0)):
return base64.decodebytes(str.encode(value))
else:
return base64.decodebytes(value)


def encode_unix(value):
Expand Down

0 comments on commit b82f222

Please sign in to comment.