mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Flake8 fixes
This commit is contained in:
parent
31524b2e6b
commit
a5bac62bc3
|
@ -227,6 +227,7 @@ def _limit_rational(val, max_val):
|
||||||
_load_dispatch = {}
|
_load_dispatch = {}
|
||||||
_write_dispatch = {}
|
_write_dispatch = {}
|
||||||
|
|
||||||
|
|
||||||
class ImageFileDirectory_v2(collections.MutableMapping):
|
class ImageFileDirectory_v2(collections.MutableMapping):
|
||||||
"""This class represents a TIFF tag directory. To speed things up, we
|
"""This class represents a TIFF tag directory. To speed things up, we
|
||||||
don't decode tags unless they're asked for.
|
don't decode tags unless they're asked for.
|
||||||
|
@ -395,7 +396,7 @@ class ImageFileDirectory_v2(collections.MutableMapping):
|
||||||
self.tagtype[tag] = 2
|
self.tagtype[tag] = 2
|
||||||
|
|
||||||
if self.tagtype[tag] == 7 and bytes is not str:
|
if self.tagtype[tag] == 7 and bytes is not str:
|
||||||
values = [value.encode("ascii",'replace') if isinstance(value, str) else value
|
values = [value.encode("ascii", 'replace') if isinstance(value, str) else value
|
||||||
for value in values]
|
for value in values]
|
||||||
|
|
||||||
values = tuple(info.cvt_enum(value) for value in values)
|
values = tuple(info.cvt_enum(value) for value in values)
|
||||||
|
@ -521,8 +522,8 @@ class ImageFileDirectory_v2(collections.MutableMapping):
|
||||||
self._offset = fp.tell()
|
self._offset = fp.tell()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for i in range(self._unpack("H", self._ensure_read(fp,2))[0]):
|
for i in range(self._unpack("H", self._ensure_read(fp, 2))[0]):
|
||||||
tag, typ, count, data = self._unpack("HHL4s", self._ensure_read(fp,12))
|
tag, typ, count, data = self._unpack("HHL4s", self._ensure_read(fp, 12))
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
tagname = TAGS_V2.get(tag, TagInfo()).name
|
tagname = TAGS_V2.get(tag, TagInfo()).name
|
||||||
typname = TYPES.get(typ, "unknown")
|
typname = TYPES.get(typ, "unknown")
|
||||||
|
@ -563,7 +564,7 @@ class ImageFileDirectory_v2(collections.MutableMapping):
|
||||||
else:
|
else:
|
||||||
print("- value:", self[tag])
|
print("- value:", self[tag])
|
||||||
|
|
||||||
self.next, = self._unpack("L", self._ensure_read(fp,4))
|
self.next, = self._unpack("L", self._ensure_read(fp, 4))
|
||||||
except IOError as msg:
|
except IOError as msg:
|
||||||
warnings.warn(str(msg))
|
warnings.warn(str(msg))
|
||||||
return
|
return
|
||||||
|
@ -644,7 +645,8 @@ for idx, name in TYPES.items():
|
||||||
setattr(ImageFileDirectory_v2, "write_" + name, _write_dispatch[idx])
|
setattr(ImageFileDirectory_v2, "write_" + name, _write_dispatch[idx])
|
||||||
del _load_dispatch, _write_dispatch, idx, name
|
del _load_dispatch, _write_dispatch, idx, name
|
||||||
|
|
||||||
#Legacy ImageFileDirectory support.
|
|
||||||
|
# Legacy ImageFileDirectory support.
|
||||||
class ImageFileDirectory_v1(ImageFileDirectory_v2):
|
class ImageFileDirectory_v1(ImageFileDirectory_v2):
|
||||||
"""This class represents the **legacy** interface to a TIFF tag directory.
|
"""This class represents the **legacy** interface to a TIFF tag directory.
|
||||||
|
|
||||||
|
@ -665,8 +667,8 @@ class ImageFileDirectory_v1(ImageFileDirectory_v2):
|
||||||
"""
|
"""
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
ImageFileDirectory_v2.__init__(self, *args, **kwargs)
|
ImageFileDirectory_v2.__init__(self, *args, **kwargs)
|
||||||
self._legacy_api=True
|
self._legacy_api = True
|
||||||
#insert deprecation warning here.
|
# insert deprecation warning here.
|
||||||
|
|
||||||
tags = property(lambda self: self._tags_v1)
|
tags = property(lambda self: self._tags_v1)
|
||||||
tagdata = property(lambda self: self._tagdata)
|
tagdata = property(lambda self: self._tagdata)
|
||||||
|
@ -716,7 +718,7 @@ class ImageFileDirectory_v1(ImageFileDirectory_v2):
|
||||||
return iter(set(self._tagdata) | set(self._tags_v1))
|
return iter(set(self._tagdata) | set(self._tags_v1))
|
||||||
|
|
||||||
def __setitem__(self, tag, value):
|
def __setitem__(self, tag, value):
|
||||||
for legacy_api in (False,True):
|
for legacy_api in (False, True):
|
||||||
self._setitem(tag, value, legacy_api)
|
self._setitem(tag, value, legacy_api)
|
||||||
|
|
||||||
def __getitem__(self, tag):
|
def __getitem__(self, tag):
|
||||||
|
@ -735,6 +737,7 @@ class ImageFileDirectory_v1(ImageFileDirectory_v2):
|
||||||
# undone -- switch this pointer when IFD_LEGACY_API == False
|
# undone -- switch this pointer when IFD_LEGACY_API == False
|
||||||
ImageFileDirectory = ImageFileDirectory_v1
|
ImageFileDirectory = ImageFileDirectory_v1
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Image plugin for TIFF files.
|
# Image plugin for TIFF files.
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
|
||||||
class TagInfo(namedtuple("_TagInfo", "value name type length enum")):
|
class TagInfo(namedtuple("_TagInfo", "value name type length enum")):
|
||||||
__slots__ = []
|
__slots__ = []
|
||||||
|
|
||||||
|
@ -278,7 +279,7 @@ TAGS = {347: 'JPEGTables',
|
||||||
50740: 'DNGPrivateData',
|
50740: 'DNGPrivateData',
|
||||||
50778: 'CalibrationIlluminant1',
|
50778: 'CalibrationIlluminant1',
|
||||||
50779: 'CalibrationIlluminant2',
|
50779: 'CalibrationIlluminant2',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _populate():
|
def _populate():
|
||||||
|
@ -312,4 +313,3 @@ TYPES = {}
|
||||||
# 11: "float",
|
# 11: "float",
|
||||||
# 12: "double",
|
# 12: "double",
|
||||||
# }
|
# }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user