<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_modules(modulename=None):
 """Return a list of modules and packages under modulename. If modulename is not given, return a list of all top level modules and packages. """

    modulename = compat.ensure_not_unicode(modulename)
    if not modulename:
        try:
            return ([modname for (importer, modname, ispkg)
                     in iter_modules()
                     if not modname.startswith("_")] +
                    list(sys.builtin_module_names))
        except OSError:
            # Bug in Python 2.6, see #275
            return list(sys.builtin_module_names)
    try:
        module = safeimport(modulename)
    except ErrorDuringImport:
        return []
    if module is None:
        return []
    if hasattr(module, "__path__"):
        return [modname for (importer, modname, ispkg)
                in iter_modules(module.__path__)
                if not modname.startswith("_")]
    return []