docs: def normalize_serial_number(sn,
                              max_length=None, left_fill='0', right_fill=str(), blank=str(),
                              valid_chars=' -0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
                              invalid_chars=None,
                              strip_whitespace=True, join=False, na=rex.nones):
      r"""Make a string compatible with typical serial number requirements
  
      # Default configuration strips internal and external whitespaces and retains only the last 10 characters
  
      >>> normalize_serial_number('1C 234567890             ')
      '0234567890'
  
      >>> normalize_serial_number('1C 234567890             ', max_length=20)
      '000000001C 234567890'
      >>> normalize_serial_number('Unknown', blank=None, left_fill=str())
      ''
      >>> normalize_serial_number('N/A', blank='', left_fill=str())
      'A'
  
      >>> normalize_serial_number('1C 234567890             ', max_length=20, left_fill='')
      '1C 234567890'
  
      Notice how the max_length setting (20) carries over from the previous test!
      >>> len(normalize_serial_number('Unknown', blank=False))
      20
      >>> normalize_serial_number('Unknown', blank=False)
      '00000000000000000000'
      >>> normalize_serial_number(' \t1C\t-\t234567890 \x00\x7f', max_length=14, left_fill='0',
      ...                         valid_chars='0123456789ABC', invalid_chars=None, join=True)
      '1C\t-\t234567890'
  
      Notice how the max_length setting carries over from the previous test!
      >>> len(normalize_serial_number('Unknown', blank=False))
      14
  
      Restore the default max_length setting
      >>> len(normalize_serial_number('Unknown', blank=False, max_length=10))
      10
      >>> normalize_serial_number('NO SERIAL', blank='--=--', left_fill='')  # doctest: +NORMALIZE_WHITESPACE
      'NO SERIAL'
      >>> normalize_serial_number('NO SERIAL', blank='', left_fill='')  # doctest: +NORMALIZE_WHITESPACE
      'NO SERIAL'
  
      >>> normalize_serial_number('1C 234567890             ', valid_chars='0123456789')
      '0234567890'
      """
      # All 9 kwargs have persistent default values stored as attributes of the funcion instance
      if max_length is None:
          max_length = normalize_serial_number.max_length
      else:
          normalize_serial_number.max_length = max_length
      if left_fill is None:
          left_fill = normalize_serial_number.left_fill
      else:
          normalize_serial_number.left_fill = left_fill
      if right_fill is None:
          right_fill = normalize_serial_number.right_fill
      else:
          normalize_serial_number.right_fill = right_fill
      if blank is None:
          blank = normalize_serial_number.blank
      else:
          normalize_serial_number.blank = blank
      if valid_chars is None:
          valid_chars = normalize_serial_number.valid_chars
      else:
          normalize_serial_number.valid_chars = valid_chars
      if invalid_chars is None:
          invalid_chars = normalize_serial_number.invalid_chars
      else:
          normalize_serial_number.invalid_chars = invalid_chars
      if strip_whitespace is None:
          strip_whitespace = normalize_serial_number.strip_whitespace
      else:
          normalize_serial_number.strip_whitespace = strip_whitespace
      if join is None:
          join = normalize_serial_number.join
      else:
          normalize_serial_number.join = join
      if na is None:
          na = normalize_serial_number.na
      else:
          normalize_serial_number.na = na
  
      if invalid_chars is None:
          invalid_chars = (c for c in charlist.ascii_all if c not in valid_chars)
      invalid_chars = ''.join(invalid_chars)
      sn = str(sn).strip(invalid_chars)
      if strip_whitespace:
          sn = sn.strip()
      if invalid_chars:
          if join:
              sn = sn.translate(dict(zip(invalid_chars, [''] * len(invalid_chars))))
          else:
              sn = multisplit(sn, invalid_chars)[-1]
      sn = sn[-max_length:]
      if strip_whitespace:
          sn = sn.strip()
      if na:
          if isinstance(na, (tuple, set, dict, list)) and sn in na:
              sn = ''
          elif na.match(sn):
              sn = ''
      if not sn and not (blank is False):
          return blank
      if left_fill:
          sn = left_fill * int(max_length - len(sn) / len(left_fill)) + sn
      if right_fill:
          sn = sn + right_fill * (max_length - len(sn) / len(right_fill))
      return sn