Skip to content

Commit 2ad1be0

Browse files
committed
refactor: delegate load_definition_xml to Runtime
1 parent 12e8032 commit 2ad1be0

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

xblock/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from xblock.internal import class_lazy
2525
from xblock.plugin import Plugin
2626
from xblock.validation import Validation
27-
from xblock.xml import is_pointer_tag, load_definition_xml
27+
from xblock.xml import is_pointer_tag
2828

2929
# OrderedDict is used so that namespace attributes are put in predictable order
3030
# This allows for simple string equality assertions in tests and have no other effects
@@ -749,7 +749,7 @@ def parse_xml(cls, node, runtime, keys):
749749
will store its data.
750750
"""
751751
if is_pointer_tag(node):
752-
node, _ = load_definition_xml(node, runtime, keys.def_id)
752+
node, _ = runtime.load_definition_xml(node, keys.def_id)
753753

754754
block = runtime.construct_xblock_from_class(cls, keys)
755755

xblock/runtime.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
FieldDataDeprecationWarning,
3232
UserIdDeprecationWarning,
3333
)
34+
from xblock.xml import format_filepath, load_file, name_to_pathname
3435

3536
log = logging.getLogger(__name__)
3637

@@ -792,6 +793,24 @@ def add_block_as_child_node(self, block, node):
792793
child = etree.SubElement(node, "unknown")
793794
block.add_xml_to_node(child)
794795

796+
def load_definition_xml(self, node, def_id):
797+
"""
798+
Load an XML definition for a block.
799+
This method can be overridden in different runtime environments.
800+
801+
Args:
802+
node: XML element containing attributes for definition loading
803+
def_id: Unique identifier for the definition being loaded
804+
805+
Returns:
806+
tuple: A tuple containing the loaded XML definition and the
807+
corresponding file path or identifier
808+
"""
809+
url_name = node.get('url_name')
810+
filepath = format_filepath(node.tag, name_to_pathname(url_name))
811+
definition_xml = load_file(filepath, self.resources_fs, def_id) # pylint: disable=no-member
812+
return definition_xml, filepath
813+
795814
# Rendering
796815

797816
def render(self, block, view_name, context=None):

xblock/xml.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,6 @@ def is_pointer_tag(xml_obj):
3939
return len(xml_obj) == 0 and actual_attr == expected_attr and not has_text
4040

4141

42-
def load_definition_xml(node, runtime, def_id):
43-
"""
44-
Parses and loads an XML definition file based on a given node, runtime
45-
environment, and definition ID.
46-
47-
Arguments:
48-
node: XML element containing attributes for definition loading.
49-
runtime: The runtime environment that provides resource access.
50-
def_id: Unique identifier for the definition being loaded.
51-
52-
Returns:
53-
tuple: A tuple containing the loaded XML definition and the
54-
corresponding file path.
55-
"""
56-
url_name = node.get('url_name')
57-
filepath = format_filepath(node.tag, name_to_pathname(url_name))
58-
definition_xml = load_file(filepath, runtime.resources_fs, def_id)
59-
return definition_xml, filepath
60-
61-
6242
def format_filepath(category, name):
6343
"""
6444
Construct a formatted filepath string based on the given category and name.

0 commit comments

Comments
 (0)