From a6dc47572d879ca0112580ad474c5f7cab73ee6e Mon Sep 17 00:00:00 2001 From: Ralf Ertzinger Date: Jul 18 2022 18:02:43 +0000 Subject: Fix python3 compatibility for RHEL8 The fix in https://pagure.io/sigul/pull-request/16 does not work for RHEL8, because the six module shipped by RHEL8 is somewhat ancient. Instead, do the same thing six.ensure_text() does, just manually. Tested on C8S and F35 and works on both. Signed-off-by: Ralf Ertzinger --- diff --git a/src/bridge.py b/src/bridge.py index 67dd153..a89e7e3 100644 --- a/src/bridge.py +++ b/src/bridge.py @@ -250,7 +250,10 @@ class StringField(Field): def validate(self, value): super(StringField, self).validate(value) if value is not None: - value = six.ensure_text(value) + # Ideally we'd use six.ensure_text() here, but RHEL8 doesn't + # have that + if isinstance(value, six.binary_type): + value = value.decode('utf-8', 'strict') if not utils.string_is_safe(value): raise InvalidRequestError( 'Field {0!s} is not printable'.format( @@ -275,7 +278,10 @@ class YYYYMMDDField(Field): def validate(self, value): super(YYYYMMDDField, self).validate(value) if value is not None: - value = six.ensure_text(value) + # Ideally we'd use six.ensure_text() here, but RHEL8 doesn't + # have that + if isinstance(value, six.binary_type): + value = value.decode('utf-8', 'strict') if not utils.yyyy_mm_dd_is_valid(value): raise InvalidRequestError( 'Field {0!s} is not a valid date'.format(self.name))