diff --git a/sample_xblocks/filethumbs/filethumbs.py b/sample_xblocks/filethumbs/filethumbs.py index 80bbef4a..dc686711 100644 --- a/sample_xblocks/filethumbs/filethumbs.py +++ b/sample_xblocks/filethumbs/filethumbs.py @@ -17,12 +17,10 @@ """ - - import json import logging -import pkg_resources +import importlib_resources import png from web_fragments.fragment import Fragment from xblock.core import XBlock @@ -72,8 +70,7 @@ def student_view(self, context=None): # pylint: disable=W0613 """ # Load the HTML fragment from within the package and fill in the template - html_str = pkg_resources.resource_string(__name__, - "static/html/thumbs.html").decode('utf-8') + html_str = importlib_resources.files(__name__).joinpath("static/html/thumbs.html").read_text() frag = Fragment(str(html_str)) if not self.fs.exists("thumbsvotes.json"): @@ -86,12 +83,10 @@ def student_view(self, context=None): # pylint: disable=W0613 self.downvotes = votes['down'] # Load the CSS and JavaScript fragments from within the package - css_str = pkg_resources.resource_string(__name__, - "static/css/thumbs.css").decode('utf-8') + css_str = importlib_resources.files(__name__).joinpath("static/css/thumbs.css").read_text() frag.add_css(str(css_str)) - js_str = pkg_resources.resource_string(__name__, - "static/js/src/thumbs.js").decode('utf-8') + js_str = importlib_resources.files(__name__).joinpath("static/js/src/thumbs.js").read_text() frag.add_javascript(str(js_str)) with self.fs.open('uparrow.png', 'wb') as file_output: diff --git a/sample_xblocks/thumbs/thumbs.py b/sample_xblocks/thumbs/thumbs.py index e6f9afca..14d93a88 100644 --- a/sample_xblocks/thumbs/thumbs.py +++ b/sample_xblocks/thumbs/thumbs.py @@ -1,10 +1,8 @@ """An XBlock providing thumbs-up/thumbs-down voting.""" - - import logging -import pkg_resources +import importlib_resources from web_fragments.fragment import Fragment from xblock.core import XBlock, XBlockAside from xblock.fields import Boolean, Integer, Scope @@ -36,17 +34,14 @@ def student_view(self, context=None): # pylint: disable=W0613 """ # Load the HTML fragment from within the package and fill in the template - html_str = pkg_resources.resource_string(__name__, - "static/html/thumbs.html").decode('utf-8') + html_str = importlib_resources.files(__name__).joinpath("static/html/thumbs.html").read_text() frag = Fragment(str(html_str).format(block=self)) # Load the CSS and JavaScript fragments from within the package - css_str = pkg_resources.resource_string(__name__, - "static/css/thumbs.css").decode('utf-8') + css_str = importlib_resources.files(__name__).joinpath("static/css/thumbs.css").read_text() frag.add_css(str(css_str)) - js_str = pkg_resources.resource_string(__name__, - "static/js/src/thumbs.js").decode('utf-8') + js_str = importlib_resources.files(__name__).joinpath("static/js/src/thumbs.js").read_text() frag.add_javascript(str(js_str)) frag.initialize_js('ThumbsBlock')