mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-10 02:18:41 +00:00
[Lint] Use Black to auto-format code
The move to using auto-formatter makes it easier to read, submit and speeds up development time. https://github.com/ambv/black/ Although I would prefer 79 chars, the default line length of 88 chars used by black suffices. The flake8 line length remains at 120 chars since black does not touch comments or docstrings and this will require another round of fixes. The only black setting that is not standard is the use of double-quotes for strings so disabled any formatting of these. Note however that flake8 will still flag usage of double-quotes. I may change my mind on double vs single quotes but for now leave them. A new pyproject.toml file has been created for black configuration.
This commit is contained in:
parent
bcca07443c
commit
b1cdc32f73
233 changed files with 9460 additions and 4112 deletions
35
msgfmt.py
35
msgfmt.py
|
@ -68,8 +68,14 @@ def generate():
|
|||
for _id in keys:
|
||||
# For each string, we need size and file offset when encoded. Each string is NUL
|
||||
# terminated; the NUL does not count into the size.
|
||||
offsets.append((len(ids.encode('utf8')), len(_id.encode('utf8')),
|
||||
len(strs.encode('utf8')), len(MESSAGES[_id].encode('utf8'))))
|
||||
offsets.append(
|
||||
(
|
||||
len(ids.encode('utf8')),
|
||||
len(_id.encode('utf8')),
|
||||
len(strs.encode('utf8')),
|
||||
len(MESSAGES[_id].encode('utf8')),
|
||||
)
|
||||
)
|
||||
ids += _id + '\x00'
|
||||
strs += MESSAGES[_id] + '\x00'
|
||||
|
||||
|
@ -87,13 +93,16 @@ def generate():
|
|||
koffsets += [l1, o1 + keystart]
|
||||
voffsets += [l2, o2 + valuestart]
|
||||
offsets = koffsets + voffsets
|
||||
output = struct.pack('Iiiiiii',
|
||||
0x950412de, # Magic
|
||||
0, # Version
|
||||
len(keys), # # of entries
|
||||
7 * 4, # start of key index
|
||||
7 * 4 + len(keys) * 8, # start of value index
|
||||
0, 0) # size and offset of hash table
|
||||
output = struct.pack(
|
||||
'Iiiiiii',
|
||||
0x950412DE, # Magic
|
||||
0, # Version
|
||||
len(keys), # # of entries
|
||||
7 * 4, # start of key index
|
||||
7 * 4 + len(keys) * 8, # start of value index
|
||||
0,
|
||||
0,
|
||||
) # size and offset of hash table
|
||||
if sys.version_info.major == 2:
|
||||
output += array.array(b'i', offsets).tostring()
|
||||
else:
|
||||
|
@ -119,6 +128,7 @@ def make(filename, outfile):
|
|||
|
||||
try:
|
||||
import io
|
||||
|
||||
with io.open(infile, encoding='utf8') as _file:
|
||||
lines = _file.readlines()
|
||||
except IOError as msg:
|
||||
|
@ -165,7 +175,7 @@ def make(filename, outfile):
|
|||
if not line.startswith('[0]'):
|
||||
msgstr += '\x00'
|
||||
# Ignore the index - must come in sequence
|
||||
line = line[line.index(']') + 1:]
|
||||
line = line[line.index(']') + 1 :]
|
||||
# Skip empty lines
|
||||
line = line.strip()
|
||||
if not line:
|
||||
|
@ -198,8 +208,9 @@ def make(filename, outfile):
|
|||
|
||||
def main():
|
||||
try:
|
||||
opts, args = getopt.getopt(sys.argv[1:], 'hVo:',
|
||||
['help', 'version', 'output-file='])
|
||||
opts, args = getopt.getopt(
|
||||
sys.argv[1:], 'hVo:', ['help', 'version', 'output-file=']
|
||||
)
|
||||
except getopt.error as msg:
|
||||
usage(1, msg)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue