@@ -30,7 +30,7 @@ mod _ssl {
3030 } ,
3131 socket:: { self , PySocket } ,
3232 vm:: {
33- builtins:: { PyBaseException , PyBaseExceptionRef , PyStrRef , PyType , PyTypeRef , PyWeak } ,
33+ builtins:: { PyBaseExceptionRef , PyStrRef , PyType , PyTypeRef , PyWeak } ,
3434 exceptions,
3535 function:: {
3636 ArgBytesLike , ArgCallable , ArgMemoryBuffer , ArgStrOrBytesLike , IntoPyException ,
@@ -39,7 +39,7 @@ mod _ssl {
3939 stdlib:: os:: PyPathLike ,
4040 types:: Constructor ,
4141 utils:: { Either , ToCString } ,
42- ItemProtocol , PyClassImpl , PyObjectRef , PyRef , PyResult , PyValue , VirtualMachine ,
42+ ItemProtocol , PyObjectRef , PyRef , PyResult , PyValue , VirtualMachine ,
4343 } ,
4444 } ;
4545 use crossbeam_utils:: atomic:: AtomicCell ;
@@ -174,90 +174,58 @@ mod _ssl {
174174 parse_version_info ( openssl_api_version)
175175 }
176176
177- #[ pyattr( name = "SSLError" ) ]
177+ /// An error occurred in the SSL implementation.
178+ #[ pyattr( name = "SSLError" , once) ]
178179 fn ssl_error ( vm : & VirtualMachine ) -> PyTypeRef {
179- rustpython_common:: static_cell! {
180- static ERROR : PyTypeRef ;
181- }
182- ERROR
183- . get_or_init ( || {
184- PyType :: new_simple_ref ( "ssl.SSLError" , & vm. ctx . exceptions . os_error ) . unwrap ( )
185- } )
186- . clone ( )
180+ vm. ctx . new_exception_type (
181+ "ssl" ,
182+ "SSLError" ,
183+ Some ( vec ! [ vm. ctx. exceptions. os_error. clone( ) ] ) ,
184+ )
187185 }
188186
189- #[ pyattr( name = "SSLCertVerificationError" ) ]
187+ /// A certificate could not be verified.
188+ #[ pyattr( name = "SSLCertVerificationError" , once) ]
190189 fn ssl_cert_verification_error ( vm : & VirtualMachine ) -> PyTypeRef {
191- rustpython_common:: static_cell! {
192- static ERROR : PyTypeRef ;
193- }
194- ERROR
195- . get_or_init ( || {
196- let ssl_error = ssl_error ( vm) ;
197- PyType :: new_ref (
198- "ssl.SSLCertVerificationError" ,
199- vec ! [ ssl_error, vm. ctx. exceptions. value_error. clone( ) ] ,
200- Default :: default ( ) ,
201- PyBaseException :: make_slots ( ) ,
202- vm. ctx . types . type_type . clone ( ) ,
203- )
204- . unwrap ( )
205- } )
206- . clone ( )
190+ vm. ctx . new_exception_type (
191+ "ssl" ,
192+ "SSLCertVerificationError" ,
193+ Some ( vec ! [ ssl_error( vm) , vm. ctx. exceptions. value_error. clone( ) ] ) ,
194+ )
207195 }
208196
209- #[ pyattr( name = "SSLZeroReturnError" ) ]
197+ /// SSL/TLS session closed cleanly.
198+ #[ pyattr( name = "SSLZeroReturnError" , once) ]
210199 fn ssl_zero_return_error ( vm : & VirtualMachine ) -> PyTypeRef {
211- rustpython_common:: static_cell! {
212- static ERROR : PyTypeRef ;
213- }
214- ERROR
215- . get_or_init ( || {
216- PyType :: new_simple_ref ( "ssl.SSLZeroReturnError" , & ssl_error ( vm) ) . unwrap ( )
217- } )
218- . clone ( )
200+ vm. ctx
201+ . new_exception_type ( "ssl" , "SSLZeroReturnError" , Some ( vec ! [ ssl_error( vm) ] ) )
219202 }
220203
221- #[ pyattr( name = "SSLWantReadError" ) ]
204+ /// Non-blocking SSL socket needs to read more data before the requested operation can be completed.
205+ #[ pyattr( name = "SSLWantReadError" , once) ]
222206 fn ssl_want_read_error ( vm : & VirtualMachine ) -> PyTypeRef {
223- rustpython_common:: static_cell! {
224- static ERROR : PyTypeRef ;
225- }
226- ERROR
227- . get_or_init ( || PyType :: new_simple_ref ( "ssl.SSLWantReadError" , & ssl_error ( vm) ) . unwrap ( ) )
228- . clone ( )
207+ vm. ctx
208+ . new_exception_type ( "ssl" , "SSLWantReadError" , Some ( vec ! [ ssl_error( vm) ] ) )
229209 }
230210
231- #[ pyattr( name = "SSLWantWriteError" ) ]
211+ /// Non-blocking SSL socket needs to write more data before the requested operation can be completed.
212+ #[ pyattr( name = "SSLWantWriteError" , once) ]
232213 fn ssl_want_write_error ( vm : & VirtualMachine ) -> PyTypeRef {
233- rustpython_common:: static_cell! {
234- static ERROR : PyTypeRef ;
235- }
236- ERROR
237- . get_or_init ( || {
238- PyType :: new_simple_ref ( "ssl.SSLWantWriteError" , & ssl_error ( vm) ) . unwrap ( )
239- } )
240- . clone ( )
214+ vm. ctx
215+ . new_exception_type ( "ssl" , "SSLWantWriteError" , Some ( vec ! [ ssl_error( vm) ] ) )
241216 }
242217
243- #[ pyattr( name = "SSLSyscallError" ) ]
218+ /// System error when attempting SSL operation.
219+ #[ pyattr( name = "SSLSyscallError" , once) ]
244220 fn ssl_syscall_error ( vm : & VirtualMachine ) -> PyTypeRef {
245- rustpython_common:: static_cell! {
246- static ERROR : PyTypeRef ;
247- }
248- ERROR
249- . get_or_init ( || PyType :: new_simple_ref ( "ssl.SSLSyscallError" , & ssl_error ( vm) ) . unwrap ( ) )
250- . clone ( )
221+ vm. ctx
222+ . new_exception_type ( "ssl" , "SSLSyscallError" , Some ( vec ! [ ssl_error( vm) ] ) )
251223 }
252224
253- #[ pyattr( name = "SSLEOFError" ) ]
225+ /// SSL/TLS connection terminated abruptly.
226+ #[ pyattr( name = "SSLEOFError" , once) ]
254227 fn ssl_eof_error ( vm : & VirtualMachine ) -> PyTypeRef {
255- rustpython_common:: static_cell! {
256- static ERROR : PyTypeRef ;
257- }
258- ERROR
259- . get_or_init ( || PyType :: new_simple_ref ( "ssl.SSLEOFError" , & ssl_error ( vm) ) . unwrap ( ) )
260- . clone ( )
228+ PyType :: new_simple_ref ( "ssl.SSLEOFError" , & ssl_error ( vm) ) . unwrap ( )
261229 }
262230
263231 type OpensslVersionInfo = ( u8 , u8 , u8 , u8 , u8 ) ;
0 commit comments