Skip to content

Commit d2b8686

Browse files
committed
fix(binascii): a2b_base64() raises binascii.Error instead of ValueError
1 parent fbd258e commit d2b8686

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

stdlib/src/binascii.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub(super) use decl::crc32;
55
#[pymodule(name = "binascii")]
66
mod decl {
77
use crate::vm::{
8-
builtins::{PyIntRef, PyTypeRef},
8+
builtins::{PyBaseExceptionRef, PyIntRef, PyTypeRef},
99
function::{ArgAsciiBuffer, ArgBytesLike, OptionalArg},
1010
PyResult, VirtualMachine,
1111
};
@@ -93,6 +93,10 @@ mod decl {
9393
newline: bool,
9494
}
9595

96+
fn new_binascii_error(msg: String, vm: &VirtualMachine) -> PyBaseExceptionRef {
97+
vm.new_exception_msg(error_type(vm), msg)
98+
}
99+
96100
#[pyfunction]
97101
fn a2b_base64(s: ArgAsciiBuffer, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
98102
s.with_ref(|b| {
@@ -109,7 +113,7 @@ mod decl {
109113
}
110114
base64::decode(b)
111115
})
112-
.map_err(|err| vm.new_value_error(format!("error decoding base64: {}", err)))
116+
.map_err(|err| new_binascii_error(format!("error decoding base64: {}", err), vm))
113117
}
114118

115119
#[pyfunction]

0 commit comments

Comments
 (0)