Operate on libraries and exported functions.

    Query the module name containing the function by default.

    Windows database must be prepared before using this.
177505
def export(context, keywords, module, update):
    
    logging.info(_('Export Mode'))
    database = context.obj['sense']
    none = True
    if update:
        exports = OrderedDict()
        from .executables.pe import PE
        for filename in keywords:
            module = split_ext(filename, basename=True)[0]
            with open(filename, 'rb') as stream:
                exports.update(
                    {module: PE(stream).get_export_table()})
        database.make_export(exports)
        none = False
    elif module:
        for module_name in keywords:
            funcs = database.query_module_funcs(module_name)
            if funcs:
                none = False
                print(', '.join(map(str, funcs)))
            else:
                logging.warning(_('No function for module: %s'),
                                module_name)
    else:
        for func_name in keywords:
            module_name = database.query_func_module(func_name)
            if module_name:
                none = False
                print(repr(module_name))
            else:
                logging.warning(_('No module for function: %s'),
                                func_name)
    sys.exit(1 if none else 0)
505150
def _import(module, cls):
    
    global Scanner

    try:
        cls = str(cls)
        mod = __import__(str(module), globals(), locals(), [cls], 1)
        Scanner = getattr(mod, cls)
    except ImportError:
        pass
945060
def load_module(module):
    
    try:
        m = importlib.import_module(module)
        return m
    except ModuleNotFoundError:  # pragma: no cover
        raise TImportError("Module `%s` is not installed. It is required for "
                           "running this function." % module)
791585
def find_function_by_name(self, name):
        
        cfg_rv = None
        for cfg in self._cfgs:
            if cfg.name == name:
                cfg_rv = cfg
                break
        return cfg_rv
900465
def _build_module_db(self):
        
        tdict = collections.defaultdict(lambda: [])
        for callable_name, callable_dict in self._exh_obj.callables_db.items():
            fname, line_no = callable_dict["code_id"]
            cname = (
                "{cls_name}.__init__".format(cls_name=callable_name)
                if callable_dict["type"] == "class"
                else callable_name
            )
            tdict[fname].append({"name": cname, "line": line_no})
        for fname in tdict.keys():
            self._module_obj_db[fname] = sorted(
                tdict[fname], key=lambda idict: idict["line"]
            )
1091839
def resolve(self):
        
        module = __import__(self.module_name, fromlist=['__name__'], level=0)
        try:
            return functools.reduce(getattr, self.attrs, module)
        except AttributeError as exc:
            raise ImportError(str(exc))
1111790
def get_function(fn_name):
    
    module_name, callable_name = fn_name.split(':')
    current = globals()
    if not callable_name:
        callable_name = module_name
    else:
        import importlib
        try:
            module = importlib.import_module(module_name)
        except ImportError:
            log.error("failed to import %s", module_name)
            raise
        current = module
    for level in callable_name.split('.'):
        current = getattr(current, level)
    code = current.__code__
    if code.co_argcount != 2:
        raise ValueError('function should take 2 arguments: lines, file_name')
    return current
347457
function module(filename) {
            return function () {
                if (verbose.local) console.log(filename);
                response.write(fs.readFileSync(filename) + '\n/*:oxsep:*/\n');
            };
        }
1233961
def serialize_func_name(func):
    
    if func.__module__ == '__main__':
        raise ValueError('Functions from the __main__ module cannot be '
                         'processed by workers.')
    try:
        # This will only work on Python 3.3 or above, but it will allow us to use static/classmethods
        func_name = func.__qualname__
    except AttributeError:
        func_name = func.__name__
    return ':'.join([func.__module__, func_name])
