docs: def make_masks(self, template):
          """This method generates all seven masks so that the best mask can
          be determined. The template parameter is a code matrix that will
          server as the base for all the generated masks.
          """
          from copy import deepcopy
  
          nmasks = len(tables.mask_patterns)
          masks = [''] * nmasks
          count = 0
  
          for n in range(nmasks):
              cur_mask = deepcopy(template)
              masks[n] = cur_mask
  
              #Add the type pattern bits to the code
              self.add_type_pattern(cur_mask, tables.type_bits[self.error][n])
  
              #Get the mask pattern
              pattern = tables.mask_patterns[n]
  
              #This will read the 1's and 0's one at a time
              bits = iter(self.buffer.getvalue())
  
              #These will help us do the up, down, up, down pattern
              row_start = itertools.cycle([len(cur_mask)-1, 0])
              row_stop = itertools.cycle([-1,len(cur_mask)])
              direction = itertools.cycle([-1, 1])
  
              #The data pattern is added using pairs of columns
              for column in range(len(cur_mask)-1, 0, -2):
  
                  #The vertical timing pattern is an exception to the rules,
                  #move the column counter over by one
                  if column <= 6:
                      column = column - 1
  
                  #This will let us fill in the pattern
                  #right-left, right-left, etc.
                  column_pair = itertools.cycle([column, column-1])
  
                  #Go through each row in the pattern moving up, then down
                  for row in range(next(row_start), next(row_stop),
                                   next(direction)):
  
                      #Fill in the right then left column
                      for i in range(2):
                          col = next(column_pair)
  
                          #Go to the next column if we encounter a
                          #preexisting pattern (usually an alignment pattern)
                          if cur_mask[row][col] != ' ':
                              continue
  
                          #Some versions don't have enough bits. You then fill
                          #in the rest of the pattern with 0's. These are
                          #called "remainder bits."
                          try:
                              bit = int(next(bits))
                          except:
                              bit = 0
  
  
                          #If the pattern is True then flip the bit
                          if pattern(row, col):
                              cur_mask[row][col] = bit ^ 1
                          else:
                              cur_mask[row][col] = bit
  
          #DEBUG CODE!!!
          #Save all of the masks as png files
          #for i, m in enumerate(masks):
          #    _png(m, self.version, 'mask-{0}.png'.format(i), 5)
  
          return masks