A decorator used to activate the mocker.

        :param prefix:
        :param backend: An instance of a storage backend.
484202
def activate(self, prefix=None, backend=None):
        
        if isinstance(prefix, compat.string_types):
            self.prefix = prefix

        if isinstance(backend, RmoqStorageBackend):
            self.backend = backend

        def activate(func):
            if isinstance(func, type):
                return self._decorate_class(func)

            def wrapper(*args, **kwargs):
                with self:
                    return func(*args, **kwargs)

            return wrapper

        return activate
1141543
def set_storage(self, storage):
        
        if isinstance(storage, BaseStorage):
            self.storage = storage
        elif isinstance(storage, dict):
            if 'backend' not in storage and 'root_dir' in storage:
                storage['backend'] = 'FileSystem'
            try:
                backend_cls = getattr(storage_package, storage['backend'])
            except AttributeError:
                try:
                    backend_cls = import_module(storage['backend'])
                except ImportError:
                    self.logger.error('cannot find backend module %s',
                                      storage['backend'])
                    sys.exit()
            kwargs = storage.copy()
            del kwargs['backend']
            self.storage = backend_cls(**kwargs)
        else:
            raise TypeError('"storage" must be a storage object or dict')
201621
def _validate_backend(self):
        
        try:
            self.backend_class
        # if we get an import error the specified path is wrong
        except (ImportError, AttributeError) as e:
            raise ValidationError(_('No valid backend found, got the following python exception: "%s"') % e)
1039636
def set_current_backend(cls, backend):
        ""
        for hook in cls._backend_switch_hooks:
            hook(backend)
        cls.current_backend = backend
131752
def get_backend(alias):
    
    if alias not in settings.BACKENDS:
        raise VCSError("Given alias '%s' is not recognized! Allowed aliases:\n"
            "%s" % (alias, pformat(settings.BACKENDS.keys())))
    backend_path = settings.BACKENDS[alias]
    klass = import_class(backend_path)
    return klass
807991
def _get_backend(args):
    """"""
    if args.backend == 'gatttool':
        backend = GatttoolBackend
    elif args.backend == 'bluepy':
        backend = BluepyBackend
    elif args.backend == 'pygatt':
        backend = PygattBackend
    else:
        raise Exception('unknown backend: {}'.format(args.backend))
    return backend
1073377
def _add_backend(self, backend):
        
        md_type = backend.verbose_name
        base = backend().get_model(self)
        # TODO: Rename this field
        new_md_attrs = {'_metadata': self.metadata, '__module__': __name__ }

        new_md_meta = {}
        new_md_meta['verbose_name'] = '%s (%s)' % (self.verbose_name, md_type)
        new_md_meta['verbose_name_plural'] = '%s (%s)' % (self.verbose_name_plural, md_type)
        new_md_meta['unique_together'] = base._meta.unique_together
        new_md_attrs['Meta'] = type("Meta", (), new_md_meta)
        new_md_attrs['_metadata_type'] = backend.name
        model = type("%s%s"%(self.name,"".join(md_type.split())), (base, self.MetadataBaseModel), new_md_attrs.copy())
        self.models[backend.name] = model
        # This is a little dangerous, but because we set __module__ to __name__, the model needs tobe accessible here
        globals()[model.__name__] = model
619911
def init_extension(self, app):
        """"""
        app.config.setdefault('CACHE_VERSION', '0')
        app.config.setdefault('CACHE_PREFIX', 'r')
        app.config.setdefault('CACHE_BACKEND', 'rio.exts.flask_cache.NullBackend')
        app.config.setdefault('CACHE_BACKEND_OPTIONS', {})
524031
def get_client(self):
        
        backend_class = import_string(current_app.config.get('CACHE_BACKEND'))
        backend = backend_class(**current_app.config.get('CACHE_BACKEND_OPTIONS'))
        return backend
959969
def register_backends(vars):
    
    new_backends = {x.replace('Backend', ''): cls
                    for x, cls in vars.items()
                    if inspect.isclass(cls) and issubclass(cls, Backend)}
    available_backends.update(new_backends)
1244518
def default_backend=(value)
      raise ArgumentError, "default_backend must be a symbol!" unless value.is_a? Symbol

      unless @backends.keys.include? value
        raise ArgumentError, "Unregistered backend cannot be set as default!"
      end

      @default_backend = value
    end
611536
def init(self, back=None):
        '''
        
        '''
        back = self.backends(back)
        for fsb in back:
            fstr = '{0}.init'.format(fsb)
            if fstr in self.servers:
                self.servers[fstr]()
816145
def backend_to_retrieve(self, namespace, stream):
    
    if namespace not in self.namespaces:
      raise NamespaceMissing('`{}` namespace is not configured'
                             .format(namespace))
    stream_prefix = self.get_matching_prefix(namespace, stream)
    read_backend = self.prefix_read_backends[namespace][stream_prefix]
    return (read_backend,
            self.prefix_confs[namespace][stream_prefix][read_backend])
964820
def _check_backend(self, backend, endpoint):
        
        # First check against hacks for old backend names
        original_backend = backend
        backend = backend.lower()
        if endpoint == 'experiment':
            if backend in self.__names_backend_ibmqxv2:
                return 'real'
            elif backend in self.__names_backend_ibmqxv3:
                return 'ibmqx3'
            elif backend in self.__names_backend_simulator:
                return 'sim_trivial_2'

        # Check for new-style backends
        backends = self.available_backends()
        for backend in backends:
            if backend['name'] == original_backend:
              return original_backend
        # backend unrecognized
        return None
650732
def init_app(self, app):
        

        self.init_blueprint(app)

        if self.flaskcache is not None:
            for func, extension_name in self.CACHED:
                func = getattr(self._extensions[extension_name], func)
                setattr(
                    self._extensions[extension_name],
                    func.__name__,
                    self.flaskcache.memoize()(func)
                )

        return self.blueprint
1100021
def enable(identifier = None, *args, **kwargs):
	'''  '''

	global cache
	if not identifier:
		for item in (config['default-caches'] + ['NoCache']):
			if caches.has_key(item):
				debug('Enabling default cache %s...' % (item,))
				cache = caches[item](*args, **kwargs)
				if not cache.status():
					warning('%s could not be loaded. Is the backend running (%s:%d)?' % (item, cache.server, cache.port))
					continue
				# This means that the cache backend was set up successfully
				break
			else:
				debug('Cache backend %s is not registered. Are all requirements satisfied?' % (item,))
	elif caches.has_key(identifier):
		debug('Enabling cache %s...' % (identifier,))
		previouscache = cache
		cache = caches[identifier](*args, **kwargs)
		if not cache.status():
			warning('%s could not be loaded. Is the backend running (%s:%d)?' % (identifier, cache.server, cache.port))
			cache = previouscache
	else:
		debug('Cache backend %s is not registered. Are all requirements satisfied?' % (identifier,))
1333588
def setup(self, app):
        """"""
        super().setup(app)

        self.enabled = len(self.cfg.backends)

        self.default = self.cfg.default
        if not self.default and self.enabled:
            self.default = self.cfg.backends[0][0]

        self.backends_hash = {name: parse.urlparse(loc) for (name, loc) in self.cfg.backends}
        if self.default and self.default not in self.backends_hash:
            raise PluginException('Backend not found: %s' % self.default)