hexathon

Common and uncommon hex string operations for python3
git clone git://git.defalsify.org/python-hexathon.git
Log | Files | Refs | LICENSE

commit 3326e66452a30135cf7189b3f94b7530b6df2791
parent 257b271f1813cac36d1104ec5eb49bf938ca3abe
Author: nolash <dev@holbrook.no>
Date:   Mon,  8 Feb 2021 10:17:55 +0100

Handle even nibble case separately

Diffstat:
Mhexathon/parse.py | 12++++++++----
Msetup.cfg | 2+-
Mtests/test_basic.py | 4++++
3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/hexathon/parse.py b/hexathon/parse.py @@ -10,10 +10,14 @@ def valid(hx): return hx -def uniform(hx): +def even(hx): if len(hx) % 2 != 0: hx = '0' + hx - return valid(hx).lower() + return valid(hx) + + +def uniform(hx): + return even(hx).lower() def strip_0x(hx): @@ -21,7 +25,7 @@ def strip_0x(hx): raise ValueError('invalid hex') if hx[:2] == '0x': hx = hx[2:] - return valid(hx) + return even(hx) def add_0x(hx): @@ -29,4 +33,4 @@ def add_0x(hx): raise ValueError('invalid hex') if hx[:2] == '0x': hx = hx[2:] - return '0x' + valid(hx) + return '0x' + even(hx) diff --git a/setup.cfg b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = hexathon -version = 0.0.1a1 +version = 0.0.1a2 description = Common and uncommon hex string operations author = Louis Holbrook author_email = dev@holbrook.no diff --git a/tests/test_basic.py b/tests/test_basic.py @@ -23,6 +23,10 @@ class HexTest(unittest.TestCase): self.assertEqual(hexathon.add_0x('abcd'), '0xabcd') + def test_even(self): + self.assertEqual(hexathon.even('aBc'), '0aBc') + + def test_uniform(self): self.assertEqual(hexathon.uniform('aBc'), '0abc')