diff options
author | Calum Lind <calumlind@gmail.com> | 2018-10-02 15:39:51 +0100 |
---|---|---|
committer | Calum Lind <calumlind@gmail.com> | 2018-10-03 15:21:53 +0100 |
commit | b1cdc32f7357e9777eb6cc2d90094c7d122af2eb (patch) | |
tree | 9106ac399a7df178c8dbed6fe58009d36b18159a /msgfmt.py | |
parent | bcca07443ccad7f130444baaac52b7b49478905e (diff) | |
download | deluge-b1cdc32f7357e9777eb6cc2d90094c7d122af2eb.tar.gz deluge-b1cdc32f7357e9777eb6cc2d90094c7d122af2eb.tar.bz2 deluge-b1cdc32f7357e9777eb6cc2d90094c7d122af2eb.zip |
[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.
Diffstat (limited to 'msgfmt.py')
-rwxr-xr-x | msgfmt.py | 35 |
1 files changed, 23 insertions, 12 deletions
@@ -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) |