Browse Source

Replace cached_property with the stdlib one

pull/449/head
Simon Conseil 4 years ago
parent
commit
441388cf8f
  1. 2
      sigal/gallery.py
  2. 2
      sigal/plugins/zip_gallery.py
  3. 21
      sigal/utils.py

2
sigal/gallery.py

@ -33,6 +33,7 @@ import random
import sys
from collections import defaultdict
from datetime import datetime
from functools import cached_property
from itertools import cycle
from os.path import isfile, join, splitext
from urllib.parse import quote as url_quote
@ -46,7 +47,6 @@ from .image import get_exif_tags, get_image_metadata, get_size, process_image
from .settings import Status, get_thumb
from .utils import (
Devnull,
cached_property,
check_or_create_dir,
copy,
get_mime,

2
sigal/plugins/zip_gallery.py

@ -34,11 +34,11 @@ See :ref:`compatibility with the encrypt plugin <compatibility-with-encrypt>`.
import logging
import os
import zipfile
from functools import cached_property
from os.path import isfile, join
from sigal import signals
from sigal.gallery import Album
from sigal.utils import cached_property
logger = logging.getLogger(__name__)

21
sigal/utils.py

@ -119,24 +119,3 @@ def is_valid_html5_video(ext):
def get_mime(ext):
"""Returns mime type for extension."""
return VIDEO_MIMES[ext]
class cached_property:
"""A property that is only computed once per instance and then replaces
itself with an ordinary attribute. Deleting the attribute resets the
property.
Source:
https://github.com/pydanny/cached-property (BSD Licensed)
https://github.com/bottlepy/bottle/commit/fa7733e075da0d790d809aa3d2f53071897e6f76
"""
def __init__(self, func):
self.__doc__ = getattr(func, '__doc__')
self.func = func
def __get__(self, obj, cls):
if obj is None:
return self
value = obj.__dict__[self.func.__name__] = self.func(obj)
return value

Loading…
Cancel
Save