@@ -106,11 +106,11 @@ impl PyFastStreamReader {
106106 value : Py < PyAny > ,
107107 ) -> PyResult < ( ) > {
108108 let future = future. bind ( py) ;
109- match future . call_method1 ( python_names:: set_result ( py) , ( value, ) ) {
109+ match python_names :: call_method1 ( py , future , python_names:: set_result ( py) , value. bind ( py ) ) {
110110 Ok ( _) => Ok ( ( ) ) ,
111111 Err ( err) => {
112- if future
113- . call_method0 ( python_names :: cancelled ( py) ) ?
112+ if python_names :: call_method0 ( py , future, python_names :: cancelled ( py ) ) ?
113+ . bind ( py)
114114 . extract :: < bool > ( ) ?
115115 {
116116 Ok ( ( ) )
@@ -127,11 +127,12 @@ impl PyFastStreamReader {
127127 exc : Py < PyAny > ,
128128 ) -> PyResult < ( ) > {
129129 let future = future. bind ( py) ;
130- match future. call_method1 ( python_names:: set_exception ( py) , ( exc, ) ) {
130+ match python_names:: call_method1 ( py, future, python_names:: set_exception ( py) , exc. bind ( py) )
131+ {
131132 Ok ( _) => Ok ( ( ) ) ,
132133 Err ( err) => {
133- if future
134- . call_method0 ( python_names :: cancelled ( py) ) ?
134+ if python_names :: call_method0 ( py , future, python_names :: cancelled ( py ) ) ?
135+ . bind ( py)
135136 . extract :: < bool > ( ) ?
136137 {
137138 Ok ( ( ) )
@@ -160,25 +161,28 @@ impl PyFastStreamReader {
160161 }
161162
162163 fn create_future ( & self , py : Python < ' _ > ) -> PyResult < Py < PyAny > > {
163- self . loop_obj
164- . bind ( py)
165- . call_method0 ( python_names:: create_future ( py) )
166- . map ( Bound :: unbind)
164+ python_names:: call_method0 ( py, self . loop_obj . bind ( py) , python_names:: create_future ( py) )
167165 }
168166
169167 fn ready_result_future ( & self , py : Python < ' _ > , value : Py < PyAny > ) -> PyResult < Py < PyAny > > {
170168 let future = self . create_future ( py) ?;
171- future
172- . bind ( py)
173- . call_method1 ( python_names:: set_result ( py) , ( value, ) ) ?;
169+ python_names:: call_method1 (
170+ py,
171+ future. bind ( py) ,
172+ python_names:: set_result ( py) ,
173+ value. bind ( py) ,
174+ ) ?;
174175 Ok ( future)
175176 }
176177
177178 fn ready_exception_future ( & self , py : Python < ' _ > , exc : Py < PyAny > ) -> PyResult < Py < PyAny > > {
178179 let future = self . create_future ( py) ?;
179- future
180- . bind ( py)
181- . call_method1 ( python_names:: set_exception ( py) , ( exc, ) ) ?;
180+ python_names:: call_method1 (
181+ py,
182+ future. bind ( py) ,
183+ python_names:: set_exception ( py) ,
184+ exc. bind ( py) ,
185+ ) ?;
182186 Ok ( future)
183187 }
184188
@@ -214,21 +218,23 @@ impl PyFastStreamReader {
214218 fn maybe_resume_transport ( & mut self , py : Python < ' _ > ) -> PyResult < ( ) > {
215219 if self . paused && self . buffer . len ( ) <= self . limit && !self . transport . bind ( py) . is_none ( ) {
216220 self . paused = false ;
217- self . transport
218- . bind ( py)
219- . call_method0 ( python_names:: resume_reading ( py) ) ?;
221+ python_names:: call_method0 (
222+ py,
223+ self . transport . bind ( py) ,
224+ python_names:: resume_reading ( py) ,
225+ ) ?;
220226 }
221227 Ok ( ( ) )
222228 }
223229
224230 fn maybe_pause_transport ( & mut self , py : Python < ' _ > ) -> PyResult < ( ) > {
225231 if !self . transport . bind ( py) . is_none ( ) && !self . paused && self . buffer . len ( ) > 2 * self . limit
226232 {
227- match self
228- . transport
229- . bind ( py)
230- . call_method0 ( python_names:: pause_reading ( py) )
231- {
233+ match python_names :: call_method0 (
234+ py ,
235+ self . transport . bind ( py) ,
236+ python_names:: pause_reading ( py) ,
237+ ) {
232238 Ok ( _) => {
233239 self . paused = true ;
234240 }
@@ -308,9 +314,11 @@ impl PyFastStreamReader {
308314 }
309315 if self . paused && !self . transport . bind ( py) . is_none ( ) {
310316 self . paused = false ;
311- self . transport
312- . bind ( py)
313- . call_method0 ( python_names:: resume_reading ( py) ) ?;
317+ python_names:: call_method0 (
318+ py,
319+ self . transport . bind ( py) ,
320+ python_names:: resume_reading ( py) ,
321+ ) ?;
314322 }
315323 let future = self . create_future ( py) ?;
316324 self . waiter = Some ( ReadWaiter {
@@ -525,14 +533,16 @@ impl PyFastStreamProtocol {
525533 reader : Py < PyFastStreamReader > ,
526534 client_connected_cb : Py < PyAny > ,
527535 ) -> PyResult < Self > {
528- let closed = loop_obj. call_method0 ( py, "create_future" ) ?;
529- let ready_none = loop_obj
530- . bind ( py)
531- . call_method0 ( python_names:: create_future ( py) ) ?
532- . unbind ( ) ;
533- ready_none
534- . bind ( py)
535- . call_method1 ( python_names:: set_result ( py) , ( py. None ( ) , ) ) ?;
536+ let closed =
537+ python_names:: call_method0 ( py, loop_obj. bind ( py) , python_names:: create_future ( py) ) ?;
538+ let ready_none =
539+ python_names:: call_method0 ( py, loop_obj. bind ( py) , python_names:: create_future ( py) ) ?;
540+ python_names:: call_method1 (
541+ py,
542+ ready_none. bind ( py) ,
543+ python_names:: set_result ( py) ,
544+ py. None ( ) . bind ( py) ,
545+ ) ?;
536546 Ok ( Self {
537547 closed,
538548 ready_none,
@@ -560,42 +570,55 @@ impl PyFastStreamProtocol {
560570 }
561571
562572 fn ready_exception_future ( & self , py : Python < ' _ > , exc : Py < PyAny > ) -> PyResult < Py < PyAny > > {
563- let future = self
564- . loop_obj
565- . bind ( py)
566- . call_method0 ( python_names:: create_future ( py) ) ?
567- . unbind ( ) ;
568- future
569- . bind ( py)
570- . call_method1 ( python_names:: set_exception ( py) , ( exc, ) ) ?;
573+ let future = python_names:: call_method0 (
574+ py,
575+ self . loop_obj . bind ( py) ,
576+ python_names:: create_future ( py) ,
577+ ) ?;
578+ python_names:: call_method1 (
579+ py,
580+ future. bind ( py) ,
581+ python_names:: set_exception ( py) ,
582+ exc. bind ( py) ,
583+ ) ?;
571584 Ok ( future)
572585 }
573586
574587 fn push_drain_waiter ( & mut self , py : Python < ' _ > ) -> PyResult < Py < PyAny > > {
575- let future = self
576- . loop_obj
577- . bind ( py)
578- . call_method0 ( python_names:: create_future ( py) ) ?
579- . unbind ( ) ;
588+ let future = python_names :: call_method0 (
589+ py ,
590+ self . loop_obj . bind ( py) ,
591+ python_names:: create_future ( py) ,
592+ ) ? ;
580593 self . drain_waiters . push ( future. clone_ref ( py) ) ;
581594 Ok ( future)
582595 }
583596
584597 fn resolve_drain_waiters ( & mut self , py : Python < ' _ > , exc : Option < Py < PyAny > > ) -> PyResult < ( ) > {
585598 for future in self . drain_waiters . drain ( ..) {
586599 let future = future. bind ( py) ;
587- if future
588- . call_method0 ( python_names :: done ( py) ) ?
600+ if python_names :: call_method0 ( py , future, python_names :: done ( py ) ) ?
601+ . bind ( py)
589602 . extract :: < bool > ( ) ?
590603 {
591604 continue ;
592605 }
593606 match exc. as_ref ( ) {
594607 Some ( exc) => {
595- future. call_method1 ( python_names:: set_exception ( py) , ( exc. clone_ref ( py) , ) ) ?;
608+ python_names:: call_method1 (
609+ py,
610+ future,
611+ python_names:: set_exception ( py) ,
612+ exc. bind ( py) ,
613+ ) ?;
596614 }
597615 None => {
598- future. call_method1 ( python_names:: set_result ( py) , ( py. None ( ) , ) ) ?;
616+ python_names:: call_method1 (
617+ py,
618+ future,
619+ python_names:: set_result ( py) ,
620+ py. None ( ) . bind ( py) ,
621+ ) ?;
599622 }
600623 }
601624 }
@@ -690,16 +713,31 @@ impl PyFastStreamProtocol {
690713 self . reader
691714 . borrow_mut ( py)
692715 . set_exception_internal ( py, exc. clone_ref ( py) ) ?;
693- if !self . closed . call_method0 ( py, "done" ) ?. extract :: < bool > ( py) ? {
694- self . closed
695- . call_method1 ( py, "set_exception" , ( exc. clone_ref ( py) , ) ) ?;
716+ if !python_names:: call_method0 ( py, self . closed . bind ( py) , python_names:: done ( py) ) ?
717+ . bind ( py)
718+ . extract :: < bool > ( ) ?
719+ {
720+ python_names:: call_method1 (
721+ py,
722+ self . closed . bind ( py) ,
723+ python_names:: set_exception ( py) ,
724+ exc. bind ( py) ,
725+ ) ?;
696726 }
697727 self . resolve_drain_waiters ( py, Some ( exc) ) ?;
698728 }
699729 None => {
700730 self . reader . borrow_mut ( py) . feed_eof_internal ( py) ?;
701- if !self . closed . call_method0 ( py, "done" ) ?. extract :: < bool > ( py) ? {
702- self . closed . call_method1 ( py, "set_result" , ( py. None ( ) , ) ) ?;
731+ if !python_names:: call_method0 ( py, self . closed . bind ( py) , python_names:: done ( py) ) ?
732+ . bind ( py)
733+ . extract :: < bool > ( ) ?
734+ {
735+ python_names:: call_method1 (
736+ py,
737+ self . closed . bind ( py) ,
738+ python_names:: set_result ( py) ,
739+ py. None ( ) . bind ( py) ,
740+ ) ?;
703741 }
704742 self . resolve_drain_waiters ( py, None ) ?;
705743 }
0 commit comments