def safe_filename(file_name, sep='<STR_LIT:_>', default=None, extension=None):
if file_name is None:<EOL><INDENT>return decode_path(default)<EOL><DEDENT>file_name = decode_path(file_name)<EOL>file_name = os.path.basename(file_name)<EOL>file_name, _extension = os.path.splitext(file_name)<EOL>file_name = _safe_name(file_name, sep=sep)<EOL>if file_name is None:<EOL><INDENT>return decode_path(default)<EOL><DEDENT>file_name = file_name[:MAX_LENGTH]<EOL>extension = _safe_name(extension or _extension, sep=sep)<EOL>if extension is not None:<EOL><INDENT>file_name = '<STR_LIT:.>'.join((file_name, extension))<EOL>file_name = file_name[:MAX_LENGTH]<EOL><DEDENT>return file_name<EOL>
Create a secure filename for plain file system storage.