reimplement Fingerprint __pretty__ better
This commit is contained in:
@@ -8,7 +8,6 @@ import binascii
|
|||||||
import bisect
|
import bisect
|
||||||
import codecs
|
import codecs
|
||||||
import collections
|
import collections
|
||||||
import itertools
|
|
||||||
import operator
|
import operator
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@@ -680,12 +679,11 @@ class Fingerprint(str):
|
|||||||
if not bool(re.match(r'^[A-F0-9]{40}$', content)):
|
if not bool(re.match(r'^[A-F0-9]{40}$', content)):
|
||||||
raise ValueError("Expected: String of 40 hex digits")
|
raise ValueError("Expected: String of 40 hex digits")
|
||||||
|
|
||||||
# store in the format: "AAAA BBBB CCCC DDDD EEEE FFFF 0000 1111 2222 3333"
|
halves = [
|
||||||
# ^^ note 2 spaces here
|
[content[i:i+4] for i in range(0, 20, 4)],
|
||||||
spaces = [ ' ' if i != 4 else ' ' for i in range(10) ]
|
[content[i:i+4] for i in range(20, 40, 4)]
|
||||||
chunks = [ ''.join(g) for g in itertools.zip_longest(*[iter(content)] * 4) ]
|
]
|
||||||
content = ''.join(j for i in itertools.zip_longest(chunks, spaces, fillvalue='') for j in i).strip()
|
return ' '.join(' '.join(c for c in half) for half in halves)
|
||||||
return content
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.__class__.__name__+"("+repr(self.__pretty__())+")"
|
return self.__class__.__name__+"("+repr(self.__pretty__())+")"
|
||||||
|
|||||||
Reference in New Issue
Block a user