<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def load_hook_files(pathname):
 """ Loads files either defined as a glob or a single file path sorted by filenames. """

    global hooks

    if sys.version_info[0] > 2 and sys.version_info[1] > 4:
        fsglob = sorted(glob.iglob(pathname, recursive=True))
    else:
        fsglob = sorted(glob.iglob(pathname))

    for path in fsglob:
        real_path = os.path.realpath(path)
        # Append hooks file directory to the sys.path so submodules can be
        # loaded too.
        if os.path.dirname(real_path) not in sys.path:
            sys.path.append(os.path.dirname(real_path))
        module = imp.load_source(os.path.basename(path), real_path)
        for name in dir(module):
            obj = getattr(module, name)
            if hasattr(obj, 'dredd_hooks') and callable(obj):
                func_hooks = getattr(obj, 'dredd_hooks')
                for hook, name in func_hooks:
                    if hook == BEFORE_ALL:
                        hooks._before_all.append(obj)
                    if hook == AFTER_ALL:
                        hooks._after_all.append(obj)
                    if hook == BEFORE_EACH:
                        hooks._before_each.append(obj)
                    if hook == AFTER_EACH:
                        hooks._after_each.append(obj)
                    if hook == BEFORE_EACH_VALIDATION:
                        hooks._before_each_validation.append(obj)
                    if hook == BEFORE_VALIDATION:
                        add_named_hook(hooks._before_validation, obj, name)
                    if hook == BEFORE:
                        add_named_hook(hooks._before, obj, name)
                    if hook == AFTER:
                        add_named_hook(hooks._after, obj, name)