def _load(self, key):
        '''
        Load a single item if you have it
        '''
        # if the key doesn't have a '.' then it isn't valid for this mod dict
        if not isinstance(key, six.string_types):
            raise KeyError('The key must be a string.')
        if '.' not in key:
            raise KeyError('The key \'{0}\' should contain a \'.\''.format(key))
        mod_name, _ = key.split('.', 1)
        with self._lock:
            # It is possible that the key is in the dictionary after
            # acquiring the lock due to another thread loading it.
            if mod_name in self.missing_modules or key in self._dict:
                return True
            # if the modulename isn't in the whitelist, don't bother
            if self.whitelist and mod_name not in self.whitelist:
                log.error(
                    'Failed to load function %s because its module (%s) is '
                    'not in the whitelist: %s', key, mod_name, self.whitelist
                )
                raise KeyError(key)

            def _inner_load(mod_name):
                for name in self._iter_files(mod_name):
                    if name in self.loaded_files:
                        continue
                    # if we got what we wanted, we are done
                    if self._load_module(name) and key in self._dict:
                        return True
                return False

            # try to load the module
            ret = None
            reloaded = False
            # re-scan up to once, IOErrors or a failed load cause re-scans of the
            # filesystem
            while True:
                try:
                    ret = _inner_load(mod_name)
                    if not reloaded and ret is not True:
                        self._refresh_file_mapping()
                        reloaded = True
                        continue
                    break
                except IOError:
                    if not reloaded:
                        self._refresh_file_mapping()
                        reloaded = True
                    continue

        return ret
def _load ( self , key ) : if not isinstance ( key , six . string_types ) : raise KeyError ( 'The key must be a string.' ) if '.' not in key : raise KeyError ( 'The key \'{0}\' should contain a \'.\'' . format ( key ) ) mod_name , _ = key . split ( '.' , 1 ) with self . _lock : if mod_name in self . missing_modules or key in self . _dict : return True if self . whitelist and mod_name not in self . whitelist : log . error ( 'Failed to load function %s because its module (%s) is ' 'not in the whitelist: %s' , key , mod_name , self . whitelist ) raise KeyError ( key ) def _inner_load ( mod_name ) : for name in self . _iter_files ( mod_name ) : if name in self . loaded_files : continue if self . _load_module ( name ) and key in self . _dict : return True return False ret = None reloaded = False while True : try : ret = _inner_load ( mod_name ) if not reloaded and ret is not True : self . _refresh_file_mapping ( ) reloaded = True continue break except IOError : if not reloaded : self . _refresh_file_mapping ( ) reloaded = True continue return ret
Load a single item if you have it