Minor cleanup.
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
from collections import namedtuple
|
||||
from re import compile as RE
|
||||
|
||||
|
||||
Snippet = namedtuple('Snippet', 'sha offset length')
|
||||
_fmt = '{%s %i %i}'
|
||||
|
||||
|
||||
pat = (
|
||||
'{'
|
||||
'\s*'
|
||||
@@ -14,14 +16,18 @@ pat = (
|
||||
'\s*'
|
||||
'}'
|
||||
)
|
||||
|
||||
|
||||
_PAT = RE(pat)
|
||||
|
||||
|
||||
def to_string(snip):
|
||||
return _fmt % _ts(*snip)
|
||||
return _ts(*snip)
|
||||
|
||||
|
||||
def _ts(sha, offset, length):
|
||||
return sha.decode('ascii'), offset, length
|
||||
return f'{{{sha.decode("ascii")} {offset} {length}}}'
|
||||
|
||||
|
||||
def from_string(text):
|
||||
m = _PAT.match(text)
|
||||
@@ -29,5 +35,6 @@ def from_string(text):
|
||||
raise ValueError
|
||||
return _fs(**m.groupdict())
|
||||
|
||||
|
||||
def _fs(sha, offset, length):
|
||||
return Snippet(sha.encode('ascii'), int(offset), int(length))
|
||||
|
||||
Reference in New Issue
Block a user