Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance: Do not store attribute in TIFF new API #365

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion sigal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from .gallery import Gallery
from .log import init_logging
from .settings import read_settings
from .utils import copy
from .utils import copy, monkey_patch_pil_tiff_imagefiledirectory_v1

try:
__version__ = get_distribution(__name__).version
Expand Down Expand Up @@ -139,6 +139,8 @@ def build(source, destination, debug, verbose, force, config, theme, title,
"directory.")
sys.exit(1)

monkey_patch_pil_tiff_imagefiledirectory_v1()

if title:
settings['title'] = title

Expand Down
24 changes: 24 additions & 0 deletions sigal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,27 @@ def __get__(self, obj, cls):
return self
value = obj.__dict__[self.func.__name__] = self.func(obj)
return value


def monkey_patch_pil_tiff_imagefiledirectory_v1():
'''
Check that **only** legacy api is used
'''
from PIL.TiffImagePlugin import ImageFileDirectory_v1

def __setitem__(self, tag, value):
self._setitem(tag, value, True)

def __getitem__(self, tag):
if tag not in self._tags_v1: # unpack on the fly
data = self._tagdata[tag]
typ = self.tagtype[tag]
size, handler = self._load_dispatch[typ]
self._setitem(tag, handler(self, data, True), True)
val = self._tags_v1[tag]
if not isinstance(val, (tuple, bytes)):
val = val,
return val

ImageFileDirectory_v1.__setitem__ = __setitem__
ImageFileDirectory_v1.__getitem__ = __getitem__