code: def format_string(m, l, capture, is_bytes):
      
  
      for fmt_type, value in capture[1:]:
          if fmt_type == FMT_ATTR:
              # Attribute
              l = getattr(l, value)
          elif fmt_type == FMT_INDEX:
              # Index
              l = l[value]
          elif fmt_type == FMT_CONV:
              if is_bytes:
                  # Conversion
                  if value in ('r', 'a'):
                      l = repr(l).encode('ascii', 'backslashreplace')
                  elif value == 's':
                      # If the object is not string or byte string already
                      l = _to_bstr(l)
              else:
                  # Conversion
                  if value == 'a':
                      l = ascii(l)
                  elif value == 'r':
                      l = repr(l)
                  elif value == 's':
                      # If the object is not string or byte string already
                      l = str(l)
          elif fmt_type == FMT_SPEC:
              # Integers and floats don't have an explicit 's' format type.
              if value[3] and value[3] == 's':
                  if isinstance(l, int):  # pragma: no cover
                      raise ValueError("Unknown format code 's' for object of type 'int'")
                  if isinstance(l, float):  # pragma: no cover
                      raise ValueError("Unknown format code 's' for object of type 'float'")
  
              # Ensure object is a byte string
              l = _to_bstr(l) if is_bytes else str(l)
  
              spec_type = value[1]
              if spec_type == '^':
                  l = l.center(value[2], value[0])
              elif spec_type == ">":
                  l = l.rjust(value[2], value[0])
              else:
                  l = l.ljust(value[2], value[0])
  
      # Make sure the final object is a byte string
      return _to_bstr(l) if is_bytes else str(l)
docs: Perform a string format.