MCPcopy Index your code
hub / github.com/RustPython/RustPython / __init__

Method __init__

Lib/test/test_hashlib.py:124–192  ·  view source on GitHub ↗
(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

122 return None
123
124 def __init__(self, *args, **kwargs):
125 algorithms = set()
126 for algorithm in self.supported_hash_names:
127 algorithms.add(algorithm.lower())
128
129 _blake2 = self._conditional_import_module('_blake2')
130 if _blake2:
131 algorithms.update({'blake2b', 'blake2s'})
132
133 self.constructors_to_test = {}
134 for algorithm in algorithms:
135 self.constructors_to_test[algorithm] = set()
136
137 # For each algorithm, test the direct constructor and the use
138 # of hashlib.new given the algorithm name.
139 for algorithm, constructors in self.constructors_to_test.items():
140 constructors.add(getattr(hashlib, algorithm))
141 def c(*args, __algorithm_name=algorithm, **kwargs):
142 return hashlib.new(__algorithm_name, *args, **kwargs)
143 c.__name__ = f'do_test_algorithm_via_hashlib_new_{algorithm}'
144 constructors.add(c)
145
146 _hashlib = self._conditional_import_module('_hashlib')
147 self._hashlib = _hashlib
148 if _hashlib:
149 # These algorithms should always be present when this module
150 # is compiled. If not, something was compiled wrong.
151 self.assertHasAttr(_hashlib, 'openssl_md5')
152 self.assertHasAttr(_hashlib, 'openssl_sha1')
153 for algorithm, constructors in self.constructors_to_test.items():
154 constructor = getattr(_hashlib, 'openssl_'+algorithm, None)
155 if constructor:
156 try:
157 constructor()
158 except ValueError:
159 # default constructor blocked by crypto policy
160 pass
161 else:
162 constructors.add(constructor)
163
164 def add_builtin_constructor(name):
165 constructor = getattr(hashlib, "__get_builtin_constructor")(name)
166 self.constructors_to_test[name].add(constructor)
167
168 _md5 = self._conditional_import_module('_md5')
169 if _md5:
170 add_builtin_constructor('md5')
171 _sha1 = self._conditional_import_module('_sha1')
172 if _sha1:
173 add_builtin_constructor('sha1')
174 _sha2 = self._conditional_import_module('_sha2')
175 if _sha2:
176 add_builtin_constructor('sha224')
177 add_builtin_constructor('sha256')
178 add_builtin_constructor('sha384')
179 add_builtin_constructor('sha512')
180 _sha3 = self._conditional_import_module('_sha3')
181 if _sha3:

Callers

nothing calls this directly

Calls 10

setFunction · 0.85
getattrFunction · 0.85
superClass · 0.85
constructorFunction · 0.50
addMethod · 0.45
lowerMethod · 0.45
updateMethod · 0.45
itemsMethod · 0.45
assertHasAttrMethod · 0.45

Tested by

no test coverage detected