<commit_before>

import logging
import re

from lxml import etree
from xblock.fields import Scope, String
from xmodule.editing_module import XMLEditingDescriptor
from xmodule.xml_module import XmlDescriptor

from .exceptions import SerializationError

log = logging.getLogger(__name__)

PRE_TAG_REGEX = re.compile(r'<pre>[\s\S]*?</pre>')


class RawMixin(object):
    """
    Common code between RawDescriptor and XBlocks converted from XModules.
    """
    resources_dir = None

    data = String(help="XML data for the module", default="", scope=Scope.content)

    @classmethod
    def definition_from_xml(cls, xml_object, system):
        pre_tag_data = [etree.tostring(pre_tag_info) for pre_tag_info in xml_object.findall('pre')]
        data = etree.tostring(xml_object, pretty_print=True, encoding='unicode')
        if pre_tag_data:<commit_msg>use xpath instead of tag to get all matches from subtree instead of subelements.<commit_after>

import logging
import re

from lxml import etree
from xblock.fields import Scope, String
from xmodule.editing_module import XMLEditingDescriptor
from xmodule.xml_module import XmlDescriptor

from .exceptions import SerializationError

log = logging.getLogger(__name__)

PRE_TAG_REGEX = re.compile(r'<pre>[\s\S]*?</pre>')


class RawMixin(object):
    """
    Common code between RawDescriptor and XBlocks converted from XModules.
    """
    resources_dir = None

    data = String(help="XML data for the module", default="", scope=Scope.content)

    @classmethod
    def definition_from_xml(cls, xml_object, system):
        pre_tag_data = [etree.tostring(pre_tag_info) for pre_tag_info in xml_object.findall('.//pre')]
        data = etree.tostring(xml_object, pretty_print=True, encoding='unicode')
        if pre_tag_data:
{'fraction_non_alphanumeric': 0.09346846846846847, 'fraction_numerical': 0.0, 'mean_word_length': 4.588050314465409, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6633145', 'n_tokens_mistral': 556, 'n_tokens_neox': 549, 'n_words': 148}