Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 8883ff5

Browse files
Remove lazy string
1 parent 2b30110 commit 8883ff5

File tree

5 files changed

+4
-159
lines changed

5 files changed

+4
-159
lines changed

ci/tests/suite/test_lazy_string.py

-104
This file was deleted.

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ keywords = ['flask', 'swagger', 'openapi', 'python', 'api', 'rest', 'openapi3']
2424
dependencies = [
2525
"Flask>=2.3.1",
2626
"PyYAML>=6.0",
27-
"jsonschema>=4.17.3",
28-
"mistune>=2.0.4",
27+
"jsonschema>=4.19.0",
28+
"mistune>=3.0.0",
2929
"six>=1.16.0",
3030
]
3131

src/flask_openapi/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
from .base import (
99
BR_SANITIZER,
1010
Flasgger,
11-
LazyJSONEncoder, # noqa
1211
MK_SANITIZER,
1312
NO_SANITIZER,
1413
Swagger,
1514
)
1615
from .constants import OPTIONAL_FIELDS # noqa
1716
from .marshmallow_apispec import APISpec, fields, Schema, SwaggerView # noqa
18-
from .utils import apispec_to_template, LazyString, swag_from, validate # noqa
17+
from .utils import apispec_to_template, swag_from, validate # noqa

src/flask_openapi/base.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
Blueprint,
2222
current_app,
2323
jsonify,
24-
Markup,
2524
redirect,
2625
render_template,
2726
request,
@@ -31,6 +30,7 @@
3130
from json import JSONEncoder
3231
from flask.views import MethodView
3332
from werkzeug.datastructures import Authorization
33+
from markupsafe import Markup
3434

3535
try:
3636
from flask_restful.reqparse import RequestParser
@@ -49,7 +49,6 @@
4949
get_specs,
5050
get_vendor_extension_fields,
5151
is_openapi3,
52-
LazyString,
5352
parse_definition_docstring,
5453
parse_imports,
5554
swag_annotation,
@@ -978,10 +977,3 @@ def is_openapi3(self):
978977

979978
# backwards compatibility
980979
Flasgger = Swagger # noqa
981-
982-
983-
class LazyJSONEncoder(JSONEncoder):
984-
def default(self, obj):
985-
if isinstance(obj, LazyString):
986-
return str(obj)
987-
return super(LazyJSONEncoder, self).default(obj)

src/flask_openapi/utils.py

-42
Original file line numberDiff line numberDiff line change
@@ -927,48 +927,6 @@ def __ge__(self, other):
927927
def text_type(self):
928928
return text_type
929929

930-
931-
class LazyString(StringLike):
932-
"""
933-
A lazy string *without* caching. The resulting string is regenerated for
934-
every request.
935-
"""
936-
937-
def __init__(self, func):
938-
"""
939-
Creates a `LazyString` object using `func` as the delayed closure.
940-
`func` must return a string.
941-
"""
942-
self._func = func
943-
944-
def __str__(self):
945-
"""
946-
Returns the actual string.
947-
"""
948-
return self.text_type(self._func())
949-
950-
951-
class CachedLazyString(LazyString):
952-
"""
953-
A lazy string with caching.
954-
"""
955-
956-
def __init__(self, func):
957-
"""
958-
Uses `__init__()` from the parent and initializes a cache.
959-
"""
960-
super(CachedLazyString, self).__init__(func)
961-
self._cache = None
962-
963-
def __str__(self):
964-
"""
965-
Returns the actual string and caches the result.
966-
"""
967-
if not self._cache:
968-
self._cache = self.text_type(self._func())
969-
return self._cache
970-
971-
972930
def swag_annotation(f):
973931
@wraps(f)
974932
def wrapper(*args, **kwargs):

0 commit comments

Comments
 (0)