<commit_before>from pyramid.path import AssetResolver
from pyramid.settings import asbool
from pyramid.threadlocal import get_current_request
from zope.interface import Interface
from webassets import Environment
from webassets.exceptions import BundleError


class Environment(Environment):
    def _normalize_source_path(self, spath):
        # spath might be an asset spec
        try:
            spath = AssetResolver(None).resolve(spath).abspath()
        except ImportError, e:
            raise BundleError(e)
        except ValueError:
            pass # Not an absolute asset spec

        return super(Environment, self)._normalize_source_path(spath)

    def absurl(self, fragment):
        query = None
        request = get_current_request()

        if self.url_expire != False and '?' in fragment:
          fragment, query = fragment.rsplit('?', 1)

        if not ':' in fragment:
          # Get the path to the file if it's not an asset spec
          fragment = super(Environment, self).abspath(fragment)

        try:
            fragment = request.static_url(fragment)
            return query and "%s?%s" % (fragment, query) or fragment
        except ValueError, e:
             raise BundleError(e)


class IWebAssetsEnvironment(Interface):
    pass


def add_webasset(config, name, bundle):
    asset_env = get_webassets_env(config)
    asset_env.register(name, bundle)


def get_webassets_env(config):
    return config.registry.queryUtility(IWebAssetsEnvironment)


def get_webassets_env_from_settings(settings, prefix='webassets'):
    """This function will take all webassets.* parameteres, and
    call the ``Environment()`` constructor with kwargs passed in.

    The only two parameters that are not passed as keywords are:

    * base_dir
    * base_url

    which are passed in positionally.

    Read the ``WebAssets`` docs for ``Environment`` for more details.
    """
    # Make a dictionary of the webassets.* elements...<commit_msg>Fix docstring typo.<commit_after>from pyramid.path import AssetResolver
from pyramid.settings import asbool
from pyramid.threadlocal import get_current_request
from zope.interface import Interface
from webassets import Environment
from webassets.exceptions import BundleError


class Environment(Environment):
    def _normalize_source_path(self, spath):
        # spath might be an asset spec
        try:
            spath = AssetResolver(None).resolve(spath).abspath()
        except ImportError, e:
            raise BundleError(e)
        except ValueError:
            pass # Not an absolute asset spec

        return super(Environment, self)._normalize_source_path(spath)

    def absurl(self, fragment):
        query = None
        request = get_current_request()

        if self.url_expire != False and '?' in fragment:
          fragment, query = fragment.rsplit('?', 1)

        if not ':' in fragment:
          # Get the path to the file if it's not an asset spec
          fragment = super(Environment, self).abspath(fragment)

        try:
            fragment = request.static_url(fragment)
            return query and "%s?%s" % (fragment, query) or fragment
        except ValueError, e:
             raise BundleError(e)


class IWebAssetsEnvironment(Interface):
    pass


def add_webasset(config, name, bundle):
    asset_env = get_webassets_env(config)
    asset_env.register(name, bundle)


def get_webassets_env(config):
    return config.registry.queryUtility(IWebAssetsEnvironment)


def get_webassets_env_from_settings(settings, prefix='webassets'):
    """This function will take all webassets.* parameters, and
    call the ``Environment()`` constructor with kwargs passed in.

    The only two parameters that are not passed as keywords are:

    * base_dir
    * base_url

    which are passed in positionally.

    Read the ``WebAssets`` docs for ``Environment`` for more details.
    """
    # Make a dictionary of the webassets.* elements...
{'fraction_non_alphanumeric': 0.07972665148063782, 'fraction_numerical': 0.0005062009617818274, 'mean_word_length': 3.065843621399177, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '493975', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1042, 'n_words': 349}