11use http_handler:: { Request , RequestExt , Version } ;
2+ use pyo3:: Borrowed ;
23use pyo3:: exceptions:: PyValueError ;
34use pyo3:: prelude:: * ;
45use pyo3:: types:: { PyAny , PyDict } ;
@@ -295,9 +296,11 @@ pub enum HttpSendMessage {
295296 } ,
296297}
297298
298- impl < ' py > FromPyObject < ' py > for HttpSendMessage {
299- fn extract_bound ( ob : & Bound < ' py , PyAny > ) -> PyResult < Self > {
300- let dict = ob. downcast :: < PyDict > ( ) ?;
299+ impl < ' a , ' py > FromPyObject < ' a , ' py > for HttpSendMessage {
300+ type Error = PyErr ;
301+
302+ fn extract ( ob : Borrowed < ' a , ' py , PyAny > ) -> PyResult < Self > {
303+ let dict = ob. cast :: < PyDict > ( ) ?;
301304 let message_type = dict
302305 . get_item ( "type" ) ?
303306 . ok_or_else ( || PyValueError :: new_err ( "Missing 'type' key in HTTP send message dictionary" ) ) ?;
@@ -318,22 +321,22 @@ impl<'py> FromPyObject<'py> for HttpSendMessage {
318321
319322 // Convert headers from list of lists to vec of tuples
320323 let mut headers: Vec < ( String , String ) > = Vec :: new ( ) ;
321- if let Ok ( headers_list) = headers_py. downcast :: < pyo3:: types:: PyList > ( ) {
324+ if let Ok ( headers_list) = headers_py. cast :: < pyo3:: types:: PyList > ( ) {
322325 for item in headers_list. iter ( ) {
323- if let Ok ( header_pair) = item. downcast :: < pyo3:: types:: PyList > ( )
326+ if let Ok ( header_pair) = item. cast :: < pyo3:: types:: PyList > ( )
324327 && header_pair. len ( ) == 2
325328 {
326329 let name = header_pair. get_item ( 0 ) ?;
327330 let value = header_pair. get_item ( 1 ) ?;
328331
329332 // Convert bytes to string
330- let name_str = if let Ok ( bytes) = name. downcast :: < pyo3:: types:: PyBytes > ( ) {
333+ let name_str = if let Ok ( bytes) = name. cast :: < pyo3:: types:: PyBytes > ( ) {
331334 String :: from_utf8_lossy ( bytes. as_bytes ( ) ) . to_string ( )
332335 } else {
333336 name. extract :: < String > ( ) ?
334337 } ;
335338
336- let value_str = if let Ok ( bytes) = value. downcast :: < pyo3:: types:: PyBytes > ( ) {
339+ let value_str = if let Ok ( bytes) = value. cast :: < pyo3:: types:: PyBytes > ( ) {
337340 String :: from_utf8_lossy ( bytes. as_bytes ( ) ) . to_string ( )
338341 } else {
339342 value. extract :: < String > ( ) ?
0 commit comments