# Path: gumpy/configuration.py
# class LocalConfiguration(Configuration):
#     def __init__(self, path=None):
#         if path and os.path.isdir(path):
#             self._dir = os.path.abspath(path)
#         else:
#             self._dir = None
#         self._docs = {}
# 
#     def __getattr__(self, key):
#         if key in self._docs:
#             return self._docs[key]
# 
#         if self._dir:
#             fn = os.path.join(self._dir, key)
#             self._docs[key] = _LocalDocument(fn)
#         else:
#             self._docs[key] = _LocalDocument()
#         return self._docs[key]
# 
#     def __getitem__(self, item):
#         return self.__getattr__(item)
# 
#     def __del__(self):
#         self.close()
# 
#     def close(self):
#         for doc in self._docs.values():
#             doc.close()
# 
#     def persist(self):
#         for doc in self._docs.values():
#             doc.persist()
# 
#     def reload(self):
#         if self._dir:
#             for key in self._docs:
#                 fn = os.path.join(self._dir, key)
#                 self._docs[key] = _LocalDocument(fn)
#         else:
#             for key in self._docs:
#                 self._docs[key] = _LocalDocument()
# 
# Path: gumpy/executor.py
# class Executor(object):
#     def __init__(self):
#         self._task_deque = deque()
#         self._lock = Lock()
#         self._thread_ident = None
#         self._closed = False
# 
#     def _step(self):
#         try:
#             future, gen = self._task_deque.popleft()
#             future.consume_result(next(gen))
#             self._task_deque.append((future, gen))
#             return True
#         except StopIteration:
#             future.set_done()
#             return True
#         except IndexError:
#             return False
#         except BaseException as err:
#             logger.exception(err)
#             future.set_exception(err)
#             return True
# 
#     def loop(self, forever=False):
#         with self._lock:
#             if not self._thread_ident:
#                 self._thread_ident = current_thread().ident
#             if self._thread_ident != current_thread().ident:
#                 # ensure same thread for loop
#                 raise ThreadError('Executor.loop for one thread only.')
#         while (self._step() or forever) and (not self._closed):
#             pass
# 
#         self._thread_ident = None
# 
#     def close(self):
#         self._closed = True
# 
#     def call(self, fn):
#         return self.call_posterior(fn)
# 
#     def call_prior(self, fn):
#         future = Future(self)
#         self._task_deque.appendleft((future, _gen(fn)))
#         return future
# 
#     def call_posterior(self, fn):
#         future = Future(self)
#         self._task_deque.append((future, _gen(fn)))
#         return future


import zipfile
import os
import functools
import itertools
import zipimport
import threading
import collections
    import ConfigParser as configparser
    import configparser
import types
import logging
    from queue import Queue
    from Queue import Queue
        from importlib import reload
        from imp import reload
    from importlib.machinery import SourceFileLoader
    from imp import load_source
from importlib import import_module
from .configuration import LocalConfiguration
from .executor import Executor
from inspect import isgeneratorfunction
        u = service_uri(uri)
        if u.bundle:
            return self._framework.bundles[u.bundle].get_service_reference_by_name(u.service)
        else:
            return self.get_service_reference_by_name(u.service)

    def get_service_reference_by_name(self, name):
        if name in self._service_references:
            return self._service_references[name]
        else:
            return None

    def get_service(self, uri):
        sr = self.get_service_reference(uri)
        return sr.get_service() if sr else None

    def get(self, uri):
        u = service_uri(uri)
        if u.service:
            return self.__framework__.bundles[u.bundle].get_service_reference_by_name(u.service)
        else:
            return self.__framework__.bundles[u.bundle]


class Framework(object):
    def __init__(self, configuration=None, repo_path=None):
        self.__executor__ = Executor()
        self._repo_path = repo_path
        self._bundles = {}
        self._lock = threading.Lock()

