From 8d7830b6fc1b0cfb2f1dd9e9315aff67dbef3c93 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Sat, 4 Aug 2018 21:00:06 +0100 Subject: [PATCH] PY3: convert samba.tests.strings to Py2/Py3 Previously the py2 api for strcasecmp_m/strstr_m required strings/unicode but couldn't actually handle unicode with anything other than the default encoding (e.g. ascii). The c-api as been fixed and the encoding steps (which were unnecessary and causing errors in PY3) have been removed --- python/samba/tests/strings.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/python/samba/tests/strings.py b/python/samba/tests/strings.py index 67c73319b04..3ce778ddd00 100644 --- a/python/samba/tests/strings.py +++ b/python/samba/tests/strings.py @@ -23,8 +23,13 @@ # best way to do that yet. # # -- mbp +from samba.compat import PY3 +if PY3: + import unicodedata + KATAKANA_LETTER_A = unicodedata.lookup("KATAKANA LETTER A") +else: + from unicodenames import KATAKANA_LETTER_A as KATAKANA_LETTER_A -from unicodenames import * import samba.tests from samba import strcasecmp_m, strstr_m @@ -38,7 +43,6 @@ def signum(a): else: return 0 - class strcasecmp_m_Tests(samba.tests.TestCase): """String comparisons in simple ASCII and unicode""" def test_strcasecmp_m(self): @@ -60,9 +64,7 @@ class strcasecmp_m_Tests(samba.tests.TestCase): (KATAKANA_LETTER_A, 'a', 1), ] for a, b, expect in cases: - self.assertEquals(signum(strcasecmp_m(a.encode('utf-8'), - b.encode('utf-8'))), - expect) + self.assertEquals(signum(strcasecmp_m(a, b)), expect) class strstr_m_Tests(samba.tests.TestCase): @@ -98,8 +100,4 @@ class strstr_m_Tests(samba.tests.TestCase): (KATAKANA_LETTER_A * 3, 'a', None), ] for a, b, expect in cases: - if expect is not None: - expect = expect.encode('utf-8') - self.assertEquals(strstr_m(a.encode('utf-8'), - b.encode('utf-8')), - expect) + self.assertEquals(strstr_m(a, b), expect)