(
encoder: &PyObjectRef,
encoding: &str,
buffer: &PyObject,
vm: &VirtualMachine,
)
| 2890 | } |
| 2891 | |
| 2892 | fn adjust_encoder_state_for_bom( |
| 2893 | encoder: &PyObjectRef, |
| 2894 | encoding: &str, |
| 2895 | buffer: &PyObject, |
| 2896 | vm: &VirtualMachine, |
| 2897 | ) -> PyResult<()> { |
| 2898 | let needs_bom = matches!(encoding, "utf-8-sig" | "utf-16" | "utf-32"); |
| 2899 | if !needs_bom { |
| 2900 | return Ok(()); |
| 2901 | } |
| 2902 | let seekable = vm.call_method(buffer, "seekable", ())?.try_to_bool(vm)?; |
| 2903 | if !seekable { |
| 2904 | return Ok(()); |
| 2905 | } |
| 2906 | let pos = vm.call_method(buffer, "tell", ())?; |
| 2907 | if vm.bool_eq(&pos, vm.ctx.new_int(0).as_ref())? { |
| 2908 | return Ok(()); |
| 2909 | } |
| 2910 | if let Err(err) = vm.call_method(encoder, "setstate", (0,)) |
| 2911 | && !err.fast_isinstance(vm.ctx.exceptions.attribute_error) |
| 2912 | { |
| 2913 | return Err(err); |
| 2914 | } |
| 2915 | Ok(()) |
| 2916 | } |
| 2917 | |
| 2918 | #[allow(clippy::type_complexity)] |
| 2919 | fn find_coder( |
nothing calls this directly
no test coverage detected