code: def parse_template(self, pattern):
          
  
          i = _util.StringIter((self._original.decode('latin-1') if self.is_bytes else self._original))
          iter(i)
          self.result = [""]
  
          while True:
              try:
                  t = next(i)
                  if self.use_format and t in _CURLY_BRACKETS:
                      self.handle_format(t, i)
                  elif t == '\\':
                      try:
                          t = next(i)
                          self.reference(t, i)
                      except StopIteration:
                          self.result.append(t)
                          raise
                  else:
                      self.result.append(t)
  
              except StopIteration:
                  break
  
          if len(self.result) > 1:
              self.literal_slots.append("".join(self.result))
              del self.result[:]
              self.result.append("")
              self.slot += 1
  
          if self.is_bytes:
              self._template = "".join(self.literal_slots).encode('latin-1')
          else:
              self._template = "".join(self.literal_slots)
          self.groups, self.literals = self.regex_parse_template(self._template, pattern)
docs: Parse template.