Skip to content

Commit d08964b

Browse files
authored
Merge pull request #101 from mrf345/testing
Fix decorators cache skipping. Add parser and cache abstract base classes
2 parents 844db5a + e5594d1 commit d08964b

File tree

5 files changed

+43
-7
lines changed

5 files changed

+43
-7
lines changed

flask_minify/about.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.49"
1+
__version__ = "0.50"
22
__doc__ = "Flask extension to minify html, css, js and less."
33
__license__ = "MIT"
44
__author__ = "Mohamed Feddad"

flask_minify/cache.py

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
1+
from abc import ABCMeta, abstractmethod
2+
13
from flask_minify.utils import get_optimized_hashing
24

35

4-
class MemoryCache:
5-
def __init__(self, store_key_getter=None, limit=0):
6+
class CacheBase(metaclass=ABCMeta):
7+
def __init__(self, store_key_getter=None):
68
self.store_key_getter = store_key_getter
9+
10+
@abstractmethod
11+
def __getitem__(self, key):
12+
pass
13+
14+
@abstractmethod
15+
def __setitem__(self, key, value):
16+
pass
17+
18+
@abstractmethod
19+
def get_or_set(self, key, getter):
20+
pass
21+
22+
@abstractmethod
23+
def clear(self):
24+
pass
25+
26+
27+
class MemoryCache(CacheBase):
28+
def __init__(self, store_key_getter=None, limit=0):
29+
super().__init__(store_key_getter)
730
self.limit = limit
8-
self._cache = {}
931
self.hashing = get_optimized_hashing()
32+
self._cache = {}
1033

1134
@property
1235
def store(self):

flask_minify/decorators.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def minify(
3939
-------
4040
String of minified HTML content.
4141
"""
42-
caching = MemoryCache(caching_limit if cache else 0)
42+
caching = MemoryCache(limit=caching_limit if cache else 0)
4343
parser = Parser(parsers, fail_safe, go=go)
4444
parser.update_runtime_options(html, js, cssless)
4545

flask_minify/parsers.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from abc import ABCMeta, abstractmethod
12
from functools import lru_cache
23
from io import StringIO
4+
from typing import Any, Dict
35

46
from htmlmin import minify as minify_html
57
from jsmin import jsmin
@@ -15,7 +17,18 @@
1517
from flask_minify.utils import get_tag_contents
1618

1719

18-
class ParserMixin:
20+
class ParserBase(metaclass=ABCMeta):
21+
@property
22+
@abstractmethod
23+
def runtime_options(self) -> Dict[str, Any]:
24+
pass
25+
26+
@abstractmethod
27+
def executer(self, *args, **kwargs):
28+
pass
29+
30+
31+
class ParserMixin(ParserBase):
1932
# parser specific runtime option will take precedence over global
2033
takes_precedence = False
2134
go = False

noxfile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
@nox.session(python=__supported_versions__) # type: ignore
19-
def test(session: nox.session):
19+
def test(session: nox.Session):
2020
session.install("-r", test_req_path)
2121
session.run("python", "-m", "pytest")
2222
session.run("python", "-m", "bandit", "-c", "bandit.yml", "-r", ".")

0 commit comments

Comments
 (0)