From: Douglas Bagnall Date: Wed, 12 Jun 2024 00:16:46 +0000 (+1200) Subject: python: remove string_to_byte_array() X-Git-Tag: tdb-1.4.11~369 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=43802f1beddc875d1f4fc15babdbadf7615705c9;p=thirdparty%2Fsamba.git python: remove string_to_byte_array() This was a useful function during the Python 2 -> 3 migration, but it is not used any more. In all the cases it was used, we knew we already had a bytes object, and this was just an inefficient way of confirming that. In cases where we actually want to cast a string into a mutable list of byte-sized ints, the builtin bytearray() function will do a better job than this, because it will encode high unicode characters as utf-8 bytes, rather than adding them as out-of-range values in the list. Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett Autobuild-User(master): Andrew Bartlett Autobuild-Date(master): Wed Jun 12 09:16:39 UTC 2024 on atb-devel-224 --- diff --git a/python/samba/__init__.py b/python/samba/__init__.py index 5b1a3f91ba8..d0e797e94c3 100644 --- a/python/samba/__init__.py +++ b/python/samba/__init__.py @@ -348,10 +348,6 @@ def current_unix_time(): return int(time.time()) -def string_to_byte_array(string): - return [c if isinstance(c, int) else ord(c) for c in string] - - def arcfour_encrypt(key, data): from samba.crypto import arcfour_crypt_blob return arcfour_crypt_blob(data, key) diff --git a/python/samba/tests/core.py b/python/samba/tests/core.py index 9f53473d4f6..eaed4f9bf84 100644 --- a/python/samba/tests/core.py +++ b/python/samba/tests/core.py @@ -20,7 +20,7 @@ import ldb import os import samba -from samba import arcfour_encrypt, string_to_byte_array +from samba import arcfour_encrypt from samba.tests import TestCase, TestCaseInTempDir @@ -61,14 +61,6 @@ class ArcfourTestCase(TestCase): self.assertEqual(crypt_expected, crypt_calculated) -class StringToByteArrayTestCase(TestCase): - - def test_byte_array(self): - expected = [218, 145, 90, 176, 108, 215, 185, 207, 153] - calculated = string_to_byte_array('\xda\x91Z\xb0l\xd7\xb9\xcf\x99') - self.assertEqual(expected, calculated) - - class LdbExtensionTests(TestCaseInTempDir): def test_searchone(self):