MCPcopy Index your code
hub / github.com/RustPython/RustPython / reconfigure

Method reconfigure

crates/vm/src/stdlib/_io.rs:3025–3118  ·  view source on GitHub ↗
(&self, args: TextIOWrapperArgs, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

3023 impl TextIOWrapper {
3024 #[pymethod]
3025 fn reconfigure(&self, args: TextIOWrapperArgs, vm: &VirtualMachine) -> PyResult<()> {
3026 let mut data = self.lock(vm)?;
3027 data.check_closed(vm)?;
3028
3029 let mut encoding = data.encoding.clone();
3030 let mut errors = data.errors.clone();
3031 let mut newline = data.newline;
3032 let mut encoding_changed = false;
3033 let mut errors_changed = false;
3034 let mut newline_changed = false;
3035 let mut line_buffering = None;
3036 let mut write_through = None;
3037
3038 if let Some(enc) = args.encoding {
3039 if enc.as_str().contains('\0') && enc.as_str().starts_with("locale") {
3040 return Err(vm.new_lookup_error(format!("unknown encoding: {enc}")));
3041 }
3042 let resolved = Self::resolve_encoding(Some(enc), vm)?;
3043 encoding_changed = resolved.as_str() != encoding.as_str();
3044 encoding = resolved;
3045 }
3046
3047 if let Some(errs) = args.errors {
3048 Self::validate_errors(&errs, vm)?;
3049 errors_changed = errs.as_str() != errors.as_str();
3050 errors = errs;
3051 } else if encoding_changed {
3052 errors = identifier_utf8!(vm, strict).to_owned();
3053 errors_changed = true;
3054 }
3055
3056 if let OptionalArg::Present(nl) = args.newline {
3057 let nl = nl.unwrap_or_default();
3058 newline_changed = nl != newline;
3059 newline = nl;
3060 }
3061
3062 if let OptionalArg::Present(Some(value)) = args.line_buffering {
3063 line_buffering = Some(Self::bool_from_index(value, vm)?);
3064 }
3065 if let OptionalArg::Present(Some(value)) = args.write_through {
3066 write_through = Some(Self::bool_from_index(value, vm)?);
3067 }
3068
3069 if (encoding_changed || newline_changed)
3070 && data.decoder.is_some()
3071 && (data.decoded_chars.is_some()
3072 || data.snapshot.is_some()
3073 || data.decoded_chars_used.chars != 0)
3074 {
3075 return Err(new_unsupported_operation(
3076 vm,
3077 "cannot reconfigure encoding or newline after reading from the stream"
3078 .to_owned(),
3079 ));
3080 }
3081
3082 if data.pending.num_bytes > 0 {

Callers

nothing calls this directly

Calls 13

starts_withMethod · 0.80
write_pendingMethod · 0.80
set_decoded_charsMethod · 0.80
ErrClass · 0.50
SomeClass · 0.50
lockMethod · 0.45
check_closedMethod · 0.45
cloneMethod · 0.45
containsMethod · 0.45
as_strMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected