return all uppercase base32
This commit is contained in:
parent
04ce15caa1
commit
bf79a05edf
1 changed files with 5 additions and 11 deletions
16
ox/format.py
16
ox/format.py
|
@ -16,22 +16,22 @@ def to32(q):
|
||||||
'0'
|
'0'
|
||||||
|
|
||||||
>>> to32(347485647)
|
>>> to32(347485647)
|
||||||
'AbCdEf'
|
'ABCDEF'
|
||||||
|
|
||||||
>>> to32(555306645)
|
>>> to32(555306645)
|
||||||
'GhJkMn'
|
'GHJKMN'
|
||||||
|
|
||||||
>>> to32(800197332334559L)
|
>>> to32(800197332334559L)
|
||||||
'PqRsTvWxYz'
|
'PQRSTVWXYZ'
|
||||||
|
|
||||||
>>> to32(32)
|
>>> to32(32)
|
||||||
'10'
|
'10'
|
||||||
|
|
||||||
>>> to32(119292)
|
>>> to32(119292)
|
||||||
'3mFw'
|
'3MFW'
|
||||||
|
|
||||||
>>> to32(939387374)
|
>>> to32(939387374)
|
||||||
'VzVtFe'
|
'VZVTFE'
|
||||||
|
|
||||||
>>> to32(-1)
|
>>> to32(-1)
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
|
@ -42,15 +42,9 @@ def to32(q):
|
||||||
if q < 0: raise ValueError, "must supply a positive integer"
|
if q < 0: raise ValueError, "must supply a positive integer"
|
||||||
letters = "0123456789ABCDEFGHJKMNPQRSTVWXYZ"
|
letters = "0123456789ABCDEFGHJKMNPQRSTVWXYZ"
|
||||||
converted = []
|
converted = []
|
||||||
upper = False
|
|
||||||
while q != 0:
|
while q != 0:
|
||||||
q, r = divmod(q, 32)
|
q, r = divmod(q, 32)
|
||||||
l = letters[r]
|
l = letters[r]
|
||||||
if upper:
|
|
||||||
upper = False
|
|
||||||
else:
|
|
||||||
l = l.lower()
|
|
||||||
upper = True
|
|
||||||
converted.insert(0, l)
|
converted.insert(0, l)
|
||||||
return "".join(converted) or '0'
|
return "".join(converted) or '0'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue