Skip to content

Commit

Permalink
Improve py2 compatibility of WMException __init__
Browse files Browse the repository at this point in the history
This solves the issue 9862,
The rationale for this change is described in the
issue comments
  • Loading branch information
mapellidario committed Aug 12, 2020
1 parent cdd4c7c commit 237e497
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/python/WMCore/WMException.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"""

from builtins import bytes

import exceptions
import inspect
import logging
Expand All @@ -27,7 +29,7 @@ class WMException(exceptions.Exception):

def __init__(self, message, errorNo=None, **data):
self.name = str(self.__class__.__name__)
if hasattr(message, "decode"):
if type(message) == bytes:
# Fix for the unicode encoding issue, see #8056 and #8403
# interprets this string using utf-8 codec and ignoring any errors
message = message.decode('utf-8', 'ignore')
Expand Down Expand Up @@ -151,7 +153,7 @@ def __str__(self):
strg += self.traceback
strg += '\n'
strg += WMEXCEPTION_END_STR
if hasattr(strg, "decode"):
if type(strg) == bytes:
# Fix for the unicode encoding issue, #8043
strg = strg.decode('utf-8', 'ignore')
return strg
Expand Down

0 comments on commit 237e497

Please sign in to comment.