@@ -1868,17 +1868,16 @@ mod _io {
1868
1868
1869
1869
#[ derive( FromArgs ) ]
1870
1870
struct TextIOWrapperArgs {
1871
- buffer : PyObjectRef ,
1872
1871
#[ pyarg( any, default ) ]
1873
1872
encoding : Option < PyStrRef > ,
1874
1873
#[ pyarg( any, default ) ]
1875
1874
errors : Option < PyStrRef > ,
1876
1875
#[ pyarg( any, default ) ]
1877
- newline : Newlines ,
1878
- #[ pyarg( any, default = "false" ) ]
1879
- line_buffering : bool ,
1880
- #[ pyarg( any, default = "false" ) ]
1881
- write_through : bool ,
1876
+ newline : Option < Newlines > ,
1877
+ #[ pyarg( any, default ) ]
1878
+ line_buffering : Option < bool > ,
1879
+ #[ pyarg( any, default ) ]
1880
+ write_through : Option < bool > ,
1882
1881
}
1883
1882
1884
1883
#[ derive( Debug , Copy , Clone , Default ) ]
@@ -2196,9 +2195,13 @@ mod _io {
2196
2195
impl DefaultConstructor for TextIOWrapper { }
2197
2196
2198
2197
impl Initializer for TextIOWrapper {
2199
- type Args = TextIOWrapperArgs ;
2198
+ type Args = ( PyObjectRef , TextIOWrapperArgs ) ;
2200
2199
2201
- fn init ( zelf : PyRef < Self > , args : Self :: Args , vm : & VirtualMachine ) -> PyResult < ( ) > {
2200
+ fn init (
2201
+ zelf : PyRef < Self > ,
2202
+ ( buffer, args) : Self :: Args ,
2203
+ vm : & VirtualMachine ,
2204
+ ) -> PyResult < ( ) > {
2202
2205
let mut data = zelf. lock_opt ( vm) ?;
2203
2206
* data = None ;
2204
2207
@@ -2218,8 +2221,6 @@ mod _io {
2218
2221
. errors
2219
2222
. unwrap_or_else ( || PyStr :: from ( "strict" ) . into_ref ( & vm. ctx ) ) ;
2220
2223
2221
- let buffer = args. buffer ;
2222
-
2223
2224
let has_read1 = vm. get_attribute_opt ( buffer. clone ( ) , "read1" ) ?. is_some ( ) ;
2224
2225
let seekable = vm. call_method ( & buffer, "seekable" , ( ) ) ?. try_to_bool ( vm) ?;
2225
2226
@@ -2256,9 +2257,9 @@ mod _io {
2256
2257
decoder,
2257
2258
encoding,
2258
2259
errors,
2259
- newline : args. newline ,
2260
- line_buffering : args. line_buffering ,
2261
- write_through : args. write_through ,
2260
+ newline : args. newline . unwrap_or_default ( ) ,
2261
+ line_buffering : args. line_buffering . unwrap_or_default ( ) ,
2262
+ write_through : args. write_through . unwrap_or_default ( ) ,
2262
2263
chunk_size : 8192 ,
2263
2264
seekable,
2264
2265
has_read1,
@@ -2294,6 +2295,27 @@ mod _io {
2294
2295
2295
2296
#[ pyclass( with( Constructor , Initializer ) , flags( BASETYPE ) ) ]
2296
2297
impl TextIOWrapper {
2298
+ #[ pymethod]
2299
+ fn reconfigure ( & self , args : TextIOWrapperArgs ) {
2300
+ let mut data = self . data . lock ( ) . unwrap ( ) ;
2301
+ if let Some ( data) = data. as_mut ( ) {
2302
+ if let Some ( encoding) = args. encoding {
2303
+ data. encoding = encoding;
2304
+ }
2305
+ if let Some ( errors) = args. errors {
2306
+ data. errors = errors;
2307
+ }
2308
+ if let Some ( newline) = args. newline {
2309
+ data. newline = newline;
2310
+ }
2311
+ if let Some ( line_buffering) = args. line_buffering {
2312
+ data. line_buffering = line_buffering;
2313
+ }
2314
+ if let Some ( write_through) = args. write_through {
2315
+ data. write_through = write_through;
2316
+ }
2317
+ }
2318
+ }
2297
2319
#[ pymethod]
2298
2320
fn seekable ( & self , vm : & VirtualMachine ) -> PyResult {
2299
2321
let textio = self . lock ( vm) ?;
0 commit comments