<commit_before>##
# Copyright (c) 2008-2011 Sprymix Inc.
# All rights reserved.
#
# See LICENSE for details.
##


import importlib.abc
import os
import sys

from semantix.utils.lang.meta import LanguageMeta


class Finder(importlib.abc.Finder):
    def find_module(self, fullname, path=None):
        basename = fullname.rpartition('.')[2]

        if path is None:
            path = sys.path

        for p in path:
            test = os.path.join(p, basename)
            is_package = os.path.isdir(test)
            result = LanguageMeta.recognize_file(test, True, is_package)
            if result:
                language, filename = result
                loader = getattr(fullname, 'loader', None)
                if loader is None:
                    loader = language.get_loader()
                return loader(fullname, filename, language)<commit_msg>utils.import: Account for FS case-insensitivity during import<commit_after>##
# Copyright (c) 2008-2012 Sprymix Inc.
# All rights reserved.
#
# See LICENSE for details.
##


import importlib.abc
from importlib import _case_ok
import os
import sys

from semantix.utils.lang.meta import LanguageMeta


class Finder(importlib.abc.Finder):
    def find_module(self, fullname, path=None):
        basename = fullname.rpartition('.')[2]

        if path is None:
            path = sys.path

        for p in path:
            test = os.path.join(p, basename)
            is_package = os.path.isdir(test)
            if is_package:
                if not _case_ok(p, basename):
                    # PEP 235
                    return
            result = LanguageMeta.recognize_file(test, True, is_package)
            if result:
                language, filename = result
                if not is_package:
                    # XXX Language should return the matched extension?
                    # Or this will be buggy with extensions containing
                    # multiple dots
                    if not _case_ok(os.path.dirname(filename),
                                    basename + '.' + filename.rpartition('.')[2]):
                        # PEP 235
                        return
                loader = getattr(fullname, 'loader', None)
                if loader is None:
                    loader = language.get_loader()

                return loader(fullname, filename, language)
{'fraction_non_alphanumeric': 0.0837917900973339, 'fraction_numerical': 0.010579771476936098, 'mean_word_length': 1.717241379310345, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3072644', 'n_tokens_mistral': 664, 'n_tokens_neox': 610, 'n_words': 184}