reformat with black

main
parent 7da0a00ef3
commit 042aac71eb
Signed by untrusted user: josch
GPG Key ID: F2CBA5C78FBD83E1

@ -4,48 +4,46 @@ from setuptools import setup
VERSION = "0.3.6" VERSION = "0.3.6"
INSTALL_REQUIRES = ( INSTALL_REQUIRES = (
'Pillow', "Pillow",
'pikepdf', "pikepdf",
) )
setup( setup(
name='img2pdf', name="img2pdf",
version=VERSION, version=VERSION,
author="Johannes 'josch' Schauer", author="Johannes 'josch' Schauer",
author_email='josch@mister-muffin.de', author_email="josch@mister-muffin.de",
description="Convert images to PDF via direct JPEG inclusion.", description="Convert images to PDF via direct JPEG inclusion.",
long_description=open('README.md').read(), long_description=open("README.md").read(),
long_description_content_type='text/markdown', long_description_content_type="text/markdown",
license="LGPL", license="LGPL",
keywords="jpeg pdf converter", keywords="jpeg pdf converter",
classifiers=[ classifiers=[
'Development Status :: 5 - Production/Stable', "Development Status :: 5 - Production/Stable",
'Intended Audience :: Developers', "Intended Audience :: Developers",
'Intended Audience :: Other Audience', "Intended Audience :: Other Audience",
'Environment :: Console', "Environment :: Console",
'Programming Language :: Python', "Programming Language :: Python",
'Programming Language :: Python :: 3', "Programming Language :: Python :: 3",
'Programming Language :: Python :: 3.5', "Programming Language :: Python :: 3.5",
'Programming Language :: Python :: Implementation :: CPython', "Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy", "Programming Language :: Python :: Implementation :: PyPy",
'License :: OSI Approved :: GNU Lesser General Public License v3 ' "License :: OSI Approved :: GNU Lesser General Public License v3 " "(LGPLv3)",
'(LGPLv3)', "Natural Language :: English",
'Natural Language :: English', "Operating System :: OS Independent",
'Operating System :: OS Independent'], ],
url='https://gitlab.mister-muffin.de/josch/img2pdf', url="https://gitlab.mister-muffin.de/josch/img2pdf",
download_url='https://gitlab.mister-muffin.de/josch/img2pdf/repository/' download_url="https://gitlab.mister-muffin.de/josch/img2pdf/repository/"
'archive.tar.gz?ref=' + VERSION, "archive.tar.gz?ref=" + VERSION,
package_dir={"": "src"}, package_dir={"": "src"},
py_modules=['img2pdf', 'jp2'], py_modules=["img2pdf", "jp2"],
include_package_data=True, include_package_data=True,
zip_safe=True, zip_safe=True,
install_requires=INSTALL_REQUIRES, install_requires=INSTALL_REQUIRES,
extras_require={ extras_require={"gui": ("tkinter"),},
'gui': ('tkinter'),
},
entry_points={ entry_points={
"setuptools.installation": ["eggsecutable = img2pdf:main"], "setuptools.installation": ["eggsecutable = img2pdf:main"],
"console_scripts": ["img2pdf = img2pdf:main"], "console_scripts": ["img2pdf = img2pdf:main"],
"gui_scripts": ["img2pdf-gui = img2pdf:gui"], "gui_scripts": ["img2pdf-gui = img2pdf:gui"],
}, },
) )

@ -1306,7 +1306,7 @@ def parse_png(rawdata):
i = 16 i = 16
while i < len(rawdata): while i < len(rawdata):
# once we can require Python >= 3.2 we can use int.from_bytes() instead # once we can require Python >= 3.2 we can use int.from_bytes() instead
n, = struct.unpack(">I", rawdata[i - 8 : i - 4]) (n,) = struct.unpack(">I", rawdata[i - 8 : i - 4])
if i + n > len(rawdata): if i + n > len(rawdata):
raise Exception("invalid png: %d %d %d" % (i, n, len(rawdata))) raise Exception("invalid png: %d %d %d" % (i, n, len(rawdata)))
if rawdata[i - 4 : i] == b"IDAT": if rawdata[i - 4 : i] == b"IDAT":

