old_contents: import re
  
  
  def get_valid_filename(s):
      """
      Returns the given string converted to a string that can be used for a clean
      filename. Specifically, leading and trailing spaces are removed; other
      spaces are converted to underscores; and anything that is not a unicode
      alphanumeric, dash, underscore, or dot, is removed.
      >>> get_valid_filename("john's portrait in 2004.jpg")
      'johns_portrait_in_2004.jpg'
      """
      s = s.strip().replace(" ", "_")
      return re.sub(r"(?u)[^-\w.]", "", s)
  
new_contents: import os
  import re
  
  
  def get_valid_filename(s):
      """
      Returns the given string converted to a string that can be used for a clean
      filename. Specifically, leading and trailing spaces are removed; other
      spaces are converted to underscores; and anything that is not a unicode
      alphanumeric, dash, underscore, or dot, is removed.
      >>> get_valid_filename("john's portrait in 2004.jpg")
      'johns_portrait_in_2004.jpg'
      """
      s = s.strip().replace(" ", "_")
      return re.sub(r"(?u)[^-\w.]", "", s)
  
  
  # Define our own abspath function that can handle joining
  # unicode paths to a current working directory that has non-ASCII
  # characters in it.  This isn't necessary on Windows since the
  # Windows version of abspath handles this correctly.  The Windows
  # abspath also handles drive letters differently than the pure
  # Python implementation, so it's best not to replace it.
  if os.name == "nt":
      abspath = os.path.abspath
  else:
      def abspath(path):
          """
          Version of os.path.abspath that uses the unicode representation
          of the current working directory, thus avoiding a UnicodeDecodeError
          in join when the cwd has non-ASCII characters.
          """
          if not os.path.isabs(path):
              path = os.path.join(os.getcwdu(), path)
          return os.path.normpath(path)
  
subject: Handle unicode in paths