def legitimize(text, os=detect_os()):
<EOL>text = text.translate({<EOL><NUM_LIT:0>: None,<EOL>ord('<STR_LIT:/>'): '<STR_LIT:->',<EOL>ord('<STR_LIT:|>'): '<STR_LIT:->',<EOL>})<EOL>if os == '<STR_LIT>' or os == '<STR_LIT>' or os == '<STR_LIT>':<EOL><INDENT>text = text.translate({<EOL>ord('<STR_LIT::>'): '<STR_LIT:->',<EOL>ord('<STR_LIT:*>'): '<STR_LIT:->',<EOL>ord('<STR_LIT:?>'): '<STR_LIT:->',<EOL>ord('<STR_LIT:\\>'): '<STR_LIT:->',<EOL>ord('<STR_LIT>'): '<STR_LIT>',<EOL>ord('<STR_LIT:+>'): '<STR_LIT:->',<EOL>ord('<STR_LIT:<>'): '<STR_LIT:->',<EOL>ord('<STR_LIT:>>'): '<STR_LIT:->',<EOL>ord('<STR_LIT:[>'): '<STR_LIT:(>',<EOL>ord('<STR_LIT:]>'): '<STR_LIT:)>',<EOL>ord('<STR_LIT:\t>'): '<STR_LIT:U+0020>',<EOL>})<EOL><DEDENT>else:<EOL><INDENT>if os == '<STR_LIT>':<EOL><INDENT>text = text.translate({<EOL>ord('<STR_LIT::>'): '<STR_LIT:->',<EOL>})<EOL><DEDENT>if text.startswith("<STR_LIT:.>"):<EOL><INDENT>text = text[<NUM_LIT:1>:]<EOL><DEDENT><DEDENT>text = text[:<NUM_LIT>] <EOL>return text<EOL>
Converts a string to a valid filename.