# Path: gears/assets.py
# def build_asset(environment, path, check=False):
#     path = strip_fingerprint(path)
#     asset_attributes = AssetAttributes(environment, path)
#     asset_attributes, absolute_path = environment.find(asset_attributes, True)
#     if not asset_attributes.processors:
#         return StaticAsset(asset_attributes, absolute_path)
#     if check:
#         return CheckAsset(asset_attributes, absolute_path)
#     return Asset(asset_attributes, absolute_path)
# 
# Path: gears/exceptions.py
# class FileNotFound(Exception):
#     pass
# 
# Path: gears/processors/base.py
# class BaseProcessor(BaseAssetHandler):
#     """Base class for all asset processors. Subclass's :meth:`__call__` method
#     must change asset's :attr:`~gears.assets.Asset.processed_source` attribute.
#     """
# 
# Path: gears/compat.py
# class UnicodeMixin(object):
#     def __str__(self):
#     def bytes(obj):


import os
import re
from ..assets import build_asset
from ..exceptions import FileNotFound
from .base import BaseProcessor
from ..compat import is_py3, is_py2


URL_RE = re.compile(r"""url\((['"]?)\s*(.*?)\s*\1\)""")


def rewrite_paths(source, func):
    repl = lambda match: 'url({quote}{path}{quote})'.format(
        quote=match.group(1),
        path=func(match.group(2)),
    )
    return URL_RE.sub(repl, source)


class HexdigestPathsProcessor(BaseProcessor):

    url_re = re.compile(r"""url\((['"]?)\s*(.*?)\s*\1\)""")

    def __call__(self, asset):

# Path: gears/assets.py
# def build_asset(environment, path, check=False):
#     path = strip_fingerprint(path)
#     asset_attributes = AssetAttributes(environment, path)
#     asset_attributes, absolute_path = environment.find(asset_attributes, True)
#     if not asset_attributes.processors:
#         return StaticAsset(asset_attributes, absolute_path)
#     if check:
#         return CheckAsset(asset_attributes, absolute_path)
#     return Asset(asset_attributes, absolute_path)
# 
# Path: gears/exceptions.py
# class FileNotFound(Exception):
#     pass
# 
# Path: gears/processors/base.py
# class BaseProcessor(BaseAssetHandler):
#     """Base class for all asset processors. Subclass's :meth:`__call__` method
#     must change asset's :attr:`~gears.assets.Asset.processed_source` attribute.
#     """
# 
# Path: gears/compat.py
# class UnicodeMixin(object):
#     def __str__(self):
#     def bytes(obj):


# Path: gears/processors/hexdigest_paths.py
import os
import re
from ..assets import build_asset
from ..exceptions import FileNotFound
from .base import BaseProcessor
from ..compat import is_py3, is_py2



URL_RE = re.compile(r"""url\((['"]?)\s*(.*?)\s*\1\)""")


def rewrite_paths(source, func):
    repl = lambda match: 'url({quote}{path}{quote})'.format(
        quote=match.group(1),
        path=func(match.group(2)),
    )
    return URL_RE.sub(repl, source)


class HexdigestPathsProcessor(BaseProcessor):

    url_re = re.compile(r"""url\((['"]?)\s*(.*?)\s*\1\)""")

    def __call__(self, asset):

        self.asset = asset