nodes: 0, module; 1, function_definition; 2, function_name:load_hook_files; 3, parameters; 4, block; 5, identifier:pathname; 6, expression_statement; 7, global_statement; 8, if_statement; 9, for_statement; 10, comment:"""
      Loads files either defined as a glob or a single file path
      sorted by filenames.
      """; 11, identifier:hooks; 12, boolean_operator; 13, block; 14, else_clause; 15, identifier:path; 16, identifier:fsglob; 17, block; 18, comparison_operator:sys.version_info[0] > 2; 19, comparison_operator:sys.version_info[1] > 4; 20, expression_statement; 21, block; 22, expression_statement; 23, comment:# Append hooks file directory to the sys.path so submodules can be; 24, comment:# loaded too.; 25, if_statement; 26, expression_statement; 27, for_statement; 28, subscript; 29, integer:2; 30, subscript; 31, integer:4; 32, assignment; 33, expression_statement; 34, assignment; 35, comparison_operator:os.path.dirname(real_path) not in sys.path; 36, block; 37, assignment; 38, identifier:name; 39, call; 40, block; 41, attribute; 42, integer:0; 43, attribute; 44, integer:1; 45, identifier:fsglob; 46, call; 47, assignment; 48, identifier:real_path; 49, call; 50, call; 51, attribute; 52, expression_statement; 53, identifier:module; 54, call; 55, identifier:dir; 56, argument_list; 57, expression_statement; 58, if_statement; 59, identifier:sys; 60, identifier:version_info; 61, identifier:sys; 62, identifier:version_info; 63, identifier:sorted; 64, argument_list; 65, identifier:fsglob; 66, call; 67, attribute; 68, argument_list; 69, attribute; 70, argument_list; 71, identifier:sys; 72, identifier:path; 73, call; 74, attribute; 75, argument_list; 76, identifier:module; 77, assignment; 78, boolean_operator; 79, block; 80, call; 81, identifier:sorted; 82, argument_list; 83, attribute; 84, identifier:realpath; 85, identifier:path; 86, attribute; 87, identifier:dirname; 88, identifier:real_path; 89, attribute; 90, argument_list; 91, identifier:imp; 92, identifier:load_source; 93, call; 94, identifier:real_path; 95, identifier:obj; 96, call; 97, call; 98, call; 99, expression_statement; 100, for_statement; 101, attribute; 102, argument_list; 103, call; 104, identifier:os; 105, identifier:path; 106, identifier:os; 107, identifier:path; 108, attribute; 109, identifier:append; 110, call; 111, attribute; 112, argument_list; 113, identifier:getattr; 114, argument_list; 115, identifier:hasattr; 116, argument_list; 117, identifier:callable; 118, argument_list; 119, assignment; 120, pattern_list; 121, identifier:func_hooks; 122, block; 123, identifier:glob; 124, identifier:iglob; 125, identifier:pathname; 126, keyword_argument; 127, attribute; 128, argument_list; 129, identifier:sys; 130, identifier:path; 131, attribute; 132, argument_list; 133, attribute; 134, identifier:basename; 135, identifier:path; 136, identifier:module; 137, identifier:name; 138, identifier:obj; 139, string; 140, identifier:obj; 141, identifier:func_hooks; 142, call; 143, identifier:hook; 144, identifier:name; 145, if_statement; 146, if_statement; 147, if_statement; 148, if_statement; 149, if_statement; 150, if_statement; 151, if_statement; 152, if_statement; 153, identifier:recursive; 154, True; 155, identifier:glob; 156, identifier:iglob; 157, identifier:pathname; 158, attribute; 159, identifier:dirname; 160, identifier:real_path; 161, identifier:os; 162, identifier:path; 163, string_content:dredd_hooks; 164, identifier:getattr; 165, argument_list; 166, comparison_operator:hook == BEFORE_ALL; 167, block; 168, comparison_operator:hook == AFTER_ALL; 169, block; 170, comparison_operator:hook == BEFORE_EACH; 171, block; 172, comparison_operator:hook == AFTER_EACH; 173, block; 174, comparison_operator:hook == BEFORE_EACH_VALIDATION; 175, block; 176, comparison_operator:hook == BEFORE_VALIDATION; 177, block; 178, comparison_operator:hook == BEFORE; 179, block; 180, comparison_operator:hook == AFTER; 181, block; 182, identifier:os; 183, identifier:path; 184, identifier:obj; 185, string; 186, identifier:hook; 187, identifier:BEFORE_ALL; 188, expression_statement; 189, identifier:hook; 190, identifier:AFTER_ALL; 191, expression_statement; 192, identifier:hook; 193, identifier:BEFORE_EACH; 194, expression_statement; 195, identifier:hook; 196, identifier:AFTER_EACH; 197, expression_statement; 198, identifier:hook; 199, identifier:BEFORE_EACH_VALIDATION; 200, expression_statement; 201, identifier:hook; 202, identifier:BEFORE_VALIDATION; 203, expression_statement; 204, identifier:hook; 205, identifier:BEFORE; 206, expression_statement; 207, identifier:hook; 208, identifier:AFTER; 209, expression_statement; 210, string_content:dredd_hooks; 211, call; 212, call; 213, call; 214, call; 215, call; 216, call; 217, call; 218, call; 219, attribute; 220, argument_list; 221, attribute; 222, argument_list; 223, attribute; 224, argument_list; 225, attribute; 226, argument_list; 227, attribute; 228, argument_list; 229, identifier:add_named_hook; 230, argument_list; 231, identifier:add_named_hook; 232, argument_list; 233, identifier:add_named_hook; 234, argument_list; 235, attribute; 236, identifier:append; 237, identifier:obj; 238, attribute; 239, identifier:append; 240, identifier:obj; 241, attribute; 242, identifier:append; 243, identifier:obj; 244, attribute; 245, identifier:append; 246, identifier:obj; 247, attribute; 248, identifier:append; 249, identifier:obj; 250, attribute; 251, identifier:obj; 252, identifier:name; 253, attribute; 254, identifier:obj; 255, identifier:name; 256, attribute; 257, identifier:obj; 258, identifier:name; 259, identifier:hooks; 260, identifier:_before_all; 261, identifier:hooks; 262, identifier:_after_all; 263, identifier:hooks; 264, identifier:_before_each; 265, identifier:hooks; 266, identifier:_after_each; 267, identifier:hooks; 268, identifier:_before_each_validation; 269, identifier:hooks; 270, identifier:_before_validation; 271, identifier:hooks; 272, identifier:_before; 273, identifier:hooks; 274, identifier:_after
code: 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)