<commit_before>from restclients.mock_http import MockHTTP
from os.path import abspath, dirname
from django.conf import settings
from django.core.exceptions import *
from django.utils.importlib import import_module
import sys
import os
import json
import logging

"""
A centralized the mock data access
"""
# Based on django.template.loaders.app_directories
fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()
app_resource_dirs = []
for app in settings.INSTALLED_APPS:
    try:
        mod = import_module(app)
    except ImportError, e:
        raise ImproperlyConfigured('ImportError %s: %s' % (app, e.args[0]))

    resource_dir = os.path.join(os.path.dirname(mod.__file__), 'resources')
    if os.path.isdir(resource_dir):
        # Cheating, to make sure our resources are overridable
        data = {
            'path': resource_dir.decode(fs_encoding),
            'app': app,
        }
        if app == 'restclients':
            app_resource_dirs.append(data)
        else:
            app_resource_dirs.insert(0, data)

def get_mockdata_url(service_name, implementation_name,
                     url, headers):

    """
    :param service_name:
        possible "sws", "pws", "book", "hfs", etc.
    :param implementation_name:
        possible values: "file", etc.
    """

    dir_base = dirname(__file__)



    RESOURCE_ROOT = abspath(dir_base + "/../resources/" +
                            service_name + "/" + implementation_name)

    file_path = None
    success = False

    for resource_dir in app_resource_dirs:<commit_msg>Change the app template finding code, so we don't have circular dependency problems<commit_after>from restclients.mock_http import MockHTTP
from os.path import abspath, dirname
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.importlib import import_module
import sys
import os
import json
import logging

"""
A centralized the mock data access
"""
# Based on django.template.loaders.app_directories
fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()
app_resource_dirs = []

# An issue w/ loading order in management commands means this needs to be
# a function.  Otherwise we can be trying to load modules that are trying to
# load this code, and python bails on us.

def __initialize_app_resource_dirs():
    if len(app_resource_dirs) > 0:
        return
    for app in settings.INSTALLED_APPS:
        try:
            mod = import_module(app)
        except ImportError, e:
            raise ImproperlyConfigured('ImportError %s: %s' % (app, e.args[0]))

        resource_dir = os.path.join(os.path.dirname(mod.__file__), 'resources')
        if os.path.isdir(resource_dir):
            # Cheating, to make sure our resources are overridable
            data = {
                'path': resource_dir.decode(fs_encoding),
                'app': app,
            }
            if app == 'restclients':
                app_resource_dirs.append(data)
            else:
                app_resource_dirs.insert(0, data)

def get_mockdata_url(service_name, implementation_name,
                     url, headers):

    """
    :param service_name:
        possible "sws", "pws", "book", "hfs", etc.
    :param implementation_name:
        possible values: "file", etc.
    """

    dir_base = dirname(__file__)
    __initialize_app_resource_dirs()


    RESOURCE_ROOT = abspath(dir_base + "/../resources/" +
                            service_name + "/" + implementation_name)

    file_path = None
    success = False

    for resource_dir in app_resource_dirs:
{'fraction_non_alphanumeric': 0.09239733629300777, 'fraction_numerical': 0.0013873473917869034, 'mean_word_length': 2.7788259958071277, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6525461', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1034, 'n_words': 288}