# Path: gears/environment.py
# class Processors(dict):
#     """Base class for processors registries."""
# 
#     def register(self, mimetype, processor):
#         """Register passed `processor` for passed `mimetype`."""
#         if mimetype not in self or processor not in self[mimetype]:
#             self.setdefault(mimetype, []).append(processor)
# 
#     def unregister(self, mimetype, processor):
#         """Remove passed `processor` for passed `mimetype`. If processor for
#         this MIME type does not found in the registry, nothing happens.
#         """
#         if mimetype in self and processor in self[mimetype]:
#             self[mimetype].remove(processor)
# 
#     def get(self, mimetype):
#         """Return a list of processors, registered for passed `mimetype`. If
#         no processors are registered for this MIME type, empty list is
#         returned.
#         """
#         return super(Processors, self).get(mimetype, [])
# 
# class Preprocessors(Processors):
#     """The registry for asset preprocessors. It acts like a dictionary with
#     MIME types as keys and lists of processors as values. Every registered MIME
#     type can have many preprocessors. Preprocessors for the MIME type are used
#     in the order they were added.
#     """
# 
#     def register_defaults(self):
#         """Register :class:`~gears.processors.DirectivesProcessor` as
#         a preprocessor for `text/css` and `application/javascript` MIME types.
#         """
#         self.register('text/css', DirectivesProcessor.as_handler())
#         self.register('application/javascript', DirectivesProcessor.as_handler())
# 
# Path: gears/processors/directives.py
# class DirectivesProcessor(BaseProcessor):
# 
#     supports_check_mode = True
# 
#     def __init__(self):
#         self.types = {
#             'public': self.process_public_directive,
#             'params': self.process_params_directive,
#             'require': self.process_require_directive,
#             'require_directory': self.process_require_directory_directive,
#             'require_tree': self.process_require_tree_directive,
#             'require_self': self.process_require_self_directive,
#             'depend_on': self.process_depend_on_directive,
#         }
# 
#     def __call__(self, asset, check=False):
#         self.asset = asset
#         self.check = check
#         self.parse()
#         self.process_directives()
# 
#     def parse(self):
#         directives, source = DirectivesParser().parse(self.asset.processed_source)
#         self.directives = directives
#         self.asset.processed_source = source
# 
#     def process_directives(self):
#         for directive in self.directives:
#             # shlex didn't support Unicode prior to 2.7.3
#             if sys.version_info < (2, 7, 3):
#                 directive = directive.encode('utf-8')
#             args = shlex.split(directive)
#             self.types[args[0]](*args[1:])
# 
#     def process_public_directive(self):
#         self.asset.params['public'] = True
# 
#     def process_params_directive(self, *params):
#         for param in params:
#             if '=' in param:
#                 key, value = param.split('=', 1)
#                 self.asset.params[key] = value
# 
#     def process_require_directive(self, path):
#         if self.check:
#             return
# 
#         found = False
#         path = self.get_relative_path(path)
#         list = self.asset.attributes.environment.list(path, self.asset.attributes.mimetype)
#         for asset_attributes, absolute_path in sorted(list, key=lambda x: x[0].path.split('/')):
#             self.asset.requirements.add(self.get_asset(asset_attributes, absolute_path))
#             self.asset.dependencies.add(os.path.dirname(absolute_path))
#             found = True
#         if not found:
#             raise FileNotFound(path)
# 
#     def process_require_directory_directive(self, path):
#         if self.check:
#             return
#         self.process_require_directive(os.path.join(path, '*'))
# 
#     def process_require_tree_directive(self, path):
#         if self.check:
#             return
#         self.process_require_directive(os.path.join(path, '**'))
# 
#     def process_require_self_directive(self):
#         if self.check:
#             return
#         self.asset.requirements.add(self.asset)
# 
#     def process_depend_on_directive(self, path):
#         if self.check:
#             return
# 
#         found = False
#         path = self.get_relative_path(path)
#         list = self.asset.attributes.environment.list(path, self.asset.attributes.mimetype)
#         for asset_attributes, absolute_path in list:
#             self.asset.dependencies.add(absolute_path)
#             found = True
#         if not found:
#             raise FileNotFound(path)
# 
#     def get_relative_path(self, require_path, is_directory=False):
#         require_path = os.path.join(self.asset.attributes.dirname, require_path)
#         return os.path.normpath(require_path)
# 
#     def get_asset(self, asset_attributes, absolute_path):
#         return Asset(asset_attributes, absolute_path, self.asset.calls)


from gears.environment import Processors, Preprocessors
from gears.processors import DirectivesProcessor
from mock import Mock
from unittest2 import TestCase



class ProcessorsTests(TestCase):

    def setUp(self):
        self.processors = Processors()
        self.first_processor = Mock()
        self.second_processor = Mock()
        self.third_processor = Mock()


