Load (optionally, compiling) pysnmp MIB modules
503334
def loadModules(self, *modNames, **userCtx):
        """"""
        # Build a list of available modules
        if not modNames:
            modNames = {}

            for mibSource in self._mibSources:
                for modName in mibSource.listdir():
                    modNames[modName] = None

            modNames = list(modNames)

        if not modNames:
            raise error.MibNotFoundError(
                'No MIB module to load at %s' % (self,))

        for modName in modNames:
            try:
                self.loadModule(modName, **userCtx)

            except error.MibNotFoundError:
                if not self._mibCompiler:
                    raise

                debug.logger & debug.FLAG_BLD and debug.logger(
                    'loadModules: calling MIB compiler for %s' % modName)

                status = self._mibCompiler.compile(modName, genTexts=self.loadTexts)

                errs = '; '.join(
                    hasattr(x, 'error') and str(x.error) or x
                    for x in status.values()
                    if x in ('failed', 'missing'))

                if errs:
                    raise error.MibNotFoundError(
                        '%s compilation error(s): %s' % (modName, errs))

                # compilation succeeded, MIB might load now
                self.loadModule(modName, **userCtx)

        return self
1297917
def load_module(self, module):
        '''
        
        '''
        m_ref = self._modules_map.get(module)
        if m_ref is None:
            raise LoaderError('Module "{0}" was not found'.format(module))
        mod = importlib.import_module('ansible.modules{0}'.format(
            '.'.join([elm.split('.')[0] for elm in m_ref.split(os.path.sep)])))

        return mod
762136
def load(filenames, prepare_data_iterator=True, batch_size=None, exclude_parameter=False, parameter_only=False):
    '''
    '''
    class Info:
        pass
    info = Info()

    proto = nnabla_pb2.NNablaProtoBuf()
    for filename in filenames:
        _, ext = os.path.splitext(filename)

        # TODO: Here is some known problems.
        #   - Even when protobuf file includes network structure,
        #     it will not loaded.
        #   - Even when prototxt file includes parameter,
        #     it will not loaded.

        if ext in ['.nntxt', '.prototxt']:
            if not parameter_only:
                with open(filename, 'rt') as f:
                    try:
                        text_format.Merge(f.read(), proto)
                    except:
                        logger.critical('Failed to read {}.'.format(filename))
                        logger.critical(
                            '2 byte characters may be used for file name or folder name.')
                        raise
            if len(proto.parameter) > 0:
                if not exclude_parameter:
                    nn.load_parameters(filename)
        elif ext in ['.protobuf', '.h5']:
            if not exclude_parameter:
                nn.load_parameters(filename)
            else:
                logger.info('Skip loading parameter.')

        elif ext == '.nnp':
            try:
                tmpdir = tempfile.mkdtemp()
                with zipfile.ZipFile(filename, 'r') as nnp:
                    for name in nnp.namelist():
                        _, ext = os.path.splitext(name)
                        if name == 'nnp_version.txt':
                            nnp.extract(name, tmpdir)
                            with open(os.path.join(tmpdir, name), 'rt') as f:
                                pass  # TODO currently do nothing with version.
                        elif ext in ['.nntxt', '.prototxt']:
                            nnp.extract(name, tmpdir)
                            if not parameter_only:
                                with open(os.path.join(tmpdir, name), 'rt') as f:
                                    text_format.Merge(f.read(), proto)
                            if len(proto.parameter) > 0:
                                if not exclude_parameter:
                                    nn.load_parameters(
                                        os.path.join(tmpdir, name))
                        elif ext in ['.protobuf', '.h5']:
                            nnp.extract(name, tmpdir)
                            if not exclude_parameter:
                                nn.load_parameters(os.path.join(tmpdir, name))
                            else:
                                logger.info('Skip loading parameter.')
            finally:
                shutil.rmtree(tmpdir)

    default_context = None
    if proto.HasField('global_config'):
        info.global_config = _global_config(proto)
        default_context = info.global_config.default_context
        if 'cuda' in default_context.backend:
            import nnabla_ext.cudnn
        elif 'cuda:float' in default_context.backend:
            try:
                import nnabla_ext.cudnn
            except:
                pass
    else:
        import nnabla_ext.cpu
        default_context = nnabla_ext.cpu.context()

    comm = current_communicator()
    if comm:
        default_context.device_id = str(comm.rank)
    if proto.HasField('training_config'):
        info.training_config = _training_config(proto)

    info.datasets = _datasets(
        proto, prepare_data_iterator if prepare_data_iterator is not None else info.training_config.max_epoch > 0)

    info.networks = _networks(proto, default_context, batch_size)

    info.optimizers = _optimizers(
        proto, default_context, info.networks, info.datasets)

    info.monitors = _monitors(
        proto, default_context, info.networks, info.datasets)

    info.executors = _executors(proto, info.networks)

    return info
