mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 10:16:27 +00:00
Feedback
This commit is contained in:
parent
0674485e76
commit
15548ff433
@ -1 +1 @@
|
|||||||
from .view import ViewImage
|
from .view import ViewImage # noqa
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import io
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from kaitaistruct import KaitaiStream
|
from kaitaistruct import KaitaiStream
|
||||||
@ -6,8 +7,9 @@ from mitmproxy.contrib.kaitaistruct import png
|
|||||||
|
|
||||||
Metadata = typing.List[typing.Tuple[str, str]]
|
Metadata = typing.List[typing.Tuple[str, str]]
|
||||||
|
|
||||||
|
|
||||||
def parse_png(data: bytes) -> Metadata:
|
def parse_png(data: bytes) -> Metadata:
|
||||||
img = png.Png(KaitaiStream(data))
|
img = png.Png(KaitaiStream(io.BytesIO(data)))
|
||||||
parts = [
|
parts = [
|
||||||
('Format', 'Portable network graphics')
|
('Format', 'Portable network graphics')
|
||||||
]
|
]
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import io, imghdr
|
import io
|
||||||
|
import imghdr
|
||||||
|
|
||||||
from PIL import ExifTags
|
from PIL import ExifTags
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
@ -7,7 +8,6 @@ from mitmproxy.types import multidict
|
|||||||
from . import image_parser
|
from . import image_parser
|
||||||
|
|
||||||
from mitmproxy.contentviews import base
|
from mitmproxy.contentviews import base
|
||||||
from kaitaistruct import KaitaiStream
|
|
||||||
|
|
||||||
|
|
||||||
class ViewImage(base.View):
|
class ViewImage(base.View):
|
||||||
@ -24,7 +24,7 @@ class ViewImage(base.View):
|
|||||||
def __call__(self, data, **metadata):
|
def __call__(self, data, **metadata):
|
||||||
if imghdr.what('', h=data) == 'png':
|
if imghdr.what('', h=data) == 'png':
|
||||||
f = "PNG"
|
f = "PNG"
|
||||||
parts = image_parser.parse_png(io.BytesIO(data))
|
parts = image_parser.parse_png(data)
|
||||||
fmt = base.format_dict(multidict.MultiDict(parts))
|
fmt = base.format_dict(multidict.MultiDict(parts))
|
||||||
return "%s image" % f, fmt
|
return "%s image" % f, fmt
|
||||||
try:
|
try:
|
||||||
|
2
setup.py
2
setup.py
@ -71,7 +71,7 @@ setup(
|
|||||||
"html2text>=2016.1.8, <=2016.9.19",
|
"html2text>=2016.1.8, <=2016.9.19",
|
||||||
"hyperframe>=4.0.1, <5",
|
"hyperframe>=4.0.1, <5",
|
||||||
"jsbeautifier>=1.6.3, <1.7",
|
"jsbeautifier>=1.6.3, <1.7",
|
||||||
"kaitaistruct>=0.5",
|
"kaitaistruct>=0.5, <0.6",
|
||||||
"Pillow>=3.2, <4.1",
|
"Pillow>=3.2, <4.1",
|
||||||
"passlib>=1.6.5, <1.8",
|
"passlib>=1.6.5, <1.8",
|
||||||
"pyasn1>=0.1.9, <0.2",
|
"pyasn1>=0.1.9, <0.2",
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import io
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from mitmproxy.contentviews.image import image_parser
|
from mitmproxy.contentviews.image import image_parser
|
||||||
from mitmproxy.test import tutils
|
from mitmproxy.test import tutils
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("filename, metadata", {
|
@pytest.mark.parametrize("filename, metadata", {
|
||||||
# no textual data
|
# no textual data
|
||||||
"mitmproxy/data/png_parser/ct0n0g04.png": [
|
"mitmproxy/data/png_parser/ct0n0g04.png": [
|
||||||
@ -20,7 +19,12 @@ from mitmproxy.test import tutils
|
|||||||
('Title', 'PngSuite'),
|
('Title', 'PngSuite'),
|
||||||
('Author', 'Willem A.J. van Schaik\n(willem@schaik.com)'),
|
('Author', 'Willem A.J. van Schaik\n(willem@schaik.com)'),
|
||||||
('Copyright', 'Copyright Willem van Schaik, Singapore 1995-96'),
|
('Copyright', 'Copyright Willem van Schaik, Singapore 1995-96'),
|
||||||
('Description', 'A compilation of a set of images created to test the\nvarious color-types of the PNG format. Included are\nblack&white, color, paletted, with alpha channel, with\ntransparency formats. All bit-depths allowed according\nto the spec are present.'), ('Software', 'Created on a NeXTstation color using "pnmtopng".'), ('Disclaimer', 'Freeware.')
|
('Description', 'A compilation of a set of images created to test the\n'
|
||||||
|
'various color-types of the PNG format. Included are\nblack&white, color,'
|
||||||
|
' paletted, with alpha channel, with\ntransparency formats. All bit-depths'
|
||||||
|
' allowed according\nto the spec are present.'),
|
||||||
|
('Software', 'Created on a NeXTstation color using "pnmtopng".'),
|
||||||
|
('Disclaimer', 'Freeware.')
|
||||||
],
|
],
|
||||||
# with compressed textual data
|
# with compressed textual data
|
||||||
"mitmproxy/data/png_parser/ctzn0g04.png": [
|
"mitmproxy/data/png_parser/ctzn0g04.png": [
|
||||||
@ -30,7 +34,12 @@ from mitmproxy.test import tutils
|
|||||||
('Title', 'PngSuite'),
|
('Title', 'PngSuite'),
|
||||||
('Author', 'Willem A.J. van Schaik\n(willem@schaik.com)'),
|
('Author', 'Willem A.J. van Schaik\n(willem@schaik.com)'),
|
||||||
('Copyright', 'Copyright Willem van Schaik, Singapore 1995-96'),
|
('Copyright', 'Copyright Willem van Schaik, Singapore 1995-96'),
|
||||||
('Description', 'A compilation of a set of images created to test the\nvarious color-types of the PNG format. Included are\nblack&white, color, paletted, with alpha channel, with\ntransparency formats. All bit-depths allowed according\nto the spec are present.'), ('Software', 'Created on a NeXTstation color using "pnmtopng".'), ('Disclaimer', 'Freeware.')
|
('Description', 'A compilation of a set of images created to test the\n'
|
||||||
|
'various color-types of the PNG format. Included are\nblack&white, color,'
|
||||||
|
' paletted, with alpha channel, with\ntransparency formats. All bit-depths'
|
||||||
|
' allowed according\nto the spec are present.'),
|
||||||
|
('Software', 'Created on a NeXTstation color using "pnmtopng".'),
|
||||||
|
('Disclaimer', 'Freeware.')
|
||||||
],
|
],
|
||||||
# UTF-8 international text - english
|
# UTF-8 international text - english
|
||||||
"mitmproxy/data/png_parser/cten0g04.png": [
|
"mitmproxy/data/png_parser/cten0g04.png": [
|
||||||
@ -40,7 +49,12 @@ from mitmproxy.test import tutils
|
|||||||
('Title', 'PngSuite'),
|
('Title', 'PngSuite'),
|
||||||
('Author', 'Willem van Schaik (willem@schaik.com)'),
|
('Author', 'Willem van Schaik (willem@schaik.com)'),
|
||||||
('Copyright', 'Copyright Willem van Schaik, Canada 2011'),
|
('Copyright', 'Copyright Willem van Schaik, Canada 2011'),
|
||||||
('Description', 'A compilation of a set of images created to test the various color-types of the PNG format. Included are black&white, color, paletted, with alpha channel, with transparency formats. All bit-depths allowed according to the spec are present.'), ('Software', 'Created on a NeXTstation color using "pnmtopng".'), ('Disclaimer', 'Freeware.')
|
('Description', 'A compilation of a set of images created to test the '
|
||||||
|
'various color-types of the PNG format. Included are black&white, color,'
|
||||||
|
' paletted, with alpha channel, with transparency formats. All bit-depths'
|
||||||
|
' allowed according to the spec are present.'),
|
||||||
|
('Software', 'Created on a NeXTstation color using "pnmtopng".'),
|
||||||
|
('Disclaimer', 'Freeware.')
|
||||||
],
|
],
|
||||||
# check gamma value
|
# check gamma value
|
||||||
"mitmproxy/data/png_parser/g07n0g16.png": [
|
"mitmproxy/data/png_parser/g07n0g16.png": [
|
||||||
@ -59,4 +73,4 @@ from mitmproxy.test import tutils
|
|||||||
}.items())
|
}.items())
|
||||||
def test_parse_png(filename, metadata):
|
def test_parse_png(filename, metadata):
|
||||||
with open(tutils.test_data.path(filename), "rb") as f:
|
with open(tutils.test_data.path(filename), "rb") as f:
|
||||||
assert metadata == image_parser.parse_png(io.BytesIO(f.read()))
|
assert metadata == image_parser.parse_png(f.read())
|
||||||
|
Loading…
Reference in New Issue
Block a user