(&self, range: Range<StrSize>, reason: Option<&str>)
| 650 | } |
| 651 | |
| 652 | fn error_encoding(&self, range: Range<StrSize>, reason: Option<&str>) -> Self::Error { |
| 653 | let vm = self.vm; |
| 654 | match self.exception.get() { |
| 655 | Some(exc) => { |
| 656 | match update_unicode_error_attrs( |
| 657 | exc.as_object(), |
| 658 | range.start.chars, |
| 659 | range.end.chars, |
| 660 | reason, |
| 661 | vm, |
| 662 | ) { |
| 663 | Ok(()) => exc.clone(), |
| 664 | Err(e) => e, |
| 665 | } |
| 666 | } |
| 667 | None => self |
| 668 | .exception |
| 669 | .get_or_init(|| { |
| 670 | let reason = reason.expect( |
| 671 | "should only ever pass reason: None if an exception is already set", |
| 672 | ); |
| 673 | vm.new_unicode_encode_error_real( |
| 674 | vm.ctx.new_str(self.encoding), |
| 675 | self.data.to_owned(), |
| 676 | range.start.chars, |
| 677 | range.end.chars, |
| 678 | vm.ctx.new_str(reason), |
| 679 | ) |
| 680 | }) |
| 681 | .clone(), |
| 682 | } |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | pub struct PyDecodeContext<'a> { |
no test coverage detected