소스 검색

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

Ask Solem 8 년 전
부모
커밋
c3fb931372
1개의 변경된 파일8개의 추가작업 그리고 1개의 파일을 삭제
  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')
     except UnicodeDecodeError:
         # 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):