human
Complete this python program:
def _rebuild_mod_path(orig_path, package_name, module):
assistant
#Here is the Python code you requested.

    """Rebuild module.__path__ ensuring that all entries are ordered
    corresponding to their sys.path order
    """
    sys_path = [_normalize_cached(p) for p in sys.path]
    def safe_sys_path_index(entry):
        '\n                                Workaround    for    #520    and    #513.\n                                '
        try:
            return sys_path.index(entry)
        except ValueError:
            return float('inf')
    def position_in_sys_path(path):
        '\n                                Return    the    ordinal    of    the    path    based    on    its    position    in    sys.path\n                                '
        path_parts = path.split(os.sep)
        module_parts = (package_name.count('.') + 1)
        parts = path_parts[:(- module_parts)]
        return safe_sys_path_index(_normalize_cached(os.sep.join(parts)))
    if (not isinstance(orig_path, list)):
        return
    orig_path.sort(key=position_in_sys_path)
    module.__path__[:] = [_normalize_cached(p) for p in orig_path]