From c72cd071bca4807eeacd351e27ce6f5750ef031b Mon Sep 17 00:00:00 2001
From: Arnaud Fontaine <arnaud.fontaine@nexedi.com>
Date: Sat, 16 Apr 2022 10:25:49 +0200
Subject: [PATCH] py3: Add functions to convert bytes/str/unicode (from
 slapos.util).

Stricter than six.ensure_{text,str}().
---
 product/ERP5Type/Utils.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/product/ERP5Type/Utils.py b/product/ERP5Type/Utils.py
index 847920940d..442eabf75a 100644
--- a/product/ERP5Type/Utils.py
+++ b/product/ERP5Type/Utils.py
@@ -550,6 +550,19 @@ def checkPythonSourceCode(source_code_str, portal_type=None):
   #LOG('Utils', INFO, 'Checking time (pylint): %.2f' % (time.time() - started))
   return message_list
 
+# Used for Python 2-3 compatibility
+if str is bytes:
+  bytes2str = str2bytes = lambda s: s
+  def unicode2str(s):
+    return s.encode('utf-8')
+else:
+  def bytes2str(s):
+    return s.decode()
+  def str2bytes(s):
+    return s.encode()
+  def unicode2str(s):
+    return s
+
 #####################################################
 # Globals initialization
 #####################################################
-- 
2.30.9