@ -23,16 +23,16 @@ import struct
def getBox(data, byteStart, noBytes): def getBox(data, byteStart, noBytes):
boxLengthValue = struct.unpack(">I", data[byteStart:byteStart+4])[0] boxLengthValue = struct.unpack(">I", data[byteStart : byteStart + 4])[0]
boxType = data[byteStart+4:byteStart+8] boxType = data[byteStart + 4 : byteStart + 8]
contentsStartOffset = 8 contentsStartOffset = 8
if boxLengthValue == 1: if boxLengthValue == 1:
boxLengthValue = struct.unpack(">Q", data[byteStart+8:byteStart+16])[0] boxLengthValue = struct.unpack(">Q", data[byteStart + 8 : byteStart + 16])[0]
contentsStartOffset = 16 contentsStartOffset = 16
if boxLengthValue == 0: if boxLengthValue == 0:
boxLengthValue = noBytes-byteStart boxLengthValue = noBytes - byteStart
byteEnd = byteStart + boxLengthValue byteEnd = byteStart + boxLengthValue
boxContents = data[byteStart+contentsStartOffset:byteEnd] boxContents = data[byteStart + contentsStartOffset : byteEnd]
return (boxLengthValue, boxType, byteEnd, boxContents) return (boxLengthValue, boxType, byteEnd, boxContents)
@ -52,14 +52,15 @@ def parse_colr(data):
elif enumCS == 17: elif enumCS == 17:
return "L" return "L"
else: else:
raise Exception("only sRGB and greyscale color space is supported, " raise Exception(
"got %d" % enumCS) "only sRGB and greyscale color space is supported, " "got %d" % enumCS
)
def parse_resc(data): def parse_resc(data):
hnum, hden, vnum, vden, hexp, vexp = struct.unpack(">HHHHBB", data) hnum, hden, vnum, vden, hexp, vexp = struct.unpack(">HHHHBB", data)
hdpi = ((hnum/hden) * (10**hexp) * 100)/2.54 hdpi = ((hnum / hden) * (10 ** hexp) * 100) / 2.54
vdpi = ((vnum/vden) * (10**vexp) * 100)/2.54 vdpi = ((vnum / vden) * (10 ** vexp) * 100) / 2.54
return hdpi, vdpi return hdpi, vdpi
@ -69,9 +70,8 @@ def parse_res(data):
byteStart = 0 byteStart = 0
boxLengthValue = 1 # dummy value for while loop condition boxLengthValue = 1 # dummy value for while loop condition
while byteStart < noBytes and boxLengthValue != 0: while byteStart < noBytes and boxLengthValue != 0:
boxLengthValue, boxType, byteEnd, boxContents = \ boxLengthValue, boxType, byteEnd, boxContents = getBox(data, byteStart, noBytes)
getBox(data, byteStart, noBytes) if boxType == b"resc":
if boxType == b'resc':
hdpi, vdpi = parse_resc(boxContents) hdpi, vdpi = parse_resc(boxContents)
break break
return hdpi, vdpi return hdpi, vdpi
@ -83,13 +83,12 @@ def parse_jp2h(data):
byteStart = 0 byteStart = 0
boxLengthValue = 1 # dummy value for while loop condition boxLengthValue = 1 # dummy value for while loop condition
while byteStart < noBytes and boxLengthValue != 0: while byteStart < noBytes and boxLengthValue != 0:
boxLengthValue, boxType, byteEnd, boxContents = \ boxLengthValue, boxType, byteEnd, boxContents = getBox(data, byteStart, noBytes)
getBox(data, byteStart, noBytes) if boxType == b"ihdr":
if boxType == b'ihdr':
width, height = parse_ihdr(boxContents) width, height = parse_ihdr(boxContents)
elif boxType == b'colr': elif boxType == b"colr":
colorspace = parse_colr(boxContents) colorspace = parse_colr(boxContents)
elif boxType == b'res ': elif boxType == b"res ":
hdpi, vdpi = parse_res(boxContents) hdpi, vdpi = parse_res(boxContents)
byteStart = byteEnd byteStart = byteEnd
return (width, height, colorspace, hdpi, vdpi) return (width, height, colorspace, hdpi, vdpi)
@ -101,9 +100,8 @@ def parsejp2(data):
boxLengthValue = 1 # dummy value for while loop condition boxLengthValue = 1 # dummy value for while loop condition
width, height, colorspace, hdpi, vdpi = None, None, None, None, None width, height, colorspace, hdpi, vdpi = None, None, None, None, None
while byteStart < noBytes and boxLengthValue != 0: while byteStart < noBytes and boxLengthValue != 0:
boxLengthValue, boxType, byteEnd, boxContents = \ boxLengthValue, boxType, byteEnd, boxContents = getBox(data, byteStart, noBytes)
getBox(data, byteStart, noBytes) if boxType == b"jp2h":
if boxType == b'jp2h':
width, height, colorspace, hdpi, vdpi = parse_jp2h(boxContents) width, height, colorspace, hdpi, vdpi = parse_jp2h(boxContents)
break break
byteStart = byteEnd byteStart = byteEnd
@ -119,6 +117,7 @@ def parsejp2(data):
if __name__ == "__main__": if __name__ == "__main__":
import sys import sys
width, height, colorspace = parsejp2(open(sys.argv[1]).read()) width, height, colorspace = parsejp2(open(sys.argv[1]).read())
sys.stdout.write("width = %d" % width) sys.stdout.write("width = %d" % width)
sys.stdout.write("height = %d" % height) sys.stdout.write("height = %d" % height)

Loading…
Cancel
Save