(
file: PyObjectRef,
options: FormatOptions,
// TODO: handle quote style, etc
_rest: FuncArgs,
vm: &VirtualMachine,
)
| 388 | |
| 389 | #[pyfunction] |
| 390 | fn writer( |
| 391 | file: PyObjectRef, |
| 392 | options: FormatOptions, |
| 393 | // TODO: handle quote style, etc |
| 394 | _rest: FuncArgs, |
| 395 | vm: &VirtualMachine, |
| 396 | ) -> PyResult<Writer> { |
| 397 | let write = match vm.get_attribute_opt(file.clone(), "write")? { |
| 398 | Some(write_meth) => write_meth, |
| 399 | None if file.is_callable() => file, |
| 400 | None => { |
| 401 | return Err(vm.new_type_error("argument 1 must have a \"write\" method")); |
| 402 | } |
| 403 | }; |
| 404 | |
| 405 | Ok(Writer { |
| 406 | write, |
| 407 | state: PyMutex::new(WriteState { |
| 408 | buffer: vec![0; 1024], |
| 409 | writer: options.to_writer(), |
| 410 | }), |
| 411 | dialect: options.result(vm)?, |
| 412 | }) |
| 413 | } |
| 414 | |
| 415 | #[inline] |
| 416 | fn resize_buf<T: num_traits::PrimInt>(buf: &mut Vec<T>) { |
nothing calls this directly
no test coverage detected