# Path: gears/environment.py
# class Processors(dict):
#     """Base class for processors registries."""
# 
#     def register(self, mimetype, processor):
#         """Register passed `processor` for passed `mimetype`."""
#         if mimetype not in self or processor not in self[mimetype]:
#             self.setdefault(mimetype, []).append(processor)
# 
#     def unregister(self, mimetype, processor):
#         """Remove passed `processor` for passed `mimetype`. If processor for
#         this MIME type does not found in the registry, nothing happens.
#         """
#         if mimetype in self and processor in self[mimetype]:
#             self[mimetype].remove(processor)
# 
#     def get(self, mimetype):
#         """Return a list of processors, registered for passed `mimetype`. If
#         no processors are registered for this MIME type, empty list is
#         returned.
#         """
#         return super(Processors, self).get(mimetype, [])
# 
# class Preprocessors(Processors):
#     """The registry for asset preprocessors. It acts like a dictionary with
#     MIME types as keys and lists of processors as values. Every registered MIME
#     type can have many preprocessors. Preprocessors for the MIME type are used
#     in the order they were added.
#     """
# 
#     def register_defaults(self):
#         """Register :class:`~gears.processors.DirectivesProcessor` as
#         a preprocessor for `text/css` and `application/javascript` MIME types.
#         """
#         self.register('text/css', DirectivesProcessor.as_handler())
#         self.register('application/javascript', DirectivesProcessor.as_handler())
# 
# Path: gears/processors/directives.py
# class DirectivesProcessor(BaseProcessor):
# 
#     supports_check_mode = True
# 
#     def __init__(self):
#         self.types = {
#             'public': self.process_public_directive,
#             'params': self.process_params_directive,
#             'require': self.process_require_directive,
#             'require_directory': self.process_require_directory_directive,
#             'require_tree': self.process_require_tree_directive,
#             'require_self': self.process_require_self_directive,
#             'depend_on': self.process_depend_on_directive,
#         }
# 
#     def __call__(self, asset, check=False):
#         self.asset = asset
#         self.check = check
#         self.parse()
#         self.process_directives()
# 
#     def parse(self):
#         directives, source = DirectivesParser().parse(self.asset.processed_source)
#         self.directives = directives
#         self.asset.processed_source = source
# 
#     def process_directives(self):
#         for directive in self.directives:
#             # shlex didn't support Unicode prior to 2.7.3
#             if sys.version_info < (2, 7, 3):
#                 directive = directive.encode('utf-8')
#             args = shlex.split(directive)
#             self.types[args[0]](*args[1:])
# 
#     def process_public_directive(self):
#         self.asset.params['public'] = True
# 
#     def process_params_directive(self, *params):
#         for param in params:
#             if '=' in param:
#                 key, value = param.split('=', 1)
#                 self.asset.params[key] = value
# 
#     def process_require_directive(self, path):
#         if self.check:
#             return
# 
#         found = False
#         path = self.get_relative_path(path)
#         list = self.asset.attributes.environment.list(path, self.asset.attributes.mimetype)
#         for asset_attributes, absolute_path in sorted(list, key=lambda x: x[0].path.split('/')):
#             self.asset.requirements.add(self.get_asset(asset_attributes, absolute_path))
#             self.asset.dependencies.add(os.path.dirname(absolute_path))
#             found = True
#         if not found:
#             raise FileNotFound(path)
# 
#     def process_require_directory_directive(self, path):
#         if self.check:
#             return
#         self.process_require_directive(os.path.join(path, '*'))
# 
#     def process_require_tree_directive(self, path):
#         if self.check:
#             return
#         self.process_require_directive(os.path.join(path, '**'))
# 
#     def process_require_self_directive(self):
#         if self.check:
#             return
#         self.asset.requirements.add(self.asset)
# 
#     def process_depend_on_directive(self, path):
#         if self.check:
#             return
# 
#         found = False
#         path = self.get_relative_path(path)
#         list = self.asset.attributes.environment.list(path, self.asset.attributes.mimetype)
#         for asset_attributes, absolute_path in list:
#             self.asset.dependencies.add(absolute_path)
#             found = True
#         if not found:
#             raise FileNotFound(path)
# 
#     def get_relative_path(self, require_path, is_directory=False):
#         require_path = os.path.join(self.asset.attributes.dirname, require_path)
#         return os.path.normpath(require_path)
# 
#     def get_asset(self, asset_attributes, absolute_path):
#         return Asset(asset_attributes, absolute_path, self.asset.calls)


# Path: tests/test_environment_processors.py
from gears.environment import Processors, Preprocessors
from gears.processors import DirectivesProcessor
from mock import Mock
from unittest2 import TestCase




class ProcessorsTests(TestCase):

    def setUp(self):
        self.processors = Processors()
        self.first_processor = Mock()
        self.second_processor = Mock()
        self.third_processor = Mock()


    def test_register(self):