◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
4 changes: 0 additions & 4 deletions Lib/test/test_binascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,6 @@ def test_hex(self):
self.assertEqual(binascii.hexlify(self.type2test(s)), t)
self.assertEqual(binascii.unhexlify(self.type2test(t)), u)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_hex_separator(self):
"""Test that hexlify and b2a_hex are binary versions of bytes.hex."""
# Logic of separators is tested in test_bytes.py. This checks that
Expand Down Expand Up @@ -388,8 +386,6 @@ def test_empty_string(self):
except Exception as err:
self.fail("{}({!r}) raises {!r}".format(func, empty, err))

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_unicode_b2a(self):
# Unicode strings are not accepted by b2a_* functions.
for func in set(all_functions) - set(a2b_functions):
Expand Down
120 changes: 113 additions & 7 deletions stdlib/src/binascii.rs
Original file line number Diff line number Diff line change
@@ -43,14 +43,120 @@ mod decl {

#[pyfunction(name = "b2a_hex")]
#[pyfunction]
fn hexlify(data: ArgBytesLike) -> Vec<u8> {
data.with_ref(|bytes| {
let mut hex = Vec::<u8>::with_capacity(bytes.len() * 2);
for b in bytes {
hex.push(hex_nibble(b >> 4));
hex.push(hex_nibble(b & 0xf));
}
hex
})
}

Expand Down Expand Up @@ -368,7 +474,7 @@ mod decl {
#[derive(FromArgs)]
struct B2aQpArgs {
#[pyarg(any)]
data: ArgAsciiBuffer,
#[pyarg(named, default = false)]
quotetabs: bool,
#[pyarg(named, default = true)]
Expand Down
Loading
Toggle all file notes Toggle all file annotations