(&self, vm: &VirtualMachine)
| 40 | |
| 41 | impl PyTokenizerIter { |
| 42 | fn readline(&self, vm: &VirtualMachine) -> PyResult<String> { |
| 43 | let raw_line = match self.readline.invoke((), vm) { |
| 44 | Ok(v) => v, |
| 45 | Err(err) => { |
| 46 | if err.fast_isinstance(vm.ctx.exceptions.stop_iteration) { |
| 47 | return Ok(String::new()); |
| 48 | } |
| 49 | return Err(err); |
| 50 | } |
| 51 | }; |
| 52 | Ok(match &self.encoding { |
| 53 | Some(encoding) => { |
| 54 | let bytes = raw_line |
| 55 | .downcast::<PyBytes>() |
| 56 | .map_err(|_| vm.new_type_error("readline() returned a non-bytes object"))?; |
| 57 | vm.state |
| 58 | .codec_registry |
| 59 | .decode_text(bytes.into(), encoding, None, vm) |
| 60 | .map(|s| s.to_string())? |
| 61 | } |
| 62 | None => raw_line |
| 63 | .downcast::<PyStr>() |
| 64 | .map(|s| s.to_string()) |
| 65 | .map_err(|_| vm.new_type_error("readline() returned a non-string object"))?, |
| 66 | }) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | impl fmt::Debug for PyTokenizerIter { |
no test coverage detected