code: def getFilename(name):
      
      # first replace all illegal chars
      name = re.sub(r"[^0-9a-zA-Z_\-\.]", "_", name)
      # then remove double dots and underscores
      while ".." in name:
          name = name.replace('..', '.')
      while "__" in name:
          name = name.replace('__', '_')
      # remove a leading dot or minus
      if name.startswith((".", "-")):
          name = name[1:]
      return name
docs: Get a filename from given name without dangerous or incompatible characters.