Lint fixes

This commit is contained in:
Andrew Murray 2020-04-04 15:02:02 +11:00
parent b685c18e95
commit 4500acb274

View File

@ -19,11 +19,8 @@
import io import io
import os import os
import shutil
import struct import struct
import subprocess
import sys import sys
import tempfile
from PIL import Image, ImageFile, PngImagePlugin from PIL import Image, ImageFile, PngImagePlugin
from PIL._binary import i8 from PIL._binary import i8
@ -304,13 +301,13 @@ class IcnsImageFile(ImageFile.ImageFile):
def to_int(s): def to_int(s):
b = s.encode('ascii') b = s.encode("ascii")
return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3] return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]
MAGIC = to_int("icns") MAGIC = to_int("icns")
HEADER_SIZE = 8 HEADER_SIZE = 8
TOC = 'TOC ' TOC = "TOC "
def _save(im, fp, filename): def _save(im, fp, filename):
@ -325,37 +322,35 @@ def _save(im, fp, filename):
# size # size
sizes = [128, 256, 512, 32, 64, 256, 512, 1024] sizes = [128, 256, 512, 32, 64, 256, 512, 1024]
size_str = ['ic07', 'ic08', 'ic09', 'ic11', 'ic12', 'ic13', 'ic14', 'ic10'] size_str = ["ic07", "ic08", "ic09", "ic11", "ic12", "ic13", "ic14", "ic10"]
file_size = 0 file_size = 0
entries = [] entries = []
for index, s in enumerate(sizes): for index, s in enumerate(sizes):
temp = io.BytesIO() temp = io.BytesIO()
nb = im.resize((s, s)) nb = im.resize((s, s))
nb.save(temp, 'png') nb.save(temp, "png")
file_size += len(temp.getvalue()) file_size += len(temp.getvalue())
entries.append({ entries.append(
'type': size_str[index], {"type": size_str[index], "size": len(temp.getvalue()), "stream": temp}
'size': len(temp.getvalue()), )
'stream': temp
})
# Header # Header
fp.write(struct.pack('i', MAGIC)[::-1]) fp.write(struct.pack("i", MAGIC)[::-1])
fp.write(struct.pack('i', file_size)[::-1]) fp.write(struct.pack("i", file_size)[::-1])
# TOC # TOC
toc_size = HEADER_SIZE + (len(entries) * HEADER_SIZE) toc_size = HEADER_SIZE + (len(entries) * HEADER_SIZE)
fp.write(struct.pack('i', to_int(TOC))[::-1]) fp.write(struct.pack("i", to_int(TOC))[::-1])
fp.write(struct.pack('i', toc_size)[::-1]) fp.write(struct.pack("i", toc_size)[::-1])
for e in entries: for e in entries:
fp.write(struct.pack('i', to_int(e.get('type')))[::-1]) fp.write(struct.pack("i", to_int(e.get("type")))[::-1])
fp.write(struct.pack('i', HEADER_SIZE + e.get('size'))[::-1]) fp.write(struct.pack("i", HEADER_SIZE + e.get("size"))[::-1])
# Data # Data
for index, e in enumerate(entries): for index, e in enumerate(entries):
fp.write(struct.pack('i', to_int(e.get('type')))[::-1]) fp.write(struct.pack("i", to_int(e.get("type")))[::-1])
fp.write(struct.pack('i', HEADER_SIZE + e.get('size'))[::-1]) fp.write(struct.pack("i", HEADER_SIZE + e.get("size"))[::-1])
fp.write(e.get('stream').getvalue()) fp.write(e.get("stream").getvalue())
fp.flush() fp.flush()