763748
def _load_modules(self, force_refresh=False, notify=False, grains=None, opts=None):
        '''
        
        '''
        opt_in = True
        if not opts:
            opts = self.opts
            opt_in = False
        # if this is a *nix system AND modules_max_memory is set, lets enforce
        # a memory limit on module imports
        # this feature ONLY works on *nix like OSs (resource module doesn't work on windows)
        modules_max_memory = False
        if opts.get('modules_max_memory', -1) > 0 and HAS_PSUTIL and HAS_RESOURCE:
            log.debug(
                'modules_max_memory set, enforcing a maximum of %s',
                opts['modules_max_memory']
            )
            modules_max_memory = True
            old_mem_limit = resource.getrlimit(resource.RLIMIT_AS)
            rss, vms = psutil.Process(os.getpid()).memory_info()[:2]
            mem_limit = rss + vms + opts['modules_max_memory']
            resource.setrlimit(resource.RLIMIT_AS, (mem_limit, mem_limit))
        elif opts.get('modules_max_memory', -1) > 0:
            if not HAS_PSUTIL:
                log.error('Unable to enforce modules_max_memory because psutil is missing')
            if not HAS_RESOURCE:
                log.error('Unable to enforce modules_max_memory because resource is missing')

        # This might be a proxy minion
        if hasattr(self, 'proxy'):
            proxy = self.proxy
        else:
            proxy = None

        if grains is None:
            opts['grains'] = salt.loader.grains(opts, force_refresh, proxy=proxy)
        self.utils = salt.loader.utils(opts, proxy=proxy)

        if opts.get('multimaster', False):
            s_opts = copy.deepcopy(opts)
            functions = salt.loader.minion_mods(s_opts, utils=self.utils, proxy=proxy,
                                                loaded_base_name=self.loaded_base_name, notify=notify)
        else:
            functions = salt.loader.minion_mods(opts, utils=self.utils, notify=notify, proxy=proxy)
        returners = salt.loader.returners(opts, functions, proxy=proxy)
        errors = {}
        if '_errors' in functions:
            errors = functions['_errors']
            functions.pop('_errors')

        # we're done, reset the limits!
        if modules_max_memory is True:
            resource.setrlimit(resource.RLIMIT_AS, old_mem_limit)

        executors = salt.loader.executors(opts, functions, proxy=proxy)

        if opt_in:
            self.opts = opts

        return functions, returners, errors, executors
179634
def loadb(chars, no_bytes=False, object_hook=None, object_pairs_hook=None, intern_object_keys=False):
    """"""
    with BytesIO(chars) as fp:
        return load(fp, no_bytes=no_bytes, object_hook=object_hook, object_pairs_hook=object_pairs_hook,
                    intern_object_keys=intern_object_keys)
1012308
def imethodcallPayload(self, methodname, localnsp, **kwargs):
        """"""

        param_list = [pywbem.IPARAMVALUE(x[0], pywbem.tocimxml(x[1]))
                      for x in kwargs.items()]

        payload = cim_xml.CIM(
            cim_xml.MESSAGE(
                cim_xml.SIMPLEREQ(
                    cim_xml.IMETHODCALL(
                        methodname,
                        cim_xml.LOCALNAMESPACEPATH(
                            [cim_xml.NAMESPACE(ns)
                             for ns in localnsp.split('/')]),
                        param_list)),
                '1001', '1.0'),
            '2.0', '2.0')

        return self.xml_header + payload.toxml()
60303
def load_nb(cls, inline=True):
        
        from IPython.display import publish_display_data
        cls._loaded = True
        init_notebook_mode(connected=not inline)
        publish_display_data(data={MIME_TYPES['jlab-hv-load']:
                                   get_plotlyjs()})
