| 761 | } |
| 762 | |
| 763 | fn try_int_radix(obj: &PyObject, base: u32, vm: &VirtualMachine) -> PyResult<BigInt> { |
| 764 | match_class!(match obj.to_owned() { |
| 765 | string @ PyStr => { |
| 766 | let s = string.as_wtf8().trim(); |
| 767 | bytes_to_int(s.as_bytes(), base, vm.state.int_max_str_digits.load()) |
| 768 | .map_err(|e| handle_bytes_to_int_err(e, obj, vm)) |
| 769 | } |
| 770 | bytes @ PyBytes => { |
| 771 | bytes_to_int(bytes.as_bytes(), base, vm.state.int_max_str_digits.load()) |
| 772 | .map_err(|e| handle_bytes_to_int_err(e, obj, vm)) |
| 773 | } |
| 774 | bytearray @ PyByteArray => { |
| 775 | let inner = bytearray.borrow_buf(); |
| 776 | bytes_to_int(&inner, base, vm.state.int_max_str_digits.load()) |
| 777 | .map_err(|e| handle_bytes_to_int_err(e, obj, vm)) |
| 778 | } |
| 779 | _ => Err(vm.new_type_error("int() can't convert non-string with explicit base")), |
| 780 | }) |
| 781 | } |
| 782 | |
| 783 | // Retrieve inner int value: |
| 784 | pub(crate) fn get_value(obj: &PyObject) -> &BigInt { |