| 69 | |
| 70 | impl IntoPyException for FormatSpecError { |
| 71 | fn into_pyexception(self, vm: &VirtualMachine) -> PyBaseExceptionRef { |
| 72 | match self { |
| 73 | Self::DecimalDigitsTooMany => { |
| 74 | vm.new_value_error("Too many decimal digits in format string") |
| 75 | } |
| 76 | Self::PrecisionTooBig => vm.new_value_error("Precision too big"), |
| 77 | Self::InvalidFormatSpecifier => vm.new_value_error("Invalid format specifier"), |
| 78 | Self::UnspecifiedFormat(c1, c2) => { |
| 79 | let msg = format!("Cannot specify '{c1}' with '{c2}'."); |
| 80 | vm.new_value_error(msg) |
| 81 | } |
| 82 | Self::ExclusiveFormat(c1, c2) => { |
| 83 | let msg = format!("Cannot specify both '{c1}' and '{c2}'."); |
| 84 | vm.new_value_error(msg) |
| 85 | } |
| 86 | Self::UnknownFormatCode(c, s) => { |
| 87 | let msg = format!("Unknown format code '{c}' for object of type '{s}'"); |
| 88 | vm.new_value_error(msg) |
| 89 | } |
| 90 | Self::PrecisionNotAllowed => { |
| 91 | vm.new_value_error("Precision not allowed in integer format specifier") |
| 92 | } |
| 93 | Self::NotAllowed(s) => { |
| 94 | let msg = format!("{s} not allowed with integer format specifier 'c'"); |
| 95 | vm.new_value_error(msg) |
| 96 | } |
| 97 | Self::UnableToConvert => vm.new_value_error("Unable to convert int to float"), |
| 98 | Self::CodeNotInRange => vm.new_overflow_error("%c arg not in range(0x110000)"), |
| 99 | Self::ZeroPadding => { |
| 100 | vm.new_value_error("Zero padding is not allowed in complex format specifier") |
| 101 | } |
| 102 | Self::AlignmentFlag => { |
| 103 | vm.new_value_error("'=' alignment flag is not allowed in complex format specifier") |
| 104 | } |
| 105 | Self::NotImplemented(c, s) => { |
| 106 | let msg = format!("Format code '{c}' for object of type '{s}' not implemented yet"); |
| 107 | vm.new_value_error(msg) |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | impl ToPyException for FormatParseError { |