<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def __get_service_from_factory(self, bundle, reference):
 # type: (Any, ServiceReference) -> Any """ Returns a service instance from a service factory or a prototype service factory :param bundle: The bundle requiring the service :param reference: A reference pointing to a factory :return: The requested service :raise BundleException: The service could not be found """

        try:
            factory, svc_reg = self.__svc_factories[reference]

            # Indicate the dependency
            imports = self.__bundle_imports.setdefault(bundle, {})
            if reference not in imports:
                # New reference usage: store a single usage
                # The Factory counter will handle the rest
                usage_counter = _UsageCounter()
                usage_counter.inc()
                imports[reference] = usage_counter
                reference.used_by(bundle)

            # Check the per-bundle usage counter
            factory_counter = self.__factory_usage.setdefault(
                bundle, _FactoryCounter(bundle)
            )
            return factory_counter.get_service(factory, svc_reg)
        except KeyError:
            # Not found
            raise BundleException(
                "Service not found (reference: {0})".format(reference)
            )