# Path: doubles/patch.py
# class Patch(object):
#     """
#     A wrapper around an object that has been ``patched``
#     """
#     def __init__(self, target):
#         """
#         :param str path: The absolute module path to the class.
#         """
#         module_path, self._name = get_path_components(target)
#         self.target = get_module(module_path, target)
#         self._capture_original_object()
#         self.set_value(None)
# 
#     def _capture_original_object(self):
#         """Capture the original python object."""
#         try:
#             self._doubles_target = getattr(self.target, self._name)
#         except AttributeError:
#             raise VerifyingDoubleError(self.target, self._name)
# 
#     def set_value(self, value):
#         """Set the value of the target.
# 
#         :param obj value: The value to set.
#         """
#         self._value = value
#         setattr(self.target, self._name, value)
# 
#     def restore_original_object(self):
#         """Restore the target to it's original value."""
#         self.set_value(self._doubles_target)
# 
# Path: doubles/proxy.py
# class Proxy(object):
#     """
#     An intermediate object used to maintain a mapping between target objects and method doubles.
#     """
# 
#     def __init__(self, obj):
#         """
#         :param object obj: The object that will be doubled.
#         """
# 
#         self._target = Target(obj)
#         self._method_doubles = {}
# 
#     def add_allowance(self, method_name, caller):
#         """Adds a new allowance for the given method name.
# 
#         :param str method_name: The name of the method to allow.
#         :param tuple caller: A tuple indicating where the allowance was added
#         :return: The new ``Allowance``.
#         :rtype: Allowance
#         """
# 
#         return self.method_double_for(method_name).add_allowance(caller)
# 
#     def add_expectation(self, method_name, caller):
#         """Adds a new expectation for the given method name.
# 
#         :param str method_name: The name of the method to expect.
#         :return: The new ``Expectation``.
#         :rtype: Expectation
#         """
# 
#         return self.method_double_for(method_name).add_expectation(caller)
# 
#     def restore_original_object(self):
#         """Remove all stubs from an object.
# 
#         Removes the proxy methods applied to each method double and replaces them with the original
#         values.
#         """
# 
#         for method_double in self._method_doubles.values():
#             method_double.restore_original_method()
# 
#     def verify(self):
#         """Verifies all expectations on all method doubles.
# 
#         :raise: ``MockExpectationError`` on the first expectation that is not satisfied, if any.
#         """
# 
#         for method_double in self._method_doubles.values():
#             method_double.verify()
# 
#     def method_double_for(self, method_name):
#         """Returns the method double for the provided method name, creating one if necessary.
# 
#         :param str method_name: The name of the method to retrieve a method double for.
#         :return: The mapped ``MethodDouble``.
#         :rtype: MethodDouble
#         """
# 
#         if method_name not in self._method_doubles:
#             self._method_doubles[method_name] = MethodDouble(method_name, self._target)
# 
#         return self._method_doubles[method_name]


from doubles.patch import Patch
from doubles.proxy import Proxy


class Space(object):
    """
    A container object for all the doubles created during the execution of a test case. Maintains
    a one-to-one mapping of target objects and ``Proxy`` objects. Maintained by the ``lifecycle``
    module and not intended to be used directly by other objects.
    """

    def __init__(self):
        self._proxies = {}
        self._patches = {}
        self._is_verified = False
        self.skip_builtin_verification = False

    def patch_for(self, path):
        """Returns the ``Patch`` for the target path, creating it if necessary.

        :param str path: The absolute module path to the target.
        :return: The mapped ``Patch``.
        :rtype: Patch
        """

        if path not in self._patches:

# Path: doubles/patch.py
# class Patch(object):
#     """
#     A wrapper around an object that has been ``patched``
#     """
#     def __init__(self, target):
#         """
#         :param str path: The absolute module path to the class.
#         """
#         module_path, self._name = get_path_components(target)
#         self.target = get_module(module_path, target)
#         self._capture_original_object()
#         self.set_value(None)
# 
#     def _capture_original_object(self):
#         """Capture the original python object."""
#         try:
#             self._doubles_target = getattr(self.target, self._name)
#         except AttributeError:
#             raise VerifyingDoubleError(self.target, self._name)
# 
#     def set_value(self, value):
#         """Set the value of the target.
# 
#         :param obj value: The value to set.
#         """
#         self._value = value
#         setattr(self.target, self._name, value)
# 
#     def restore_original_object(self):
#         """Restore the target to it's original value."""
#         self.set_value(self._doubles_target)
# 
# Path: doubles/proxy.py
# class Proxy(object):
#     """
#     An intermediate object used to maintain a mapping between target objects and method doubles.
#     """
# 
#     def __init__(self, obj):
#         """
#         :param object obj: The object that will be doubled.
#         """
# 
#         self._target = Target(obj)
#         self._method_doubles = {}
# 
#     def add_allowance(self, method_name, caller):
#         """Adds a new allowance for the given method name.
# 
#         :param str method_name: The name of the method to allow.
#         :param tuple caller: A tuple indicating where the allowance was added
#         :return: The new ``Allowance``.
#         :rtype: Allowance
#         """
# 
#         return self.method_double_for(method_name).add_allowance(caller)
# 
#     def add_expectation(self, method_name, caller):
#         """Adds a new expectation for the given method name.
# 
#         :param str method_name: The name of the method to expect.
#         :return: The new ``Expectation``.
#         :rtype: Expectation
#         """
# 
#         return self.method_double_for(method_name).add_expectation(caller)
# 
#     def restore_original_object(self):
#         """Remove all stubs from an object.
# 
#         Removes the proxy methods applied to each method double and replaces them with the original
#         values.
#         """
# 
#         for method_double in self._method_doubles.values():
#             method_double.restore_original_method()
# 
#     def verify(self):
#         """Verifies all expectations on all method doubles.
# 
#         :raise: ``MockExpectationError`` on the first expectation that is not satisfied, if any.
#         """
# 
#         for method_double in self._method_doubles.values():
#             method_double.verify()
# 
#     def method_double_for(self, method_name):
#         """Returns the method double for the provided method name, creating one if necessary.
# 
#         :param str method_name: The name of the method to retrieve a method double for.
#         :return: The mapped ``MethodDouble``.
#         :rtype: MethodDouble
#         """
# 
#         if method_name not in self._method_doubles:
#             self._method_doubles[method_name] = MethodDouble(method_name, self._target)
# 
#         return self._method_doubles[method_name]


# Path: doubles/space.py
from doubles.patch import Patch
from doubles.proxy import Proxy



class Space(object):
    """
    A container object for all the doubles created during the execution of a test case. Maintains
    a one-to-one mapping of target objects and ``Proxy`` objects. Maintained by the ``lifecycle``
    module and not intended to be used directly by other objects.
    """

    def __init__(self):
        self._proxies = {}
        self._patches = {}
        self._is_verified = False
        self.skip_builtin_verification = False

    def patch_for(self, path):
        """Returns the ``Patch`` for the target path, creating it if necessary.

        :param str path: The absolute module path to the target.
        :return: The mapped ``Patch``.
        :rtype: Patch
        """

        if path not in self._patches:

            self._patches[path] = Patch(path)