code: 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
      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