# 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
    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
        self.environment = self.asset.attributes.environment
        self.current_dir = self.asset.attributes.dirname
        self.process()

    def process(self):
        if self.environment.fingerprinting:
            self.asset.processed_source = rewrite_paths(
                self.asset.processed_source,
                self.rewrite_path,
            )

    def rewrite_path(self, path):
        logical_path = os.path.normpath(os.path.join(self.current_dir, path))
        try:
            asset = build_asset(self.environment, logical_path)
        except FileNotFound:
            return path
        self.asset.dependencies.add(asset.absolute_path)
        relpath = str(os.path.relpath(asset.hexdigest_path, self.current_dir))
        if is_py2:
            return relpath.encode('string-escape')

# 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

    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
        self.environment = self.asset.attributes.environment
        self.current_dir = self.asset.attributes.dirname
        self.process()

    def process(self):
        if self.environment.fingerprinting:
            self.asset.processed_source = rewrite_paths(
                self.asset.processed_source,
                self.rewrite_path,
            )

    def rewrite_path(self, path):
        logical_path = os.path.normpath(os.path.join(self.current_dir, path))
        try:
            asset = build_asset(self.environment, logical_path)
        except FileNotFound:
            return path
        self.asset.dependencies.add(asset.absolute_path)
        relpath = str(os.path.relpath(asset.hexdigest_path, self.current_dir))
        if is_py2:
            return relpath.encode('string-escape')

        elif is_py3: