MCPcopy Index your code
hub / github.com/RustPython/RustPython / unhexlify

Function unhexlify

crates/stdlib/src/binascii.rs:174–197  ·  view source on GitHub ↗
(data: ArgAsciiBuffer, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

172 #[pyfunction(name = "a2b_hex")]
173 #[pyfunction]
174 fn unhexlify(data: ArgAsciiBuffer, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
175 data.with_ref(|hex_bytes| {
176 if hex_bytes.len() % 2 != 0 {
177 return Err(super::new_binascii_error(
178 "Odd-length string".to_owned(),
179 vm,
180 ));
181 }
182
183 let mut unhex = Vec::<u8>::with_capacity(hex_bytes.len() / 2);
184 for (n1, n2) in hex_bytes.iter().tuples() {
185 if let (Some(n1), Some(n2)) = (unhex_nibble(*n1), unhex_nibble(*n2)) {
186 unhex.push((n1 << 4) | n2);
187 } else {
188 return Err(super::new_binascii_error(
189 "Non-hexadecimal digit found".to_owned(),
190 vm,
191 ));
192 }
193 }
194
195 Ok(unhex)
196 })
197 }
198
199 #[pyfunction]
200 pub(crate) fn crc32(data: ArgBytesLike, init: OptionalArg<PyIntRef>) -> u32 {

Callers 2

KDFTestsClass · 0.90
test_oneMethod · 0.85

Calls 8

new_binascii_errorFunction · 0.85
unhex_nibbleFunction · 0.85
with_refMethod · 0.80
ErrClass · 0.50
lenMethod · 0.45
to_ownedMethod · 0.45
iterMethod · 0.45
pushMethod · 0.45

Tested by 1

test_oneMethod · 0.68