|
1 | 1 | import importlib |
| 2 | +import importlib.resources |
2 | 3 | from string import Template |
3 | 4 |
|
4 | 5 | import cornice |
5 | 6 | import cornice_swagger |
6 | | -import pkg_resources |
7 | 7 | from pyramid.response import Response |
8 | 8 |
|
9 | 9 |
|
@@ -33,8 +33,10 @@ def swagger_ui_template_view(request): |
33 | 33 | package, callable = script_generator.split(":") |
34 | 34 | imported_package = importlib.import_module(package) |
35 | 35 | script_callable = getattr(imported_package, callable) |
36 | | - template = pkg_resources.resource_string("cornice_swagger", "templates/index.html").decode( |
37 | | - "utf8" |
| 36 | + template = ( |
| 37 | + importlib.resources.files("cornice_swagger") |
| 38 | + .joinpath("templates/index.html") |
| 39 | + .read_text(encoding="utf-8") |
38 | 40 | ) |
39 | 41 |
|
40 | 42 | html = Template(template).safe_substitute( |
@@ -70,9 +72,11 @@ def swagger_ui_script_template(request, **kwargs): |
70 | 72 | into index template |
71 | 73 | """ |
72 | 74 | swagger_spec_url = request.route_url("cornice_swagger.open_api_path") |
73 | | - template = pkg_resources.resource_string( |
74 | | - "cornice_swagger", "templates/index_script_template.html" |
75 | | - ).decode("utf8") |
| 75 | + template = ( |
| 76 | + importlib.resources.files("cornice_swagger") |
| 77 | + .joinpath("templates/index_script_template.html") |
| 78 | + .read_text(encoding="utf-8") |
| 79 | + ) |
76 | 80 | return Template(template).safe_substitute( |
77 | 81 | swagger_spec_url=swagger_spec_url, |
78 | 82 | ) |
0 commit comments