# Path: gumpy/configuration.py
# class LocalConfiguration(Configuration):
#     def __init__(self, path=None):
#         if path and os.path.isdir(path):
#             self._dir = os.path.abspath(path)
#         else:
#             self._dir = None
#         self._docs = {}
# 
#     def __getattr__(self, key):
#         if key in self._docs:
#             return self._docs[key]
# 
#         if self._dir:
#             fn = os.path.join(self._dir, key)
#             self._docs[key] = _LocalDocument(fn)
#         else:
#             self._docs[key] = _LocalDocument()
#         return self._docs[key]
# 
#     def __getitem__(self, item):
#         return self.__getattr__(item)
# 
#     def __del__(self):
#         self.close()
# 
#     def close(self):
#         for doc in self._docs.values():
#             doc.close()
# 
#     def persist(self):
#         for doc in self._docs.values():
#             doc.persist()
# 
#     def reload(self):
#         if self._dir:
#             for key in self._docs:
#                 fn = os.path.join(self._dir, key)
#                 self._docs[key] = _LocalDocument(fn)
#         else:
#             for key in self._docs:
#                 self._docs[key] = _LocalDocument()
# 
# Path: gumpy/executor.py
# class Executor(object):
#     def __init__(self):
#         self._task_deque = deque()
#         self._lock = Lock()
#         self._thread_ident = None
#         self._closed = False
# 
#     def _step(self):
#         try:
#             future, gen = self._task_deque.popleft()
#             future.consume_result(next(gen))
#             self._task_deque.append((future, gen))
#             return True
#         except StopIteration:
#             future.set_done()
#             return True
#         except IndexError:
#             return False
#         except BaseException as err:
#             logger.exception(err)
#             future.set_exception(err)
#             return True
# 
#     def loop(self, forever=False):
#         with self._lock:
#             if not self._thread_ident:
#                 self._thread_ident = current_thread().ident
#             if self._thread_ident != current_thread().ident:
#                 # ensure same thread for loop
#                 raise ThreadError('Executor.loop for one thread only.')
#         while (self._step() or forever) and (not self._closed):
#             pass
# 
#         self._thread_ident = None
# 
#     def close(self):
#         self._closed = True
# 
#     def call(self, fn):
#         return self.call_posterior(fn)
# 
#     def call_prior(self, fn):
#         future = Future(self)
#         self._task_deque.appendleft((future, _gen(fn)))
#         return future
# 
#     def call_posterior(self, fn):
#         future = Future(self)
#         self._task_deque.append((future, _gen(fn)))
#         return future


# Path: gumpy/framework.py
import zipfile
import os
import functools
import itertools
import zipimport
import threading
import collections
    import ConfigParser as configparser
    import configparser
import types
import logging
    from queue import Queue
    from Queue import Queue
        from importlib import reload
        from imp import reload
    from importlib.machinery import SourceFileLoader
    from imp import load_source
from importlib import import_module
from .configuration import LocalConfiguration
from .executor import Executor
from inspect import isgeneratorfunction

        u = service_uri(uri)
        if u.bundle:
            return self._framework.bundles[u.bundle].get_service_reference_by_name(u.service)
        else:
            return self.get_service_reference_by_name(u.service)

    def get_service_reference_by_name(self, name):
        if name in self._service_references:
            return self._service_references[name]
        else:
            return None

    def get_service(self, uri):
        sr = self.get_service_reference(uri)
        return sr.get_service() if sr else None

    def get(self, uri):
        u = service_uri(uri)
        if u.service:
            return self.__framework__.bundles[u.bundle].get_service_reference_by_name(u.service)
        else:
            return self.__framework__.bundles[u.bundle]


class Framework(object):
    def __init__(self, configuration=None, repo_path=None):
        self.__executor__ = Executor()
        self._repo_path = repo_path
        self._bundles = {}
        self._lock = threading.Lock()

        self._configuration = configuration or LocalConfiguration()