(&self, byte_range: Range<usize>, reason: Option<&str>)
| 759 | } |
| 760 | |
| 761 | fn error_decoding(&self, byte_range: Range<usize>, reason: Option<&str>) -> Self::Error { |
| 762 | let vm = self.vm; |
| 763 | |
| 764 | match self.exception.get() { |
| 765 | Some(exc) => { |
| 766 | match update_unicode_error_attrs( |
| 767 | exc.as_object(), |
| 768 | byte_range.start, |
| 769 | byte_range.end, |
| 770 | reason, |
| 771 | vm, |
| 772 | ) { |
| 773 | Ok(()) => exc.clone(), |
| 774 | Err(e) => e, |
| 775 | } |
| 776 | } |
| 777 | None => self |
| 778 | .exception |
| 779 | .get_or_init(|| { |
| 780 | let reason = reason.expect( |
| 781 | "should only ever pass reason: None if an exception is already set", |
| 782 | ); |
| 783 | let data = if let Some(bytes) = self.orig_bytes { |
| 784 | bytes.to_owned() |
| 785 | } else { |
| 786 | vm.ctx.new_bytes(self.data.to_vec()) |
| 787 | }; |
| 788 | vm.new_unicode_decode_error_real( |
| 789 | vm.ctx.new_str(self.encoding), |
| 790 | data, |
| 791 | byte_range.start, |
| 792 | byte_range.end, |
| 793 | vm.ctx.new_str(reason), |
| 794 | ) |
| 795 | }) |
| 796 | .clone(), |
| 797 | } |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | #[derive(strum_macros::EnumString)] |
no test coverage detected