1070144
def modules(self):
        """"""
        defmodule = lib.EnvGetNextDefmodule(self._env, ffi.NULL)

        while defmodule != ffi.NULL:
            yield Module(self._env, defmodule)

            defmodule = lib.EnvGetNextDefmodule(self._env, defmodule)
1122785
def _load_lexers(module_name):
    """"""
    mod = __import__(module_name, None, None, ['__all__'])
    for lexer_name in mod.__all__:
        cls = getattr(mod, lexer_name)
        _lexer_cache[cls.name] = cls
627215
def load_modules(self, data=None, proxy=None):
        '''
        
        '''
        log.info('Loading fresh modules for state activity')
        # Load a modified client interface that looks like the interface used
        # from the minion, but uses remote execution
        #
        self.functions = salt.client.FunctionWrapper(
                self.opts,
                self.opts['id']
                )
        # Load the states, but they should not be used in this class apart
        # from inspection
        self.utils = salt.loader.utils(self.opts)
        self.serializers = salt.loader.serializers(self.opts)
        self.states = salt.loader.states(self.opts, self.functions, self.utils, self.serializers)
        self.rend = salt.loader.render(self.opts, self.functions, states=self.states, context=self.state_con)
669465
def backend_from_mime(mime):
    """"""
    try:
        mod_name = MIMETYPE_TO_BACKENDS[mime]

    except KeyError:
        msg = "No handler for %r, defaulting to %r" % (mime, DEFAULT_MIME)
        if 'FULLTEXT_TESTING' in os.environ:
            warn(msg)
        else:
            LOGGER.debug(msg)

        mod_name = MIMETYPE_TO_BACKENDS[DEFAULT_MIME]
    mod = import_mod(mod_name)
    return mod
1280605
def module2uri(self, module_name):
        """"""
        encoded_str = super(EncodedModuleLoader, self).module2uri(module_name)
        encoded = encoded_str.encode('ASCII')
        compressed = base64.b64decode(encoded, b'+&')
        return zlib.decompress(compressed)
227255
def init_mimedb():
    """"""
    global mimedb
    try:
        mimedb = mimetypes.MimeTypes(strict=False)
    except Exception as msg:
        log_error("could not initialize MIME database: %s" % msg)
        return
    add_mimedb_data(mimedb)
191763
def init_mimedb():
    """"""
    global mimedb
    try:
        mimedb = mimetypes.MimeTypes(strict=False)
    except Exception as msg:
        log.error(LOG_CHECK, "could not initialize MIME database: %s" % msg)
        return
    # For Opera bookmark files (opera6.adr)
    add_mimetype(mimedb, 'text/plain', '.adr')
    # To recognize PHP files as HTML with content check.
    add_mimetype(mimedb, 'application/x-httpd-php', '.php')
    # To recognize WML files
    add_mimetype(mimedb, 'text/vnd.wap.wml', '.wml')
165548
def load_module(prefix, epoch, data_names, data_shapes):
    
    sym, arg_params, aux_params = mx.model.load_checkpoint(prefix, epoch)

    # We don't need CTC loss for prediction, just a simple softmax will suffice.
    # We get the output of the layer just before the loss layer ('pred_fc') and add softmax on top
    pred_fc = sym.get_internals()['pred_fc_output']
    sym = mx.sym.softmax(data=pred_fc)

    mod = mx.mod.Module(symbol=sym, context=mx.cpu(), data_names=data_names, label_names=None)
    mod.bind(for_training=False, data_shapes=data_shapes)
    mod.set_params(arg_params, aux_params, allow_missing=False)
    return mod
451381
def load_module(name, filename):
    ''''''
    if sys.version_info < (3, 5):
        import imp
        import warnings
        with warnings.catch_warnings():  # Required for Python 2.7
            warnings.simplefilter("ignore", RuntimeWarning)
            return imp.load_source(name, filename)
    else:
        from importlib.machinery import SourceFileLoader
        loader = SourceFileLoader(name, filename)
        return loader.load_module()
1010085
function initNPM() {
    if (npmIsReady) return npmIsReady;

    npmIsReady = Promise.nfcall(npm.load, {
        silent: true,
        loglevel: 'silent'
    });

    return npmIsReady;
}