Browse Source

saferepr: bytes.hex() not available on Python 3.4

Ask Solem 8 years ago
parent
commit
c3fb931372
1 changed files with 8 additions and 1 deletions
  1. 8 1
      celery/utils/saferepr.py

+ 8 - 1
celery/utils/saferepr.py

@@ -121,7 +121,14 @@ def _repr_binary_bytes(val):
         return val.decode('utf-8')
         return val.decode('utf-8')
     except UnicodeDecodeError:
     except UnicodeDecodeError:
         # possibly not unicode, but binary data so format as hex.
         # possibly not unicode, but binary data so format as hex.
-        return val.hex()
+        try:
+            ashex = val.hex
+        except AttributeError:  # pragma: no cover
+            # Python 3.4
+            return val.decode('utf-8', errors='backslashreplace')
+        else:
+            # Python 3.5+
+            return ashex()
 
 
 
 
 def _format_chars(val, maxlen):
 def _format_chars(val, maxlen):