docs: def parse(cls, format):
          """
          Parse a format string.  Factory function for the Format class.
  
          :param format: The format string to parse.
  
          :returns: An instance of class Format.
          """
  
          fmt = cls()
  
          # Return an empty Format if format is empty
          if not format:
              return fmt
  
          # Initialize the state for parsing
          state = ParseState(fmt, format)
  
          # Loop through the format string with a state-based parser
          for idx, char in enumerate(format):
              # Some characters get ignored
              if state.check_ignore():
                  continue
  
              if state == 'string':
                  if char == '%':
                      # Handle '%%'
                      if format[idx:idx + 2] == '%%':
                          # Add one % to the string context
                          state.add_text(idx + 1, idx + 2)
                          state.set_ignore(1)
                      else:
                          state.add_text(idx)
                          state.conversion(idx)
                  elif char == '\\':
                      state.add_text(idx)
                      state.escape(idx)
              elif state == 'escape':
                  state.add_escape(idx + 1, char)
                  state.pop_state(idx + 1)
              elif state == 'param':
                  if char == '}':
                      state.set_param(idx)
                      state.pop_state()
              elif state == 'conv':
                  if char == ')':
                      state.set_conversion(idx)
                      state.pop_state()  # now in 'conversion'
                      state.pop_state(idx + 1)  # now in 'string'
              else:  # state == 'conversion'
                  if char in '<>':
                      # Allowed for Apache compatibility, but ignored
                      continue
                  elif char == '!':
                      state.set_reject()
                      continue
                  elif char == ',' and state.code_last:
                      # Syntactically allowed ','
                      continue
                  elif char.isdigit():
                      # True if the code is valid
                      if state.set_code(idx):
                          continue
                  elif char == '{' and state.param_begin is None:
                      state.param(idx + 1)
                      continue
                  elif char == '(' and state.conv_begin is None:
                      state.conv(idx + 1)
                      continue
  
                  # OK, we have a complete conversion
                  state.set_conversion(idx)
                  state.pop_state(idx + 1)
  
          # Finish the parse and return the completed format
          return state.end_state()