Skip to content

Commit 02e05e4

Browse files
authored
Correct binascii.unhexlify error type (RustPython#4005)
* Correct `binascii.unhexlify` error type * Unmark resolved tests
1 parent eb9a5fa commit 02e05e4

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

Lib/test/test_base64.py

-2
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,6 @@ def test_b16encode(self):
369369
b'0102ABCDEF')
370370
self.check_encode_type_errors(base64.b16encode)
371371

372-
# TODO: RUSTPYTHON
373-
@unittest.expectedFailure
374372
def test_b16decode(self):
375373
eq = self.assertEqual
376374
eq(base64.b16decode(b'0102ABCDEF'), b'\x01\x02\xab\xcd\xef')

Lib/test/test_binascii.py

-2
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,6 @@ def test_rle(self):
234234
decoded = binascii.rledecode_hqx(encoded)
235235
self.assertEqual(decoded, data)
236236

237-
# TODO: RUSTPYTHON
238-
@unittest.expectedFailure
239237
def test_hex(self):
240238
# test hexlification
241239
s = b'{s\005\000\000\000worldi\002\000\000\000s\005\000\000\000helloi\001\000\000\0000'

stdlib/src/binascii.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,18 @@ mod decl {
6060
fn unhexlify(data: ArgAsciiBuffer, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
6161
data.with_ref(|hex_bytes| {
6262
if hex_bytes.len() % 2 != 0 {
63-
return Err(vm.new_value_error("Odd-length string".to_owned()));
63+
return Err(new_binascii_error("Odd-length string".to_owned(), vm));
6464
}
6565

6666
let mut unhex = Vec::<u8>::with_capacity(hex_bytes.len() / 2);
6767
for (n1, n2) in hex_bytes.iter().tuples() {
6868
if let (Some(n1), Some(n2)) = (unhex_nibble(*n1), unhex_nibble(*n2)) {
6969
unhex.push(n1 << 4 | n2);
7070
} else {
71-
return Err(vm.new_value_error("Non-hexadecimal digit found".to_owned()));
71+
return Err(new_binascii_error(
72+
"Non-hexadecimal digit found".to_owned(),
73+
vm,
74+
));
7275
}
7376
}
7477

0 commit comments

Comments
 (0)