@@ -86,6 +86,15 @@ impl BufferedIO {
8686 fn tell ( & self ) -> u64 {
8787 self . cursor . position ( )
8888 }
89+
90+ fn readline ( & mut self ) -> Option < String > {
91+ let mut buf = String :: new ( ) ;
92+
93+ match self . cursor . read_line ( & mut buf) {
94+ Ok ( _) => Some ( buf) ,
95+ Err ( _) => None ,
96+ }
97+ }
8998}
9099
91100#[ derive( Debug ) ]
@@ -150,6 +159,13 @@ impl PyStringIORef {
150159 fn tell ( self , _vm : & VirtualMachine ) -> u64 {
151160 self . buffer . borrow ( ) . tell ( )
152161 }
162+
163+ fn readline ( self , vm : & VirtualMachine ) -> PyResult < String > {
164+ match self . buffer . borrow_mut ( ) . readline ( ) {
165+ Some ( line) => Ok ( line) ,
166+ None => Err ( vm. new_value_error ( "Error Performing Operation" . to_string ( ) ) ) ,
167+ }
168+ }
153169}
154170
155171fn string_io_new (
@@ -220,6 +236,13 @@ impl PyBytesIORef {
220236 fn tell ( self , _vm : & VirtualMachine ) -> u64 {
221237 self . buffer . borrow ( ) . tell ( )
222238 }
239+
240+ fn readline ( self , vm : & VirtualMachine ) -> PyResult < Vec < u8 > > {
241+ match self . buffer . borrow_mut ( ) . readline ( ) {
242+ Some ( line) => Ok ( line. as_bytes ( ) . to_vec ( ) ) ,
243+ None => Err ( vm. new_value_error ( "Error Performing Operation" . to_string ( ) ) ) ,
244+ }
245+ }
223246}
224247
225248fn bytes_io_new (
@@ -735,6 +758,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
735758 "write" => ctx. new_rustfunc( PyStringIORef :: write) ,
736759 "getvalue" => ctx. new_rustfunc( PyStringIORef :: getvalue) ,
737760 "tell" => ctx. new_rustfunc( PyStringIORef :: tell) ,
761+ "readline" => ctx. new_rustfunc( PyStringIORef :: readline) ,
738762 } ) ;
739763
740764 //BytesIO: in-memory bytes
@@ -746,7 +770,8 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
746770 "seekable" => ctx. new_rustfunc( PyBytesIORef :: seekable) ,
747771 "write" => ctx. new_rustfunc( PyBytesIORef :: write) ,
748772 "getvalue" => ctx. new_rustfunc( PyBytesIORef :: getvalue) ,
749- "tell" => ctx. new_rustfunc( PyBytesIORef :: tell)
773+ "tell" => ctx. new_rustfunc( PyBytesIORef :: tell) ,
774+ "readline" => ctx. new_rustfunc( PyBytesIORef :: readline) ,
750775 } ) ;
751776
752777 py_module ! ( vm, "_io" , {
0 commit comments