comparison mercurial/pure/base85.py @ 8632:9e055cfdd620

replace "i in range(len(xs))" with "i, x in enumerate(xs)" The remaining occurrences should be the ones where "xs" is mutated or where "i" is used for index arithmetic.
author Martin Geisler <mg@lazybytes.net>
date Tue, 26 May 2009 22:59:52 +0200
parents 46293a0c7e9f
children 0001e49f1c11
comparison
equal deleted inserted replaced
8631:a87c41f65aff 8632:9e055cfdd620
11 "abcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~" 11 "abcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~"
12 _b85chars2 = [(a + b) for a in _b85chars for b in _b85chars] 12 _b85chars2 = [(a + b) for a in _b85chars for b in _b85chars]
13 _b85dec = {} 13 _b85dec = {}
14 14
15 def _mkb85dec(): 15 def _mkb85dec():
16 for i in range(len(_b85chars)): 16 for i, c in enumerate(_b85chars):
17 _b85dec[_b85chars[i]] = i 17 _b85dec[c] = i
18 18
19 def b85encode(text, pad=False): 19 def b85encode(text, pad=False):
20 """encode text in base85 format""" 20 """encode text in base85 format"""
21 l = len(text) 21 l = len(text)
22 r = l % 4 22 r = l % 4
48 l = len(text) 48 l = len(text)
49 out = [] 49 out = []
50 for i in range(0, len(text), 5): 50 for i in range(0, len(text), 5):
51 chunk = text[i:i+5] 51 chunk = text[i:i+5]
52 acc = 0 52 acc = 0
53 for j in range(len(chunk)): 53 for j, c in enumerate(chunk):
54 try: 54 try:
55 acc = acc * 85 + _b85dec[chunk[j]] 55 acc = acc * 85 + _b85dec[c]
56 except KeyError: 56 except KeyError:
57 raise TypeError('Bad base85 character at byte %d' % (i + j)) 57 raise TypeError('Bad base85 character at byte %d' % (i + j))
58 if acc > 4294967295: 58 if acc > 4294967295:
59 raise OverflowError('Base85 overflow in hunk starting at byte %d' % i) 59 raise OverflowError('Base85 overflow in hunk starting at byte %d' % i)
60 out.append(acc) 60 out.append(acc)