<commit_before>import json
import pkg_resources
import yaml

try:
    from yaml import CLoader as Loader
except ImportError:
    from yaml import Loader

def yml_load(stream, loader=Loader, close=False):
    if isinstance(stream, basestring):
        stream = open(stream)
        close = True
    try:
        return yaml.load_all(stream, loader=Loader)
    finally:
        if close is True:
            stream.close()


def resource_spec(spec):
    """
    Loads resource from a string specifier. 
    
    >>> config.resource_spec('egg:monkeylib#data/languages.ini')
    '.../monkeylib/data/languages.ini'

    >>> config.resource_spec('file:data/languages.ini')<commit_msg>simplify yml_load<commit_after>import json
import pkg_resources
import yaml

try:
    from yaml import CLoader as Loader
except ImportError:
    from yaml import Loader


def yml_load(stream, loader=Loader):
    return yaml.load_all(stream, loader)


def resource_spec(spec):
    """
    Loads resource from a string specifier. 
    
    >>> config.resource_spec('egg:monkeylib#data/languages.ini')
    '.../monkeylib/data/languages.ini'

    >>> config.resource_spec('file:data/languages.ini')
{'fraction_non_alphanumeric': 0.10494880546075085, 'fraction_numerical': 0.0, 'mean_word_length': 3.4264150943396228, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '3170719', 'n_tokens_mistral': 381, 'n_tokens_neox': 367, 'n_words': 87}