# Path: sydpy/_util/_injector.py
# class FeatureBroker:
# class RequiredFeature(object):
#     def __init__(self, allowReplace=False):
#     def Provide(self, feature, provider, *args, **kwargs):
#             def call(): return provider(*args, **kwargs)
#             def call(): return provider
#     def __getitem__(self, feature):
# def NoAssertion(obj): return True
# def IsInstanceOf(*classes):
#     def test(obj): return isinstance(obj, classes)
# def HasAttributes(*attributes):
#     def test(obj):
# def HasMethods(*methods):
#     def test(obj):
# def RequiredVariable(feature, assertion=NoAssertion):
#     def __init__(self, feature, assertion=NoAssertion):
#     def __get__(self, obj, T):
#     def __getattr__(self, name):
#     def Request(self):
# 
# Path: sydpy/_util/_util.py
# def class_load(cls):
#     """Instatiate class given by path string
#     
#     The format expected of the class path is:
#     path.to.the.module.ClassName
#     """
#     if isinstance(cls, str):
#         class_path_partition = cls.rpartition('.')
#         
#         class_name = class_path_partition[-1]
#         module_name = class_path_partition[0]
#         
#         if not module_name:
#             module_name = "sydpy"
#         
#         module = __import__(module_name, fromlist=[class_name])
#         class_ = getattr(module, class_name)
#         
#         return class_
#     else:
#         return cls
# 
# def unif_enum(obj):
#     if hasattr(obj, '__iter__'):
#         for e in obj:
#             yield e
#     else:
#         yield obj
# 
# def factory(cls, *args, **kwargs):
#     class_load(cls)(*args, **kwargs)
# 
# Path: sydpy/_configurator.py
# class Configurator(object):
#     """Class for handling configuration dictionaries."""
# 
#     def update_config(self, qualified_name, config):
#         """Update the values of the passed config dictionary.
#         
#         The values of the config are updated according to the
#         entries of the configuration contained with in the 
#         Configuration object.
#         """
#         for p_pat in self.config:
#             # For every key in Configuration dict, try to match it
#             # with keys of the passed config dict.
#             if fnmatch.fnmatch(qualified_name, p_pat):
#                 for c_pat in self.config[p_pat]:
#                     for c in config:
#                         if fnmatch.fnmatch(c, c_pat):
#                             config[c] = self.config[p_pat][c_pat]
#     
#     def __setitem__(self, args, val):
#         comp = args[0]
#         cfg = args[1]
#         
#         if comp not in self.config:
#             self.config[comp] = {}
#             
#         self.config[comp][cfg] = val
#     
#     def __getitem__(self, args):
#         
#         comp = args[0]
#         cfg = args[1]
#         
#         if len(args) == 2:
#             return self.config[comp][cfg]
#         else:
#             dflt = args[2]
#             
#             if comp in self.config:
#                 if cfg in self.config[comp]:
#                     return self.config[comp][cfg]
#         
#         return dflt
#     
#     def __init__(self, config):
#         '''
#         Constructor
#         '''
#         
#         self.config = {}
#         
#         for c in config:
#             path_pat, dummy , conf_pat = c.rpartition('.')
#             
#             path_pat = path_pat.replace('[', '(').replace(']', ')')
#             
#             path_pat = path_pat.replace('(', '[[]').replace(')', '[]]')
#             
#             if path_pat not in self.config:
#                 self.config[path_pat] = {}
#                 
#             self.config[path_pat][conf_pat] = config[c]


import os
import inspect
from sydpy._util._injector import features, RequiredVariable  # @UnresolvedImport
from sydpy._util._util import class_load, unif_enum, factory
from sydpy._configurator import Configurator
from greenlet import greenlet
    def proc_reg(self, proc):
        """Register a process with simulator kernel."""
        self._ready_pool.add(proc)
        self._proc_pool.append(proc)
            
    def __init__(self, config={}):
        '''Create a new Simulator object.'''
        self.time = 0
        self.running = False
        self._finished = False
        self._cosim = None
        self._config = config
        self.arch_inst = 0
        
        # Create events for Simulator extensions to hook to.
        self.events = {
                       'init_start'     : SimEvent(),
                       'run_start'      : SimEvent(),
                       'run_end'        : SimEvent(),
                       'delta_start'    : SimEvent(),
                       'post_evaluate'  : SimEvent(),
                       'delta_end'      : SimEvent(),
                       'timestep_start' : SimEvent(),
                       'timestep_end'   : SimEvent(),
                       }
        
        features.Provide('Simulator', self)
        
        # Create a configurator object from the simulator configuration dictionary
        self._configurator = Configurator(self._config)

