--- a/mercurial/pure/base85.py Sat Oct 05 10:29:34 2019 -0400
+++ b/mercurial/pure/base85.py Sun Oct 06 09:45:02 2019 -0400
@@ -11,15 +11,19 @@
from .. import pycompat
-_b85chars = pycompat.bytestr("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef"
- "ghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~")
+_b85chars = pycompat.bytestr(
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef"
+ "ghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~"
+)
_b85chars2 = [(a + b) for a in _b85chars for b in _b85chars]
_b85dec = {}
+
def _mkb85dec():
for i, c in enumerate(_b85chars):
_b85dec[c] = i
+
def b85encode(text, pad=False):
"""encode text in base85 format"""
l = len(text)
@@ -27,12 +31,14 @@
if r:
text += '\0' * (4 - r)
longs = len(text) >> 2
- words = struct.unpack('>%dL' % (longs), text)
+ words = struct.unpack('>%dL' % longs, text)
- out = ''.join(_b85chars[(word // 52200625) % 85] +
- _b85chars2[(word // 7225) % 7225] +
- _b85chars2[word % 7225]
- for word in words)
+ out = ''.join(
+ _b85chars[(word // 52200625) % 85]
+ + _b85chars2[(word // 7225) % 7225]
+ + _b85chars2[word % 7225]
+ for word in words
+ )
if pad:
return out
@@ -44,6 +50,7 @@
olen += l // 4 * 5
return out[:olen]
+
def b85decode(text):
"""decode base85-encoded text"""
if not _b85dec:
@@ -52,15 +59,16 @@
l = len(text)
out = []
for i in range(0, len(text), 5):
- chunk = text[i:i + 5]
+ chunk = text[i : i + 5]
chunk = pycompat.bytestr(chunk)
acc = 0
for j, c in enumerate(chunk):
try:
acc = acc * 85 + _b85dec[c]
except KeyError:
- raise ValueError('bad base85 character at position %d'
- % (i + j))
+ raise ValueError(
+ 'bad base85 character at position %d' % (i + j)
+ )
if acc > 4294967295:
raise ValueError('Base85 overflow in hunk starting at byte %d' % i)
out.append(acc)
@@ -70,11 +78,11 @@
if cl:
acc *= 85 ** (5 - cl)
if cl > 1:
- acc += 0xffffff >> (cl - 2) * 8
+ acc += 0xFFFFFF >> (cl - 2) * 8
out[-1] = acc
out = struct.pack('>%dL' % (len(out)), *out)
if cl:
- out = out[:-(5 - cl)]
+ out = out[: -(5 - cl)]
return out