21
21
from test import support
22
22
from test .support import _4G , bigmemtest
23
23
from test .support import hashlib_helper
24
- from test .support .import_helper import import_fresh_module , import_module
24
+ from test .support .import_helper import import_fresh_module
25
25
from test .support import requires_resource
26
26
from test .support import threading_helper
27
27
from http .client import HTTPException
@@ -96,19 +96,6 @@ def read_vectors(hash_name):
96
96
yield parts
97
97
98
98
99
- def find_gil_minsize (* modules_names , default = 2048 ):
100
- sizes = []
101
- for module_name in modules_names :
102
- if SKIP_SHA3 and module_name == '_sha3' :
103
- continue
104
- try :
105
- module = importlib .import_module (module_name )
106
- except ImportError :
107
- continue
108
- sizes .append (module ._GIL_MINSIZE )
109
- return max (sizes , default = default )
110
-
111
-
112
99
class HashLibTestCase (unittest .TestCase ):
113
100
supported_hash_names = ( 'md5' , 'MD5' , 'sha1' , 'SHA1' ,
114
101
'sha224' , 'SHA224' , 'sha256' , 'SHA256' ,
@@ -930,10 +917,10 @@ def test_gil(self):
930
917
# for multithreaded operation. Currently, all cryptographic modules
931
918
# have the same constant value (2048) but in the future it might not
932
919
# be the case.
933
- gil_minsize = find_gil_minsize (
934
- '_md5' , '_sha1' , '_sha2' , '_sha3' , '_blake2' , '_hashlib' ,
935
- )
920
+ mods = ['_md5' , '_sha1' , '_sha2' , '_sha3' , '_blake2' , '_hashlib' ]
921
+ gil_minsize = hashlib_helper .find_gil_minsize (mods )
936
922
for cons in self .hash_constructors :
923
+ # constructors belong to one of the above modules
937
924
m = cons (usedforsecurity = False )
938
925
m .update (b'1' )
939
926
m .update (b'#' * gil_minsize )
@@ -943,7 +930,7 @@ def test_gil(self):
943
930
m .update (b'1' )
944
931
945
932
def test_sha256_gil (self ):
946
- gil_minsize = find_gil_minsize ('_sha2' , '_hashlib' )
933
+ gil_minsize = hashlib_helper . find_gil_minsize ([ '_sha2' , '_hashlib' ] )
947
934
m = hashlib .sha256 ()
948
935
m .update (b'1' )
949
936
m .update (b'#' * gil_minsize )
0 commit comments