801028
function Library (libfile, funcs, lib) {
  debug('creating Library object for', libfile);

  if (libfile && libfile.indexOf(EXT) === -1) {
    debug('appending library extension to library name', EXT);
    libfile += EXT;
  }

  if (!lib) {
    lib = {};
  }
  const dl = new DynamicLibrary(libfile || null, RTLD_NOW);

  Object.keys(funcs || {}).forEach(function (func) {
    debug('defining function', func);

    const fptr = dl.get(func);
    const info = funcs[func];

    if (fptr.isNull()) {
      throw new Error('Library: "' + libfile
        + '" returned NULL function pointer for "' + func + '"');
    }

    const resultType = info[0];
    const paramTypes = info[1];
    const fopts = info[2];
    const abi = fopts && fopts.abi;
    const async = fopts && fopts.async;
    const varargs = fopts && fopts.varargs;

    if (varargs) {
      lib[func] = VariadicForeignFunction(fptr, resultType, paramTypes, abi);
    } else {
      const ff = ForeignFunction(fptr, resultType, paramTypes, abi);
      lib[func] = async ? ff.async : ff;
    }
  });

  return lib;
}
982339
function getExports(fullpath, { initializer, call, inject }, pathName) {
  let exports = utils.loadFile(fullpath);
  // process exports as you like
  if (initializer) {
    exports = initializer(exports, { path: fullpath, pathName });
  }

  // return exports when it's a class or generator
  //
  // module.exports = class Service {};
  // or
  // module.exports = function*() {}
  if (is.class(exports) || is.generatorFunction(exports) || is.asyncFunction(exports)) {
    return exports;
  }

  // return exports after call when it's a function
  //
  // module.exports = function(app) {
  //   return {};
  // }
  if (call && is.function(exports)) {
    exports = exports(inject);
    if (exports != null) {
      return exports;
    }
  }

  // return exports what is
  return exports;
}
861892
def missing_fun_string(self, function_name):
        '''
        
        '''
        mod_name = function_name.split('.')[0]
        if mod_name in self.loaded_modules:
            return '\'{0}\' is not available.'.format(function_name)
        else:
            try:
                reason = self.missing_modules[mod_name]
            except KeyError:
                return '\'{0}\' is not available.'.format(function_name)
            else:
                if reason is not None:
                    return '\'{0}\' __virtual__ returned False: {1}'.format(mod_name, reason)
                else:
                    return '\'{0}\' __virtual__ returned False'.format(mod_name)
128515
function(modules){
		return function(System){
			if(!Array.isArray(modules)) {
				return [System.main];
			} else if(typeof modules === "function") {
				return modules.apply(this, arguments);
			} else {
				return modules;
			}
		};
	}
955770
def _get_module(module_name=None, module=None, register=True):
    
    if module is None and module_name is not None:
        try:
            module = sys.modules[module_name]
        except KeyError as ex:
            print(ex)
            raise KeyError(('module_name=%r must be loaded before ' +
                            'receiving injections') % module_name)
    elif module is not None and module_name is None:
        pass
    else:
        raise ValueError('module_name or module must be exclusively specified')
    if register is True:
        _add_injected_module(module)
    return module
285102
function() {
		
		/*
		 * Automatically load spirit scripts by naming convention?
		 * ns.MySpirit would automatically load ns.MySpirit.edbml
		 */
		var edbmlscript, basespirit = gui.Spirit.prototype;
		gui.Function.decorateAfter(basespirit, 'onconfigure', function() {
			if (edbml.bootload && !this.script.loaded) {
				edbmlscript = gui.Object.lookup(this.$classname + '.edbml');
				if (gui.Type.isFunction(edbmlscript)) {
					this.script.load(edbmlscript);
				}
			}
		});

		/*
		 * Nasty hack to circumvent that we hardcode "event" into inline poke 
		 * events, this creates an undesired global variable, but fixes an 
		 * exception in the console, at least I think this was the problem.
		 */
		if (!window.event) {
			try {
				window.event = null;
			} catch (ieexception) {}
		}
	}
330828
def add_library(self, library):
        
        for fn in library.__dict__.copy().values():
            # ignore imported methods and anything beginning __
            if inspect.isfunction(fn) and inspect.getmodule(fn) == library and not fn.__name__.startswith('__'):
                name = fn.__name__.lower()

                # strip preceding _ chars used to avoid conflicts with Java keywords
                if name.startswith('_'):
                    name = name[1:]

                self._functions[name] = fn
656713
def _function_lookup(name, module):
    
    try:
        return _registered_functions[name]
    except KeyError:  # force function registering
        __import__(module)
        mod = sys.modules[module]
        getattr(mod, name)

        return _registered_functions[name]