def get_mode(self, old_mode=None):
if self.mode is not None:<EOL><INDENT>return self.mode<EOL><DEDENT>assert self.can_write, "<STR_LIT>"<EOL>if old_mode is None:<EOL><INDENT>return self.output_modes[<NUM_LIT:0>]<EOL><DEDENT>if old_mode in self.output_modes:<EOL><INDENT>return old_mode<EOL><DEDENT>try:<EOL><INDENT>idx = PILLOW_MODES.index(old_mode)<EOL><DEDENT>except ValueError:<EOL><INDENT>return self.output_modes[<NUM_LIT:0>]<EOL><DEDENT>for mode in PILLOW_MODES[idx+<NUM_LIT:1>:]:<EOL><INDENT>if mode in self.output_modes:<EOL><INDENT>return mode<EOL><DEDENT><DEDENT>opposite = PILLOW_MODES[:idx]<EOL>opposite.reverse()<EOL>for mode in opposite:<EOL><INDENT>if mode in self.output_modes:<EOL><INDENT>return mode<EOL><DEDENT><DEDENT>
Returns output mode. If `mode` not set it will try to guess best
        mode, or next best mode comparing to old mode