From 0695d80ce9c379da368da0cd2713d92044c78c0a Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 7 Aug 2010 20:08:31 +0200 Subject: [PATCH] fix base32 --- ox/format.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/ox/format.py b/ox/format.py index ed27b62..4e439ad 100644 --- a/ox/format.py +++ b/ox/format.py @@ -39,9 +39,24 @@ def to32(q): return "".join(converted) or '0' def from32(q): + """ + Converts an base 32 string to an integer + We exclude 4 of the 26 letters: I L O U. + http://www.crockford.com/wrmg/base32.html + + >>> form32(to32(35)) + 35 + >>> form32(to32(119292)) + 119292 + >>> from32(to32(0)) + 0 + """ _32map = { '0': 0, + 'O': 0, '1': 1, + 'I': 1, + 'L': 1, '2': 2, '3': 3, '4': 4, @@ -72,11 +87,8 @@ def from32(q): 'X': 29, 'Y': 30, 'Z': 31, - 'O': 0, - 'I': 1, - 'L': 1, } - base32 = '0123456789ABCDEFGHIJKLMNOPQRSTUV' + base32 = "0123456789ACBEDGFHKJMNQPSRTWVYXZ" q = q.replace('-','') q = ''.join([base32[_32map[i.upper()]] for i in q]) return int(q, 32)