# Path: sydpy/_util/_injector.py
# class FeatureBroker:
# class RequiredFeature(object):
#     def __init__(self, allowReplace=False):
#     def Provide(self, feature, provider, *args, **kwargs):
#             def call(): return provider(*args, **kwargs)
#             def call(): return provider
#     def __getitem__(self, feature):
# def NoAssertion(obj): return True
# def IsInstanceOf(*classes):
#     def test(obj): return isinstance(obj, classes)
# def HasAttributes(*attributes):
#     def test(obj):
# def HasMethods(*methods):
#     def test(obj):
# def RequiredVariable(feature, assertion=NoAssertion):
#     def __init__(self, feature, assertion=NoAssertion):
#     def __get__(self, obj, T):
#     def __getattr__(self, name):
#     def Request(self):
# 
# Path: sydpy/_util/_util.py
# def class_load(cls):
#     """Instatiate class given by path string
#     
#     The format expected of the class path is:
#     path.to.the.module.ClassName
#     """
#     if isinstance(cls, str):
#         class_path_partition = cls.rpartition('.')
#         
#         class_name = class_path_partition[-1]
#         module_name = class_path_partition[0]
#         
#         if not module_name:
#             module_name = "sydpy"
#         
#         module = __import__(module_name, fromlist=[class_name])
#         class_ = getattr(module, class_name)
#         
#         return class_
#     else:
#         return cls
# 
# def unif_enum(obj):
#     if hasattr(obj, '__iter__'):
#         for e in obj:
#             yield e
#     else:
#         yield obj
# 
# def factory(cls, *args, **kwargs):
#     class_load(cls)(*args, **kwargs)
# 
# Path: sydpy/_configurator.py
# class Configurator(object):
#     """Class for handling configuration dictionaries."""
# 
#     def update_config(self, qualified_name, config):
#         """Update the values of the passed config dictionary.
#         
#         The values of the config are updated according to the
#         entries of the configuration contained with in the 
#         Configuration object.
#         """
#         for p_pat in self.config:
#             # For every key in Configuration dict, try to match it
#             # with keys of the passed config dict.
#             if fnmatch.fnmatch(qualified_name, p_pat):
#                 for c_pat in self.config[p_pat]:
#                     for c in config:
#                         if fnmatch.fnmatch(c, c_pat):
#                             config[c] = self.config[p_pat][c_pat]
#     
#     def __setitem__(self, args, val):
#         comp = args[0]
#         cfg = args[1]
#         
#         if comp not in self.config:
#             self.config[comp] = {}
#             
#         self.config[comp][cfg] = val
#     
#     def __getitem__(self, args):
#         
#         comp = args[0]
#         cfg = args[1]
#         
#         if len(args) == 2:
#             return self.config[comp][cfg]
#         else:
#             dflt = args[2]
#             
#             if comp in self.config:
#                 if cfg in self.config[comp]:
#                     return self.config[comp][cfg]
#         
#         return dflt
#     
#     def __init__(self, config):
#         '''
#         Constructor
#         '''
#         
#         self.config = {}
#         
#         for c in config:
#             path_pat, dummy , conf_pat = c.rpartition('.')
#             
#             path_pat = path_pat.replace('[', '(').replace(']', ')')
#             
#             path_pat = path_pat.replace('(', '[[]').replace(')', '[]]')
#             
#             if path_pat not in self.config:
#                 self.config[path_pat] = {}
#                 
#             self.config[path_pat][conf_pat] = config[c]


# Path: sydpy/_simulator.py
import os
import inspect
from sydpy._util._injector import features, RequiredVariable  # @UnresolvedImport
from sydpy._util._util import class_load, unif_enum, factory
from sydpy._configurator import Configurator
from greenlet import greenlet

    def proc_reg(self, proc):
        """Register a process with simulator kernel."""
        self._ready_pool.add(proc)
        self._proc_pool.append(proc)
            
    def __init__(self, config={}):
        '''Create a new Simulator object.'''
        self.time = 0
        self.running = False
        self._finished = False
        self._cosim = None
        self._config = config
        self.arch_inst = 0
        
        # Create events for Simulator extensions to hook to.
        self.events = {
                       'init_start'     : SimEvent(),
                       'run_start'      : SimEvent(),
                       'run_end'        : SimEvent(),
                       'delta_start'    : SimEvent(),
                       'post_evaluate'  : SimEvent(),
                       'delta_end'      : SimEvent(),
                       'timestep_start' : SimEvent(),
                       'timestep_end'   : SimEvent(),
                       }
        
        features.Provide('Simulator', self)
        
        # Create a configurator object from the simulator configuration dictionary
        self._configurator = Configurator(self._config)

        features.Provide('Configurator', self._configurator)