docs: def get_number_header_lines(docbody, page_break_posns):
      """Try to guess the number of header lines each page of a document has.
         The positions of the page breaks in the document are used to try to guess
         the number of header lines.
         @param docbody: (list) of strings - each string being a line in the
          document
         @param page_break_posns: (list) of integers - each integer is the
          position of a page break in the document.
         @return: (int) the number of lines that make up the header of each page.
      """
      remaining_breaks = len(page_break_posns) - 1
      num_header_lines = empty_line = 0
      # pattern to search for a word in a line:
      p_wordSearch = re.compile(ur'([A-Za-z0-9-]+)', re.UNICODE)
      if remaining_breaks > 2:
          if remaining_breaks > 3:
              # Only check odd page headers
              next_head = 2
          else:
              # Check headers on each page
              next_head = 1
          keep_checking = 1
          while keep_checking:
              cur_break = 1
              if docbody[(page_break_posns[cur_break] +
                          num_header_lines + 1)].isspace():
                  # this is a blank line
                  empty_line = 1
  
              if (page_break_posns[cur_break] + num_header_lines + 1) \
                      == (page_break_posns[(cur_break + 1)]):
                  # Have reached next page-break: document has no
                  # body - only head/footers!
                  keep_checking = 0
  
              grps_headLineWords = \
                  p_wordSearch.findall(docbody[(page_break_posns[cur_break] +
                                                num_header_lines + 1)])
              cur_break = cur_break + next_head
              while (cur_break < remaining_breaks) and keep_checking:
                  lineno = page_break_posns[cur_break] + num_header_lines + 1
                  if lineno >= len(docbody):
                      keep_checking = 0
                      break
                  grps_thisLineWords = \
                      p_wordSearch.findall(docbody[lineno])
                  if empty_line:
                      if len(grps_thisLineWords) != 0:
                          # This line should be empty, but isn't
                          keep_checking = 0
                  else:
                      if (len(grps_thisLineWords) == 0) or \
                              (len(grps_headLineWords) != len(grps_thisLineWords)):
                          # Not same num 'words' as equivilent line
                          # in 1st header:
                          keep_checking = 0
                      else:
                          keep_checking = \
                              check_boundary_lines_similar(grps_headLineWords,
                                                           grps_thisLineWords)
                  # Update cur_break for nxt line to check
                  cur_break = cur_break + next_head
              if keep_checking:
                  # Line is a header line: check next
                  num_header_lines = num_header_lines + 1
              empty_line = 0
      return num_header_lines