code: def normalize_filepath(filepath):
      r
      filename = os.path.basename(filepath)
      dirpath = filepath[:-len(filename)]
      cre_controlspace = re.compile(r'[\t\r\n\f]+')
      new_filename = cre_controlspace.sub('', filename)
      if not new_filename == filename:
          logger.warning('Stripping whitespace from filename: {} => {}'.format(
              repr(filename), repr(new_filename)))
          filename = new_filename
      filename = filename.lower()
      filename = normalize_ext(filename)
      if dirpath:
          dirpath = dirpath[:-1]  # get rid of the trailing os.path.sep
          return os.path.join(dirpath, filename)
      return filename
docs: r""" Lowercase the filename and ext, expanding extensions like .tgz to .tar.gz.
  
      >>> normalize_filepath('/Hello_World.txt\n')
      'hello_world.txt'
      >>> normalize_filepath('NLPIA/src/nlpia/bigdata/Goog New 300Dneg\f.bIn\n.GZ')
      'NLPIA/src/nlpia/bigdata/goog new 300dneg.bin.gz'